SettingsUI.java revision b078b2bc8ac167f002d604d309fa99d7cb866714
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
17package com.android.systemui.settings;
18
19import java.io.FileDescriptor;
20import java.io.PrintWriter;
21
22import android.content.BroadcastReceiver;
23import android.content.Context;
24import android.content.DialogInterface;
25import android.content.Intent;
26import android.content.IntentFilter;
27import android.os.Handler;
28import android.os.UserHandle;
29import android.util.Slog;
30
31import com.android.systemui.SystemUI;
32
33public 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) Slog.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                Slog.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