public void makeVoipCall(final String number) {
    AudioManagerUtils.setLoudSpeaker(false);
    ((BaseActivity) getActivity()).showProgressDialog("Connecting VOIP Call");
    RequestParams params = new RequestParams();
    params.put("smartPagerID", SmartPagerApplication.getInstance().getPreferences().getUserID());
    params.put("uberPassword", SmartPagerApplication.getInstance().getPreferences().getPassword());

    AsyncHttpClient httpClient = new AsyncHttpClient();
    httpClient.post(
        getActivity().getApplicationContext(),
        Constants.BASE_REST_URL + "/getTwilioClientToken",
        params,
        new JsonHttpResponseHandler() {

          @Override
          public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            System.out.println("successful response: " + response);
            ((BaseActivity) getActivity()).hideProgressDialog();

            VoipPhone voipPhone =
                new VoipPhone(
                    ((BaseActivity) getActivity()).getApplicationContext(),
                    response.optString("token"));
            voipPhone.connect(number);
          }

          @Override
          public void onFailure(
              int statusCode, Header[] headers, String responseBody, Throwable error) {
            System.out.println("failure response: " + responseBody);
            ((BaseActivity) getActivity()).hideProgressDialog();
          }
        });
  }
  public void startArmCallback(final String number) {
    Bundle extras = new Bundle();
    extras.putString(WebSendParam.phoneNumber.name(), number);
    //        SmartPagerApplication.getInstance().startWebAction(WebAction.armCallback, extras);
    ((BaseActivity) getActivity()).showProgressDialog(getString(R.string.sending_request));

    RequestParams params = new RequestParams();
    params.put("smartPagerID", SmartPagerApplication.getInstance().getPreferences().getUserID());
    params.put("uberPassword", SmartPagerApplication.getInstance().getPreferences().getPassword());
    params.put("phoneNumber", number);

    httpClient.post(
        getActivity().getApplicationContext(),
        Constants.BASE_REST_URL + "/armCallback",
        params,
        new JsonHttpResponseHandler() {

          @Override
          public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            System.out.println("successful response: " + response);
            ((BaseActivity) getActivity()).hideProgressDialog();
            makeArmCallBack(number);
          }

          @Override
          public void onFailure(
              int statusCode, Header[] headers, String responseBody, Throwable error) {
            System.out.println("failure response: " + responseBody);
            ((BaseActivity) getActivity()).hideProgressDialog();
          }
        });
  }
        @Override
        public void onCallButtonClick(String phoneNumber) {
          if (SmartPagerApplication.getInstance().getSettingsPreferences().getVoipToggled()) {
            makeVoipCall(phoneNumber);
            return;
          }

          if (SmartPagerApplication.getInstance().getPreferences().getShowMobileNumbers()
              == false) {
            startArmCallback(phoneNumber);
            return;
          }

          TelephoneUtils.dial(phoneNumber);
        }
  public void makeArmCallBack(String number) {
    String pagerNumber = SmartPagerApplication.getInstance().getPreferences().getPagerNumber();
    String routerNumber =
        SmartPagerApplication.getInstance().getPreferences().getCallRouterPhoneNumber();

    if (TextUtils.isEmpty(pagerNumber) && TextUtils.isEmpty(routerNumber)) {
      // !PagerNo + !RouterNo
      ((BaseActivity) getActivity()).showErrorDialog(R.string.your_pager_number_is_invalid);
    } else if (!TextUtils.isEmpty(pagerNumber) && TextUtils.isEmpty(routerNumber)) {
      // PagerNo + !RouterNo
      pushOutgoingCallNumber(number);
      TelephoneUtils.dial(pagerNumber);
    } else if (TextUtils.isEmpty(pagerNumber) && !TextUtils.isEmpty(routerNumber)) {
      // !PagerNo + RouterNo
      pushOutgoingCallNumber(number);
      TelephoneUtils.dial(routerNumber);
    } else {
      // PagerNo + RouterNo
      pushOutgoingCallNumber(number);
      TelephoneUtils.dial(pagerNumber);
    }
  }
  private void startGroupDetailsService(Recipient recipient) {

    String id = recipient.getId();
    String smartPagerId = recipient.getSmartPagerId();
    String name = recipient.getName();

    ((BaseActivity) getActivity()).showProgressDialog(getActivity().getString(R.string.processing));
    Bundle extras = new Bundle();
    extras.putString(WebSendParam.groupId.name(), id);
    extras.putString(GroupDetails.name.name(), name);
    extras.putString(GroupContactItem.contact_smart_pager_id_or_group_id.name(), smartPagerId);
    SmartPagerApplication.getInstance().startWebAction(WebAction.getPagingGroupDetails, extras);
  }
  private void startContactDetails(Recipient recipient) {

    String id = recipient.getId();
    String smartPagerId = recipient.getSmartPagerId();

    Intent intent =
        new Intent(
            SmartPagerApplication.getInstance().getApplicationContext(),
            ContactDetailsActivity.class);
    intent.putExtra(GroupContactItem.id.name(), id);
    intent.putExtra(GroupContactItem.contact_smart_pager_id_or_group_id.name(), smartPagerId);
    startActivity(intent);
  }
 private void startMarkMessageCalled(Context context, String messageID) {
   Bundle extras = new Bundle();
   extras.putString(WebSendParam.messageId.name(), messageID);
   SmartPagerApplication.getInstance().startWebAction(WebAction.markMessageCalled, extras);
 }
  private LinkedHashMap<String, List<IHolderSource>> getIndexableContactsList(Cursor cursor) {
    String[] sectionTitles = {
      "Favorites",
      "Groups",
      "#",
      "A",
      "B",
      "C",
      "D",
      "E",
      "F",
      "G",
      "H",
      "I",
      "J",
      "K",
      "L",
      "M",
      "N",
      "O",
      "P",
      "Q",
      "R",
      "S",
      "T",
      "U",
      "V",
      "W",
      "X",
      "Y",
      "Z"
    };
    LinkedHashMap<String, List<IHolderSource>> tableDataMap =
        new LinkedHashMap<String, List<IHolderSource>>();
    for (String title : sectionTitles) {
      tableDataMap.put(title, new ArrayList<IHolderSource>());
    }

    if (cursor.moveToFirst()) {
      do {
        Recipient recipient = Recipient.createFromDepartmentCursor(cursor);
        // Don't add currently logged in user as a contact
        if (recipient
            .getSmartPagerId()
            .equalsIgnoreCase(
                SmartPagerApplication.getInstance().getPreferences().getSmartPagerID())) continue;

        if (recipient.isGroup()) {
          tableDataMap.get("Groups").add(recipient);
        } else {
          // trim() to account for any last names that have a leading space
          String firstChar = recipient.getLastName().trim().substring(0, 1).toUpperCase();
          if (Arrays.asList(sectionTitles).contains(firstChar)) {
            tableDataMap.get(firstChar).add(recipient);
          }
        }

        if (SmartPagerApplication.getInstance()
            .isFavourite(getActivity().getApplicationContext(), recipient.getSmartPagerId())) {
          tableDataMap.get("Favorites").add(recipient);
        }

        if (recipient.getGroupType().equalsIgnoreCase("LOCAL")) {
          tableDataMap.get("Favorites").add(recipient);
        }

      } while (cursor.moveToNext());
    }

    // Only sort Favorites and Groups, the rest of the sections appear to sort properly.
    Collections.sort(tableDataMap.get("Favorites"), new RecipientsGroupsComparator());
    Collections.sort(tableDataMap.get("Groups"), new RecipientsGroupsComparator());

    return tableDataMap;
  }
 public String getActionName(String actionName) {
   return SmartPagerApplication.getInstance().getPackageName() + "." + actionName;
 }