Make brightness panel behave like volume panel.

Moves the brightness panel to the same spot as the volume panel. To avoid a conflict with the volume panel, brightness is dismissed when the volume keys are pressed.

Bug: 7217009
Bug: 7217154
Change-Id: Ib8331a1e390cbedca40fa237243ea2cfd088e521
This commit is contained in:
Adrian Roos
2014-01-10 17:42:51 -08:00
parent 4a5eb8fe18
commit d8ea484e2c

View File

@@ -21,6 +21,8 @@ import android.content.Context;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Handler;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
@@ -67,9 +69,15 @@ public class BrightnessDialog extends Dialog implements
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Window window = getWindow();
window.setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY);
window.getAttributes().privateFlags |=
window.setGravity(Gravity.TOP);
WindowManager.LayoutParams lp = window.getAttributes();
// Offset from the top
lp.y = getContext().getResources().getDimensionPixelOffset(
com.android.internal.R.dimen.volume_panel_top);
lp.type = WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY;
lp.privateFlags |=
WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
window.setAttributes(lp);
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
window.requestFeature(Window.FEATURE_NO_TITLE);
@@ -108,4 +116,13 @@ public class BrightnessDialog extends Dialog implements
mHandler.removeCallbacks(mDismissDialogRunnable);
}
@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();
}
return super.onKeyDown(keyCode, event);
}
}