mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-27 15:26:58 +00:00
Add filtering of preferences in developer options
Search will recursively go into each preference group and set visibility of preferences based on title match. If a preference group (category) has no preferences, we will hide that preference group as well. All queries and titles are sanitized by turning them to lower case and replacing underscores with spaces for convenience. Change-Id: Ibdc689d74d0c872c92c1d523bbc0efdb9e31aecd
This commit is contained in:
21
res/layout/home_settings.xml
Normal file
21
res/layout/home_settings.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/filter_box"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="@dimen/developer_options_filter_margins"
|
||||
android:hint="@string/developer_options_filter_hint"
|
||||
android:visibility="gone"
|
||||
/>
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@android:id/list_container"/>
|
||||
</LinearLayout>
|
||||
@@ -247,6 +247,9 @@
|
||||
<dimen name="snackbar_min_text_size">12sp</dimen>
|
||||
<dimen name="snackbar_max_text_size">14sp</dimen>
|
||||
|
||||
<!-- Developer Options -->
|
||||
<dimen name="developer_options_filter_margins">10dp</dimen>
|
||||
|
||||
<!-- Theming related -->
|
||||
<dimen name="default_dialog_corner_radius">8dp</dimen>
|
||||
|
||||
|
||||
@@ -348,7 +348,8 @@
|
||||
<!-- content description for paused work apps list -->
|
||||
<string name="work_apps_paused_content_description">Work profile is paused. Work apps can\’t send you notifications, use your battery, or access your location</string>
|
||||
|
||||
|
||||
<!-- A hint shown in launcher settings develop options filter box -->
|
||||
<string name="developer_options_filter_hint">Filter</string>
|
||||
|
||||
<!-- A tip shown pointing at work toggle -->
|
||||
<string name="work_switch_tip">Pause work apps and notifications</string>
|
||||
|
||||
@@ -149,6 +149,15 @@
|
||||
|
||||
<style name="HomeSettingsTheme" parent="@android:style/Theme.DeviceDefault.Settings">
|
||||
<item name="android:navigationBarColor">@android:color/transparent</item>
|
||||
<item name="preferenceTheme">@style/HomeSettingsPreferenceTheme</item>
|
||||
</style>
|
||||
|
||||
<style name="HomeSettingsPreferenceTheme" parent="@style/PreferenceThemeOverlay.v14.Material">
|
||||
<item name="preferenceFragmentCompatStyle">@style/HomeSettingsFragmentCompatStyle</item>
|
||||
</style>
|
||||
|
||||
<style name="HomeSettingsFragmentCompatStyle" parent="@style/PreferenceFragment.Material">
|
||||
<item name="android:layout">@layout/home_settings</item>
|
||||
</style>
|
||||
|
||||
<!--
|
||||
|
||||
@@ -34,17 +34,23 @@ import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.Pair;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceDataStore;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
import androidx.preference.PreferenceGroup;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
import androidx.preference.SwitchPreference;
|
||||
@@ -81,6 +87,7 @@ public class DeveloperOptionsFragment extends PreferenceFragmentCompat {
|
||||
private PreferenceCategory mPluginsCategory;
|
||||
private FlagTogglerPrefUi mFlagTogglerPrefUi;
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||
IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
|
||||
@@ -99,6 +106,50 @@ public class DeveloperOptionsFragment extends PreferenceFragmentCompat {
|
||||
maybeAddSandboxCategory();
|
||||
}
|
||||
|
||||
private void filterPreferences(String query, PreferenceGroup pg) {
|
||||
int count = pg.getPreferenceCount();
|
||||
int hidden = 0;
|
||||
for (int i = 0; i < count; i++) {
|
||||
Preference preference = pg.getPreference(i);
|
||||
if (preference instanceof PreferenceGroup) {
|
||||
filterPreferences(query, (PreferenceGroup) preference);
|
||||
} else {
|
||||
String title = preference.getTitle().toString().toLowerCase().replace("_", " ");
|
||||
if (query.isEmpty() || title.contains(query)) {
|
||||
preference.setVisible(true);
|
||||
} else {
|
||||
preference.setVisible(false);
|
||||
hidden++;
|
||||
}
|
||||
}
|
||||
}
|
||||
pg.setVisible(hidden != count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
EditText filterBox = view.findViewById(R.id.filter_box);
|
||||
filterBox.setVisibility(View.VISIBLE);
|
||||
filterBox.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable editable) {
|
||||
String query = editable.toString().toLowerCase().replace("_", " ");
|
||||
filterPreferences(query, mPreferenceScreen);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
Reference in New Issue
Block a user