diff options
author | Bananeweizen <bananeweizen@gmx.de> | 2011-11-13 18:08:03 +0100 |
---|---|---|
committer | Bananeweizen <bananeweizen@gmx.de> | 2011-11-13 18:08:03 +0100 |
commit | e508761acbd433aeb6f0b153c2619b792b7dba3c (patch) | |
tree | b7d34aa7ecb9535c60be32a0cc47655b40d7f67d /main/src/cgeo | |
parent | 92b82a8e9bae779e0edd7618b30fa3909afe6ceb (diff) | |
download | cgeo-e508761acbd433aeb6f0b153c2619b792b7dba3c.zip cgeo-e508761acbd433aeb6f0b153c2619b792b7dba3c.tar.gz cgeo-e508761acbd433aeb6f0b153c2619b792b7dba3c.tar.bz2 |
refactor duplicate code from map
Diffstat (limited to 'main/src/cgeo')
3 files changed, 50 insertions, 40 deletions
diff --git a/main/src/cgeo/geocaching/maps/OtherCachersOverlayItem.java b/main/src/cgeo/geocaching/maps/OtherCachersOverlayItem.java new file mode 100644 index 0000000..16e2677 --- /dev/null +++ b/main/src/cgeo/geocaching/maps/OtherCachersOverlayItem.java @@ -0,0 +1,36 @@ +package cgeo.geocaching.maps; + +import cgeo.geocaching.R; +import cgeo.geocaching.go4cache.Go4CacheUser; + +import android.content.Context; +import android.graphics.drawable.Drawable; + +public class OtherCachersOverlayItem { + private final Context context; + private final Go4CacheUser user; + + public OtherCachersOverlayItem(Context contextIn, Go4CacheUser userIn) { + context = contextIn; + user = userIn; + } + + public Drawable getMarker(int state) { + Drawable marker = null; + + if (user != null && user.getDate() != null && user.getDate().getTime() >= (System.currentTimeMillis() - (20 * 60 * 1000))) { + marker = context.getResources().getDrawable(R.drawable.user_location_active); + } else { + marker = context.getResources().getDrawable(R.drawable.user_location); + } + + marker.setBounds(0, 0, marker.getIntrinsicWidth(), marker.getIntrinsicHeight()); + marker.setAlpha(190); + + return marker; + } + + public Go4CacheUser getUser() { + return user; + } +}
\ No newline at end of file diff --git a/main/src/cgeo/geocaching/maps/google/GoogleOtherCachersOverlayItem.java b/main/src/cgeo/geocaching/maps/google/GoogleOtherCachersOverlayItem.java index 286129d..9d9580c 100644 --- a/main/src/cgeo/geocaching/maps/google/GoogleOtherCachersOverlayItem.java +++ b/main/src/cgeo/geocaching/maps/google/GoogleOtherCachersOverlayItem.java @@ -1,7 +1,7 @@ package cgeo.geocaching.maps.google; -import cgeo.geocaching.R; import cgeo.geocaching.go4cache.Go4CacheUser; +import cgeo.geocaching.maps.OtherCachersOverlayItem; import cgeo.geocaching.maps.interfaces.OtherCachersOverlayItemImpl; import com.google.android.maps.GeoPoint; @@ -11,34 +11,21 @@ import android.content.Context; import android.graphics.drawable.Drawable; public class GoogleOtherCachersOverlayItem extends OverlayItem implements OtherCachersOverlayItemImpl { - private Context context = null; - private Go4CacheUser user = null; + final private OtherCachersOverlayItem item; - public GoogleOtherCachersOverlayItem(Context contextIn, Go4CacheUser userIn) { - super(new GeoPoint(userIn.getCoords().getLatitudeE6(), userIn.getCoords().getLongitudeE6()), userIn.getUsername(), ""); - - context = contextIn; - user = userIn; + public GoogleOtherCachersOverlayItem(Context context, Go4CacheUser user) { + super(new GeoPoint(user.getCoords().getLatitudeE6(), user.getCoords().getLongitudeE6()), user.getUsername(), ""); + item = new OtherCachersOverlayItem(context, user); } @Override public Drawable getMarker(int state) { - Drawable marker = null; - - if (user != null && user.getDate() != null && user.getDate().getTime() >= (System.currentTimeMillis() - (20 * 60 * 1000))) { - marker = context.getResources().getDrawable(R.drawable.user_location_active); - } else { - marker = context.getResources().getDrawable(R.drawable.user_location); - } - - marker.setBounds(0, 0, marker.getIntrinsicWidth(), marker.getIntrinsicHeight()); - marker.setAlpha(190); + final Drawable marker = item.getMarker(state); setMarker(marker); - return marker; } public Go4CacheUser getUser() { - return user; + return item.getUser(); } } diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOtherCachersOverlayItem.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOtherCachersOverlayItem.java index 10f62b9..e9c1d0b 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOtherCachersOverlayItem.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOtherCachersOverlayItem.java @@ -1,7 +1,7 @@ package cgeo.geocaching.maps.mapsforge; -import cgeo.geocaching.R; import cgeo.geocaching.go4cache.Go4CacheUser; +import cgeo.geocaching.maps.OtherCachersOverlayItem; import cgeo.geocaching.maps.interfaces.OtherCachersOverlayItemImpl; import org.mapsforge.android.maps.GeoPoint; @@ -11,34 +11,21 @@ import android.content.Context; import android.graphics.drawable.Drawable; public class MapsforgeOtherCachersOverlayItem extends OverlayItem implements OtherCachersOverlayItemImpl { - private Context context = null; - private Go4CacheUser user = null; + private final OtherCachersOverlayItem item; - public MapsforgeOtherCachersOverlayItem(Context contextIn, Go4CacheUser userIn) { - super(new GeoPoint(userIn.getCoords().getLatitudeE6(), userIn.getCoords().getLongitudeE6()), userIn.getUsername(), ""); - - context = contextIn; - user = userIn; + public MapsforgeOtherCachersOverlayItem(Context context, Go4CacheUser user) { + super(new GeoPoint(user.getCoords().getLatitudeE6(), user.getCoords().getLongitudeE6()), user.getUsername(), ""); + item = new OtherCachersOverlayItem(context, user); } @Override public Drawable getMarker(int state) { - Drawable marker = null; - - if (user != null && user.getDate() != null && user.getDate().getTime() >= (System.currentTimeMillis() - (20 * 60 * 1000))) { - marker = context.getResources().getDrawable(R.drawable.user_location_active); - } else { - marker = context.getResources().getDrawable(R.drawable.user_location); - } - - marker.setBounds(0, 0, marker.getIntrinsicWidth(), marker.getIntrinsicHeight()); - marker.setAlpha(190); + Drawable marker = item.getMarker(state); setMarker(marker); - return marker; } public Go4CacheUser getUser() { - return user; + return item.getUser(); } } |