diff options
| author | Danny Baumann <dannybaumann@web.de> | 2013-04-02 00:54:14 -0700 |
|---|---|---|
| committer | Gerrit Code Review <gerrit@cyanogenmod.org> | 2013-04-02 00:54:14 -0700 |
| commit | 2f9b1f02e016e1070f3bbcc70aed758325cc1880 (patch) | |
| tree | e229feaae05abb43e790e0d58288e4358a651693 /packages/SystemUI/src | |
| parent | 675432c81c82a8d6509ba13f6d6e38c74e603330 (diff) | |
| parent | 1c601ac8dde76d68e3824191e675256b47e0493f (diff) | |
| download | frameworks_base-2f9b1f02e016e1070f3bbcc70aed758325cc1880.zip frameworks_base-2f9b1f02e016e1070f3bbcc70aed758325cc1880.tar.gz frameworks_base-2f9b1f02e016e1070f3bbcc70aed758325cc1880.tar.bz2 | |
Merge "Merge Navigation Bar and Pie Controls button config (1/2)" into cm-10.1
Diffstat (limited to 'packages/SystemUI/src')
7 files changed, 370 insertions, 240 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java index 8eef365..8865842 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java @@ -1354,7 +1354,7 @@ public abstract class BaseStatusBar extends SystemUI implements resolver.registerContentObserver(Settings.System.getUriFor( Settings.System.PIE_CONTROLS), false, this); resolver.registerContentObserver(Settings.System.getUriFor( - Settings.System.PIE_GRAVITY), false, this); + Settings.System.PIE_POSITIONS), false, this); resolver.registerContentObserver(Settings.System.getUriFor( Settings.System.EXPANDED_DESKTOP_STATE), false, this); resolver.registerContentObserver(Settings.System.getUriFor( @@ -1366,7 +1366,7 @@ public abstract class BaseStatusBar extends SystemUI implements ContentResolver resolver = mContext.getContentResolver(); mPieTriggerSlots = Settings.System.getInt(resolver, - Settings.System.PIE_GRAVITY, Position.BOTTOM.FLAG); + Settings.System.PIE_POSITIONS, Position.BOTTOM.FLAG); boolean expanded = Settings.System.getInt(resolver, Settings.System.EXPANDED_DESKTOP_STATE, 0) == 1; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NavigationButtons.java b/packages/SystemUI/src/com/android/systemui/statusbar/NavigationButtons.java new file mode 100644 index 0000000..58c8181 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NavigationButtons.java @@ -0,0 +1,204 @@ +/* + * Copyright (C) 2013 The CyanogenMod Project + * This code is loosely based on portions of the ParanoidAndroid Project source, Copyright (C) 2012. + * + * 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. + */ +package com.android.systemui.statusbar; + +import android.content.Context; +import android.provider.Settings; +import android.view.KeyEvent; + +import com.android.systemui.R; + +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * Class that holds the global information about supported navigation buttons + * in CyanogenMod. + */ +public class NavigationButtons { + + /** + * Defines how many keys / key slots there may be for navigation. + * <b>WARNING</b> If you ever change this, don't forget check the source in + * {@code /phone/NavBarEdit.java} and {/pie/PieController.java} + */ + public static final int SLOT_COUNT = 6; + /** + * Defines the weight of each of the 6 keys. For most implementations this is + * hard-coded within a resource file. + */ + public static final boolean IS_SLOT_SMALL[] = { true, false, false, false, false, true }; + + /** + * Class to store the information about supported buttons + */ + public static final class ButtonInfo { + public final int displayId; + public final int contentDescription; + public final int keyCode; + public final int portResource; + public final int landResource; + public final int sideResource; + private final String key; + + /** + * Public constructor for new button types. Use this to create own {@link ButtonInfo}s + * for additional special keys you may want to support. <b>Note:</b> You can not + * persist your own {@link ButtonInfo}s with + * {@link NavigationButtons#storeButtonMap(Context, ButtonInfo[])}! + * @param rId - resource id of text shown to user in choose dialog + * @param cD - accessibility information regarding button + * @param mC - keyCode to execute on button press + * @param pR - portrait resource used to display button + * @param lR - landscape resource used to display button + * @param sR - smaller scaled resource for side buttons + */ + public ButtonInfo(int rId, int cD, int mC, int pR, int lR, int sR) { + displayId = rId; + contentDescription = cD; + keyCode = mC; + portResource = pR; + landResource = lR; + sideResource = sR; + key = ""; + } + /** + * Constructor for new button types + * @param rId - resource id of text shown to user in choose dialog + * @param cD - accessibility information regarding button + * @param mC - keyCode to execute on button press + * @param pR - portrait resource used to display button + * @param lR - landscape resource used to display button + * @param sR - smaller scaled resource for side buttons + * @param key - the internal key of the button + */ + public ButtonInfo(int rId, int cD, int mC, int pR, int lR, int sR, String key) { + displayId = rId; + contentDescription = cD; + keyCode = mC; + portResource = pR; + landResource = lR; + sideResource = sR; + this.key = key; + } + } + + // Available buttons string constants + private static final String EMPTY_STRING = "empty"; + private static final String HOME_STRING = "home"; + private static final String BACK_STRING = "back"; + private static final String SEARCH_STRING = "search"; + private static final String RECENT_STRING = "recent"; + private static final String CONDITIONAL_MENU_STRING = "menu0"; + private static final String ALWAYS_MENU_STRING = "menu1"; + private static final String MENU_BIG_STRING = "menu2"; + + private static final String DEFAULT_SETTING_STRING = "empty|back|home|recent|empty|menu0"; + + // All navigation button information CyanogenMod needs + public static final ButtonInfo HOME = new ButtonInfo( + R.string.navbar_home_button, + R.string.accessibility_home, KeyEvent.KEYCODE_HOME, R.drawable.ic_sysbar_home, + R.drawable.ic_sysbar_home_land, R.drawable.ic_sysbar_home, HOME_STRING); + public static final ButtonInfo CONDITIONAL_MENU = new ButtonInfo( + R.string.navbar_menu_conditional_button, + R.string.accessibility_menu, KeyEvent.KEYCODE_MENU, R.drawable.ic_sysbar_menu, + R.drawable.ic_sysbar_menu_land, R.drawable.ic_sysbar_menu, CONDITIONAL_MENU_STRING); + public static final ButtonInfo ALWAYS_MENU = new ButtonInfo( + R.string.navbar_menu_always_button, + R.string.accessibility_menu, KeyEvent.KEYCODE_MENU, R.drawable.ic_sysbar_menu, + R.drawable.ic_sysbar_menu_land, R.drawable.ic_sysbar_menu, ALWAYS_MENU_STRING); + public static final ButtonInfo MENU_BIG = new ButtonInfo( + R.string.navbar_menu_big_button, + R.string.accessibility_menu, KeyEvent.KEYCODE_MENU, R.drawable.ic_sysbar_menu_big, + R.drawable.ic_sysbar_menu_big_land, 0, MENU_BIG_STRING); + public static final ButtonInfo BACK = new ButtonInfo( + R.string.navbar_back_button, R.string.accessibility_back, + KeyEvent.KEYCODE_BACK, R.drawable.ic_sysbar_back, + R.drawable.ic_sysbar_back_land, R.drawable.ic_sysbar_back_side, BACK_STRING); + public static final ButtonInfo SEARCH = new ButtonInfo( + R.string.navbar_search_button, + R.string.accessibility_back, KeyEvent.KEYCODE_SEARCH, R.drawable.ic_sysbar_search, + R.drawable.ic_sysbar_search_land, R.drawable.ic_sysbar_search_side, SEARCH_STRING); + public static final ButtonInfo RECENT = new ButtonInfo( + R.string.navbar_recent_button, + R.string.accessibility_recent, 0, R.drawable.ic_sysbar_recent, + R.drawable.ic_sysbar_recent_land, R.drawable.ic_sysbar_recent_side, RECENT_STRING); + public static final ButtonInfo EMPTY = new ButtonInfo( + R.string.navbar_empty_button, + R.string.accessibility_clear_all, 0, R.drawable.ic_sysbar_add, + R.drawable.ic_sysbar_add_land, R.drawable.ic_sysbar_add_side, EMPTY_STRING); + + + /** + * Map which holds references to supported/available buttons. This is a unmodifiable map. + */ + public static final Map<String, ButtonInfo> BUTTON_MAP; + + static { + Map<String, ButtonInfo> temp = new LinkedHashMap<String,ButtonInfo>(); + temp.put(HOME_STRING, HOME); + temp.put(CONDITIONAL_MENU_STRING, CONDITIONAL_MENU); + temp.put(ALWAYS_MENU_STRING, ALWAYS_MENU); + temp.put(MENU_BIG_STRING, MENU_BIG); + temp.put(BACK_STRING, BACK); + temp.put(SEARCH_STRING, SEARCH); + temp.put(RECENT_STRING, RECENT); + temp.put(EMPTY_STRING, EMPTY); + BUTTON_MAP = Collections.unmodifiableMap(temp); + } + + /** + * Retrieves the button configuration from the settings. + * @return the current button map, or the default button map. + */ + public static ButtonInfo[] loadButtonMap(Context context) { + String saved = Settings.System.getString(context.getContentResolver(), + Settings.System.NAV_BUTTONS); + if (saved == null) { + saved = NavigationButtons.DEFAULT_SETTING_STRING; + } + String[] buttons = saved.split("\\|"); + if (buttons.length < SLOT_COUNT) { + buttons = NavigationButtons.DEFAULT_SETTING_STRING.split("\\|"); + } + + ButtonInfo[] result = new ButtonInfo[6]; + for (int i = 0; i < result.length; i++) { + result[i] = BUTTON_MAP.get(buttons[i]); + if (result[i] == null) { + result[i] = EMPTY; + } + } + return result; + } + + public static void storeButtonMap(Context context, ButtonInfo[] map) { + if (map.length != SLOT_COUNT) { + throw new IllegalArgumentException("Navigation button count does not match! Is: " + + map.length + " expected: " + SLOT_COUNT); + } + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < SLOT_COUNT; i++) { + if (i != 0) sb.append("|"); + sb.append(map[i].key); + } + Settings.System.putString(context.getContentResolver(), + Settings.System.NAV_BUTTONS, sb.toString()); + } +} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavbarEditor.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavbarEditor.java index c4a7fde..4f4d407 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavbarEditor.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavbarEditor.java @@ -3,7 +3,7 @@ package com.android.systemui.statusbar.phone; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.LinkedHashMap; +import java.util.List; import android.app.AlertDialog; import android.content.Context; @@ -30,6 +30,8 @@ import android.widget.TextView; import com.android.internal.util.ArrayUtils; import com.android.systemui.R; +import com.android.systemui.statusbar.NavigationButtons; +import com.android.systemui.statusbar.NavigationButtons.ButtonInfo; import com.android.systemui.statusbar.policy.KeyButtonView; /** @@ -40,23 +42,19 @@ import com.android.systemui.statusbar.policy.KeyButtonView; public class NavbarEditor implements OnTouchListener { /** - * Holds reference to all assignable button ids + * Holds reference to all assignable button ids. + * Hold this in sync with {@link NavigationButtons#BUTTON_COUNT} */ ArrayList<Integer> mIds = new ArrayList<Integer>(Arrays.asList(R.id.one, R.id.two, R.id.three, R.id.four, R.id.five,R.id.six)); /** * Subset of mIds, to differentiate small/side buttons - * since they can be assigned additional functionality + * since they can be assigned additional functionality. + * Hold this in sync with {@link NavigationButtons#BUTTON_IS_SMALL} */ public static final int[] smallButtonIds = {R.id.one, R.id.six}; - /** - * Map which holds references to supported/available buttons. - */ - public static final LinkedHashMap<String, ButtonInfo> buttonMap = - new LinkedHashMap<String,ButtonInfo>(); - protected static int visibleCount = 4; private static Boolean mIsDevicePhone = null; @@ -78,43 +76,6 @@ public class NavbarEditor implements OnTouchListener { private Context mContext; - //Available buttons - public static final String NAVBAR_EMPTY = "empty"; - public static final String NAVBAR_HOME = "home"; - public static final String NAVBAR_BACK = "back"; - public static final String NAVBAR_SEARCH = "search"; - public static final String NAVBAR_RECENT = "recent"; - public static final String NAVBAR_CONDITIONAL_MENU = "menu0"; - public static final String NAVBAR_ALWAYS_MENU = "menu1"; - public static final String NAVBAR_MENU_BIG = "menu2"; - - static { - buttonMap.put(NAVBAR_HOME, - new ButtonInfo(R.string.navbar_home_button, R.string.accessibility_home, KeyEvent.KEYCODE_HOME, R.drawable.ic_sysbar_home, - R.drawable.ic_sysbar_home_land, R.drawable.ic_sysbar_home)); - buttonMap.put(NAVBAR_CONDITIONAL_MENU, - new ButtonInfo(R.string.navbar_menu_conditional_button, R.string.accessibility_menu, KeyEvent.KEYCODE_MENU, R.drawable.ic_sysbar_menu, - R.drawable.ic_sysbar_menu_land, R.drawable.ic_sysbar_menu)); - buttonMap.put(NAVBAR_ALWAYS_MENU, - new ButtonInfo(R.string.navbar_menu_always_button, R.string.accessibility_menu, KeyEvent.KEYCODE_MENU, R.drawable.ic_sysbar_menu, - R.drawable.ic_sysbar_menu_land, R.drawable.ic_sysbar_menu)); - buttonMap.put(NAVBAR_MENU_BIG, - new ButtonInfo(R.string.navbar_menu_big_button, R.string.accessibility_menu, KeyEvent.KEYCODE_MENU, R.drawable.ic_sysbar_menu_big, - R.drawable.ic_sysbar_menu_big_land, 0)); - buttonMap.put(NAVBAR_BACK, - new ButtonInfo(R.string.navbar_back_button, R.string.accessibility_back,KeyEvent.KEYCODE_BACK, R.drawable.ic_sysbar_back, - R.drawable.ic_sysbar_back_land, R.drawable.ic_sysbar_back_side)); - buttonMap.put(NAVBAR_SEARCH, - new ButtonInfo(R.string.navbar_search_button, R.string.accessibility_back, KeyEvent.KEYCODE_SEARCH, R.drawable.ic_sysbar_search, - R.drawable.ic_sysbar_search_land, R.drawable.ic_sysbar_search_side)); - buttonMap.put(NAVBAR_RECENT, - new ButtonInfo(R.string.navbar_recent_button, R.string.accessibility_recent,0, R.drawable.ic_sysbar_recent, - R.drawable.ic_sysbar_recent_land, R.drawable.ic_sysbar_recent_side)); - buttonMap.put(NAVBAR_EMPTY, - new ButtonInfo(R.string.navbar_empty_button, R.string.accessibility_clear_all,0, R.drawable.ic_sysbar_add, - R.drawable.ic_sysbar_add_land, R.drawable.ic_sysbar_add_side)); - } - public NavbarEditor (ViewGroup parent, Boolean orientation) { mParent = parent; mVertical = orientation; @@ -245,7 +206,7 @@ public class NavbarEditor implements OnTouchListener { builder.setAdapter(list, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - ((KeyButtonView) view).setInfo(list.getItem(which).toString(), mVertical); + ((KeyButtonView) view).setInfo((ButtonInfo) list.getItem(which), mVertical); } }) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @@ -301,16 +262,13 @@ public class NavbarEditor implements OnTouchListener { @SuppressWarnings("unchecked") protected void saveKeys() { ((ViewGroup) mParent.findViewById(R.id.mid_nav_buttons)).setLayoutTransition(null); - StringBuilder saveValue = new StringBuilder(); - String delim = ""; - ArrayList<Integer> idMap = (ArrayList<Integer>) mIds.clone(); + ButtonInfo[] buttons = new ButtonInfo[NavigationButtons.SLOT_COUNT]; + List<Integer> idMap = (List<Integer>) mIds.clone(); if (mVertical) Collections.reverse(idMap); - for (int id : idMap) { - saveValue.append(delim); - delim="|"; - saveValue.append(mParent.findViewById(id).getTag()); + for (int i = 0; i < NavigationButtons.SLOT_COUNT; i++) { + buttons[i] = (ButtonInfo) mParent.findViewById(idMap.get(i)).getTag(); } - Settings.System.putString(mContext.getContentResolver(), Settings.System.NAV_BUTTONS, saveValue.toString()); + NavigationButtons.storeButtonMap(mContext, buttons); } /** @@ -332,19 +290,16 @@ public class NavbarEditor implements OnTouchListener { */ @SuppressWarnings("unchecked") protected void updateKeys() { - String saved = Settings.System.getString(mContext.getContentResolver(), Settings.System.NAV_BUTTONS); - if (saved == null) { - saved = "empty|back|home|recent|empty|menu0"; - } + ButtonInfo[] buttons = NavigationButtons.loadButtonMap(mContext); int cc = 0; ArrayList<Integer> idMap = (ArrayList<Integer>) mIds.clone(); if (mVertical) Collections.reverse(idMap); visibleCount = 0; - for (String buttons : saved.split("\\|")) { + for (ButtonInfo bi : buttons) { KeyButtonView curView = (KeyButtonView) mParent.findViewById(idMap.get(cc)); - boolean isSmallButton = ArrayUtils.contains(NavbarEditor.smallButtonIds, curView.getId()); - curView.setInfo(buttons, mVertical); - if (!curView.getTag().equals(NAVBAR_EMPTY) && !isSmallButton) { + boolean isSmallButton = NavigationButtons.IS_SLOT_SMALL[cc]; + curView.setInfo(bi, mVertical); + if (!curView.getTag().equals(NavigationButtons.EMPTY) && !isSmallButton) { visibleCount++; } cc++; @@ -367,13 +322,14 @@ public class NavbarEditor implements OnTouchListener { View nextPadding = viewParent.getChildAt(v+1); if (nextPadding != null) { View nextKey = viewParent.getChildAt(v+2); - String nextTag = NAVBAR_EMPTY; + ButtonInfo nextBi = NavigationButtons.EMPTY; if (nextKey != null) { - nextTag = (String) nextKey.getTag(); + nextBi = (ButtonInfo) nextKey.getTag(); } - String curTag = (String) cView.getTag(); - if (nextKey != null && nextTag != null && curTag != null && !curTag.equals(NAVBAR_EMPTY)) { - if (!nextTag.equals(NAVBAR_EMPTY)){ + ButtonInfo curBi = (ButtonInfo) cView.getTag(); + if (nextKey != null && nextBi != null + && curBi != null && curBi != NavigationButtons.EMPTY) { + if (nextBi != NavigationButtons.EMPTY){ nextPadding.setVisibility(View.VISIBLE); } else { if (sCount > 1) { @@ -416,63 +372,34 @@ public class NavbarEditor implements OnTouchListener { } } - /** - * Class to store info about supported buttons - */ - public static final class ButtonInfo { - public int displayId; - public int contentDescription; - public int keyCode; - public int portResource; - public int landResource; - public int sideResource; - /** - * Constructor for new button type - * @param rId - resource id of text shown to user in choose dialog - * @param cD - accessibility information regarding button - * @param mC - keyCode to execute on button press - * @param pR - portrait resource used to display button - * @param lR - landscape resource used to display button - * @param sR - smaller scaled resource for side buttons - */ - ButtonInfo (int rId, int cD, int mC, int pR, int lR, int sR) { - displayId = rId; - contentDescription = cD; - keyCode = mC; - portResource = pR; - landResource = lR; - sideResource = sR; - } - } - private class ButtonAdapter implements ListAdapter { /** * Already assigned items */ - ArrayList<String> takenItems; - ArrayList<String> items; + ArrayList<ButtonInfo> takenItems; + ArrayList<ButtonInfo> items; LayoutInflater inflater; ButtonAdapter (boolean smallButtons) { inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - takenItems = new ArrayList<String>(); + takenItems = new ArrayList<ButtonInfo>(); for (int id : mIds) { - String vTag = (String) mParent.findViewById(id).getTag(); - if (vTag == null || vTag.equals(NAVBAR_EMPTY)) { + ButtonInfo vTag = (ButtonInfo) mParent.findViewById(id).getTag(); + if (vTag == null || vTag == NavigationButtons.EMPTY) { continue; } takenItems.add(vTag); } - items = new ArrayList<String>(buttonMap.keySet()); + items = new ArrayList<ButtonInfo>(NavigationButtons.BUTTON_MAP.values()); // home button is not assignable - items.remove(NAVBAR_HOME); + items.remove(NavigationButtons.HOME); // menu buttons can only be assigned to side buttons if (!smallButtons) { - items.remove(NAVBAR_CONDITIONAL_MENU); - items.remove(NAVBAR_ALWAYS_MENU); + items.remove(NavigationButtons.CONDITIONAL_MENU); + items.remove(NavigationButtons.ALWAYS_MENU); } else { - items.remove(NAVBAR_MENU_BIG); + items.remove(NavigationButtons.MENU_BIG); } } @@ -507,7 +434,7 @@ public class NavbarEditor implements OnTouchListener { } else { text.setBackground(null); } - text.setText(mParent.getResources().getString(buttonMap.get(items.get(arg0)).displayId)); + text.setText(mParent.getResources().getString(items.get(arg0).displayId)); return convertView; } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java index 9d5ca96..047ee58 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java @@ -51,6 +51,8 @@ import com.android.internal.statusbar.IStatusBarService; import com.android.systemui.R; import com.android.systemui.statusbar.BaseStatusBar; import com.android.systemui.statusbar.DelegateViewHelper; +import com.android.systemui.statusbar.NavigationButtons; +import com.android.systemui.statusbar.NavigationButtons.ButtonInfo; import com.android.systemui.statusbar.policy.DeadZone; public class NavigationBarView extends LinearLayout implements BaseStatusBar.NavigationBarCallback { @@ -155,19 +157,19 @@ public class NavigationBarView extends LinearLayout implements BaseStatusBar.Nav } protected void toggleButtonListener(boolean enable) { - View recentView = mCurrentView.findViewWithTag(NavbarEditor.NAVBAR_RECENT); + View recentView = mCurrentView.findViewWithTag(NavigationButtons.RECENT); if (recentView != null) { recentView.setOnClickListener(enable ? mRecentsClickListener : null); recentView.setOnTouchListener(enable ? mRecentsPreloadListener : null); } - View homeView = mCurrentView.findViewWithTag(NavbarEditor.NAVBAR_HOME); + View homeView = mCurrentView.findViewWithTag(NavigationButtons.HOME); if (homeView != null) { homeView.setOnTouchListener(enable ? mHomeSearchActionListener : null); } } - private void setButtonWithTagVisibility(String string, int visibility) { - View findView = mCurrentView.findViewWithTag(string); + private void setButtonWithTagVisibility(ButtonInfo type, int visibility) { + View findView = mCurrentView.findViewWithTag(type); if (findView != null) { findView.setVisibility(visibility); } @@ -276,17 +278,17 @@ public class NavigationBarView extends LinearLayout implements BaseStatusBar.Nav mNavigationIconHints = hints; - View button = mCurrentView.findViewWithTag(NavbarEditor.NAVBAR_HOME); + View button = mCurrentView.findViewWithTag(NavigationButtons.HOME); if (button != null) { button.setAlpha( (0 != (hints & StatusBarManager.NAVIGATION_HINT_HOME_NOP)) ? 0.5f : 1.0f); } - button = mCurrentView.findViewWithTag(NavbarEditor.NAVBAR_RECENT); + button = mCurrentView.findViewWithTag(NavigationButtons.RECENT); if (button != null) { button.setAlpha( (0 != (hints & StatusBarManager.NAVIGATION_HINT_RECENT_NOP)) ? 0.5f : 1.0f); } - button = mCurrentView.findViewWithTag(NavbarEditor.NAVBAR_BACK); + button = mCurrentView.findViewWithTag(NavigationButtons.BACK); if (button != null) { button.setAlpha( (0 != (hints & StatusBarManager.NAVIGATION_HINT_BACK_NOP)) ? 0.5f : 1.0f); @@ -328,13 +330,13 @@ public class NavigationBarView extends LinearLayout implements BaseStatusBar.Nav } } - setButtonWithTagVisibility(NavbarEditor.NAVBAR_BACK, disableBack ? View.INVISIBLE : View.VISIBLE); - setButtonWithTagVisibility(NavbarEditor.NAVBAR_HOME, disableHome ? View.INVISIBLE : View.VISIBLE); - setButtonWithTagVisibility(NavbarEditor.NAVBAR_RECENT, disableRecent ? View.INVISIBLE : View.VISIBLE); - setButtonWithTagVisibility(NavbarEditor.NAVBAR_RECENT, disableRecent ? View.INVISIBLE : View.VISIBLE); - setButtonWithTagVisibility(NavbarEditor.NAVBAR_ALWAYS_MENU, disableRecent ? View.INVISIBLE : View.VISIBLE); - setButtonWithTagVisibility(NavbarEditor.NAVBAR_MENU_BIG, disableRecent ? View.INVISIBLE : View.VISIBLE); - setButtonWithTagVisibility(NavbarEditor.NAVBAR_SEARCH, disableRecent ? View.INVISIBLE : View.VISIBLE); + setButtonWithTagVisibility(NavigationButtons.BACK, disableBack ? View.INVISIBLE : View.VISIBLE); + setButtonWithTagVisibility(NavigationButtons.HOME, disableHome ? View.INVISIBLE : View.VISIBLE); + setButtonWithTagVisibility(NavigationButtons.RECENT, disableRecent ? View.INVISIBLE : View.VISIBLE); + setButtonWithTagVisibility(NavigationButtons.RECENT, disableRecent ? View.INVISIBLE : View.VISIBLE); + setButtonWithTagVisibility(NavigationButtons.ALWAYS_MENU, disableRecent ? View.INVISIBLE : View.VISIBLE); + setButtonWithTagVisibility(NavigationButtons.MENU_BIG, disableRecent ? View.INVISIBLE : View.VISIBLE); + setButtonWithTagVisibility(NavigationButtons.SEARCH, disableRecent ? View.INVISIBLE : View.VISIBLE); getSearchLight().setVisibility((disableHome && !disableSearch) ? View.VISIBLE : View.GONE); } @@ -364,7 +366,7 @@ public class NavigationBarView extends LinearLayout implements BaseStatusBar.Nav mShowMenu = show; - setButtonWithTagVisibility(NavbarEditor.NAVBAR_CONDITIONAL_MENU, mShowMenu ? View.VISIBLE : View.INVISIBLE); + setButtonWithTagVisibility(NavigationButtons.CONDITIONAL_MENU, mShowMenu ? View.VISIBLE : View.INVISIBLE); } public void setLowProfile(final boolean lightsOut) { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pie/PieLayout.java b/packages/SystemUI/src/com/android/systemui/statusbar/pie/PieLayout.java index 9161b9f..a9f02df 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/pie/PieLayout.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/pie/PieLayout.java @@ -256,7 +256,7 @@ public class PieLayout extends FrameLayout implements View.OnTouchListener { resolver.registerContentObserver(Settings.System.getUriFor( Settings.System.PIE_SIZE), false, this); resolver.registerContentObserver(Settings.System.getUriFor( - Settings.System.PIE_GRAVITY), false, this); + Settings.System.PIE_POSITIONS), false, this); } @Override @@ -279,7 +279,7 @@ public class PieLayout extends FrameLayout implements View.OnTouchListener { getColors(); mTriggerSlots = Settings.System.getInt(mContext.getContentResolver(), - Settings.System.PIE_GRAVITY, Position.BOTTOM.FLAG); + Settings.System.PIE_POSITIONS, Position.BOTTOM.FLAG); } public void setOnSnapListener(OnSnapListener onSnapListener) { @@ -317,7 +317,7 @@ public class PieLayout extends FrameLayout implements View.OnTouchListener { private void setupSnapPoints(int width, int height, boolean force) { if (force) { mTriggerSlots = Settings.System.getInt(mContext.getContentResolver(), - Settings.System.PIE_GRAVITY, Position.BOTTOM.FLAG); + Settings.System.PIE_POSITIONS, Position.BOTTOM.FLAG); } mActiveSnap = null; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyButtonView.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyButtonView.java index a9a1560..0bad729 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyButtonView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyButtonView.java @@ -40,8 +40,8 @@ import android.widget.ImageView; import com.android.internal.util.ArrayUtils; import com.android.systemui.R; +import com.android.systemui.statusbar.NavigationButtons; import com.android.systemui.statusbar.phone.NavbarEditor; -import com.android.systemui.statusbar.phone.NavbarEditor.ButtonInfo; import com.android.systemui.statusbar.phone.NavigationBarView; public class KeyButtonView extends ImageView { @@ -209,34 +209,33 @@ public class KeyButtonView extends ImageView { super.setPressed(pressed); } - public void setInfo (String itemKey, boolean isVertical) { - ButtonInfo item = NavbarEditor.buttonMap.get(itemKey); - setTag(itemKey); + public void setInfo(NavigationButtons.ButtonInfo buttonInfo, boolean isVertical) { + setTag(buttonInfo); final Resources res = getResources(); - setContentDescription(res.getString(item.contentDescription)); - mCode = item.keyCode; + setContentDescription(res.getString(buttonInfo.contentDescription)); + mCode = buttonInfo.keyCode; boolean isSmallButton = ArrayUtils.contains(NavbarEditor.smallButtonIds, getId()); Drawable keyD; if (isSmallButton) { - keyD = res.getDrawable(item.sideResource); + keyD = res.getDrawable(buttonInfo.sideResource); } else if (!isVertical) { - keyD = res.getDrawable(item.portResource); + keyD = res.getDrawable(buttonInfo.portResource); } else { - keyD = res.getDrawable(item.landResource); + keyD = res.getDrawable(buttonInfo.landResource); } //Reason for setImageDrawable vs setImageResource is because setImageResource calls relayout() w/o //any checks. setImageDrawable performs size checks and only calls relayout if necessary. We rely on this //because otherwise the setX/setY attributes which are post layout cause it to mess up the layout. setImageDrawable(keyD); - if (itemKey.equals(NavbarEditor.NAVBAR_EMPTY)) { + if (buttonInfo == NavigationButtons.EMPTY) { if (isSmallButton) { setVisibility(NavigationBarView.getEditMode() ? View.VISIBLE : View.INVISIBLE); } else { setVisibility(NavigationBarView.getEditMode() ? View.VISIBLE : View.GONE); } - } else if (itemKey.equals(NavbarEditor.NAVBAR_CONDITIONAL_MENU)) { + } else if (buttonInfo == NavigationButtons.CONDITIONAL_MENU) { setVisibility(NavigationBarView.getEditMode() ? View.VISIBLE : View.INVISIBLE); - } else if (itemKey.equals(NavbarEditor.NAVBAR_HOME)) { + } else if (buttonInfo == NavigationButtons.HOME) { mSupportsLongpress = false; } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/PieController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/PieController.java index 047206f..45c8a13 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/PieController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/PieController.java @@ -46,14 +46,20 @@ import android.telephony.TelephonyManager; import android.util.Slog; import android.view.HapticFeedbackConstants; import android.view.IWindowManager; +import android.view.InputDevice; +import android.view.KeyCharacterMap; import android.view.KeyEvent; import android.view.MotionEvent; +import android.view.SoundEffectConstants; import android.view.View; import android.view.ViewGroup.LayoutParams; +import android.view.accessibility.AccessibilityEvent; import android.widget.ImageView; import com.android.systemui.R; import com.android.systemui.statusbar.BaseStatusBar; +import com.android.systemui.statusbar.NavigationButtons; +import com.android.systemui.statusbar.NavigationButtons.ButtonInfo; import com.android.systemui.statusbar.pie.PieItem; import com.android.systemui.statusbar.pie.PieLayout; import com.android.systemui.statusbar.pie.PieLayout.PieDrawable; @@ -72,19 +78,14 @@ public class PieController implements BaseStatusBar.NavigationBarCallback, public static final String TAG = "PieController"; public static final boolean DEBUG = false; - private enum ButtonType { - BACK, - HOME, - RECENT, - MENU, - SEARCH, - SEARCHLIGHT - }; + private static final ButtonInfo SEARCHLIGHT = new ButtonInfo(0, 0, 0, + R.drawable.search_light, R.drawable.search_light, 0); public static final float EMPTY_ANGLE = 10; public static final float START_ANGLE = 180 + EMPTY_ANGLE; - private static final int MSG_INJECT_KEY = 1066; + private static final int MSG_INJECT_KEY_DOWN = 1066; + private static final int MSG_INJECT_KEY_UP = 1067; private Context mContext; private PieLayout mPieContainer; @@ -213,27 +214,37 @@ public class PieController implements BaseStatusBar.NavigationBarCallback, private class H extends Handler { public void handleMessage(Message m) { + final InputManager inputManager = InputManager.getInstance(); switch (m.what) { - case MSG_INJECT_KEY: - final long eventTime = SystemClock.uptimeMillis(); - final InputManager inputManager = InputManager.getInstance(); - - inputManager.injectInputEvent(new KeyEvent(eventTime - 50, eventTime - 50, - KeyEvent.ACTION_DOWN, m.arg1, 0), + case MSG_INJECT_KEY_DOWN: + inputManager.injectInputEvent((KeyEvent) m.obj, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC); - inputManager.injectInputEvent(new KeyEvent(eventTime - 50, eventTime - 25, - KeyEvent.ACTION_UP, m.arg1, 0), + mPieContainer.playSoundEffect(SoundEffectConstants.CLICK); + break; + case MSG_INJECT_KEY_UP: + inputManager.injectInputEvent((KeyEvent) m.obj, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC); - break; } } } private H mHandler = new H(); - private void injectKeyDelayed(int keycode) { - mHandler.removeMessages(MSG_INJECT_KEY); - mHandler.sendMessageDelayed(Message.obtain(mHandler, MSG_INJECT_KEY, keycode, 0), 50); + private void injectKeyDelayed(int keyCode, long when) { + mHandler.removeMessages(MSG_INJECT_KEY_DOWN); + mHandler.removeMessages(MSG_INJECT_KEY_UP); + + KeyEvent down = new KeyEvent(when, when + 10, KeyEvent.ACTION_DOWN, keyCode, 0, 0, + KeyCharacterMap.VIRTUAL_KEYBOARD, 0, + KeyEvent.FLAG_FROM_SYSTEM | KeyEvent.FLAG_VIRTUAL_HARD_KEY, + InputDevice.SOURCE_KEYBOARD); + KeyEvent up = new KeyEvent(when, when + 30, KeyEvent.ACTION_UP, keyCode, 0, 0, + KeyCharacterMap.VIRTUAL_KEYBOARD, 0, + KeyEvent.FLAG_FROM_SYSTEM | KeyEvent.FLAG_VIRTUAL_HARD_KEY, + InputDevice.SOURCE_KEYBOARD); + + mHandler.sendMessageDelayed(Message.obtain(mHandler, MSG_INJECT_KEY_DOWN, down), 10); + mHandler.sendMessageDelayed(Message.obtain(mHandler, MSG_INJECT_KEY_UP, up), 30); } private final class SettingsObserver extends ContentObserver { @@ -244,7 +255,7 @@ public class PieController implements BaseStatusBar.NavigationBarCallback, void observe() { ContentResolver resolver = mContext.getContentResolver(); resolver.registerContentObserver(Settings.System.getUriFor( - Settings.System.PIE_SEARCH), false, this); + Settings.System.NAV_BUTTONS), false, this); } @Override @@ -346,35 +357,35 @@ public class PieController implements BaseStatusBar.NavigationBarCallback, private void setupNavigationItems() { int minimumImageSize = (int)mContext.getResources().getDimension(R.dimen.pie_item_size); + ButtonInfo[] buttons = NavigationButtons.loadButtonMap(mContext); mNavigationSlice.clear(); - mNavigationSlice.addItem(constructItem(2, ButtonType.BACK, - R.drawable.ic_sysbar_back, minimumImageSize)); - mNavigationSlice.addItem(constructItem(2, ButtonType.HOME, - R.drawable.ic_sysbar_home, minimumImageSize)); - mNavigationSlice.addItem(constructItem(2, ButtonType.RECENT, - R.drawable.ic_sysbar_recent, minimumImageSize)); - if (Settings.System.getInt(mContext.getContentResolver(), - Settings.System.PIE_SEARCH, 0) == 1) { - mNavigationSlice.addItem(constructItem(1, ButtonType.SEARCH, - R.drawable.ic_sysbar_search_side, minimumImageSize)); - } - - // search light has a width of 6 to take the complete space that normally - // BACK HOME RECENT would occupy - mSearchLight = constructItem(6, ButtonType.SEARCHLIGHT, - R.drawable.search_light, minimumImageSize); - mNavigationSlice.addItem(mSearchLight); - - mMenuButton = constructItem(1, ButtonType.MENU, - R.drawable.ic_sysbar_menu, minimumImageSize); - mNavigationSlice.addItem(mMenuButton); + + for (int i = 0; i < buttons.length; i++) { + if (buttons[i] != NavigationButtons.EMPTY) { + ButtonInfo bi = buttons[i]; + + // search light is at the same position as the home button + if (bi == NavigationButtons.HOME) { + // search light has a width of 6 to take the complete space that normally + // BACK HOME RECENT would occupy + mSearchLight = constructItem(6, SEARCHLIGHT, + SEARCHLIGHT.portResource, minimumImageSize); + mNavigationSlice.addItem(mSearchLight); + } + + boolean isSmall = NavigationButtons.IS_SLOT_SMALL[i]; + mNavigationSlice.addItem(constructItem(isSmall ? 1 : 2, bi, + isSmall ? bi.sideResource : bi.portResource, minimumImageSize)); + } + } + mMenuButton = findItem(NavigationButtons.CONDITIONAL_MENU); setNavigationIconHints(mNavigationIconHints, true); setMenuVisibility(mShowMenu); } - private PieItem constructItem(int width, ButtonType type, int image, int minimumImageSize) { + private PieItem constructItem(int width, ButtonInfo type, int image, int minimumImageSize) { ImageView view = new ImageView(mContext); view.setImageResource(image); view.setMinimumWidth(minimumImageSize); @@ -386,6 +397,23 @@ public class PieController implements BaseStatusBar.NavigationBarCallback, return item; } + private PieItem findItem(ButtonInfo type) { + for (PieItem item : mNavigationSlice.getItems()) { + if (type == item.tag) { + return item; + } + } + + return null; + } + + private void setItemWithTagVisibility(ButtonInfo type, boolean show) { + PieItem item = findItem(type); + if (item != null) { + item.show(show); + } + } + public void activateFromTrigger(View view, MotionEvent event, Position position) { if (mPieContainer != null && !isShowing()) { doHapticTriggerFeedback(); @@ -415,17 +443,17 @@ public class PieController implements BaseStatusBar.NavigationBarCallback, mNavigationIconHints = hints; - PieItem item = findItem(ButtonType.HOME); + PieItem item = findItem(NavigationButtons.HOME); if (item != null) { boolean isNop = (hints & StatusBarManager.NAVIGATION_HINT_HOME_NOP) != 0; item.setAlpha(isNop ? 0.5f : 1.0f); } - item = findItem(ButtonType.RECENT); + item = findItem(NavigationButtons.RECENT); if (item != null) { boolean isNop = (hints & StatusBarManager.NAVIGATION_HINT_RECENT_NOP) != 0; item.setAlpha(isNop ? 0.5f : 1.0f); } - item = findItem(ButtonType.BACK); + item = findItem(NavigationButtons.BACK); if (item != null) { boolean isNop = (hints & StatusBarManager.NAVIGATION_HINT_BACK_NOP) != 0; boolean isAlt = (hints & StatusBarManager.NAVIGATION_HINT_BACK_ALT) != 0; @@ -435,17 +463,6 @@ public class PieController implements BaseStatusBar.NavigationBarCallback, setDisabledFlags(mDisabledFlags, true); } - private PieItem findItem(ButtonType type) { - for (PieItem item : mNavigationSlice.getItems()) { - ButtonType itemType = (ButtonType) item.tag; - if (type == itemType) { - return item; - } - } - - return null; - } - @Override public void setDisabledFlags(int disabledFlags) { // this call may come from outside @@ -468,23 +485,13 @@ public class PieController implements BaseStatusBar.NavigationBarCallback, && ((mNavigationIconHints & StatusBarManager.NAVIGATION_HINT_BACK_ALT) == 0); final boolean disableSearch = ((disabledFlags & View.STATUS_BAR_DISABLE_SEARCH) != 0); - PieItem item = findItem(ButtonType.BACK); - if (item != null) { - item.show(!disableBack); - } - item = findItem(ButtonType.HOME); - if (item != null) { - item.show(!disableHome); - } - item = findItem(ButtonType.RECENT); - if (item != null) { - item.show(!disableRecent); - } - item = findItem(ButtonType.SEARCH); - if (item != null) { - item.show(!disableRecent && !disableSearch); - } - // enable searchlight when nothing except search is enabled + setItemWithTagVisibility(NavigationButtons.BACK, !disableBack); + setItemWithTagVisibility(NavigationButtons.HOME, !disableHome); + setItemWithTagVisibility(NavigationButtons.RECENT, !disableRecent); + setItemWithTagVisibility(NavigationButtons.ALWAYS_MENU, !disableRecent); + setItemWithTagVisibility(NavigationButtons.MENU_BIG, !disableRecent); + setItemWithTagVisibility(NavigationButtons.SEARCH, !disableRecent); + // enable search light when nothing except search is enabled if (mSearchLight != null) { mSearchLight.show(disableHome && disableRecent && disableBack && !disableSearch); } @@ -495,8 +502,7 @@ public class PieController implements BaseStatusBar.NavigationBarCallback, public void setMenuVisibility(boolean showMenu) { // this call may come from outside if (mMenuButton != null) { - final boolean disableRecent = ((mDisabledFlags & View.STATUS_BAR_DISABLE_RECENT) != 0); - mMenuButton.show(showMenu && !disableRecent); + mMenuButton.show(showMenu); } mShowMenu = showMenu; @@ -515,40 +521,32 @@ public class PieController implements BaseStatusBar.NavigationBarCallback, } int triggerSlots = Settings.System.getInt(mContext.getContentResolver(), - Settings.System.PIE_GRAVITY, Position.BOTTOM.FLAG); + Settings.System.PIE_POSITIONS, Position.BOTTOM.FLAG); triggerSlots = triggerSlots & ~mPosition.FLAG | position.FLAG; Settings.System.putInt(mContext.getContentResolver(), - Settings.System.PIE_GRAVITY, triggerSlots); + Settings.System.PIE_POSITIONS, triggerSlots); } @Override public void onClick(PieItem item) { - ButtonType type = (ButtonType) item.tag; - - // provide the same haptic feedback as if a virtual key is pressed - mPieContainer.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); - - switch (type) { - case BACK: - injectKeyDelayed(KeyEvent.KEYCODE_BACK); - break; - case HOME: - injectKeyDelayed(KeyEvent.KEYCODE_HOME); - break; - case MENU: - injectKeyDelayed(KeyEvent.KEYCODE_MENU); - break; - case RECENT: + long when = SystemClock.uptimeMillis(); + ButtonInfo bi = (ButtonInfo) item.tag; + + if (bi.keyCode != 0) { + injectKeyDelayed(bi.keyCode, when); + } else { + // provide the same haptic feedback as if a virtual key is pressed + mPieContainer.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); + mPieContainer.playSoundEffect(SoundEffectConstants.CLICK); + if (bi == NavigationButtons.RECENT) { if (mStatusBar != null) { mStatusBar.toggleRecentApps(); } - break; - case SEARCH: - case SEARCHLIGHT: - launchAssistAction(type == ButtonType.SEARCHLIGHT); - break; + } else if (bi == SEARCHLIGHT) { + launchAssistAction(true); + } } } |
