Esempio n. 1
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);
    }
  }