use of com.android.contacts.common.model.account.AccountWithDataSet in project android_packages_apps_Dialer by LineageOS.
the class ContactsPreferences method maybeMigrateSystemSettings.
/**
* If there are currently no preferences (which means this is the first time we are run), For sort
* order and display order, check to see if there are any preferences stored in system settings
* (pre-L) which can be copied into our own SharedPreferences. For default account setting, check
* to see if there are any preferences stored in the previous SharedPreferences which can be
* copied into current SharedPreferences.
*/
private void maybeMigrateSystemSettings() {
if (!mPreferences.contains(SORT_ORDER_KEY)) {
int sortOrder = getDefaultSortOrder();
try {
sortOrder = Settings.System.getInt(mContext.getContentResolver(), SORT_ORDER_KEY);
} catch (SettingNotFoundException e) {
}
setSortOrder(sortOrder);
}
if (!mPreferences.contains(DISPLAY_ORDER_KEY)) {
int displayOrder = getDefaultDisplayOrder();
try {
displayOrder = Settings.System.getInt(mContext.getContentResolver(), DISPLAY_ORDER_KEY);
} catch (SettingNotFoundException e) {
}
setDisplayOrder(displayOrder);
}
if (!mPreferences.contains(mDefaultAccountKey)) {
final SharedPreferences previousPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
final String defaultAccount = previousPrefs.getString(mDefaultAccountKey, null);
if (!TextUtils.isEmpty(defaultAccount)) {
final AccountWithDataSet accountWithDataSet = AccountWithDataSet.unstringify(defaultAccount);
setDefaultAccount(accountWithDataSet);
}
}
}
use of com.android.contacts.common.model.account.AccountWithDataSet in project android_packages_apps_Dialer by LineageOS.
the class ContactsPreferences method getDefaultAccount.
public String getDefaultAccount() {
if (!isDefaultAccountUserChangeable()) {
return mDefaultAccount;
}
if (TextUtils.isEmpty(mDefaultAccount)) {
final String accountString = mPreferences.getString(mDefaultAccountKey, mDefaultAccount);
if (!TextUtils.isEmpty(accountString)) {
final AccountWithDataSet accountWithDataSet = AccountWithDataSet.unstringify(accountString);
mDefaultAccount = accountWithDataSet.name;
}
}
return mDefaultAccount;
}
use of com.android.contacts.common.model.account.AccountWithDataSet in project packages_apps_Contacts by AOKP.
the class ConfirmAddDetailActivity method addEditableRawContact.
/**
* Create an {@link RawContactDelta} for a raw_contact on the first editable account found, and add
* to the list. Also copy the structured name from an existing (read-only) raw_contact to the
* new one, if any of the read-only contacts has a name.
*/
private static RawContactDelta addEditableRawContact(Context context, RawContactDeltaList entityDeltaList) {
// First, see if there's an editable account.
final AccountTypeManager accounts = AccountTypeManager.getInstance(context);
final List<AccountWithDataSet> editableAccounts = accounts.getAccounts(true);
if (editableAccounts.size() == 0) {
// No editable account type found. The dialog will be read-only mode.
return null;
}
final AccountWithDataSet editableAccount = editableAccounts.get(0);
final AccountType accountType = accounts.getAccountType(editableAccount.type, editableAccount.dataSet);
// Create a new RawContactDelta for the new raw_contact.
final RawContact rawContact = new RawContact();
rawContact.setAccount(editableAccount);
final RawContactDelta entityDelta = new RawContactDelta(ValuesDelta.fromAfter(rawContact.getValues()));
// Then, copy the structure name from an existing (read-only) raw_contact.
for (RawContactDelta entity : entityDeltaList) {
final ArrayList<ValuesDelta> readOnlyNames = entity.getMimeEntries(StructuredName.CONTENT_ITEM_TYPE);
if ((readOnlyNames != null) && (readOnlyNames.size() > 0)) {
final ValuesDelta readOnlyName = readOnlyNames.get(0);
final ValuesDelta newName = RawContactModifier.ensureKindExists(entityDelta, accountType, StructuredName.CONTENT_ITEM_TYPE);
// Copy all the data fields.
newName.copyStructuredNameFieldsFrom(readOnlyName);
break;
}
}
// Add the new RawContactDelta to the list.
entityDeltaList.add(entityDelta);
return entityDelta;
}
use of com.android.contacts.common.model.account.AccountWithDataSet 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.model.account.AccountWithDataSet in project packages_apps_Contacts by AOKP.
the class AttachPhotoActivity method selectAccountAndCreateContact.
private void selectAccountAndCreateContact() {
// If there is no default account or the accounts have changed such that we need to
// prompt the user again, then launch the account prompt.
final ContactEditorUtils editorUtils = ContactEditorUtils.getInstance(this);
if (editorUtils.shouldShowAccountChangedNotification()) {
Intent intent = new Intent(this, ContactEditorAccountsChangedActivity.class);
startActivityForResult(intent, REQUEST_PICK_DEFAULT_ACCOUNT_FOR_NEW_CONTACT);
} else {
// Otherwise, there should be a default account. Then either create a local contact
// (if default account is null) or create a contact with the specified account.
AccountWithDataSet defaultAccount = editorUtils.getDefaultAccount();
createNewRawContact(defaultAccount);
}
}
Aggregations