diff options
| author | Karsten Priegnitz <koem@petoria.de> | 2011-09-09 18:11:07 +0200 |
|---|---|---|
| committer | Karsten Priegnitz <koem@petoria.de> | 2011-09-09 18:11:07 +0200 |
| commit | 7aed42d7b34d32e01e08799caf1ce0f4485fdf77 (patch) | |
| tree | 43ddf13844e606dfd0d98638b03c165b72a71580 /src/cgeo | |
| parent | a946f2607f421a239e003967986e2454ded1ce0b (diff) | |
| parent | 8533fd50866694fb29a4b5caaf91852789eed5c8 (diff) | |
| download | cgeo-7aed42d7b34d32e01e08799caf1ce0f4485fdf77.zip cgeo-7aed42d7b34d32e01e08799caf1ce0f4485fdf77.tar.gz cgeo-7aed42d7b34d32e01e08799caf1ce0f4485fdf77.tar.bz2 | |
Merge commit 'upstream/master'
Conflicts:
AndroidManifest.xml
Diffstat (limited to 'src/cgeo')
| -rw-r--r-- | src/cgeo/geocaching/ICache.java | 15 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgBase.java | 38 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgCache.java | 7 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgCompass.java | 157 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgeopoint.java | 5 | ||||
| -rw-r--r-- | src/cgeo/geocaching/files/GPXParser.java | 69 | ||||
| -rw-r--r-- | src/cgeo/geocaching/geopoint/Geopoint.java | 101 | ||||
| -rw-r--r-- | src/cgeo/geocaching/mapcommon/cgeomap.java | 74 |
8 files changed, 185 insertions, 281 deletions
diff --git a/src/cgeo/geocaching/ICache.java b/src/cgeo/geocaching/ICache.java index d32c48c..c91b959 100644 --- a/src/cgeo/geocaching/ICache.java +++ b/src/cgeo/geocaching/ICache.java @@ -1,5 +1,5 @@ /**
- *
+ *
*/
package cgeo.geocaching;
@@ -10,12 +10,7 @@ package cgeo.geocaching; *
*/
public interface ICache {
-
- /**
- * @return The data returned by the HTTP-GET request for this cache. Only for testing purposes.
- */
- public String getData();
-
+
/**
* @return Geocode like GCxxxx
*/
@@ -45,9 +40,9 @@ public interface ICache { */
public Float getTerrain();
/**
- * @return Latitute, e.g. N 52° 12.345
+ * @return Latitude, e.g. N 52° 12.345
*/
- public String getLatitute();
+ public String getLatitude();
/**
* @return Longitude, e.g. E 9° 34.567
*/
@@ -73,7 +68,7 @@ public interface ICache { */
public String getHint();
/**
- * @return Descrition
+ * @return Description
*/
public String getDescription();
/**
diff --git a/src/cgeo/geocaching/cgBase.java b/src/cgeo/geocaching/cgBase.java index 3abd142..9b78ce9 100644 --- a/src/cgeo/geocaching/cgBase.java +++ b/src/cgeo/geocaching/cgBase.java @@ -1236,20 +1236,7 @@ public class cgBase { } // cache found - try - { - final Matcher matcherFound = patternFound.matcher(page); - final Matcher matcherFoundAlternative = patternFoundAlternative.matcher(page); - - if (matcherFound.find() || matcherFoundAlternative.find()) { - cache.found = true; - } - } - catch (Exception e) - { - // failed to parse found - Log.w(cgSettings.tag, "cgeoBase.parseCache: Failed to parse found"); - } + cache.found = patternFound.matcher(page).find() || patternFoundAlternative.matcher(page).find(); // cache type try { @@ -1348,7 +1335,7 @@ public class cgBase { try { final Matcher matcherPersonalNote = patternPersonalNote.matcher(page); if (matcherPersonalNote.find() && matcherPersonalNote.groupCount() > 0) { - cache.personalNote = getMatch(matcherPersonalNote.group(1).trim()); + cache.personalNote = getMatch(matcherPersonalNote.group(1)); } } catch (Exception e) { // failed to parse cache personal note @@ -1772,7 +1759,7 @@ public class cgBase { private static String getMatch(String match) { // creating a new String via String constructor is necessary here!! - return new String(match); + return new String(match.trim()); // Java copies the whole page String, when matching with regular expressions // later this would block the garbage collector, as we only need tiny parts of the page // see http://developer.android.com/reference/java/lang/String.html#backing_array @@ -3257,7 +3244,7 @@ public class cgBase { } search.viewstates = caches.viewstates; search.totalCnt = caches.totalCnt; - + if (CollectionUtils.isNotEmpty(caches.cacheList)) { for (cgCache cache : caches.cacheList) { if ((excludeDisabled == 0 || (excludeDisabled == 1 && cache.disabled == false)) @@ -3272,7 +3259,7 @@ public class cgBase { } return cacheList; } - + public cgTrackable searchTrackable(Map<String, String> parameters) { final String geocode = parameters.get("geocode"); final String guid = parameters.get("guid"); @@ -5011,7 +4998,6 @@ public class cgBase { * Generate a time string according to system-wide settings (locale, 12/24 hour) * such as "13:24". * - * @param context a context * @param date milliseconds since the epoch * @return the formatted string */ @@ -5023,7 +5009,6 @@ public class cgBase { * Generate a date string according to system-wide settings (locale, date format) * such as "20 December" or "20 December 2010". The year will only be included when necessary. * - * @param context a context * @param date milliseconds since the epoch * @return the formatted string */ @@ -5061,7 +5046,6 @@ public class cgBase { * Generate a numeric date string according to system-wide settings (locale, date format) * such as "10/20/2010". * - * @param context a context * @param date milliseconds since the epoch * @return the formatted string */ @@ -5071,6 +5055,18 @@ public class cgBase { } /** + * Generate a numeric date and time string according to system-wide settings (locale, + * date format) such as "7 sept. à 12:35". + * + * @param context a Context + * @param date milliseconds since the epoch + * @return the formatted string + */ + public static String formatShortDateTime(Context context, long date) { + return DateUtils.formatDateTime(context, date, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_ALL); + } + + /** * TODO This method is only needed until the settings are a singleton * @return */ diff --git a/src/cgeo/geocaching/cgCache.java b/src/cgeo/geocaching/cgCache.java index e9c37ef..dfa5029 100644 --- a/src/cgeo/geocaching/cgCache.java +++ b/src/cgeo/geocaching/cgCache.java @@ -392,11 +392,6 @@ public class cgCache implements ICache { } @Override
- public String getData() {
- return null;
- }
-
- @Override
public Float getDifficulty() {
return difficulty;
}
@@ -407,7 +402,7 @@ public class cgCache implements ICache { }
@Override
- public String getLatitute() {
+ public String getLatitude() {
return latitudeString;
}
diff --git a/src/cgeo/geocaching/cgCompass.java b/src/cgeo/geocaching/cgCompass.java index 4a004b3..7ecee4b 100644 --- a/src/cgeo/geocaching/cgCompass.java +++ b/src/cgeo/geocaching/cgCompass.java @@ -15,18 +15,16 @@ import android.view.View; public class cgCompass extends View { private changeThread watchdog = null; - private boolean wantStop = false; - private boolean lock = false; - private boolean drawing = false; + private volatile boolean wantStop = false; private Context context = null; private Bitmap compassUnderlay = null; private Bitmap compassRose = null; private Bitmap compassArrow = null; private Bitmap compassOverlay = null; - private Double azimuth = Double.valueOf(0); - private Double heading = Double.valueOf(0); - private Double cacheHeading = Double.valueOf(0); - private Double northHeading = Double.valueOf(0); + private double azimuth = 0.0; + private double heading = 0.0; + private double cacheHeading = 0.0; + private double northHeading = 0.0; private PaintFlagsDrawFilter setfil = null; private PaintFlagsDrawFilter remfil = null; private int compassUnderlayWidth = 0; @@ -105,11 +103,40 @@ public class cgCompass extends View { } } - protected void updateNorth(Double northHeadingIn, Double cacheHeadingIn) { + protected synchronized void updateNorth(double northHeadingIn, double cacheHeadingIn) { northHeading = northHeadingIn; cacheHeading = cacheHeadingIn; } + /** + * Compute the new value, moving by small increments. + * @param goal the goal to reach + * @param actual the actual value + * @return the new value + */ + static protected double smoothUpdate(double goal, double actual) { + double diff = goal - actual; + final boolean largeDiff = Math.abs(diff) > 5; + + double offset = 0.0; + + if (diff < 0.0) { + diff = diff + 360.0; + } else if (diff >= 360.0) { + diff = diff - 360.0; + } + + // If the difference is smaller than 1 degree, do nothing as it + // causes the arrow to vibrate. + if (diff > 1.0 && diff <= 180.0) { + offset = largeDiff ? 2.0 : 1.0; + } else if (diff > 180.0 && diff < 359.0) { + offset = largeDiff ? -2.0 : -1.0; + } + + return actual + offset; + } + private class changeThread extends Thread { @Override @@ -121,93 +148,11 @@ public class cgCompass extends View { // nothing } - if (Math.abs(azimuth - northHeading) < 2 && Math.abs(heading - cacheHeading) < 2) { - continue; - } - - lock = true; - - Double diff = Double.valueOf(0); - Double diffAbs = Double.valueOf(0); - Double tempAzimuth = Double.valueOf(0); - Double tempHeading = Double.valueOf(0); - - Double actualAzimuth = azimuth; - Double actualHeading = heading; - - diff = northHeading - actualAzimuth; - diffAbs = Math.abs(northHeading - actualAzimuth); - if (diff < 0) { - diff = diff + 360; - } else if (diff >= 360) { - diff = diff - 360; - } - - if (diff > 0 && diff <= 180) { - if (diffAbs > 5) { - tempAzimuth = actualAzimuth + 2; - } else if (diffAbs > 1) { - tempAzimuth = actualAzimuth + 1; - } else { - tempAzimuth = actualAzimuth; - } - } else if (diff > 180 && diff < 360) { - if (diffAbs > 5) { - tempAzimuth = actualAzimuth - 2; - } else if (diffAbs > 1) { - tempAzimuth = actualAzimuth - 1; - } else { - tempAzimuth = actualAzimuth; - } - } else { - tempAzimuth = actualAzimuth; + synchronized(cgCompass.this) { + azimuth = smoothUpdate(northHeading, azimuth); + heading = smoothUpdate(cacheHeading, heading); } - diff = cacheHeading - actualHeading; - diffAbs = Math.abs(cacheHeading - actualHeading); - if (diff < 0) { - diff = diff + 360; - } else if (diff >= 360) { - diff = diff - 360; - } - - if (diff > 0 && diff <= 180) { - if (diffAbs > 5) { - tempHeading = actualHeading + 2; - } else if (diffAbs > 1) { - tempHeading = actualHeading + 1; - } else { - tempHeading = actualHeading; - } - } else if (diff > 180 && diff < 360) { - if (diffAbs > 5) { - tempHeading = actualHeading - 2; - } else if (diffAbs > 1) { - tempHeading = actualHeading - 1; - } else { - tempHeading = actualHeading; - } - } else { - tempHeading = actualHeading; - } - - if (tempAzimuth >= 360) { - tempAzimuth = tempAzimuth - 360; - } else if (tempAzimuth < 0) { - tempAzimuth = tempAzimuth + 360; - } - - if (tempHeading >= 360) { - tempHeading = tempHeading - 360; - } else if (tempHeading < 0) { - tempHeading = tempHeading + 360; - } - - azimuth = tempAzimuth; - heading = tempHeading; - - lock = false; - changeHandler.sendMessage(new Message()); } } @@ -215,15 +160,16 @@ public class cgCompass extends View { @Override protected void onDraw(Canvas canvas) { - if (lock) { - return; - } - if (drawing) { - return; + double currentAzimuth; + double currentHeading; + + synchronized(this) { + currentAzimuth = azimuth; + currentHeading = heading; } - Double azimuthTemp = azimuth; - Double azimuthRelative = azimuthTemp - heading; + double azimuthTemp = currentAzimuth; + double azimuthRelative = azimuthTemp - currentHeading; if (azimuthRelative < 0) { azimuthRelative = azimuthRelative + 360; } else if (azimuthRelative >= 360) { @@ -237,7 +183,6 @@ public class cgCompass extends View { int marginLeftTemp = 0; int marginTopTemp = 0; - drawing = true; super.onDraw(canvas); canvas.save(); @@ -251,16 +196,16 @@ public class cgCompass extends View { marginLeftTemp = (getWidth() - compassRoseWidth) / 2; marginTopTemp = (getHeight() - compassRoseHeight) / 2; - canvas.rotate(-(azimuthTemp.floatValue()), canvasCenterX, canvasCenterY); + canvas.rotate((float) -azimuthTemp, canvasCenterX, canvasCenterY); canvas.drawBitmap(compassRose, marginLeftTemp, marginTopTemp, null); - canvas.rotate(azimuthTemp.floatValue(), canvasCenterX, canvasCenterY); + canvas.rotate((float) azimuthTemp, canvasCenterX, canvasCenterY); marginLeftTemp = (getWidth() - compassArrowWidth) / 2; marginTopTemp = (getHeight() - compassArrowHeight) / 2; - canvas.rotate(-(azimuthRelative.floatValue()), canvasCenterX, canvasCenterY); + canvas.rotate((float) -azimuthRelative, canvasCenterX, canvasCenterY); canvas.drawBitmap(compassArrow, marginLeftTemp, marginTopTemp, null); - canvas.rotate(azimuthRelative.floatValue(), canvasCenterX, canvasCenterY); + canvas.rotate((float) azimuthRelative, canvasCenterX, canvasCenterY); marginLeftTemp = (getWidth() - compassOverlayWidth) / 2; marginTopTemp = (getHeight() - compassOverlayHeight) / 2; @@ -269,8 +214,6 @@ public class cgCompass extends View { canvas.setDrawFilter(remfil); canvas.restore(); - - drawing = false; } @Override diff --git a/src/cgeo/geocaching/cgeopoint.java b/src/cgeo/geocaching/cgeopoint.java index dba015d..530f557 100644 --- a/src/cgeo/geocaching/cgeopoint.java +++ b/src/cgeo/geocaching/cgeopoint.java @@ -14,7 +14,6 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Configuration; import android.os.Bundle; -import android.text.format.DateFormat; import android.util.Log; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; @@ -66,9 +65,7 @@ public class cgeopoint extends AbstractActivity { longitude.setText(lonString); latitude.setText(latString); - CharSequence dateString = DateFormat.format("dd/MM/yy kk:mm", - loc.getDate()); - date.setText(dateString); + date.setText(cgBase.formatShortDateTime(getContext(), loc.getDate())); return convertView; } diff --git a/src/cgeo/geocaching/files/GPXParser.java b/src/cgeo/geocaching/files/GPXParser.java index 0719621..101d68b 100644 --- a/src/cgeo/geocaching/files/GPXParser.java +++ b/src/cgeo/geocaching/files/GPXParser.java @@ -48,6 +48,8 @@ public abstract class GPXParser extends FileParser { "http://www.groundspeak.com/cache/1/0", // PQ 1.0 }; + private static final String GSAK_NS = "http://www.gsak.net/xmlv1/5"; + private static cgeoapplication app = null; private int listId = 1; private cgSearch search = null; @@ -64,6 +66,20 @@ public abstract class GPXParser extends FileParser { private String name = null; private String cmt = null; private String desc = null; + protected String[] userData = new String[5]; // take 5 cells, that makes indexing 1..4 easier + + private final class UserDataListener implements EndTextElementListener { + private int index; + + public UserDataListener(int index) { + this.index = index; + } + + @Override + public void end(String user) { + userData[index] = validate(user); + } + } private static final class CacheAttributeTranslator { // List of cache attributes matching IDs used in GPX files. @@ -243,19 +259,25 @@ public abstract class GPXParser extends FileParser { cache.reason = listId; cache.detailed = true; + if (StringUtils.isBlank(cache.personalNote)) { + StringBuilder buffer = new StringBuilder(); + for (int i = 0; i < userData.length; i++) { + if (StringUtils.isNotBlank(userData[i])) { + buffer.append(' ').append(userData[i]); + } + } + String note = buffer.toString().trim(); + if (StringUtils.isNotBlank(note)) { + cache.personalNote = note; + } + } + app.addCacheToSearch(search, cache); } showFinishedMessage(handler, search); - type = null; - sym = null; - name = null; - desc = null; - cmt = null; - - cache = null; - cache = new cgCache(); + resetCache(); } }); @@ -353,6 +375,24 @@ public abstract class GPXParser extends FileParser { // for GPX 1.1 from extensions node final Element cacheParent = getCacheParent(waypoint); + + // GSAK extensions + final Element gsak = cacheParent.getChild(GSAK_NS, "wptExtension"); + gsak.getChild(GSAK_NS, "Watch").setEndTextElementListener(new EndTextElementListener() { + + @Override + public void end(String watchList) { + cache.onWatchlist = Boolean.valueOf(watchList.trim()); + } + }); + + gsak.getChild(GSAK_NS, "UserData").setEndTextElementListener(new UserDataListener(1)); + + for (int i = 2; i <= 4; i++) { + gsak.getChild(GSAK_NS, "User" + i).setEndTextElementListener(new UserDataListener(i)); + } + + // 3 different versions of the GC schema for (String nsGC : nsGCList) { // waypoints.cache final Element gcCache = cacheParent.getChild(nsGC, "cache"); @@ -720,6 +760,19 @@ public abstract class GPXParser extends FileParser { } } + private void resetCache() { + type = null; + sym = null; + name = null; + desc = null; + cmt = null; + + cache = new cgCache(); + for (int i = 0; i < userData.length; i++) { + userData[i] = null; + } + } + public static UUID parseGPX(cgeoapplication app, File file, int listId, Handler handler) { final cgSearch search = new cgSearch(); UUID searchId = null; diff --git a/src/cgeo/geocaching/geopoint/Geopoint.java b/src/cgeo/geocaching/geopoint/Geopoint.java index 85149be..44aadcc 100644 --- a/src/cgeo/geocaching/geopoint/Geopoint.java +++ b/src/cgeo/geocaching/geopoint/Geopoint.java @@ -14,15 +14,6 @@ public class Geopoint private double longitude; /** - * Creates new Geopoint with latitude and longitude set to 0. - */ - public Geopoint() - { - setLatitude(0); - setLongitude(0); - } - - /** * Creates new Geopoint with given latitude and longitude (both degree). * * @param lat latitude @@ -33,6 +24,18 @@ public class Geopoint setLatitude(lat); setLongitude(lon); } + + /** + * Creates new Geopoint with given latitude and longitude (both microdegree). + * + * @param lat latitude + * @param lon longitude + */ + public Geopoint(final int lat, final int lon) + { + setLatitude(lat * 1E-6); + setLongitude(lon * 1E-6); + } /** * Creates new Geopoint with latitude and longitude parsed from string. @@ -63,7 +66,7 @@ public class Geopoint * @return this * @throws MalformedCoordinateException if not -90 <= lat <= 90 */ - public Geopoint setLatitude(final double lat) + private void setLatitude(final double lat) { if (lat <= 90 && lat >= -90) { @@ -73,35 +76,6 @@ public class Geopoint { throw new MalformedCoordinateException("malformed latitude: " + lat); } - - return this; - } - - /** - * Set latitude in microdegree. - * - * @param lat latitude - * @return this - * @see setLatitude(final double lat) - * @throws MalformedCoordinateException if not -90 <= (lat * 1E-6) <= 90 - */ - public Geopoint setLatitudeE6(final int lat) - { - return setLatitude(lat * 1E-6); - } - - /** - * Set latitude by parsing string. - * - * @param lat latitude - * @return this - * @see setLatitude(final double lat) - * @throws ParseException if lat could not be parsed - * @throws MalformedCoordinateException if not -90 <= lat <= 90 - */ - public Geopoint setLatitude(final String lat) - { - return setLatitude(GeopointParser.parseLatitude(lat)); } /** @@ -131,7 +105,7 @@ public class Geopoint * @return this * @throws MalformedCoordinateException if not -180 <= lon <= 180 */ - public Geopoint setLongitude(final double lon) + private void setLongitude(final double lon) { if (lon <= 180 && lon >=-180) { @@ -141,35 +115,6 @@ public class Geopoint { throw new MalformedCoordinateException("malformed longitude: " + lon); } - - return this; - } - - /** - * Set longitude in microdegree. - * - * @param lon longitude - * @return this - * @see setLongitude(final double lon) - * @throws MalformedCoordinateException if not -180 <= (lon * 1E-6) <= 180 - */ - public Geopoint setLongitudeE6(final int lon) - { - return setLongitude(lon * 1E-6); - } - - /** - * Set longitude by parsing string. - * - * @param lon longitude - * @return this - * @see setLongitude(final double lon) - * @throws ParseException if lon could not be parsed - * @throws MalformedCoordinateException if not -180 <= lon <= 180 - */ - public Geopoint setLongitude(final String lon) - { - return setLongitude(GeopointParser.parseLongitude(lon)); } /** @@ -243,25 +188,11 @@ public class Geopoint } else if (ilat1 == ilat2) { - if (ilon1 > ilon2) - { - return 270; - } - else - { - return 90; - } + return (ilon1 > ilon2) ? 270 : 90; } else if (ilon1 == ilon2) { - if (ilat1 > ilat2) - { - return 180; - } - else - { - return 0; - } + return (ilat1 > ilat2) ? 180: 0; } else { diff --git a/src/cgeo/geocaching/mapcommon/cgeomap.java b/src/cgeo/geocaching/mapcommon/cgeomap.java index c9fb60b..2798a61 100644 --- a/src/cgeo/geocaching/mapcommon/cgeomap.java +++ b/src/cgeo/geocaching/mapcommon/cgeomap.java @@ -7,6 +7,8 @@ import java.util.Locale; import java.util.Map; import java.util.UUID; +import org.apache.commons.lang3.StringUtils; + import android.app.Activity; import android.app.ProgressDialog; import android.content.Context; @@ -24,7 +26,11 @@ import android.view.MenuItem; import android.view.SubMenu; import android.view.View; import android.view.WindowManager; +import android.view.ViewGroup.LayoutParams; +import android.widget.ImageSwitcher; import android.widget.ImageView; +import android.widget.ImageView.ScaleType; +import android.widget.ViewSwitcher.ViewFactory; import cgeo.geocaching.R; import cgeo.geocaching.cgBase; import cgeo.geocaching.cgCache; @@ -32,13 +38,13 @@ import cgeo.geocaching.cgCoord; import cgeo.geocaching.cgDirection; import cgeo.geocaching.cgGeo; import cgeo.geocaching.cgSettings; -import cgeo.geocaching.cgSettings.mapSourceEnum; import cgeo.geocaching.cgUpdateDir; import cgeo.geocaching.cgUpdateLoc; import cgeo.geocaching.cgUser; import cgeo.geocaching.cgWaypoint; import cgeo.geocaching.cgeoapplication; import cgeo.geocaching.activity.ActivityMixin; +import cgeo.geocaching.cgSettings.mapSourceEnum; import cgeo.geocaching.mapinterfaces.ActivityImpl; import cgeo.geocaching.mapinterfaces.CacheOverlayItemImpl; import cgeo.geocaching.mapinterfaces.GeoPointImpl; @@ -48,7 +54,7 @@ import cgeo.geocaching.mapinterfaces.MapViewImpl; import cgeo.geocaching.mapinterfaces.OnDragListener; import cgeo.geocaching.mapinterfaces.UserOverlayItemImpl; -public class cgeomap extends MapBase implements OnDragListener { +public class cgeomap extends MapBase implements OnDragListener, ViewFactory { private static final int MENU_SELECT_MAPVIEW = 1; private static final int MENU_MAP_LIVE = 2; @@ -126,7 +132,7 @@ public class cgeomap extends MapBase implements OnDragListener { private int detailProgress = 0; private Long detailProgressTime = 0L; // views - private ImageView myLocSwitch = null; + private ImageSwitcher myLocSwitch = null; // other things private boolean live = true; // live map (live, dead) or rest (displaying caches on map) private boolean liveChanged = false; // previous state for loadTimer @@ -344,8 +350,14 @@ public class cgeomap extends MapBase implements OnDragListener { centerMap(geocodeIntent, searchIdIntent, latitudeIntent, longitudeIntent, mapStateIntent); } + // prepare my location button + myLocSwitch = (ImageSwitcher) activity.findViewById(R.id.my_position); + myLocSwitch.setFactory(this); + myLocSwitch.setInAnimation(activity, android.R.anim.fade_in); + myLocSwitch.setOutAnimation(activity, android.R.anim.fade_out); + myLocSwitch.setOnClickListener(new MyLocationListener()); + switchMyLocationButton(); - setMyLoc(null); startTimer(); } @@ -1064,7 +1076,7 @@ public class cgeomap extends MapBase implements OnDragListener { // stage 1 - pull and render from the DB only - if (fromDetailIntent) { + if (fromDetailIntent || StringUtils.isNotEmpty(searchIdIntent)) { searchId = UUID.fromString(searchIdIntent); } else { if (!live || settings.maplive == 0) { @@ -1657,7 +1669,7 @@ public class cgeomap extends MapBase implements OnDragListener { if (geocodeCenter != null) { viewport = app.getBounds(geocodeCenter); } else { - viewport = app.getBounds(searchIdCenter); + viewport = app.getBounds(UUID.fromString(searchIdCenter)); } if (viewport == null) return; @@ -1724,46 +1736,20 @@ public class cgeomap extends MapBase implements OnDragListener { } // switch My Location button image - private void setMyLoc(Boolean status) { - if (myLocSwitch == null) { - myLocSwitch = (ImageView) activity.findViewById(R.id.my_position); - } - - if (status == null) { - if (followMyLocation) { - myLocSwitch.setImageResource(R.drawable.actionbar_mylocation_on); - } else { - myLocSwitch.setImageResource(R.drawable.actionbar_mylocation_off); - } + private void switchMyLocationButton() { + if (followMyLocation) { + myLocSwitch.setImageResource(R.drawable.actionbar_mylocation_on); + myLocationInMiddle(); } else { - if (status) { - myLocSwitch.setImageResource(R.drawable.actionbar_mylocation_on); - } else { - myLocSwitch.setImageResource(R.drawable.actionbar_mylocation_off); - } + myLocSwitch.setImageResource(R.drawable.actionbar_mylocation_off); } - - myLocSwitch.setOnClickListener(new MyLocationListener()); } // set my location listener private class MyLocationListener implements View.OnClickListener { - public void onClick(View view) { - if (myLocSwitch == null) { - myLocSwitch = (ImageView) activity.findViewById(R.id.my_position); - } - - if (followMyLocation) { - followMyLocation = false; - - myLocSwitch.setImageResource(R.drawable.actionbar_mylocation_off); - } else { - followMyLocation = true; - myLocationInMiddle(); - - myLocSwitch.setImageResource(R.drawable.actionbar_mylocation_on); - } + followMyLocation = !followMyLocation; + switchMyLocationButton(); } } @@ -1771,7 +1757,7 @@ public class cgeomap extends MapBase implements OnDragListener { public void onDrag() { if (followMyLocation) { followMyLocation = false; - myLocSwitch.setImageResource(R.drawable.actionbar_mylocation_off); + switchMyLocationButton(); } } @@ -1789,4 +1775,12 @@ public class cgeomap extends MapBase implements OnDragListener { public void goManual(View view) { ActivityMixin.goManual(activity, "c:geo-live-map"); } + + @Override + public View makeView() { + ImageView imageView = new ImageView(activity); + imageView.setScaleType(ScaleType.CENTER); + imageView.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); + return imageView; + } } |
