LineageParts: 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: Vladimir Oltean <olteanv@gmail.com>
diff --git a/res/values/config.xml b/res/values/config.xml
index d49bab4..4236b27 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -27,4 +27,18 @@
          The array should be sorted in the same order as the
          touchscreen gestures advertised by the device's LineageHW 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>
diff --git a/src/org/lineageos/lineageparts/input/ButtonSettings.java b/src/org/lineageos/lineageparts/input/ButtonSettings.java
index e598e57..cdd9943 100644
--- a/src/org/lineageos/lineageparts/input/ButtonSettings.java
+++ b/src/org/lineageos/lineageparts/input/ButtonSettings.java
@@ -663,18 +663,20 @@
     @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();
+            int value;
 
-                DisplayInfo displayInfo = new DisplayInfo();
-                defaultDisplay.getDisplayInfo(displayInfo);
-
-                // Not all tablets are landscape
-                if (displayInfo.getNaturalWidth() < displayInfo.getNaturalHeight()) {
-                    value = 1;
-                }
+            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;
             }
             LineageSettings.System.putInt(getActivity().getContentResolver(),
                     LineageSettings.System.SWAP_VOLUME_KEYS_ON_ROTATION, value);