Change VM playback fragment layout.

- Remove increase/decrease playback rate functionality.
- Flip button controls below the scrubber.
- Delete TextController.

Bug: 20433758
Change-Id: Id628bac0c9f8baed014079f2a89ce912fd2bb549
diff --git a/res/layout/playback_layout.xml b/res/layout/playback_layout.xml
index 00f1c3f..96feba6 100644
--- a/res/layout/playback_layout.xml
+++ b/res/layout/playback_layout.xml
@@ -19,15 +19,55 @@
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:orientation="vertical"
-    android:background="@color/background_dialer_call_log_list_item"
->
-    <!-- Mute, playback, trash buttons. -->
+    android:background="@color/background_dialer_call_log_list_item">
+
+    <RelativeLayout
+        android:id="@+id/seek_container"
+        android:layout_width="match_parent"
+        android:layout_height="80dp"
+        android:layout_marginTop="@dimen/call_detail_button_spacing">
+
+        <!-- SeekBar left-right margin decreased from redlines 72dp by 8dp to account for
+             half thumb width (thumb is 16dp).
+             Vertically, SeekBar and rate buttons should be below centre, position achieved by
+             making them centred but giving a difference between top and bottom padding,
+             difference is currently 10dp. -->
+        <SeekBar
+            android:id="@+id/playback_seek"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:progressDrawable="@drawable/seekbar_drawable"
+            android:thumb="@drawable/ic_voicemail_seek_handle"
+            android:thumbOffset="8dp"
+            android:progress="0"
+            android:paddingStart="8dp"
+            android:paddingEnd="8dp"
+            android:paddingTop="30dp"
+            android:paddingBottom="20dp"
+            android:layout_marginEnd="64dp"
+            android:layout_marginStart="64dp"
+            android:max="0"
+            android:layout_centerVertical="true"
+            android:contentDescription="@string/description_playback_seek" />
+
+        <TextView
+            android:id="@+id/playback_position_text"
+            android:layout_height="wrap_content"
+            android:layout_width="wrap_content"
+            android:textSize="14sp"
+            android:layout_alignParentTop="true"
+            android:layout_centerHorizontal="true"
+            android:layout_marginTop="10dp" />
+
+    </RelativeLayout>
+
+    <!-- Playback, speakerphone buttons. -->
     <LinearLayout
         android:id="@+id/buttons_linear_layout"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:orientation="horizontal"
-    >
+        android:orientation="horizontal">
+
         <ImageButton
             android:id="@+id/playback_start_stop"
             android:layout_width="match_parent"
@@ -36,93 +76,17 @@
             android:layout_weight="1"
             android:background="?android:attr/selectableItemBackground"
             android:src="@drawable/ic_hold_pause"
-            android:contentDescription="@string/voicemail_play_start_pause"
-        />
+            android:contentDescription="@string/voicemail_play_start_pause" />
+
         <ImageButton
             android:id="@+id/playback_speakerphone"
             android:layout_width="match_parent"
-            android:layout_height="58dip"
+            android:layout_height="58dp"
             android:layout_weight="1"
             android:background="?android:attr/selectableItemBackground"
             android:src="@drawable/ic_speakerphone_on"
-            android:contentDescription="@string/description_playback_speakerphone"
-        />
+            android:contentDescription="@string/description_playback_speakerphone" />
+
     </LinearLayout>
-    <RelativeLayout
-        android:id="@+id/seek_container"
-        android:layout_width="match_parent"
-        android:layout_height="80dip"
-        android:layout_marginTop="@dimen/call_detail_button_spacing"
-    >
-        <!-- SeekBar left-right margin decreased from redlines 72dip by 8dip to account for
-             half thumb width (thumb is 16dip).
-             Vertically, SeekBar and rate buttons should be below centre, position achieved by
-             making them centred but giving a difference between top and bottom padding,
-             difference is currently 10dip. -->
-        <SeekBar
-            android:id="@+id/playback_seek"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:progressDrawable="@drawable/seekbar_drawable"
-            android:thumb="@drawable/ic_voicemail_seek_handle"
-            android:thumbOffset="8dip"
-            android:progress="0"
-            android:paddingStart="8dip"
-            android:paddingEnd="8dip"
-            android:paddingTop="30dip"
-            android:paddingBottom="20dip"
-            android:layout_marginEnd="64dip"
-            android:layout_marginStart="64dip"
-            android:max="0"
-            android:layout_centerVertical="true"
-            android:contentDescription="@string/description_playback_seek"
-        />
-        <TextView
-            android:id="@+id/playback_position_text"
-            android:layout_height="wrap_content"
-            android:layout_width="wrap_content"
-            android:textSize="14sp"
-            android:layout_alignParentTop="true"
-            android:layout_centerHorizontal="true"
-            android:layout_marginTop="10dip"
-        />
-        <TextView
-            android:id="@+id/playback_speed_text"
-            android:layout_height="wrap_content"
-            android:layout_width="wrap_content"
-            android:textSize="14sp"
-            android:layout_alignParentTop="true"
-            android:layout_centerHorizontal="true"
-            android:layout_marginTop="10dip"
-            android:alpha="0"
-        />
-        <ImageButton
-            android:id="@+id/rate_decrease_button"
-            android:src="@drawable/ic_minus"
-            android:layout_width="64dip"
-            android:layout_height="wrap_content"
-            android:background="?android:attr/selectableItemBackground"
-            android:paddingBottom="19dip"
-            android:paddingTop="29dip"
-            android:layout_alignParentStart="true"
-            android:layout_centerVertical="true"
-            android:contentDescription="@string/voicemail_play_slower"
-        />
-        <ImageButton
-            android:id="@+id/rate_increase_button"
-            android:src="@drawable/ic_plus"
-            android:layout_width="64dip"
-            android:layout_height="wrap_content"
-            android:background="?android:attr/selectableItemBackground"
-            android:paddingBottom="19dip"
-            android:paddingTop="29dip"
-            android:layout_alignParentEnd="true"
-            android:layout_centerVertical="true"
-            android:contentDescription="@string/voicemail_play_faster"
-        />
-        <View
-            android:layout_width="match_parent"
-            android:layout_height="2dp"
-            android:layout_alignParentBottom="true"/>
-    </RelativeLayout>
+
 </LinearLayout>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 2e236a6..e3b2682 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -152,17 +152,6 @@
     server directly to listen to the voicemails. [CHAR LIMIT=20] -->
     <string name="voicemail_status_action_call_server">Call voicemail</string>
 
-    <!-- The slowest voicemail playback speed. [CHAR LIMIT=30] -->
-    <string name="voicemail_speed_slowest">Slowest speed</string>
-    <!-- Slower than normal voicemail playback speed. [CHAR LIMIT=30] -->
-    <string name="voicemail_speed_slower">Slow speed</string>
-    <!--  Normal voicemail playback speed. [CHAR LIMIT=30] -->
-    <string name="voicemail_speed_normal">Normal speed</string>
-    <!--  Faster than normal pvoicemail playback speed. [CHAR LIMIT=30] -->
-    <string name="voicemail_speed_faster">Fast speed</string>
-    <!--  Fastest voicemail playback speed. [CHAR LIMIT=30] -->
-    <string name="voicemail_speed_fastest">Fastest speed</string>
-
     <!-- The counter for calls in a group and the date of the latest call as shown in the call log [CHAR LIMIT=15] -->
     <string name="call_log_item_count_and_date">(<xliff:g id="count">%1$d</xliff:g>)
         <xliff:g id="date">%2$s</xliff:g>
diff --git a/src/com/android/dialer/voicemail/VoicemailPlaybackFragment.java b/src/com/android/dialer/voicemail/VoicemailPlaybackFragment.java
index fd98688..8aa0197 100644
--- a/src/com/android/dialer/voicemail/VoicemailPlaybackFragment.java
+++ b/src/com/android/dialer/voicemail/VoicemailPlaybackFragment.java
@@ -256,9 +256,7 @@
         private final SeekBar mPlaybackSeek;
         private final ImageButton mStartStopButton;
         private final ImageButton mPlaybackSpeakerphone;
-        private final ImageButton mRateDecreaseButton;
-        private final ImageButton mRateIncreaseButton;
-        private final TextViewWithMessagesController mTextController;
+        private final TextView mPlaybackPosition;
 
         public PlaybackViewImpl(ActivityReference activityReference, Context applicationContext,
                 View playbackLayout) {
@@ -272,13 +270,8 @@
                     R.id.playback_start_stop);
             mPlaybackSpeakerphone = (ImageButton) playbackLayout.findViewById(
                     R.id.playback_speakerphone);
-            mRateDecreaseButton = (ImageButton) playbackLayout.findViewById(
-                    R.id.rate_decrease_button);
-            mRateIncreaseButton = (ImageButton) playbackLayout.findViewById(
-                    R.id.rate_increase_button);
-            mTextController = new TextViewWithMessagesController(
-                    (TextView) playbackLayout.findViewById(R.id.playback_position_text),
-                    (TextView) playbackLayout.findViewById(R.id.playback_speed_text));
+            mPlaybackPosition =
+                    (TextView) playbackLayout.findViewById(R.id.playback_position_text);
         }
 
         @Override
@@ -303,16 +296,6 @@
         }
 
         @Override
-        public void setRateDecreaseButtonListener(View.OnClickListener listener) {
-            mRateDecreaseButton.setOnClickListener(listener);
-        }
-
-        @Override
-        public void setRateIncreaseButtonListener(View.OnClickListener listener) {
-            mRateIncreaseButton.setOnClickListener(listener);
-        }
-
-        @Override
         public void setStartStopListener(View.OnClickListener listener) {
             mStartStopButton.setOnClickListener(listener);
         }
@@ -323,12 +306,6 @@
         }
 
         @Override
-        public void setRateDisplay(float rate, int stringResourceId) {
-            mTextController.setTemporaryText(
-                    mApplicationContext.getString(stringResourceId), 1, TimeUnit.SECONDS);
-        }
-
-        @Override
         public void setPositionSeekListener(SeekBar.OnSeekBarChangeListener listener) {
             mPlaybackSeek.setOnSeekBarChangeListener(listener);
         }
@@ -379,8 +356,7 @@
                 mPlaybackSeek.setMax(seekBarMax);
             }
             mPlaybackSeek.setProgress(seekBarPosition);
-            mTextController.setPermanentText(
-                    formatAsMinutesAndSeconds(seekBarMax - seekBarPosition));
+            mPlaybackPosition.setText(formatAsMinutesAndSeconds(seekBarMax - seekBarPosition));
         }
 
         private String getString(int resId) {
@@ -390,19 +366,19 @@
         @Override
         public void setIsBuffering() {
             disableUiElements();
-            mTextController.setPermanentText(getString(R.string.voicemail_buffering));
+            mPlaybackPosition.setText(getString(R.string.voicemail_buffering));
         }
 
         @Override
         public void setIsFetchingContent() {
             disableUiElements();
-            mTextController.setPermanentText(getString(R.string.voicemail_fetching_content));
+            mPlaybackPosition.setText(getString(R.string.voicemail_fetching_content));
         }
 
         @Override
         public void setFetchContentTimeout() {
             disableUiElements();
-            mTextController.setPermanentText(getString(R.string.voicemail_fetching_timout));
+            mPlaybackPosition.setText(getString(R.string.voicemail_fetching_timout));
         }
 
         @Override
@@ -412,8 +388,6 @@
 
         @Override
         public void disableUiElements() {
-            mRateIncreaseButton.setEnabled(false);
-            mRateDecreaseButton.setEnabled(false);
             mStartStopButton.setEnabled(false);
             mPlaybackSpeakerphone.setEnabled(false);
             mPlaybackSeek.setProgress(0);
@@ -423,14 +397,12 @@
         @Override
         public void playbackError(Exception e) {
             disableUiElements();
-            mTextController.setPermanentText(getString(R.string.voicemail_playback_error));
+            mPlaybackPosition.setText(getString(R.string.voicemail_playback_error));
             Log.e(TAG, "Could not play voicemail", e);
         }
 
         @Override
         public void enableUiElements() {
-            mRateIncreaseButton.setEnabled(true);
-            mRateDecreaseButton.setEnabled(true);
             mStartStopButton.setEnabled(true);
             mPlaybackSpeakerphone.setEnabled(true);
             mPlaybackSeek.setEnabled(true);
@@ -491,64 +463,4 @@
             }
         }
     }
-
-    /**
-     * Controls a TextView with dynamically changing text.
-     * <p>
-     * There are two methods here of interest,
-     * {@link TextViewWithMessagesController#setPermanentText(String)} and
-     * {@link TextViewWithMessagesController#setTemporaryText(String, long, TimeUnit)}.  The
-     * former is used to set the text on the text view immediately, and is used in our case for
-     * the countdown of duration remaining during voicemail playback.  The second is used to
-     * temporarily replace this countdown with a message, in our case faster voicemail speed or
-     * slower voicemail speed, before returning to the countdown display.
-     * <p>
-     * All the methods on this class must be called from the ui thread.
-     */
-    private static final class TextViewWithMessagesController {
-        private static final float VISIBLE = 1;
-        private static final float INVISIBLE = 0;
-        private static final long SHORT_ANIMATION_MS = 200;
-        private static final long LONG_ANIMATION_MS = 400;
-        private final Object mLock = new Object();
-        private final TextView mPermanentTextView;
-        private final TextView mTemporaryTextView;
-        @GuardedBy("mLock") private Runnable mRunnable;
-
-        public TextViewWithMessagesController(TextView permanentTextView,
-                TextView temporaryTextView) {
-            mPermanentTextView = permanentTextView;
-            mTemporaryTextView = temporaryTextView;
-        }
-
-        public void setPermanentText(String text) {
-            mPermanentTextView.setText(text);
-        }
-
-        public void setTemporaryText(String text, long duration, TimeUnit units) {
-            synchronized (mLock) {
-                mTemporaryTextView.setText(text);
-                mTemporaryTextView.animate().alpha(VISIBLE).setDuration(SHORT_ANIMATION_MS);
-                mPermanentTextView.animate().alpha(INVISIBLE).setDuration(SHORT_ANIMATION_MS);
-                mRunnable = new Runnable() {
-                    @Override
-                    public void run() {
-                        synchronized (mLock) {
-                            // We check for (mRunnable == this) becuase if not true, then another
-                            // setTemporaryText call has taken place in the meantime, and this
-                            // one is now defunct and needs to take no action.
-                            if (mRunnable == this) {
-                                mRunnable = null;
-                                mTemporaryTextView.animate()
-                                        .alpha(INVISIBLE).setDuration(LONG_ANIMATION_MS);
-                                mPermanentTextView.animate()
-                                        .alpha(VISIBLE).setDuration(LONG_ANIMATION_MS);
-                            }
-                        }
-                    }
-                };
-                mTemporaryTextView.postDelayed(mRunnable, units.toMillis(duration));
-            }
-        }
-    }
 }
diff --git a/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java b/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java
index 6a10411..029f5bd 100644
--- a/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java
+++ b/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java
@@ -80,9 +80,6 @@
         boolean isSpeakerPhoneOn();
         void setSpeakerPhoneOn(boolean on);
         void finish();
-        void setRateDisplay(float rate, int stringResourceId);
-        void setRateIncreaseButtonListener(View.OnClickListener listener);
-        void setRateDecreaseButtonListener(View.OnClickListener listener);
         void setIsFetchingContent();
         void disableUiElements();
         void enableUiElements();
@@ -121,28 +118,6 @@
     private static final String CLIP_POSITION_KEY = VoicemailPlaybackPresenter.class.getName()
             + ".CLIP_POSITION_KEY";
 
-    /** The preset variable-speed rates.  Each is greater than the previous by 25%. */
-    private static final float[] PRESET_RATES = new float[] {
-        0.64f, 0.8f, 1.0f, 1.25f, 1.5625f
-    };
-    /** The string resource ids corresponding to the names given to the above preset rates. */
-    private static final int[] PRESET_NAMES = new int[] {
-        R.string.voicemail_speed_slowest,
-        R.string.voicemail_speed_slower,
-        R.string.voicemail_speed_normal,
-        R.string.voicemail_speed_faster,
-        R.string.voicemail_speed_fastest,
-    };
-
-    /**
-     * Pointer into the {@link VoicemailPlaybackPresenter#PRESET_RATES} array.
-     * <p>
-     * This doesn't need to be synchronized, it's used only by the {@link RateChangeListener}
-     * which in turn is only executed on the ui thread.  This can't be encapsulated inside the
-     * rate change listener since multiple rate change listeners must share the same value.
-     */
-    private int mRateIndex = 2;
-
     /**
      * The most recently calculated duration.
      * <p>
@@ -349,8 +324,6 @@
         mPlayer.setOnErrorListener(new MediaPlayerErrorListener());
         mPlayer.setOnCompletionListener(new MediaPlayerCompletionListener());
         mView.setSpeakerPhoneOn(mView.isSpeakerPhoneOn());
-        mView.setRateDecreaseButtonListener(createRateDecreaseListener());
-        mView.setRateIncreaseButtonListener(createRateIncreaseListener());
         if (mPlaying) {
            resetPrepareStartPlaying(mPosition);
         } else {
@@ -422,37 +395,6 @@
         }
     }
 
-    public View.OnClickListener createRateDecreaseListener() {
-        return new RateChangeListener(false);
-    }
-
-    public View.OnClickListener createRateIncreaseListener() {
-        return new RateChangeListener(true);
-    }
-
-    /**
-     * Listens to clicks on the rate increase and decrease buttons.
-     * <p>
-     * This class is not thread-safe, but all interactions with it will happen on the ui thread.
-     */
-    private class RateChangeListener implements View.OnClickListener {
-        private final boolean mIncrease;
-
-        public RateChangeListener(boolean increase) {
-            mIncrease = increase;
-        }
-
-        @Override
-        public void onClick(View v) {
-            // Adjust the current rate, then clamp it to the allowed values.
-            mRateIndex = constrain(mRateIndex + (mIncrease ? 1 : -1), 0, PRESET_RATES.length - 1);
-            // Whether or not we have actually changed the index, call changeRate().
-            // This will ensure that we show the "fastest" or "slowest" text on the ui to indicate
-            // to the user that it doesn't get any faster or slower.
-            changeRate(PRESET_RATES[mRateIndex], PRESET_NAMES[mRateIndex]);
-        }
-    }
-
     private class AsyncPrepareTask extends AsyncTask<Void, Void, Exception> {
         private int mClipPositionInMillis;
 
@@ -607,11 +549,6 @@
         }
     }
 
-    private void changeRate(float rate, int stringResourceId) {
-        ((SingleThreadedMediaPlayerProxy) mPlayer).setVariableSpeed(rate);
-        mView.setRateDisplay(rate, stringResourceId);
-    }
-
     private class SpeakerphoneListener implements View.OnClickListener {
         @Override
         public void onClick(View v) {
diff --git a/tests/src/com/android/dialer/CallDetailActivityTest.java b/tests/src/com/android/dialer/CallDetailActivityTest.java
index f9f0a58..15e90fc 100644
--- a/tests/src/com/android/dialer/CallDetailActivityTest.java
+++ b/tests/src/com/android/dialer/CallDetailActivityTest.java
@@ -155,7 +155,6 @@
         setActivityIntentForTestVoicemailEntry();
         startActivityUnderTest();
         mTestUtils.clickButton(mActivityUnderTest, R.id.playback_start_stop);
-        mTestUtils.clickButton(mActivityUnderTest, R.id.rate_increase_button);
     }
 
     /** Test for bug where missing Extras on intent used to start Activity causes NPE. */
@@ -188,30 +187,6 @@
         assertTrue(menu.findItem(R.id.menu_remove_from_call_log).isVisible());
     }
 
-    /**
-     * Test to show that we are correctly displaying playback rate on the ui.
-     * <p>
-     * See bug http://b/5044075.
-     */
-    @Suppress
-    public void testVoicemailPlaybackRateDisplayedOnUi() throws Throwable {
-        setActivityIntentForTestVoicemailEntry();
-        startActivityUnderTest();
-        // Find the TextView containing the duration.  It should be initially displaying "00:00".
-        List<TextView> views = mTestUtils.getTextViewsWithString(mActivityUnderTest, "00:00");
-        assertEquals(1, views.size());
-        TextView timeDisplay = views.get(0);
-        // Hit the plus button.  At this point we should be displaying "fast speed".
-        mTestUtils.clickButton(mActivityUnderTest, R.id.rate_increase_button);
-        assertEquals("fast speed", mTestUtils.getText(timeDisplay));
-        // Hit the minus button.  We should be back to "normal" speed.
-        mTestUtils.clickButton(mActivityUnderTest, R.id.rate_decrease_button);
-        assertEquals("normal speed", mTestUtils.getText(timeDisplay));
-        // Wait for one and a half seconds.  The timer will be back.
-        Thread.sleep(1500);
-        assertEquals("00:00", mTestUtils.getText(timeDisplay));
-    }
-
     @Suppress
     public void testClickingCallStopsPlayback() throws Throwable {
         setActivityIntentForRealFileVoicemailEntry();