Support zoom in image view

This commit is contained in:
drdev
2014-05-23 00:42:42 +00:00
parent cf8efce2f0
commit 31a6bf16cc
2 changed files with 28 additions and 3 deletions

View File

@@ -62,6 +62,7 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
private GroupDef groupBy = null;
private ItemInfo focalItem;
private boolean updatingLayout;
private float totalZoomAmount;
private final ArrayList<ItemInfo> orderedItems = new ArrayList<ItemInfo>();
private final ArrayList<Group> groups = new ArrayList<Group>();
@@ -545,7 +546,7 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
}
@Override
protected boolean onScrollerTap(float x, float y, int count) {
protected boolean tap(float x, float y, int count) {
ItemInfo item = getItemAtPoint(x, y);
if (count == 1) {
selectItem(item);
@@ -558,6 +559,22 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
return true;
}
@Override
protected boolean zoom(float x, float y, float amount) {
totalZoomAmount += amount;
float columnZoomAmount = Utils.AVG_FINGER_WIDTH;
while (totalZoomAmount >= columnZoomAmount) {
setColumnCount(getColumnCount() - 1);
totalZoomAmount -= columnZoomAmount;
}
while (totalZoomAmount <= -columnZoomAmount) {
setColumnCount(getColumnCount() + 1);
totalZoomAmount += columnZoomAmount;
}
return true;
}
private ItemInfo getItemAtPoint(float x, float y) {
for (int i = groups.size() - 1; i >= 0; i--) {
Group group = groups.get(i);

View File

@@ -55,7 +55,12 @@ public abstract class ItemView<T extends InventoryItem> {
@Override
public boolean tap(float x, float y, int count) {
return onScrollerTap(x, y, count);
return ItemView.this.tap(x, y, count);
}
@Override
public boolean zoom(float x, float y, float amount) {
return ItemView.this.zoom(x, y, amount);
}
@Override
@@ -64,7 +69,10 @@ public abstract class ItemView<T extends InventoryItem> {
}
}
protected boolean onScrollerTap(float x, float y, int count) {
protected boolean tap(float x, float y, int count) {
return false;
}
protected boolean zoom(float x, float y, float amount) {
return false;
}
protected abstract float getScrollHeight();