platform/android/Rhodes/src/com/rhomobile/rhodes/mapview/GoogleMapView.java in rhodes-3.1.1 vs platform/android/Rhodes/src/com/rhomobile/rhodes/mapview/GoogleMapView.java in rhodes-3.2.0.beta.1
- old
+ new
@@ -33,23 +33,29 @@
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
+import android.content.res.Configuration;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.os.IBinder;
+import android.view.Display;
import android.view.ViewGroup.LayoutParams;
import android.widget.RelativeLayout;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
+import com.google.android.maps.MyLocationOverlay;
import com.rhomobile.rhodes.AndroidR;
import com.rhomobile.rhodes.Logger;
+import com.rhomobile.rhodes.RhoConf;
import com.rhomobile.rhodes.RhodesActivity;
import com.rhomobile.rhodes.RhodesService;
import com.rhomobile.rhodes.util.PerformOnUiThread;
import com.rhomobile.rhodes.util.Utils;
@@ -64,18 +70,21 @@
private ServiceConnection mServiceConnection = null;
private com.google.android.maps.MapView view;
private AnnotationsOverlay annOverlay;
+ private CalloutOverlay mCalloutOverlay;
+ private MyLocationOverlay mMyLocationOverlay;
private double spanLat = 0;
private double spanLon = 0;
private String apiKey;
private Vector<Annotation> annotations;
+ private int mRuntimeOrientation;
static private ExtrasHolder mHolder = null;
private static class Coordinates {
public double latitude;
@@ -101,10 +110,41 @@
}
super.onDestroy();
mc = null;
}
+ public void selectAnnotation(Annotation ann) {
+ final Annotation fann = ann;
+ PerformOnUiThread.exec(new Runnable() {
+ public void run() {
+ mCalloutOverlay.selectAnnotation(fann);
+ }
+ }, false);
+ }
+
+ protected int getScreenOrientation() {
+ Display display = getWindowManager().getDefaultDisplay();
+ int orientation = display.getOrientation();
+
+ if (orientation == Configuration.ORIENTATION_UNDEFINED)
+ {
+ orientation = getResources().getConfiguration().orientation;
+
+ if (orientation == Configuration.ORIENTATION_UNDEFINED) {
+ if (display.getWidth() == display.getHeight())
+ orientation = Configuration.ORIENTATION_SQUARE;
+ else if(display.getWidth() < display.getHeight())
+ orientation = Configuration.ORIENTATION_PORTRAIT;
+ else
+ orientation = Configuration.ORIENTATION_LANDSCAPE;
+ }
+ }
+ return orientation;
+ }
+
+
+
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
Intent intent = new Intent(this, RhodesService.class);
@@ -135,11 +175,11 @@
if (map_type == null)
map_type = "roadmap";
boolean zoom_enabled = extras.getBoolean(SETTINGS_PREFIX + "zoom_enabled");
//boolean scroll_enabled = extras.getBoolean(SETTINGS_PREFIX + "scroll_enabled");
- //boolean shows_user_location = extras.getBoolean(SETTINGS_PREFIX + "shows_user_location");
+ boolean shows_user_location = extras.getBoolean(SETTINGS_PREFIX + "shows_user_location");
// Extract annotations
int size = extras.getInt(ANNOTATIONS_PREFIX + "size") + 1;
annotations = new Vector<Annotation>(size);
for (int i = 0; i < size; ++i) {
@@ -170,23 +210,40 @@
ann.title = extras.getString(prefix + "title");
ann.subtitle = extras.getString(prefix + "subtitle");
ann.url = extras.getString(prefix + "url");
if (ann.url != null)
ann.url = RhodesService.getInstance().normalizeUrl(ann.url);
+
+ ann.image = extras.getString(prefix+"image");
+ ann.image_x_offset = extras.getInt(prefix + "image_x_offset");
+ ann.image_y_offset = extras.getInt(prefix + "image_y_offset");
+
annotations.addElement(ann);
}
// Create view
view = new com.google.android.maps.MapView(this, apiKey);
view.setClickable(true);
layout.addView(view);
+ Bitmap pin = BitmapFactory.decodeResource(getResources(), AndroidR.drawable.marker);
+
Drawable marker = getResources().getDrawable(AndroidR.drawable.marker);
marker.setBounds(0, 0, marker.getIntrinsicWidth(), marker.getIntrinsicHeight());
- annOverlay = new AnnotationsOverlay(this, marker);
+ annOverlay = new AnnotationsOverlay(this, marker, pin.getDensity());
+
+ mCalloutOverlay = new CalloutOverlay(this, marker);
+
+ if (shows_user_location) {
+ mMyLocationOverlay = new MyLocationOverlay(this, view);
+ view.getOverlays().add(mMyLocationOverlay);
+ }
+
view.getOverlays().add(annOverlay);
+ view.getOverlays().add(mCalloutOverlay);
+
// Apply extracted parameters
view.setBuiltInZoomControls(zoom_enabled);
view.setSatellite(map_type.equals("hybrid") || map_type.equals("satellite"));
view.setTraffic(false);
@@ -238,29 +295,66 @@
Logger.E(TAG, "Wrong region radius: " + e.getMessage());
}
}
}
- mHolder.clear();
+ //mHolder.clear();
view.preLoad();
Thread geocoding = new Thread(new Runnable() {
public void run() {
doGeocoding();
}
});
geocoding.start();
+
+ mRuntimeOrientation = this.getScreenOrientation();
+
}
@Override
+ public void onConfigurationChanged(Configuration newConfig) {
+ Logger.T(TAG, "+++ onConfigurationChanged");
+ if (RhoConf.getBool("disable_screen_rotation"))
+ {
+ super.onConfigurationChanged(newConfig);
+ this.setRequestedOrientation(mRuntimeOrientation);
+ }
+ else
+ {
+ mRuntimeOrientation = this.getScreenOrientation();
+ super.onConfigurationChanged(newConfig);
+ RhodesService.getInstance().rereadScreenProperties();
+ }
+ }
+
+
+
+ @Override
protected void onStart() {
super.onStart();
RhodesService.activityStarted();
}
@Override
+ protected void onResume() {
+ super.onResume();
+ if (mMyLocationOverlay != null)
+ mMyLocationOverlay.enableMyLocation();
+
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ if (mMyLocationOverlay != null)
+ mMyLocationOverlay.disableMyLocation();
+
+ }
+
+ @Override
protected void onStop() {
RhodesService.activityStopped();
super.onStop();
}
@@ -445,9 +539,21 @@
intent.putExtra(prefix + "subtitle", (String)subtitle);
Object url = ann.get("url");
if (url != null && (url instanceof String))
intent.putExtra(prefix + "url", (String)url);
+
+ Object image = ann.get("image");
+ if (image != null && (image instanceof String))
+ intent.putExtra(prefix + "image", (String)image);
+
+ Object image_x_offset = ann.get("image_x_offset");
+ if (image_x_offset != null && (image_x_offset instanceof String))
+ intent.putExtra(prefix + "image_x_offset", (String)image_x_offset);
+
+ Object image_y_offset = ann.get("image_y_offset");
+ if (image_y_offset != null && (image_y_offset instanceof String))
+ intent.putExtra(prefix + "image_y_offset", (String)image_y_offset);
}
}
RhodesService.getInstance().startActivity(intent_obj);
}