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.content.BroadcastReceiver;
     20 import android.content.Context;
     21 import android.content.DialogInterface;
     22 import android.content.Intent;
     23 import android.content.IntentFilter;
     24 import android.os.Handler;
     25 import android.os.UserHandle;
     26 import android.util.Log;
     27 
     28 import com.android.systemui.SystemUI;
     29 
     30 import java.io.FileDescriptor;
     31 import java.io.PrintWriter;
     32 
     33 public class SettingsUI extends SystemUI {
     34     private static final String TAG = "SettingsUI";
     35     private static final boolean DEBUG = false;
     36 
     37     private final Handler mHandler = new Handler();
     38     private BrightnessDialog mBrightnessDialog;
     39 
     40     private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
     41         @Override
     42         public void onReceive(Context context, Intent intent) {
     43             String action = intent.getAction();
     44             if (action.equals(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG)) {
     45                 if (DEBUG) Log.d(TAG, "showing brightness dialog");
     46 
     47                 if (mBrightnessDialog == null) {
     48                     mBrightnessDialog = new BrightnessDialog(mContext);
     49                     mBrightnessDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
     50                         @Override
     51                         public void onDismiss(DialogInterface dialog) {
     52                             mBrightnessDialog = null;
     53                         }
     54                     });
     55                 }
     56 
     57                 if (!mBrightnessDialog.isShowing()) {
     58                     mBrightnessDialog.show();
     59                 }
     60 
     61             } else {
     62                 Log.w(TAG, "unknown intent: " + intent);
     63             }
     64         }
     65     };
     66 
     67     public void start() {
     68         IntentFilter filter = new IntentFilter();
     69         filter.addAction(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG);
     70         mContext.registerReceiverAsUser(mIntentReceiver, UserHandle.ALL, filter, null, mHandler);
     71     }
     72 
     73     public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
     74         pw.print("mBrightnessDialog=");
     75         pw.println(mBrightnessDialog == null ? "null" : mBrightnessDialog.toString());
     76     }
     77 }
     78