summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorToha <tohenk@yahoo.com>2018-02-13 12:58:31 +0700
committerSemavi Ulusoy <doc.divxm@gmail.com>2022-02-06 11:02:19 +0300
commit326bc45b14a727e0ade13006a36c7df9c57a2542 (patch)
tree975736e6ff2c03c97023d019459f9c1e6315a3d2 /src
parent59afd52c77b0e2d5bc5b1ae9cd60e8da1cc1ef7b (diff)
Contacts: Enable support for device contact.s12.0
Change-Id: I8f2e907deadced5316be5a418dab2538476a4033 Signed-off-by: Toha <tohenk@yahoo.com> Contacts: Ignore device null account. As of commit 2cb5e0752a8def94c386a02213c54bb1be4b6344 which adds device contact, the behavior is correct if there is a google account already setup, otherwise there are two device contacts shown. So, always ignore null account. Change-Id: I9f18a45efcaa93b8583013beb5995bf85ae58dcd Signed-off-by: Toha <tohenk@yahoo.com>
Diffstat (limited to 'src')
-rw-r--r--src/com/android/contacts/drawer/DrawerAdapter.java3
-rw-r--r--src/com/android/contacts/model/AccountTypeManager.java21
-rw-r--r--src/com/android/contacts/model/DeviceLocalAccountLocator.java10
-rw-r--r--src/com/android/contacts/model/account/AccountTypeProvider.java3
-rw-r--r--src/com/android/contacts/util/AccountSelectionUtil.java2
-rw-r--r--src/com/android/contacts/util/AccountsListAdapter.java2
6 files changed, 26 insertions, 15 deletions
diff --git a/src/com/android/contacts/drawer/DrawerAdapter.java b/src/com/android/contacts/drawer/DrawerAdapter.java
index a2ab9f739..f6898b54f 100644
--- a/src/com/android/contacts/drawer/DrawerAdapter.java
+++ b/src/com/android/contacts/drawer/DrawerAdapter.java
@@ -357,7 +357,8 @@ public class DrawerAdapter extends BaseAdapter {
final AccountDisplayInfo displayableAccount =
mAccountDisplayFactory.getAccountDisplayInfoFor(item.account);
final TextView textView = ((TextView) result.findViewById(R.id.title));
- textView.setText(displayableAccount.getNameLabel());
+ textView.setText(mActivity.getPackageName().equals(account.accountType) ?
+ mActivity.getString(R.string.account_phone) : displayableAccount.getNameLabel());
final boolean activated = account.equals(mSelectedAccount)
&& mSelectedView == ContactsView.ACCOUNT_VIEW;
textView.setTextAppearance(mActivity, activated
diff --git a/src/com/android/contacts/model/AccountTypeManager.java b/src/com/android/contacts/model/AccountTypeManager.java
index 8e013581d..1adacf83a 100644
--- a/src/com/android/contacts/model/AccountTypeManager.java
+++ b/src/com/android/contacts/model/AccountTypeManager.java
@@ -80,6 +80,7 @@ public abstract class AccountTypeManager {
public static final String BROADCAST_ACCOUNTS_CHANGED = AccountTypeManager.class.getName() +
".AccountsChanged";
+ public static final String DEVICE_ACCOUNT_NAME = "DEVICE";
public enum AccountFilter implements Predicate<AccountInfo> {
ALL {
@@ -398,7 +399,7 @@ class AccountTypeManagerImpl extends AccountTypeManager
*/
public AccountTypeManagerImpl(Context context) {
mContext = context;
- mLocalAccountLocator = new DeviceLocalAccountLocator(context, AccountManager.get(context));
+ mLocalAccountLocator = new DeviceLocalAccountLocator(context);
mTypeProvider = new AccountTypeProvider(context);
mFallbackAccountType = new FallbackAccountType(context);
@@ -629,16 +630,24 @@ class AccountTypeManagerImpl extends AccountTypeManager
private List<AccountWithDataSet> getAccountsWithDataSets(Account[] accounts,
AccountTypeProvider typeProvider) {
List<AccountWithDataSet> result = new ArrayList<>();
+ // add local device account
+ populateAccountsDataSet(typeProvider, new Account(DEVICE_ACCOUNT_NAME,
+ mContext.getPackageName()), result);
for (Account account : accounts) {
- final List<AccountType> types = typeProvider.getAccountTypes(account.type);
- for (AccountType type : types) {
- result.add(new AccountWithDataSet(
- account.name, account.type, type.dataSet));
- }
+ populateAccountsDataSet(typeProvider, account, result);
}
return result;
}
+ private void populateAccountsDataSet(AccountTypeProvider typeProvider, Account account,
+ List<AccountWithDataSet> result) {
+ final List<AccountType> types = typeProvider.getAccountTypes(account.type);
+ for (AccountType type : types) {
+ result.add(new AccountWithDataSet(
+ account.name, account.type, type.dataSet));
+ }
+ }
+
/**
* Returns the default google account specified in preferences, the first google account
* if it is not specified in preferences or is no longer on the device, and null otherwise.
diff --git a/src/com/android/contacts/model/DeviceLocalAccountLocator.java b/src/com/android/contacts/model/DeviceLocalAccountLocator.java
index e8a2ba0ff..89f1ce2db 100644
--- a/src/com/android/contacts/model/DeviceLocalAccountLocator.java
+++ b/src/com/android/contacts/model/DeviceLocalAccountLocator.java
@@ -21,7 +21,6 @@ import android.content.Context;
import android.provider.ContactsContract;
import com.android.contacts.model.account.AccountWithDataSet;
-import com.android.contacts.model.account.GoogleAccountType;
import java.util.Collections;
import java.util.List;
@@ -32,12 +31,10 @@ import java.util.List;
public final class DeviceLocalAccountLocator {
private final Context mContext;
- private final AccountManager mAccountManager;
private final List<AccountWithDataSet> mLocalAccount;
- public DeviceLocalAccountLocator(Context context, AccountManager accountManager) {
+ public DeviceLocalAccountLocator(Context context) {
mContext = context;
- mAccountManager = accountManager;
mLocalAccount = Collections.singletonList(AccountWithDataSet.getLocalAccount(context));
}
@@ -45,10 +42,7 @@ public final class DeviceLocalAccountLocator {
* Returns a list of device local accounts
*/
public List<AccountWithDataSet> getDeviceLocalAccounts() {
- @SuppressWarnings("MissingPermission") final Account[] accounts = mAccountManager
- .getAccountsByType(GoogleAccountType.ACCOUNT_TYPE);
-
- if (accounts.length > 0 && !mLocalAccount.get(0).hasData(mContext)) {
+ if (!mLocalAccount.get(0).hasData(mContext)) {
return Collections.emptyList();
} else {
return mLocalAccount;
diff --git a/src/com/android/contacts/model/account/AccountTypeProvider.java b/src/com/android/contacts/model/account/AccountTypeProvider.java
index 2888dfa38..95b998cb6 100644
--- a/src/com/android/contacts/model/account/AccountTypeProvider.java
+++ b/src/com/android/contacts/model/account/AccountTypeProvider.java
@@ -82,6 +82,9 @@ public class AccountTypeProvider {
* </p>
*/
public List<AccountType> getAccountTypes(String accountType) {
+ if (mContext.getPackageName().equals(accountType)) {
+ accountType = null;
+ }
// ConcurrentHashMap doesn't support null keys
if (accountType == null || mLocalAccountTypeFactory.classifyAccount(accountType)
== DeviceLocalAccountTypeFactory.TYPE_SIM) {
diff --git a/src/com/android/contacts/util/AccountSelectionUtil.java b/src/com/android/contacts/util/AccountSelectionUtil.java
index bfe8a08b3..2b226d0a1 100644
--- a/src/com/android/contacts/util/AccountSelectionUtil.java
+++ b/src/com/android/contacts/util/AccountSelectionUtil.java
@@ -126,6 +126,8 @@ public class AccountSelectionUtil {
text1.setText(accountType.getDisplayLabel(context));
text2.setText(account.name);
+ text2.setVisibility(context.getPackageName().equals(account.type) ?
+ View.GONE : View.VISIBLE);
icon.setImageDrawable(accountType.getDisplayIcon(getContext()));
return convertView;
diff --git a/src/com/android/contacts/util/AccountsListAdapter.java b/src/com/android/contacts/util/AccountsListAdapter.java
index 2bcc68b84..cc80b7985 100644
--- a/src/com/android/contacts/util/AccountsListAdapter.java
+++ b/src/com/android/contacts/util/AccountsListAdapter.java
@@ -95,6 +95,8 @@ public final class AccountsListAdapter extends BaseAdapter {
text1.setText(mAccounts.get(position).getTypeLabel());
text2.setText(mAccounts.get(position).getNameLabel());
+ text2.setVisibility(mAccounts.get(position).getNameLabel().equals(
+ mAccounts.get(position).getTypeLabel()) ? View.GONE : View.VISIBLE);
icon.setImageDrawable(mAccounts.get(position).getIcon());