diff options
author | Chad Jones <chadj@google.com> | 2015-09-10 07:20:59 +0000 |
---|---|---|
committer | Chad Jones <chadj@google.com> | 2015-09-10 07:20:59 +0000 |
commit | 879f6b944c3106072579b748e54f9d780c3ebe63 (patch) | |
tree | 94c84304342051eab6ae82281f4beb9ca3f2fc02 | |
parent | 499902cca2562db728671a74044ffc2f70a7c39d (diff) |
Revert "Improve speakerphone setting."
This reverts commit 499902cca2562db728671a74044ffc2f70a7c39d.
Change-Id: I9f6321f0d745aadd47085dde09db8dfc8d21af19
3 files changed, 41 insertions, 41 deletions
diff --git a/res/layout/voicemail_playback_layout.xml b/res/layout/voicemail_playback_layout.xml index 54493f17d..555d20142 100644 --- a/res/layout/voicemail_playback_layout.xml +++ b/res/layout/voicemail_playback_layout.xml @@ -71,7 +71,7 @@ <ImageButton android:id="@+id/playback_speakerphone" style="@style/VoicemailPlaybackLayoutButtonStyle" - android:src="@drawable/ic_volume_down_24dp" + android:src="@drawable/ic_speakerphone_on" android:tint="@color/voicemail_icon_tint" android:contentDescription="@string/description_playback_speakerphone" /> diff --git a/src/com/android/dialer/voicemail/VoicemailPlaybackLayout.java b/src/com/android/dialer/voicemail/VoicemailPlaybackLayout.java index 133da363d..69c075f80 100644 --- a/src/com/android/dialer/voicemail/VoicemailPlaybackLayout.java +++ b/src/com/android/dialer/voicemail/VoicemailPlaybackLayout.java @@ -159,7 +159,7 @@ public class VoicemailPlaybackLayout extends LinearLayout @Override public void onClick(View v) { if (mPresenter != null) { - mPresenter.toggleSpeakerphone(); + onSpeakerphoneOn(!mPresenter.isSpeakerphoneOn()); } } }; @@ -286,6 +286,10 @@ public class VoicemailPlaybackLayout extends LinearLayout mStartStopButton.setImageResource(R.drawable.ic_pause); + if (mPresenter != null) { + onSpeakerphoneOn(mPresenter.isSpeakerphoneOn()); + } + if (mPositionUpdater != null) { mPositionUpdater.stopUpdating(); mPositionUpdater = null; @@ -317,6 +321,10 @@ public class VoicemailPlaybackLayout extends LinearLayout } public void onSpeakerphoneOn(boolean on) { + if (mPresenter != null) { + mPresenter.setSpeakerphoneOn(on); + } + if (on) { mPlaybackSpeakerphone.setImageResource(R.drawable.ic_volume_up_24dp); // Speaker is now on, tapping button will turn it off. @@ -365,6 +373,7 @@ public class VoicemailPlaybackLayout extends LinearLayout @Override public void disableUiElements() { mStartStopButton.setEnabled(false); + mPlaybackSpeakerphone.setEnabled(false); mPlaybackSeek.setProgress(0); mPlaybackSeek.setEnabled(false); @@ -375,6 +384,7 @@ public class VoicemailPlaybackLayout extends LinearLayout @Override public void enableUiElements() { mStartStopButton.setEnabled(true); + mPlaybackSpeakerphone.setEnabled(true); mPlaybackSeek.setEnabled(true); mPositionText.setVisibility(View.VISIBLE); diff --git a/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java b/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java index 1a9c23952..3f5a489ce 100644 --- a/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java +++ b/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java @@ -60,7 +60,7 @@ import javax.annotation.concurrent.ThreadSafe; * {@link CallLogFragment} and {@link CallLogAdapter}. * <p> * This controls a single {@link com.android.dialer.voicemail.VoicemailPlaybackLayout}. A single - * instance can be reused for different such layouts, using {@link #setPlaybackView}. This + * instance can be reused for different such layouts, using {@link #setVoicemailPlaybackView}. This * is to facilitate reuse across different voicemail call log entries. * <p> * This class is not thread safe. The thread policy for this class is thread-confinement, all calls @@ -120,8 +120,6 @@ public class VoicemailPlaybackPresenter // If present in the saved instance bundle, indicates where to set the playback slider. private static final String CLIP_POSITION_KEY = VoicemailPlaybackPresenter.class.getName() + ".CLIP_POSITION_KEY"; - private static final String IS_SPEAKERPHONE_ON_KEY = - VoicemailPlaybackPresenter.class.getName() + ".IS_SPEAKER_PHONE_ON"; /** * The most recently cached duration. We cache this since we don't want to keep requesting it @@ -143,7 +141,6 @@ public class VoicemailPlaybackPresenter // MediaPlayer crashes on some method calls if not prepared but does not have a method which // exposes its prepared state. Store this locally, so we can check and prevent crashes. private boolean mIsPrepared; - private boolean mIsSpeakerphoneOn; private boolean mShouldResumePlaybackAfterSeeking; private int mInitialOrientation; @@ -214,7 +211,6 @@ public class VoicemailPlaybackPresenter mIsPrepared = savedInstanceState.getBoolean(IS_PREPARED_KEY); mPosition = savedInstanceState.getInt(CLIP_POSITION_KEY, 0); mIsPlaying = savedInstanceState.getBoolean(IS_PLAYING_STATE_KEY, false); - mIsSpeakerphoneOn = savedInstanceState.getBoolean(IS_SPEAKERPHONE_ON_KEY, false); } if (mMediaPlayer == null) { @@ -232,7 +228,6 @@ public class VoicemailPlaybackPresenter outState.putBoolean(IS_PREPARED_KEY, mIsPrepared); outState.putInt(CLIP_POSITION_KEY, mView.getDesiredClipPosition()); outState.putBoolean(IS_PLAYING_STATE_KEY, mIsPlaying); - outState.putBoolean(IS_SPEAKERPHONE_ON_KEY, mIsSpeakerphoneOn); } } @@ -244,21 +239,16 @@ public class VoicemailPlaybackPresenter mView = view; mView.setPresenter(this, voicemailUri); - // Handles cases where the same entry is binded again when scrolling in list, or where - // the MediaPlayer was retained after an orientation change. if (mMediaPlayer != null && mIsPrepared && voicemailUri.equals(mVoicemailUri)) { + // Handles case where MediaPlayer was retained after an orientation change. onPrepared(mMediaPlayer); + mView.onSpeakerphoneOn(isSpeakerphoneOn()); } else { if (!voicemailUri.equals(mVoicemailUri)) { - mVoicemailUri = voicemailUri; mPosition = 0; - // Default to earpiece. - setSpeakerphoneOn(false); - } else { - // Update the view to the current speakerphone state. - mView.onSpeakerphoneOn(mIsSpeakerphoneOn); } + mVoicemailUri = voicemailUri; mDuration.set(0); if (startPlayingImmediately) { @@ -268,6 +258,9 @@ public class VoicemailPlaybackPresenter mIsPlaying = startPlayingImmediately; checkForContent(); } + + // Default to earpiece. + mView.onSpeakerphoneOn(false); } } @@ -602,6 +595,7 @@ public class VoicemailPlaybackPresenter // If we haven't downloaded the voicemail yet, attempt to download it. checkForContent(); mIsPlaying = true; + return; } @@ -622,7 +616,6 @@ public class VoicemailPlaybackPresenter throw new RejectedExecutionException("Could not capture audio focus."); } - setSpeakerphoneOn(mIsSpeakerphoneOn); // Can throw RejectedExecutionException. mMediaPlayer.start(); } catch (RejectedExecutionException e) { @@ -632,6 +625,11 @@ public class VoicemailPlaybackPresenter Log.d(TAG, "Resumed playback at " + mPosition + "."); mView.onPlaybackStarted(mDuration.get(), getScheduledExecutorServiceInstance()); + if (isSpeakerphoneOn()) { + mActivity.getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON); + } else { + enableProximitySensor(); + } } /** @@ -683,7 +681,7 @@ public class VoicemailPlaybackPresenter } private void enableProximitySensor() { - if (mProximityWakeLock == null || mIsSpeakerphoneOn || !mIsPrepared + if (mProximityWakeLock == null || isSpeakerphoneOn() || !mIsPrepared || mMediaPlayer == null || !mMediaPlayer.isPlaying()) { return; } @@ -709,34 +707,26 @@ public class VoicemailPlaybackPresenter } } - public void toggleSpeakerphone() { - setSpeakerphoneOn(!mIsSpeakerphoneOn); - } - - private void setSpeakerphoneOn(boolean on) { - mView.onSpeakerphoneOn(on); - if (mIsSpeakerphoneOn == on) { - return; - } - - mIsSpeakerphoneOn = on; - mAudioManager.setSpeakerphoneOn(mIsSpeakerphoneOn); + public void setSpeakerphoneOn(boolean on) { + mAudioManager.setSpeakerphoneOn(on); - if (mIsPlaying) { - if (on) { - disableProximitySensor(false /* waitForFarState */); - if (mIsPrepared && mMediaPlayer != null && mMediaPlayer.isPlaying()) { - mActivity.getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON); - } - } else { - enableProximitySensor(); - if (mActivity != null) { - mActivity.getWindow().clearFlags(LayoutParams.FLAG_KEEP_SCREEN_ON); - } + if (on) { + disableProximitySensor(false /* waitForFarState */); + if (mIsPrepared && mMediaPlayer != null && mMediaPlayer.isPlaying()) { + mActivity.getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON); + } + } else { + enableProximitySensor(); + if (mActivity != null) { + mActivity.getWindow().clearFlags(LayoutParams.FLAG_KEEP_SCREEN_ON); } } } + public boolean isSpeakerphoneOn() { + return mAudioManager.isSpeakerphoneOn(); + } + public void setOnVoicemailDeletedListener(OnVoicemailDeletedListener listener) { mOnVoicemailDeletedListener = listener; } |