diff options
Diffstat (limited to 'packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowManager.java')
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowManager.java | 172 |
1 files changed, 165 insertions, 7 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowManager.java index ccfa0dd..f0d7828 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowManager.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowManager.java @@ -18,19 +18,28 @@ package com.android.systemui.statusbar.phone; import android.content.Context; import android.content.pm.ActivityInfo; +import android.content.res.Configuration; import android.content.res.Resources; +import android.database.ContentObserver; +import android.graphics.Point; import android.graphics.PixelFormat; +import android.os.Handler; import android.os.SystemProperties; +import android.provider.Settings; import android.view.Gravity; +import android.view.Display; +import android.view.SurfaceSession; import android.view.View; import android.view.ViewGroup; -import android.view.Window; import android.view.WindowManager; import com.android.keyguard.R; import com.android.systemui.keyguard.KeyguardViewMediator; import com.android.systemui.statusbar.BaseStatusBar; import com.android.systemui.statusbar.StatusBarState; +import com.android.systemui.statusbar.policy.KeyguardMonitor; +import com.android.systemui.statusbar.policy.LiveLockScreenController; +import cyanogenmod.providers.CMSettings; import java.io.FileDescriptor; import java.io.PrintWriter; @@ -39,7 +48,7 @@ import java.lang.reflect.Field; /** * Encapsulates all logic for the status bar window state management. */ -public class StatusBarWindowManager { +public class StatusBarWindowManager implements KeyguardMonitor.Callback { private final Context mContext; private final WindowManager mWindowManager; @@ -47,22 +56,49 @@ public class StatusBarWindowManager { private WindowManager.LayoutParams mLp; private WindowManager.LayoutParams mLpChanged; private int mBarHeight; - private final boolean mKeyguardScreenRotation; + private boolean mKeyguardScreenRotation; private final float mScreenBrightnessDoze; + private final boolean mBlurSupported; + + private boolean mKeyguardBlurEnabled; + private boolean mShowingMedia; + private BlurLayer mKeyguardBlur; + private final SurfaceSession mFxSession; + + private final KeyguardMonitor mKeyguardMonitor; + private int mCurrentOrientation; + + private static final int TYPE_LAYER_MULTIPLIER = 10000; // refer to WindowManagerService.TYPE_LAYER_MULTIPLIER + private static final int TYPE_LAYER_OFFSET = 1000; // refer to WindowManagerService.TYPE_LAYER_OFFSET + + private static final int STATUS_BAR_LAYER = 16 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET; + private final State mCurrentState = new State(); + private LiveLockScreenController mLiveLockScreenController; - public StatusBarWindowManager(Context context) { + public StatusBarWindowManager(Context context, KeyguardMonitor kgm) { mContext = context; mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); mKeyguardScreenRotation = shouldEnableKeyguardScreenRotation(); mScreenBrightnessDoze = mContext.getResources().getInteger( com.android.internal.R.integer.config_screenBrightnessDoze) / 255f; + mBlurSupported = mContext.getResources().getBoolean( + com.android.internal.R.bool.config_ui_blur_enabled); + + mKeyguardMonitor = kgm; + mKeyguardMonitor.addCallback(this); + mFxSession = new SurfaceSession(); } private boolean shouldEnableKeyguardScreenRotation() { Resources res = mContext.getResources(); + boolean enableAccelerometerRotation = Settings.System.getInt(mContext.getContentResolver(), + Settings.System.ACCELEROMETER_ROTATION, 1) != 0; + boolean enableLockScreenRotation = CMSettings.System.getInt(mContext.getContentResolver(), + CMSettings.System.LOCKSCREEN_ROTATION, 0) != 0; return SystemProperties.getBoolean("lockscreen.rot_override", false) - || res.getBoolean(R.bool.config_enableLockScreenRotation); + || (res.getBoolean(R.bool.config_enableLockScreenRotation) + && (enableLockScreenRotation && enableAccelerometerRotation)); } /** @@ -72,7 +108,6 @@ public class StatusBarWindowManager { * @param barHeight The height of the status bar in collapsed state. */ public void add(View statusBarView, int barHeight) { - // Now that the status bar window encompasses the sliding panel and its // translucent backdrop, the entire thing is made TRANSLUCENT and is // hardware-accelerated. @@ -96,15 +131,37 @@ public class StatusBarWindowManager { mWindowManager.addView(mStatusBarView, mLp); mLpChanged = new WindowManager.LayoutParams(); mLpChanged.copyFrom(mLp); + + mKeyguardBlurEnabled = mBlurSupported ? + CMSettings.Secure.getInt(mContext.getContentResolver(), + CMSettings.Secure.LOCK_SCREEN_BLUR_ENABLED, 1) == 1 : false; + if (mBlurSupported) { + Display display = mWindowManager.getDefaultDisplay(); + Point xy = new Point(); + display.getRealSize(xy); + mCurrentOrientation = mContext.getResources().getConfiguration().orientation; + mKeyguardBlur = new BlurLayer(mFxSession, xy.x, xy.y, "KeyGuard"); + if (mKeyguardBlur != null) { + mKeyguardBlur.setLayer(STATUS_BAR_LAYER - 2); + } + } + + SettingsObserver observer = new SettingsObserver(new Handler()); + observer.observe(mContext); } private void applyKeyguardFlags(State state) { if (state.keyguardShowing) { - mLpChanged.flags |= WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; mLpChanged.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; + if (!mKeyguardBlurEnabled || mShowingMedia) { + mLpChanged.flags |= WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; + } } else { mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; mLpChanged.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; + if (mKeyguardBlurEnabled && mKeyguardBlur != null) { + mKeyguardBlur.hide(); + } } } @@ -217,13 +274,33 @@ public class StatusBarWindowManager { } } + private void applyKeyguardBlurShow(){ + boolean isblur = false; + if (mCurrentState.keyguardShowing && mKeyguardBlurEnabled + && !mCurrentState.keyguardOccluded + && !mShowingMedia) { + isblur = true; + } + if (mKeyguardBlur != null) { + if (isblur) { + mKeyguardBlur.show(); + } else { + mKeyguardBlur.hide(); + } + } + } + public void setKeyguardShowing(boolean showing) { mCurrentState.keyguardShowing = showing; apply(mCurrentState); } public void setKeyguardOccluded(boolean occluded) { + final boolean oldOccluded = mCurrentState.keyguardOccluded; mCurrentState.keyguardOccluded = occluded; + if (oldOccluded != occluded) { + applyKeyguardBlurShow(); + } apply(mCurrentState); } @@ -263,6 +340,39 @@ public class StatusBarWindowManager { apply(mCurrentState); } + void setBlur(float b){ + if (mKeyguardBlurEnabled && mKeyguardBlur != null) { + float minBlur = mKeyguardMonitor.isSecure() ? 1.0f : 0.0f; + if (b < minBlur) { + b = minBlur; + } else if (b > 1.0f) { + b = 1.0f; + } + mKeyguardBlur.setBlur(b); + } + } + + public void setShowingMedia(boolean showingMedia) { + mShowingMedia = showingMedia; + applyKeyguardBlurShow(); + } + + public void setKeyguardExternalViewFocus(boolean hasFocus) { + mLiveLockScreenController.onLiveLockScreenFocusChanged(hasFocus); + // make the keyguard occluded so the external view gets full focus + setKeyguardOccluded(hasFocus); + } + + public void onConfigurationChanged(Configuration newConfig) { + if (mKeyguardBlur != null && newConfig.orientation != mCurrentOrientation) { + Display display = mWindowManager.getDefaultDisplay(); + Point xy = new Point(); + display.getRealSize(xy); + mKeyguardBlur.setSize(xy.x, xy.y); + mCurrentOrientation = newConfig.orientation; + } + } + /** * @param state The {@link StatusBarState} of the status bar. */ @@ -300,11 +410,24 @@ public class StatusBarWindowManager { apply(mCurrentState); } + @Override + public void onKeyguardChanged() { + applyKeyguardBlurShow(); + } + public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { pw.println("StatusBarWindowManager state:"); pw.println(mCurrentState); } + public boolean keyguardExternalViewHasFocus() { + return mLiveLockScreenController.getLiveLockScreenHasFocus(); + } + + public void setLiveLockscreenController(LiveLockScreenController liveLockScreenController) { + mLiveLockScreenController = liveLockScreenController; + } + private static class State { boolean keyguardShowing; boolean keyguardOccluded; @@ -355,4 +478,39 @@ public class StatusBarWindowManager { return result.toString(); } } + + private class SettingsObserver extends ContentObserver { + public SettingsObserver(Handler handler) { + super(handler); + } + + public void observe(Context context) { + context.getContentResolver().registerContentObserver( + CMSettings.Secure.getUriFor(CMSettings.Secure.LOCK_SCREEN_BLUR_ENABLED), + false, + this); + context.getContentResolver().registerContentObserver( + Settings.System.getUriFor(Settings.System.ACCELEROMETER_ROTATION), + false, + this); + context.getContentResolver().registerContentObserver( + CMSettings.System.getUriFor(CMSettings.System.LOCKSCREEN_ROTATION), + false, + this); + } + + public void unobserve(Context context) { + context.getContentResolver().unregisterContentObserver(this); + } + + @Override + public void onChange(boolean selfChange) { + mKeyguardBlurEnabled = mBlurSupported ? + CMSettings.Secure.getInt(mContext.getContentResolver(), + CMSettings.Secure.LOCK_SCREEN_BLUR_ENABLED, 1) == 1 : false; + mKeyguardScreenRotation = shouldEnableKeyguardScreenRotation(); + // update the state + apply(mCurrentState); + } + } } |