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

Commit 5a399490 authored by Alan Viverette's avatar Alan Viverette
Browse files

Use activity for brightness dialog

Also fixes brightness controller failure to unregister callbacks.

BUG: 15512088
Change-Id: Ia665e006d93391d5a66d4ace614660c4e6d2d5b5
parent a5a2cf41
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -2682,8 +2682,7 @@ public class Intent implements Parcelable, Cloneable {
            "android.intent.action.QUICK_CLOCK";

    /**
     * Broadcast Action: This is broadcast when a user action should request the
     * brightness setting dialog.
     * Activity Action: Shows the brightness setting dialog.
     * @hide
     */
    public static final String ACTION_SHOW_BRIGHTNESS_DIALOG =
+13 −0
Original line number Diff line number Diff line
@@ -302,6 +302,19 @@
            </intent-filter>
        </activity>

        <activity
            android:name=".settings.BrightnessDialog"
            android:label="@string/quick_settings_brightness_dialog_title"
            android:theme="@android:style/Theme.DeviceDefault.Light.Dialog"
            android:finishOnCloseSystemDialogs="true"
            android:launchMode="singleInstance"
            android:excludeFromRecents="true"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.SHOW_BRIGHTNESS_DIALOG" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

        <!-- I dream of notifications -->
        <service
+1 −2
Original line number Diff line number Diff line
@@ -46,8 +46,7 @@ public class SystemUIApplication extends Application {
            com.android.systemui.statusbar.SystemBars.class,
            com.android.systemui.usb.StorageNotification.class,
            com.android.systemui.power.PowerUI.class,
            com.android.systemui.media.RingtonePlayer.class,
            com.android.systemui.settings.SettingsUI.class,
            com.android.systemui.media.RingtonePlayer.class
    };

    /**
+6 −3
Original line number Diff line number Diff line
@@ -163,15 +163,17 @@ public class BrightnessController implements ToggleSlider.Listener {
        if (mListening) {
            return;
        }

        mBrightnessObserver.startObserving();
        mUserTracker.startTracking();

        // Update the slider and mode before attaching the listener so we don't receive the
        // onChanged notifications for the initial values.
        // Update the slider and mode before attaching the listener so we don't
        // receive the onChanged notifications for the initial values.
        updateMode();
        updateSlider();

        mControl.setOnChangedListener(this);
        mListening = true;
    }

    /** Unregister all call backs, both to and from the controller */
@@ -179,10 +181,11 @@ public class BrightnessController implements ToggleSlider.Listener {
        if (!mListening) {
            return;
        }

        mBrightnessObserver.stopObserving();
        mChangeCallbacks.clear();
        mUserTracker.stopTracking();
        mControl.setOnChangedListener(null);
        mListening = false;
    }

    public void onChanged(ToggleSlider view, boolean tracking, boolean automatic, int value) {
+35 −42
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.settings;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.res.Resources;
@@ -30,76 +31,66 @@ import android.widget.ImageView;
import com.android.systemui.R;

/** A dialog that provides controls for adjusting the screen brightness. */
public class BrightnessDialog extends Dialog implements
public class BrightnessDialog extends Activity implements
        BrightnessController.BrightnessStateChangeCallback {

    private static final String TAG = "BrightnessDialog";
    private static final boolean DEBUG = false;

    protected Handler mHandler = new Handler();
    private final Handler mHandler = new Handler();

    private BrightnessController mBrightnessController;
    private final int mBrightnessDialogLongTimeout;
    private final int mBrightnessDialogShortTimeout;
    private int mBrightnessDialogLongTimeout;
    private int mBrightnessDialogShortTimeout;

    private final Runnable mDismissDialogRunnable = new Runnable() {
        public void run() {
            if (BrightnessDialog.this.isShowing()) {
                BrightnessDialog.this.dismiss();
            }
            finish();
        };
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    public BrightnessDialog(Context ctx) {
        super(ctx);
        Resources r = ctx.getResources();
        mBrightnessDialogLongTimeout =
                r.getInteger(R.integer.quick_settings_brightness_dialog_long_timeout);
        mBrightnessDialogShortTimeout =
                r.getInteger(R.integer.quick_settings_brightness_dialog_short_timeout);
    }
        final Resources r = getResources();
        mBrightnessDialogLongTimeout = r.getInteger(
                R.integer.quick_settings_brightness_dialog_long_timeout);
        mBrightnessDialogShortTimeout = r.getInteger(
                R.integer.quick_settings_brightness_dialog_short_timeout);

        final Window window = getWindow();
        final WindowManager.LayoutParams lp = window.getAttributes();

    /**
     * Create the brightness dialog and any resources that are used for the
     * entire lifetime of the dialog.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window window = getWindow();
        window.setGravity(Gravity.TOP);
        WindowManager.LayoutParams lp = window.getAttributes();
        // Offset from the top
        lp.y = getContext().getResources().getDimensionPixelOffset(R.dimen.volume_panel_top);
        lp.y = getResources().getDimensionPixelOffset(R.dimen.volume_panel_top);
        lp.type = WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY;
        lp.privateFlags |=
                WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
        lp.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;

        window.setAttributes(lp);
        window.setGravity(Gravity.TOP);
        window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        window.requestFeature(Window.FEATURE_NO_TITLE);

        setContentView(R.layout.quick_settings_brightness_dialog);
        setCanceledOnTouchOutside(true);
    }


    @Override
    protected void onStart() {
        super.onStart();
        mBrightnessController = new BrightnessController(getContext(),
                (ImageView) findViewById(R.id.brightness_icon),
                (ToggleSlider) findViewById(R.id.brightness_slider));

        final ImageView icon = (ImageView) findViewById(R.id.brightness_icon);
        final ToggleSlider slider = (ToggleSlider) findViewById(R.id.brightness_slider);
        mBrightnessController = new BrightnessController(this, icon, slider);
        mBrightnessController.registerCallbacks();
        dismissBrightnessDialog(mBrightnessDialogLongTimeout);
        mBrightnessController.addStateChangedCallback(this);

        dismissBrightnessDialog(mBrightnessDialogLongTimeout);
    }

    @Override
    protected void onStop() {
        super.onStop();

        mBrightnessController.removeStateChangedCallback(this);
        mBrightnessController.unregisterCallbacks();

        removeAllBrightnessDialogCallbacks();
    }

@@ -109,6 +100,7 @@ public class BrightnessDialog extends Dialog implements

    private void dismissBrightnessDialog(int timeout) {
        removeAllBrightnessDialogCallbacks();

        mHandler.postDelayed(mDismissDialogRunnable, timeout);
    }

@@ -118,11 +110,12 @@ public class BrightnessDialog extends Dialog implements

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN ||
                keyCode == KeyEvent.KEYCODE_VOLUME_UP ||
                keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) {
            dismiss();
        if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
                || keyCode == KeyEvent.KEYCODE_VOLUME_UP
                || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) {
            finish();
        }

        return super.onKeyDown(keyCode, event);
    }
}
Loading