OSDN Git Service

Remove unnecessary casts on calls to findViewById
[android-x86/frameworks-base.git] / packages / SystemUI / src / com / android / systemui / settings / BrightnessDialog.java
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.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;
29
30 import com.android.internal.logging.MetricsLogger;
31 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
32 import com.android.systemui.R;
33
34 /** A dialog that provides controls for adjusting the screen brightness. */
35 public class BrightnessDialog extends Activity {
36
37     private BrightnessController mBrightnessController;
38
39     @Override
40     protected void onCreate(Bundle savedInstanceState) {
41         super.onCreate(savedInstanceState);
42
43         final Window window = getWindow();
44
45         window.setGravity(Gravity.TOP);
46         window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
47         window.requestFeature(Window.FEATURE_NO_TITLE);
48
49         // Use a dialog theme as the activity theme, but inflate the content as
50         // the QS content.
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);
55         setContentView(v);
56
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);
60     }
61
62     @Override
63     protected void onStart() {
64         super.onStart();
65         mBrightnessController.registerCallbacks();
66         MetricsLogger.visible(this, MetricsEvent.BRIGHTNESS_DIALOG);
67     }
68
69     @Override
70     protected void onStop() {
71         super.onStop();
72         MetricsLogger.hidden(this, MetricsEvent.BRIGHTNESS_DIALOG);
73         mBrightnessController.unregisterCallbacks();
74     }
75
76     @Override
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) {
81             finish();
82         }
83
84         return super.onKeyDown(keyCode, event);
85     }
86 }