Merge "Make Volume control non-modal and allow touches underneath to take effect."

This commit is contained in:
Amith Yamasani
2011-09-19 10:03:14 -07:00
committed by Android (Google) Code Review
3 changed files with 23 additions and 18 deletions

View File

@@ -34,10 +34,12 @@ import android.media.ToneGenerator;
import android.net.Uri; import android.net.Uri;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.os.RemoteException;
import android.os.Vibrator; import android.os.Vibrator;
import android.provider.Settings; import android.provider.Settings;
import android.provider.Settings.System; import android.provider.Settings.System;
import android.util.Log; import android.util.Log;
import android.view.WindowManager.LayoutParams;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.SeekBar; import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener; import android.widget.SeekBar.OnSeekBarChangeListener;
@@ -175,20 +177,8 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
View view = mView = inflater.inflate(R.layout.volume_adjust, null); View view = mView = inflater.inflate(R.layout.volume_adjust, null);
mView.setOnTouchListener(new View.OnTouchListener() { mView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) { public boolean onTouch(View v, MotionEvent event) {
// Dismiss the dialog if the user touches outside the visible area. This is not
// handled by the usual dialog dismissing code because there is a region above
// the panel (marginTop) that is still within the dialog.
if (event.getAction() == MotionEvent.ACTION_DOWN) {
int x = (int) event.getX();
int y = (int) event.getY();
if (x < mPanel.getLeft() || x > mPanel.getRight() || y < mPanel.getTop()
|| y > mPanel.getBottom()) {
forceTimeout();
return true;
}
}
resetTimeout(); resetTimeout();
return true; return false;
} }
}); });
mPanel = (ViewGroup) mView.findViewById(R.id.visible_panel); mPanel = (ViewGroup) mView.findViewById(R.id.visible_panel);
@@ -196,7 +186,15 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
mMoreButton = (ImageView) mView.findViewById(R.id.expand_button); mMoreButton = (ImageView) mView.findViewById(R.id.expand_button);
mDivider = (ImageView) mView.findViewById(R.id.expand_button_divider); mDivider = (ImageView) mView.findViewById(R.id.expand_button_divider);
mDialog = new Dialog(context, R.style.Theme_Panel_Volume); mDialog = new Dialog(context, R.style.Theme_Panel_Volume) {
public boolean onTouchEvent(MotionEvent event) {
if (isShowing() && event.getAction() == MotionEvent.ACTION_OUTSIDE) {
forceTimeout();
return true;
}
return false;
}
};
mDialog.setTitle("Volume control"); // No need to localize mDialog.setTitle("Volume control"); // No need to localize
mDialog.setContentView(mView); mDialog.setContentView(mView);
mDialog.setOnDismissListener(new OnDismissListener() { mDialog.setOnDismissListener(new OnDismissListener() {
@@ -208,11 +206,17 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
// Change some window properties // Change some window properties
Window window = mDialog.getWindow(); Window window = mDialog.getWindow();
window.setGravity(Gravity.TOP); window.setGravity(Gravity.TOP);
WindowManager.LayoutParams lp = window.getAttributes(); LayoutParams lp = window.getAttributes();
lp.token = null; lp.token = null;
lp.type = WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY; // Offset from the top
lp.y = mContext.getResources().getDimensionPixelOffset(
com.android.internal.R.dimen.volume_panel_top);
lp.type = LayoutParams.TYPE_VOLUME_OVERLAY;
lp.width = LayoutParams.WRAP_CONTENT;
lp.height = LayoutParams.WRAP_CONTENT;
window.setAttributes(lp); window.setAttributes(lp);
window.addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); window.addFlags(LayoutParams.FLAG_NOT_FOCUSABLE | LayoutParams.FLAG_NOT_TOUCH_MODAL
| LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH);
mToneGenerators = new ToneGenerator[AudioSystem.getNumStreamTypes()]; mToneGenerators = new ToneGenerator[AudioSystem.getNumStreamTypes()];
mVibrator = new Vibrator(); mVibrator = new Vibrator();

View File

@@ -21,7 +21,6 @@
android:id="@+id/visible_panel" android:id="@+id/visible_panel"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="80dp"
android:background="@android:drawable/dialog_full_holo_dark" android:background="@android:drawable/dialog_full_holo_dark"
android:orientation="horizontal" android:orientation="horizontal"
> >

View File

@@ -178,4 +178,6 @@
<!-- Default width for a textview error popup --> <!-- Default width for a textview error popup -->
<dimen name="textview_error_popup_default_width">240dip</dimen> <dimen name="textview_error_popup_default_width">240dip</dimen>
<!-- Volume panel y offset -->
<dimen name="volume_panel_top">80dp</dimen>
</resources> </resources>