use of com.android.contacts.common.util.AccountsListAdapter in project packages_apps_Contacts by AOKP.
the class ContactEditorAccountsChangedActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mEditorUtils = ContactEditorUtils.getInstance(this);
final List<AccountWithDataSet> accounts = AccountTypeManager.getInstance(this).getAccounts(true);
final int numAccounts = accounts.size();
if (numAccounts < 0) {
throw new IllegalStateException("Cannot have a negative number of accounts");
}
final View view;
if (numAccounts > 0) {
// When the user has writable accounts, show a list of accounts so the user can pick
// which account to create a contact in (add also the phone-local storage account).
view = View.inflate(this, R.layout.contact_editor_accounts_changed_activity_with_picker, null);
final TextView textView = (TextView) view.findViewById(R.id.text);
textView.setText(getString(R.string.contact_editor_prompt_multiple_accounts));
final Button button = (Button) view.findViewById(R.id.add_account_button);
button.setText(getString(R.string.add_new_account));
button.setOnClickListener(mAddAccountClickListener);
final ListView accountListView = (ListView) view.findViewById(R.id.account_list);
mAccountListAdapter = new AccountsListAdapter(this, AccountListFilter.ACCOUNTS_CONTACT_WRITABLE);
accountListView.setAdapter(mAccountListAdapter);
accountListView.setOnItemClickListener(mAccountListItemClickListener);
} else {
// If the user has 0 writable accounts, we will just show the user a message with 2
// possible action buttons.
view = View.inflate(this, R.layout.contact_editor_accounts_changed_activity_with_text, null);
final TextView textView = (TextView) view.findViewById(R.id.text);
final Button leftButton = (Button) view.findViewById(R.id.left_button);
final Button rightButton = (Button) view.findViewById(R.id.right_button);
textView.setText(getString(R.string.contact_editor_prompt_zero_accounts));
// This button allows the user to continue editing the contact as a phone-only
// local contact.
leftButton.setText(getString(R.string.keep_local));
leftButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Remember that the user wants to create local contacts, so the user is not
// prompted again with this activity.
mEditorUtils.saveDefaultAndAllAccounts(null);
setResult(RESULT_OK);
finish();
}
});
// This button allows the user to add a new account to the device and return to
// this app afterwards.
rightButton.setText(getString(R.string.add_account));
rightButton.setOnClickListener(mAddAccountClickListener);
}
new AlertDialog.Builder(this).setView(view).setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
finish();
}
}).create().show();
}
use of com.android.contacts.common.util.AccountsListAdapter in project packages_apps_Contacts by AOKP.
the class CompactRawContactsEditorView method addAccountSelector.
private void addAccountSelector(Pair<String, String> accountInfo, final RawContactDelta rawContactDelta) {
mAccountSelectorContainer.setVisibility(View.VISIBLE);
if (TextUtils.isEmpty(accountInfo.first)) {
// Hide this view so the other text view will be centered vertically
mAccountSelectorName.setVisibility(View.GONE);
} else {
mAccountSelectorName.setVisibility(View.VISIBLE);
mAccountSelectorName.setText(accountInfo.first);
MoreContactUtils.setSimOperatorName(accountInfo.first, mAccountSelectorName, getContext());
}
final String selectorTitle = getResources().getString(R.string.compact_editor_account_selector_title);
mAccountSelectorType.setText(selectorTitle);
mAccountSelectorContainer.setContentDescription(getResources().getString(R.string.compact_editor_account_selector_description, accountInfo.first));
mAccountSelectorContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final ListPopupWindow popup = new ListPopupWindow(getContext(), null);
final AccountsListAdapter adapter = new AccountsListAdapter(getContext(), AccountsListAdapter.AccountListFilter.ACCOUNTS_CONTACT_WRITABLE, mPrimaryAccount);
popup.setWidth(mAccountSelectorContainer.getWidth());
popup.setAnchorView(mAccountSelectorContainer);
popup.setAdapter(adapter);
popup.setModal(true);
popup.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NOT_NEEDED);
popup.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
UiClosables.closeQuietly(popup);
final AccountWithDataSet newAccount = adapter.getItem(position);
if (mListener != null && !mPrimaryAccount.equals(newAccount)) {
mListener.onRebindEditorsForNewContact(rawContactDelta, mPrimaryAccount, newAccount);
}
}
});
popup.show();
}
});
}
use of com.android.contacts.common.util.AccountsListAdapter in project packages_apps_Contacts by AOKP.
the class ContactEditorFragment method addAccountSwitcher.
private void addAccountSwitcher(final RawContactDelta currentState, BaseRawContactEditorView editor) {
final AccountWithDataSet currentAccount = new AccountWithDataSet(currentState.getAccountName(), currentState.getAccountType(), currentState.getDataSet());
final View accountView = editor.findViewById(R.id.account);
final View anchorView = editor.findViewById(R.id.account_selector_container);
if (accountView == null) {
return;
}
anchorView.setVisibility(View.VISIBLE);
accountView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final ListPopupWindow popup = new ListPopupWindow(mContext, null);
final AccountsListAdapter adapter = new AccountsListAdapter(mContext, AccountListFilter.ACCOUNTS_CONTACT_WRITABLE, currentAccount);
popup.setWidth(anchorView.getWidth());
popup.setAnchorView(anchorView);
popup.setAdapter(adapter);
popup.setModal(true);
popup.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NOT_NEEDED);
popup.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
UiClosables.closeQuietly(popup);
AccountWithDataSet newAccount = adapter.getItem(position);
if (!newAccount.equals(currentAccount)) {
rebindEditorsForNewContact(currentState, currentAccount, newAccount);
}
}
});
popup.show();
}
});
}
Aggregations