diff options
author | Danesh M <daneshm90@gmail.com> | 2011-12-25 18:38:22 -0500 |
---|---|---|
committer | Danesh M <daneshm90@gmail.com> | 2012-02-02 23:13:30 -0500 |
commit | cf7e4a7eaa4107ffdc46c763813d43fedfef6a5f (patch) | |
tree | daa367d5b9f00246f60978d8d81ac3d6be8ad7f0 /packages/SystemUI/src/com/android | |
parent | 8a9f3161d983b131a857e58141c4e7ff69a94fea (diff) | |
download | frameworks_base-cf7e4a7eaa4107ffdc46c763813d43fedfef6a5f.zip frameworks_base-cf7e4a7eaa4107ffdc46c763813d43fedfef6a5f.tar.gz frameworks_base-cf7e4a7eaa4107ffdc46c763813d43fedfef6a5f.tar.bz2 |
Statusbar slide brightness control
This allows the ability to control brightness by sliding across the statusbar.
Patchset 2 : Cleanup as per suggestions.
Removed duplicate key from Settings, after settings merge
Reduce mLinger threshold (Need feedback on whether its too sensitive for some)
Patchset 3,4 : Minor cleanup
Patchset 5 : Cleanup as per comments
Patchset 6 : Remove unused import
Avoid unecessary gc of unchanging variables (make them instance variables)
Patchset 7 : Cleanup
Change-Id: I19ee7de07be7bfeabde3fb2ae3c60ebdbb4afd72
Diffstat (limited to 'packages/SystemUI/src/com/android')
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java | 46 |
1 files changed, 43 insertions, 3 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 d46ea93..0175f13 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java @@ -38,6 +38,7 @@ import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.IBinder; +import android.os.IPowerManager; import android.os.RemoteException; import android.os.Handler; import android.os.Message; @@ -134,6 +135,8 @@ public class PhoneStatusBar extends StatusBar { private float mExpandAccelPx; // classic value: 2000px/s/s private float mCollapseAccelPx; // classic value: 2000px/s/s (will be negated to collapse "up") + private float mScreenWidth; + private int mMinBrightness; PhoneStatusBarPolicy mIconPolicy; @@ -226,6 +229,7 @@ public class PhoneStatusBar extends StatusBar { boolean mAnimatingReveal = false; int mViewDelta; int[] mAbsPos = new int[2]; + int mLinger = 0; Runnable mPostCollapseCleanup = null; @@ -286,7 +290,9 @@ public class PhoneStatusBar extends StatusBar { loadDimens(); mIconSize = res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_icon_size); - + mScreenWidth = (float) context.getResources().getDisplayMetrics().widthPixels; + mMinBrightness = context.getResources().getInteger( + com.android.internal.R.integer.config_screenBrightnessDim); ExpandedView expanded = (ExpandedView)View.inflate(context, R.layout.status_bar_expanded, null); if (DEBUG) { @@ -1499,6 +1505,7 @@ public class PhoneStatusBar extends StatusBar { final int hitSize = statusBarSize*2; final int y = (int)event.getRawY(); if (action == MotionEvent.ACTION_DOWN) { + mLinger = 0; if (!mExpanded) { mViewDelta = statusBarSize - y; } else { @@ -1523,8 +1530,41 @@ public class PhoneStatusBar extends StatusBar { final int minY = statusBarSize + mCloseView.getHeight(); if (action == MotionEvent.ACTION_MOVE) { if (mAnimatingReveal && y < minY) { - // nothing - } else { + 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); + } + } + } else { + mLinger++; + } + } else { + mLinger = 0; + } + } + } else { mAnimatingReveal = false; updateExpandedViewPos(y + mViewDelta); } |