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

Commit 28a46cac authored by Ricardo Cerqueira's avatar Ricardo Cerqueira
Browse files

Swap volume buttons when the screen is rotated (1/2)

See: http://review.cyanogenmod.org/#/c/14530/

Patch Set 8: Invert the orientation interpretations on tablets

Change-Id: I201febc2827e6fbd347cb0e3f8d3347ad1bc487b

Conflicts:
	core/java/android/provider/Settings.java
parent 0bf89892
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -3003,6 +3003,15 @@ public final class Settings {
         */
        public static final String POWER_MENU_SOUND_ENABLED = "power_menu_silent_enabled";

        /**
          * Swap volume buttons when the screen is rotated
          * 0 - Disabled
          * 1 - Enabled (screen is rotated by 90 or 180 degrees: phone, hybrid)
          * 2 - Enabled (screen is rotated by 180 or 270 degrees: tablet)
          * @hide
          */
         public static final String SWAP_VOLUME_KEYS_ON_ROTATION = "swap_volume_keys_on_rotation";

         /**
          * Volume keys control cursor in text fields (default is 0)
          * 0 - Disabled
+27 −11
Original line number Diff line number Diff line
@@ -39,7 +39,9 @@ import android.os.ServiceManager;
import android.provider.Settings;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Surface;
import android.view.VolumePanel;
import android.view.WindowManager;

import java.util.HashMap;

@@ -58,6 +60,7 @@ public class AudioManager {
    private final Binder mToken = new Binder();
    private static String TAG = "AudioManager";
    private final ProfileManager mProfileManager;
    private final WindowManager mWindowManager;

    /**
     * Broadcast intent, a hint for applications that audio is about to become
@@ -436,6 +439,7 @@ public class AudioManager {
        mUseVolumeKeySounds = mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_useVolumeKeySounds);
        mProfileManager = (ProfileManager) context.getSystemService(Context.PROFILE_SERVICE);
        mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    }

    private static IAudioService getService()
@@ -518,21 +522,33 @@ public class AudioManager {
                 * Adjust the volume in on key down since it is more
                 * responsive to the user.
                 */
                int direction;
                int swapKeys = Settings.System.getInt(mContext.getContentResolver(),
                        Settings.System.SWAP_VOLUME_KEYS_ON_ROTATION, 0);
                int rotation = mWindowManager.getDefaultDisplay().getRotation();
                if (swapKeys == 1 // phone or hybrid
                        && (rotation == Surface.ROTATION_90
                        || rotation == Surface.ROTATION_180)) {
                    direction = keyCode == KeyEvent.KEYCODE_VOLUME_UP
                            ? ADJUST_LOWER
                            : ADJUST_RAISE;
                } else if (swapKeys == 2 // tablet
                        && (rotation == Surface.ROTATION_180
                        || rotation == Surface.ROTATION_270)) {
                    direction = keyCode == KeyEvent.KEYCODE_VOLUME_UP
                            ? ADJUST_LOWER
                            : ADJUST_RAISE;
                } else {
                    direction = keyCode == KeyEvent.KEYCODE_VOLUME_UP
                            ? ADJUST_RAISE
                            : ADJUST_LOWER;
                }
                int flags = FLAG_SHOW_UI | FLAG_VIBRATE;

                if (mUseMasterVolume) {
                    adjustMasterVolume(
                            keyCode == KeyEvent.KEYCODE_VOLUME_UP
                                    ? ADJUST_RAISE
                                    : ADJUST_LOWER,
                            flags);
                    adjustMasterVolume(direction, flags);
                } else {
                    adjustSuggestedStreamVolume(
                            keyCode == KeyEvent.KEYCODE_VOLUME_UP
                                    ? ADJUST_RAISE
                                    : ADJUST_LOWER,
                            stream,
                            flags);
                    adjustSuggestedStreamVolume(direction, stream, flags);
                }
                break;
            case KeyEvent.KEYCODE_VOLUME_MUTE: