Bug 900234 - Replace LinkedHashMap with ArrayList to allow insertions. r=wesj

This commit is contained in:
Shilpan Bhagat 2013-08-12 11:42:16 -07:00
parent c22c26ca12
commit 6d85f60925

View File

@ -31,7 +31,7 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import java.util.UUID;
import java.util.LinkedHashMap;
import java.util.ArrayList;
public class PageActionLayout extends LinearLayout implements GeckoEventListener,
View.OnClickListener,
@ -40,7 +40,7 @@ public class PageActionLayout extends LinearLayout implements GeckoEventListener
private final String MENU_BUTTON_KEY = "MENU_BUTTON_KEY";
private final int DEFAULT_PAGE_ACTIONS_SHOWN = 2;
private LinkedHashMap<String, PageAction> mPageActionList;
private ArrayList<PageAction> mPageActionList;
private GeckoPopupMenu mPageActionsMenu;
private Context mContext;
private LinearLayout mLayout;
@ -53,7 +53,7 @@ public class PageActionLayout extends LinearLayout implements GeckoEventListener
mContext = context;
mLayout = this;
mPageActionList = new LinkedHashMap<String, PageAction>();
mPageActionList = new ArrayList<PageAction>();
setNumberShown(DEFAULT_PAGE_ACTIONS_SHOWN);
refreshPageActionIcons();
@ -116,12 +116,12 @@ public class PageActionLayout extends LinearLayout implements GeckoEventListener
public void addPageAction(final String id, final String title, final String imageData, final OnPageActionClickListeners mOnPageActionClickListeners) {
final PageAction pageAction = new PageAction(id, title, null, mOnPageActionClickListeners);
mPageActionList.put(id, pageAction);
mPageActionList.add(pageAction);
BitmapUtils.getDrawable(mContext, imageData, new BitmapUtils.BitmapLoader() {
@Override
public void onBitmapFound(final Drawable d) {
if (mPageActionList.containsKey(id)) {
if (mPageActionList.contains(pageAction)) {
pageAction.setDrawable(d);
refreshPageActionIcons();
}
@ -130,8 +130,13 @@ public class PageActionLayout extends LinearLayout implements GeckoEventListener
}
public void removePageAction(String id) {
mPageActionList.remove(id);
refreshPageActionIcons();
for(int i = 0; i < mPageActionList.size(); i++) {
if (mPageActionList.get(i).getID().equals(id)) {
mPageActionList.remove(i);
refreshPageActionIcons();
return;
}
}
}
private ImageButton createImageButton() {
@ -150,7 +155,7 @@ public class PageActionLayout extends LinearLayout implements GeckoEventListener
if (buttonClickedId.equals(MENU_BUTTON_KEY)) {
showMenu(v, mPageActionList.size() - mMaxVisiblePageActions + 1);
} else {
mPageActionList.get(buttonClickedId).onClick();
getPageActionWithId(buttonClickedId).onClick();
}
}
}
@ -162,7 +167,7 @@ public class PageActionLayout extends LinearLayout implements GeckoEventListener
showMenu(v, mPageActionList.size() - mMaxVisiblePageActions + 1);
return true;
} else {
return mPageActionList.get(buttonClickedId).onLongClick();
return getPageActionWithId(buttonClickedId).onLongClick();
}
}
@ -230,18 +235,17 @@ public class PageActionLayout extends LinearLayout implements GeckoEventListener
if (mPageActionList.size() > buttonIndex) {
// Return the pageactions starting from the end of the list for the number of visible pageactions.
return getPageActionAt((mPageActionList.size() - totalVisibleButtons) + buttonIndex);
return mPageActionList.get((mPageActionList.size() - totalVisibleButtons) + buttonIndex);
}
return null;
}
private PageAction getPageActionAt(int index) {
int count = 0;
for(PageAction pageAction : mPageActionList.values()) {
if (count == index) {
private PageAction getPageActionWithId(String id) {
for(int i = 0; i < mPageActionList.size(); i++) {
PageAction pageAction = mPageActionList.get(i);
if (pageAction.getID().equals(id)) {
return pageAction;
}
count++;
}
return null;
}
@ -253,25 +257,27 @@ public class PageActionLayout extends LinearLayout implements GeckoEventListener
mPageActionsMenu.setOnMenuItemClickListener(new GeckoPopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
for(PageAction pageAction : mPageActionList.values()) {
if (pageAction.key() == item.getItemId()) {
int id = item.getItemId();
for(int i = 0; i < mPageActionList.size(); i++) {
PageAction pageAction = mPageActionList.get(i);
if (pageAction.key() == id) {
pageAction.onClick();
return true;
}
}
return true;
return false;
}
});
}
Menu menu = mPageActionsMenu.getMenu();
menu.clear();
int count = 0;
for(PageAction pageAction : mPageActionList.values()) {
if (count < toShow) {
for(int i = 0; i < mPageActionList.size(); i++) {
if (i < toShow) {
PageAction pageAction = mPageActionList.get(i);
MenuItem item = menu.add(Menu.NONE, pageAction.key(), Menu.NONE, pageAction.getTitle());
item.setIcon(pageAction.getDrawable());
}
count++;
}
mPageActionsMenu.show();
}