diff options
author | Nancy Chen <nancychen@google.com> | 2015-09-18 01:30:34 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-09-18 01:30:34 +0000 |
commit | 5a1f189507603f7515b04fb798dd5d4d246a61a1 (patch) | |
tree | a028214377be7aaa925c6d41ed6ea443507f894c /src | |
parent | c42c814ab6349b7e4b28847c4ec4e3e51e7655d0 (diff) | |
parent | 5ded83c610eeda06a8ea5f06f306d89009ed5b4c (diff) |
Merge "Resume voicemail playback at previous position on resume." into ub-contactsdialer-a-dev
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/dialer/voicemail/VoicemailPlaybackLayout.java | 19 | ||||
-rw-r--r-- | src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java | 33 |
2 files changed, 39 insertions, 13 deletions
diff --git a/src/com/android/dialer/voicemail/VoicemailPlaybackLayout.java b/src/com/android/dialer/voicemail/VoicemailPlaybackLayout.java index 440d92134..f86fc5539 100644 --- a/src/com/android/dialer/voicemail/VoicemailPlaybackLayout.java +++ b/src/com/android/dialer/voicemail/VoicemailPlaybackLayout.java @@ -19,6 +19,7 @@ package com.android.dialer.voicemail; import android.app.Activity; import android.app.Fragment; import android.content.Context; +import android.graphics.drawable.Drawable; import android.media.MediaPlayer; import android.net.Uri; import android.os.Bundle; @@ -238,6 +239,8 @@ public class VoicemailPlaybackLayout extends LinearLayout private TextView mTotalDurationText; private PositionUpdater mPositionUpdater; + private Drawable mVoicemailSeekHandleEnabled; + private Drawable mVoicemailSeekHandleDisabled; public VoicemailPlaybackLayout(Context context) { this(context, null); @@ -277,6 +280,11 @@ public class VoicemailPlaybackLayout extends LinearLayout mPositionText.setText(formatAsMinutesAndSeconds(0)); mTotalDurationText.setText(formatAsMinutesAndSeconds(0)); + + mVoicemailSeekHandleEnabled = getResources().getDrawable( + R.drawable.ic_voicemail_seek_handle, mContext.getTheme()); + mVoicemailSeekHandleDisabled = getResources().getDrawable( + R.drawable.ic_voicemail_seek_handle_disabled, mContext.getTheme()); } @Override @@ -365,17 +373,22 @@ public class VoicemailPlaybackLayout extends LinearLayout @Override public void disableUiElements() { mStartStopButton.setEnabled(false); - mPlaybackSeek.setProgress(0); mPlaybackSeek.setEnabled(false); + mPlaybackSeek.setThumb(mVoicemailSeekHandleDisabled); } @Override public void enableUiElements() { mStartStopButton.setEnabled(true); mPlaybackSeek.setEnabled(true); + mPlaybackSeek.setThumb(mVoicemailSeekHandleEnabled); + } - mPositionText.setVisibility(View.VISIBLE); - mTotalDurationText.setVisibility(View.VISIBLE); + @Override + public void resetSeekBar() { + mPlaybackSeek.setProgress(0); + mPlaybackSeek.setEnabled(false); + mPlaybackSeek.setThumb(mVoicemailSeekHandleDisabled); } @Override diff --git a/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java b/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java index 208096dac..7a2bffcd9 100644 --- a/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java +++ b/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java @@ -85,6 +85,7 @@ public class VoicemailPlaybackPresenter implements MediaPlayer.OnPreparedListene void setFetchContentTimeout(); void setIsFetchingContent(); void setPresenter(VoicemailPlaybackPresenter presenter, Uri voicemailUri); + void resetSeekBar(); } public interface OnVoicemailDeletedListener { @@ -272,16 +273,20 @@ public class VoicemailPlaybackPresenter implements MediaPlayer.OnPreparedListene * Reset the presenter for playback back to its original state. */ public void resetAll() { - reset(); + pausePresenter(true); mView = null; mVoicemailUri = null; } /** - * Reset the presenter such that it is as if the voicemail has not been played. + * When navigating away from voicemail playback, we need to release the media player, + * pause the UI and save the position. + * + * @param reset {@code true} if we want to reset the position of the playback, {@code false} if + * we want to retain the current position (in case we return to the voicemail). */ - public void reset() { + public void pausePresenter(boolean reset) { if (mMediaPlayer != null) { mMediaPlayer.release(); mMediaPlayer = null; @@ -291,12 +296,19 @@ public class VoicemailPlaybackPresenter implements MediaPlayer.OnPreparedListene mIsPrepared = false; mIsPlaying = false; - mPosition = 0; - mDuration.set(0); + + if (reset) { + // We want to reset the position whether or not the view is valid. + mPosition = 0; + } if (mView != null) { mView.onPlaybackStopped(); - mView.setClipPosition(0, mDuration.get()); + if (reset) { + mView.setClipPosition(0, mDuration.get()); + } else { + mPosition = mView.getDesiredClipPosition(); + } } } @@ -312,7 +324,7 @@ public class VoicemailPlaybackPresenter implements MediaPlayer.OnPreparedListene } // Release the media player, otherwise there may be failures. - reset(); + pausePresenter(false); if (mActivity != null) { mActivity.getWindow().clearFlags(LayoutParams.FLAG_KEEP_SCREEN_ON); @@ -345,8 +357,8 @@ public class VoicemailPlaybackPresenter implements MediaPlayer.OnPreparedListene * voicemail we've been asked to play has any content available. * <p> * Notify the user that we are fetching the content, then check to see if the content field in - * the DB is set. If set, we proceed to {@link #prepareContent()} method. If not set, make - * a request to fetch the content asynchronously via {@link #requestContent()}. + * the DB is set. If set, we proceed to {@link #prepareContent()} method. We get the duration of + * the voicemail from the query and set it if the content is not available. */ private void checkForContent() { mAsyncTaskExecutor.submit(Tasks.CHECK_FOR_CONTENT, new AsyncTask<Void, Void, Boolean>() { @@ -360,6 +372,7 @@ public class VoicemailPlaybackPresenter implements MediaPlayer.OnPreparedListene if (hasContent) { prepareContent(); } else { + mView.resetSeekBar(); mView.setClipPosition(0, mDuration.get()); } } @@ -523,7 +536,6 @@ public class VoicemailPlaybackPresenter implements MediaPlayer.OnPreparedListene mIsPrepared = true; mDuration.set(mMediaPlayer.getDuration()); - mPosition = mMediaPlayer.getCurrentPosition(); Log.d(TAG, "onPrepared: mPosition=" + mPosition); mView.setClipPosition(mPosition, mDuration.get()); @@ -618,6 +630,7 @@ public class VoicemailPlaybackPresenter implements MediaPlayer.OnPreparedListene if (!mMediaPlayer.isPlaying()) { // Clamp the start position between 0 and the duration. mPosition = Math.max(0, Math.min(mPosition, mDuration.get())); + mMediaPlayer.seekTo(mPosition); try { |