summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/app/voicemail
diff options
context:
space:
mode:
Diffstat (limited to 'java/com/android/dialer/app/voicemail')
-rw-r--r--java/com/android/dialer/app/voicemail/VoicemailAudioManager.java88
-rw-r--r--java/com/android/dialer/app/voicemail/VoicemailPlaybackLayout.java252
-rw-r--r--java/com/android/dialer/app/voicemail/VoicemailPlaybackPresenter.java460
-rw-r--r--java/com/android/dialer/app/voicemail/WiredHeadsetManager.java40
4 files changed, 418 insertions, 422 deletions
diff --git a/java/com/android/dialer/app/voicemail/VoicemailAudioManager.java b/java/com/android/dialer/app/voicemail/VoicemailAudioManager.java
index d3c3820d7..79716cb38 100644
--- a/java/com/android/dialer/app/voicemail/VoicemailAudioManager.java
+++ b/java/com/android/dialer/app/voicemail/VoicemailAudioManager.java
@@ -32,28 +32,28 @@ public final class VoicemailAudioManager
public static final int PLAYBACK_STREAM = AudioManager.STREAM_VOICE_CALL;
- private AudioManager mAudioManager;
- private VoicemailPlaybackPresenter mVoicemailPlaybackPresenter;
- private WiredHeadsetManager mWiredHeadsetManager;
- private boolean mWasSpeakerOn;
- private CallAudioState mCallAudioState;
- private boolean mBluetoothScoEnabled;
+ private AudioManager audioManager;
+ private VoicemailPlaybackPresenter voicemailPlaybackPresenter;
+ private WiredHeadsetManager wiredHeadsetManager;
+ private boolean wasSpeakerOn;
+ private CallAudioState callAudioState;
+ private boolean bluetoothScoEnabled;
public VoicemailAudioManager(
Context context, VoicemailPlaybackPresenter voicemailPlaybackPresenter) {
- mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
- mVoicemailPlaybackPresenter = voicemailPlaybackPresenter;
- mWiredHeadsetManager = new WiredHeadsetManager(context);
- mWiredHeadsetManager.setListener(this);
+ audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
+ this.voicemailPlaybackPresenter = voicemailPlaybackPresenter;
+ wiredHeadsetManager = new WiredHeadsetManager(context);
+ wiredHeadsetManager.setListener(this);
- mCallAudioState = getInitialAudioState();
+ callAudioState = getInitialAudioState();
LogUtil.i(
- "VoicemailAudioManager.VoicemailAudioManager", "Initial audioState = " + mCallAudioState);
+ "VoicemailAudioManager.VoicemailAudioManager", "Initial audioState = " + callAudioState);
}
public void requestAudioFocus() {
int result =
- mAudioManager.requestAudioFocus(
+ audioManager.requestAudioFocus(
this, PLAYBACK_STREAM, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
if (result != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
throw new RejectedExecutionException("Could not capture audio focus.");
@@ -63,13 +63,13 @@ public final class VoicemailAudioManager
public void abandonAudioFocus() {
updateBluetoothScoState(false);
- mAudioManager.abandonAudioFocus(this);
+ audioManager.abandonAudioFocus(this);
}
@Override
public void onAudioFocusChange(int focusChange) {
LogUtil.d("VoicemailAudioManager.onAudioFocusChange", "focusChange=" + focusChange);
- mVoicemailPlaybackPresenter.onAudioFocusChange(focusChange == AudioManager.AUDIOFOCUS_GAIN);
+ voicemailPlaybackPresenter.onAudioFocusChange(focusChange == AudioManager.AUDIOFOCUS_GAIN);
}
@Override
@@ -82,19 +82,19 @@ public final class VoicemailAudioManager
return;
}
- int newRoute = mCallAudioState.getRoute(); // start out with existing route
+ int newRoute = callAudioState.getRoute(); // start out with existing route
if (newIsPluggedIn) {
newRoute = CallAudioState.ROUTE_WIRED_HEADSET;
} else {
- mVoicemailPlaybackPresenter.pausePlayback();
- if (mWasSpeakerOn) {
+ voicemailPlaybackPresenter.pausePlayback();
+ if (wasSpeakerOn) {
newRoute = CallAudioState.ROUTE_SPEAKER;
} else {
newRoute = CallAudioState.ROUTE_EARPIECE;
}
}
- mVoicemailPlaybackPresenter.setSpeakerphoneOn(newRoute == CallAudioState.ROUTE_SPEAKER);
+ voicemailPlaybackPresenter.setSpeakerphoneOn(newRoute == CallAudioState.ROUTE_SPEAKER);
// We need to call this every time even if we do not change the route because the supported
// routes changed either to include or not include WIRED_HEADSET.
@@ -107,16 +107,16 @@ public final class VoicemailAudioManager
}
public boolean isWiredHeadsetPluggedIn() {
- return mWiredHeadsetManager.isPluggedIn();
+ return wiredHeadsetManager.isPluggedIn();
}
public void registerReceivers() {
// Receivers is plural because we expect to add bluetooth support.
- mWiredHeadsetManager.registerReceiver();
+ wiredHeadsetManager.registerReceiver();
}
public void unregisterReceivers() {
- mWiredHeadsetManager.unregisterReceiver();
+ wiredHeadsetManager.unregisterReceiver();
}
/**
@@ -127,34 +127,34 @@ public final class VoicemailAudioManager
private void updateBluetoothScoState(boolean hasAudioFocus) {
if (hasAudioFocus) {
if (hasMediaAudioCapability()) {
- mBluetoothScoEnabled = false;
+ bluetoothScoEnabled = false;
} else {
- mBluetoothScoEnabled = true;
+ bluetoothScoEnabled = true;
LogUtil.i(
"VoicemailAudioManager.updateBluetoothScoState",
"bluetooth device doesn't support media, using SCO instead");
}
} else {
- mBluetoothScoEnabled = false;
+ bluetoothScoEnabled = false;
}
applyBluetoothScoState();
}
private void applyBluetoothScoState() {
- if (mBluetoothScoEnabled) {
- mAudioManager.startBluetoothSco();
+ if (bluetoothScoEnabled) {
+ audioManager.startBluetoothSco();
// The doc for startBluetoothSco() states it could take seconds to establish the SCO
// connection, so we should probably resume the playback after we've acquired SCO.
// In practice the delay is unnoticeable so this is ignored for simplicity.
- mAudioManager.setBluetoothScoOn(true);
+ audioManager.setBluetoothScoOn(true);
} else {
- mAudioManager.setBluetoothScoOn(false);
- mAudioManager.stopBluetoothSco();
+ audioManager.setBluetoothScoOn(false);
+ audioManager.stopBluetoothSco();
}
}
private boolean hasMediaAudioCapability() {
- for (AudioDeviceInfo info : mAudioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS)) {
+ for (AudioDeviceInfo info : audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS)) {
if (info.getType() == AudioDeviceInfo.TYPE_BLUETOOTH_A2DP) {
return true;
}
@@ -173,10 +173,10 @@ public final class VoicemailAudioManager
"route: " + CallAudioState.audioRouteToString(route));
// Change ROUTE_WIRED_OR_EARPIECE to a single entry.
- int newRoute = selectWiredOrEarpiece(route, mCallAudioState.getSupportedRouteMask());
+ int newRoute = selectWiredOrEarpiece(route, callAudioState.getSupportedRouteMask());
// If route is unsupported, do nothing.
- if ((mCallAudioState.getSupportedRouteMask() | newRoute) == 0) {
+ if ((callAudioState.getSupportedRouteMask() | newRoute) == 0) {
LogUtil.w(
"VoicemailAudioManager.setAudioRoute",
"Asking to set to a route that is unsupported: " + newRoute);
@@ -185,9 +185,9 @@ public final class VoicemailAudioManager
// Remember the new speaker state so it can be restored when the user plugs and unplugs
// a headset.
- mWasSpeakerOn = newRoute == CallAudioState.ROUTE_SPEAKER;
+ wasSpeakerOn = newRoute == CallAudioState.ROUTE_SPEAKER;
setSystemAudioState(
- new CallAudioState(false /* muted */, newRoute, mCallAudioState.getSupportedRouteMask()));
+ new CallAudioState(false /* muted */, newRoute, callAudioState.getSupportedRouteMask()));
}
private CallAudioState getInitialAudioState() {
@@ -198,7 +198,7 @@ public final class VoicemailAudioManager
private int calculateSupportedRoutes() {
int routeMask = CallAudioState.ROUTE_SPEAKER;
- if (mWiredHeadsetManager.isPluggedIn()) {
+ if (wiredHeadsetManager.isPluggedIn()) {
routeMask |= CallAudioState.ROUTE_WIRED_HEADSET;
} else {
routeMask |= CallAudioState.ROUTE_EARPIECE;
@@ -224,18 +224,18 @@ public final class VoicemailAudioManager
}
private void setSystemAudioState(CallAudioState callAudioState) {
- CallAudioState oldAudioState = mCallAudioState;
- mCallAudioState = callAudioState;
+ CallAudioState oldAudioState = this.callAudioState;
+ this.callAudioState = callAudioState;
LogUtil.i(
"VoicemailAudioManager.setSystemAudioState",
- "changing from " + oldAudioState + " to " + mCallAudioState);
+ "changing from " + oldAudioState + " to " + this.callAudioState);
// Audio route.
- if (mCallAudioState.getRoute() == CallAudioState.ROUTE_SPEAKER) {
+ if (this.callAudioState.getRoute() == CallAudioState.ROUTE_SPEAKER) {
turnOnSpeaker(true);
- } else if (mCallAudioState.getRoute() == CallAudioState.ROUTE_EARPIECE
- || mCallAudioState.getRoute() == CallAudioState.ROUTE_WIRED_HEADSET) {
+ } else if (this.callAudioState.getRoute() == CallAudioState.ROUTE_EARPIECE
+ || this.callAudioState.getRoute() == CallAudioState.ROUTE_WIRED_HEADSET) {
// Just handle turning off the speaker, the system will handle switching between wired
// headset and earpiece.
turnOnSpeaker(false);
@@ -245,9 +245,9 @@ public final class VoicemailAudioManager
}
private void turnOnSpeaker(boolean on) {
- if (mAudioManager.isSpeakerphoneOn() != on) {
+ if (audioManager.isSpeakerphoneOn() != on) {
LogUtil.i("VoicemailAudioManager.turnOnSpeaker", "turning speaker phone on: " + on);
- mAudioManager.setSpeakerphoneOn(on);
+ audioManager.setSpeakerphoneOn(on);
}
}
}
diff --git a/java/com/android/dialer/app/voicemail/VoicemailPlaybackLayout.java b/java/com/android/dialer/app/voicemail/VoicemailPlaybackLayout.java
index 9c1e446ab..010f55fa8 100644
--- a/java/com/android/dialer/app/voicemail/VoicemailPlaybackLayout.java
+++ b/java/com/android/dialer/app/voicemail/VoicemailPlaybackLayout.java
@@ -58,27 +58,27 @@ public class VoicemailPlaybackLayout extends LinearLayout
private static final String TAG = VoicemailPlaybackLayout.class.getSimpleName();
private static final int VOICEMAIL_DELETE_DELAY_MS = 3000;
- private Context mContext;
- private CallLogListItemViewHolder mViewHolder;
- private VoicemailPlaybackPresenter mPresenter;
+ private Context context;
+ private CallLogListItemViewHolder viewHolder;
+ private VoicemailPlaybackPresenter presenter;
/** Click listener to toggle speakerphone. */
- private final View.OnClickListener mSpeakerphoneListener =
+ private final View.OnClickListener speakerphoneListener =
new View.OnClickListener() {
@Override
public void onClick(View v) {
- if (mPresenter != null) {
- mPresenter.toggleSpeakerphone();
+ if (presenter != null) {
+ presenter.toggleSpeakerphone();
}
}
};
- private Uri mVoicemailUri;
- private final View.OnClickListener mDeleteButtonListener =
+ private Uri voicemailUri;
+ private final View.OnClickListener deleteButtonListener =
new View.OnClickListener() {
@Override
public void onClick(View view) {
- Logger.get(mContext).logImpression(DialerImpression.Type.VOICEMAIL_DELETE_ENTRY);
- if (mPresenter == null) {
+ Logger.get(context).logImpression(DialerImpression.Type.VOICEMAIL_DELETE_ENTRY);
+ if (presenter == null) {
return;
}
@@ -86,19 +86,19 @@ public class VoicemailPlaybackLayout extends LinearLayout
// we hide the view it is binded to something else, and the layout is not updated for
// hidden items. copy the adapter position so we can update the view upon undo.
// TODO(twyen): refactor this so the view holder will always be valid.
- final int adapterPosition = mViewHolder.getAdapterPosition();
+ final int adapterPosition = viewHolder.getAdapterPosition();
- mPresenter.pausePlayback();
- mPresenter.onVoicemailDeleted(mViewHolder);
+ presenter.pausePlayback();
+ presenter.onVoicemailDeleted(viewHolder);
- final Uri deleteUri = mVoicemailUri;
+ final Uri deleteUri = voicemailUri;
final Runnable deleteCallback =
new Runnable() {
@Override
public void run() {
- if (Objects.equals(deleteUri, mVoicemailUri)) {
+ if (Objects.equals(deleteUri, voicemailUri)) {
CallLogAsyncTaskUtil.deleteVoicemail(
- mContext, deleteUri, VoicemailPlaybackLayout.this);
+ context, deleteUri, VoicemailPlaybackLayout.this);
}
}
};
@@ -118,56 +118,56 @@ public class VoicemailPlaybackLayout extends LinearLayout
new View.OnClickListener() {
@Override
public void onClick(View view) {
- mPresenter.onVoicemailDeleteUndo(adapterPosition);
+ presenter.onVoicemailDeleteUndo(adapterPosition);
handler.removeCallbacks(deleteCallback);
}
})
.setActionTextColor(
- mContext.getResources().getColor(R.color.dialer_snackbar_action_text_color))
+ context.getResources().getColor(R.color.dialer_snackbar_action_text_color))
.show();
}
};
- private boolean mIsPlaying = false;
+ private boolean isPlaying = false;
/** Click listener to play or pause voicemail playback. */
- private final View.OnClickListener mStartStopButtonListener =
+ private final View.OnClickListener startStopButtonListener =
new View.OnClickListener() {
@Override
public void onClick(View view) {
- if (mPresenter == null) {
+ if (presenter == null) {
return;
}
- if (mIsPlaying) {
- mPresenter.pausePlayback();
+ if (isPlaying) {
+ presenter.pausePlayback();
} else {
- Logger.get(mContext)
+ Logger.get(context)
.logImpression(DialerImpression.Type.VOICEMAIL_PLAY_AUDIO_AFTER_EXPANDING_ENTRY);
- mPresenter.resumePlayback();
+ presenter.resumePlayback();
}
}
};
- private SeekBar mPlaybackSeek;
- private ImageButton mStartStopButton;
- private ImageButton mPlaybackSpeakerphone;
- private ImageButton mDeleteButton;
- private TextView mStateText;
- private TextView mPositionText;
- private TextView mTotalDurationText;
+ private SeekBar playbackSeek;
+ private ImageButton startStopButton;
+ private ImageButton playbackSpeakerphone;
+ private ImageButton deleteButton;
+ private TextView stateText;
+ private TextView positionText;
+ private TextView totalDurationText;
/** Handle state changes when the user manipulates the seek bar. */
- private final OnSeekBarChangeListener mSeekBarChangeListener =
+ private final OnSeekBarChangeListener seekBarChangeListener =
new OnSeekBarChangeListener() {
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
- if (mPresenter != null) {
- mPresenter.pausePlaybackForSeeking();
+ if (presenter != null) {
+ presenter.pausePlaybackForSeeking();
}
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
- if (mPresenter != null) {
- mPresenter.resumePlaybackAfterSeeking(seekBar.getProgress());
+ if (presenter != null) {
+ presenter.resumePlaybackAfterSeeking(seekBar.getProgress());
}
}
@@ -177,14 +177,14 @@ public class VoicemailPlaybackLayout extends LinearLayout
// Update the seek position if user manually changed it. This makes sure position gets
// updated when user use volume button to seek playback in talkback mode.
if (fromUser) {
- mPresenter.seek(progress);
+ presenter.seek(progress);
}
}
};
- private PositionUpdater mPositionUpdater;
- private Drawable mVoicemailSeekHandleEnabled;
- private Drawable mVoicemailSeekHandleDisabled;
+ private PositionUpdater positionUpdater;
+ private Drawable voicemailSeekHandleEnabled;
+ private Drawable voicemailSeekHandleDisabled;
public VoicemailPlaybackLayout(Context context) {
this(context, null);
@@ -192,99 +192,97 @@ public class VoicemailPlaybackLayout extends LinearLayout
public VoicemailPlaybackLayout(Context context, AttributeSet attrs) {
super(context, attrs);
- mContext = context;
+ this.context = context;
LayoutInflater inflater =
(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.voicemail_playback_layout, this);
}
public void setViewHolder(CallLogListItemViewHolder mViewHolder) {
- this.mViewHolder = mViewHolder;
+ this.viewHolder = mViewHolder;
}
@Override
public void setPresenter(VoicemailPlaybackPresenter presenter, Uri voicemailUri) {
- mPresenter = presenter;
- mVoicemailUri = voicemailUri;
+ this.presenter = presenter;
+ this.voicemailUri = voicemailUri;
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
- mPlaybackSeek = (SeekBar) findViewById(R.id.playback_seek);
- mStartStopButton = (ImageButton) findViewById(R.id.playback_start_stop);
- mPlaybackSpeakerphone = (ImageButton) findViewById(R.id.playback_speakerphone);
- mDeleteButton = (ImageButton) findViewById(R.id.delete_voicemail);
+ playbackSeek = (SeekBar) findViewById(R.id.playback_seek);
+ startStopButton = (ImageButton) findViewById(R.id.playback_start_stop);
+ playbackSpeakerphone = (ImageButton) findViewById(R.id.playback_speakerphone);
+ deleteButton = (ImageButton) findViewById(R.id.delete_voicemail);
- mStateText = (TextView) findViewById(R.id.playback_state_text);
- mStateText.setAccessibilityLiveRegion(ACCESSIBILITY_LIVE_REGION_POLITE);
- mPositionText = (TextView) findViewById(R.id.playback_position_text);
- mTotalDurationText = (TextView) findViewById(R.id.total_duration_text);
+ stateText = (TextView) findViewById(R.id.playback_state_text);
+ stateText.setAccessibilityLiveRegion(ACCESSIBILITY_LIVE_REGION_POLITE);
+ positionText = (TextView) findViewById(R.id.playback_position_text);
+ totalDurationText = (TextView) findViewById(R.id.total_duration_text);
- mPlaybackSeek.setOnSeekBarChangeListener(mSeekBarChangeListener);
- mStartStopButton.setOnClickListener(mStartStopButtonListener);
- mPlaybackSpeakerphone.setOnClickListener(mSpeakerphoneListener);
- mDeleteButton.setOnClickListener(mDeleteButtonListener);
+ playbackSeek.setOnSeekBarChangeListener(seekBarChangeListener);
+ startStopButton.setOnClickListener(startStopButtonListener);
+ playbackSpeakerphone.setOnClickListener(speakerphoneListener);
+ deleteButton.setOnClickListener(deleteButtonListener);
- mPositionText.setText(formatAsMinutesAndSeconds(0));
- mTotalDurationText.setText(formatAsMinutesAndSeconds(0));
+ positionText.setText(formatAsMinutesAndSeconds(0));
+ totalDurationText.setText(formatAsMinutesAndSeconds(0));
- mVoicemailSeekHandleEnabled =
- getResources().getDrawable(R.drawable.ic_voicemail_seek_handle, mContext.getTheme());
- mVoicemailSeekHandleDisabled =
+ voicemailSeekHandleEnabled =
+ getResources().getDrawable(R.drawable.ic_voicemail_seek_handle, context.getTheme());
+ voicemailSeekHandleDisabled =
getResources()
- .getDrawable(R.drawable.ic_voicemail_seek_handle_disabled, mContext.getTheme());
+ .getDrawable(R.drawable.ic_voicemail_seek_handle_disabled, context.getTheme());
}
@Override
public void onPlaybackStarted(int duration, ScheduledExecutorService executorService) {
- mIsPlaying = true;
+ isPlaying = true;
- mStartStopButton.setImageResource(R.drawable.ic_pause);
+ startStopButton.setImageResource(R.drawable.ic_pause);
- if (mPositionUpdater != null) {
- mPositionUpdater.stopUpdating();
- mPositionUpdater = null;
+ if (positionUpdater != null) {
+ positionUpdater.stopUpdating();
+ positionUpdater = null;
}
- mPositionUpdater = new PositionUpdater(duration, executorService);
- mPositionUpdater.startUpdating();
+ positionUpdater = new PositionUpdater(duration, executorService);
+ positionUpdater.startUpdating();
}
@Override
public void onPlaybackStopped() {
- mIsPlaying = false;
+ isPlaying = false;
- mStartStopButton.setImageResource(R.drawable.ic_play_arrow);
+ startStopButton.setImageResource(R.drawable.ic_play_arrow);
- if (mPositionUpdater != null) {
- mPositionUpdater.stopUpdating();
- mPositionUpdater = null;
+ if (positionUpdater != null) {
+ positionUpdater.stopUpdating();
+ positionUpdater = null;
}
}
@Override
public void onPlaybackError() {
- if (mPositionUpdater != null) {
- mPositionUpdater.stopUpdating();
+ if (positionUpdater != null) {
+ positionUpdater.stopUpdating();
}
disableUiElements();
- mStateText.setText(getString(R.string.voicemail_playback_error));
+ stateText.setText(getString(R.string.voicemail_playback_error));
}
@Override
public void onSpeakerphoneOn(boolean on) {
if (on) {
- mPlaybackSpeakerphone.setImageResource(R.drawable.quantum_ic_volume_up_white_24);
+ playbackSpeakerphone.setImageResource(R.drawable.quantum_ic_volume_up_white_24);
// Speaker is now on, tapping button will turn it off.
- mPlaybackSpeakerphone.setContentDescription(
- mContext.getString(R.string.voicemail_speaker_off));
+ playbackSpeakerphone.setContentDescription(context.getString(R.string.voicemail_speaker_off));
} else {
- mPlaybackSpeakerphone.setImageResource(R.drawable.quantum_ic_volume_down_white_24);
+ playbackSpeakerphone.setImageResource(R.drawable.quantum_ic_volume_down_white_24);
// Speaker is now off, tapping button will turn it on.
- mPlaybackSpeakerphone.setContentDescription(
- mContext.getString(R.string.voicemail_speaker_on));
+ playbackSpeakerphone.setContentDescription(context.getString(R.string.voicemail_speaker_on));
}
}
@@ -292,66 +290,66 @@ public class VoicemailPlaybackLayout extends LinearLayout
public void setClipPosition(int positionMs, int durationMs) {
int seekBarPositionMs = Math.max(0, positionMs);
int seekBarMax = Math.max(seekBarPositionMs, durationMs);
- if (mPlaybackSeek.getMax() != seekBarMax) {
- mPlaybackSeek.setMax(seekBarMax);
+ if (playbackSeek.getMax() != seekBarMax) {
+ playbackSeek.setMax(seekBarMax);
}
- mPlaybackSeek.setProgress(seekBarPositionMs);
+ playbackSeek.setProgress(seekBarPositionMs);
- mPositionText.setText(formatAsMinutesAndSeconds(seekBarPositionMs));
- mTotalDurationText.setText(formatAsMinutesAndSeconds(durationMs));
+ positionText.setText(formatAsMinutesAndSeconds(seekBarPositionMs));
+ totalDurationText.setText(formatAsMinutesAndSeconds(durationMs));
}
@Override
public void setSuccess() {
- mStateText.setText(null);
+ stateText.setText(null);
}
@Override
public void setIsFetchingContent() {
disableUiElements();
- mStateText.setText(getString(R.string.voicemail_fetching_content));
+ stateText.setText(getString(R.string.voicemail_fetching_content));
}
@Override
public void setFetchContentTimeout() {
- mStartStopButton.setEnabled(true);
- mStateText.setText(getString(R.string.voicemail_fetching_timout));
+ startStopButton.setEnabled(true);
+ stateText.setText(getString(R.string.voicemail_fetching_timout));
}
@Override
public int getDesiredClipPosition() {
- return mPlaybackSeek.getProgress();
+ return playbackSeek.getProgress();
}
@Override
public void disableUiElements() {
- mStartStopButton.setEnabled(false);
+ startStopButton.setEnabled(false);
resetSeekBar();
}
@Override
public void enableUiElements() {
- mDeleteButton.setEnabled(true);
- mStartStopButton.setEnabled(true);
- mPlaybackSeek.setEnabled(true);
- mPlaybackSeek.setThumb(mVoicemailSeekHandleEnabled);
+ deleteButton.setEnabled(true);
+ startStopButton.setEnabled(true);
+ playbackSeek.setEnabled(true);
+ playbackSeek.setThumb(voicemailSeekHandleEnabled);
}
@Override
public void resetSeekBar() {
- mPlaybackSeek.setProgress(0);
- mPlaybackSeek.setEnabled(false);
- mPlaybackSeek.setThumb(mVoicemailSeekHandleDisabled);
+ playbackSeek.setProgress(0);
+ playbackSeek.setEnabled(false);
+ playbackSeek.setThumb(voicemailSeekHandleDisabled);
}
@Override
public void onDeleteVoicemail() {
- mPresenter.onVoicemailDeletedInDatabase();
+ presenter.onVoicemailDeletedInDatabase();
}
private String getString(int resId) {
- return mContext.getString(resId);
+ return context.getString(resId);
}
/**
@@ -372,7 +370,7 @@ public class VoicemailPlaybackLayout extends LinearLayout
@VisibleForTesting
public String getStateText() {
- return mStateText.getText().toString();
+ return stateText.getText().toString();
}
/** Controls the animation of the playback slider. */
@@ -382,61 +380,61 @@ public class VoicemailPlaybackLayout extends LinearLayout
/** Update rate for the slider, 30fps. */
private static final int SLIDER_UPDATE_PERIOD_MILLIS = 1000 / 30;
- private final ScheduledExecutorService mExecutorService;
- private final Object mLock = new Object();
- private int mDurationMs;
+ private final ScheduledExecutorService executorService;
+ private final Object lock = new Object();
+ private int durationMs;
- @GuardedBy("mLock")
- private ScheduledFuture<?> mScheduledFuture;
+ @GuardedBy("lock")
+ private ScheduledFuture<?> scheduledFuture;
- private Runnable mUpdateClipPositionRunnable =
+ private Runnable updateClipPositionRunnable =
new Runnable() {
@Override
public void run() {
int currentPositionMs = 0;
- synchronized (mLock) {
- if (mScheduledFuture == null || mPresenter == null) {
+ synchronized (lock) {
+ if (scheduledFuture == null || presenter == null) {
// This task has been canceled. Just stop now.
return;
}
- currentPositionMs = mPresenter.getMediaPlayerPosition();
+ currentPositionMs = presenter.getMediaPlayerPosition();
}
- setClipPosition(currentPositionMs, mDurationMs);
+ setClipPosition(currentPositionMs, durationMs);
}
};
public PositionUpdater(int durationMs, ScheduledExecutorService executorService) {
- mDurationMs = durationMs;
- mExecutorService = executorService;
+ this.durationMs = durationMs;
+ this.executorService = executorService;
}
@Override
public void run() {
- post(mUpdateClipPositionRunnable);
+ post(updateClipPositionRunnable);
}
public void startUpdating() {
- synchronized (mLock) {
+ synchronized (lock) {
cancelPendingRunnables();
- mScheduledFuture =
- mExecutorService.scheduleAtFixedRate(
+ scheduledFuture =
+ executorService.scheduleAtFixedRate(
this, 0, SLIDER_UPDATE_PERIOD_MILLIS, TimeUnit.MILLISECONDS);
}
}
public void stopUpdating() {
- synchronized (mLock) {
+ synchronized (lock) {
cancelPendingRunnables();
}
}
- @GuardedBy("mLock")
+ @GuardedBy("lock")
private void cancelPendingRunnables() {
- if (mScheduledFuture != null) {
- mScheduledFuture.cancel(true);
- mScheduledFuture = null;
+ if (scheduledFuture != null) {
+ scheduledFuture.cancel(true);
+ scheduledFuture = null;
}
- removeCallbacks(mUpdateClipPositionRunnable);
+ removeCallbacks(updateClipPositionRunnable);
}
}
}
diff --git a/java/com/android/dialer/app/voicemail/VoicemailPlaybackPresenter.java b/java/com/android/dialer/app/voicemail/VoicemailPlaybackPresenter.java
index 10afe479f..e9b64dfe3 100644
--- a/java/com/android/dialer/app/voicemail/VoicemailPlaybackPresenter.java
+++ b/java/com/android/dialer/app/voicemail/VoicemailPlaybackPresenter.java
@@ -113,41 +113,41 @@ public class VoicemailPlaybackPresenter
private static final String VOICEMAIL_SHARE_FILE_NAME_DATE_FORMAT = "MM-dd-yy_hhmmaa";
private static final String CONFIG_SHARE_VOICEMAIL_ALLOWED = "share_voicemail_allowed";
- private static VoicemailPlaybackPresenter sInstance;
- private static ScheduledExecutorService mScheduledExecutorService;
+ private static VoicemailPlaybackPresenter instance;
+ private static ScheduledExecutorService scheduledExecutorService;
/**
* The most recently cached duration. We cache this since we don't want to keep requesting it from
* the player, as this can easily lead to throwing {@link IllegalStateException} (any time the
* player is released, it's illegal to ask for the duration).
*/
- private final AtomicInteger mDuration = new AtomicInteger(0);
+ private final AtomicInteger duration = new AtomicInteger(0);
- protected Context mContext;
- private long mRowId;
- protected Uri mVoicemailUri;
- protected MediaPlayer mMediaPlayer;
+ protected Context context;
+ private long rowId;
+ protected Uri voicemailUri;
+ protected MediaPlayer mediaPlayer;
// Used to run async tasks that need to interact with the UI.
- protected AsyncTaskExecutor mAsyncTaskExecutor;
- private Activity mActivity;
- private PlaybackView mView;
- private int mPosition;
- private boolean mIsPlaying;
+ protected AsyncTaskExecutor asyncTaskExecutor;
+ private Activity activity;
+ private PlaybackView view;
+ private int position;
+ private boolean isPlaying;
// 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 isPrepared;
+ private boolean isSpeakerphoneOn;
- private boolean mShouldResumePlaybackAfterSeeking;
+ private boolean shouldResumePlaybackAfterSeeking;
/**
* Used to handle the result of a successful or time-out fetch result.
*
* <p>This variable is thread-contained, accessed only on the ui thread.
*/
- private FetchResultHandler mFetchResultHandler;
+ private FetchResultHandler fetchResultHandler;
- private PowerManager.WakeLock mProximityWakeLock;
- private VoicemailAudioManager mVoicemailAudioManager;
- private OnVoicemailDeletedListener mOnVoicemailDeletedListener;
+ private PowerManager.WakeLock proximityWakeLock;
+ private VoicemailAudioManager voicemailAudioManager;
+ private OnVoicemailDeletedListener onVoicemailDeletedListener;
private View shareVoicemailButtonView;
private DialerExecutor<Pair<Context, Uri>> shareVoicemailExecutor;
@@ -155,11 +155,11 @@ public class VoicemailPlaybackPresenter
/** Initialize variables which are activity-independent and state-independent. */
protected VoicemailPlaybackPresenter(Activity activity) {
Context context = activity.getApplicationContext();
- mAsyncTaskExecutor = AsyncTaskExecutors.createAsyncTaskExecutor();
- mVoicemailAudioManager = new VoicemailAudioManager(context, this);
+ asyncTaskExecutor = AsyncTaskExecutors.createAsyncTaskExecutor();
+ voicemailAudioManager = new VoicemailAudioManager(context, this);
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
if (powerManager.isWakeLockLevelSupported(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK)) {
- mProximityWakeLock =
+ proximityWakeLock =
powerManager.newWakeLock(
PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, "VoicemailPlaybackPresenter");
}
@@ -177,63 +177,63 @@ public class VoicemailPlaybackPresenter
@MainThread
public static VoicemailPlaybackPresenter getInstance(
Activity activity, Bundle savedInstanceState) {
- if (sInstance == null) {
- sInstance = new VoicemailPlaybackPresenter(activity);
+ if (instance == null) {
+ instance = new VoicemailPlaybackPresenter(activity);
}
- sInstance.init(activity, savedInstanceState);
- return sInstance;
+ instance.init(activity, savedInstanceState);
+ return instance;
}
private static synchronized ScheduledExecutorService getScheduledExecutorServiceInstance() {
- if (mScheduledExecutorService == null) {
- mScheduledExecutorService = Executors.newScheduledThreadPool(NUMBER_OF_THREADS_IN_POOL);
+ if (scheduledExecutorService == null) {
+ scheduledExecutorService = Executors.newScheduledThreadPool(NUMBER_OF_THREADS_IN_POOL);
}
- return mScheduledExecutorService;
+ return scheduledExecutorService;
}
/** Update variables which are activity-dependent or state-dependent. */
@MainThread
protected void init(Activity activity, Bundle savedInstanceState) {
Assert.isMainThread();
- mActivity = activity;
- mContext = activity;
+ this.activity = activity;
+ context = activity;
if (savedInstanceState != null) {
// Restores playback state when activity is recreated, such as after rotation.
- mVoicemailUri = savedInstanceState.getParcelable(VOICEMAIL_URI_KEY);
- 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);
+ voicemailUri = savedInstanceState.getParcelable(VOICEMAIL_URI_KEY);
+ isPrepared = savedInstanceState.getBoolean(IS_PREPARED_KEY);
+ position = savedInstanceState.getInt(CLIP_POSITION_KEY, 0);
+ isPlaying = savedInstanceState.getBoolean(IS_PLAYING_STATE_KEY, false);
+ isSpeakerphoneOn = savedInstanceState.getBoolean(IS_SPEAKERPHONE_ON_KEY, false);
}
- if (mMediaPlayer == null) {
- mIsPrepared = false;
- mIsPlaying = false;
+ if (mediaPlayer == null) {
+ isPrepared = false;
+ isPlaying = false;
}
- if (mActivity != null) {
+ if (this.activity != null) {
if (isPlaying()) {
- mActivity.getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);
+ this.activity.getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);
} else {
- mActivity.getWindow().clearFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);
+ this.activity.getWindow().clearFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);
}
shareVoicemailExecutor =
- DialerExecutorComponent.get(mContext)
+ DialerExecutorComponent.get(context)
.dialerExecutorFactory()
.createUiTaskBuilder(
- mActivity.getFragmentManager(), "shareVoicemail", new ShareVoicemailWorker())
+ this.activity.getFragmentManager(), "shareVoicemail", new ShareVoicemailWorker())
.onSuccess(
output -> {
if (output == null) {
LogUtil.e("VoicemailAsyncTaskUtil.shareVoicemail", "failed to get voicemail");
return;
}
- mContext.startActivity(
+ context.startActivity(
Intent.createChooser(
- getShareIntent(mContext, output.first, output.second),
- mContext
+ getShareIntent(context, output.first, output.second),
+ context
.getResources()
.getText(R.string.call_log_action_share_voicemail)));
})
@@ -243,12 +243,12 @@ public class VoicemailPlaybackPresenter
/** Must be invoked when the parent Activity is saving it state. */
public void onSaveInstanceState(Bundle outState) {
- if (mView != null) {
- outState.putParcelable(VOICEMAIL_URI_KEY, mVoicemailUri);
- 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);
+ if (view != null) {
+ outState.putParcelable(VOICEMAIL_URI_KEY, voicemailUri);
+ outState.putBoolean(IS_PREPARED_KEY, isPrepared);
+ outState.putInt(CLIP_POSITION_KEY, view.getDesiredClipPosition());
+ outState.putBoolean(IS_PLAYING_STATE_KEY, isPlaying);
+ outState.putBoolean(IS_SPEAKERPHONE_ON_KEY, isSpeakerphoneOn);
}
}
@@ -259,26 +259,26 @@ public class VoicemailPlaybackPresenter
Uri voicemailUri,
final boolean startPlayingImmediately,
View shareVoicemailButtonView) {
- mRowId = rowId;
- mView = view;
- mView.setPresenter(this, voicemailUri);
- mView.onSpeakerphoneOn(mIsSpeakerphoneOn);
+ this.rowId = rowId;
+ this.view = view;
+ this.view.setPresenter(this, voicemailUri);
+ this.view.onSpeakerphoneOn(isSpeakerphoneOn);
this.shareVoicemailButtonView = shareVoicemailButtonView;
showShareVoicemailButton(false);
// 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)) {
+ if (mediaPlayer != null && isPrepared && voicemailUri.equals(this.voicemailUri)) {
// If the voicemail card was rebinded, we need to set the position to the appropriate
// point. Since we retain the media player, we can just set it to the position of the
// media player.
- mPosition = mMediaPlayer.getCurrentPosition();
- onPrepared(mMediaPlayer);
+ position = mediaPlayer.getCurrentPosition();
+ onPrepared(mediaPlayer);
showShareVoicemailButton(true);
} else {
- if (!voicemailUri.equals(mVoicemailUri)) {
- mVoicemailUri = voicemailUri;
- mPosition = 0;
+ if (!voicemailUri.equals(this.voicemailUri)) {
+ this.voicemailUri = voicemailUri;
+ position = 0;
}
/*
* Check to see if the content field in the DB is set. If set, we proceed to
@@ -294,9 +294,9 @@ public class VoicemailPlaybackPresenter
if (startPlayingImmediately) {
requestContent(PLAYBACK_REQUEST);
}
- if (mView != null) {
- mView.resetSeekBar();
- mView.setClipPosition(0, mDuration.get());
+ if (this.view != null) {
+ this.view.resetSeekBar();
+ this.view.setClipPosition(0, duration.get());
}
}
});
@@ -305,7 +305,7 @@ public class VoicemailPlaybackPresenter
// Since setPlaybackView can get called during the view binding process, we don't
// want to reset mIsPlaying to false if the user is currently playing the
// voicemail and the view is rebound.
- mIsPlaying = startPlayingImmediately;
+ isPlaying = startPlayingImmediately;
}
}
}
@@ -314,8 +314,8 @@ public class VoicemailPlaybackPresenter
public void resetAll() {
pausePresenter(true);
- mView = null;
- mVoicemailUri = null;
+ view = null;
+ voicemailUri = null;
}
/**
@@ -327,41 +327,41 @@ public class VoicemailPlaybackPresenter
*/
public void pausePresenter(boolean reset) {
pausePlayback();
- if (mMediaPlayer != null) {
- mMediaPlayer.release();
- mMediaPlayer = null;
+ if (mediaPlayer != null) {
+ mediaPlayer.release();
+ mediaPlayer = null;
}
disableProximitySensor(false /* waitForFarState */);
- mIsPrepared = false;
- mIsPlaying = false;
+ isPrepared = false;
+ isPlaying = false;
if (reset) {
// We want to reset the position whether or not the view is valid.
- mPosition = 0;
+ position = 0;
}
- if (mView != null) {
- mView.onPlaybackStopped();
+ if (view != null) {
+ view.onPlaybackStopped();
if (reset) {
- mView.setClipPosition(0, mDuration.get());
+ view.setClipPosition(0, duration.get());
} else {
- mPosition = mView.getDesiredClipPosition();
+ position = view.getDesiredClipPosition();
}
}
}
/** Must be invoked when the parent activity is resumed. */
public void onResume() {
- mVoicemailAudioManager.registerReceivers();
+ voicemailAudioManager.registerReceivers();
}
/** Must be invoked when the parent activity is paused. */
public void onPause() {
- mVoicemailAudioManager.unregisterReceivers();
+ voicemailAudioManager.unregisterReceivers();
- if (mActivity != null && mIsPrepared && mActivity.isChangingConfigurations()) {
+ if (activity != null && isPrepared && activity.isChangingConfigurations()) {
// If an configuration change triggers the pause, retain the MediaPlayer.
LogUtil.d("VoicemailPlaybackPresenter.onPause", "configuration changed.");
return;
@@ -374,28 +374,28 @@ public class VoicemailPlaybackPresenter
/** Must be invoked when the parent activity is destroyed. */
public void onDestroy() {
// Clear references to avoid leaks from the singleton instance.
- mActivity = null;
- mContext = null;
+ activity = null;
+ context = null;
- if (mScheduledExecutorService != null) {
- mScheduledExecutorService.shutdown();
- mScheduledExecutorService = null;
+ if (scheduledExecutorService != null) {
+ scheduledExecutorService.shutdown();
+ scheduledExecutorService = null;
}
- if (mFetchResultHandler != null) {
- mFetchResultHandler.destroy();
- mFetchResultHandler = null;
+ if (fetchResultHandler != null) {
+ fetchResultHandler.destroy();
+ fetchResultHandler = null;
}
}
/** Checks to see if we have content available for this voicemail. */
protected void checkForContent(final OnContentCheckedListener callback) {
- mAsyncTaskExecutor.submit(
+ asyncTaskExecutor.submit(
Tasks.CHECK_FOR_CONTENT,
new AsyncTask<Void, Void, Boolean>() {
@Override
public Boolean doInBackground(Void... params) {
- return queryHasContent(mVoicemailUri);
+ return queryHasContent(voicemailUri);
}
@Override
@@ -406,17 +406,17 @@ public class VoicemailPlaybackPresenter
}
private boolean queryHasContent(Uri voicemailUri) {
- if (voicemailUri == null || mContext == null) {
+ if (voicemailUri == null || context == null) {
return false;
}
- ContentResolver contentResolver = mContext.getContentResolver();
+ ContentResolver contentResolver = context.getContentResolver();
Cursor cursor = contentResolver.query(voicemailUri, null, null, null, null);
try {
if (cursor != null && cursor.moveToNext()) {
int duration = cursor.getInt(cursor.getColumnIndex(VoicemailContract.Voicemails.DURATION));
// Convert database duration (seconds) into mDuration (milliseconds)
- mDuration.set(duration > 0 ? duration * 1000 : 0);
+ this.duration.set(duration > 0 ? duration * 1000 : 0);
return cursor.getInt(cursor.getColumnIndex(VoicemailContract.Voicemails.HAS_CONTENT)) == 1;
}
} finally {
@@ -440,38 +440,34 @@ public class VoicemailPlaybackPresenter
* @return whether issued request to fetch content
*/
protected boolean requestContent(int code) {
- if (mContext == null || mVoicemailUri == null) {
+ if (context == null || voicemailUri == null) {
return false;
}
FetchResultHandler tempFetchResultHandler =
- new FetchResultHandler(new Handler(), mVoicemailUri, code);
+ new FetchResultHandler(new Handler(), voicemailUri, code);
switch (code) {
default:
- if (mFetchResultHandler != null) {
- mFetchResultHandler.destroy();
+ if (fetchResultHandler != null) {
+ fetchResultHandler.destroy();
}
- mView.setIsFetchingContent();
- mFetchResultHandler = tempFetchResultHandler;
+ view.setIsFetchingContent();
+ fetchResultHandler = tempFetchResultHandler;
break;
}
- mAsyncTaskExecutor.submit(
+ asyncTaskExecutor.submit(
Tasks.SEND_FETCH_REQUEST,
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... voids) {
try (Cursor cursor =
- mContext
+ context
.getContentResolver()
.query(
- mVoicemailUri,
- new String[] {Voicemails.SOURCE_PACKAGE},
- null,
- null,
- null)) {
+ voicemailUri, new String[] {Voicemails.SOURCE_PACKAGE}, null, null, null)) {
String sourcePackage;
if (!hasContent(cursor)) {
LogUtil.e(
@@ -482,12 +478,12 @@ public class VoicemailPlaybackPresenter
sourcePackage = cursor.getString(0);
}
// Send voicemail fetch request.
- Intent intent = new Intent(VoicemailContract.ACTION_FETCH_VOICEMAIL, mVoicemailUri);
+ Intent intent = new Intent(VoicemailContract.ACTION_FETCH_VOICEMAIL, voicemailUri);
intent.setPackage(sourcePackage);
LogUtil.i(
"VoicemailPlaybackPresenter.requestContent",
"Sending ACTION_FETCH_VOICEMAIL to " + sourcePackage);
- mContext.sendBroadcast(intent);
+ context.sendBroadcast(intent);
}
return null;
}
@@ -504,35 +500,35 @@ public class VoicemailPlaybackPresenter
* will call {@link #onError()} otherwise.
*/
protected void prepareContent() {
- if (mView == null || mContext == null) {
+ if (view == null || context == null) {
return;
}
LogUtil.d("VoicemailPlaybackPresenter.prepareContent", null);
// Release the previous media player, otherwise there may be failures.
- if (mMediaPlayer != null) {
- mMediaPlayer.release();
- mMediaPlayer = null;
+ if (mediaPlayer != null) {
+ mediaPlayer.release();
+ mediaPlayer = null;
}
- mView.disableUiElements();
- mIsPrepared = false;
+ view.disableUiElements();
+ isPrepared = false;
- if (mContext != null && TelecomUtil.isInManagedCall(mContext)) {
+ if (context != null && TelecomUtil.isInManagedCall(context)) {
handleError(new IllegalStateException("Cannot play voicemail when call is in progress"));
return;
}
try {
- mMediaPlayer = new MediaPlayer();
- mMediaPlayer.setOnPreparedListener(this);
- mMediaPlayer.setOnErrorListener(this);
- mMediaPlayer.setOnCompletionListener(this);
-
- mMediaPlayer.reset();
- mMediaPlayer.setDataSource(mContext, mVoicemailUri);
- mMediaPlayer.setAudioStreamType(VoicemailAudioManager.PLAYBACK_STREAM);
- mMediaPlayer.prepareAsync();
+ mediaPlayer = new MediaPlayer();
+ mediaPlayer.setOnPreparedListener(this);
+ mediaPlayer.setOnErrorListener(this);
+ mediaPlayer.setOnCompletionListener(this);
+
+ mediaPlayer.reset();
+ mediaPlayer.setDataSource(context, voicemailUri);
+ mediaPlayer.setAudioStreamType(VoicemailAudioManager.PLAYBACK_STREAM);
+ mediaPlayer.prepareAsync();
} catch (IOException e) {
handleError(e);
}
@@ -543,23 +539,23 @@ public class VoicemailPlaybackPresenter
*/
@Override
public void onPrepared(MediaPlayer mp) {
- if (mView == null || mContext == null) {
+ if (view == null || context == null) {
return;
}
LogUtil.d("VoicemailPlaybackPresenter.onPrepared", null);
- mIsPrepared = true;
+ isPrepared = true;
- mDuration.set(mMediaPlayer.getDuration());
+ duration.set(mediaPlayer.getDuration());
- LogUtil.d("VoicemailPlaybackPresenter.onPrepared", "mPosition=" + mPosition);
- mView.setClipPosition(mPosition, mDuration.get());
- mView.enableUiElements();
- mView.setSuccess();
+ LogUtil.d("VoicemailPlaybackPresenter.onPrepared", "mPosition=" + position);
+ view.setClipPosition(position, duration.get());
+ view.enableUiElements();
+ view.setSuccess();
if (!mp.isPlaying()) {
- mMediaPlayer.seekTo(mPosition);
+ mediaPlayer.seekTo(position);
}
- if (mIsPlaying) {
+ if (isPlaying) {
resumePlayback();
} else {
pausePlayback();
@@ -579,18 +575,18 @@ public class VoicemailPlaybackPresenter
protected void handleError(Exception e) {
LogUtil.e("VoicemailPlaybackPresenter.handlerError", "could not play voicemail", e);
- if (mIsPrepared) {
- mMediaPlayer.release();
- mMediaPlayer = null;
- mIsPrepared = false;
+ if (isPrepared) {
+ mediaPlayer.release();
+ mediaPlayer = null;
+ isPrepared = false;
}
- if (mView != null) {
- mView.onPlaybackError();
+ if (view != null) {
+ view.onPlaybackError();
}
- mPosition = 0;
- mIsPlaying = false;
+ position = 0;
+ isPlaying = false;
showShareVoicemailButton(false);
}
@@ -600,10 +596,10 @@ public class VoicemailPlaybackPresenter
pausePlayback();
// Reset the seekbar position to the beginning.
- mPosition = 0;
- if (mView != null) {
+ position = 0;
+ if (view != null) {
mediaPlayer.seekTo(0);
- mView.setClipPosition(0, mDuration.get());
+ view.setClipPosition(0, duration.get());
}
}
@@ -617,7 +613,7 @@ public class VoicemailPlaybackPresenter
* @param gainedFocus {@code true} if the audio focus was gained, {@code} false otherwise.
*/
public void onAudioFocusChange(boolean gainedFocus) {
- if (mIsPlaying == gainedFocus) {
+ if (isPlaying == gainedFocus) {
// Nothing new here, just exit.
return;
}
@@ -634,11 +630,11 @@ public class VoicemailPlaybackPresenter
* playing.
*/
public void resumePlayback() {
- if (mView == null) {
+ if (view == null) {
return;
}
- if (!mIsPrepared) {
+ if (!isPrepared) {
/*
* Check content before requesting content to avoid duplicated requests. It is possible
* that the UI doesn't know content has arrived if the fetch took too long causing a
@@ -649,41 +645,41 @@ public class VoicemailPlaybackPresenter
if (!hasContent) {
// No local content, download from server. Queue playing if the request was
// issued,
- mIsPlaying = requestContent(PLAYBACK_REQUEST);
+ isPlaying = requestContent(PLAYBACK_REQUEST);
} else {
showShareVoicemailButton(true);
// Queue playing once the media play loaded the content.
- mIsPlaying = true;
+ isPlaying = true;
prepareContent();
}
});
return;
}
- mIsPlaying = true;
+ isPlaying = true;
- mActivity.getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);
+ activity.getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);
- if (mMediaPlayer != null && !mMediaPlayer.isPlaying()) {
+ if (mediaPlayer != null && !mediaPlayer.isPlaying()) {
// Clamp the start position between 0 and the duration.
- mPosition = Math.max(0, Math.min(mPosition, mDuration.get()));
+ position = Math.max(0, Math.min(position, duration.get()));
- mMediaPlayer.seekTo(mPosition);
+ mediaPlayer.seekTo(position);
try {
// Grab audio focus.
// Can throw RejectedExecutionException.
- mVoicemailAudioManager.requestAudioFocus();
- mMediaPlayer.start();
- setSpeakerphoneOn(mIsSpeakerphoneOn);
- mVoicemailAudioManager.setSpeakerphoneOn(mIsSpeakerphoneOn);
+ voicemailAudioManager.requestAudioFocus();
+ mediaPlayer.start();
+ setSpeakerphoneOn(isSpeakerphoneOn);
+ voicemailAudioManager.setSpeakerphoneOn(isSpeakerphoneOn);
} catch (RejectedExecutionException e) {
handleError(e);
}
}
- LogUtil.d("VoicemailPlaybackPresenter.resumePlayback", "resumed playback at %d.", mPosition);
- mView.onPlaybackStarted(mDuration.get(), getScheduledExecutorServiceInstance());
+ LogUtil.d("VoicemailPlaybackPresenter.resumePlayback", "resumed playback at %d.", position);
+ view.onPlaybackStarted(duration.get(), getScheduledExecutorServiceInstance());
}
/** Pauses voicemail playback at the current position. Null-op if already paused. */
@@ -692,29 +688,29 @@ public class VoicemailPlaybackPresenter
}
private void pausePlayback(boolean keepFocus) {
- if (!mIsPrepared) {
+ if (!isPrepared) {
return;
}
- mIsPlaying = false;
+ isPlaying = false;
- if (mMediaPlayer != null && mMediaPlayer.isPlaying()) {
- mMediaPlayer.pause();
+ if (mediaPlayer != null && mediaPlayer.isPlaying()) {
+ mediaPlayer.pause();
}
- mPosition = mMediaPlayer == null ? 0 : mMediaPlayer.getCurrentPosition();
+ position = mediaPlayer == null ? 0 : mediaPlayer.getCurrentPosition();
- LogUtil.d("VoicemailPlaybackPresenter.pausePlayback", "paused playback at %d.", mPosition);
+ LogUtil.d("VoicemailPlaybackPresenter.pausePlayback", "paused playback at %d.", position);
- if (mView != null) {
- mView.onPlaybackStopped();
+ if (view != null) {
+ view.onPlaybackStopped();
}
if (!keepFocus) {
- mVoicemailAudioManager.abandonAudioFocus();
+ voicemailAudioManager.abandonAudioFocus();
}
- if (mActivity != null) {
- mActivity.getWindow().clearFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);
+ if (activity != null) {
+ activity.getWindow().clearFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);
}
disableProximitySensor(true /* waitForFarState */);
}
@@ -724,16 +720,16 @@ public class VoicemailPlaybackPresenter
* playing to know whether to resume playback once the user selects a new position.
*/
public void pausePlaybackForSeeking() {
- if (mMediaPlayer != null) {
- mShouldResumePlaybackAfterSeeking = mMediaPlayer.isPlaying();
+ if (mediaPlayer != null) {
+ shouldResumePlaybackAfterSeeking = mediaPlayer.isPlaying();
}
pausePlayback(true);
}
public void resumePlaybackAfterSeeking(int desiredPosition) {
- mPosition = desiredPosition;
- if (mShouldResumePlaybackAfterSeeking) {
- mShouldResumePlaybackAfterSeeking = false;
+ position = desiredPosition;
+ if (shouldResumePlaybackAfterSeeking) {
+ shouldResumePlaybackAfterSeeking = false;
resumePlayback();
}
}
@@ -743,23 +739,23 @@ public class VoicemailPlaybackPresenter
* touch or volume button while in talkback mode.
*/
public void seek(int position) {
- mPosition = position;
- mMediaPlayer.seekTo(mPosition);
+ this.position = position;
+ mediaPlayer.seekTo(this.position);
}
private void enableProximitySensor() {
- if (mProximityWakeLock == null
- || mIsSpeakerphoneOn
- || !mIsPrepared
- || mMediaPlayer == null
- || !mMediaPlayer.isPlaying()) {
+ if (proximityWakeLock == null
+ || isSpeakerphoneOn
+ || !isPrepared
+ || mediaPlayer == null
+ || !mediaPlayer.isPlaying()) {
return;
}
- if (!mProximityWakeLock.isHeld()) {
+ if (!proximityWakeLock.isHeld()) {
LogUtil.i(
"VoicemailPlaybackPresenter.enableProximitySensor", "acquiring proximity wake lock");
- mProximityWakeLock.acquire();
+ proximityWakeLock.acquire();
} else {
LogUtil.i(
"VoicemailPlaybackPresenter.enableProximitySensor",
@@ -768,14 +764,14 @@ public class VoicemailPlaybackPresenter
}
private void disableProximitySensor(boolean waitForFarState) {
- if (mProximityWakeLock == null) {
+ if (proximityWakeLock == null) {
return;
}
- if (mProximityWakeLock.isHeld()) {
+ if (proximityWakeLock.isHeld()) {
LogUtil.i(
"VoicemailPlaybackPresenter.disableProximitySensor", "releasing proximity wake lock");
int flags = waitForFarState ? PowerManager.RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY : 0;
- mProximityWakeLock.release(flags);
+ proximityWakeLock.release(flags);
} else {
LogUtil.i(
"VoicemailPlaybackPresenter.disableProximitySensor",
@@ -785,44 +781,44 @@ public class VoicemailPlaybackPresenter
/** This is for use by UI interactions only. It simplifies UI logic. */
public void toggleSpeakerphone() {
- mVoicemailAudioManager.setSpeakerphoneOn(!mIsSpeakerphoneOn);
- setSpeakerphoneOn(!mIsSpeakerphoneOn);
+ voicemailAudioManager.setSpeakerphoneOn(!isSpeakerphoneOn);
+ setSpeakerphoneOn(!isSpeakerphoneOn);
}
public void setOnVoicemailDeletedListener(OnVoicemailDeletedListener listener) {
- mOnVoicemailDeletedListener = listener;
+ onVoicemailDeletedListener = listener;
}
public int getMediaPlayerPosition() {
- return mIsPrepared && mMediaPlayer != null ? mMediaPlayer.getCurrentPosition() : 0;
+ return isPrepared && mediaPlayer != null ? mediaPlayer.getCurrentPosition() : 0;
}
void onVoicemailDeleted(CallLogListItemViewHolder viewHolder) {
- if (mOnVoicemailDeletedListener != null) {
- mOnVoicemailDeletedListener.onVoicemailDeleted(viewHolder, mVoicemailUri);
+ if (onVoicemailDeletedListener != null) {
+ onVoicemailDeletedListener.onVoicemailDeleted(viewHolder, voicemailUri);
}
}
void onVoicemailDeleteUndo(int adapterPosition) {
- if (mOnVoicemailDeletedListener != null) {
- mOnVoicemailDeletedListener.onVoicemailDeleteUndo(mRowId, adapterPosition, mVoicemailUri);
+ if (onVoicemailDeletedListener != null) {
+ onVoicemailDeletedListener.onVoicemailDeleteUndo(rowId, adapterPosition, voicemailUri);
}
}
void onVoicemailDeletedInDatabase() {
- if (mOnVoicemailDeletedListener != null) {
- mOnVoicemailDeletedListener.onVoicemailDeletedInDatabase(mRowId, mVoicemailUri);
+ if (onVoicemailDeletedListener != null) {
+ onVoicemailDeletedListener.onVoicemailDeletedInDatabase(rowId, voicemailUri);
}
}
@VisibleForTesting
public boolean isPlaying() {
- return mIsPlaying;
+ return isPlaying;
}
@VisibleForTesting
public boolean isSpeakerphoneOn() {
- return mIsSpeakerphoneOn;
+ return isSpeakerphoneOn;
}
/**
@@ -831,19 +827,19 @@ public class VoicemailPlaybackPresenter
* presenter without the presenter triggering the audio manager and duplicating actions.
*/
public void setSpeakerphoneOn(boolean on) {
- if (mView == null) {
+ if (view == null) {
return;
}
- mView.onSpeakerphoneOn(on);
+ view.onSpeakerphoneOn(on);
- mIsSpeakerphoneOn = on;
+ isSpeakerphoneOn = on;
// This should run even if speakerphone is not being toggled because we may be switching
// from earpiece to headphone and vise versa. Also upon initial setup the default audio
// source is the earpiece, so we want to trigger the proximity sensor.
- if (mIsPlaying) {
- if (on || mVoicemailAudioManager.isWiredHeadsetPluggedIn()) {
+ if (isPlaying) {
+ if (on || voicemailAudioManager.isWiredHeadsetPluggedIn()) {
disableProximitySensor(false /* waitForFarState */);
} else {
enableProximitySensor();
@@ -853,16 +849,16 @@ public class VoicemailPlaybackPresenter
@VisibleForTesting
public void clearInstance() {
- sInstance = null;
+ instance = null;
}
private void showShareVoicemailButton(boolean show) {
- if (mContext == null) {
+ if (context == null) {
return;
}
- if (isShareVoicemailAllowed(mContext) && shareVoicemailButtonView != null) {
+ if (isShareVoicemailAllowed(context) && shareVoicemailButtonView != null) {
if (show) {
- Logger.get(mContext).logImpression(DialerImpression.Type.VVM_SHARE_VISIBLE);
+ Logger.get(context).logImpression(DialerImpression.Type.VVM_SHARE_VISIBLE);
}
LogUtil.d("VoicemailPlaybackPresenter.showShareVoicemailButton", "show: %b", show);
shareVoicemailButtonView.setVisibility(show ? View.VISIBLE : View.GONE);
@@ -931,7 +927,7 @@ public class VoicemailPlaybackPresenter
* voicemail to a temporary file in background and launch a chooser intent to share it.
*/
public void shareVoicemail() {
- shareVoicemailExecutor.executeParallel(new Pair<>(mContext, mVoicemailUri));
+ shareVoicemailExecutor.executeParallel(new Pair<>(context, voicemailUri));
}
private static String getFileName(String cachedName, String number, String mimeType, long date) {
@@ -1052,55 +1048,55 @@ public class VoicemailPlaybackPresenter
@ThreadSafe
private class FetchResultHandler extends ContentObserver implements Runnable {
- private final Handler mFetchResultHandler;
- private final Uri mVoicemailUri;
- private AtomicBoolean mIsWaitingForResult = new AtomicBoolean(true);
+ private final Handler fetchResultHandler;
+ private final Uri voicemailUri;
+ private AtomicBoolean isWaitingForResult = new AtomicBoolean(true);
public FetchResultHandler(Handler handler, Uri uri, int code) {
super(handler);
- mFetchResultHandler = handler;
- mVoicemailUri = uri;
- if (mContext != null) {
- if (PermissionsUtil.hasReadVoicemailPermissions(mContext)) {
- mContext.getContentResolver().registerContentObserver(mVoicemailUri, false, this);
+ fetchResultHandler = handler;
+ voicemailUri = uri;
+ if (context != null) {
+ if (PermissionsUtil.hasReadVoicemailPermissions(context)) {
+ context.getContentResolver().registerContentObserver(voicemailUri, false, this);
}
- mFetchResultHandler.postDelayed(this, FETCH_CONTENT_TIMEOUT_MS);
+ fetchResultHandler.postDelayed(this, FETCH_CONTENT_TIMEOUT_MS);
}
}
/** Stop waiting for content and notify UI if {@link FETCH_CONTENT_TIMEOUT_MS} has elapsed. */
@Override
public void run() {
- if (mIsWaitingForResult.getAndSet(false) && mContext != null) {
- mContext.getContentResolver().unregisterContentObserver(this);
- if (mView != null) {
- mView.setFetchContentTimeout();
+ if (isWaitingForResult.getAndSet(false) && context != null) {
+ context.getContentResolver().unregisterContentObserver(this);
+ if (view != null) {
+ view.setFetchContentTimeout();
}
}
}
public void destroy() {
- if (mIsWaitingForResult.getAndSet(false) && mContext != null) {
- mContext.getContentResolver().unregisterContentObserver(this);
- mFetchResultHandler.removeCallbacks(this);
+ if (isWaitingForResult.getAndSet(false) && context != null) {
+ context.getContentResolver().unregisterContentObserver(this);
+ fetchResultHandler.removeCallbacks(this);
}
}
@Override
public void onChange(boolean selfChange) {
- mAsyncTaskExecutor.submit(
+ asyncTaskExecutor.submit(
Tasks.CHECK_CONTENT_AFTER_CHANGE,
new AsyncTask<Void, Void, Boolean>() {
@Override
public Boolean doInBackground(Void... params) {
- return queryHasContent(mVoicemailUri);
+ return queryHasContent(voicemailUri);
}
@Override
public void onPostExecute(Boolean hasContent) {
- if (hasContent && mContext != null && mIsWaitingForResult.getAndSet(false)) {
- mContext.getContentResolver().unregisterContentObserver(FetchResultHandler.this);
+ if (hasContent && context != null && isWaitingForResult.getAndSet(false)) {
+ context.getContentResolver().unregisterContentObserver(FetchResultHandler.this);
showShareVoicemailButton(true);
prepareContent();
}
diff --git a/java/com/android/dialer/app/voicemail/WiredHeadsetManager.java b/java/com/android/dialer/app/voicemail/WiredHeadsetManager.java
index 24d4c6ff7..2873f8d5e 100644
--- a/java/com/android/dialer/app/voicemail/WiredHeadsetManager.java
+++ b/java/com/android/dialer/app/voicemail/WiredHeadsetManager.java
@@ -20,50 +20,52 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.media.AudioManager;
-import android.util.Log;
+import com.android.dialer.common.LogUtil;
/** Listens for and caches headset state. */
class WiredHeadsetManager {
private static final String TAG = WiredHeadsetManager.class.getSimpleName();
- private final WiredHeadsetBroadcastReceiver mReceiver;
- private boolean mIsPluggedIn;
- private Listener mListener;
- private Context mContext;
+ private final WiredHeadsetBroadcastReceiver receiver;
+ private boolean isPluggedIn;
+ private Listener listener;
+ private Context context;
WiredHeadsetManager(Context context) {
- mContext = context;
- mReceiver = new WiredHeadsetBroadcastReceiver();
+ this.context = context;
+ receiver = new WiredHeadsetBroadcastReceiver();
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
- mIsPluggedIn = audioManager.isWiredHeadsetOn();
+ isPluggedIn = audioManager.isWiredHeadsetOn();
}
void setListener(Listener listener) {
- mListener = listener;
+ this.listener = listener;
}
boolean isPluggedIn() {
- return mIsPluggedIn;
+ return isPluggedIn;
}
void registerReceiver() {
// Register for misc other intent broadcasts.
IntentFilter intentFilter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
- mContext.registerReceiver(mReceiver, intentFilter);
+ context.registerReceiver(receiver, intentFilter);
}
void unregisterReceiver() {
- mContext.unregisterReceiver(mReceiver);
+ context.unregisterReceiver(receiver);
}
private void onHeadsetPluggedInChanged(boolean isPluggedIn) {
- if (mIsPluggedIn != isPluggedIn) {
- Log.v(TAG, "onHeadsetPluggedInChanged, mIsPluggedIn: " + mIsPluggedIn + " -> " + isPluggedIn);
- boolean oldIsPluggedIn = mIsPluggedIn;
- mIsPluggedIn = isPluggedIn;
- if (mListener != null) {
- mListener.onWiredHeadsetPluggedInChanged(oldIsPluggedIn, mIsPluggedIn);
+ if (this.isPluggedIn != isPluggedIn) {
+ LogUtil.v(
+ TAG,
+ "onHeadsetPluggedInChanged, mIsPluggedIn: " + this.isPluggedIn + " -> " + isPluggedIn);
+ boolean oldIsPluggedIn = this.isPluggedIn;
+ this.isPluggedIn = isPluggedIn;
+ if (listener != null) {
+ listener.onWiredHeadsetPluggedInChanged(oldIsPluggedIn, this.isPluggedIn);
}
}
}
@@ -80,7 +82,7 @@ class WiredHeadsetManager {
public void onReceive(Context context, Intent intent) {
if (AudioManager.ACTION_HEADSET_PLUG.equals(intent.getAction())) {
boolean isPluggedIn = intent.getIntExtra("state", 0) == 1;
- Log.v(TAG, "ACTION_HEADSET_PLUG event, plugged in: " + isPluggedIn);
+ LogUtil.v(TAG, "ACTION_HEADSET_PLUG event, plugged in: " + isPluggedIn);
onHeadsetPluggedInChanged(isPluggedIn);
}
}