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; |
Michael Wright | 0087a14 | 2013-02-05 16:29:39 -0800 | [diff] [blame] | 23 | import android.view.Window; |
| 24 | import android.view.WindowManager; |
| 25 | import android.widget.ImageView; |
| 26 | |
Jason Monk | 97b87a9 | 2015-06-23 15:04:44 -0400 | [diff] [blame] | 27 | import com.android.internal.logging.MetricsLogger; |
Tamas Berghammer | cbd3f0c | 2016-06-22 15:21:38 +0100 | [diff] [blame^] | 28 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 29 | import com.android.systemui.R; |
Michael Wright | 0087a14 | 2013-02-05 16:29:39 -0800 | [diff] [blame] | 30 | |
| 31 | /** A dialog that provides controls for adjusting the screen brightness. */ |
Adrian Roos | 5a46f8c | 2014-07-25 01:03:17 +0200 | [diff] [blame] | 32 | public class BrightnessDialog extends Activity { |
Michael Wright | 0087a14 | 2013-02-05 16:29:39 -0800 | [diff] [blame] | 33 | |
| 34 | private BrightnessController mBrightnessController; |
Michael Wright | 0087a14 | 2013-02-05 16:29:39 -0800 | [diff] [blame] | 35 | |
Michael Wright | 0087a14 | 2013-02-05 16:29:39 -0800 | [diff] [blame] | 36 | @Override |
Alan Viverette | 5a39949 | 2014-07-14 16:19:38 -0700 | [diff] [blame] | 37 | protected void onCreate(Bundle savedInstanceState) { |
Michael Wright | 0087a14 | 2013-02-05 16:29:39 -0800 | [diff] [blame] | 38 | super.onCreate(savedInstanceState); |
Alan Viverette | 5a39949 | 2014-07-14 16:19:38 -0700 | [diff] [blame] | 39 | |
Alan Viverette | 5a39949 | 2014-07-14 16:19:38 -0700 | [diff] [blame] | 40 | final Window window = getWindow(); |
Alan Viverette | 5a39949 | 2014-07-14 16:19:38 -0700 | [diff] [blame] | 41 | |
Alan Viverette | 5a39949 | 2014-07-14 16:19:38 -0700 | [diff] [blame] | 42 | window.setGravity(Gravity.TOP); |
Michael Wright | 0087a14 | 2013-02-05 16:29:39 -0800 | [diff] [blame] | 43 | window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
| 44 | window.requestFeature(Window.FEATURE_NO_TITLE); |
| 45 | |
| 46 | setContentView(R.layout.quick_settings_brightness_dialog); |
Adrian Roos | b7ebbde | 2014-08-15 20:11:38 +0200 | [diff] [blame] | 47 | |
| 48 | final ImageView icon = (ImageView) findViewById(R.id.brightness_icon); |
| 49 | final ToggleSlider slider = (ToggleSlider) findViewById(R.id.brightness_slider); |
| 50 | mBrightnessController = new BrightnessController(this, icon, slider); |
Michael Wright | 0087a14 | 2013-02-05 16:29:39 -0800 | [diff] [blame] | 51 | } |
| 52 | |
Michael Wright | 0087a14 | 2013-02-05 16:29:39 -0800 | [diff] [blame] | 53 | @Override |
| 54 | protected void onStart() { |
| 55 | super.onStart(); |
Jorim Jaggi | f056e35 | 2014-05-11 23:09:22 +0200 | [diff] [blame] | 56 | mBrightnessController.registerCallbacks(); |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 57 | MetricsLogger.visible(this, MetricsEvent.BRIGHTNESS_DIALOG); |
Michael Wright | 0087a14 | 2013-02-05 16:29:39 -0800 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | @Override |
| 61 | protected void onStop() { |
| 62 | super.onStop(); |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 63 | MetricsLogger.hidden(this, MetricsEvent.BRIGHTNESS_DIALOG); |
Michael Wright | 0087a14 | 2013-02-05 16:29:39 -0800 | [diff] [blame] | 64 | mBrightnessController.unregisterCallbacks(); |
Michael Wright | 0087a14 | 2013-02-05 16:29:39 -0800 | [diff] [blame] | 65 | } |
| 66 | |
Adrian Roos | d8ea484 | 2014-01-10 17:42:51 -0800 | [diff] [blame] | 67 | @Override |
| 68 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Alan Viverette | 5a39949 | 2014-07-14 16:19:38 -0700 | [diff] [blame] | 69 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN |
| 70 | || keyCode == KeyEvent.KEYCODE_VOLUME_UP |
| 71 | || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) { |
| 72 | finish(); |
Adrian Roos | d8ea484 | 2014-01-10 17:42:51 -0800 | [diff] [blame] | 73 | } |
Alan Viverette | 5a39949 | 2014-07-14 16:19:38 -0700 | [diff] [blame] | 74 | |
Adrian Roos | d8ea484 | 2014-01-10 17:42:51 -0800 | [diff] [blame] | 75 | return super.onKeyDown(keyCode, event); |
| 76 | } |
Michael Wright | 0087a14 | 2013-02-05 16:29:39 -0800 | [diff] [blame] | 77 | } |