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

Commit 9ca0da14 authored by Vladimir Oltean's avatar Vladimir Oltean
Browse files

Parts: make volume button re-orient functionality act based on relevant input



* The only variable that matters in making the re-orient decision is
  where (on what side) the volume buttons are situated relative to the
  default screen orientation.
* This variable has been synthesized as a configurable integer resource
  named config_volumeRockerVsDisplayOrientation. The values for this
  resource are compatible with values expected by InputFlinger
  (1 for what it understands to be, generically, a "phone", and 2 for a
  "tablet").
* The patch is needed because the old logic could not determine reliably,
  programatically, what sort of tablets it was dealing with. It just
  assumed that landscape tablets automatically have the volume buttons
  placed on top, and portrait tablets on the sides (basically in the
  same place, considering that the framework's understanding of the
  device's screen orientation is the only thing that's changed here).
* Therefore, this patch makes things right for landscape tablets with
  the volume rocker on the sides, while also leaving room for more
  exotic future devices.

Change-Id: I46cc8fbee43c9ac3f5ae306ccbfe0bdd3a71d4b4
Signed-off-by: default avatarVladimir Oltean <olteanv@gmail.com>
parent b773f60d
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -27,4 +27,18 @@
         The array should be sorted in the same order as the
         touchscreen gestures advertised by the device's CMHW impl. -->
    <integer-array name="config_defaultTouchscreenGestureActions" />

    <!-- The position of the volume rocker, as opposed to the natural
         orientation of the display.
         Currently used for the volume button re-orient functionality.
         This integer should be set to:

         1 - if the volume rocker is on (or parallel to) one the lateral
             sides, relative to the natural orientation of the display
             (true for all phones and some tablets)
         2 - the volume rocker is on (or parallel to) the top or bottom,
             relative to the natural orientation of the display
             (true for some tablets) -->
    <integer name="config_volumeRockerVsDisplayOrientation">1</integer>

</resources>
+14 −12
Original line number Diff line number Diff line
@@ -732,18 +732,20 @@ public class ButtonSettings extends SettingsPreferenceFragment implements
    @Override
    public boolean onPreferenceTreeClick(Preference preference) {
        if (preference == mSwapVolumeButtons) {
            int value = mSwapVolumeButtons.isChecked()
                    ? (ScreenType.isTablet(getActivity()) ? 2 : 1) : 0;
            if (value == 2) {
                Display defaultDisplay = getActivity().getWindowManager().getDefaultDisplay();

                DisplayInfo displayInfo = new DisplayInfo();
                defaultDisplay.getDisplayInfo(displayInfo);

                // Not all tablets are landscape
                if (displayInfo.getNaturalWidth() < displayInfo.getNaturalHeight()) {
                    value = 1;
                }
            int value;

            if (mSwapVolumeButtons.isChecked()) {
                /* The native inputflinger service uses the same logic of:
                 *   1 - the volume rocker is on one the sides, relative to the natural
                 *       orientation of the display (true for all phones and most tablets)
                 *   2 - the volume rocker is on the top or bottom, relative to the
                 *       natural orientation of the display (true for some tablets)
                 */
                value = getResources().getInteger(
                        R.integer.config_volumeRockerVsDisplayOrientation);
            } else {
                /* Disable the re-orient functionality */
                value = 0;
            }
            CMSettings.System.putInt(getActivity().getContentResolver(),
                    CMSettings.System.SWAP_VOLUME_KEYS_ON_ROTATION, value);