summaryrefslogtreecommitdiffstats
path: root/policy
diff options
context:
space:
mode:
authorDavid van Tonder <david.vantonder@gmail.com>2013-07-02 10:54:23 -0700
committerGerrit Code Review <gerrit@cyanogenmod.org>2013-07-02 10:54:23 -0700
commitfcf0fd60fdceec638722b62427223db8b4fd66a5 (patch)
tree8010dbbf2b2d3609fae54863747ee76765264762 /policy
parent4e3a324eaa56759df05029dc2f51fbc6bc00eb7f (diff)
parent5a96c12a4d16a00c49556adc4955d7cf9475aa2b (diff)
downloadframeworks_base-fcf0fd60fdceec638722b62427223db8b4fd66a5.zip
frameworks_base-fcf0fd60fdceec638722b62427223db8b4fd66a5.tar.gz
frameworks_base-fcf0fd60fdceec638722b62427223db8b4fd66a5.tar.bz2
Merge "Add option to hide music controls in lockscreen." into cm-10.1
Diffstat (limited to 'policy')
-rw-r--r--policy/src/com/android/internal/policy/impl/keyguard/KeyguardTransportControlView.java74
1 files changed, 65 insertions, 9 deletions
diff --git a/policy/src/com/android/internal/policy/impl/keyguard/KeyguardTransportControlView.java b/policy/src/com/android/internal/policy/impl/keyguard/KeyguardTransportControlView.java
index ffa88d5..e8ee81e 100644
--- a/policy/src/com/android/internal/policy/impl/keyguard/KeyguardTransportControlView.java
+++ b/policy/src/com/android/internal/policy/impl/keyguard/KeyguardTransportControlView.java
@@ -20,6 +20,7 @@ import android.app.PendingIntent;
import android.app.PendingIntent.CanceledException;
import android.content.Context;
import android.content.Intent;
+import android.database.ContentObserver;
import android.graphics.Bitmap;
import android.media.AudioManager;
import android.media.IRemoteControlDisplay;
@@ -32,6 +33,8 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.os.RemoteException;
import android.os.SystemClock;
+import android.os.UserHandle;
+import android.provider.Settings;
import android.text.Spannable;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
@@ -75,6 +78,8 @@ public class KeyguardTransportControlView extends FrameLayout implements OnClick
private AudioManager mAudioManager;
private IRemoteControlDisplayWeak mIRCD;
private boolean mMusicClientPresent = true;
+ private boolean mShouldBeShown = true;
+ private boolean mAttachNotified = false;
/**
* The metadata which should be populated into the view once we've been attached
@@ -126,6 +131,20 @@ public class KeyguardTransportControlView extends FrameLayout implements OnClick
};
private KeyguardHostView.TransportCallback mTransportCallback;
+ private ContentObserver mSettingsObserver = new ContentObserver(mHandler) {
+ @Override
+ public void onChange(boolean selfChange) {
+ updateSettings();
+ }
+ };
+
+ KeyguardUpdateMonitorCallback mUpdateCallback = new KeyguardUpdateMonitorCallback() {
+ @Override
+ public void onUserSwitched(int userId) {
+ updateSettings();
+ }
+ };
+
/**
* This class is required to have weak linkage to the current TransportControlView
* because the remote process can hold a strong reference to this binder object and
@@ -198,20 +217,48 @@ public class KeyguardTransportControlView extends FrameLayout implements OnClick
protected void onListenerDetached() {
mMusicClientPresent = false;
if (DEBUG) Log.v(TAG, "onListenerDetached()");
- if (mTransportCallback != null) {
- mTransportCallback.onListenerDetached();
- } else {
- Log.w(TAG, "onListenerDetached: no callback");
- }
+ callCallbackIfNeeded();
}
private void onListenerAttached() {
mMusicClientPresent = true;
if (DEBUG) Log.v(TAG, "onListenerAttached()");
- if (mTransportCallback != null) {
+ callCallbackIfNeeded();
+ }
+
+ private void updateSettings() {
+ boolean oldShown = mShouldBeShown;
+ mShouldBeShown = Settings.System.getIntForUser(mContext.getContentResolver(),
+ Settings.System.LOCKSCREEN_MUSIC_CONTROLS, 1, UserHandle.USER_CURRENT) != 0;
+ if (DEBUG) Log.v(TAG, "updateSettings(): mShouldBeShown=" + mShouldBeShown);
+ if (oldShown != mShouldBeShown) {
+ callCallbackIfNeeded();
+ if (mShouldBeShown && mMusicClientPresent
+ && mCurrentPlayState != RemoteControlClient.PLAYSTATE_NONE) {
+ // send out the play state change event that we suppressed earlier
+ mTransportCallback.onPlayStateChanged();
+ }
+ }
+ }
+
+ private void callCallbackIfNeeded() {
+ if (mTransportCallback == null) {
+ Log.w(TAG, "callCallbackIfNeeded: no callback");
+ return;
+ }
+
+ boolean shouldBeAttached = mMusicClientPresent && mShouldBeShown;
+ if (DEBUG) {
+ Log.v(TAG, "callCallbackIfNeeded(): shouldBeAttached=" + shouldBeAttached +
+ ", mAttachNotified=" + mAttachNotified);
+ }
+
+ if (shouldBeAttached && !mAttachNotified) {
mTransportCallback.onListenerAttached();
- } else {
- Log.w(TAG, "onListenerAttached(): no callback");
+ mAttachNotified = true;
+ } else if (!shouldBeAttached && mAttachNotified) {
+ mTransportCallback.onListenerDetached();
+ mAttachNotified = false;
}
}
@@ -245,6 +292,11 @@ public class KeyguardTransportControlView extends FrameLayout implements OnClick
if (!mAttached) {
if (DEBUG) Log.v(TAG, "Registering TCV " + this);
mAudioManager.registerRemoteControlDisplay(mIRCD);
+ KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mUpdateCallback);
+ mContext.getContentResolver().registerContentObserver(
+ Settings.System.getUriFor(Settings.System.LOCKSCREEN_MUSIC_CONTROLS),
+ false, mSettingsObserver);
+ updateSettings();
}
mAttached = true;
}
@@ -256,6 +308,8 @@ public class KeyguardTransportControlView extends FrameLayout implements OnClick
if (mAttached) {
if (DEBUG) Log.v(TAG, "Unregistering TCV " + this);
mAudioManager.unregisterRemoteControlDisplay(mIRCD);
+ KeyguardUpdateMonitor.getInstance(mContext).removeCallback(mUpdateCallback);
+ mContext.getContentResolver().unregisterContentObserver(mSettingsObserver);
}
mAttached = false;
}
@@ -381,7 +435,9 @@ public class KeyguardTransportControlView extends FrameLayout implements OnClick
mBtnPlay.setImageResource(imageResId);
mBtnPlay.setContentDescription(getResources().getString(imageDescId));
mCurrentPlayState = state;
- mTransportCallback.onPlayStateChanged();
+ if (mShouldBeShown) {
+ mTransportCallback.onPlayStateChanged();
+ }
}
static class SavedState extends BaseSavedState {