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

Commit b21dcd64 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 f4bf533b
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -2196,6 +2196,12 @@ public final class Settings {
         */
        public static final String VOLUME_WAKE_SCREEN = "volume_wake_screen";

        /**
         * 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).
         *
+56 −8
Original line number Diff line number Diff line
@@ -408,6 +408,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    // Volume wake control flag
    boolean mVolumeWakeScreen;

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

    PointerLocationView mPointerLocationView;

    // The current size of the screen; really; extends into the overscan area of
@@ -608,6 +612,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
    private static final int MSG_HIDE_BOOT_MESSAGE = 11;
    private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
    private static final int MSG_DISPATCH_VOLKEY_WITH_WAKE_LOCK = 13;
    boolean mWifiDisplayConnected = false;
    int     mWifiDisplayCustomRotation = -1;
    private boolean mHasPermanentMenuKey;
@@ -628,6 +633,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
                    dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
                    break;
                case MSG_DISPATCH_VOLKEY_WITH_WAKE_LOCK:
                    dispatchMediaKeyWithWakeLockToAudioService((KeyEvent)msg.obj);
                    dispatchMediaKeyWithWakeLockToAudioService(KeyEvent.changeAction((KeyEvent)msg.obj, KeyEvent.ACTION_UP));
                    break;
                case MSG_DISPATCH_SHOW_RECENTS:
                    showRecentApps(false);
                    break;
@@ -740,6 +749,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.VOLUME_WAKE_SCREEN), false, this,
                    UserHandle.USER_ALL);
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.VOLBTN_MUSIC_CONTROLS), false, this,
                    UserHandle.USER_ALL);
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.ACCELEROMETER_ROTATION_ANGLES), false, this,
                    UserHandle.USER_ALL);
@@ -1612,6 +1624,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    UserHandle.USER_CURRENT);
            mHomeWakeScreen = (Settings.System.getIntForUser(resolver,
                    Settings.System.HOME_WAKE_SCREEN, 1, UserHandle.USER_CURRENT) == 1);
            mVolBtnMusicControls = (Settings.System.getIntForUser(resolver,
                    Settings.System.VOLBTN_MUSIC_CONTROLS, 1, UserHandle.USER_CURRENT) == 1);

            // Configure wake gesture.
            boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
@@ -2539,7 +2553,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();
@@ -2547,6 +2560,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;
        int keyCode = event.getKeyCode();

        if (DEBUG_INPUT) {
            Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
@@ -4661,6 +4675,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;

@@ -4943,6 +4971,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 we aren't passing to the user and no one else
@@ -4954,7 +5003,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                }
                }
                break;
            }

            case KeyEvent.KEYCODE_HOME:
                if (down && !interactive && mHomeWakeScreen) {