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