UI fix for account selector
- don't show account info when there's just one account
- modify layout for account selector
Bug: 4184675
Change-Id: I7e5a9527a2bcb2406a1bc377b063bb262b8f12de
diff --git a/res/layout-xlarge/account_selector_list_item.xml b/res/layout-xlarge/account_selector_list_item.xml
new file mode 100644
index 0000000..38acfc5
--- /dev/null
+++ b/res/layout-xlarge/account_selector_list_item.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:minHeight="?android:attr/listPreferredItemHeight"
+>
+ <ImageView android:id="@android:id/icon"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="6dip"
+ android:layout_centerVertical="true"
+ />
+
+ <TextView android:id="@android:id/text1"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="6dip"
+ android:layout_marginTop="6dip"
+ android:layout_toRightOf="@android:id/icon"
+ android:textAppearance="?android:attr/textAppearanceLarge"
+ />
+
+ <TextView android:id="@android:id/text2"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_below="@android:id/text1"
+ android:layout_alignLeft="@android:id/text1"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ />
+</RelativeLayout>
diff --git a/res/layout/account_selector_list_item.xml b/res/layout/account_selector_list_item.xml
index 38acfc5..6fe2a50 100644
--- a/res/layout/account_selector_list_item.xml
+++ b/res/layout/account_selector_list_item.xml
@@ -17,29 +17,23 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:minHeight="?android:attr/listPreferredItemHeight"
->
- <ImageView android:id="@android:id/icon"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="6dip"
- android:layout_centerVertical="true"
- />
+ android:paddingLeft="@dimen/account_selector_horizontal_margin"
+ android:paddingRight="@dimen/account_selector_horizontal_margin"
+ android:minHeight="@dimen/account_selector_min_item_height" >
<TextView android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_marginLeft="6dip"
- android:layout_marginTop="6dip"
- android:layout_toRightOf="@android:id/icon"
- android:textAppearance="?android:attr/textAppearanceLarge"
+ android:layout_alignParentLeft="true"
+ android:layout_toLeftOf="@android:id/icon"
+ android:layout_centerVertical="true"
+ android:textAppearance="?android:attr/textAppearanceMedium"
/>
- <TextView android:id="@android:id/text2"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_below="@android:id/text1"
- android:layout_alignLeft="@android:id/text1"
- android:textAppearance="?android:attr/textAppearanceSmall"
+ <ImageView android:id="@android:id/icon"
+ android:layout_width="@dimen/account_selector_icon_size"
+ android:layout_height="@dimen/account_selector_icon_size"
+ android:layout_alignParentRight="true"
+ android:layout_centerVertical="true"
/>
</RelativeLayout>
diff --git a/res/layout/raw_contact_editor_view.xml b/res/layout/raw_contact_editor_view.xml
index 7c027eb..5aa1e95 100644
--- a/res/layout/raw_contact_editor_view.xml
+++ b/res/layout/raw_contact_editor_view.xml
@@ -32,7 +32,7 @@
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_marginRight="4dip"
- android:background="@color/account_selection_background"
+ android:background="@android:drawable/list_selector_background"
android:orientation="horizontal"
android:gravity="left|center_vertical">
@@ -49,10 +49,13 @@
<LinearLayout
android:id="@+id/account"
- android:layout_height="wrap_content"
+ android:layout_height="match_parent"
android:layout_width="match_parent"
+ android:paddingLeft="@dimen/account_selector_horizontal_margin"
+ android:paddingRight="@dimen/account_selector_horizontal_margin"
android:background="@color/account_selection_background"
- android:orientation="vertical">
+ android:orientation="vertical"
+ android:gravity="left|center_vertical">
<TextView
android:id="@+id/account_type"
android:layout_width="wrap_content"
@@ -78,8 +81,8 @@
<ImageView
android:id="@+id/account_icon"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content" />
+ android:layout_width="@dimen/account_selector_icon_size"
+ android:layout_height="@dimen/account_selector_icon_size" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 354bec7..ff7d873 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -26,6 +26,9 @@
<dimen name="aggregation_suggestion_icon_size">40dip</dimen>
<dimen name="account_selector_popup_width">400dip</dimen>
+ <dimen name="account_selector_icon_size">30dip</dimen>
+ <dimen name="account_selector_min_item_height">48dip</dimen>
+ <dimen name="account_selector_horizontal_margin">6dip</dimen>
<dimen name="photo_action_popup_width">400dip</dimen>
diff --git a/src/com/android/contacts/editor/RawContactEditorView.java b/src/com/android/contacts/editor/RawContactEditorView.java
index 4effb5e..5ef2c21 100644
--- a/src/com/android/contacts/editor/RawContactEditorView.java
+++ b/src/com/android/contacts/editor/RawContactEditorView.java
@@ -20,11 +20,13 @@
import com.android.contacts.R;
import com.android.contacts.model.AccountType;
import com.android.contacts.model.AccountType.EditType;
+import com.android.contacts.model.AccountTypeManager;
import com.android.contacts.model.DataKind;
import com.android.contacts.model.EntityDelta;
import com.android.contacts.model.EntityDelta.ValuesDelta;
import com.android.contacts.model.EntityModifier;
+import android.accounts.Account;
import android.content.Context;
import android.content.Entity;
import android.database.Cursor;
@@ -68,6 +70,7 @@
private ViewGroup mFields;
+ private View mAccountContainer;
private ImageView mAccountIcon;
private TextView mAccountTypeTextView;
private TextView mAccountNameTextView;
@@ -136,6 +139,7 @@
mFields = (ViewGroup)findViewById(R.id.sect_fields);
+ mAccountContainer = findViewById(R.id.account);
mAccountIcon = (ImageView) findViewById(R.id.account_icon);
mAccountTypeTextView = (TextView) findViewById(R.id.account_type);
mAccountNameTextView = (TextView) findViewById(R.id.account_name);
@@ -169,22 +173,29 @@
// Make sure we have StructuredName
EntityModifier.ensureKindExists(state, type, StructuredName.CONTENT_ITEM_TYPE);
- // Fill in the header info
ValuesDelta values = state.getValues();
- String accountName = values.getAsString(RawContacts.ACCOUNT_NAME);
- CharSequence accountType = type.getDisplayLabel(mContext);
- if (TextUtils.isEmpty(accountType)) {
- accountType = mContext.getString(R.string.account_phone);
- }
- if (!TextUtils.isEmpty(accountName)) {
- mAccountNameTextView.setText(
- mContext.getString(R.string.from_account_format, accountName));
- }
- mAccountTypeTextView.setText(mContext.getString(R.string.account_type_format, accountType));
- mAccountIcon.setImageDrawable(type.getDisplayIcon(mContext));
-
mRawContactId = values.getAsLong(RawContacts._ID);
+ final ArrayList<Account> accounts =
+ AccountTypeManager.getInstance(mContext).getAccounts(true);
+ if (accounts.size() > 1) {
+ // Fill in the account info
+ String accountName = values.getAsString(RawContacts.ACCOUNT_NAME);
+ CharSequence accountType = type.getDisplayLabel(mContext);
+ if (TextUtils.isEmpty(accountType)) {
+ accountType = mContext.getString(R.string.account_phone);
+ }
+ if (!TextUtils.isEmpty(accountName)) {
+ mAccountNameTextView.setText(
+ mContext.getString(R.string.from_account_format, accountName));
+ }
+ mAccountTypeTextView.setText(
+ mContext.getString(R.string.account_type_format, accountType));
+ mAccountIcon.setImageDrawable(type.getDisplayIcon(mContext));
+ } else {
+ mAccountContainer.setVisibility(View.GONE);
+ }
+
// Show photo editor when supported
EntityModifier.ensureKindExists(state, type, Photo.CONTENT_ITEM_TYPE);
setHasPhotoEditor((type.getKindForMimetype(Photo.CONTENT_ITEM_TYPE) != null));
diff --git a/src/com/android/contacts/util/AccountsListAdapter.java b/src/com/android/contacts/util/AccountsListAdapter.java
index 8dbfc8d..97a9f84 100644
--- a/src/com/android/contacts/util/AccountsListAdapter.java
+++ b/src/com/android/contacts/util/AccountsListAdapter.java
@@ -60,7 +60,9 @@
final AccountType accountType = mAccountTypes.getAccountType(account.type);
text1.setText(account.name);
- text2.setText(accountType.getDisplayLabel(mContext));
+ if (text2 != null) {
+ text2.setText(accountType.getDisplayLabel(mContext));
+ }
icon.setImageDrawable(accountType.getDisplayIcon(mContext));
return resultView;