diff options
author | Andrew Lee <anwlee@google.com> | 2015-05-13 12:23:35 -0700 |
---|---|---|
committer | Andrew Lee <anwlee@google.com> | 2015-05-13 12:29:11 -0700 |
commit | 93b816f753b67157f14a8389dc63f32cff40c8d4 (patch) | |
tree | 48d0c49acdbf729baa756bb02a59d780a3a76f97 /src | |
parent | 91dc991cecfd283b2cf58dbe45dc7c6e6c58ed39 (diff) |
Move proximity sensor logic into VM fragment.
In preparation for moving it from the CallDetailActivity into
the call log. Seems to make sense to consolidate this within the
fragment in any case.
Bug: 20433758
Change-Id: I1aa0cd9a766fac3e1eb9285d31df5ed90523b8ad
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/dialer/CallDetailActivity.java | 45 | ||||
-rw-r--r-- | src/com/android/dialer/ProximitySensorAware.java | 33 | ||||
-rw-r--r-- | src/com/android/dialer/voicemail/VoicemailPlaybackFragment.java | 64 |
3 files changed, 51 insertions, 91 deletions
diff --git a/src/com/android/dialer/CallDetailActivity.java b/src/com/android/dialer/CallDetailActivity.java index 0a295c4fe..536a97cca 100644 --- a/src/com/android/dialer/CallDetailActivity.java +++ b/src/com/android/dialer/CallDetailActivity.java @@ -80,7 +80,7 @@ import java.util.List; * This activity can be either started with the URI of a single call log entry, or with the * {@link #EXTRA_CALL_LOG_IDS} extra to specify a group of call log entries. */ -public class CallDetailActivity extends Activity implements ProximitySensorAware { +public class CallDetailActivity extends Activity { private static final String TAG = "CallDetail"; private static final char LEFT_TO_RIGHT_EMBEDDING = '\u202A'; @@ -142,8 +142,6 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware /** Whether we should show "remove from call log" in the options menu. */ private boolean mHasRemoveFromCallLogOption; - private PowerManager.WakeLock mProximityWakeLock; - static final String[] CALL_LOG_PROJECTION = new String[] { CallLog.Calls.DATE, CallLog.Calls.DURATION, @@ -197,13 +195,6 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware mAccountLabel = (TextView) findViewById(R.id.phone_account_label); mDefaultCountryIso = GeoUtil.getCurrentCountryIso(this); mContactPhotoManager = ContactPhotoManager.getInstance(this); - final PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); - if (powerManager.isWakeLockLevelSupported(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK)) { - mProximityWakeLock = powerManager.newWakeLock( - PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, TAG); - } else { - mProximityWakeLock = null; - } mContactInfoHelper = new ContactInfoHelper(this, GeoUtil.getCurrentCountryIso(this)); getActionBar().setDisplayHomeAsUpEnabled(true); @@ -707,40 +698,6 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware ); } - @Override - protected void onPause() { - // Immediately stop the proximity sensor. - disableProximitySensor(false); - super.onPause(); - } - - @Override - public void enableProximitySensor() { - if (mProximityWakeLock == null) { - return; - } - if (!mProximityWakeLock.isHeld()) { - Log.i(TAG, "Acquiring proximity wake lock"); - mProximityWakeLock.acquire(); - } else { - Log.i(TAG, "Proximity wake lock already acquired"); - } - } - - @Override - public void disableProximitySensor(boolean waitForFarState) { - if (mProximityWakeLock == null) { - return; - } - if (mProximityWakeLock.isHeld()) { - Log.i(TAG, "Releasing proximity wake lock"); - int flags = (waitForFarState ? PowerManager.RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY : 0); - mProximityWakeLock.release(flags); - } else { - Log.i(TAG, "Proximity wake lock already released"); - } - } - private void closeSystemDialogs() { sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); } diff --git a/src/com/android/dialer/ProximitySensorAware.java b/src/com/android/dialer/ProximitySensorAware.java deleted file mode 100644 index 145b8606c..000000000 --- a/src/com/android/dialer/ProximitySensorAware.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2011 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.dialer; - -/** - * An object that is aware of the state of the proximity sensor. - */ -public interface ProximitySensorAware { - /** Start tracking the state of the proximity sensor. */ - public void enableProximitySensor(); - - /** - * Stop tracking the state of the proximity sensor. - * - * @param waitForFarState if true and the sensor is currently in the near state, it will wait - * until it is again in the far state before stopping to track its state. - */ - public void disableProximitySensor(boolean waitForFarState); -} diff --git a/src/com/android/dialer/voicemail/VoicemailPlaybackFragment.java b/src/com/android/dialer/voicemail/VoicemailPlaybackFragment.java index 0d5c3deed..fd98688f1 100644 --- a/src/com/android/dialer/voicemail/VoicemailPlaybackFragment.java +++ b/src/com/android/dialer/voicemail/VoicemailPlaybackFragment.java @@ -41,7 +41,6 @@ import android.widget.TextView; import com.android.common.io.MoreCloseables; import com.android.contacts.commonbind.analytics.AnalyticsUtil; -import com.android.dialer.ProximitySensorAware; import com.android.dialer.R; import com.android.dialer.util.AsyncTaskExecutors; import com.android.ex.variablespeed.MediaPlayerProxy; @@ -68,7 +67,7 @@ import javax.annotation.concurrent.NotThreadSafe; */ @NotThreadSafe public class VoicemailPlaybackFragment extends Fragment { - private static final String TAG = "VoicemailPlayback"; + private static final String TAG = VoicemailPlaybackFragment.class.getSimpleName(); private static final int NUMBER_OF_THREADS_IN_POOL = 2; private static final String[] HAS_CONTENT_PROJECTION = new String[] { VoicemailContract.Voicemails.HAS_CONTENT, @@ -80,6 +79,8 @@ public class VoicemailPlaybackFragment extends Fragment { private static ScheduledExecutorService mScheduledExecutorService; private View mPlaybackLayout; + private PowerManager.WakeLock mProximityWakeLock; + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -95,15 +96,24 @@ public class VoicemailPlaybackFragment extends Fragment { Uri voicemailUri = arguments.getParcelable(EXTRA_VOICEMAIL_URI); Preconditions.checkNotNull(voicemailUri, "fragment must contain EXTRA_VOICEMAIL_URI"); boolean startPlayback = arguments.getBoolean(EXTRA_VOICEMAIL_START_PLAYBACK, false); + PowerManager powerManager = (PowerManager) getActivity().getSystemService(Context.POWER_SERVICE); - PowerManager.WakeLock wakeLock = - powerManager.newWakeLock( - PowerManager.SCREEN_DIM_WAKE_LOCK, getClass().getSimpleName()); - mPresenter = new VoicemailPlaybackPresenter(createPlaybackViewImpl(), - getMediaPlayerInstance(), voicemailUri, - getScheduledExecutorServiceInstance(), startPlayback, - AsyncTaskExecutors.createAsyncTaskExecutor(), wakeLock); + if (powerManager.isWakeLockLevelSupported(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK)) { + mProximityWakeLock = powerManager.newWakeLock( + PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, TAG); + } else { + mProximityWakeLock = null; + } + + mPresenter = new VoicemailPlaybackPresenter( + createPlaybackViewImpl(), + getMediaPlayerInstance(), + voicemailUri, + getScheduledExecutorServiceInstance(), + startPlayback, + AsyncTaskExecutors.createAsyncTaskExecutor(), + mProximityWakeLock); mPresenter.onCreate(savedInstanceState); } @@ -134,6 +144,7 @@ public class VoicemailPlaybackFragment extends Fragment { @Override public void onPause() { + releaseProximitySensor(false /* waitForFarState */); mPresenter.onPause(); super.onPause(); } @@ -175,6 +186,31 @@ public class VoicemailPlaybackFragment extends Fragment { } } + private void acquireProximitySensor() { + if (mProximityWakeLock == null) { + return; + } + if (!mProximityWakeLock.isHeld()) { + Log.i(TAG, "Acquiring proximity wake lock"); + mProximityWakeLock.acquire(); + } else { + Log.i(TAG, "Proximity wake lock already acquired"); + } + } + + private void releaseProximitySensor(boolean waitForFarState) { + if (mProximityWakeLock == null) { + return; + } + if (mProximityWakeLock.isHeld()) { + Log.i(TAG, "Releasing proximity wake lock"); + int flags = waitForFarState ? PowerManager.RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY : 0; + mProximityWakeLock.release(flags); + } else { + Log.i(TAG, "Proximity wake lock already released"); + } + } + /** * Formats a number of milliseconds as something that looks like {@code 00:05}. * <p> @@ -214,7 +250,7 @@ public class VoicemailPlaybackFragment extends Fragment { } /** Methods required by the PlaybackView for the VoicemailPlaybackPresenter. */ - private static final class PlaybackViewImpl implements VoicemailPlaybackPresenter.PlaybackView { + private final class PlaybackViewImpl implements VoicemailPlaybackPresenter.PlaybackView { private final ActivityReference mActivityReference; private final Context mApplicationContext; private final SeekBar mPlaybackSeek; @@ -311,8 +347,8 @@ public class VoicemailPlaybackFragment extends Fragment { public void enableProximitySensor() { // Only change the state if the activity is still around. Activity activity = mActivityReference.get(); - if (activity != null && activity instanceof ProximitySensorAware) { - ((ProximitySensorAware) activity).enableProximitySensor(); + if (activity != null) { + acquireProximitySensor(); } } @@ -320,8 +356,8 @@ public class VoicemailPlaybackFragment extends Fragment { public void disableProximitySensor() { // Only change the state if the activity is still around. Activity activity = mActivityReference.get(); - if (activity != null && activity instanceof ProximitySensorAware) { - ((ProximitySensorAware) activity).disableProximitySensor(true); + if (activity != null) { + releaseProximitySensor(true /* waitForFarState */); } } |