blob: 8bc72c93fa01c32feb56de9e05854e7e4c7ee707 [file] [log] [blame]
Michael Wright0087a142013-02-05 16:29:39 -08001/*
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
17package com.android.systemui.settings;
18
Michael Wright0087a142013-02-05 16:29:39 -080019import android.content.BroadcastReceiver;
20import android.content.Context;
21import android.content.DialogInterface;
22import android.content.Intent;
23import android.content.IntentFilter;
24import android.os.Handler;
Amith Yamasanib078b2b2013-04-22 09:27:08 -070025import android.os.UserHandle;
John Spurlockcd686b52013-06-05 10:13:46 -040026import android.util.Log;
Michael Wright0087a142013-02-05 16:29:39 -080027
28import com.android.systemui.SystemUI;
29
John Spurlockde84f0e2013-06-12 12:41:00 -040030import java.io.FileDescriptor;
31import java.io.PrintWriter;
32
Michael Wright0087a142013-02-05 16:29:39 -080033public 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)) {
John Spurlockcd686b52013-06-05 10:13:46 -040045 if (DEBUG) Log.d(TAG, "showing brightness dialog");
Michael Wright0087a142013-02-05 16:29:39 -080046
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 {
John Spurlockcd686b52013-06-05 10:13:46 -040062 Log.w(TAG, "unknown intent: " + intent);
Michael Wright0087a142013-02-05 16:29:39 -080063 }
64 }
65 };
66
67 public void start() {
68 IntentFilter filter = new IntentFilter();
69 filter.addAction(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG);
Amith Yamasanib078b2b2013-04-22 09:27:08 -070070 mContext.registerReceiverAsUser(mIntentReceiver, UserHandle.ALL, filter, null, mHandler);
Michael Wright0087a142013-02-05 16:29:39 -080071 }
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}