diff options
author | Alan Viverette <alanv@google.com> | 2014-07-14 16:19:38 -0700 |
---|---|---|
committer | Alan Viverette <alanv@google.com> | 2014-07-14 16:20:40 -0700 |
commit | 5a399490c2185ebfd458b1a1d9394f3a68c5fde2 (patch) | |
tree | f4823567419f609f8e45282ec1e0ce9107c2519a /packages/SystemUI/src/com/android/systemui/settings | |
parent | a5a2cf419d72b28d0ce3948199d6f6874d6dbf9b (diff) | |
download | frameworks_base-5a399490c2185ebfd458b1a1d9394f3a68c5fde2.zip frameworks_base-5a399490c2185ebfd458b1a1d9394f3a68c5fde2.tar.gz frameworks_base-5a399490c2185ebfd458b1a1d9394f3a68c5fde2.tar.bz2 |
Use activity for brightness dialog
Also fixes brightness controller failure to unregister callbacks.
BUG: 15512088
Change-Id: Ia665e006d93391d5a66d4ace614660c4e6d2d5b5
Diffstat (limited to 'packages/SystemUI/src/com/android/systemui/settings')
3 files changed, 41 insertions, 122 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/settings/BrightnessController.java b/packages/SystemUI/src/com/android/systemui/settings/BrightnessController.java index 6d5bb9d..108c8df 100644 --- a/packages/SystemUI/src/com/android/systemui/settings/BrightnessController.java +++ b/packages/SystemUI/src/com/android/systemui/settings/BrightnessController.java @@ -163,15 +163,17 @@ public class BrightnessController implements ToggleSlider.Listener { if (mListening) { return; } + mBrightnessObserver.startObserving(); mUserTracker.startTracking(); - // Update the slider and mode before attaching the listener so we don't receive the - // onChanged notifications for the initial values. + // Update the slider and mode before attaching the listener so we don't + // receive the onChanged notifications for the initial values. updateMode(); updateSlider(); mControl.setOnChangedListener(this); + mListening = true; } /** Unregister all call backs, both to and from the controller */ @@ -179,10 +181,11 @@ public class BrightnessController implements ToggleSlider.Listener { if (!mListening) { return; } + mBrightnessObserver.stopObserving(); - mChangeCallbacks.clear(); mUserTracker.stopTracking(); mControl.setOnChangedListener(null); + mListening = false; } public void onChanged(ToggleSlider view, boolean tracking, boolean automatic, int value) { diff --git a/packages/SystemUI/src/com/android/systemui/settings/BrightnessDialog.java b/packages/SystemUI/src/com/android/systemui/settings/BrightnessDialog.java index 65e1cc6..ad98168 100644 --- a/packages/SystemUI/src/com/android/systemui/settings/BrightnessDialog.java +++ b/packages/SystemUI/src/com/android/systemui/settings/BrightnessDialog.java @@ -16,6 +16,7 @@ package com.android.systemui.settings; +import android.app.Activity; import android.app.Dialog; import android.content.Context; import android.content.res.Resources; @@ -30,76 +31,66 @@ import android.widget.ImageView; import com.android.systemui.R; /** A dialog that provides controls for adjusting the screen brightness. */ -public class BrightnessDialog extends Dialog implements +public class BrightnessDialog extends Activity implements BrightnessController.BrightnessStateChangeCallback { - - private static final String TAG = "BrightnessDialog"; - private static final boolean DEBUG = false; - - protected Handler mHandler = new Handler(); + private final Handler mHandler = new Handler(); private BrightnessController mBrightnessController; - private final int mBrightnessDialogLongTimeout; - private final int mBrightnessDialogShortTimeout; + private int mBrightnessDialogLongTimeout; + private int mBrightnessDialogShortTimeout; private final Runnable mDismissDialogRunnable = new Runnable() { public void run() { - if (BrightnessDialog.this.isShowing()) { - BrightnessDialog.this.dismiss(); - } + finish(); }; }; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); - public BrightnessDialog(Context ctx) { - super(ctx); - Resources r = ctx.getResources(); - mBrightnessDialogLongTimeout = - r.getInteger(R.integer.quick_settings_brightness_dialog_long_timeout); - mBrightnessDialogShortTimeout = - r.getInteger(R.integer.quick_settings_brightness_dialog_short_timeout); - } + final Resources r = getResources(); + mBrightnessDialogLongTimeout = r.getInteger( + R.integer.quick_settings_brightness_dialog_long_timeout); + mBrightnessDialogShortTimeout = r.getInteger( + R.integer.quick_settings_brightness_dialog_short_timeout); + final Window window = getWindow(); + final WindowManager.LayoutParams lp = window.getAttributes(); - /** - * Create the brightness dialog and any resources that are used for the - * entire lifetime of the dialog. - */ - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - Window window = getWindow(); - window.setGravity(Gravity.TOP); - WindowManager.LayoutParams lp = window.getAttributes(); // Offset from the top - lp.y = getContext().getResources().getDimensionPixelOffset(R.dimen.volume_panel_top); + lp.y = getResources().getDimensionPixelOffset(R.dimen.volume_panel_top); lp.type = WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY; - lp.privateFlags |= - WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; + lp.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; + window.setAttributes(lp); + window.setGravity(Gravity.TOP); window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); window.requestFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.quick_settings_brightness_dialog); - setCanceledOnTouchOutside(true); } - @Override protected void onStart() { super.onStart(); - mBrightnessController = new BrightnessController(getContext(), - (ImageView) findViewById(R.id.brightness_icon), - (ToggleSlider) findViewById(R.id.brightness_slider)); + + final ImageView icon = (ImageView) findViewById(R.id.brightness_icon); + final ToggleSlider slider = (ToggleSlider) findViewById(R.id.brightness_slider); + mBrightnessController = new BrightnessController(this, icon, slider); mBrightnessController.registerCallbacks(); - dismissBrightnessDialog(mBrightnessDialogLongTimeout); mBrightnessController.addStateChangedCallback(this); + + dismissBrightnessDialog(mBrightnessDialogLongTimeout); } @Override protected void onStop() { super.onStop(); + + mBrightnessController.removeStateChangedCallback(this); mBrightnessController.unregisterCallbacks(); + removeAllBrightnessDialogCallbacks(); } @@ -109,6 +100,7 @@ public class BrightnessDialog extends Dialog implements private void dismissBrightnessDialog(int timeout) { removeAllBrightnessDialogCallbacks(); + mHandler.postDelayed(mDismissDialogRunnable, timeout); } @@ -118,11 +110,12 @@ public class BrightnessDialog extends Dialog implements @Override public boolean onKeyDown(int keyCode, KeyEvent event) { - if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || - keyCode == KeyEvent.KEYCODE_VOLUME_UP || - keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) { - dismiss(); + if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN + || keyCode == KeyEvent.KEYCODE_VOLUME_UP + || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) { + finish(); } + return super.onKeyDown(keyCode, event); } } diff --git a/packages/SystemUI/src/com/android/systemui/settings/SettingsUI.java b/packages/SystemUI/src/com/android/systemui/settings/SettingsUI.java deleted file mode 100644 index 8bc72c9..0000000 --- a/packages/SystemUI/src/com/android/systemui/settings/SettingsUI.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.systemui.settings; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.IntentFilter; -import android.os.Handler; -import android.os.UserHandle; -import android.util.Log; - -import com.android.systemui.SystemUI; - -import java.io.FileDescriptor; -import java.io.PrintWriter; - -public class SettingsUI extends SystemUI { - private static final String TAG = "SettingsUI"; - private static final boolean DEBUG = false; - - private final Handler mHandler = new Handler(); - private BrightnessDialog mBrightnessDialog; - - private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - String action = intent.getAction(); - if (action.equals(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG)) { - if (DEBUG) Log.d(TAG, "showing brightness dialog"); - - if (mBrightnessDialog == null) { - mBrightnessDialog = new BrightnessDialog(mContext); - mBrightnessDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { - @Override - public void onDismiss(DialogInterface dialog) { - mBrightnessDialog = null; - } - }); - } - - if (!mBrightnessDialog.isShowing()) { - mBrightnessDialog.show(); - } - - } else { - Log.w(TAG, "unknown intent: " + intent); - } - } - }; - - public void start() { - IntentFilter filter = new IntentFilter(); - filter.addAction(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG); - mContext.registerReceiverAsUser(mIntentReceiver, UserHandle.ALL, filter, null, mHandler); - } - - public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { - pw.print("mBrightnessDialog="); - pw.println(mBrightnessDialog == null ? "null" : mBrightnessDialog.toString()); - } -} |