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

Commit 4b55c80e authored by Danesh's avatar Danesh Committed by Steve Kondik
Browse files

This allows the ability to control brightness by sliding

across the statusbar.

The original work was done daryelv on his github : https://github.com/daryelv/android_frameworks_base

However author didn't have time to submit / make it configurable through cm parts. So i took up the project,

rebased it on 2.3.4 and allowed it to be configurable via cmparts.

Option can be found under Cm Parts -> Interface -> Status Bar Tweaks

Change-Id: I202e3641bcea5dd90daaab2cf804d59b40724df4
parent 33dd309f
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -2311,6 +2311,13 @@ public final class Settings {
         */
        public static final String STATUS_BAR_COMPACT_CARRIER = "status_bar_compact_carrier";

         /**
         * Whether to control brightness from status bar
         *
         * @hide
         */
        public static final String STATUS_BAR_BRIGHTNESS_TOGGLE = "status_bar_brightness_toggle";

        /**
         * Whether to wake the screen with the trackball. The value is boolean (1 or 0).
         * @hide
+62 −3
Original line number Diff line number Diff line
@@ -24,7 +24,8 @@ import com.android.internal.statusbar.StatusBarNotification;
import com.android.systemui.statusbar.CmBatteryMiniIcon.SettingsObserver;
import com.android.systemui.statusbar.powerwidget.PowerWidget;
import com.android.systemui.R;

import android.os.IPowerManager;
import android.provider.Settings.SettingNotFoundException;
import android.app.ActivityManagerNative;
import android.app.Dialog;
import android.app.Notification;
@@ -247,6 +248,9 @@ public class StatusBarService extends Service implements CommandQueue.Callbacks
        }
    }

    // for brightness control on status bar
    int mLinger = 0;

    private class ExpandedDialog extends Dialog {
        ExpandedDialog(Context context) {
            super(context, com.android.internal.R.style.Theme_Light_NoTitleBar);
@@ -1154,7 +1158,7 @@ public class StatusBarService extends Service implements CommandQueue.Callbacks
        final int hitSize = statusBarSize*2;
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            final int y = (int)event.getRawY();

            mLinger = 0;
            if (!mExpanded) {
                mViewDelta = mBottomBar ? mDisplay.getHeight() - y : statusBarSize - y;
            } else {
@@ -1195,7 +1199,62 @@ public class StatusBarService extends Service implements CommandQueue.Callbacks
                int y = (int)event.getRawY();
                if ((!mBottomBar && mAnimatingReveal && y < minY) ||
                        (mBottomBar && mAnimatingReveal && y > minY)) {
                    // nothing
                        try {
                                if (Settings.System.getInt(mStatusBarView.getContext().getContentResolver(),Settings.System.STATUS_BAR_BRIGHTNESS_TOGGLE) == 1){
                                        //Credit for code goes to daryelv github : https://github.com/daryelv/android_frameworks_base
                                        // See if finger is moving left/right an adequate amount
                                        mVelocityTracker.computeCurrentVelocity(1000);
                                        float yVel = mVelocityTracker.getYVelocity();
                                        if (yVel < 0) {
                                                yVel = -yVel;
                                        }
                                        if (yVel < 50.0f) {
                                                if (mLinger > 50) {
                                                        // Check that Auto-Brightness not enabled
                                                        Context context = mStatusBarView.getContext();
                                                        boolean auto_brightness = false;
                                                        int brightness_mode = 0;
                                                        try {
                                                                brightness_mode = Settings.System.getInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE);
                                                        }catch (SettingNotFoundException e){
                                                                auto_brightness = false;
                                                        }
                                                        auto_brightness = (brightness_mode == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
                                                        if (auto_brightness)
                                                        {
                                                                // do nothing - Don't manually set brightness from statusbar
                                                        }
                                                        else
                                                        {
                                                                // set brightness according to x position on statusbar
                                                                float x = (float)event.getRawX();
                                                                float screen_width = (float)(context.getResources().getDisplayMetrics().widthPixels);
                                                                // Brightness set from the 90% of pixels in the middle of screen, can't always get to the edges
                                                                int new_brightness = (int)(((x - (screen_width * 0.05f))/(screen_width * 0.9f)) * (float)android.os.Power.BRIGHTNESS_ON );
                                                                // don't let screen go completely dim or past 100% bright
                                                                if (new_brightness < 10) new_brightness = 10;
                                                                if (new_brightness > android.os.Power.BRIGHTNESS_ON ) new_brightness = android.os.Power.BRIGHTNESS_ON;
                                                                // Set the brightness
                                                                try {
                                                                        IPowerManager.Stub.asInterface(ServiceManager.getService("power")).setBacklightBrightness(new_brightness);
                                                                        Settings.System.putInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, new_brightness);
                                                                }catch (Exception e){
                                                                        Slog.w(TAG, "Setting Brightness failed: " + e);
                                                                }
                                                       }
                                                }
                                                else
                                                {
                                                        mLinger++;
                                                }
                                        }
                                        else
                                        {
                                                mLinger = 0;
                                        }
                                }
                }catch (SettingNotFoundException e){
                }
                } else  {
                    mAnimatingReveal = false;
                    updateExpandedViewPos(y + (mBottomBar ? -mViewDelta : mViewDelta));