Michael Wright | 0087a14 | 2013-02-05 16:29:39 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.settings; |
| 18 | |
Alan Viverette | 5a39949 | 2014-07-14 16:19:38 -0700 | [diff] [blame] | 19 | import android.app.Activity; |
Michael Wright | 0087a14 | 2013-02-05 16:29:39 -0800 | [diff] [blame] | 20 | import android.os.Bundle; |
Adrian Roos | d8ea484 | 2014-01-10 17:42:51 -0800 | [diff] [blame] | 21 | import android.view.Gravity; |
| 22 | import android.view.KeyEvent; |
Jason Monk | e5cff1a | 2017-03-31 11:05:39 -0400 | [diff] [blame] | 23 | import android.view.LayoutInflater; |
| 24 | import android.view.View; |
Michael Wright | 0087a14 | 2013-02-05 16:29:39 -0800 | [diff] [blame] | 25 | import android.view.Window; |
| 26 | import android.view.WindowManager; |
Michael Wright | 0087a14 | 2013-02-05 16:29:39 -0800 | [diff] [blame] | 27 | |
Jason Monk | 97b87a9 | 2015-06-23 15:04:44 -0400 | [diff] [blame] | 28 | import com.android.internal.logging.MetricsLogger; |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 29 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 30 | import com.android.systemui.R; |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 31 | import com.android.systemui.broadcast.BroadcastDispatcher; |
| 32 | |
| 33 | import javax.inject.Inject; |
Michael Wright | 0087a14 | 2013-02-05 16:29:39 -0800 | [diff] [blame] | 34 | |
| 35 | /** A dialog that provides controls for adjusting the screen brightness. */ |
Adrian Roos | 5a46f8c | 2014-07-25 01:03:17 +0200 | [diff] [blame] | 36 | public class BrightnessDialog extends Activity { |
Michael Wright | 0087a14 | 2013-02-05 16:29:39 -0800 | [diff] [blame] | 37 | |
| 38 | private BrightnessController mBrightnessController; |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 39 | private final BroadcastDispatcher mBroadcastDispatcher; |
| 40 | |
| 41 | @Inject |
| 42 | public BrightnessDialog(BroadcastDispatcher broadcastDispatcher) { |
| 43 | mBroadcastDispatcher = broadcastDispatcher; |
| 44 | } |
| 45 | |
Michael Wright | 0087a14 | 2013-02-05 16:29:39 -0800 | [diff] [blame] | 46 | |
Michael Wright | 0087a14 | 2013-02-05 16:29:39 -0800 | [diff] [blame] | 47 | @Override |
Alan Viverette | 5a39949 | 2014-07-14 16:19:38 -0700 | [diff] [blame] | 48 | protected void onCreate(Bundle savedInstanceState) { |
Michael Wright | 0087a14 | 2013-02-05 16:29:39 -0800 | [diff] [blame] | 49 | super.onCreate(savedInstanceState); |
Alan Viverette | 5a39949 | 2014-07-14 16:19:38 -0700 | [diff] [blame] | 50 | |
Alan Viverette | 5a39949 | 2014-07-14 16:19:38 -0700 | [diff] [blame] | 51 | final Window window = getWindow(); |
Alan Viverette | 5a39949 | 2014-07-14 16:19:38 -0700 | [diff] [blame] | 52 | |
Alan Viverette | 5a39949 | 2014-07-14 16:19:38 -0700 | [diff] [blame] | 53 | window.setGravity(Gravity.TOP); |
Michael Wright | 0087a14 | 2013-02-05 16:29:39 -0800 | [diff] [blame] | 54 | window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
| 55 | window.requestFeature(Window.FEATURE_NO_TITLE); |
| 56 | |
Lucas Dupin | ee7bdf6 | 2018-10-02 14:59:45 -0700 | [diff] [blame] | 57 | View v = LayoutInflater.from(this).inflate( |
Jason Monk | e5cff1a | 2017-03-31 11:05:39 -0400 | [diff] [blame] | 58 | R.layout.quick_settings_brightness_dialog, null); |
| 59 | setContentView(v); |
Adrian Roos | b7ebbde | 2014-08-15 20:11:38 +0200 | [diff] [blame] | 60 | |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 61 | final ToggleSliderView slider = findViewById(R.id.brightness_slider); |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 62 | mBrightnessController = new BrightnessController(this, slider, mBroadcastDispatcher); |
Michael Wright | 0087a14 | 2013-02-05 16:29:39 -0800 | [diff] [blame] | 63 | } |
| 64 | |
Michael Wright | 0087a14 | 2013-02-05 16:29:39 -0800 | [diff] [blame] | 65 | @Override |
| 66 | protected void onStart() { |
| 67 | super.onStart(); |
Jorim Jaggi | f056e35 | 2014-05-11 23:09:22 +0200 | [diff] [blame] | 68 | mBrightnessController.registerCallbacks(); |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 69 | MetricsLogger.visible(this, MetricsEvent.BRIGHTNESS_DIALOG); |
Michael Wright | 0087a14 | 2013-02-05 16:29:39 -0800 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | @Override |
| 73 | protected void onStop() { |
| 74 | super.onStop(); |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 75 | MetricsLogger.hidden(this, MetricsEvent.BRIGHTNESS_DIALOG); |
Michael Wright | 0087a14 | 2013-02-05 16:29:39 -0800 | [diff] [blame] | 76 | mBrightnessController.unregisterCallbacks(); |
Michael Wright | 0087a14 | 2013-02-05 16:29:39 -0800 | [diff] [blame] | 77 | } |
| 78 | |
Adrian Roos | d8ea484 | 2014-01-10 17:42:51 -0800 | [diff] [blame] | 79 | @Override |
| 80 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Alan Viverette | 5a39949 | 2014-07-14 16:19:38 -0700 | [diff] [blame] | 81 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN |
| 82 | || keyCode == KeyEvent.KEYCODE_VOLUME_UP |
| 83 | || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) { |
| 84 | finish(); |
Adrian Roos | d8ea484 | 2014-01-10 17:42:51 -0800 | [diff] [blame] | 85 | } |
Alan Viverette | 5a39949 | 2014-07-14 16:19:38 -0700 | [diff] [blame] | 86 | |
Adrian Roos | d8ea484 | 2014-01-10 17:42:51 -0800 | [diff] [blame] | 87 | return super.onKeyDown(keyCode, event); |
| 88 | } |
Michael Wright | 0087a14 | 2013-02-05 16:29:39 -0800 | [diff] [blame] | 89 | } |