From d074a5ff3835bb62dab5bf4c98754bc2642611a0 Mon Sep 17 00:00:00 2001 From: drdev Date: Thu, 22 May 2014 23:58:07 +0000 Subject: [PATCH] Fix image view selection --- .../forge/itemmanager/views/ImageView.java | 95 ++++++++++--------- .../src/forge/itemmanager/views/ItemView.java | 8 ++ 2 files changed, 58 insertions(+), 45 deletions(-) diff --git a/forge-gui-mobile/src/forge/itemmanager/views/ImageView.java b/forge-gui-mobile/src/forge/itemmanager/views/ImageView.java index 9e4bc66bec0..51c974ed5a0 100644 --- a/forge-gui-mobile/src/forge/itemmanager/views/ImageView.java +++ b/forge-gui-mobile/src/forge/itemmanager/views/ImageView.java @@ -544,6 +544,20 @@ public class ImageView extends ItemView { return groups.get(groups.size() - 1).getBottom() + PADDING; } + @Override + protected boolean onScrollerTap(float x, float y, int count) { + ItemInfo item = getItemAtPoint(x, y); + if (count == 1) { + selectItem(item); + } + else if (count == 2) { + if (item != null && item.selected) { + itemManager.activateSelectedItems(); + } + } + return true; + } + private ItemInfo getItemAtPoint(float x, float y) { for (int i = groups.size() - 1; i >= 0; i--) { Group group = groups.get(i); @@ -682,6 +696,35 @@ public class ImageView extends ItemView { } } + private boolean selectItem(ItemInfo item) { + if (item == null) { + if (!KeyInputAdapter.isCtrlKeyDown() && !KeyInputAdapter.isShiftKeyDown()) { + clearSelection(); + onSelectionChange(); + } + return false; + } + + if (item.selected) { + if (KeyInputAdapter.isCtrlKeyDown()) { + item.selected = false; + selectedIndices.remove((Object)item.index); + onSelectionChange(); + item.group.scrollIntoView(item); + return true; + } + } + if (!allowMultipleSelections || (!KeyInputAdapter.isCtrlKeyDown() && !KeyInputAdapter.isShiftKeyDown())) { + clearSelection(); + } + selectedIndices.add(0, item.index); + item.selected = true; + onSelectionChange(); + item.group.scrollIntoView(item); + getScroller().scrollIntoView(item); + return true; + } + @Override public void scrollSelectionIntoView() { if (selectedIndices.isEmpty()) { return; } @@ -782,57 +825,19 @@ public class ImageView extends ItemView { btnExpandCollapseAll.updateIsAllCollapsed(); clearSelection(); //must clear selection since indices and visible items will be changing updateLayout(false); - } - else if (count == 1) { - selectItem(getItemAtPoint(x + getLeft(), y + getTop())); - } - else if (count == 2) { - ItemInfo item = getItemAtPoint(x + getLeft(), y + getTop()); - if (item != null && item.selected) { - itemManager.activateSelectedItems(); - } - } - return true; - } - - @Override - public boolean longPress(float x, float y) { - ItemInfo item = getItemAtPoint(x + getLeft(), y + getTop()); - selectItem(item); - if (item != null && item.item instanceof IPaperCard) { - CardZoom.show(Card.getCardForUi((IPaperCard) item.item)); return true; } return false; } - private boolean selectItem(ItemInfo item) { - if (item == null) { - if (!KeyInputAdapter.isCtrlKeyDown() && !KeyInputAdapter.isShiftKeyDown()) { - clearSelection(); - onSelectionChange(); - } - return false; + @Override + public boolean longPress(float x, float y) { + ItemInfo item = getItemAtPoint(x + getLeft(), y + getTop()); + if (item != null && item.item instanceof IPaperCard) { + CardZoom.show(Card.getCardForUi((IPaperCard) item.item)); + return true; } - - if (item.selected) { - if (KeyInputAdapter.isCtrlKeyDown()) { - item.selected = false; - selectedIndices.remove((Object)item.index); - onSelectionChange(); - item.group.scrollIntoView(item); - return true; - } - } - if (!allowMultipleSelections || (!KeyInputAdapter.isCtrlKeyDown() && !KeyInputAdapter.isShiftKeyDown())) { - clearSelection(); - } - selectedIndices.add(0, item.index); - item.selected = true; - onSelectionChange(); - item.group.scrollIntoView(item); - getScroller().scrollIntoView(item); - return true; + return false; } //provide special override for this function to account for special ItemInfo positioning logic diff --git a/forge-gui-mobile/src/forge/itemmanager/views/ItemView.java b/forge-gui-mobile/src/forge/itemmanager/views/ItemView.java index a682cbe91b0..ae8b852cbb2 100644 --- a/forge-gui-mobile/src/forge/itemmanager/views/ItemView.java +++ b/forge-gui-mobile/src/forge/itemmanager/views/ItemView.java @@ -53,12 +53,20 @@ public abstract class ItemView { return new ScrollBounds(visibleWidth, ItemView.this.getScrollHeight()); } + @Override + public boolean tap(float x, float y, int count) { + return onScrollerTap(x, y, count); + } + @Override public void drawOverlay(Graphics g) { g.drawRect(1.5f, BORDER_COLOR, 0, 0, getWidth(), getHeight()); } } + protected boolean onScrollerTap(float x, float y, int count) { + return false; + } protected abstract float getScrollHeight(); protected abstract float layoutOptionsPanel(float visibleWidth, float height);