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

Commit 51ea2ebc authored by Austin T. Conn's avatar Austin T. Conn Committed by Steve Kondik
Browse files

Settings: Forward Port Volume Long Press Skip Tracks (1/2)

Bring Forward Volume Rocker Track Change

Requires Settings Change
http://review.cyanogenmod.org/#/c/82222/

Change-Id: I70b00e08fe48707110725dd1daa56b1e48d15a03
parent 2f9cb3be
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -2609,6 +2609,12 @@ public final class Settings {

        private static final Validator VOLUME_MASTER_MUTE_VALIDATOR = sBooleanValidator;

        /**
         * Whether or not volume button music controls should be enabled to seek media tracks
         * @hide
         */
        public static final String VOLBTN_MUSIC_CONTROLS = "volbtn_music_controls";

        /**
         * Microphone mute (int 1 = mute, 0 = not muted).
         *
+61 −12
Original line number Diff line number Diff line
@@ -461,6 +461,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    WindowState mFocusedWindow;
    IApplicationToken mFocusedApp;

    // Behavior of volbtn music controls
    boolean mVolBtnMusicControls;
    boolean mIsLongPress;

    PointerLocationView mPointerLocationView;

    // The current size of the screen; really; extends into the overscan area of
@@ -692,6 +696,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    private static final int MSG_POWER_DELAYED_PRESS = 13;
    private static final int MSG_POWER_LONG_PRESS = 14;
    private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
    private static final int MSG_DISPATCH_VOLKEY_WITH_WAKE_LOCK = 16;

    boolean mWifiDisplayConnected = false;
    int mWifiDisplayCustomRotation = -1;

@@ -747,6 +753,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
                    updateDreamingSleepToken(msg.arg1 != 0);
                    break;
                case MSG_DISPATCH_VOLKEY_WITH_WAKE_LOCK:
                    dispatchMediaKeyWithWakeLockToAudioService((KeyEvent)msg.obj);
                    dispatchMediaKeyWithWakeLockToAudioService(KeyEvent.changeAction((KeyEvent)msg.obj, KeyEvent.ACTION_UP));
                    break;
            }
        }
    }
@@ -826,6 +836,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.ACCELEROMETER_ROTATION_ANGLES), false, this,
                    UserHandle.USER_ALL);
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.VOLBTN_MUSIC_CONTROLS), false, this,
                    UserHandle.USER_ALL);

            updateSettings();
        }
@@ -1927,6 +1940,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
                    Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
                    UserHandle.USER_CURRENT);
            mVolBtnMusicControls = (Settings.System.getIntForUser(resolver,
                    Settings.System.VOLBTN_MUSIC_CONTROLS, 1, UserHandle.USER_CURRENT) == 1);

            // Configure wake gesture.
            boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
@@ -2865,7 +2880,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    @Override
    public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
        final boolean keyguardOn = keyguardOn();
        final int keyCode = event.getKeyCode();
        final int repeatCount = event.getRepeatCount();
        final int metaState = event.getMetaState();
        final int flags = event.getFlags();
@@ -2873,6 +2887,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        final boolean canceled = event.isCanceled();
        final boolean longPress = (flags & KeyEvent.FLAG_LONG_PRESS) != 0;
        final boolean virtualKey = event.getDeviceId() == KeyCharacterMap.VIRTUAL_KEYBOARD;
        final int keyCode = event.getKeyCode();

        if (DEBUG_INPUT) {
            Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
@@ -5128,6 +5143,20 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        setHdmiPlugged(!mHdmiPlugged);
    }

    /**
     * @return Whether music is being played right now "locally" (e.g. on the device's speakers
     *    or wired headphones) or "remotely" (e.g. on a device using the Cast protocol and
     *    controlled by this device, or through remote submix).
     */
    private boolean isMusicActive() {
        final AudioManager am = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
        if (am == null) {
            Log.w(TAG, "isMusicActive: couldn't get AudioManager reference");
            return false;
        }
        return am.isMusicActive();
    }

    final Object mScreenshotLock = new Object();
    ServiceConnection mScreenshotConnection = null;

@@ -5334,6 +5363,27 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                            break;
                        }
                    }
                }

                if (isMusicActive() && (result & ACTION_PASS_TO_USER) == 0) {
                    if (mVolBtnMusicControls && down && (keyCode != KeyEvent.KEYCODE_VOLUME_MUTE)) {
                        mIsLongPress = false;
                        int newKeyCode = event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP ?
                                KeyEvent.KEYCODE_MEDIA_NEXT : KeyEvent.KEYCODE_MEDIA_PREVIOUS;
                        Message msg = mHandler.obtainMessage(MSG_DISPATCH_VOLKEY_WITH_WAKE_LOCK,
                                new KeyEvent(event.getDownTime(), event.getEventTime(), event.getAction(), newKeyCode, 0));
                        msg.setAsynchronous(true);
                        mHandler.sendMessageDelayed(msg, ViewConfiguration.getLongPressTimeout());
                        break;
                    } else {
                        if (mVolBtnMusicControls && !down) {
                            mHandler.removeMessages(MSG_DISPATCH_VOLKEY_WITH_WAKE_LOCK);
                            if (mIsLongPress) {
                                break;
                            }
                        }
                    }
                }

                if ((result & ACTION_PASS_TO_USER) == 0) {
                    if (mUseTvRouting) {
@@ -5349,7 +5399,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                }
                }
                break;
            }

            case KeyEvent.KEYCODE_ENDCALL: {
                result &= ~ACTION_PASS_TO_USER;