Esempio n. 1
0
  /**
   * Shows "call via" menu allowing user to selected from multiple providers.
   *
   * @param context the android context
   * @param v the View that will contain the popup menu.
   * @param destination target callee name.
   */
  private static void showCallViaMenu(final Context context, View v, final String destination) {
    PopupMenu popup = new PopupMenu(context, v);

    Menu menu = popup.getMenu();

    Iterator<ProtocolProviderService> registeredProviders =
        AccountUtils.getRegisteredProviders().iterator();

    while (registeredProviders.hasNext()) {
      final ProtocolProviderService provider = registeredProviders.next();
      String accountAddress = provider.getAccountID().getAccountAddress();

      MenuItem menuItem = menu.add(Menu.NONE, Menu.NONE, Menu.NONE, accountAddress);

      menuItem.setOnMenuItemClickListener(
          new MenuItem.OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem item) {
              createCall(context, destination, provider);

              return false;
            }
          });
    }

    popup.show();
  }
  /** Initializes "select account" spinner with existing accounts. */
  private void initAccountSpinner() {
    Spinner accountsSpiner = (Spinner) findViewById(R.id.selectAccountSpinner);

    Iterator<ProtocolProviderService> providers = AccountUtils.getRegisteredProviders().iterator();

    List<AccountID> accounts = new ArrayList<AccountID>();

    int selectedIdx = -1;
    int idx = 0;

    while (providers.hasNext()) {
      ProtocolProviderService provider = providers.next();

      OperationSet opSet = provider.getOperationSet(OperationSetPresence.class);

      if (opSet == null) continue;

      AccountID account = provider.getAccountID();
      accounts.add(account);
      idx++;

      if (account.isPreferredProvider()) {
        selectedIdx = idx;
      }
    }

    AccountsListAdapter accountsAdapter =
        new AccountsListAdapter(
            this, R.layout.select_account_row, R.layout.select_account_dropdown, accounts, true);
    accountsSpiner.setAdapter(accountsAdapter);

    // if we have only select account option and only one account
    // select the available account
    if (accounts.size() == 1) accountsSpiner.setSelection(0);
    else accountsSpiner.setSelection(selectedIdx);
  }