Michael Wright | 0087a14 | 2013-02-05 16:29:39 -0800 | [diff] [blame] | 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 java.io.FileDescriptor; |
| 20 | import java.io.PrintWriter; |
| 21 | |
| 22 | import android.content.BroadcastReceiver; |
| 23 | import android.content.Context; |
| 24 | import android.content.DialogInterface; |
| 25 | import android.content.Intent; |
| 26 | import android.content.IntentFilter; |
| 27 | import android.os.Handler; |
Amith Yamasani | b078b2b | 2013-04-22 09:27:08 -0700 | [diff] [blame] | 28 | import android.os.UserHandle; |
Michael Wright | 0087a14 | 2013-02-05 16:29:39 -0800 | [diff] [blame] | 29 | import android.util.Slog; |
| 30 | |
| 31 | import com.android.systemui.SystemUI; |
| 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) 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); |
Amith Yamasani | b078b2b | 2013-04-22 09:27:08 -0700 | [diff] [blame] | 70 | mContext.registerReceiverAsUser(mIntentReceiver, UserHandle.ALL, filter, null, mHandler); |
Michael Wright | 0087a14 | 2013-02-05 16:29:39 -0800 | [diff] [blame] | 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 | } |