Dismiss the volume overlay dialog when user touches above the dialog as well.
Bug: 5165168
Change-Id: Ib343c3b88371cb93f8241b1085d1a2f36a77b1ac
diff --git a/core/java/android/view/VolumePanel.java b/core/java/android/view/VolumePanel.java
index cb85e5f..e1aa9a4 100644
--- a/core/java/android/view/VolumePanel.java
+++ b/core/java/android/view/VolumePanel.java
@@ -101,6 +101,8 @@
/** Dialog's content view */
private final View mView;
+ /** The visible portion of the volume overlay */
+ private final ViewGroup mPanel;
/** Contains the sliders and their touchable icons */
private final ViewGroup mSliderGroup;
/** The button that expands the dialog to show all sliders */
@@ -173,10 +175,23 @@
View view = mView = inflater.inflate(R.layout.volume_adjust, null);
mView.setOnTouchListener(new View.OnTouchListener() {
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();
return true;
}
});
+ mPanel = (ViewGroup) mView.findViewById(R.id.visible_panel);
mSliderGroup = (ViewGroup) mView.findViewById(R.id.slider_group);
mMoreButton = (ImageView) mView.findViewById(R.id.expand_button);
mDivider = (ImageView) mView.findViewById(R.id.expand_button_divider);
@@ -639,6 +654,11 @@
sendMessageDelayed(obtainMessage(MSG_TIMEOUT), TIMEOUT_DELAY);
}
+ private void forceTimeout() {
+ removeMessages(MSG_TIMEOUT);
+ sendMessage(obtainMessage(MSG_TIMEOUT));
+ }
+
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
final Object tag = seekBar.getTag();
diff --git a/core/res/res/layout/volume_adjust.xml b/core/res/res/layout/volume_adjust.xml
index 7303003..ea4e1f9 100644
--- a/core/res/res/layout/volume_adjust.xml
+++ b/core/res/res/layout/volume_adjust.xml
@@ -18,6 +18,7 @@
android:layout_width="480dp"
android:layout_height="wrap_content">
<LinearLayout
+ android:id="@+id/visible_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="80dp"