aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/res/layout/cache.xml253
-rw-r--r--main/src/cgeo/geocaching/cgCache.java9
-rw-r--r--main/src/cgeo/geocaching/cgeocaches.java50
-rw-r--r--main/src/cgeo/geocaching/ui/CacheListAdapter.java360
-rw-r--r--main/src/cgeo/geocaching/ui/CacheListView.java2
5 files changed, 220 insertions, 454 deletions
diff --git a/main/res/layout/cache.xml b/main/res/layout/cache.xml
index bc109cf..3f13fbe 100644
--- a/main/res/layout/cache.xml
+++ b/main/res/layout/cache.xml
@@ -3,154 +3,143 @@
android:id="@+id/one_cache"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
+ android:paddingBottom="7dip"
+ android:paddingTop="7dip"
android:background="?background_color" >
- <RelativeLayout android:id="@+id/one_checkbox"
+ <CheckBox android:id="@+id/checkbox"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_centerVertical="true"
+ android:layout_alignParentLeft="true"
+ android:layout_gravity="left"
+ android:padding="5dip"
+ android:gravity="left|center_horizontal"
+ android:visibility="visible" />
+ <ImageView android:id="@+id/log_status_mark"
+ android:layout_width="2dip"
+ android:layout_height="30dip"
+ android:layout_centerVertical="true"
+ android:layout_toRightOf="@id/checkbox"
+ android:scaleType="fitXY"
+ android:src="@drawable/mark_green" />
+ <TextView android:id="@+id/text"
android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:paddingBottom="7dip"
- android:paddingTop="7dip"
- android:background="?background_color" >
- <CheckBox android:id="@+id/checkbox"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerVertical="true"
- android:layout_alignParentLeft="true"
- android:layout_gravity="left"
- android:padding="5dip"
- android:gravity="left|center_horizontal" />
- </RelativeLayout>
- <RelativeLayout android:id="@+id/one_info"
+ android:layout_height="wrap_content"
+ android:layout_marginRight="110dip"
+ android:layout_marginLeft="10dip"
+ android:layout_toRightOf="@+id/log_status_mark"
+ android:layout_gravity="left"
+ android:paddingRight="3dip"
+ android:lines="1"
+ android:singleLine="true"
+ android:scrollHorizontally="true"
+ android:ellipsize="marquee"
+ android:textSize="18dip"
+ android:textColor="?text_color" />
+ <TextView android:id="@+id/info"
android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:paddingBottom="7dip"
- android:paddingTop="7dip"
- android:background="?background_color" >
- <ImageView android:id="@+id/log_status_mark"
- android:layout_width="2dip"
- android:layout_height="30dip"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="28dip"
+ android:layout_marginRight="110dip"
+ android:layout_marginLeft="10dip"
+ android:layout_alignParentBottom="true"
+ android:layout_toRightOf="@id/log_status_mark"
+ android:layout_gravity="left"
+ android:paddingRight="3dip"
+ android:lines="1"
+ android:singleLine="true"
+ android:scrollHorizontally="true"
+ android:ellipsize="marquee"
+ android:textSize="12dip"
+ android:textColor="?text_color_grey" />
+ <RelativeLayout android:id="@+id/direction_layout"
+ android:visibility="gone"
+ android:layout_width="78dip"
+ android:layout_height="wrap_content"
android:layout_centerVertical="true"
- android:layout_alignParentLeft="true"
- android:scaleType="fitXY"
- android:src="@drawable/mark_green" />
- <TextView android:id="@+id/text"
- android:layout_width="fill_parent"
+ android:layout_alignParentRight="true"
+ android:layout_marginTop="1dip"
+ android:layout_marginBottom="1dip"
+ android:layout_marginRight="30dip" >
+ <view class="cgeo.geocaching.ui.DistanceView"
+ android:id="@+id/distance"
+ android:layout_width="78dip"
android:layout_height="wrap_content"
- android:layout_marginRight="110dip"
- android:layout_marginLeft="10px"
- android:layout_alignParentLeft="true"
- android:layout_gravity="left"
- android:paddingRight="3dip"
+ android:layout_centerHorizontal="true"
+ android:layout_gravity="center"
android:lines="1"
android:singleLine="true"
android:scrollHorizontally="true"
android:ellipsize="marquee"
- android:textSize="18dip"
- android:textColor="?text_color" />
- <TextView android:id="@+id/info"
- android:layout_width="fill_parent"
+ android:textSize="16dip"
+ android:textColor="?text_color"
+ android:gravity="center" />
+ <view class="cgeo.geocaching.ui.CompassMiniView"
+ android:id="@+id/direction"
+ android:layout_width="78dip"
+ android:layout_height="28px"
+ android:layout_marginTop="21dip"
+ android:layout_centerHorizontal="true"
+ android:layout_gravity="center"
+ android:minWidth="28px"
+ android:minHeight="28px"
+ android:gravity="center"
+ cc:skin="?compass" />
+ </RelativeLayout>
+ <RelativeLayout android:id="@+id/dirimg_layout"
+ android:visibility="gone"
+ android:layout_width="78dip"
+ android:layout_height="wrap_content"
+ android:layout_centerVertical="true"
+ android:layout_alignParentRight="true"
+ android:layout_marginTop="1dip"
+ android:layout_marginBottom="1dip"
+ android:layout_marginRight="30dip" >
+ <ImageView android:id="@+id/dirimg"
+ android:layout_width="55dip"
+ android:layout_height="30dip"
+ android:layout_centerInParent="true"
+ android:layout_gravity="center"
+ android:gravity="center"
+ android:scaleType="fitXY"
+ android:src="@null" />
+ </RelativeLayout>
+ <RelativeLayout
+ android:layout_width="28dip"
+ android:layout_height="wrap_content"
+ android:layout_centerVertical="true"
+ android:layout_alignParentRight="true"
+ android:layout_marginTop="1dip"
+ android:layout_marginBottom="1dip"
+ android:layout_marginRight="2dip" >
+ <RelativeLayout android:id="@+id/inventory"
+ android:visibility="gone"
+ android:layout_width="28dip"
+ android:layout_height="22dip"
+ android:layout_marginTop="2dip"
+ android:layout_centerHorizontal="true"
+ android:layout_alignParentTop="true"
+ android:layout_gravity="center"
+ android:background="?inventory" >
+ </RelativeLayout>
+ <TextView android:id="@+id/favourite"
+ android:layout_width="28dip"
android:layout_height="wrap_content"
- android:layout_marginTop="28dip"
- android:layout_marginRight="110dip"
- android:layout_marginLeft="10dip"
+ android:layout_marginTop="24dip"
+ android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
- android:layout_alignParentLeft="true"
- android:layout_gravity="left"
+ android:layout_gravity="center"
+ android:gravity="center"
+ android:paddingLeft="3dip"
android:paddingRight="3dip"
+ android:paddingBottom="1dip"
android:lines="1"
android:singleLine="true"
android:scrollHorizontally="true"
android:ellipsize="marquee"
android:textSize="12dip"
- android:textColor="?text_color_grey" />
- <RelativeLayout android:id="@+id/direction_layout"
- android:visibility="gone"
- android:layout_width="78dip"
- android:layout_height="wrap_content"
- android:layout_centerVertical="true"
- android:layout_alignParentRight="true"
- android:layout_marginTop="1dip"
- android:layout_marginBottom="1dip"
- android:layout_marginRight="30dip" >
- <view class="cgeo.geocaching.ui.DistanceView"
- android:id="@+id/distance"
- android:layout_width="78dip"
- android:layout_height="wrap_content"
- android:layout_centerHorizontal="true"
- android:layout_gravity="center"
- android:lines="1"
- android:singleLine="true"
- android:scrollHorizontally="true"
- android:ellipsize="marquee"
- android:textSize="16dip"
- android:textColor="?text_color"
- android:gravity="center" />
- <view class="cgeo.geocaching.ui.CompassMiniView"
- android:id="@+id/direction"
- android:layout_width="78dip"
- android:layout_height="28px"
- android:layout_marginTop="21dip"
- android:layout_centerHorizontal="true"
- android:layout_gravity="center"
- android:minWidth="28px"
- android:minHeight="28px"
- android:gravity="center"
- cc:skin="?compass" />
- </RelativeLayout>
- <RelativeLayout android:id="@+id/dirimg_layout"
- android:visibility="gone"
- android:layout_width="78dip"
- android:layout_height="wrap_content"
- android:layout_centerVertical="true"
- android:layout_alignParentRight="true"
- android:layout_marginTop="1dip"
- android:layout_marginBottom="1dip"
- android:layout_marginRight="30dip" >
- <ImageView android:id="@+id/dirimg"
- android:layout_width="55dip"
- android:layout_height="30dip"
- android:layout_centerInParent="true"
- android:layout_gravity="center"
- android:gravity="center"
- android:scaleType="fitXY"
- android:src="@null" />
- </RelativeLayout>
- <RelativeLayout
- android:layout_width="28dip"
- android:layout_height="wrap_content"
- android:layout_centerVertical="true"
- android:layout_alignParentRight="true"
- android:layout_marginTop="1dip"
- android:layout_marginBottom="1dip"
- android:layout_marginRight="2dip" >
- <RelativeLayout android:id="@+id/inventory"
- android:visibility="gone"
- android:layout_width="28dip"
- android:layout_height="22dip"
- android:layout_marginTop="2dip"
- android:layout_centerHorizontal="true"
- android:layout_alignParentTop="true"
- android:layout_gravity="center"
- android:background="?inventory" >
- </RelativeLayout>
- <TextView android:id="@+id/favourite"
- android:layout_width="28dip"
- android:layout_height="wrap_content"
- android:layout_marginTop="24dip"
- android:layout_centerHorizontal="true"
- android:layout_alignParentBottom="true"
- android:layout_gravity="center"
- android:gravity="center"
- android:paddingLeft="3dip"
- android:paddingRight="3dip"
- android:paddingBottom="1dip"
- android:lines="1"
- android:singleLine="true"
- android:scrollHorizontally="true"
- android:ellipsize="marquee"
- android:textSize="12dip"
- android:textStyle="bold"
- android:background="?favourite"
- android:textColor="?text_color" />
- </RelativeLayout>
+ android:textStyle="bold"
+ android:background="?favourite"
+ android:textColor="?text_color" />
</RelativeLayout>
</RelativeLayout> \ No newline at end of file
diff --git a/main/src/cgeo/geocaching/cgCache.java b/main/src/cgeo/geocaching/cgCache.java
index a426614..fb44129 100644
--- a/main/src/cgeo/geocaching/cgCache.java
+++ b/main/src/cgeo/geocaching/cgCache.java
@@ -98,7 +98,6 @@ public class cgCache implements ICache, IWaypoint {
private boolean userModifiedCoords = false;
// temporary values
private boolean statusChecked = false;
- private boolean statusCheckedView = false;
private String directionImg = "";
private String nameForSorting;
private final EnumSet<StorageLocation> storageLocation = EnumSet.of(StorageLocation.HEAP);
@@ -960,14 +959,6 @@ public class cgCache implements ICache, IWaypoint {
this.statusChecked = statusChecked;
}
- public boolean isStatusCheckedView() {
- return statusCheckedView;
- }
-
- public void setStatusCheckedView(boolean statusCheckedView) {
- this.statusCheckedView = statusCheckedView;
- }
-
public String getDirectionImg() {
return directionImg;
}
diff --git a/main/src/cgeo/geocaching/cgeocaches.java b/main/src/cgeo/geocaching/cgeocaches.java
index b4caa89..5e16109 100644
--- a/main/src/cgeo/geocaching/cgeocaches.java
+++ b/main/src/cgeo/geocaching/cgeocaches.java
@@ -229,7 +229,7 @@ public class cgeocaches extends AbstractListActivity implements IObserver<Object
}
if (adapter != null) {
- adapter.setSelectMode(false, true);
+ adapter.setSelectMode(false);
}
}
};
@@ -287,7 +287,7 @@ public class cgeocaches extends AbstractListActivity implements IObserver<Object
showProgress(false);
if (adapter != null) {
- adapter.setSelectMode(false, true);
+ adapter.setSelectMode(false);
}
}
};
@@ -375,7 +375,7 @@ public class cgeocaches extends AbstractListActivity implements IObserver<Object
}
} else {
if (adapter != null) {
- adapter.setSelectMode(false, true);
+ adapter.setSelectMode(false);
}
cacheList.clear();
@@ -398,7 +398,7 @@ public class cgeocaches extends AbstractListActivity implements IObserver<Object
public void handleMessage(Message msg) {
if (msg.what != MSG_CANCEL) {
if (adapter != null) {
- adapter.setSelectMode(false, true);
+ adapter.setSelectMode(false);
}
refreshCurrentList();
@@ -432,7 +432,7 @@ public class cgeocaches extends AbstractListActivity implements IObserver<Object
}
} else {
if (adapter != null) {
- adapter.setSelectMode(false, true);
+ adapter.setSelectMode(false);
}
// reload history list
@@ -647,7 +647,7 @@ public class cgeocaches extends AbstractListActivity implements IObserver<Object
startGeoAndDir();
if (adapter != null) {
- adapter.setSelectMode(false, true);
+ adapter.setSelectMode(false);
final Geopoint coordsNow = app.currentGeo().getCoords();
if (coordsNow != null) {
adapter.setActualCoordinates(coordsNow);
@@ -775,7 +775,7 @@ public class cgeocaches extends AbstractListActivity implements IObserver<Object
menu.findItem(MENU_INVERT_SELECTION).setVisible(false);
}
- boolean hasSelection = adapter != null && adapter.getChecked() > 0;
+ boolean hasSelection = adapter != null && adapter.getCheckedCount() > 0;
boolean isNonDefaultList = listId != StoredList.STANDARD_LIST_ID;
if (type == CacheListType.OFFLINE) { // only offline list
@@ -846,9 +846,9 @@ public class cgeocaches extends AbstractListActivity implements IObserver<Object
if (menuItem == null) {
return;
}
- boolean hasSelection = adapter != null && adapter.getChecked() > 0;
+ boolean hasSelection = adapter != null && adapter.getCheckedCount() > 0;
if (hasSelection) {
- menuItem.setTitle(res.getString(resIdSelection) + " (" + adapter.getChecked() + ")");
+ menuItem.setTitle(res.getString(resIdSelection) + " (" + adapter.getCheckedCount() + ")");
} else {
menuItem.setTitle(res.getString(resId));
}
@@ -1036,14 +1036,14 @@ public class cgeocaches extends AbstractListActivity implements IObserver<Object
@Override
public void run(Integer newListId) {
List<cgCache> selected;
- final boolean moveAll = adapter.getChecked() == 0;
+ final boolean moveAll = adapter.getCheckedCount() == 0;
if (moveAll) {
selected = new ArrayList<cgCache>(cacheList);
} else {
selected = adapter.getCheckedCaches();
}
app.moveToList(selected, newListId);
- adapter.resetChecks();
+ adapter.setSelectMode(false);
refreshCurrentList();
}
@@ -1106,7 +1106,7 @@ public class cgeocaches extends AbstractListActivity implements IObserver<Object
@Override
public void run(Integer newListId) {
app.moveToList(Collections.singletonList(cache), newListId);
- adapter.resetChecks();
+ adapter.setSelectMode(false);
refreshCurrentList();
}
});
@@ -1157,10 +1157,8 @@ public class cgeocaches extends AbstractListActivity implements IObserver<Object
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (adapter != null) {
- if (adapter.resetChecks()) {
- return true;
- } else if (adapter.getSelectMode()) {
- adapter.setSelectMode(false, true);
+ if (adapter.getSelectMode()) {
+ adapter.setSelectMode(false);
return true;
}
}
@@ -1263,9 +1261,9 @@ public class cgeocaches extends AbstractListActivity implements IObserver<Object
}
public void refreshStored() {
- if (adapter != null && adapter.getChecked() > 0) {
+ if (adapter != null && adapter.getCheckedCount() > 0) {
// there are some checked caches
- detailTotal = adapter.getChecked();
+ detailTotal = adapter.getCheckedCount();
} else {
// no checked caches, download everything (when already stored - refresh them)
detailTotal = cacheList.size();
@@ -1297,7 +1295,7 @@ public class cgeocaches extends AbstractListActivity implements IObserver<Object
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setCancelable(true);
dialog.setTitle(res.getString(R.string.caches_removing_from_history));
- dialog.setMessage((adapter != null && adapter.getChecked() > 0) ? res.getString(R.string.cache_remove_from_history)
+ dialog.setMessage((adapter != null && adapter.getCheckedCount() > 0) ? res.getString(R.string.cache_remove_from_history)
: res.getString(R.string.cache_clear_history));
dialog.setPositiveButton(getString(android.R.string.yes), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
@@ -1316,10 +1314,10 @@ public class cgeocaches extends AbstractListActivity implements IObserver<Object
}
public void removeFromHistory() {
- if (adapter != null && adapter.getChecked() > 0)
+ if (adapter != null && adapter.getCheckedCount() > 0)
{
// there are some checked caches
- detailTotal = adapter.getChecked();
+ detailTotal = adapter.getCheckedCount();
}
else
{
@@ -1338,7 +1336,7 @@ public class cgeocaches extends AbstractListActivity implements IObserver<Object
public void exportCaches() {
List<cgCache> caches;
- if (adapter != null && adapter.getChecked() > 0) {
+ if (adapter != null && adapter.getCheckedCount() > 0) {
// there are some caches checked
caches = adapter.getCheckedCaches();
} else {
@@ -1364,7 +1362,7 @@ public class cgeocaches extends AbstractListActivity implements IObserver<Object
dialog.setCancelable(true);
dialog.setTitle(res.getString(R.string.caches_drop_stored));
- if (adapter != null && adapter.getChecked() > 0) {
+ if (adapter != null && adapter.getCheckedCount() > 0) {
dialog.setMessage(res.getString(R.string.caches_drop_selected_ask));
} else {
dialog.setMessage(res.getString(R.string.caches_drop_all_ask));
@@ -1606,7 +1604,7 @@ public class cgeocaches extends AbstractListActivity implements IObserver<Object
this.listIdLD = Math.max(listId, StoredList.STANDARD_LIST_ID);
if (adapter != null) {
- checked = adapter.getChecked();
+ checked = adapter.getCheckedCount();
}
}
@@ -1767,7 +1765,7 @@ public class cgeocaches extends AbstractListActivity implements IObserver<Object
handler = handlerIn;
- int checked = adapter.getChecked();
+ int checked = adapter.getCheckedCount();
if (checked == 0) {
selected = new ArrayList<cgCache>(cacheList);
}
@@ -1798,7 +1796,7 @@ public class cgeocaches extends AbstractListActivity implements IObserver<Object
handler = handlerIn;
if (adapter != null) {
- checked = adapter.getChecked();
+ checked = adapter.getCheckedCount();
}
}
diff --git a/main/src/cgeo/geocaching/ui/CacheListAdapter.java b/main/src/cgeo/geocaching/ui/CacheListAdapter.java
index 5d54359..b98aea1 100644
--- a/main/src/cgeo/geocaching/ui/CacheListAdapter.java
+++ b/main/src/cgeo/geocaching/ui/CacheListAdapter.java
@@ -27,17 +27,12 @@ import android.graphics.drawable.LayerDrawable;
import android.text.Spannable;
import android.text.Spanned;
import android.text.style.StrikethroughSpan;
-import android.util.DisplayMetrics;
import android.util.SparseArray;
import android.view.GestureDetector;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
-import android.view.animation.AccelerateDecelerateInterpolator;
-import android.view.animation.Animation;
-import android.view.animation.AnimationSet;
-import android.view.animation.TranslateAnimation;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
@@ -52,33 +47,31 @@ import java.util.Set;
public class CacheListAdapter extends ArrayAdapter<cgCache> {
- final private Resources res;
- /** Resulting list of caches */
- final private List<cgCache> list;
private CacheListView holder = null;
private LayoutInflater inflater = null;
private CacheComparator cacheComparator = null;
private Geopoint coords = null;
private float azimuth = 0;
private long lastSort = 0L;
- private boolean sort = true;
- private int checked = 0;
private boolean selectMode = false;
- final private static SparseArray<Drawable> gcIconDrawables = new SparseArray<Drawable>();
+ private IFilter currentFilter = null;
+ private List<cgCache> originalList = null;
+
final private Set<CompassMiniView> compasses = new LinkedHashSet<CompassMiniView>();
final private Set<DistanceView> distances = new LinkedHashSet<DistanceView>();
final private int[] ratingBcgs = new int[3];
- final private float pixelDensity;
+ final private CacheListType cacheListType;
+ final private Resources res;
+ /** Resulting list of caches */
+ final private List<cgCache> list;
+
private static final int SWIPE_MIN_DISTANCE = 60;
private static final int SWIPE_MAX_OFF_PATH = 100;
- private static final int SWIPE_DISTANCE = 80;
+ private static final SparseArray<Drawable> gcIconDrawables = new SparseArray<Drawable>();
/**
* time in milliseconds after which the list may be resorted due to position updates
*/
private static final int PAUSE_BETWEEN_LIST_SORT = 1000;
- private IFilter currentFilter = null;
- private List<cgCache> originalList = null;
- private final CacheListType cacheListType;
public CacheListAdapter(final Activity activity, final List<cgCache> list, CacheListType cacheListType) {
super(activity, 0, list);
@@ -90,11 +83,7 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> {
cacheComparator = new VisitComparator();
}
- final DisplayMetrics metrics = new DisplayMetrics();
- activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
- pixelDensity = metrics.density;
-
- Drawable modifiedCoordinatesMarker = activity.getResources().getDrawable(R.drawable.marker_usermodifiedcoords);
+ final Drawable modifiedCoordinatesMarker = activity.getResources().getDrawable(R.drawable.marker_usermodifiedcoords);
for (final CacheType cacheType : CacheType.values()) {
// unmodified icon
int hashCode = getIconHashCode(cacheType, false);
@@ -198,29 +187,25 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> {
return currentFilter.getName();
}
- public int getChecked() {
+ public int getCheckedCount() {
+ int checked = 0;
+ for (cgCache cache : list) {
+ if (cache.isStatusChecked()) {
+ checked++;
+ }
+ }
return checked;
}
- public boolean setSelectMode(final boolean status, final boolean clear) {
- selectMode = status;
+ public void setSelectMode(final boolean selectMode) {
+ this.selectMode = selectMode;
- if (!selectMode && clear) {
+ if (!selectMode) {
for (final cgCache cache : list) {
cache.setStatusChecked(false);
- cache.setStatusCheckedView(false);
- }
- checked = 0;
- } else if (selectMode) {
- for (final cgCache cache : list) {
- cache.setStatusCheckedView(false);
}
}
- checkChecked(0);
-
notifyDataSetChanged();
-
- return selectMode;
}
public boolean getSelectMode() {
@@ -228,45 +213,18 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> {
}
public void switchSelectMode() {
- selectMode = !selectMode;
-
- if (!selectMode) {
- for (final cgCache cache : list) {
- cache.setStatusChecked(false);
- cache.setStatusCheckedView(false);
- }
- checked = 0;
- } else {
- for (final cgCache cache : list) {
- cache.setStatusCheckedView(false);
- }
- }
- checkChecked(0);
-
- notifyDataSetChanged();
+ setSelectMode(!getSelectMode());
}
public void invertSelection() {
- int check = 0;
-
for (cgCache cache : list) {
- if (cache.isStatusChecked()) {
- cache.setStatusChecked(false);
- cache.setStatusCheckedView(false);
- } else {
- cache.setStatusChecked(true);
- cache.setStatusCheckedView(true);
-
- check++;
- }
+ cache.setStatusChecked(!cache.isStatusChecked());
}
- checkChecked(check);
-
notifyDataSetChanged();
}
public void forceSort(final Geopoint coordsIn) {
- if (CollectionUtils.isEmpty(list) || !sort) {
+ if (CollectionUtils.isEmpty(list) || selectMode) {
return;
}
@@ -290,7 +248,7 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> {
coords = coordsIn;
- if (CollectionUtils.isNotEmpty(list) && (System.currentTimeMillis() - lastSort) > PAUSE_BETWEEN_LIST_SORT && sort && isSortedByDistance()) {
+ if (CollectionUtils.isNotEmpty(list) && (System.currentTimeMillis() - lastSort) > PAUSE_BETWEEN_LIST_SORT && !selectMode && isSortedByDistance()) {
Collections.sort(list, new DistanceComparator(coordsIn, list));
notifyDataSetChanged();
lastSort = System.currentTimeMillis();
@@ -323,35 +281,6 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> {
}
}
- /**
- * clear all check marks
- *
- * @return
- */
- public boolean resetChecks() {
- if (list.isEmpty()) {
- return false;
- }
- if (checked <= 0) {
- return false;
- }
-
- boolean status = getSelectMode();
- int cleared = 0;
- for (cgCache cache : list) {
- if (cache.isStatusChecked()) {
- cache.setStatusChecked(false);
-
- checkChecked(-1);
- cleared++;
- }
- }
- setSelectMode(false, false);
- notifyDataSetChanged();
-
- return cleared > 0 || status;
- }
-
@Override
public View getView(final int position, final View rowView, final ViewGroup parent) {
if (inflater == null) {
@@ -363,7 +292,7 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> {
return null;
}
- cgCache cache = getItem(position);
+ final cgCache cache = getItem(position);
View v = rowView;
@@ -372,8 +301,6 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> {
holder = new CacheListView();
holder.checkbox = (CheckBox) v.findViewById(R.id.checkbox);
- holder.oneInfo = (RelativeLayout) v.findViewById(R.id.one_info);
- holder.oneCheckbox = (RelativeLayout) v.findViewById(R.id.one_checkbox);
holder.logStatusMark = (ImageView) v.findViewById(R.id.log_status_mark);
holder.text = (TextView) v.findViewById(R.id.text);
holder.directionLayout = (RelativeLayout) v.findViewById(R.id.direction_layout);
@@ -390,53 +317,23 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> {
holder = (CacheListView) v.getTag();
}
- if (cache.isOwn()) {
- if (Settings.isLightSkin()) {
- holder.oneInfo.setBackgroundResource(R.color.owncache_background_light);
- holder.oneCheckbox.setBackgroundResource(R.color.owncache_background_light);
- } else {
- holder.oneInfo.setBackgroundResource(R.color.owncache_background_dark);
- holder.oneCheckbox.setBackgroundResource(R.color.owncache_background_dark);
- }
- } else {
- if (Settings.isLightSkin()) {
- holder.oneInfo.setBackgroundResource(R.color.background_light);
- holder.oneCheckbox.setBackgroundResource(R.color.background_light);
- } else {
- holder.oneInfo.setBackgroundResource(R.color.background_dark);
- holder.oneCheckbox.setBackgroundResource(R.color.background_dark);
- }
- }
+ final boolean lightSkin = Settings.isLightSkin();
- final touchListener touchLst = new touchListener(cache.getGeocode(), cache.getName(), cache);
+ final TouchListener touchLst = new TouchListener(cache);
v.setOnClickListener(touchLst);
v.setOnLongClickListener(touchLst);
v.setOnTouchListener(touchLst);
v.setLongClickable(true);
if (selectMode) {
- if (cache.isStatusCheckedView()) {
- moveRight(holder, cache, true); // move fast when already slided
- } else {
- moveRight(holder, cache, false);
- }
- } else if (cache.isStatusChecked()) {
- holder.checkbox.setChecked(true);
- if (cache.isStatusCheckedView()) {
- moveRight(holder, cache, true); // move fast when already slided
- } else {
- moveRight(holder, cache, false);
- }
- } else {
- holder.checkbox.setChecked(false);
- if (cache.isStatusCheckedView()) {
- moveLeft(holder, cache, false);
- } else {
- holder.oneInfo.clearAnimation();
- }
+ holder.checkbox.setVisibility(View.VISIBLE);
+ }
+ else {
+ holder.checkbox.setVisibility(View.GONE);
}
- holder.checkbox.setOnClickListener(new checkBoxListener(cache));
+ holder.checkbox.setChecked(cache.isStatusChecked());
+ holder.checkbox.setOnClickListener(new SelectionCheckBoxListener(cache));
distances.add(holder.distance);
holder.distance.setContent(cache.getCoords());
@@ -470,9 +367,8 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> {
holder.inventory.removeAllViews();
}
- ImageView tbIcon;
if (cache.getInventoryItems() > 0) {
- tbIcon = (ImageView) inflater.inflate(R.layout.trackable_icon, null);
+ final ImageView tbIcon = (ImageView) inflater.inflate(R.layout.trackable_icon, null);
tbIcon.setImageResource(R.drawable.trackable_all);
holder.inventory.addView(tbIcon);
@@ -521,9 +417,9 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> {
}
if (dirImg != null) {
- if (!Settings.isLightSkin()) {
- int length = dirImg.getWidth() * dirImg.getHeight();
- int[] pixels = new int[length];
+ if (!lightSkin) {
+ final int length = dirImg.getWidth() * dirImg.getHeight();
+ final int[] pixels = new int[length];
dirImg.getPixels(pixels, 0, dirImg.getWidth(), 0, 0, dirImg.getWidth(), dirImg.getHeight());
for (int i = 0; i < length; i++) {
if (pixels[i] == 0xff000000) { // replace black with white
@@ -545,12 +441,12 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> {
int favoriteBack;
// set default background, neither vote nor rating may be available
- if (Settings.isLightSkin()) {
+ if (lightSkin) {
favoriteBack = R.drawable.favourite_background_light;
} else {
favoriteBack = R.drawable.favourite_background_dark;
}
- float myVote = cache.getMyVote();
+ final float myVote = cache.getMyVote();
if (myVote > 0) { // use my own rating for display, if I have voted
if (myVote >= 4) {
favoriteBack = ratingBcgs[2];
@@ -560,7 +456,7 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> {
favoriteBack = ratingBcgs[0];
}
} else {
- float rating = cache.getRating();
+ final float rating = cache.getRating();
if (rating >= 3.5) {
favoriteBack = ratingBcgs[2];
} else if (rating >= 2.1) {
@@ -572,13 +468,13 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> {
holder.favourite.setBackgroundResource(favoriteBack);
if (cacheListType == CacheListType.HISTORY && cache.getVisitedDate() > 0) {
- ArrayList<String> infos = new ArrayList<String>();
+ final ArrayList<String> infos = new ArrayList<String>();
infos.add(StringUtils.upperCase(cache.getGeocode()));
infos.add(Formatter.formatDate(cache.getVisitedDate()));
infos.add(Formatter.formatTime(cache.getVisitedDate()));
holder.info.setText(StringUtils.join(infos, Formatter.SEPARATOR));
} else {
- ArrayList<String> infos = new ArrayList<String>();
+ final ArrayList<String> infos = new ArrayList<String>();
if (StringUtils.isNotBlank(cache.getGeocode())) {
infos.add(cache.getGeocode());
}
@@ -610,7 +506,7 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> {
private static Drawable getCacheIcon(cgCache cache) {
int hashCode = getIconHashCode(cache.getType(), cache.hasUserModifiedCoords() || cache.hasFinalDefined());
- Drawable drawable = gcIconDrawables.get(hashCode);
+ final Drawable drawable = gcIconDrawables.get(hashCode);
if (drawable != null) {
return drawable;
}
@@ -623,53 +519,33 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> {
@Override
public void notifyDataSetChanged() {
super.notifyDataSetChanged();
-
- checked = 0;
- for (cgCache cache : list) {
- if (cache.isStatusChecked()) {
- checked++;
- }
- }
-
distances.clear();
compasses.clear();
}
- private class checkBoxListener implements View.OnClickListener {
+ private static class SelectionCheckBoxListener implements View.OnClickListener {
- private cgCache cache = null;
+ private final cgCache cache;
- public checkBoxListener(cgCache cacheIn) {
- cache = cacheIn;
+ public SelectionCheckBoxListener(cgCache cache) {
+ this.cache = cache;
}
public void onClick(View view) {
final boolean checkNow = ((CheckBox) view).isChecked();
-
- if (checkNow) {
- cache.setStatusChecked(true);
- checked++;
- } else {
- cache.setStatusChecked(false);
- checked--;
- }
+ cache.setStatusChecked(checkNow);
}
}
- private class touchListener implements View.OnLongClickListener, View.OnClickListener, View.OnTouchListener {
+ private class TouchListener implements View.OnLongClickListener, View.OnClickListener, View.OnTouchListener {
- private String geocode = null;
- private String name = null;
- private cgCache cache = null;
private boolean touch = true;
- private GestureDetector gestureDetector = null;
-
- public touchListener(String geocodeIn, String nameIn, cgCache cacheIn) {
- geocode = geocodeIn;
- name = nameIn;
- cache = cacheIn;
+ private final GestureDetector gestureDetector;
+ private final cgCache cache;
- final detectGesture dGesture = new detectGesture(holder, cache);
+ public TouchListener(final cgCache cache) {
+ this.cache = cache;
+ final FlingGesture dGesture = new FlingGesture(cache);
gestureDetector = new GestureDetector(dGesture);
}
@@ -680,12 +556,14 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> {
return;
}
- if (getSelectMode() || getChecked() > 0) {
+ if (getSelectMode()) {
+ cache.setStatusChecked(!cache.isStatusChecked());
+ notifyDataSetChanged();
return;
}
// load cache details
- CacheDetailActivity.startActivity(getContext(), geocode, name);
+ CacheDetailActivity.startActivity(getContext(), cache.getGeocode(), cache.getName());
}
// long tap on item
@@ -709,142 +587,54 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> {
}
}
- class detectGesture extends GestureDetector.SimpleOnGestureListener {
+ private class FlingGesture extends GestureDetector.SimpleOnGestureListener {
- private CacheListView holder = null;
- private cgCache cache = null;
+ private final cgCache cache;
- public detectGesture(CacheListView holderIn, cgCache cacheIn) {
- holder = holderIn;
- cache = cacheIn;
+ public FlingGesture(cgCache cache) {
+ this.cache = cache;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
try {
- if (getSelectMode()) {
- return false;
- }
-
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH) {
return false;
}
+ // left to right swipe
if ((e2.getX() - e1.getX()) > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > Math.abs(velocityY)) {
- // left to right swipe
- if (cache.isStatusChecked()) {
- return true;
- }
-
- if (holder != null && holder.oneInfo != null) {
- checkChecked(+1);
- holder.checkbox.setChecked(true);
+ if (!selectMode) {
+ switchSelectMode();
cache.setStatusChecked(true);
- moveRight(holder, cache, false);
}
-
return true;
- } else if ((e1.getX() - e2.getX()) > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > Math.abs(velocityY)) {
- // right to left swipe
- if (!cache.isStatusChecked()) {
- return true;
- }
-
- if (holder != null && holder.oneInfo != null) {
- if (getSelectMode()) {
- setSelectMode(false, false);
- }
+ }
- checkChecked(-1);
- holder.checkbox.setChecked(false);
- cache.setStatusChecked(false);
- moveLeft(holder, cache, false);
+ // right to left swipe
+ if ((e1.getX() - e2.getX()) > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > Math.abs(velocityY)) {
+ if (selectMode) {
+ switchSelectMode();
}
-
return true;
}
} catch (Exception e) {
- Log.w("CacheListAdapter.detectGesture.onFling: " + e.toString());
+ Log.w("CacheListAdapter.FlingGesture.onFling: " + e.toString());
}
return false;
}
}
- private void checkChecked(int cnt) {
- // check how many caches are selected, if any block sorting of list
- checked += cnt;
- sort = !(checked > 0 || getSelectMode());
-
- if (sort) {
- forceSort(coords);
- }
- }
-
- private void moveRight(CacheListView holder, cgCache cache, boolean force) {
- if (cache == null) {
- return;
- }
-
- holder.checkbox.setChecked(cache.isStatusChecked());
-
- // slide cache info
- final Animation showCheckbox = new TranslateAnimation(0, (int) (SWIPE_DISTANCE * pixelDensity), 0, 0);
- showCheckbox.setRepeatCount(0);
- showCheckbox.setDuration(force ? 0 : 400);
- showCheckbox.setFillEnabled(true);
- showCheckbox.setFillAfter(true);
- showCheckbox.setInterpolator(new AccelerateDecelerateInterpolator());
-
- // animation set (container)
- final AnimationSet selectAnimation = new AnimationSet(true);
- selectAnimation.setFillEnabled(true);
- selectAnimation.setFillAfter(true);
-
- selectAnimation.addAnimation(showCheckbox);
-
- holder.oneInfo.startAnimation(selectAnimation);
- cache.setStatusCheckedView(true);
- }
-
- private void moveLeft(CacheListView holder, cgCache cache, boolean force) {
- if (cache == null) {
- return;
- }
-
- holder.checkbox.setChecked(cache.isStatusChecked());
-
- // slide cache info
- final Animation hideCheckbox = new TranslateAnimation((int) (SWIPE_DISTANCE * pixelDensity), 0, 0, 0);
- hideCheckbox.setRepeatCount(0);
- hideCheckbox.setDuration(force ? 0 : 400);
- hideCheckbox.setFillEnabled(true);
- hideCheckbox.setFillAfter(true);
- hideCheckbox.setInterpolator(new AccelerateDecelerateInterpolator());
-
- // animation set (container)
- final AnimationSet selectAnimation = new AnimationSet(true);
- selectAnimation.setFillEnabled(true);
- selectAnimation.setFillAfter(true);
-
- selectAnimation.addAnimation(hideCheckbox);
-
- holder.oneInfo.startAnimation(selectAnimation);
- cache.setStatusCheckedView(false);
- }
-
public List<cgCache> getFilteredList() {
return list;
}
public List<cgCache> getCheckedCaches() {
- ArrayList<cgCache> result = new ArrayList<cgCache>();
- int checked = getChecked();
- if (checked > 0) {
- for (cgCache cache : list) {
- if (cache.isStatusChecked()) {
- result.add(cache);
- }
+ final ArrayList<cgCache> result = new ArrayList<cgCache>();
+ for (cgCache cache : list) {
+ if (cache.isStatusChecked()) {
+ result.add(cache);
}
}
return result;
diff --git a/main/src/cgeo/geocaching/ui/CacheListView.java b/main/src/cgeo/geocaching/ui/CacheListView.java
index ca5d23d..00d3ad7 100644
--- a/main/src/cgeo/geocaching/ui/CacheListView.java
+++ b/main/src/cgeo/geocaching/ui/CacheListView.java
@@ -8,8 +8,6 @@ import android.widget.TextView;
public class CacheListView {
// layouts & views
- public RelativeLayout oneInfo;
- public RelativeLayout oneCheckbox;
public CheckBox checkbox;
public ImageView logStatusMark;
public TextView text;