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

Commit a29884a2 authored by Michael W's avatar Michael W
Browse files

LineageParts: Rewrite ButtonSettings to support feature exclusion

* Instead of maintaining 2 different sets of keys/values, introduce a
  mechanism to exclude specific values
* This allows to exclude certain values not just based on Go vs Non-Go
  devices

Change-Id: If7cf14b43b0e121ef07bb7e683ea7d5d0e98c157
parent 74bb6e4a
Loading
Loading
Loading
Loading
+0 −35
Original line number Diff line number Diff line
@@ -66,24 +66,6 @@
        <item>@string/hardware_keys_action_kill_app</item>
    </string-array>

    <!-- Hardware key rebinding for Go enabled devices -->
    <string-array name="hardware_keys_action_entries_go" translatable="false">
        <item>@string/hardware_keys_action_nothing</item>
        <item>@string/hardware_keys_action_menu</item>
        <item>@string/hardware_keys_action_app_switch</item>
        <item>@string/hardware_keys_action_search</item>
        <item>@string/hardware_keys_action_voice_search</item>
        <item>@string/hardware_keys_action_in_app_search</item>
        <item>@string/hardware_keys_action_launch_camera</item>
        <item>@string/hardware_keys_action_sleep</item>
        <item>@string/hardware_keys_action_last_app</item>
        <!--
        split-screen is not supported on Android Go devices
        <item>@string/hardware_keys_action_split_screen</item>
        -->
        <item>@string/hardware_keys_action_kill_app</item>
    </string-array>

    <string-array name="hardware_keys_action_values" translatable="false">
        <item>0</item>
        <item>1</item>
@@ -98,23 +80,6 @@
        <item>10</item>
    </string-array>

    <string-array name="hardware_keys_action_values_go" translatable="false">
        <item>0</item>
        <item>1</item>
        <item>2</item>
        <item>3</item>
        <item>4</item>
        <item>5</item>
        <item>6</item>
        <item>7</item>
        <item>8</item>
        <!--
        split-screen is not supported on Android Go devices
        <item>9</item>
        -->
        <item>10</item>
    </string-array>

    <!-- Volume key cursor control -->
    <string-array name="volbtn_cursor_control_entries" translatable="false">
        <item>@string/volbtn_cursor_control_off</item>
+57 −41
Original line number Diff line number Diff line
@@ -60,6 +60,9 @@ import org.lineageos.internal.util.ScreenType;

import static org.lineageos.internal.util.DeviceKeysConstants.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;

import lineageos.hardware.LineageHardwareManager;
@@ -484,63 +487,76 @@ public class ButtonSettings extends SettingsPreferenceFragment
            }
        }

        List<Integer> unsupportedValues = new ArrayList<>();
        List<String> entries = new ArrayList<>(
                Arrays.asList(res.getStringArray(R.array.hardware_keys_action_entries)));
        List<String> values = new ArrayList<>(
                Arrays.asList(res.getStringArray(R.array.hardware_keys_action_values)));

        // Override key actions on Go devices in order to hide any unsupported features
        if (ActivityManager.isLowRamDeviceStatic()) {
            String[] actionEntriesGo = res.getStringArray(R.array.hardware_keys_action_entries_go);
            String[] actionValuesGo = res.getStringArray(R.array.hardware_keys_action_values_go);
            unsupportedValues.add(Action.SPLIT_SCREEN.ordinal());
        }

        for (int unsupportedValue: unsupportedValues) {
            entries.remove(unsupportedValue);
            values.remove(unsupportedValue);
        }

        String[] actionEntries = entries.toArray(new String[0]);
        String[] actionValues = values.toArray(new String[0]);

        if (hasBackKey) {
                mBackLongPressAction.setEntries(actionEntriesGo);
                mBackLongPressAction.setEntryValues(actionValuesGo);
            mBackLongPressAction.setEntries(actionEntries);
            mBackLongPressAction.setEntryValues(actionValues);
        }

        if (hasHomeKey) {
                mHomeLongPressAction.setEntries(actionEntriesGo);
                mHomeLongPressAction.setEntryValues(actionValuesGo);
            mHomeLongPressAction.setEntries(actionEntries);
            mHomeLongPressAction.setEntryValues(actionValues);

                mHomeDoubleTapAction.setEntries(actionEntriesGo);
                mHomeDoubleTapAction.setEntryValues(actionValuesGo);
            mHomeDoubleTapAction.setEntries(actionEntries);
            mHomeDoubleTapAction.setEntryValues(actionValues);
        }

        if (hasMenuKey) {
                mMenuPressAction.setEntries(actionEntriesGo);
                mMenuPressAction.setEntryValues(actionValuesGo);
            mMenuPressAction.setEntries(actionEntries);
            mMenuPressAction.setEntryValues(actionValues);

                mMenuLongPressAction.setEntries(actionEntriesGo);
                mMenuLongPressAction.setEntryValues(actionValuesGo);
            mMenuLongPressAction.setEntries(actionEntries);
            mMenuLongPressAction.setEntryValues(actionValues);
        }

        if (hasAssistKey) {
                mAssistPressAction.setEntries(actionEntriesGo);
                mAssistPressAction.setEntryValues(actionValuesGo);
            mAssistPressAction.setEntries(actionEntries);
            mAssistPressAction.setEntryValues(actionValues);

                mAssistLongPressAction.setEntries(actionEntriesGo);
                mAssistLongPressAction.setEntryValues(actionValuesGo);
            mAssistLongPressAction.setEntries(actionEntries);
            mAssistLongPressAction.setEntryValues(actionValues);
        }

        if (hasAppSwitchKey) {
                mAppSwitchPressAction.setEntries(actionEntriesGo);
                mAppSwitchPressAction.setEntryValues(actionValuesGo);
            mAppSwitchPressAction.setEntries(actionEntries);
            mAppSwitchPressAction.setEntryValues(actionValues);

                mAppSwitchLongPressAction.setEntries(actionEntriesGo);
                mAppSwitchLongPressAction.setEntryValues(actionValuesGo);
            mAppSwitchLongPressAction.setEntries(actionEntries);
            mAppSwitchLongPressAction.setEntryValues(actionValues);
        }

            mNavigationBackLongPressAction.setEntries(actionEntriesGo);
            mNavigationBackLongPressAction.setEntryValues(actionValuesGo);
        mNavigationBackLongPressAction.setEntries(actionEntries);
        mNavigationBackLongPressAction.setEntryValues(actionValues);

            mNavigationHomeLongPressAction.setEntries(actionEntriesGo);
            mNavigationHomeLongPressAction.setEntryValues(actionValuesGo);
        mNavigationHomeLongPressAction.setEntries(actionEntries);
        mNavigationHomeLongPressAction.setEntryValues(actionValues);

            mNavigationHomeDoubleTapAction.setEntries(actionEntriesGo);
            mNavigationHomeDoubleTapAction.setEntryValues(actionValuesGo);
        mNavigationHomeDoubleTapAction.setEntries(actionEntries);
        mNavigationHomeDoubleTapAction.setEntryValues(actionValues);

            mNavigationAppSwitchLongPressAction.setEntries(actionEntriesGo);
            mNavigationAppSwitchLongPressAction.setEntryValues(actionValuesGo);
        mNavigationAppSwitchLongPressAction.setEntries(actionEntries);
        mNavigationAppSwitchLongPressAction.setEntryValues(actionValues);

            mEdgeLongSwipeAction.setEntries(actionEntriesGo);
            mEdgeLongSwipeAction.setEntryValues(actionValuesGo);
        }
        mEdgeLongSwipeAction.setEntries(actionEntries);
        mEdgeLongSwipeAction.setEntryValues(actionValues);
    }

    @Override