コード例 #1
0
  @Override
  public void onResume() {
    super.onResume();
    ActivityMonitor.getInstance().setCurrentActivity(this);

    if (!(preferences.getEmail().equals("")
        || preferences.getPassword().equals("")
        || preferences.getDid().equals(""))) {
      preRecentUpdate();
    } else {
      AlertDialog.Builder builder = new AlertDialog.Builder(this);
      builder.setMessage(getString(R.string.conversations_first_run_dialog_text));
      builder.setPositiveButton(
          getString(R.string.preferences_name),
          new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
              Intent preferencesIntent =
                  new Intent(conversationsActivity, PreferencesActivity.class);
              startActivity(preferencesIntent);
            }
          });
      builder.setNegativeButton(
          getString(R.string.help_name),
          new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
              Intent helpIntent = new Intent(conversationsActivity, HelpActivity.class);
              startActivity(helpIntent);
            }
          });
      builder.setCancelable(false);
      builder.show();
    }
  }
コード例 #2
0
  /**
   * Enable SMS notifications by configuring the VoIP.ms URL callback, registering for GCM and
   * making the appropriate changes to the application preferences.
   *
   * @param activity The source activity.
   */
  public void enableNotifications(final Activity activity) {
    if (preferences.getEmail().equals("")
        || preferences.getPassword().equals("")
        || preferences.getDid().equals("")) {
      Utils.showInfoDialog(
          activity,
          applicationContext.getString(R.string.notifications_callback_username_password_did));
      return;
    }

    final ProgressDialog progressDialog = new ProgressDialog(activity);
    progressDialog.setMessage(activity.getString(R.string.notifications_callback_progress));
    progressDialog.setCancelable(false);
    progressDialog.show();

    new AsyncTask<Boolean, Void, Boolean>() {
      @Override
      protected Boolean doInBackground(Boolean... params) {
        try {
          String url =
              "https://www.voip.ms/api/v1/rest.php?"
                  + "api_username="******"UTF-8")
                  + "&"
                  + "api_password="******"UTF-8")
                  + "&"
                  + "method=setSMS"
                  + "&"
                  + "did="
                  + URLEncoder.encode(preferences.getDid(), "UTF-8")
                  + "&"
                  + "enable=1"
                  + "&"
                  + "url_callback_enable=1"
                  + "&"
                  + "url_callback="
                  + URLEncoder.encode(
                      "http://voipmssms-kourlas.rhcloud.com/sms_callback?did={TO}", "UTF-8")
                  + "&"
                  + "url_callback_retry=0";

          JSONObject result = Utils.getJson(url);
          String status = result.optString("status");
          return !(status == null || !status.equals("success"));
        } catch (Exception ex) {
          return false;
        }
      }

      @Override
      protected void onPostExecute(Boolean success) {
        progressDialog.hide();

        DialogInterface.OnClickListener gcmOnClickListener =
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                gcm.registerForGcm(activity, true, true);
              }
            };

        if (!success) {
          Utils.showAlertDialog(
              activity,
              null,
              applicationContext.getString(R.string.notifications_callback_fail),
              applicationContext.getString(R.string.ok),
              gcmOnClickListener,
              null,
              null);
        } else {
          Utils.showAlertDialog(
              activity,
              null,
              applicationContext.getString(R.string.notifications_callback_success),
              applicationContext.getString(R.string.ok),
              gcmOnClickListener,
              null,
              null);
        }
      }
    }.execute();
  }