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

Commit bed06dd5 authored by Michael Bestas's avatar Michael Bestas
Browse files

CMParts: Remove unused power menu actions and cleanup

Change-Id: Iadadd369ebe3843502cc16aa7ff4916ab04de89c
parent 90d663a1
Loading
Loading
Loading
Loading
+0 −10
Original line number Diff line number Diff line
@@ -81,16 +81,6 @@
        <item>11</item>
    </string-array>

    <string-array name="power_menu_actions_array" translatable="false">
        <item>power</item>
        <item>restart</item>
        <item>screenshot</item>
        <item>airplane</item>
        <item>users</item>
        <item>bugreport</item>
        <item>silent</item>
    </string-array>

    <!-- Volume key cursor control -->
    <string-array name="volbtn_cursor_control_entries" translatable="false">
        <item>@string/volbtn_cursor_control_off</item>
+1 −3
Original line number Diff line number Diff line
@@ -244,11 +244,9 @@
    <string name="power_menu_screenshot_title">Screenshot</string>
    <string name="power_menu_airplane_title">Airplane mode</string>
    <string name="power_menu_users_title">User switcher</string>
    <string name="power_menu_settings_title">Settings shortcut</string>
    <string name="power_menu_lockdown_title">Device lockdown</string>
    <string name="power_menu_bug_report_title">Bug report</string>
    <string name="power_menu_sound_title">Sound panel</string>
    <string name="power_menu_bug_report_disabled">Bug reporting is disabled in development settings</string>
    <string name="power_menu_sound_title">Sound panel</string>

    <string name="volume_keys_control_ring_stream_title">Control ringtone volume</string>
    <string name="volume_keys_control_ring_stream_summary_on">Volume keys control ringtone volume</string>
+1 −21
Original line number Diff line number Diff line
@@ -39,16 +39,6 @@
        android:title="@string/power_menu_users_title"
        android:defaultValue="false" />

    <CheckBoxPreference
        android:key="settings"
        android:title="@string/power_menu_settings_title"
        android:defaultValue="false" />

    <CheckBoxPreference
        android:key="lockdown"
        android:title="@string/power_menu_lockdown_title"
        android:defaultValue="false" />

    <CheckBoxPreference
        android:key="bugreport"
        android:title="@string/power_menu_bug_report_title"
@@ -57,16 +47,6 @@
    <CheckBoxPreference
        android:key="silent"
        android:title="@string/power_menu_sound_title"
        android:defaultValue="true" />

    <CheckBoxPreference
        android:key="voiceassist"
        android:title="@string/power_menu_sound_title"
        android:defaultValue="true" />

    <CheckBoxPreference
        android:key="assist"
        android:title="@string/power_menu_sound_title"
        android:defaultValue="true" />
        android:defaultValue="false" />

</PreferenceScreen>
+1 −63
Original line number Diff line number Diff line
@@ -33,7 +33,6 @@ import org.cyanogenmod.cmparts.R;
import org.cyanogenmod.cmparts.SettingsPreferenceFragment;

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

import cyanogenmod.providers.CMSettings;
@@ -56,16 +55,11 @@ public class PowerMenuActions extends SettingsPreferenceFragment {
    private CheckBoxPreference mScreenshotPref;
    private CheckBoxPreference mAirplanePref;
    private CheckBoxPreference mUsersPref;
    private CheckBoxPreference mSettingsPref;
    private CheckBoxPreference mLockdownPref;
    private CheckBoxPreference mBugReportPref;
    private CheckBoxPreference mSilentPref;
    private CheckBoxPreference mVoiceAssistPref;
    private CheckBoxPreference mAssistPref;

    Context mContext;
    private ArrayList<String> mLocalUserConfig = new ArrayList<String>();
    private String[] mAvailableActions;
    private String[] mAllActions;

    @Override
@@ -75,17 +69,9 @@ public class PowerMenuActions extends SettingsPreferenceFragment {
        addPreferencesFromResource(R.xml.power_menu_settings);
        mContext = getActivity().getApplicationContext();

        mAvailableActions = getActivity().getResources().getStringArray(
                R.array.power_menu_actions_array);
        mAllActions = PowerMenuConstants.getAllActions();

        for (String action : mAllActions) {
        // Remove preferences not present in the overlay
            if (!isActionAllowed(action)) {
                getPreferenceScreen().removePreference(findPreference(action));
                continue;
            }

            if (action.equals(GLOBAL_ACTION_KEY_RESTART)) {
                mRebootPref = (CheckBoxPreference) findPreference(GLOBAL_ACTION_KEY_RESTART);
            } else if (action.equals(GLOBAL_ACTION_KEY_SCREENSHOT)) {
@@ -94,18 +80,10 @@ public class PowerMenuActions extends SettingsPreferenceFragment {
                mAirplanePref = (CheckBoxPreference) findPreference(GLOBAL_ACTION_KEY_AIRPLANE);
            } else if (action.equals(GLOBAL_ACTION_KEY_USERS)) {
                mUsersPref = (CheckBoxPreference) findPreference(GLOBAL_ACTION_KEY_USERS);
            } else if (action.equals(GLOBAL_ACTION_KEY_SETTINGS)) {
                mSettingsPref = (CheckBoxPreference) findPreference(GLOBAL_ACTION_KEY_SETTINGS);
            } else if (action.equals(GLOBAL_ACTION_KEY_LOCKDOWN)) {
                mLockdownPref = (CheckBoxPreference) findPreference(GLOBAL_ACTION_KEY_LOCKDOWN);
            } else if (action.equals(GLOBAL_ACTION_KEY_BUGREPORT)) {
                mBugReportPref = (CheckBoxPreference) findPreference(GLOBAL_ACTION_KEY_BUGREPORT);
            } else if (action.equals(GLOBAL_ACTION_KEY_SILENT)) {
                mSilentPref = (CheckBoxPreference) findPreference(GLOBAL_ACTION_KEY_SILENT);
            } else if (action.equals(GLOBAL_ACTION_KEY_VOICEASSIST)) {
                mSilentPref = (CheckBoxPreference) findPreference(GLOBAL_ACTION_KEY_VOICEASSIST);
            } else if (action.equals(GLOBAL_ACTION_KEY_ASSIST)) {
                mSilentPref = (CheckBoxPreference) findPreference(GLOBAL_ACTION_KEY_ASSIST);
            }
        }

@@ -141,14 +119,6 @@ public class PowerMenuActions extends SettingsPreferenceFragment {
            }
        }

        if (mSettingsPref != null) {
            mSettingsPref.setChecked(settingsArrayContains(GLOBAL_ACTION_KEY_SETTINGS));
        }

        if (mLockdownPref != null) {
            mLockdownPref.setChecked(settingsArrayContains(GLOBAL_ACTION_KEY_LOCKDOWN));
        }

        if (mBugReportPref != null) {
            mBugReportPref.setChecked(settingsArrayContains(GLOBAL_ACTION_KEY_BUGREPORT));
        }
@@ -157,14 +127,6 @@ public class PowerMenuActions extends SettingsPreferenceFragment {
            mSilentPref.setChecked(settingsArrayContains(GLOBAL_ACTION_KEY_SILENT));
        }

        if (mVoiceAssistPref != null) {
            mVoiceAssistPref.setChecked(settingsArrayContains(GLOBAL_ACTION_KEY_VOICEASSIST));
        }

        if (mAssistPref != null) {
            mAssistPref.setChecked(settingsArrayContains(GLOBAL_ACTION_KEY_ASSIST));
        }

        updatePreferences();
    }

@@ -194,14 +156,6 @@ public class PowerMenuActions extends SettingsPreferenceFragment {
            value = mUsersPref.isChecked();
            updateUserConfig(value, GLOBAL_ACTION_KEY_USERS);

        } else if (preference == mSettingsPref) {
            value = mSettingsPref.isChecked();
            updateUserConfig(value, GLOBAL_ACTION_KEY_SETTINGS);

        } else if (preference == mLockdownPref) {
            value = mLockdownPref.isChecked();
            updateUserConfig(value, GLOBAL_ACTION_KEY_LOCKDOWN);

        } else if (preference == mBugReportPref) {
            value = mBugReportPref.isChecked();
            updateUserConfig(value, GLOBAL_ACTION_KEY_BUGREPORT);
@@ -210,14 +164,6 @@ public class PowerMenuActions extends SettingsPreferenceFragment {
            value = mSilentPref.isChecked();
            updateUserConfig(value, GLOBAL_ACTION_KEY_SILENT);

        } else if (preference == mVoiceAssistPref) {
            value = mVoiceAssistPref.isChecked();
            updateUserConfig(value, GLOBAL_ACTION_KEY_VOICEASSIST);

        } else if (preference == mAssistPref) {
            value = mAssistPref.isChecked();
            updateUserConfig(value, GLOBAL_ACTION_KEY_ASSIST);

        } else {
            return super.onPreferenceTreeClick(preference);
        }
@@ -228,13 +174,6 @@ public class PowerMenuActions extends SettingsPreferenceFragment {
        return mLocalUserConfig.contains(preference);
    }

    private boolean isActionAllowed(String action) {
        if (Arrays.asList(mAvailableActions).contains(action)) {
            return true;
        }
        return false;
    }

    private void updateUserConfig(boolean enabled, String action) {
        if (enabled) {
            if (!settingsArrayContains(action)) {
@@ -284,10 +223,9 @@ public class PowerMenuActions extends SettingsPreferenceFragment {
    private void saveUserConfig() {
        StringBuilder s = new StringBuilder();

        // TODO: Use DragSortListView
        ArrayList<String> setactions = new ArrayList<String>();
        for (String action : mAllActions) {
            if (settingsArrayContains(action) && isActionAllowed(action)) {
            if (settingsArrayContains(action)) {
                setactions.add(action);
            } else {
                continue;