diff options
author | Danny Baumann <dannybaumann@web.de> | 2013-06-30 14:42:10 +0200 |
---|---|---|
committer | Danny Baumann <dannybaumann@web.de> | 2013-07-02 09:16:01 +0200 |
commit | 5a96c12a4d16a00c49556adc4955d7cf9475aa2b (patch) | |
tree | e7b0290213aad759b034c6620063ebd51274c3b0 /policy/src | |
parent | 9e3fa9cb673f69aa69de0294bebba61d10befddc (diff) | |
download | frameworks_base-5a96c12a4d16a00c49556adc4955d7cf9475aa2b.zip frameworks_base-5a96c12a4d16a00c49556adc4955d7cf9475aa2b.tar.gz frameworks_base-5a96c12a4d16a00c49556adc4955d7cf9475aa2b.tar.bz2 |
Add option to hide music controls in lockscreen.
JIRA:CYAN-1566
Change-Id: Iae3dd9914b1685c6bf1e39e421372ce0bdfb93cc
Diffstat (limited to 'policy/src')
-rw-r--r-- | policy/src/com/android/internal/policy/impl/keyguard/KeyguardTransportControlView.java | 74 |
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 { |