diff options
author | Danny Baumann <dannybaumann@web.de> | 2013-06-22 14:14:58 +0200 |
---|---|---|
committer | Danny Baumann <dannybaumann@web.de> | 2013-06-24 16:49:19 +0200 |
commit | c2d2a6951ca0791515ba4f0f3d9ca94657a3f0be (patch) | |
tree | 90475b7e0102aa1f7bced19bc6b12172d2917bcf /packages/SystemUI/src/com/android/systemui/statusbar/phone/NavbarEditor.java | |
parent | a012186757fb6fe7695e0c21b79fa20cad57b2d2 (diff) | |
download | frameworks_base-c2d2a6951ca0791515ba4f0f3d9ca94657a3f0be.zip frameworks_base-c2d2a6951ca0791515ba4f0f3d9ca94657a3f0be.tar.gz frameworks_base-c2d2a6951ca0791515ba4f0f3d9ca94657a3f0be.tar.bz2 |
Make navigation bar ready for per-user configuration.
Also clean it up a bit.
Change-Id: Ic10bd161fce53bf30048a0cb927dcf1e2bfa7774
Diffstat (limited to 'packages/SystemUI/src/com/android/systemui/statusbar/phone/NavbarEditor.java')
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/phone/NavbarEditor.java | 583 |
1 files changed, 270 insertions, 313 deletions
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 4f4d407..9de38ad 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavbarEditor.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavbarEditor.java @@ -1,31 +1,38 @@ -package com.android.systemui.statusbar.phone; +/* + * Copyright (C) 2012 The CyanogenMod 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. + */ -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; +package com.android.systemui.statusbar.phone; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; -import android.content.res.Configuration; -import android.database.DataSetObserver; -import android.graphics.Color; +import android.graphics.PorterDuff; +import android.graphics.PorterDuffColorFilter; import android.provider.Settings; import android.util.DisplayMetrics; import android.view.DisplayInfo; import android.view.HapticFeedbackConstants; -import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; -import android.view.View.OnTouchListener; import android.view.ViewConfiguration; import android.view.ViewGroup; import android.view.WindowManager; +import android.widget.ArrayAdapter; import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.ListAdapter; import android.widget.TextView; import com.android.internal.util.ArrayUtils; @@ -34,364 +41,363 @@ import com.android.systemui.statusbar.NavigationButtons; import com.android.systemui.statusbar.NavigationButtons.ButtonInfo; import com.android.systemui.statusbar.policy.KeyButtonView; +import java.util.ArrayList; +import java.util.Collections; + /** * Handles the editing of the navigation bar * @author Danesh M * @hide */ -public class NavbarEditor implements OnTouchListener { - +public class NavbarEditor implements View.OnTouchListener { /** * 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)); + private static final int[] BUTTON_IDS = + { 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 + * Subset of BUTON_IDS, to differentiate small/side buttons * 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}; + private static final int[] SMALL_BUTTON_IDS = { R.id.one, R.id.six }; - protected static int visibleCount = 4; - private static Boolean mIsDevicePhone = null; + // holds the button views in the order they currently appear on screen + private final ArrayList<KeyButtonView> mButtonViews; - /** - * Holds reference to the parent/root of the inflated view - */ - private ViewGroup mParent; + private Context mContext; + private static Boolean sIsDevicePhone = null; + private boolean mInEditMode = false; - /** - * Button chooser dialog - */ - AlertDialog mDialog; + // Holds reference to the parent/root of the inflated view + private View mParent; + + // Button chooser dialog + private AlertDialog mDialog; + + // true == we're in landscape mode + private boolean mVertical; + // true == we're currently checking for long press + private boolean mLongPressed; + // start point of the current drag operation + private float mDragOrigin; + + // just to avoid reallocations + private static final int[] sLocation = new int[2]; /** - * mVertical = Whether we're in landscape mode - * mLongPressed = Whether the longpress runnable was activated. + * Longpress runnable to assign buttons in edit mode */ - boolean mVertical,mLongPressed; - - private Context mContext; + private Runnable mCheckLongPress = new Runnable() { + public void run() { + if (mInEditMode) { + mLongPressed = true; + mParent.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); + } + } + }; - public NavbarEditor (ViewGroup parent, Boolean orientation) { + public NavbarEditor (View parent, boolean orientation) { + mContext = parent.getContext(); mParent = parent; mVertical = orientation; - mContext = parent.getContext(); + + mButtonViews = new ArrayList<KeyButtonView>(); + for (int id : BUTTON_IDS) { + mButtonViews.add((KeyButtonView) mParent.findViewById(id)); + } } - /** - * Set the button listeners to this - * class when in edit mode - */ - protected void setupListeners() { - for (int id : mIds) { - mParent.findViewById(id).setOnTouchListener(this); + public void setEditMode(boolean editMode) { + mInEditMode = editMode; + for (Integer id : BUTTON_IDS) { + KeyButtonView button = (KeyButtonView) mParent.findViewById(id); + if (button != null) { + button.setEditMode(editMode); + button.setOnTouchListener(editMode ? this : null); + } + } + if (!editMode && mDialog != null && mDialog.isShowing()) { + mDialog.dismiss(); } } + public static boolean isDevicePhone(Context context) { + if (sIsDevicePhone == null) { + WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); + DisplayInfo outDisplayInfo = new DisplayInfo(); + + wm.getDefaultDisplay().getDisplayInfo(outDisplayInfo); + + int shortSize = Math.min(outDisplayInfo.logicalHeight, outDisplayInfo.logicalWidth); + int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / outDisplayInfo.logicalDensityDpi; + + // 0-599dp: "phone" UI with a separate status & navigation bar + sIsDevicePhone = shortSizeDp < 600; + } + + return sIsDevicePhone; + } + /** - * Find intersecting views in mIds + * Find intersecting view in mButtonViews * @param pos - pointer location * @param v - view being dragged - * @return array index in mIds of view intersecting + * @return intersecting view or null */ - private int findInterceptingViewIndex(float pos, View v) { - int location[] = new int[2]; - for (int cc = 0; cc < mIds.size(); cc++) { - if (!ArrayUtils.contains(smallButtonIds,mIds.get(cc))) { - View tmpV = mParent.findViewById(mIds.get(cc)); - tmpV.getLocationOnScreen(location); - if (tmpV == v) { - continue; - } else if (!mVertical && (pos > (location[0]+v.getWidth()/4) && pos < location[0]+v.getWidth())) { - return cc; - } else if (mVertical && (pos > (location[1]+v.getHeight()/4) && pos < location[1]+v.getHeight())) { - return cc; - } + private View findInterceptingView(float pos, View v) { + for (KeyButtonView otherView : mButtonViews) { + if (otherView == v) { + continue; } - } - return -1; - } - /** - * Longpress runnable to assign buttons in edit mode - */ - Runnable mCheckLongPress = new Runnable() { - public void run() { - if (NavigationBarView.getEditMode()) { - mLongPressed = true; - mParent.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); - return; + if (ArrayUtils.contains(SMALL_BUTTON_IDS, otherView.getId())) { + continue; } - } - }; - protected static boolean isDevicePhone(Context con) { - if (mIsDevicePhone == null) { - WindowManager wm = (WindowManager)con.getSystemService(Context.WINDOW_SERVICE); - DisplayInfo outDisplayInfo = new DisplayInfo(); - wm.getDefaultDisplay().getDisplayInfo(outDisplayInfo); - int shortSize = Math.min(outDisplayInfo.logicalHeight, outDisplayInfo.logicalWidth); - int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / outDisplayInfo.logicalDensityDpi; - if (shortSizeDp < 600) { - // 0-599dp: "phone" UI with a separate status & navigation bar - mIsDevicePhone = true; - } else { - mIsDevicePhone = false; + otherView.getLocationOnScreen(sLocation); + float otherPos = sLocation[mVertical ? 1 : 0]; + float otherDimension = mVertical ? v.getHeight() : v.getWidth(); + + if (pos > (otherPos + otherDimension / 4) && pos < (otherPos + otherDimension)) { + return otherView; } } - return mIsDevicePhone; + return null; } @Override public boolean onTouch(final View view, MotionEvent event) { - if (!NavigationBarView.getEditMode() || (mDialog != null && mDialog.isShowing())) { + if (!mInEditMode || (mDialog != null && mDialog.isShowing())) { return false; } - float curPos = 0; - if (!mVertical) { - curPos = event.getRawX(); - } else { - curPos = event.getRawY(); - } + if (event.getAction() == MotionEvent.ACTION_DOWN) { - int screenLoc[] = new int[2]; view.setPressed(true); - view.getLocationOnScreen(screenLoc); - // Store the starting view position in the parent's tag - if (!mVertical) { - mParent.setTag(Float.valueOf(screenLoc[0])); - } else { - mParent.setTag(Float.valueOf(screenLoc[1])); - } + view.getLocationOnScreen(sLocation); + mDragOrigin = sLocation[mVertical ? 1 : 0]; view.postDelayed(mCheckLongPress, ViewConfiguration.getLongPressTimeout()); } else if (event.getAction() == MotionEvent.ACTION_MOVE) { view.setPressed(false); - if (!mLongPressed || ArrayUtils.contains(smallButtonIds, view.getId())) { + + if (!mLongPressed || ArrayUtils.contains(SMALL_BUTTON_IDS, view.getId())) { return false; } - view.bringToFront(); + ViewGroup viewParent = (ViewGroup) view.getParent(); - float buttonSize = 0; - if (!mVertical) { - buttonSize = view.getWidth(); - } else { - buttonSize = view.getHeight(); - } + float pos = mVertical ? event.getRawY() : event.getRawX(); + float buttonSize = mVertical ? view.getHeight() : view.getWidth(); + float min = mVertical ? viewParent.getTop() : (viewParent.getLeft() - buttonSize / 2); + float max = mVertical ? (viewParent.getTop() + viewParent.getHeight()) + : (viewParent.getLeft() + viewParent.getWidth()); + // Prevents user from dragging view outside of bounds - if ((!mVertical && ((curPos) > (viewParent.getWidth() + viewParent.getLeft()) || (curPos - buttonSize/2 <= viewParent.getLeft()))) || - (mVertical && ((curPos > (viewParent.getHeight() + viewParent.getTop())) || (curPos < viewParent.getTop())))) { + if (pos < min || pos > max) { return false; } if (!mVertical) { - view.setX(curPos - viewParent.getLeft() - buttonSize/2); + view.setX(pos - viewParent.getLeft() - buttonSize / 2); } else { - view.setY(curPos - viewParent.getTop() - buttonSize/2); + view.setY(pos - viewParent.getTop() - buttonSize / 2); } - int affectedViewPosition = findInterceptingViewIndex(curPos, view); - if (affectedViewPosition == -1) { + View affectedView = findInterceptingView(pos, view); + if (affectedView == null) { return false; } - switchId(mIds.indexOf(view.getId()), affectedViewPosition, view); - } else if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) { + switchId(affectedView, view); + } else if (event.getAction() == MotionEvent.ACTION_UP + || event.getAction() == MotionEvent.ACTION_CANCEL) { view.setPressed(false); view.removeCallbacks(mCheckLongPress); - if (!mLongPressed && !view.getTag().equals("home")) { - final ButtonAdapter list = new ButtonAdapter(ArrayUtils.contains(smallButtonIds, view.getId()) ? true : false); - AlertDialog.Builder builder = new AlertDialog.Builder(mContext); - builder.setTitle(mContext.getString(R.string.navbar_dialog_title)); - builder.setAdapter(list, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - ((KeyButtonView) view).setInfo((ButtonInfo) list.getItem(which), mVertical); - } - }) - .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - dialog.cancel(); - } - }); + + if (!mLongPressed && !view.getTag().equals(NavigationButtons.HOME)) { + final boolean isSmallButton = ArrayUtils.contains(SMALL_BUTTON_IDS, view.getId()); + final ButtonAdapter list = new ButtonAdapter(mContext, mButtonViews, isSmallButton); + + AlertDialog.Builder builder = new AlertDialog.Builder(mContext) + .setTitle(mContext.getString(R.string.navbar_dialog_title)) + .setAdapter(list, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + KeyButtonView button = (KeyButtonView) view; + ButtonInfo info = (ButtonInfo) list.getItem(which); + + button.setInfo(info, mVertical, isSmallButton); + } + }) + .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + dialog.cancel(); + } + }); + mDialog = builder.create(); - mDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); + mDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG); mDialog.setCanceledOnTouchOutside(false); mDialog.show(); - mLongPressed=false; - return true; - } - mLongPressed=false; - // Reset the dragged view to its original location - ViewGroup vParent = (ViewGroup) view.getParent(); - if (!mVertical) { - view.setX((Float) mParent.getTag() - vParent.getLeft()); } else { - view.setY((Float) mParent.getTag() - vParent.getTop()); + // Reset the dragged view to its original location + ViewGroup parent = (ViewGroup) view.getParent(); + + if (!mVertical) { + view.setX(mDragOrigin - parent.getLeft()); + } else { + view.setY(mDragOrigin - parent.getTop()); + } } + mLongPressed = false; } return true; } /** * Switches positions of two views and - * updates their mIds entry - * @param to - index for new position in mIds - * @param from - index for old position in mIds + * updates their mButtonViews entry + * @param targetView - view to be replaced * @param view - view being dragged */ - private void switchId(int to, int from, View view) { - View tView = mParent.findViewById(mIds.get(from)); - int screenLoc[] = new int[2]; - tView.getLocationOnScreen(screenLoc); - ViewGroup a = (ViewGroup) view.getParent(); + private void switchId(View targetView, View view) { + ViewGroup parent = (ViewGroup) view.getParent(); + + targetView.getLocationOnScreen(sLocation); if (!mVertical) { - tView.setX((Float) mParent.getTag() - a.getLeft()); - mParent.setTag(Float.valueOf(screenLoc[0])); + targetView.setX(mDragOrigin - parent.getLeft()); + mDragOrigin = sLocation[0]; } else { - tView.setY((Float) mParent.getTag() - a.getTop()); - mParent.setTag(Float.valueOf(screenLoc[1])); + targetView.setY(mDragOrigin - parent.getTop()); + mDragOrigin = sLocation[1]; } - Collections.swap(mIds,to,from); + + int targetIndex = mButtonViews.indexOf(targetView); + int draggedIndex = mButtonViews.indexOf(view); + Collections.swap(mButtonViews, draggedIndex, targetIndex); } /** * Saves the current key arrangement * to the settings provider */ - @SuppressWarnings("unchecked") protected void saveKeys() { - ((ViewGroup) mParent.findViewById(R.id.mid_nav_buttons)).setLayoutTransition(null); ButtonInfo[] buttons = new ButtonInfo[NavigationButtons.SLOT_COUNT]; - List<Integer> idMap = (List<Integer>) mIds.clone(); - if (mVertical) Collections.reverse(idMap); for (int i = 0; i < NavigationButtons.SLOT_COUNT; i++) { - buttons[i] = (ButtonInfo) mParent.findViewById(idMap.get(i)).getTag(); + int idIndex = mVertical ? NavigationButtons.SLOT_COUNT - i : i; + buttons[i] = (ButtonInfo) mButtonViews.get(idIndex).getTag(); } NavigationButtons.storeButtonMap(mContext, buttons); } /** - * Reinflates navigation bar on demand - * base on current orientation - */ - protected void reInflate() { - ((ViewGroup)mParent).removeAllViews(); - if (mVertical) { - View.inflate(mContext, R.layout.mid_navigation_bar_land, (ViewGroup) mParent); - } else { - View.inflate(mContext, R.layout.mid_navigation_bar_port, (ViewGroup) mParent); - } - } - - /** * Updates the buttons according to the * key arrangement stored in settings provider */ - @SuppressWarnings("unchecked") protected void updateKeys() { ButtonInfo[] buttons = NavigationButtons.loadButtonMap(mContext); - int cc = 0; - ArrayList<Integer> idMap = (ArrayList<Integer>) mIds.clone(); - if (mVertical) Collections.reverse(idMap); - visibleCount = 0; - for (ButtonInfo bi : buttons) { - KeyButtonView curView = (KeyButtonView) mParent.findViewById(idMap.get(cc)); - boolean isSmallButton = NavigationButtons.IS_SLOT_SMALL[cc]; - curView.setInfo(bi, mVertical); - if (!curView.getTag().equals(NavigationButtons.EMPTY) && !isSmallButton) { + int visibleCount = 0; + + for (int i = 0; i < buttons.length; i++) { + int id = BUTTON_IDS[i]; + ButtonInfo info = buttons[i]; + KeyButtonView button = (KeyButtonView) mParent.findViewById(id); + boolean isSmallButton = NavigationButtons.IS_SLOT_SMALL[i]; + + button.setInfo(info, mVertical, isSmallButton); + if (!info.equals(NavigationButtons.EMPTY) && !isSmallButton) { visibleCount++; } - cc++; + + button.setTranslationX(0); + mButtonViews.set(i, button); } + if (isDevicePhone(mContext)) { - adjustPadding(); + adjustPadding(visibleCount); } + updateLowLights(visibleCount); } /** * Accommodates the padding between keys based on * number of keys in use. */ - private void adjustPadding() { + private void adjustPadding(int visibleCount) { ViewGroup viewParent = (ViewGroup) mParent.findViewById(R.id.mid_nav_buttons); - int sCount = visibleCount; - for (int v = 0; v < viewParent.getChildCount();v++) { - View cView = viewParent.getChildAt(v); - if (cView instanceof KeyButtonView) { - View nextPadding = viewParent.getChildAt(v+1); - if (nextPadding != null) { - View nextKey = viewParent.getChildAt(v+2); - ButtonInfo nextBi = NavigationButtons.EMPTY; - if (nextKey != null) { - nextBi = (ButtonInfo) nextKey.getTag(); - } - 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) { - nextPadding.setVisibility(View.VISIBLE); - } else { - nextPadding.setVisibility(View.GONE); - } - } - sCount--; - } else { - nextPadding.setVisibility(View.GONE); - } + int totalViews = viewParent.getChildCount(); + + for (int v = 0; v < totalViews; v++) { + View currentKey = viewParent.getChildAt(v); + if (!(currentKey instanceof KeyButtonView)) { + continue; + } + View nextPadding = viewParent.getChildAt(v + 1); + if (nextPadding == null) { + continue; + } + + View nextKey = viewParent.getChildAt(v + 2); + ButtonInfo nextInfo = nextKey == null ? null : (ButtonInfo) nextKey.getTag(); + ButtonInfo currentInfo = (ButtonInfo) currentKey.getTag(); + + if (nextInfo != null && currentInfo != null && currentInfo != NavigationButtons.EMPTY) { + if (nextInfo != NavigationButtons.EMPTY || visibleCount > 1) { + nextPadding.setVisibility(View.VISIBLE); + } else { + nextPadding.setVisibility(View.GONE); } + visibleCount--; + } else { + nextPadding.setVisibility(View.GONE); } } } - protected void updateLowLights(View current) { - ViewGroup lowLights = (ViewGroup) current.findViewById(R.id.lights_out); + protected void updateLowLights(int visibleCount) { + ViewGroup lowLights = (ViewGroup) mParent.findViewById(R.id.lights_out); int totalViews = lowLights.getChildCount(); - int visibleCount = NavbarEditor.visibleCount; - for (int v = 0;v<totalViews;v++) { - if (lowLights.getChildAt(v) instanceof ImageView) { - View blank = lowLights.getChildAt(v+1); - if (visibleCount <= 0) { - lowLights.getChildAt(v).setVisibility(View.GONE); - if (blank != null) { - blank.setVisibility(View.GONE); - } - } else { - lowLights.getChildAt(v).setVisibility(View.VISIBLE); - visibleCount--; - if (visibleCount > 0 && blank != null) { - blank.setVisibility(View.VISIBLE); - } else if (blank != null) { - blank.setVisibility(View.GONE); - } - } + + for (int v = 0;v < totalViews; v++) { + View currentView = lowLights.getChildAt(v); + if (!(currentView instanceof ImageView)) { + continue; + } + + if (visibleCount <= 0) { + currentView.setVisibility(View.GONE); + } else { + currentView.setVisibility(View.VISIBLE); + visibleCount--; + } + + View blank = lowLights.getChildAt(v + 1); + if (blank != null) { + blank.setVisibility(visibleCount > 0 ? View.VISIBLE : View.GONE); } } } - private class ButtonAdapter implements ListAdapter { - - /** - * Already assigned items - */ - ArrayList<ButtonInfo> takenItems; - ArrayList<ButtonInfo> items; - LayoutInflater inflater; - - ButtonAdapter (boolean smallButtons) { - inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - takenItems = new ArrayList<ButtonInfo>(); - for (int id : mIds) { - ButtonInfo vTag = (ButtonInfo) mParent.findViewById(id).getTag(); - if (vTag == null || vTag == NavigationButtons.EMPTY) { - continue; + private static class ButtonAdapter extends ArrayAdapter<ButtonInfo> { + private ArrayList<ButtonInfo> mTakenItems; + + public ButtonAdapter(Context context, + ArrayList<KeyButtonView> buttons, boolean smallButtons) { + super(context, R.layout.navigation_bar_edit_menu_item, R.id.key_text, + buildItems(smallButtons)); + + mTakenItems = new ArrayList<ButtonInfo>(); + for (KeyButtonView button : buttons) { + ButtonInfo info = (ButtonInfo) button.getTag(); + if (info != null && info != NavigationButtons.EMPTY) { + mTakenItems.add(info); } - takenItems.add(vTag); } - items = new ArrayList<ButtonInfo>(NavigationButtons.BUTTON_MAP.values()); + } + + private static ArrayList<ButtonInfo> buildItems(boolean smallButtons) { + ArrayList<ButtonInfo> items = + new ArrayList<ButtonInfo>(NavigationButtons.BUTTON_MAP.values()); + // home button is not assignable items.remove(NavigationButtons.HOME); // menu buttons can only be assigned to side buttons @@ -401,64 +407,26 @@ public class NavbarEditor implements OnTouchListener { } else { items.remove(NavigationButtons.MENU_BIG); } - } - - @Override - public int getCount() { - return items.size(); - } - @Override - public Object getItem(int arg0) { - return items.get(arg0); - } - - @Override - public long getItemId(int arg0) { - return 0; + return items; } @Override - public int getItemViewType(int arg0) { - return 0; - } + public View getView(int position, View convertView, ViewGroup parent) { + View view = super.getView(position, convertView, parent); + ButtonInfo info = getItem(position); + boolean enabled = isEnabled(position); - @Override - public View getView(int arg0, View convertView, ViewGroup parent) { - if(convertView == null) { - convertView = inflater.inflate(android.R.layout.select_dialog_item, parent,false); - } - TextView text = (TextView) convertView.findViewById(android.R.id.text1); - if (takenItems.contains(items.get(arg0))) { - text.setBackgroundColor(Color.parseColor("#181818")); - } else { - text.setBackground(null); - } - text.setText(mParent.getResources().getString(items.get(arg0).displayId)); - return convertView; - } + TextView text = (TextView) view.findViewById(R.id.key_text); + text.setText(getContext().getResources().getString(info.displayId)); + text.setEnabled(enabled); - @Override - public int getViewTypeCount() { - return 1; - } + ImageView icon = (ImageView) view.findViewById(R.id.key_icon); + icon.setImageResource(info.portResource); + icon.setColorFilter(new PorterDuffColorFilter( + text.getCurrentTextColor(), PorterDuff.Mode.SRC_IN)); - @Override - public boolean hasStableIds() { - return false; - } - - @Override - public boolean isEmpty() { - return false; - } - - @Override - public void registerDataSetObserver(DataSetObserver arg0) { - } - - @Override - public void unregisterDataSetObserver(DataSetObserver arg0) { + return view; } @Override @@ -467,19 +435,8 @@ public class NavbarEditor implements OnTouchListener { } @Override - public boolean isEnabled(int arg0) { - if (takenItems.contains(items.get(arg0))) { - return false; - } - return true; + public boolean isEnabled(int position) { + return !mTakenItems.contains(getItem(position)); } - } - - final void dismissDialog() { - if (mDialog != null && mDialog.isShowing()) { - mDialog.dismiss(); - } - } - } |