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