Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 74a82726 authored by Steve Kondik's avatar Steve Kondik Committed by Gerrit Code Review
Browse files

Merge "Statusbar slide brightness control" into ics

parents 56297e25 cf7e4a7e
Loading
Loading
Loading
Loading
+43 −3
Original line number Diff line number Diff line
@@ -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,7 +1530,40 @@ public class PhoneStatusBar extends StatusBar {
            final int minY = statusBarSize + mCloseView.getHeight();
            if (action == MotionEvent.ACTION_MOVE) {
                if (mAnimatingReveal && y < minY) {
                    // nothing
                        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);