Skip to content

Commit 7ac4c35

Browse files
maxwendinosnore1
authored andcommitted
base: tuner: fix navbar layout switch and remove old cruft
Change-Id: Ic9c63c1abf0493ee69a1ef8a3e95710be52a9f8e
1 parent 4b6cd5c commit 7ac4c35

6 files changed

Lines changed: 11 additions & 492 deletions

File tree

packages/SystemUI/res/xml/nav_bar_tuner.xml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,12 @@
1818
xmlns:sysui="http://schemas.android.com/apk/res-auto"
1919
android:title="@string/nav_bar">
2020

21-
<com.android.systemui.tuner.RadioListPreference
21+
<ListPreference
2222
android:key="layout"
2323
android:title="@string/nav_bar_layout"
2424
android:summary="%s"
2525
android:persistent="false"
2626
android:entries="@array/nav_bar_layouts"
2727
android:entryValues="@array/nav_bar_layouts_values" />
2828

29-
<Preference
30-
android:key="navbar_editor"
31-
android:title="@string/navbar_editor_title"
32-
android:summary="@string/navbar_editor_summary"
33-
android:fragment="com.android.systemui.tuner.NavBarEditor" />
34-
3529
</PreferenceScreen>

packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,12 @@
4040
import com.android.systemui.statusbar.phone.ReverseLinearLayout.ReverseRelativeLayout;
4141
import com.android.systemui.statusbar.policy.KeyButtonView;
4242
import com.android.systemui.tuner.TunerService;
43+
import com.android.systemui.tuner.TunerService.Tunable;
4344

4445
import java.util.Objects;
4546

4647
public class NavigationBarInflaterView extends FrameLayout
47-
implements NavigationModeController.ModeChangedListener, TunerService.Tunable {
48+
implements NavigationModeController.ModeChangedListener, Tunable {
4849

4950
private static final String TAG = "NavBarInflater";
5051

@@ -157,6 +158,7 @@ public void onNavigationModeChanged(int mode) {
157158
protected void onAttachedToWindow() {
158159
super.onAttachedToWindow();
159160
Dependency.get(TunerService.class).addTunable(this, NAV_BAR_INVERSE);
161+
Dependency.get(TunerService.class).addTunable(this, NAV_BAR_VIEWS);
160162
}
161163

162164
@Override
@@ -172,6 +174,9 @@ public void onTuningChanged(String key, String newValue) {
172174
mInverseLayout = TunerService.parseIntegerSwitch(newValue, false);
173175
updateLayoutInversion();
174176
}
177+
if (NAV_BAR_VIEWS.equals(key)) {
178+
setNavigationBarLayout(newValue);
179+
}
175180
}
176181

177182
@Override

packages/SystemUI/src/com/android/systemui/tuner/CustomListPreference.java

Lines changed: 0 additions & 170 deletions
This file was deleted.

packages/SystemUI/src/com/android/systemui/tuner/NavBarTuner.java

Lines changed: 4 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -44,31 +44,17 @@
4444
import androidx.preference.ListPreference;
4545
import androidx.preference.Preference;
4646
import androidx.preference.Preference.OnPreferenceChangeListener;
47+
import androidx.preference.PreferenceFragment;
4748

4849
import com.android.systemui.Dependency;
4950
import com.android.systemui.R;
5051
import com.android.systemui.tuner.TunerService.Tunable;
5152

5253
import java.util.ArrayList;
5354

54-
public class NavBarTuner extends TunerPreferenceFragment {
55+
public class NavBarTuner extends PreferenceFragment {
5556

5657
private static final String LAYOUT = "layout";
57-
private static final String LEFT = "left";
58-
private static final String RIGHT = "right";
59-
60-
private static final String TYPE = "type";
61-
private static final String KEYCODE = "keycode";
62-
private static final String ICON = "icon";
63-
64-
private static final int[][] ICONS = new int[][]{
65-
{R.drawable.ic_qs_circle, R.string.tuner_circle},
66-
{R.drawable.ic_add, R.string.tuner_plus},
67-
{R.drawable.ic_remove, R.string.tuner_minus},
68-
{R.drawable.ic_left, R.string.tuner_left},
69-
{R.drawable.ic_right, R.string.tuner_right},
70-
{R.drawable.ic_menu, R.string.tuner_menu},
71-
};
7258

7359
private final ArrayList<Tunable> mTunables = new ArrayList<>();
7460
private Handler mHandler;
@@ -89,8 +75,6 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
8975
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
9076
addPreferencesFromResource(R.xml.nav_bar_tuner);
9177
bindLayout((ListPreference) findPreference(LAYOUT));
92-
bindButton(NAV_BAR_LEFT, NAVSPACE, LEFT);
93-
bindButton(NAV_BAR_RIGHT, MENU_IME_ROTATE, RIGHT);
9478
}
9579

9680
@Override
@@ -114,126 +98,11 @@ private void bindLayout(ListPreference preference) {
11498
}), NAV_BAR_VIEWS);
11599
preference.setOnPreferenceChangeListener((preference1, newValue) -> {
116100
String val = (String) newValue;
101+
int valueIndex = preference.findIndexOfValue(val);
102+
preference.setSummary(preference.getEntries()[valueIndex]);
117103
if ("default".equals(val)) val = null;
118104
Dependency.get(TunerService.class).setValue(NAV_BAR_VIEWS, val);
119105
return true;
120106
});
121107
}
122-
123-
private void bindButton(String setting, String def, String k) {
124-
ListPreference type = (ListPreference) findPreference(TYPE + "_" + k);
125-
Preference keycode = findPreference(KEYCODE + "_" + k);
126-
ListPreference icon = (ListPreference) findPreference(ICON + "_" + k);
127-
setupIcons(icon);
128-
addTunable((key, newValue) -> mHandler.post(() -> {
129-
String val = newValue;
130-
if (val == null) {
131-
val = def;
132-
}
133-
String button = extractButton(val);
134-
if (button.startsWith(KEY)) {
135-
type.setValue(KEY);
136-
String uri = extractImage(button);
137-
int code = extractKeycode(button);
138-
icon.setValue(uri);
139-
updateSummary(icon);
140-
keycode.setSummary(code + "");
141-
keycode.setVisible(true);
142-
icon.setVisible(true);
143-
} else {
144-
type.setValue(button);
145-
keycode.setVisible(false);
146-
icon.setVisible(false);
147-
}
148-
}), setting);
149-
OnPreferenceChangeListener listener = (preference, newValue) -> {
150-
mHandler.post(() -> {
151-
setValue(setting, type, keycode, icon);
152-
updateSummary(icon);
153-
});
154-
return true;
155-
};
156-
type.setOnPreferenceChangeListener(listener);
157-
icon.setOnPreferenceChangeListener(listener);
158-
keycode.setOnPreferenceClickListener(preference -> {
159-
EditText editText = new EditText(getContext());
160-
new AlertDialog.Builder(getContext())
161-
.setTitle(preference.getTitle())
162-
.setView(editText)
163-
.setNegativeButton(android.R.string.cancel, null)
164-
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
165-
int code = KeyEvent.KEYCODE_ENTER;
166-
try {
167-
code = Integer.parseInt(editText.getText().toString());
168-
} catch (Exception e) {
169-
}
170-
keycode.setSummary(code + "");
171-
setValue(setting, type, keycode, icon);
172-
}).show();
173-
return true;
174-
});
175-
}
176-
177-
private void updateSummary(ListPreference icon) {
178-
try {
179-
int size = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 14,
180-
getContext().getResources().getDisplayMetrics());
181-
String pkg = icon.getValue().split("/")[0];
182-
int id = Integer.parseInt(icon.getValue().split("/")[1]);
183-
SpannableStringBuilder builder = new SpannableStringBuilder();
184-
Drawable d = Icon.createWithResource(pkg, id)
185-
.loadDrawable(getContext());
186-
d.setTint(Color.BLACK);
187-
d.setBounds(0, 0, size, size);
188-
ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BASELINE);
189-
builder.append(" ", span, 0);
190-
builder.append(" ");
191-
for (int i = 0; i < ICONS.length; i++) {
192-
if (ICONS[i][0] == id) {
193-
builder.append(getString(ICONS[i][1]));
194-
}
195-
}
196-
icon.setSummary(builder);
197-
} catch (Exception e) {
198-
Log.d("NavButton", "Problem with summary", e);
199-
icon.setSummary(null);
200-
}
201-
}
202-
203-
private void setValue(String setting, ListPreference type, Preference keycode,
204-
ListPreference icon) {
205-
String button = type.getValue();
206-
if (KEY.equals(button)) {
207-
String uri = icon.getValue();
208-
int code = KeyEvent.KEYCODE_ENTER;
209-
try {
210-
code = Integer.parseInt(keycode.getSummary().toString());
211-
} catch (Exception e) {
212-
}
213-
button = button + KEY_CODE_START + code + KEY_IMAGE_DELIM + uri + KEY_CODE_END;
214-
}
215-
Dependency.get(TunerService.class).setValue(setting, button);
216-
}
217-
218-
private void setupIcons(ListPreference icon) {
219-
CharSequence[] labels = new CharSequence[ICONS.length];
220-
CharSequence[] values = new CharSequence[ICONS.length];
221-
int size = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 14,
222-
getContext().getResources().getDisplayMetrics());
223-
for (int i = 0; i < ICONS.length; i++) {
224-
SpannableStringBuilder builder = new SpannableStringBuilder();
225-
Drawable d = Icon.createWithResource(getContext().getPackageName(), ICONS[i][0])
226-
.loadDrawable(getContext());
227-
d.setTint(Color.BLACK);
228-
d.setBounds(0, 0, size, size);
229-
ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BASELINE);
230-
builder.append(" ", span, 0);
231-
builder.append(" ");
232-
builder.append(getString(ICONS[i][1]));
233-
labels[i] = builder;
234-
values[i] = getContext().getPackageName() + "/" + ICONS[i][0];
235-
}
236-
icon.setEntries(labels);
237-
icon.setEntryValues(values);
238-
}
239108
}

0 commit comments

Comments
 (0)