diff options
author | nebkat <nebkat@teamhacksung.org> | 2012-02-22 16:29:13 +0000 |
---|---|---|
committer | nebkat <nebkat@teamhacksung.org> | 2012-03-01 19:54:43 +0000 |
commit | d16ec2bb69411991121c43f157872df57da82152 (patch) | |
tree | feaf6f675333671e4ce4be962fa19614a77461f8 /packages | |
parent | 12be70374da2e62249b9b23d06be7856263c875d (diff) | |
download | frameworks_base-d16ec2bb69411991121c43f157872df57da82152.zip frameworks_base-d16ec2bb69411991121c43f157872df57da82152.tar.gz frameworks_base-d16ec2bb69411991121c43f157872df57da82152.tar.bz2 |
Clean up status bar brightness control code
Change-Id: Iab1694cd4d98b4d33bbfb08c91ed0d48f421503b
Diffstat (limited to 'packages')
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java | 86 |
1 files changed, 57 insertions, 29 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java index 01e52a9..e72a741 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java @@ -33,6 +33,7 @@ import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.Resources; import android.content.res.Configuration; +import android.database.ContentObserver; import android.graphics.PixelFormat; import android.graphics.Rect; import android.graphics.drawable.Drawable; @@ -123,6 +124,8 @@ public class PhoneStatusBar extends StatusBar { private static final boolean CLOSE_PANEL_WHEN_EMPTIED = true; private boolean mShowClock; + private boolean mBrightnessControl; + private boolean mAutoBrightness; // fling gesture tuning parameters, scaled to display density private float mSelfExpandVelocityPx; // classic value: 2000px/s @@ -241,6 +244,35 @@ public class PhoneStatusBar extends StatusBar { DisplayMetrics mDisplayMetrics = new DisplayMetrics(); + class SettingsObserver extends ContentObserver { + SettingsObserver(Handler handler) { + super(handler); + } + + void observe() { + ContentResolver resolver = mContext.getContentResolver(); + resolver.registerContentObserver(Settings.System.getUriFor( + Settings.System.STATUS_BAR_BRIGHTNESS_TOGGLE), false, this); + resolver.registerContentObserver(Settings.System.getUriFor( + Settings.System.SCREEN_BRIGHTNESS_MODE), false, this); + update(); + } + + @Override + public void onChange(boolean selfChange) { + update(); + } + + public void update() { + ContentResolver resolver = mContext.getContentResolver(); + mBrightnessControl = Settings.System.getInt(resolver, + Settings.System.STATUS_BAR_BRIGHTNESS_TOGGLE, 0) != 0; + mAutoBrightness = Settings.System.getInt(resolver, + Settings.System.SCREEN_BRIGHTNESS_MODE, 0) == + Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC; + } + } + private class ExpandedDialog extends Dialog { ExpandedDialog(Context context) { super(context, com.android.internal.R.style.Theme_Translucent_NoTitleBar); @@ -274,6 +306,9 @@ public class PhoneStatusBar extends StatusBar { //addIntruderView(); + SettingsObserver observer = new SettingsObserver(mHandler); + observer.observe(); + // Lastly, call to the icon policy to install/update all the icons. mIconPolicy = new PhoneStatusBarPolicy(mContext); } @@ -1531,40 +1566,33 @@ public class PhoneStatusBar extends StatusBar { final int minY = statusBarSize + mCloseView.getHeight(); if (action == MotionEvent.ACTION_MOVE) { if (mAnimatingReveal && y < minY) { - boolean brightnessControl = Settings.System.getInt(mStatusBarView.getContext().getContentResolver(), - Settings.System.STATUS_BAR_BRIGHTNESS_TOGGLE, 0) == 1; - if (brightnessControl){ - mVelocityTracker.computeCurrentVelocity(1000); - float yVel = mVelocityTracker.getYVelocity(); - yVel = Math.abs(yVel); - if (yVel < 50.0f) { - if (mLinger > 20) { - Context context = mStatusBarView.getContext(); - boolean autoBrightness = Settings.System.getInt(context.getContentResolver(), - Settings.System.SCREEN_BRIGHTNESS_MODE, 0) == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC; - if (!autoBrightness) { - float x = (float) event.getRawX(); - int newBrightness = (int) Math.round(((x/mScreenWidth) * android.os.Power.BRIGHTNESS_ON)); - newBrightness = Math.min(newBrightness, android.os.Power.BRIGHTNESS_ON); - newBrightness = Math.max(newBrightness, mMinBrightness); - try { - IPowerManager power = IPowerManager.Stub.asInterface(ServiceManager.getService("power")); - if (power != null) { - power.setBacklightBrightness(newBrightness); - Settings.System.putInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, - newBrightness); - } - } catch (RemoteException e) { - Slog.w(TAG, "Setting Brightness failed: " + e); - } + if (mBrightnessControl && !mAutoBrightness) { + mVelocityTracker.computeCurrentVelocity(1000); + float yVel = mVelocityTracker.getYVelocity(); + yVel = Math.abs(yVel); + if (yVel < 50.0f) { + if (mLinger > 20) { + float x = (float) event.getRawX(); + int newBrightness = (int) Math.round(((x / mScreenWidth) * android.os.Power.BRIGHTNESS_ON)); + newBrightness = Math.min(newBrightness, android.os.Power.BRIGHTNESS_ON); + newBrightness = Math.max(newBrightness, mMinBrightness); + try { + IPowerManager power = IPowerManager.Stub.asInterface(ServiceManager.getService("power")); + if (power != null) { + power.setBacklightBrightness(newBrightness); + Settings.System.putInt(mContext.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, + newBrightness); } - } else { - mLinger++; + } catch (RemoteException e) { + Slog.w(TAG, "Setting Brightness failed: " + e); } } else { - mLinger = 0; + mLinger++; } + } else { + mLinger = 0; } + } } else { mAnimatingReveal = false; updateExpandedViewPos(y + mViewDelta); |