Stub out extrabutton row. do not submit
Daisuke Miyakawa [Wed, 29 Feb 2012 18:17:35 +0000 (10:17 -0800)]
This change stop inflating 7 Views, so will improve CPU/memory usage,
a bit.

TESTED:
- usual phone calls
- conference calls (GSM)
- multiple calls (CDMA)

Bug: 1271870
Bug: 6005703
Change-Id: Ic4b27b13bca244f25a89c932561bc7771a58027e

res/layout/extra_button_row.xml [new file with mode: 0644]
res/layout/incall_touch_ui.xml
src/com/android/phone/InCallTouchUi.java

diff --git a/res/layout/extra_button_row.xml b/res/layout/extra_button_row.xml
new file mode 100644 (file)
index 0000000..fb6da6a
--- /dev/null
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 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="match_parent"
+    android:layout_height="wrap_content"
+    android:background="@drawable/dialpad_background_opaque">
+    <!-- The buttons here have a text label floating off to the side
+         (which is necessary because these buttons are used only in
+         a few rare states, and the meaning of the icon might not be
+         obvious.)  The entire row (button + text) is clickable. -->
+
+    <!-- "Manage conference" -->
+    <!-- This button is used only on GSM devices, during a conference call. -->
+    <LinearLayout android:id="@+id/manageConferenceButton"
+        android:orientation="horizontal"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:background="?android:attr/selectableItemBackground">
+        <!-- The entire LinearLayout here is clickable, so we don't
+             care about clicks on the ImageButton itself. -->
+        <ImageButton android:id="@+id/manageConferenceButtonImage"
+            android:clickable="false"
+            style="@style/InCallButton"
+            android:src="@drawable/ic_groups_holo_dark"
+            android:contentDescription="@string/onscreenManageConferenceText" />
+        <TextView android:id="@+id/manageConferenceButtonLabel"
+            style="@style/InCallExtraRowButtonLabel"
+            android:text="@string/onscreenManageConferenceText" />
+    </LinearLayout>
+
+    <!-- CDMA-specific "Merge" -->
+    <!-- This button is used only on CDMA devices, where we can't use
+         the Merge button in the main button row (because the "Add Call"
+         button might need to be enabled at the same time.) -->
+    <LinearLayout android:id="@+id/cdmaMergeButton"
+        android:orientation="horizontal"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:background="?android:attr/selectableItemBackground">
+        <!-- The entire LinearLayout here is clickable, so we don't
+             care about clicks on the ImageButton itself. -->
+        <ImageButton android:id="@+id/cdmaMergeButtonImage"
+            android:clickable="false"
+            style="@style/InCallButton"
+            android:src="@drawable/ic_merge_holo_dark"
+            android:contentDescription="@string/onscreenMergeCallsText" />
+        <TextView android:id="@+id/cdmaMergeButtonLabel"
+            style="@style/InCallExtraRowButtonLabel"
+            android:text="@string/onscreenMergeCallsText" />
+    </LinearLayout>
+
+</FrameLayout>
index 9421c3f..850876c 100644 (file)
                       android:orientation="vertical"
                       android:layout_width="match_parent"
                       android:layout_height="wrap_content"
-                      android:layout_alignParentBottom="true"
-                      >
+                      android:layout_alignParentBottom="true">
 
             <!-- Row 1, the "extra button row": A couple of relatively rare
                  buttons used only in certain call states.
                  Most of the time this whole row is GONE.
                  For now, at least, there's only ever one button visible here
                  at a time, so this can be a simple FrameLayout. -->
-            <FrameLayout android:id="@+id/extraButtonRow"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:background="@drawable/dialpad_background_opaque"
-                android:paddingLeft="@dimen/button_cluster_side_padding"
-                android:paddingRight="@dimen/button_cluster_side_padding"
-                >
-                <!-- The buttons here have a text label floating off to the side
-                     (which is necessary because these buttons are used only in
-                     a few rare states, and the meaning of the icon might not be
-                     obvious.)  The entire row (button + text) is clickable. -->
-
-                <!-- "Manage conference" -->
-                <!-- This button is used only on GSM devices, during a conference call. -->
-                <LinearLayout android:id="@+id/manageConferenceButton"
-                    android:orientation="horizontal"
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
-                    android:background="?android:attr/selectableItemBackground"
-                    >
-                    <!-- The entire LinearLayout here is clickable, so we don't
-                         care about clicks on the ImageButton itself. -->
-                    <ImageButton android:id="@+id/manageConferenceButtonImage"
-                        android:clickable="false"
-                        style="@style/InCallButton"
-                        android:src="@drawable/ic_groups_holo_dark"
-                        android:contentDescription="@string/onscreenManageConferenceText"
-                        />
-                    <TextView android:id="@+id/manageConferenceButtonLabel"
-                        style="@style/InCallExtraRowButtonLabel"
-                        android:text="@string/onscreenManageConferenceText"
-                        />
-                </LinearLayout>
-
-                <!-- CDMA-specific "Merge" -->
-                <!-- This button is used only on CDMA devices, where we can't use
-                     the Merge button in the main button row (because the "Add Call"
-                     button might need to be enabled at the same time.) -->
-                <LinearLayout android:id="@+id/cdmaMergeButton"
-                    android:orientation="horizontal"
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
-                    android:background="?android:attr/selectableItemBackground"
-                    >
-                    <!-- The entire LinearLayout here is clickable, so we don't
-                         care about clicks on the ImageButton itself. -->
-                    <ImageButton android:id="@+id/cdmaMergeButtonImage"
-                        android:clickable="false"
-                        style="@style/InCallButton"
-                        android:src="@drawable/ic_merge_holo_dark"
-                        android:contentDescription="@string/onscreenMergeCallsText"
-                        />
-                    <TextView android:id="@+id/cdmaMergeButtonLabel"
-                        style="@style/InCallExtraRowButtonLabel"
-                        android:text="@string/onscreenMergeCallsText"
-                        />
-                </LinearLayout>
-
-            </FrameLayout>
-
+            <ViewStub android:id="@+id/extraButtonRow"
+                      android:layout="@layout/extra_button_row"
+                      android:layout_width="match_parent"
+                      android:layout_height="wrap_content"
+                      android:paddingLeft="@dimen/button_cluster_side_padding"
+                      android:paddingRight="@dimen/button_cluster_side_padding" />
 
             <!-- Row 2: The "End call" button. -->
             <ImageButton android:id="@+id/endButton"
index c179eaa..7598f53 100644 (file)
@@ -30,6 +30,7 @@ import android.view.MenuItem;
 import android.view.MotionEvent;
 import android.view.View;
 import android.view.ViewGroup;
+import android.view.ViewStub;
 import android.view.animation.AlphaAnimation;
 import android.view.animation.Animation;
 import android.view.animation.Animation.AnimationListener;
@@ -90,8 +91,9 @@ public class InCallTouchUi extends FrameLayout
     private CompoundButton mHoldButton;
     private ImageButton mSwapButton;
     private View mHoldSwapSpacer;
-    //
-    private ViewGroup mExtraButtonRow;
+
+    // "Extra button row"
+    private ViewStub mExtraButtonRow;
     private ViewGroup mCdmaMergeButton;
     private ViewGroup mManageConferenceButton;
     private ImageButton mManageConferenceButtonImage;
@@ -197,18 +199,7 @@ public class InCallTouchUi extends FrameLayout
         // button in CDMA.
 
         // Buttons shown on the "extra button row", only visible in certain (rare) states.
-        mExtraButtonRow = (ViewGroup) mInCallControls.findViewById(R.id.extraButtonRow);
-        // The two "buttons" here (mCdmaMergeButton and mManageConferenceButton)
-        // are actually layouts containing an icon and a text label side-by-side.
-        mCdmaMergeButton =
-                (ViewGroup) mInCallControls.findViewById(R.id.cdmaMergeButton);
-        mCdmaMergeButton.setOnClickListener(this);
-        //
-        mManageConferenceButton =
-                (ViewGroup) mInCallControls.findViewById(R.id.manageConferenceButton);
-        mManageConferenceButton.setOnClickListener(this);
-        mManageConferenceButtonImage =
-                (ImageButton) mInCallControls.findViewById(R.id.manageConferenceButtonImage);
+        mExtraButtonRow = (ViewStub) mInCallControls.findViewById(R.id.extraButtonRow);
 
         // Add a custom OnTouchListener to manually shrink the "hit
         // target" of some buttons.
@@ -455,10 +446,6 @@ public class InCallTouchUi extends FrameLayout
         // state of the various onscreen buttons:
         InCallControlState inCallControlState = mInCallScreen.getUpdatedInCallControlState();
 
-        // The "extra button row" will be visible only if any of its
-        // buttons need to be visible.
-        boolean showExtraButtonRow = false;
-
         if (DBG) {
             log("updateInCallControls()...");
             inCallControlState.dumpState();
@@ -577,17 +564,6 @@ public class InCallTouchUi extends FrameLayout
             Log.w(LOG_TAG, "updateInCallControls: Hold *and* Swap enabled, but can't show both!");
         }
 
-        // CDMA-specific "Merge" button.
-        // This button and its label are totally hidden (rather than just disabled)
-        // when the operation isn't available.
-        boolean showCdmaMerge =
-                (phoneType == Phone.PHONE_TYPE_CDMA) && inCallControlState.canMerge;
-        if (showCdmaMerge) {
-            mCdmaMergeButton.setVisibility(View.VISIBLE);
-            showExtraButtonRow = true;
-        } else {
-            mCdmaMergeButton.setVisibility(View.GONE);
-        }
         if (phoneType == Phone.PHONE_TYPE_CDMA) {
             if (inCallControlState.canSwap && inCallControlState.canMerge) {
                 // Uh oh, the InCallControlState thinks that Swap *and* Merge
@@ -600,21 +576,37 @@ public class InCallTouchUi extends FrameLayout
             }
         }
 
-        // "Manage conference" (used only on GSM devices)
-        // This button and its label are shown or hidden together.
-        if (inCallControlState.manageConferenceVisible) {
-            mManageConferenceButton.setVisibility(View.VISIBLE);
-            showExtraButtonRow = true;
-            mManageConferenceButtonImage.setEnabled(inCallControlState.manageConferenceEnabled);
-        } else {
-            mManageConferenceButton.setVisibility(View.GONE);
-        }
-
         // Finally, update the "extra button row": It's displayed above the
         // "End" button, but only if necessary.  Also, it's never displayed
         // while the dialpad is visible (since it would overlap.)
+        //
+        // The row contains two buttons:
+        //
+        // - "Manage conference" (used only on GSM devices)
+        // - "Merge" button (used only on CDMA devices)
+        //
+        // Note that mExtraButtonRow is ViewStub, which will be inflated for the first time when
+        // any of its buttons becomes visible.
+        final boolean showCdmaMerge =
+                (phoneType == Phone.PHONE_TYPE_CDMA) && inCallControlState.canMerge;
+        final boolean showExtraButtonRow =
+                showCdmaMerge || inCallControlState.manageConferenceVisible;
         if (showExtraButtonRow && !inCallControlState.dialpadVisible) {
+            // This will require the ViewStub inflate itself.
             mExtraButtonRow.setVisibility(View.VISIBLE);
+
+            // Need to set up mCdmaMergeButton and mManageConferenceButton if this is the first
+            // time they're visible.
+            if (mCdmaMergeButton == null) {
+                setupExtraButtons();
+            }
+            mCdmaMergeButton.setVisibility(showCdmaMerge ? View.VISIBLE : View.GONE);
+            if (inCallControlState.manageConferenceVisible) {
+                mManageConferenceButton.setVisibility(View.VISIBLE);
+                mManageConferenceButtonImage.setEnabled(inCallControlState.manageConferenceEnabled);
+            } else {
+                mManageConferenceButton.setVisibility(View.GONE);
+            }
         } else {
             mExtraButtonRow.setVisibility(View.GONE);
         }
@@ -625,6 +617,26 @@ public class InCallTouchUi extends FrameLayout
         }
     }
 
+    /**
+     * Set up the buttons that are part of the "extra button row"
+     */
+    private void setupExtraButtons() {
+        // The two "buttons" here (mCdmaMergeButton and mManageConferenceButton)
+        // are actually layouts containing an icon and a text label side-by-side.
+        mCdmaMergeButton = (ViewGroup) mInCallControls.findViewById(R.id.cdmaMergeButton);
+        if (mCdmaMergeButton == null) {
+            Log.wtf(LOG_TAG, "CDMA Merge button is null even after ViewStub being inflated.");
+            return;
+        }
+        mCdmaMergeButton.setOnClickListener(this);
+
+        mManageConferenceButton =
+                (ViewGroup) mInCallControls.findViewById(R.id.manageConferenceButton);
+        mManageConferenceButton.setOnClickListener(this);
+        mManageConferenceButtonImage =
+                (ImageButton) mInCallControls.findViewById(R.id.manageConferenceButtonImage);
+    }
+
     private void dumpBottomButtonState() {
         log(" - dialpad: " + getButtonState(mDialpadButton));
         log(" - speaker: " + getButtonState(mAudioButton));
@@ -639,6 +651,9 @@ public class InCallTouchUi extends FrameLayout
     }
 
     private static String getButtonState(View view) {
+        if (view == null) {
+            return "(null)";
+        }
         StringBuilder builder = new StringBuilder();
         builder.append("visibility: " + (view.getVisibility() == View.VISIBLE ? "VISIBLE"
                 : view.getVisibility() == View.INVISIBLE ? "INVISIBLE" : "GONE"));