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

Commit cf7e4a7e authored by Danesh M's avatar Danesh M
Browse files

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
parent 8a9f3161
Loading
Loading
Loading
Loading
+43 −3
Original line number Original line Diff line number Diff line
@@ -38,6 +38,7 @@ import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Build;
import android.os.IBinder;
import android.os.IBinder;
import android.os.IPowerManager;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.Handler;
import android.os.Handler;
import android.os.Message;
import android.os.Message;
@@ -134,6 +135,8 @@ public class PhoneStatusBar extends StatusBar {


    private float mExpandAccelPx; // classic value: 2000px/s/s
    private float mExpandAccelPx; // classic value: 2000px/s/s
    private float mCollapseAccelPx; // classic value: 2000px/s/s (will be negated to collapse "up")
    private float mCollapseAccelPx; // classic value: 2000px/s/s (will be negated to collapse "up")
    private float mScreenWidth;
    private int mMinBrightness;


    PhoneStatusBarPolicy mIconPolicy;
    PhoneStatusBarPolicy mIconPolicy;


@@ -226,6 +229,7 @@ public class PhoneStatusBar extends StatusBar {
    boolean mAnimatingReveal = false;
    boolean mAnimatingReveal = false;
    int mViewDelta;
    int mViewDelta;
    int[] mAbsPos = new int[2];
    int[] mAbsPos = new int[2];
    int mLinger = 0;
    Runnable mPostCollapseCleanup = null;
    Runnable mPostCollapseCleanup = null;




@@ -286,7 +290,9 @@ public class PhoneStatusBar extends StatusBar {
        loadDimens();
        loadDimens();


        mIconSize = res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_icon_size);
        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,
        ExpandedView expanded = (ExpandedView)View.inflate(context,
                R.layout.status_bar_expanded, null);
                R.layout.status_bar_expanded, null);
        if (DEBUG) {
        if (DEBUG) {
@@ -1499,6 +1505,7 @@ public class PhoneStatusBar extends StatusBar {
        final int hitSize = statusBarSize*2;
        final int hitSize = statusBarSize*2;
        final int y = (int)event.getRawY();
        final int y = (int)event.getRawY();
        if (action == MotionEvent.ACTION_DOWN) {
        if (action == MotionEvent.ACTION_DOWN) {
            mLinger = 0;
            if (!mExpanded) {
            if (!mExpanded) {
                mViewDelta = statusBarSize - y;
                mViewDelta = statusBarSize - y;
            } else {
            } else {
@@ -1523,7 +1530,40 @@ public class PhoneStatusBar extends StatusBar {
            final int minY = statusBarSize + mCloseView.getHeight();
            final int minY = statusBarSize + mCloseView.getHeight();
            if (action == MotionEvent.ACTION_MOVE) {
            if (action == MotionEvent.ACTION_MOVE) {
                if (mAnimatingReveal && y < minY) {
                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 {
                } else {
                    mAnimatingReveal = false;
                    mAnimatingReveal = false;
                    updateExpandedViewPos(y + mViewDelta);
                    updateExpandedViewPos(y + mViewDelta);