2 * Copyright (C) 2013 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.systemui.settings;
19 import android.app.Activity;
20 import android.os.Bundle;
21 import android.view.ContextThemeWrapper;
22 import android.view.Gravity;
23 import android.view.KeyEvent;
24 import android.view.LayoutInflater;
25 import android.view.View;
26 import android.view.Window;
27 import android.view.WindowManager;
28 import android.widget.ImageView;
30 import com.android.internal.logging.MetricsLogger;
31 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
32 import com.android.systemui.R;
34 /** A dialog that provides controls for adjusting the screen brightness. */
35 public class BrightnessDialog extends Activity {
37 private BrightnessController mBrightnessController;
40 protected void onCreate(Bundle savedInstanceState) {
41 super.onCreate(savedInstanceState);
43 final Window window = getWindow();
45 window.setGravity(Gravity.TOP);
46 window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
47 window.requestFeature(Window.FEATURE_NO_TITLE);
49 // Use a dialog theme as the activity theme, but inflate the content as
51 ContextThemeWrapper themedContext = new ContextThemeWrapper(this,
52 com.android.internal.R.style.Theme_DeviceDefault_QuickSettings);
53 View v = LayoutInflater.from(themedContext).inflate(
54 R.layout.quick_settings_brightness_dialog, null);
57 final ImageView icon = findViewById(R.id.brightness_icon);
58 final ToggleSliderView slider = findViewById(R.id.brightness_slider);
59 mBrightnessController = new BrightnessController(this, icon, slider);
63 protected void onStart() {
65 mBrightnessController.registerCallbacks();
66 MetricsLogger.visible(this, MetricsEvent.BRIGHTNESS_DIALOG);
70 protected void onStop() {
72 MetricsLogger.hidden(this, MetricsEvent.BRIGHTNESS_DIALOG);
73 mBrightnessController.unregisterCallbacks();
77 public boolean onKeyDown(int keyCode, KeyEvent event) {
78 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
79 || keyCode == KeyEvent.KEYCODE_VOLUME_UP
80 || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) {
84 return super.onKeyDown(keyCode, event);