mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-18 03:52:11 +01:00
Android Map widget tests
gitignore eclipse .metadata
This commit is contained in:
parent
c60a750d96
commit
1823135573
1
.gitignore
vendored
1
.gitignore
vendored
@ -52,3 +52,4 @@ openpilotgcs-build-desktop
|
||||
/androidgcs/gen/
|
||||
/.cproject
|
||||
/.project
|
||||
/.metadata
|
||||
|
38
androidgcs/res/layout/mycustommapview.xml
Normal file
38
androidgcs/res/layout/mycustommapview.xml
Normal file
@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
>
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
>
|
||||
<TextView
|
||||
android:id="@+id/longitude"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:text="@string/longitude"
|
||||
/>
|
||||
<TextView
|
||||
android:id="@+id/latitude"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:text="@string/latitude"
|
||||
/>
|
||||
<TextView
|
||||
android:id="@+id/altitude"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:text="@string/altitude"
|
||||
/>
|
||||
</LinearLayout>
|
||||
<org.openpilot.androidgcs.MyCustomMapView
|
||||
android:id="@+id/mapview"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:clickable="true"
|
||||
android:apiKey="098Goj3psJ2Vg_lGi2v0pRWf4mqxjBvh2FI4frg"
|
||||
/>
|
||||
</LinearLayout>
|
9
androidgcs/res/menu/map_menu.xml
Normal file
9
androidgcs/res/menu/map_menu.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
<item android:id="@+id/poi1" android:title="Set POI"></item>
|
||||
<item android:id="@+id/poi2" android:title="Set FollowMe POI"></item>
|
||||
<item android:id="@+id/view1" android:title="View Satellite images"></item>
|
||||
<item android:id="@+id/view2" android:title="View Map"></item>
|
||||
|
||||
|
||||
</menu>
|
@ -32,6 +32,9 @@
|
||||
<string name="alarms">Alarms</string>
|
||||
<string name="txrate">TxRate: </string>
|
||||
<string name="rxrate">RxRate: </string>
|
||||
<string name="latitude">Latitude:</string>
|
||||
<string name="longitude">Longitude:</string>
|
||||
<string name="altitude">Altitude:</string>
|
||||
<string name="tester">Tester</string>
|
||||
<string name="_3dview">3DView</string>
|
||||
<string name="tuning">Tuning</string>
|
||||
|
@ -66,12 +66,14 @@ public class Controller extends ObjectManagerActivity {
|
||||
private boolean leftJoystickHeld, rightJoystickHeld;
|
||||
|
||||
Timer sendTimer = new Timer();
|
||||
|
||||
TextView manualView;
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.controller);
|
||||
manualView = (TextView) findViewById(R.id.manualControlValues);
|
||||
}
|
||||
|
||||
Observer settingsUpdated = new Observer() {
|
||||
|
121
androidgcs/src/org/openpilot/androidgcs/MyCustomMapView.java
Normal file
121
androidgcs/src/org/openpilot/androidgcs/MyCustomMapView.java
Normal file
@ -0,0 +1,121 @@
|
||||
package org.openpilot.androidgcs;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import com.google.android.maps.GeoPoint;
|
||||
import com.google.android.maps.MapView;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
public class MyCustomMapView extends MapView {
|
||||
|
||||
// Define the interface we will interact with from our Map
|
||||
public interface OnLongpressListener {
|
||||
public void onLongpress(MapView view, GeoPoint longpressLocation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Time in ms before the OnLongpressListener is triggered.
|
||||
*/
|
||||
static final int LONGPRESS_THRESHOLD = 500;
|
||||
|
||||
/**
|
||||
* Keep a record of the center of the map, to know if the map
|
||||
* has been panned.
|
||||
*/
|
||||
private GeoPoint lastMapCenter;
|
||||
|
||||
private Timer longpressTimer = new Timer();
|
||||
private MyCustomMapView.OnLongpressListener longpressListener;
|
||||
|
||||
|
||||
public MyCustomMapView(Context context, String apiKey) {
|
||||
super(context, apiKey);
|
||||
}
|
||||
|
||||
public MyCustomMapView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public MyCustomMapView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
}
|
||||
|
||||
public void setOnLongpressListener(MyCustomMapView.OnLongpressListener listener) {
|
||||
longpressListener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called every time user touches the map,
|
||||
* drags a finger on the map, or removes finger from the map.
|
||||
*/
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
handleLongpress(event);
|
||||
|
||||
return super.onTouchEvent(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method takes MotionEvents and decides whether or not
|
||||
* a longpress has been detected. This is the meat of the
|
||||
* OnLongpressListener.
|
||||
*
|
||||
* The Timer class executes a TimerTask after a given time,
|
||||
* and we start the timer when a finger touches the screen.
|
||||
*
|
||||
* We then listen for map movements or the finger being
|
||||
* removed from the screen. If any of these events occur
|
||||
* before the TimerTask is executed, it gets cancelled. Else
|
||||
* the listener is fired.
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
private void handleLongpress(final MotionEvent event) {
|
||||
|
||||
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
// Finger has touched screen.
|
||||
longpressTimer = new Timer();
|
||||
longpressTimer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
GeoPoint longpressLocation = getProjection().fromPixels((int)event.getX(),
|
||||
(int)event.getY());
|
||||
|
||||
/*
|
||||
* Fire the listener. We pass the map location
|
||||
* of the longpress as well, in case it is needed
|
||||
* by the caller.
|
||||
*/
|
||||
longpressListener.onLongpress(MyCustomMapView.this, longpressLocation);
|
||||
}
|
||||
|
||||
}, LONGPRESS_THRESHOLD);
|
||||
|
||||
lastMapCenter = getMapCenter();
|
||||
}
|
||||
|
||||
if (event.getAction() == MotionEvent.ACTION_MOVE) {
|
||||
|
||||
if (!getMapCenter().equals(lastMapCenter)) {
|
||||
// User is panning the map, this is no longpress
|
||||
longpressTimer.cancel();
|
||||
}
|
||||
|
||||
lastMapCenter = getMapCenter();
|
||||
}
|
||||
|
||||
if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||
// User has removed finger from map.
|
||||
longpressTimer.cancel();
|
||||
}
|
||||
|
||||
if (event.getPointerCount() > 1) {
|
||||
// This is a multitouch event, probably zooming.
|
||||
longpressTimer.cancel();
|
||||
}
|
||||
}
|
||||
}
|
@ -49,13 +49,22 @@ import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Point;
|
||||
import android.location.Location;
|
||||
import android.location.LocationListener;
|
||||
import android.location.LocationManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.ContextMenu.ContextMenuInfo;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.android.maps.GeoPoint;
|
||||
import com.google.android.maps.MapActivity;
|
||||
@ -72,9 +81,11 @@ public class UAVLocation extends MapActivity
|
||||
// private static boolean WARN = LOGLEVEL > 1;
|
||||
private static boolean DEBUG = LOGLEVEL > 0;
|
||||
|
||||
private MapView mapView;
|
||||
//private MapView mapView;
|
||||
private MyCustomMapView mapView;
|
||||
private MapController mapController;
|
||||
|
||||
private GeoPoint mContextMenuGeoPoint = null;
|
||||
|
||||
UAVObjectManager objMngr;
|
||||
boolean mBound = false;
|
||||
boolean mConnected = false;
|
||||
@ -84,23 +95,37 @@ public class UAVLocation extends MapActivity
|
||||
GeoPoint homeLocation;
|
||||
GeoPoint uavLocation;
|
||||
|
||||
boolean towerEnabled;
|
||||
boolean gpsEnabled;
|
||||
|
||||
LocationManager gpsLocationManager;
|
||||
LocationManager towerLocationManager;
|
||||
MyLocationListener gpsLocationListener;
|
||||
MyLocationListener towerLocationListener;
|
||||
private TextView myLongitude, myLatitude, myAltitude;
|
||||
|
||||
@Override public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
setContentView(R.layout.map_layout);
|
||||
mapView = (MapView)findViewById(R.id.map_view);
|
||||
super.onCreate(icicle);
|
||||
setContentView(R.layout.mycustommapview);
|
||||
mapView = (MyCustomMapView)findViewById(R.id.mapview);
|
||||
mapController = mapView.getController();
|
||||
registerForContextMenu(mapView);
|
||||
|
||||
mapView.displayZoomControls(true);
|
||||
Double lat = 37.422006*1E6;
|
||||
Double lng = -122.084095*1E6;
|
||||
homeLocation = new GeoPoint(lat.intValue(), lng.intValue());
|
||||
uavLocation = homeLocation;
|
||||
mapController.setCenter(homeLocation);
|
||||
mapController.setZoom(18);
|
||||
//mapController.setCenter(homeLocation);
|
||||
mapController.setZoom(16);
|
||||
|
||||
List<Overlay> overlays = mapView.getOverlays();
|
||||
UAVOverlay myOverlay = new UAVOverlay();
|
||||
overlays.add(myOverlay);
|
||||
|
||||
myLongitude = (TextView)findViewById(R.id.longitude);
|
||||
myLatitude = (TextView)findViewById(R.id.latitude);
|
||||
myAltitude = (TextView)findViewById(R.id.altitude);
|
||||
|
||||
MyLocationOverlay myLocationOverlay = new MyLocationOverlay(this, mapView);
|
||||
myLocationOverlay.enableMyLocation();
|
||||
@ -108,15 +133,159 @@ public class UAVLocation extends MapActivity
|
||||
overlays.add(myLocationOverlay);
|
||||
|
||||
mapView.postInvalidate();
|
||||
gpsLocationListener = new MyLocationListener();
|
||||
towerLocationListener = new MyLocationListener();
|
||||
gpsLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
|
||||
towerLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
|
||||
|
||||
CheckTowerAndGpsStatus();
|
||||
if(gpsEnabled)
|
||||
{
|
||||
gpsLocationManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, gpsLocationListener);
|
||||
|
||||
//Get the current location in start-up
|
||||
Location last = gpsLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
|
||||
if(last != null)
|
||||
{
|
||||
GeoPoint initGeoPoint = new GeoPoint(
|
||||
(int)(last.getLatitude()*1000000),
|
||||
(int)(last.getLongitude()*1000000));
|
||||
CenterLocation(initGeoPoint,(last.getAltitude()));
|
||||
}
|
||||
}
|
||||
mapView.setOnLongpressListener(new MyCustomMapView.OnLongpressListener() {
|
||||
public void onLongpress(final MapView view, final GeoPoint longpressLocation) {
|
||||
mContextMenuGeoPoint = longpressLocation;
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
// Insert your longpress action here
|
||||
//Toast.makeText(mapView.getContext(), "You pressed here: Lat:", Toast.LENGTH_LONG).show();
|
||||
openContextMenu(view);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void CenterLocation(GeoPoint centerGeoPoint, double Altitude)
|
||||
{
|
||||
mapController.animateTo(centerGeoPoint);
|
||||
|
||||
|
||||
myLongitude.setText("Longitude: "+
|
||||
String.valueOf((float)centerGeoPoint.getLongitudeE6()/1000000)
|
||||
);
|
||||
myLatitude.setText("Latitude: "+
|
||||
String.valueOf((float)centerGeoPoint.getLatitudeE6()/1000000)
|
||||
);
|
||||
myAltitude.setText("Altitude: "+
|
||||
String.valueOf(Altitude)
|
||||
);
|
||||
};
|
||||
|
||||
private void CheckTowerAndGpsStatus() {
|
||||
towerEnabled = towerLocationManager
|
||||
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
|
||||
gpsEnabled = gpsLocationManager
|
||||
.isProviderEnabled(LocationManager.GPS_PROVIDER);
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
|
||||
@Override
|
||||
protected boolean isRouteDisplayed() {
|
||||
// IMPORTANT: This method must return true if your Activity // is displaying driving directions. Otherwise return false.
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View v,
|
||||
ContextMenuInfo menuInfo) {
|
||||
super.onCreateContextMenu(menu, v, menuInfo);
|
||||
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.map_menu, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onContextItemSelected(MenuItem item) {
|
||||
int lat = mContextMenuGeoPoint.getLatitudeE6();
|
||||
int lon = mContextMenuGeoPoint.getLongitudeE6();
|
||||
switch (item.getItemId()) {
|
||||
case R.id.poi1:
|
||||
|
||||
return true;
|
||||
case R.id.poi2:
|
||||
Toast.makeText(mapView.getContext(), "You pressed here: Lat:" + lat/1000000.0 + " Lon:" + lon/1000000.0, Toast.LENGTH_LONG).show();
|
||||
return true;
|
||||
case R.id.view1:
|
||||
mapView.setSatellite(true);
|
||||
mapView.invalidate();
|
||||
return true;
|
||||
case R.id.view2:
|
||||
mapView.setSatellite(false);
|
||||
mapView.invalidate();
|
||||
return true;
|
||||
default:
|
||||
return super.onContextItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Class My Location Listener */
|
||||
|
||||
public class MyLocationListener implements LocationListener
|
||||
{
|
||||
@Override
|
||||
public void onLocationChanged(Location loc)
|
||||
{
|
||||
GeoPoint myGeoPoint = new GeoPoint(
|
||||
(int)(loc.getLatitude()*1000000),
|
||||
(int)(loc.getLongitude()*1000000));
|
||||
|
||||
CenterLocation(myGeoPoint,loc.getAltitude());
|
||||
}
|
||||
@Override
|
||||
public void onProviderDisabled(String provider)
|
||||
{
|
||||
Toast.makeText( getApplicationContext(),
|
||||
"Gps Disabled",
|
||||
Toast.LENGTH_SHORT ).show();
|
||||
}
|
||||
@Override
|
||||
public void onProviderEnabled(String provider)
|
||||
{
|
||||
Toast.makeText( getApplicationContext(),
|
||||
"Gps Enabled",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStatusChanged(String provider, int status, Bundle extras)
|
||||
{
|
||||
}
|
||||
}/* End of Class MyLocationListener */
|
||||
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
switch (keyCode) {
|
||||
case KeyEvent.KEYCODE_DPAD_UP:
|
||||
mapController.zoomIn();
|
||||
break;
|
||||
case KeyEvent.KEYCODE_DPAD_DOWN:
|
||||
mapController.zoomOut();
|
||||
break;
|
||||
case KeyEvent.KEYCODE_DPAD_LEFT:
|
||||
mapController.setZoom(17);
|
||||
mapView.setSatellite(true);
|
||||
mapView.invalidate();
|
||||
break;
|
||||
case KeyEvent.KEYCODE_DPAD_RIGHT:
|
||||
mapController.setZoom(17);
|
||||
mapView.setSatellite(false);
|
||||
mapView.invalidate();
|
||||
break;
|
||||
|
||||
}
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
public class UAVOverlay extends Overlay {
|
||||
Bitmap homeSymbol = BitmapFactory.decodeResource(getResources(), R.drawable.ic_home);
|
||||
|
Loading…
x
Reference in New Issue
Block a user