Allow width control of nav bar buttons
Encode the width as part of the spec as a float. For instance:
"home[.5]" is a home button with half its normal width.
The UI will allow users to adjust the width of standard buttons and
spaces from .25 to 1.75, excluding the app shelf, which fills all
available space.
Change-Id: Icd2f498c164933d61f55d779b3e9be0afaba9c2d
diff --git a/packages/SystemUI/res/layout/nav_width_view.xml b/packages/SystemUI/res/layout/nav_width_view.xml
new file mode 100644
index 0000000..6a72faf
--- /dev/null
+++ b/packages/SystemUI/res/layout/nav_width_view.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+**
+** Copyright 2016, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+** http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+
+<SeekBar
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/seekbar"
+ android:layout_height="wrap_content"
+ android:layout_width="match_parent"
+ android:paddingTop="12dp"
+ android:paddingBottom="4dp" />
diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml
index f1c90a5..c1b58d8 100644
--- a/packages/SystemUI/res/values/strings.xml
+++ b/packages/SystemUI/res/values/strings.xml
@@ -1378,4 +1378,7 @@
<!-- SysUI Tuner: Message of no home warning dialog [CHAR LIMIT=NONE] -->
<string name="no_home_message">A home button is required to be able to navigate this device. Please add a home button before saving.</string>
+ <!-- SysUI Tuner: Adjust button width dialog title [CHAR LIMIT=60] -->
+ <string name="adjust_button_width">Adjust button width</string>
+
</resources>
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java
index 6de4d5c..d49e295 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java
@@ -50,6 +50,9 @@
protected final LayoutInflater mLayoutInflater;
protected final LayoutInflater mLandscapeInflater;
+ public static final String SIZE_MOD_START = "[";
+ public static final String SIZE_MOD_END = "]";
+
protected FrameLayout mRot0;
protected FrameLayout mRot90;
private SparseArray<ButtonDispatcher> mButtonDispatchers;
@@ -206,9 +209,11 @@
}
@Nullable
- protected View inflateButton(String button, ViewGroup parent, boolean landscape) {
- View v;
+ protected View inflateButton(String buttonSpec, ViewGroup parent, boolean landscape) {
LayoutInflater inflater = landscape ? mLandscapeInflater : mLayoutInflater;
+ float size = extractSize(buttonSpec);
+ String button = extractButton(buttonSpec);
+ View v = null;
if (HOME.equals(button)) {
v = inflater.inflate(R.layout.home, parent, false);
if (landscape && isSw600Dp()) {
@@ -232,11 +237,31 @@
return null;
}
+ if (size != 0) {
+ ViewGroup.LayoutParams params = v.getLayoutParams();
+ params.width = (int) (params.width * size);
+ }
parent.addView(v);
addToDispatchers(v);
return v;
}
+ public static float extractSize(String buttonSpec) {
+ if (!buttonSpec.contains(SIZE_MOD_START)) {
+ return 1;
+ }
+ final int sizeStart = buttonSpec.indexOf(SIZE_MOD_START);
+ String sizeStr = buttonSpec.substring(sizeStart + 1, buttonSpec.indexOf(SIZE_MOD_END));
+ return Float.parseFloat(sizeStr);
+ }
+
+ public static String extractButton(String buttonSpec) {
+ if (!buttonSpec.contains(SIZE_MOD_START)) {
+ return buttonSpec;
+ }
+ return buttonSpec.substring(0, buttonSpec.indexOf(SIZE_MOD_START));
+ }
+
private void addToDispatchers(View v) {
if (mButtonDispatchers != null) {
final int indexOfKey = mButtonDispatchers.indexOfKey(v.getId());
diff --git a/packages/SystemUI/src/com/android/systemui/tuner/NavBarTuner.java b/packages/SystemUI/src/com/android/systemui/tuner/NavBarTuner.java
index eed453a..5d0c145 100644
--- a/packages/SystemUI/src/com/android/systemui/tuner/NavBarTuner.java
+++ b/packages/SystemUI/src/com/android/systemui/tuner/NavBarTuner.java
@@ -39,11 +39,16 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
+import android.widget.SeekBar;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
+import static com.android.systemui.statusbar.phone.NavigationBarInflaterView.SIZE_MOD_END;
+import static com.android.systemui.statusbar.phone.NavigationBarInflaterView.SIZE_MOD_START;
+import static com.android.systemui.statusbar.phone.NavigationBarInflaterView.extractButton;
+import static com.android.systemui.statusbar.phone.NavigationBarInflaterView.extractSize;
import static com.android.systemui.statusbar.phone.NavigationBarInflaterView.BACK;
import static com.android.systemui.statusbar.phone.NavigationBarInflaterView.BUTTON_SEPARATOR;
import static com.android.systemui.statusbar.phone.NavigationBarInflaterView.GRAVITY_SEPARATOR;
@@ -143,15 +148,15 @@
}
private static CharSequence getLabel(String button, Context context) {
- if (HOME.equals(button)) {
+ if (button.startsWith(HOME)) {
return context.getString(R.string.accessibility_home);
- } else if (BACK.equals(button)) {
+ } else if (button.startsWith(BACK)) {
return context.getString(R.string.accessibility_back);
- } else if (RECENT.equals(button)) {
+ } else if (button.startsWith(RECENT)) {
return context.getString(R.string.accessibility_recent);
- } else if (NAVSPACE.equals(button)) {
+ } else if (button.startsWith(NAVSPACE)) {
return context.getString(R.string.space);
- } else if (MENU_IME.equals(button)) {
+ } else if (button.startsWith(MENU_IME)) {
return context.getString(R.string.menu_ime);
}
return button;
@@ -238,7 +243,13 @@
}
public boolean hasHomeButton() {
- return mButtons.contains(HOME);
+ final int N = mButtons.size();
+ for (int i = 0; i < N; i++) {
+ if (mButtons.get(i).startsWith(HOME)) {
+ return true;
+ }
+ }
+ return false;
}
public String getNavString() {
@@ -367,16 +378,46 @@
@Override
public void onClick(View v) {
Holder holder = (Holder) v.getTag();
- int position = holder.getAdapterPosition();
if (v.getId() == R.id.width) {
- // TODO: Handle width control.
+ showWidthDialog(holder, v.getContext());
} else if (v.getId() == R.id.close) {
+ int position = holder.getAdapterPosition();
mButtons.remove(position);
mLabels.remove(position);
notifyItemRemoved(position);
}
}
+ private void showWidthDialog(final Holder holder, Context context) {
+ final String buttonSpec = mButtons.get(holder.getAdapterPosition());
+ float amount = extractSize(buttonSpec);
+ final AlertDialog dialog = new AlertDialog.Builder(context)
+ .setTitle(R.string.adjust_button_width)
+ .setView(R.layout.nav_width_view)
+ .setNegativeButton(android.R.string.cancel, null).create();
+ dialog.setButton(DialogInterface.BUTTON_POSITIVE,
+ context.getString(android.R.string.ok),
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface d, int which) {
+ final String button = extractButton(buttonSpec);
+ SeekBar seekBar = (SeekBar) dialog.findViewById(R.id.seekbar);
+ if (seekBar.getProgress() == 75) {
+ mButtons.set(holder.getAdapterPosition(), button);
+ } else {
+ float amount = (seekBar.getProgress() + 25) / 100f;
+ mButtons.set(holder.getAdapterPosition(), button
+ + SIZE_MOD_START + amount + SIZE_MOD_END);
+ }
+ }
+ });
+ dialog.show();
+ SeekBar seekBar = (SeekBar) dialog.findViewById(R.id.seekbar);
+ // Range is .25 - 1.75.
+ seekBar.setMax(150);
+ seekBar.setProgress((int) ((amount - .25f) * 100));
+ }
+
@Override
public int getItemCount() {
return mButtons.size();