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 19 import android.app.Activity; 20 import android.os.Bundle; 21 import android.view.Gravity; 22 import android.view.KeyEvent; 23 import android.view.LayoutInflater; 24 import android.view.View; 25 import android.view.Window; 26 import android.view.WindowManager; 27 28 import com.android.internal.logging.MetricsLogger; 29 import com.android.internal.logging.nano.MetricsProto.MetricsEvent; 30 import com.android.systemui.R; 31 32 /** A dialog that provides controls for adjusting the screen brightness. */ 33 public class BrightnessDialog extends Activity { 34 35 private BrightnessController mBrightnessController; 36 37 @Override 38 protected void onCreate(Bundle savedInstanceState) { 39 super.onCreate(savedInstanceState); 40 41 final Window window = getWindow(); 42 43 window.setGravity(Gravity.TOP); 44 window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); 45 window.requestFeature(Window.FEATURE_NO_TITLE); 46 47 View v = LayoutInflater.from(this).inflate( 48 R.layout.quick_settings_brightness_dialog, null); 49 setContentView(v); 50 51 final ToggleSliderView slider = findViewById(R.id.brightness_slider); 52 mBrightnessController = new BrightnessController(this, slider); 53 } 54 55 @Override 56 protected void onStart() { 57 super.onStart(); 58 mBrightnessController.registerCallbacks(); 59 MetricsLogger.visible(this, MetricsEvent.BRIGHTNESS_DIALOG); 60 } 61 62 @Override 63 protected void onStop() { 64 super.onStop(); 65 MetricsLogger.hidden(this, MetricsEvent.BRIGHTNESS_DIALOG); 66 mBrightnessController.unregisterCallbacks(); 67 } 68 69 @Override 70 public boolean onKeyDown(int keyCode, KeyEvent event) { 71 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN 72 || keyCode == KeyEvent.KEYCODE_VOLUME_UP 73 || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) { 74 finish(); 75 } 76 77 return super.onKeyDown(keyCode, event); 78 } 79 } 80