Loading core/java/android/provider/Settings.java +6 −10 Original line number Diff line number Diff line Loading @@ -2513,20 +2513,16 @@ public final class Settings { public static final String POINTER_SPEED = "pointer_speed"; /** * Whether to enable pie controls on expanded screen? * The value is boolean (1 or 0). * Whether to enable pie controls? * The value is integer: * 2 = always on * 1 = expanded desktop * 0 = off * Default: 0 * @hide */ public static final String PIE_CONTROLS = "pie_controls"; /** * Display search button in pie? * The value is boolean (1 or 0). * @hide */ public static final String PIE_SEARCH = "pie_search"; /** * Locations of the pie in the screen. * (1<<0) = LEFT Loading @@ -2536,7 +2532,7 @@ public final class Settings { * Default: BOTTOM * @hide */ public static final String PIE_GRAVITY = "pie_gravity"; public static final String PIE_POSITIONS = "pie_positions"; /** * Relative pie size (fraction) Loading packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java +2 −2 Original line number Diff line number Diff line Loading @@ -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( Loading @@ -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; Loading packages/SystemUI/src/com/android/systemui/statusbar/NavigationButtons.java 0 → 100644 +204 −0 Original line number Diff line number Diff line /* * 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()); } } packages/SystemUI/src/com/android/systemui/statusbar/phone/NavbarEditor.java +35 −108 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; /** Loading @@ -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; Loading @@ -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; Loading Loading @@ -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() { Loading Loading @@ -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); } /** Loading @@ -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++; Loading @@ -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) { Loading Loading @@ -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); } } Loading Loading @@ -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; } Loading packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java +17 −15 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
core/java/android/provider/Settings.java +6 −10 Original line number Diff line number Diff line Loading @@ -2513,20 +2513,16 @@ public final class Settings { public static final String POINTER_SPEED = "pointer_speed"; /** * Whether to enable pie controls on expanded screen? * The value is boolean (1 or 0). * Whether to enable pie controls? * The value is integer: * 2 = always on * 1 = expanded desktop * 0 = off * Default: 0 * @hide */ public static final String PIE_CONTROLS = "pie_controls"; /** * Display search button in pie? * The value is boolean (1 or 0). * @hide */ public static final String PIE_SEARCH = "pie_search"; /** * Locations of the pie in the screen. * (1<<0) = LEFT Loading @@ -2536,7 +2532,7 @@ public final class Settings { * Default: BOTTOM * @hide */ public static final String PIE_GRAVITY = "pie_gravity"; public static final String PIE_POSITIONS = "pie_positions"; /** * Relative pie size (fraction) Loading
packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java +2 −2 Original line number Diff line number Diff line Loading @@ -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( Loading @@ -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; Loading
packages/SystemUI/src/com/android/systemui/statusbar/NavigationButtons.java 0 → 100644 +204 −0 Original line number Diff line number Diff line /* * 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()); } }
packages/SystemUI/src/com/android/systemui/statusbar/phone/NavbarEditor.java +35 −108 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; /** Loading @@ -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; Loading @@ -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; Loading Loading @@ -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() { Loading Loading @@ -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); } /** Loading @@ -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++; Loading @@ -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) { Loading Loading @@ -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); } } Loading Loading @@ -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; } Loading
packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java +17 −15 File changed.Preview size limit exceeded, changes collapsed. Show changes