implement dialog go to point by location

git-svn-id: https://osmand.googlecode.com/svn/trunk@93 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-05-28 13:19:56 +00:00
parent 2136c74871
commit 2ec7068197
7 changed files with 204 additions and 3 deletions

View file

@ -131,9 +131,7 @@ public class MapTileDownloader {
public void refuseAllPreviousRequests(){ public void refuseAllPreviousRequests(){
while(!threadPoolExecutor.getQueue().isEmpty()){ threadPoolExecutor.getQueue().clear();
threadPoolExecutor.getQueue().remove();
}
} }
public void requestToDownload(DownloadRequest request){ public void requestToDownload(DownloadRequest request){

View file

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
<TextView android:id="@+id/TextView03" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:text="Input latitude &amp; longitude in the selected format (D - degrees, M - minutes, S - seconds)" android:layout_marginTop="10dp" android:layout_marginBottom="10dp"></TextView>
<LinearLayout android:id="@+id/LinearLayout01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal">
<TextView android:id="@+id/TextView01" android:layout_width="130dp" android:layout_height="wrap_content" android:text="Latitude" android:layout_marginLeft="5dp"></TextView>
<EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/LatitudeEdit" android:layout_marginRight="5dp" android:inputType="number|time"></EditText>
</LinearLayout>
<LinearLayout android:id="@+id/LinearLayout02" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal">
<TextView android:text="Longitude" android:id="@+id/TextView02" android:layout_width="130dp" android:layout_height="wrap_content" android:layout_marginLeft="5dp"></TextView>
<EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/LongitudeEdit" android:layout_marginRight="5dp" android:inputType="number|time"></EditText>
</LinearLayout>
<RadioGroup android:id="@+id/RadioGroup01" android:layout_marginLeft="5dp" android:layout_marginTop="5dp" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" >
<RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="DDD.DDD" android:id="@+id/Format1" ></RadioButton>
<RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/Format2" android:text="DDD:MM.MMM" ></RadioButton>
<RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/Format3" android:text="DDD:MM:SS.SSS"></RadioButton>
</RadioGroup>
<TextView android:id="@+id/ValidateTextView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="" android:gravity="center" android:textColor="@color/color_red"></TextView>
<LinearLayout android:id="@+id/LinearLayout02" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal"
android:gravity="bottom|center">
<Button android:layout_width="125dp" android:layout_height="wrap_content" android:text="Show on map" android:id="@+id/ShowOnMap"></Button>
<Button android:layout_width="125dp" android:layout_height="wrap_content" android:text="Cancel" android:id="@+id/Cancel"></Button>
</LinearLayout>
</LinearLayout>

View file

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
<TextView android:id="@+id/TextView03" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:text="Input latitude &amp; longitude in the selected format (D - degrees, M - minutes, S - seconds)" android:layout_marginTop="10dp" android:layout_marginBottom="10dp"></TextView>
<LinearLayout android:id="@+id/LinearLayout01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal">
<TextView android:id="@+id/TextView01" android:layout_width="130dp" android:layout_height="wrap_content" android:text="Latitude" android:layout_marginLeft="5dp"></TextView>
<EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/LatitudeEdit" android:layout_marginRight="5dp" android:inputType="number|time"></EditText>
</LinearLayout>
<LinearLayout android:id="@+id/LinearLayout02" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal">
<TextView android:text="Longitude" android:id="@+id/TextView02" android:layout_width="130dp" android:layout_height="wrap_content" android:layout_marginLeft="5dp"></TextView>
<EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/LongitudeEdit" android:layout_marginRight="5dp" android:inputType="number|time"></EditText>
</LinearLayout>
<RadioGroup android:id="@+id/RadioGroup01" android:layout_marginLeft="70dp" android:layout_marginTop="5dp" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical">
<RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="DDD.DDDDD" android:id="@+id/Format1" ></RadioButton>
<RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/Format2" android:text="DDD:MM.MMMMM" ></RadioButton>
<RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/Format3" android:text="DDD:MM:SS.SSSSS"></RadioButton>
</RadioGroup>
<TextView android:id="@+id/ValidateTextView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="" android:gravity="center" android:textColor="@color/color_red"></TextView>
<LinearLayout android:id="@+id/LinearLayout02" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal"
android:gravity="bottom|center">
<Button android:layout_width="125dp" android:layout_height="wrap_content" android:text="Show on map" android:id="@+id/ShowOnMap"></Button>
<Button android:layout_width="125dp" android:layout_height="wrap_content" android:text="Cancel" android:id="@+id/Cancel"></Button>
</LinearLayout>
</LinearLayout>

View file

@ -4,5 +4,6 @@
<group android:id="@+id/map_context_menu" android:menuCategory="container"><item android:id="@+id/map_show_settings" android:title="@string/settings_Button"></item> <group android:id="@+id/map_context_menu" android:menuCategory="container"><item android:id="@+id/map_show_settings" android:title="@string/settings_Button"></item>
<item android:id="@+id/map_show_location" android:title="@string/show_location"></item> <item android:id="@+id/map_show_location" android:title="@string/show_location"></item>
<item android:title="@string/navigate_to_point" android:id="@+id/map_navigate_to_point"></item> <item android:title="@string/navigate_to_point" android:id="@+id/map_navigate_to_point"></item>
<item android:title="@string/map_specify_point" android:id="@+id/map_specify_point"></item>
</group> </group>
</menu> </menu>

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string name="map_specify_point">Specify point</string>
<string name="show_view_angle_descr">Show aspect of vew based on compass</string> <string name="show_view_angle_descr">Show aspect of vew based on compass</string>
<string name="show_view_angle">Show aspect of view</string> <string name="show_view_angle">Show aspect of view</string>
<string name="stop_navigation">Unmark location</string> <string name="stop_navigation">Unmark location</string>
@ -29,4 +30,5 @@
<color name="menu_background">#CFFACD</color> <color name="menu_background">#CFFACD</color>
<string name="search_activity">search</string> <string name="search_activity">search</string>
<color name="color_white">#FFFFFF</color> <color name="color_white">#FFFFFF</color>
<color name="color_red">#FF0000</color>
</resources> </resources>

View file

@ -328,6 +328,9 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
final Intent settings = new Intent(MapActivity.this, SettingsActivity.class); final Intent settings = new Intent(MapActivity.this, SettingsActivity.class);
startActivity(settings); startActivity(settings);
return true; return true;
} else if (item.getItemId() == R.id.map_specify_point) {
openChangeLocationDialog();
return true;
} else if (item.getItemId() == R.id.map_navigate_to_point) { } else if (item.getItemId() == R.id.map_navigate_to_point) {
if(navigationLayer.getPointToNavigate() != null){ if(navigationLayer.getPointToNavigate() != null){
item.setTitle(R.string.navigate_to_point); item.setTitle(R.string.navigate_to_point);
@ -340,6 +343,11 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
private void openChangeLocationDialog() {
NavigatePointDialog dlg = new NavigatePointDialog(this, mapView);
dlg.showDialog();
}
@Override @Override
public void onAccuracyChanged(Sensor sensor, int accuracy) { public void onAccuracyChanged(Sensor sensor, int accuracy) {
} }

View file

@ -0,0 +1,129 @@
package com.osmand.activities;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Locale;
import android.app.Dialog;
import android.content.Context;
import android.location.Location;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import com.osmand.OsmandSettings;
import com.osmand.R;
import com.osmand.views.OsmandMapTileView;
public class NavigatePointDialog {
Dialog dlg;
OsmandMapTileView view;
int currentFormat = Location.FORMAT_DEGREES;
public NavigatePointDialog(Context ctx, OsmandMapTileView view){
this.view = view;
dlg = new Dialog(ctx);
initUI(view.getLatitude(), view.getLongitude());
}
public void initUI(double latitude, double longitude){
dlg.setContentView(R.layout.navigate_point);
dlg.setTitle("Navigate to point");
((TextView)dlg.findViewById(R.id.LatitudeEdit)).setText(convert(latitude, Location.FORMAT_DEGREES));
((TextView)dlg.findViewById(R.id.LongitudeEdit)).setText(convert(longitude, Location.FORMAT_DEGREES));
((RadioButton)dlg.findViewById(R.id.Format1)).setChecked(true);
((RadioGroup)dlg.findViewById(R.id.RadioGroup01)).setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener(){
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
int newFormat = currentFormat;
if(checkedId == R.id.Format1){
newFormat = Location.FORMAT_DEGREES;
} else if(checkedId == R.id.Format2){
newFormat = Location.FORMAT_MINUTES;
} else if(checkedId == R.id.Format3){
newFormat = Location.FORMAT_SECONDS;
}
try {
double lat = Location.convert(((TextView) dlg.findViewById(R.id.LatitudeEdit)).getText().toString());
double lon = Location.convert(((TextView) dlg.findViewById(R.id.LongitudeEdit)).getText().toString());
((TextView)dlg.findViewById(R.id.LatitudeEdit)).setText(convert(lat, newFormat));
((TextView)dlg.findViewById(R.id.LongitudeEdit)).setText(convert(lon, newFormat));
} catch (RuntimeException e) {
}
}
});
((Button) dlg.findViewById(R.id.Cancel)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dlg.dismiss();
}
});
((Button) dlg.findViewById(R.id.ShowOnMap)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
double lat = Location.convert(((TextView) dlg.findViewById(R.id.LatitudeEdit)).getText().toString());
double lon = Location.convert(((TextView) dlg.findViewById(R.id.LongitudeEdit)).getText().toString());
if(view != null) {
view.setLatLon(lat, lon);
} else {
OsmandSettings.setLastKnownMapLocation(dlg.getContext(), lat, lon);
}
dlg.dismiss();
} catch (RuntimeException e) {
((TextView) dlg.findViewById(R.id.ValidateTextView)).setText("Locations are invalid");
}
}
});
}
// THIS code is copied from Location.convert() in order to change locale
public static final int FORMAT_DEGREES = 0;
public static final int FORMAT_MINUTES = 1;
public static final int FORMAT_SECONDS = 2;
public static String convert(double coordinate, int outputType) {
if (coordinate < -180.0 || coordinate > 180.0 || Double.isNaN(coordinate)) {
throw new IllegalArgumentException("coordinate=" + coordinate);
}
if ((outputType != FORMAT_DEGREES) && (outputType != FORMAT_MINUTES) && (outputType != FORMAT_SECONDS)) {
throw new IllegalArgumentException("outputType=" + outputType);
}
StringBuilder sb = new StringBuilder();
// Handle negative values
if (coordinate < 0) {
sb.append('-');
coordinate = -coordinate;
}
DecimalFormat df = new DecimalFormat("###.#####", new DecimalFormatSymbols(Locale.US));
if (outputType == FORMAT_MINUTES || outputType == FORMAT_SECONDS) {
int degrees = (int) Math.floor(coordinate);
sb.append(degrees);
sb.append(':');
coordinate -= degrees;
coordinate *= 60.0;
if (outputType == FORMAT_SECONDS) {
int minutes = (int) Math.floor(coordinate);
sb.append(minutes);
sb.append(':');
coordinate -= minutes;
coordinate *= 60.0;
}
}
sb.append(df.format(coordinate));
return sb.toString();
}
public void showDialog(){
dlg.show();
}
}