Exemplo n.º 1
0
 @Override
 public void onReceive(Context context, Intent intent) {
   String status = intent.getStringExtra(Constants.INTENT_KEY_STATUS);
   Preference.putString(
       context,
       context.getResources().getString(R.string.emm_server_url),
       intent.getStringExtra(Constants.INTENT_KEY_SERVER));
   CommonDialogUtils.stopProgressDialog(progressDialog);
   if (Constants.Status.SUCCESSFUL.equals(status)) {
     if (intent.hasExtra(Constants.INTENT_KEY_PAYLOAD)
         && intent.getStringExtra(Constants.INTENT_KEY_PAYLOAD) != null) {
       try {
         JSONObject payload =
             new JSONObject(intent.getStringExtra(Constants.INTENT_KEY_PAYLOAD));
         if (!payload.isNull(Constants.ApplicationPayload.APP_LIST)) {
           JSONArray applicationList =
               payload.getJSONArray(Constants.ApplicationPayload.APP_LIST);
           appList.setVisibility(View.VISIBLE);
           btnMobileApps.setVisibility(View.VISIBLE);
           btnWebApps.setVisibility(View.VISIBLE);
           txtError.setVisibility(View.GONE);
           setAppListUI(applicationList);
         }
       } catch (JSONException e) {
         appList.setVisibility(View.GONE);
         btnMobileApps.setVisibility(View.GONE);
         btnWebApps.setVisibility(View.GONE);
         txtError.setVisibility(View.VISIBLE);
         Log.e(TAG, "Failed parsing application list response" + e);
       }
     } else {
       appList.setVisibility(View.GONE);
       btnMobileApps.setVisibility(View.GONE);
       btnWebApps.setVisibility(View.GONE);
       txtError.setVisibility(View.VISIBLE);
     }
   } else {
     appList.setVisibility(View.GONE);
     btnMobileApps.setVisibility(View.GONE);
     btnWebApps.setVisibility(View.GONE);
     txtError.setVisibility(View.VISIBLE);
   }
 }
Exemplo n.º 2
0
  private void getAppList() {
    DialogInterface.OnCancelListener cancelListener =
        new DialogInterface.OnCancelListener() {

          @Override
          public void onCancel(DialogInterface arg0) {
            CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(
                context,
                getResources().getString(R.string.error_app_fetch_failed_detail),
                getResources().getString(R.string.app_list_failed),
                getResources().getString(R.string.button_ok),
                null);
          }
        };

    progressDialog =
        CommonDialogUtils.showProgressDialog(
            context,
            getResources().getString(R.string.dialog_app_list),
            getResources().getString(R.string.dialog_please_wait),
            cancelListener);

    // Check network connection availability before calling the API.
    if (CommonUtils.isNetworkAvailable(context)) {
      ApplicationManager applicationManager = new ApplicationManager(context);
      if (applicationManager.isPackageInstalled(Constants.AGENT_PACKAGE_NAME)) {
        btnSignOut.setVisibility(View.GONE);
        IntentFilter filter = new IntentFilter(Constants.AGENT_APP_ACTION_RESPONSE);
        filter.addCategory(Intent.CATEGORY_DEFAULT);
        AgentServiceResponseReceiver receiver = new AgentServiceResponseReceiver();
        registerReceiver(receiver, filter);
        CommonUtils.callAgentApp(context, Constants.Operation.GET_APPLICATION_LIST, null, null);
      } else {
        btnSignOut.setVisibility(View.VISIBLE);
        btnSignOut.setTag(TAG_BTN_SIGN_OUT);
        btnSignOut.setOnClickListener(onClickListener);
        getAppListFromServer();
      }
    } else {
      CommonDialogUtils.stopProgressDialog(progressDialog);
      CommonDialogUtils.showNetworkUnavailableMessage(context);
    }
  }
Exemplo n.º 3
0
 @Override
 public void onReceiveAPIResult(Map<String, String> result, int requestCode) {
   String responseStatus;
   CommonDialogUtils.stopProgressDialog(progressDialog);
   if (requestCode == Constants.APP_LIST_REQUEST_CODE) {
     if (result != null && result.get(Constants.RESPONSE) != null) {
       responseStatus = result.get(Constants.STATUS);
       if (Constants.Status.SUCCESSFUL.equals(responseStatus)) {
         try {
           JSONObject payload = new JSONObject(result.get(Constants.RESPONSE));
           if (!payload.isNull(Constants.ApplicationPayload.APP_LIST)) {
             JSONArray applicationList =
                 payload.getJSONArray(Constants.ApplicationPayload.APP_LIST);
             appList.setVisibility(View.VISIBLE);
             btnMobileApps.setVisibility(View.VISIBLE);
             btnWebApps.setVisibility(View.VISIBLE);
             txtError.setVisibility(View.GONE);
             setAppListUI(applicationList);
           }
         } catch (JSONException e) {
           appList.setVisibility(View.GONE);
           btnMobileApps.setVisibility(View.GONE);
           btnWebApps.setVisibility(View.GONE);
           txtError.setVisibility(View.VISIBLE);
           Log.e(TAG, "Failed parsing application list response" + e);
         }
       } else {
         appList.setVisibility(View.GONE);
         btnMobileApps.setVisibility(View.GONE);
         btnWebApps.setVisibility(View.GONE);
         txtError.setVisibility(View.VISIBLE);
       }
     } else {
       appList.setVisibility(View.GONE);
       btnMobileApps.setVisibility(View.GONE);
       btnWebApps.setVisibility(View.GONE);
       txtError.setVisibility(View.VISIBLE);
     }
   }
 }