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

Commit 87a1007b authored by Adnan Begovic's avatar Adnan Begovic
Browse files

Settings: Clean up code style in ButtonSettings

Change-Id: I6df0ee12536dcca2b9734785bebe16a0fea7f0c2
parent 55cdb1ac
Loading
Loading
Loading
Loading
+16 −11
Original line number Diff line number Diff line
@@ -156,7 +156,8 @@ public class ButtonSettings extends SettingsPreferenceFragment implements
        mNavigationBarLeftPref = (SwitchPreference) findPreference(KEY_NAVIGATION_BAR_LEFT);

        // Navigation bar recents long press activity needs custom setup
        mNavigationRecentsLongPressAction = initRecentsLongPressAction(KEY_NAVIGATION_RECENTS_LONG_PRESS);
        mNavigationRecentsLongPressAction =
                initRecentsLongPressAction(KEY_NAVIGATION_RECENTS_LONG_PRESS);

        HashMap<String, String> prefsToRemove = (HashMap<String, String>)
                getPreferencesToRemove(this, getActivity());
@@ -459,15 +460,17 @@ public class ButtonSettings extends SettingsPreferenceFragment implements
            targetComponent = ComponentName.unflattenFromString(componentString);
        }

        // Dyanamically generate the list array, query PackageManager for all Activites that are registered for
        // ACTION_RECENTS_LONG_PRESS
        // Dyanamically generate the list array,
        // query PackageManager for all Activites that are registered for ACTION_RECENTS_LONG_PRESS
        PackageManager pm = getPackageManager();
        Intent intent = new Intent(Intent.ACTION_RECENTS_LONG_PRESS);
        List<ResolveInfo> recentsActivities = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
        List<ResolveInfo> recentsActivities = pm.queryIntentActivities(intent,
                PackageManager.MATCH_DEFAULT_ONLY);
        if (recentsActivities.size() == 0) {
            // No entries available, disable
            list.setSummary(getString(R.string.hardware_keys_action_last_app));
            Settings.Secure.putString(getContentResolver(), Settings.Secure.RECENTS_LONG_PRESS_ACTIVITY, null);
            Settings.Secure.putString(getContentResolver(),
                    Settings.Secure.RECENTS_LONG_PRESS_ACTIVITY, null);
            list.setEnabled(false);
            return list;
        }
@@ -481,8 +484,8 @@ public class ButtonSettings extends SettingsPreferenceFragment implements
        int i = 1;
        for (ResolveInfo info : recentsActivities) {
            try {
                // Use pm.getApplicationInfo for the label, we cannot rely on ResolveInfo that comes back from
                // queryIntentActivities.
                // Use pm.getApplicationInfo for the label,
                // we cannot rely on ResolveInfo that comes back from queryIntentActivities.
                entries[i] = pm.getApplicationInfo(info.activityInfo.packageName, 0).loadLabel(pm);
            } catch (PackageManager.NameNotFoundException e) {
                Log.e(TAG, "Error package not found: " + info.activityInfo.packageName, e);
@@ -491,7 +494,8 @@ public class ButtonSettings extends SettingsPreferenceFragment implements
            }

            // Set the value to the ComponentName that will handle this intent
            ComponentName entryComponent = new ComponentName(info.activityInfo.packageName, info.activityInfo.name);
            ComponentName entryComponent = new ComponentName(info.activityInfo.packageName,
                    info.activityInfo.name);
            values[i] = entryComponent.flattenToString();
            if (targetComponent != null) {
                if (entryComponent.equals(targetComponent)) {
@@ -553,8 +557,8 @@ public class ButtonSettings extends SettingsPreferenceFragment implements
                    Settings.System.VOLUME_KEY_CURSOR_CONTROL);
            return true;
        } else if (preference == mNavigationRecentsLongPressAction) {
            // RecentsLongPressAction is handled differently because it intentionally uses Settings.
            // Settings.System.
            // RecentsLongPressAction is handled differently because it intentionally uses
            // Settings.System
            String putString = (String) newValue;
            int index = mNavigationRecentsLongPressAction.findIndexOfValue(putString);
            CharSequence summary = mNavigationRecentsLongPressAction.getEntries()[index];
@@ -563,7 +567,8 @@ public class ButtonSettings extends SettingsPreferenceFragment implements
            if (putString.length() == 0) {
                putString = null;
            }
            Settings.Secure.putString(getContentResolver(), Settings.Secure.RECENTS_LONG_PRESS_ACTIVITY, putString);
            Settings.Secure.putString(getContentResolver(),
                    Settings.Secure.RECENTS_LONG_PRESS_ACTIVITY, putString);
            return true;
        }
        return false;