Bringing read-only contact editor in compliance with mocks
Change-Id: I34c058e9e225acf25fbad0f76096af197bf8cd88
diff --git a/res/layout-xlarge/raw_contact_editor_header.xml b/res/layout-xlarge/raw_contact_editor_header.xml
new file mode 100644
index 0000000..b53ae9c
--- /dev/null
+++ b/res/layout-xlarge/raw_contact_editor_header.xml
@@ -0,0 +1,72 @@
+<?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.
+-->
+
+
+<!-- Account info header -->
+<RelativeLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_height="64dip"
+ android:layout_width="match_parent"
+ android:background="@android:drawable/list_selector_background">
+
+ <ImageView
+ android:id="@+id/header_color_bar"
+ android:layout_width="match_parent"
+ android:layout_height="4dip"
+ android:layout_marginBottom="5dip"
+ android:background="@color/edit_divider" />
+
+ <ImageView
+ android:id="@+id/header_icon"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="7dip"
+ android:layout_marginRight="7dip"
+ android:layout_centerVertical="true"
+ android:layout_alignParentRight="true"
+ android:layout_below="@id/header_color_bar" />
+
+ <TextView
+ android:id="@+id/header_account_type"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_toLeftOf="@+id/header_icon"
+ android:layout_alignTop="@id/header_icon"
+ android:layout_marginTop="-4dip"
+
+ android:textSize="24sp"
+ android:textColor="?android:attr/textColorPrimary"
+ android:singleLine="true" />
+
+ <TextView
+ android:id="@+id/header_account_name"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_toLeftOf="@+id/header_icon"
+ android:layout_alignBottom="@+id/header_icon"
+ android:layout_marginBottom="2dip"
+
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:textColor="?android:attr/textColorPrimary"
+ android:singleLine="true" />
+
+ <View
+ android:layout_width="match_parent"
+ android:layout_height="1px"
+ android:layout_alignParentBottom="true"
+
+ android:background="?android:attr/listDivider" />
+</RelativeLayout>
diff --git a/res/layout-xlarge/raw_contact_editor_photo.xml b/res/layout-xlarge/raw_contact_editor_photo.xml
new file mode 100644
index 0000000..b1b86fb
--- /dev/null
+++ b/res/layout-xlarge/raw_contact_editor_photo.xml
@@ -0,0 +1,36 @@
+<?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.
+-->
+
+<com.android.contacts.widget.InterpolatingLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:ex="http://schemas.android.com/apk/res/com.android.contacts"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+
+ <FrameLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ ex:layout_wideParentWidth="960dip"
+ ex:layout_wideLeftMargin="96dip"
+ ex:layout_narrowParentWidth="800dip"
+ ex:layout_narrowLeftMargin="15dip">
+
+ <include
+ android:id="@+id/edit_photo"
+ layout="@layout/item_photo_editor" />
+
+ </FrameLayout>
+</com.android.contacts.widget.InterpolatingLayout>
diff --git a/res/layout-xlarge/raw_contact_editor_view.xml b/res/layout-xlarge/raw_contact_editor_view.xml
index a0b7c00..a65e602 100644
--- a/res/layout-xlarge/raw_contact_editor_view.xml
+++ b/res/layout-xlarge/raw_contact_editor_view.xml
@@ -22,62 +22,9 @@
android:orientation="vertical"
>
- <!-- Account info header -->
- <RelativeLayout android:id="@+id/header"
- android:layout_height="64dip"
- android:layout_width="match_parent"
- android:background="@android:drawable/list_selector_background"
- >
-
- <ImageView android:id="@+id/header_color_bar"
- android:layout_width="match_parent"
- android:layout_height="4dip"
- android:layout_marginBottom="5dip"
- android:background="@color/edit_divider"
- />
-
- <ImageView android:id="@+id/header_icon"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="7dip"
- android:layout_marginRight="7dip"
- android:layout_centerVertical="true"
- android:layout_alignParentRight="true"
- android:layout_below="@id/header_color_bar"
- />
-
- <TextView android:id="@+id/header_account_type"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_toLeftOf="@+id/header_icon"
- android:layout_alignTop="@id/header_icon"
- android:layout_marginTop="-4dip"
-
- android:textSize="24sp"
- android:textColor="?android:attr/textColorPrimary"
- android:singleLine="true"
- />
-
- <TextView android:id="@+id/header_account_name"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_toLeftOf="@+id/header_icon"
- android:layout_alignBottom="@+id/header_icon"
- android:layout_marginBottom="2dip"
-
- android:textAppearance="?android:attr/textAppearanceSmall"
- android:textColor="?android:attr/textColorPrimary"
- android:singleLine="true"
- />
-
- <View
- android:layout_width="match_parent"
- android:layout_height="1px"
- android:layout_alignParentBottom="true"
-
- android:background="?android:attr/listDivider"
- />
- </RelativeLayout>
+ <include
+ layout="@layout/raw_contact_editor_header"
+ android:id="@+id/header" />
<LinearLayout
android:id="@+id/body"
@@ -87,25 +34,9 @@
android:paddingTop="10dip"
>
- <com.android.contacts.widget.InterpolatingLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
- <FrameLayout
- android:id="@+id/stub_photo"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- ex:layout_wideParentWidth="960dip"
- ex:layout_wideLeftMargin="96dip"
- ex:layout_narrowParentWidth="800dip"
- ex:layout_narrowLeftMargin="15dip"
- >
-
- <include
- android:id="@+id/edit_photo"
- layout="@layout/item_photo_editor" />
-
- </FrameLayout>
- </com.android.contacts.widget.InterpolatingLayout>
+ <include
+ layout="@layout/raw_contact_editor_photo"
+ android:id="@+id/stub_photo"/>
<com.android.contacts.widget.InterpolatingLayout
android:layout_width="match_parent"
@@ -127,7 +58,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingRight="?android:attr/scrollbarSize"
- android:layout_below="@id/stub_photo"
android:layout_marginTop="6dip"
android:layout_marginBottom="4dip" />
diff --git a/res/layout-xlarge/read_only_raw_contact_editor_view.xml b/res/layout-xlarge/read_only_raw_contact_editor_view.xml
new file mode 100644
index 0000000..f91789d
--- /dev/null
+++ b/res/layout-xlarge/read_only_raw_contact_editor_view.xml
@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2007 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.
+-->
+
+<com.android.contacts.views.editor.ReadOnlyRawContactEditorView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:ex="http://schemas.android.com/apk/res/com.android.contacts"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <include
+ layout="@layout/raw_contact_editor_header"
+ android:id="@+id/header" />
+
+ <LinearLayout
+ android:id="@+id/body"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:paddingTop="10dip">
+
+ <include
+ layout="@layout/raw_contact_editor_photo"
+ android:id="@+id/stub_photo" />
+
+ <com.android.contacts.widget.InterpolatingLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ ex:layout_wideParentWidth="960dip"
+ ex:layout_wideLeftMargin="96dip"
+ ex:layout_wideRightMargin="96dip"
+ ex:layout_narrowParentWidth="800dip"
+ ex:layout_narrowLeftMargin="15dip"
+ ex:layout_narrowRightMargin="15dip">
+
+ <TextView
+ android:id="@+id/read_only_name"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="12dip"
+ android:layout_marginBottom="6dip"
+ android:layout_marginLeft="6dip"
+ android:textAppearance="?android:attr/textAppearanceMedium" />
+
+ <View
+ android:layout_width="match_parent"
+ android:layout_height="1px"
+ android:background="?android:attr/listDivider" />
+
+ <TextView
+ android:id="@+id/read_only_warning"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="13dip"
+ android:layout_marginBottom="13dip"
+ android:layout_marginLeft="13dip"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:textColor="?android:attr/textColorPrimary"
+ android:drawableLeft="@android:drawable/ic_dialog_alert"
+ android:drawablePadding="10dip"
+ android:gravity="center_vertical" />
+
+ <View
+ android:layout_width="match_parent"
+ android:layout_height="1px"
+ android:background="?android:attr/listDivider" />
+
+ <LinearLayout
+ android:id="@+id/sect_general"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical" />
+ </LinearLayout>
+ </com.android.contacts.widget.InterpolatingLayout>
+ </LinearLayout>
+</com.android.contacts.views.editor.ReadOnlyRawContactEditorView>
diff --git a/src/com/android/contacts/views/editor/BaseRawContactEditorView.java b/src/com/android/contacts/views/editor/BaseRawContactEditorView.java
index 2cc3a81..52c9a29 100644
--- a/src/com/android/contacts/views/editor/BaseRawContactEditorView.java
+++ b/src/com/android/contacts/views/editor/BaseRawContactEditorView.java
@@ -16,6 +16,7 @@
package com.android.contacts.views.editor;
+import com.android.contacts.R;
import com.android.contacts.model.AccountType;
import com.android.contacts.model.AccountType.EditType;
import com.android.contacts.model.EntityDelta;
@@ -30,14 +31,13 @@
import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.RawContacts;
import android.util.AttributeSet;
-import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
import android.widget.LinearLayout;
/**
* Base view that provides common code for the editor interaction for a specific
- * RawContact represented through an {@link EntityDelta}. Callers can
- * reuse this view and quickly rebuild its contents through
- * {@link #setState(EntityDelta, AccountType)}.
+ * RawContact represented through an {@link EntityDelta}.
* <p>
* Internal updates are performed against {@link ValuesDelta} so that the
* source {@link Entity} can be swapped out. Any state-based changes, such as
@@ -45,10 +45,14 @@
* {@link EntityModifier} to ensure that {@link AccountType} are enforced.
*/
public abstract class BaseRawContactEditorView extends LinearLayout {
- protected LayoutInflater mInflater;
- protected PhotoEditorView mPhoto;
- protected boolean mHasPhotoEditor = false;
+ private PhotoEditorView mPhoto;
+ private boolean mHasPhotoEditor = false;
+
+ private View mHeader;
+ private View mBody;
+
+ private boolean mExpanded = true;
public BaseRawContactEditorView(Context context) {
super(context);
@@ -58,6 +62,22 @@
super(context, attrs);
}
+ @Override
+ protected void onFinishInflate() {
+ super.onFinishInflate();
+
+ mHeader = findViewById(R.id.header);
+ mBody = findViewById(R.id.body);
+ mHeader.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ setExpanded(!mExpanded);
+ }
+ });
+
+ mPhoto = (PhotoEditorView)findViewById(R.id.edit_photo);
+ }
+
public void setGroupMetaData(Cursor groupMetaData) {
}
@@ -69,6 +89,11 @@
mPhoto.setPhotoBitmap(bitmap);
}
+ protected void setHasPhotoEditor(boolean hasPhotoEditor) {
+ mHasPhotoEditor = hasPhotoEditor;
+ mPhoto.setVisibility(hasPhotoEditor ? View.VISIBLE : View.GONE);
+ }
+
/**
* Return true if the current {@link RawContacts} supports {@link Photo},
* which means that {@link PhotoEditorView} is enabled.
@@ -99,4 +124,18 @@
* apply to that state.
*/
public abstract void setState(EntityDelta state, AccountType source, ViewIdGenerator vig);
+
+ /* package */ void setExpanded(boolean value) {
+ // only allow collapsing if we are one of several children
+ final boolean newValue;
+ if (getParent() instanceof ViewGroup && ((ViewGroup) getParent()).getChildCount() == 1) {
+ newValue = true;
+ } else {
+ newValue = value;
+ }
+
+ if (newValue == mExpanded) return;
+ mExpanded = newValue;
+ mBody.setVisibility(newValue ? View.VISIBLE : View.GONE);
+ }
}
diff --git a/src/com/android/contacts/views/editor/RawContactEditorView.java b/src/com/android/contacts/views/editor/RawContactEditorView.java
index f3ac4fd..ed9b0d4 100644
--- a/src/com/android/contacts/views/editor/RawContactEditorView.java
+++ b/src/com/android/contacts/views/editor/RawContactEditorView.java
@@ -60,20 +60,18 @@
* {@link EntityModifier} to ensure that {@link AccountType} are enforced.
*/
public class RawContactEditorView extends BaseRawContactEditorView {
- private View mPhotoStub;
+ private LayoutInflater mInflater;
+
private TextFieldsEditorView mName;
private GroupMembershipView mGroupMembershipView;
private ViewGroup mFields;
- private View mHeader;
- private View mBody;
private ImageView mHeaderIcon;
private TextView mHeaderAccountType;
private TextView mHeaderAccountName;
private Button mAddFieldButton;
- private boolean mExpanded = true;
private long mRawContactId = -1;
private boolean mAutoAddToDefaultGroup = true;
@@ -89,16 +87,12 @@
super(context, attrs);
}
- /** {@inheritDoc} */
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mInflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- mPhoto = (PhotoEditorView)findViewById(R.id.edit_photo);
- mPhotoStub = findViewById(R.id.stub_photo);
-
final int photoSize = getResources().getDimensionPixelSize(R.dimen.edit_photo_size);
mName = (TextFieldsEditorView)findViewById(R.id.edit_name);
@@ -107,14 +101,6 @@
mFields = (ViewGroup)findViewById(R.id.sect_fields);
- mHeader = findViewById(R.id.header);
- mBody = findViewById(R.id.body);
- mHeader.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- setExpanded(!mExpanded);
- }
- });
mHeaderIcon = (ImageView) findViewById(R.id.header_icon);
mHeaderAccountType = (TextView) findViewById(R.id.header_account_type);
mHeaderAccountName = (TextView) findViewById(R.id.header_account_name);
@@ -166,9 +152,8 @@
// Show photo editor when supported
EntityModifier.ensureKindExists(state, source, Photo.CONTENT_ITEM_TYPE);
- mHasPhotoEditor = (source.getKindForMimetype(Photo.CONTENT_ITEM_TYPE) != null);
- mPhoto.setVisibility(mHasPhotoEditor ? View.VISIBLE : View.GONE);
- mPhoto.setEnabled(true);
+ setHasPhotoEditor((source.getKindForMimetype(Photo.CONTENT_ITEM_TYPE) != null));
+ getPhotoEditor().setEnabled(true);
mName.setEnabled(true);
// Show and hide the appropriate views
@@ -195,8 +180,7 @@
} else if (Photo.CONTENT_ITEM_TYPE.equals(mimeType)) {
// Handle special case editor for photos
final ValuesDelta primary = state.getPrimaryEntry(mimeType);
- mPhoto.setValues(kind, primary, state, false, vig);
- mPhotoStub.setVisibility(View.VISIBLE);
+ getPhotoEditor().setValues(kind, primary, state, false, vig);
} else if (GroupMembership.CONTENT_ITEM_TYPE.equals(mimeType)) {
if (mGroupMembershipView != null) {
mGroupMembershipView.setState(state);
@@ -295,20 +279,6 @@
return mRawContactId;
}
- /* package */ void setExpanded(boolean value) {
- // only allow collapsing if we are one of several children
- final boolean newValue;
- if (getParent() instanceof ViewGroup && ((ViewGroup) getParent()).getChildCount() == 1) {
- newValue = true;
- } else {
- newValue = value;
- }
-
- if (newValue == mExpanded) return;
- mExpanded = newValue;
- mBody.setVisibility(newValue ? View.VISIBLE : View.GONE);
- }
-
private void showAddInformationPopupWindow() {
final ArrayList<KindSectionView> fields =
new ArrayList<KindSectionView>(mFields.getChildCount());
diff --git a/src/com/android/contacts/views/editor/ReadOnlyRawContactEditorView.java b/src/com/android/contacts/views/editor/ReadOnlyRawContactEditorView.java
index 021f3d6..3b678ca 100644
--- a/src/com/android/contacts/views/editor/ReadOnlyRawContactEditorView.java
+++ b/src/com/android/contacts/views/editor/ReadOnlyRawContactEditorView.java
@@ -44,15 +44,14 @@
/**
* Custom view that displays read-only contacts in the edit screen.
*/
-class ReadOnlyRawContactEditorView extends BaseRawContactEditorView {
+public class ReadOnlyRawContactEditorView extends BaseRawContactEditorView {
+ private LayoutInflater mInflater;
private View mPhotoStub;
private TextView mName;
private TextView mReadOnlyWarning;
private ViewGroup mGeneral;
- private View mHeaderColorBar;
- private View mSideBar;
private ImageView mHeaderIcon;
private TextView mHeaderAccountType;
private TextView mHeaderAccountName;
@@ -75,15 +74,12 @@
mInflater = (LayoutInflater)getContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
- mPhoto = (PhotoEditorView)findViewById(R.id.edit_photo);
mPhotoStub = findViewById(R.id.stub_photo);
mName = (TextView) findViewById(R.id.read_only_name);
mReadOnlyWarning = (TextView) findViewById(R.id.read_only_warning);
mGeneral = (ViewGroup)findViewById(R.id.sect_general);
- mHeaderColorBar = findViewById(R.id.header_color_bar);
- mSideBar = findViewById(R.id.color_bar);
mHeaderIcon = (ImageView) findViewById(R.id.header_icon);
mHeaderAccountType = (TextView) findViewById(R.id.header_account_type);
mHeaderAccountName = (TextView) findViewById(R.id.header_account_name);
@@ -129,10 +125,11 @@
DataKind kind = source.getKindForMimetype(Photo.CONTENT_ITEM_TYPE);
if (kind != null) {
EntityModifier.ensureKindExists(state, source, Photo.CONTENT_ITEM_TYPE);
- mHasPhotoEditor = (source.getKindForMimetype(Photo.CONTENT_ITEM_TYPE) != null);
+ boolean hasPhotoEditor = source.getKindForMimetype(Photo.CONTENT_ITEM_TYPE) != null;
+ setHasPhotoEditor(hasPhotoEditor);
primary = state.getPrimaryEntry(Photo.CONTENT_ITEM_TYPE);
- mPhoto.setValues(kind, primary, state, source.readOnly, vig);
- if (!mHasPhotoEditor || !mPhoto.hasSetPhoto()) {
+ getPhotoEditor().setValues(kind, primary, state, source.readOnly, vig);
+ if (!hasPhotoEditor || !getPhotoEditor().hasSetPhoto()) {
mPhotoStub.setVisibility(View.GONE);
} else {
mPhotoStub.setVisibility(View.VISIBLE);