Editor expander changes

Missed tinting the phonetic name expander in ag/1417505.
Went ahead and did some refactoring since
phonetic_name_edit_expansion_view was the same as the name_edit one
but with a different content description. Removed it since content
description should be dynamic with the state of the expander anyway.
Along that line also made accessibility improvements and fixed a bug
with the state of the icon after rotation.

Test:
Checked the color of the phonetic name expander.
Actioned the expanders with Talkback on and made sure the correct
announcements were made.
Checked state of icon after rotation was consistent.

Bug: 30160325
Bug: 31033553
Change-Id: Ia62ed1a03b4edda81815387e3bcf4f48449699e2
diff --git a/res/layout/name_edit_expansion_view.xml b/res/layout/name_edit_expansion_view.xml
index 4d1bd61..066850f 100644
--- a/res/layout/name_edit_expansion_view.xml
+++ b/res/layout/name_edit_expansion_view.xml
@@ -22,7 +22,6 @@
     android:layout_width="wrap_content"
     android:layout_height="@dimen/editor_min_line_item_height"
     android:layout_gravity="top"
-    android:contentDescription="@string/expand_collapse_name_fields_description"
     android:importantForAccessibility="yes"
     android:focusable="true"
     android:clickable="true">
diff --git a/res/layout/phonetic_name_edit_expansion_view.xml b/res/layout/phonetic_name_edit_expansion_view.xml
deleted file mode 100644
index 1613391..0000000
--- a/res/layout/phonetic_name_edit_expansion_view.xml
+++ /dev/null
@@ -1,40 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-  Copyright (C) 2015 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.
-  -->
-
-<FrameLayout
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="wrap_content"
-    android:layout_height="@dimen/editor_min_line_item_height"
-    android:layout_gravity="top"
-    android:contentDescription="@string/expand_collapse_phonetic_name_fields_description"
-    android:importantForAccessibility="yes"
-    android:focusable="true"
-    android:clickable="true">
-    <ImageView
-        android:id="@+id/expansion_view"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_gravity="center"
-        android:duplicateParentState="true"
-        android:background="?android:attr/selectableItemBackground"
-        android:paddingLeft="@dimen/editor_round_button_padding_left"
-        android:paddingRight="@dimen/editor_round_button_padding_right"
-        android:paddingStart="@dimen/editor_round_button_padding_left"
-        android:paddingEnd="@dimen/editor_round_button_padding_right"
-        android:paddingTop="@dimen/editor_round_button_padding_top"
-        android:paddingBottom="@dimen/editor_round_button_padding_bottom" />
-</FrameLayout>
diff --git a/res/layout/phonetic_name_editor_view.xml b/res/layout/phonetic_name_editor_view.xml
index f51d3df..efaf644 100644
--- a/res/layout/phonetic_name_editor_view.xml
+++ b/res/layout/phonetic_name_editor_view.xml
@@ -35,7 +35,7 @@
 
     <include
         android:id="@+id/expansion_view_container"
-        layout="@layout/phonetic_name_edit_expansion_view"
+        layout="@layout/name_edit_expansion_view"
         android:visibility="visible" />
 
     <!-- This isn't used in PhoneticNameEditorView. It is only included so that
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 04f2b0d..becab16 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1278,11 +1278,28 @@
          fields corresponding to each part of the name (Name Prefix, First Name,
          Middle Name, Last Name, Name Suffix).
          [CHAR LIMIT=NONE] -->
-    <string name="expand_collapse_name_fields_description">Expand or collapse name fields</string>
+    <string name="expand_name_fields_description">Expand name fields</string>
 
-    <!-- Content description for the expand or collapse phonetic name fields button. [CHAR LIMIT=100] -->
-    <string name="expand_collapse_phonetic_name_fields_description">Expand or collapse phonetic
-        name fields</string>
+    <!-- Content description for the collapse name fields button. [CHAR LIMIT=NONE] -->
+    <string name="collapse_name_fields_description">Collapse name fields</string>
+
+    <!-- Content description for the expand phonetic name fields button. [CHAR LIMIT=NONE] -->
+    <string name="expand_phonetic_name_fields_description">Expand phonetic name fields</string>
+
+    <!-- Content description for the collapse phonetic name fields button. [CHAR LIMIT=NONE] -->
+    <string name="collapse_phonetic_name_fields_description">Collapse phonetic name fields</string>
+
+    <!-- Content description for a generic expand fields button. [CHAR LIMIT=NONE] -->
+    <string name="expand_fields_description">Expand</string>
+
+    <!-- Content description for a generic collapse fields button. [CHAR LIMIT=NONE] -->
+    <string name="collapse_fields_description">Collapse</string>
+
+    <!-- A11y announcement text for when a expand fields button is actioned. [CHAR LIMIT=NONE] -->
+    <string name="announce_expanded_fields">Expanded</string>
+
+    <!-- A11y announcement text for when a collapse fields button is actioned. [CHAR LIMIT=NONE] -->
+    <string name="announce_collapsed_fields">Collapsed</string>
 
     <!-- Contact list filter label indicating that the list is showing all available accounts [CHAR LIMIT=64] -->
     <string name="list_filter_all_accounts">All contacts</string>
diff --git a/src/com/android/contacts/editor/PhoneticNameEditorView.java b/src/com/android/contacts/editor/PhoneticNameEditorView.java
index 420575c..1c6f6a1 100644
--- a/src/com/android/contacts/editor/PhoneticNameEditorView.java
+++ b/src/com/android/contacts/editor/PhoneticNameEditorView.java
@@ -17,9 +17,11 @@
 package com.android.contacts.editor;
 
 import android.content.Context;
+import android.content.res.Resources;
 import android.text.TextUtils;
 import android.util.AttributeSet;
 
+import com.android.contacts.R;
 import com.android.contacts.common.model.RawContactDelta;
 import com.android.contacts.common.model.ValuesDelta;
 import com.android.contacts.common.model.dataitem.DataKind;
@@ -102,6 +104,16 @@
     }
 
     @Override
+    protected void onFinishInflate() {
+        super.onFinishInflate();
+        final Resources res = getResources();
+        mCollapseButtonDescription = res
+                .getString(R.string.collapse_phonetic_name_fields_description);
+        mExpandButtonDescription = res
+                .getString(R.string.expand_phonetic_name_fields_description);
+    }
+
+    @Override
     public void setValues(DataKind kind, ValuesDelta entry, RawContactDelta state, boolean readOnly,
             ViewIdGenerator vig) {
         if (!(entry instanceof PhoneticValuesDelta)) {
diff --git a/src/com/android/contacts/editor/StructuredNameEditorView.java b/src/com/android/contacts/editor/StructuredNameEditorView.java
index 1a9c693..2fcc19d 100644
--- a/src/com/android/contacts/editor/StructuredNameEditorView.java
+++ b/src/com/android/contacts/editor/StructuredNameEditorView.java
@@ -16,9 +16,9 @@
 
 package com.android.contacts.editor;
 
-import com.android.contacts.R;
 import android.content.ContentValues;
 import android.content.Context;
+import android.content.res.Resources;
 import android.os.Parcel;
 import android.os.Parcelable;
 import android.provider.ContactsContract.CommonDataKinds.StructuredName;
@@ -29,13 +29,14 @@
 import android.widget.LinearLayout;
 import android.widget.TextView;
 
+import com.android.contacts.R;
 import com.android.contacts.common.model.RawContactDelta;
 import com.android.contacts.common.model.ValuesDelta;
 import com.android.contacts.common.model.account.AccountType;
 import com.android.contacts.common.model.dataitem.DataItem;
 import com.android.contacts.common.model.dataitem.DataKind;
-import com.android.contacts.common.util.NameConverter;
 import com.android.contacts.common.model.dataitem.StructuredNameDataItem;
+import com.android.contacts.common.util.NameConverter;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -68,6 +69,16 @@
     }
 
     @Override
+    protected void onFinishInflate() {
+        super.onFinishInflate();
+        final Resources res = getResources();
+        mCollapseButtonDescription = res
+                .getString(R.string.collapse_name_fields_description);
+        mExpandButtonDescription = res
+                .getString(R.string.expand_name_fields_description);
+    }
+
+    @Override
     public void setValues(DataKind kind, ValuesDelta entry, RawContactDelta state, boolean readOnly,
             ViewIdGenerator vig) {
         super.setValues(kind, entry, state, readOnly, vig);
diff --git a/src/com/android/contacts/editor/TextFieldsEditorView.java b/src/com/android/contacts/editor/TextFieldsEditorView.java
index 564a9f5..8bdbcd4 100644
--- a/src/com/android/contacts/editor/TextFieldsEditorView.java
+++ b/src/com/android/contacts/editor/TextFieldsEditorView.java
@@ -58,8 +58,12 @@
 
     private EditText[] mFieldEditTexts = null;
     private ViewGroup mFields = null;
-    private View mExpansionViewContainer;
-    private ImageView mExpansionView;
+    protected View mExpansionViewContainer;
+    protected ImageView mExpansionView;
+    protected String mCollapseButtonDescription;
+    protected String mExpandButtonDescription;
+    protected String mCollapsedAnnouncement;
+    protected String mExpandedAnnouncement;
     private boolean mHideOptional = true;
     private boolean mHasShortAndLongForms;
     private int mMinFieldHeight;
@@ -91,6 +95,15 @@
         mFields = (ViewGroup) findViewById(R.id.editors);
         mHintTextColorUnfocused = getResources().getColor(R.color.editor_disabled_text_color);
         mExpansionView = (ImageView) findViewById(R.id.expansion_view);
+        mCollapseButtonDescription = getResources()
+                .getString(R.string.collapse_fields_description);
+        mCollapsedAnnouncement = getResources()
+                .getString(R.string.announce_collapsed_fields);
+        mExpandButtonDescription = getResources()
+                .getString(R.string.expand_fields_description);
+        mExpandedAnnouncement = getResources()
+                .getString(R.string.announce_expanded_fields);
+
         mExpansionViewContainer = findViewById(R.id.expansion_view_container);
         if (mExpansionViewContainer != null) {
             mExpansionViewContainer.setOnClickListener(new OnClickListener() {
@@ -116,6 +129,8 @@
                     newFocusView.requestFocus();
 
                     EditorAnimator.getInstance().slideAndFadeIn(mFields, mPreviousViewHeight);
+                    announceForAccessibility(mHideOptional ?
+                            mCollapsedAnnouncement : mExpandedAnnouncement);
                 }
             });
         }
@@ -170,6 +185,8 @@
                 ? R.drawable.ic_menu_expand_minimized_24dp
                 : R.drawable.ic_menu_expand_maximized_24dp);
         mExpansionView.setImageDrawable(expandIcon);
+        mExpansionView.setContentDescription(collapsed ? mExpandButtonDescription
+                : mCollapseButtonDescription);
         mExpansionViewContainer.setVisibility(shouldExist ? View.VISIBLE : View.INVISIBLE);
     }
 
@@ -390,6 +407,7 @@
         for (int i = 0; i < numChildren; i++) {
             mFieldEditTexts[i].setVisibility(ss.mVisibilities[i]);
         }
+        rebuildValues();
     }
 
     private static class SavedState extends BaseSavedState {