Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 284e630a authored by Amith Yamasani's avatar Amith Yamasani
Browse files

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

Bug: 5308506 "Video" App halts playback when volume slider is present
Change-Id: Ib0672384b9074af73d729d1f64db62e5a8882d80
parent 5908eaef
Loading
Loading
Loading
Loading
+21 −17
Original line number Diff line number Diff line
@@ -34,10 +34,12 @@ import android.media.ToneGenerator;
import android.net.Uri;
import android.os.Handler;
import android.os.Message;
import android.os.RemoteException;
import android.os.Vibrator;
import android.provider.Settings;
import android.provider.Settings.System;
import android.util.Log;
import android.view.WindowManager.LayoutParams;
import android.widget.ImageView;
import android.widget.SeekBar;
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);
        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;
                return false;
            }
        });
        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);
        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.setContentView(mView);
        mDialog.setOnDismissListener(new OnDismissListener() {
@@ -208,11 +206,17 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
        // Change some window properties
        Window window = mDialog.getWindow();
        window.setGravity(Gravity.TOP);
        WindowManager.LayoutParams lp = window.getAttributes();
        LayoutParams lp = window.getAttributes();
        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.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()];
        mVibrator = new Vibrator();
+0 −1
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@
        android:id="@+id/visible_panel"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="80dp"
        android:background="@android:drawable/dialog_full_holo_dark"
        android:orientation="horizontal"
        >
+2 −0
Original line number Diff line number Diff line
@@ -178,4 +178,6 @@
    <!-- Default width for a textview error popup -->
    <dimen name="textview_error_popup_default_width">240dip</dimen>

    <!-- Volume panel y offset -->
    <dimen name="volume_panel_top">80dp</dimen>
</resources>