Update maps

This commit is contained in:
Victor Shcherb 2015-03-14 20:10:22 +01:00
parent 5f83cd3b2c
commit 7ed68a48c8
15 changed files with 415 additions and 750 deletions

View file

@ -8,7 +8,6 @@
<!-- TOP ROW -->
<LinearLayout
android:id="@+id/WaypointVisit2"
android:layout_width="fill_parent"
android:layout_height="@dimen/map_address_height"
android:background="@drawable/btn_flat"
@ -33,10 +32,11 @@
android:maxLines="1"
android:shadowColor="@color/color_myloc_distance"
android:shadowRadius="10"
android:text="TEST Street name"
android:text="Long Street Name"
android:textColor="@color/color_black"
android:textSize="@dimen/map_widget_text_size"
android:textStyle="bold" >
android:textStyle="bold"
android:visibility="gone" >
</TextView>
<ImageButton
@ -68,10 +68,10 @@
android:weightSum="1" >
<LinearLayout
android:id="@+id/map_left_widgets_panel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="top|left"
android:id="@+id/map_left_widgets_panel"
android:layout_weight="0.4"
android:orientation="vertical" >
@ -118,7 +118,25 @@
android:layout_weight="0.6" >
</LinearLayout>
</LinearLayout>
<!-- CENTER TODO -->
<!-- CENTER -->
<LinearLayout
android:id="@+id/map_center_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|center"
android:background="@drawable/btn_round"
android:orientation="vertical"
>
<ProgressBar
android:id="@+id/map_horizontal_progress"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:max="100"
android:progress="60"
android:visibility="gone"/>
</LinearLayout>
<!-- RIGHT widgets colon -->
<LinearLayout
@ -149,11 +167,12 @@
android:layout_gravity="top|right"
android:orientation="vertical" >
<!--
<!--
<include layout="@layout/map_hud_widget" />
<include layout="@layout/map_hud_widget" />
<include layout="@layout/map_hud_widget" />
-->
-->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >

View file

@ -4,10 +4,10 @@
android:minWidth="100dp"
android:layout_height="wrap_content"
android:background="@drawable/btn_left_round"
android:orientation="vertical"
>
android:orientation="vertical">
<ImageButton
android:id="@+id/widget_top_icon"
android:layout_width="wrap_content"
android:layout_height="@dimen/map_widget_image"
android:layout_gravity="center"
@ -22,13 +22,16 @@
<ImageView
android:layout_width="@dimen/map_widget_icon"
android:layout_height="@dimen/map_widget_icon"
android:id="@+id/widget_icon"
android:gravity="center"
android:layout_gravity="left|center_vertical"
android:src="@drawable/ic_action_remove_light" />
android:src="@drawable/ic_action_remove_light"
android:visibility="invisible"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/widget_text"
android:layout_gravity="bottom"
android:layout_marginBottom="@dimen/map_widget_text_bottom_margin"
android:layout_weight="1"
@ -43,6 +46,7 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/widget_text_small"
android:layout_marginLeft="4dp"
android:layout_gravity="bottom"
android:layout_marginBottom="@dimen/map_widget_text_bottom_margin"

View file

@ -58,7 +58,6 @@ import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.media.AudioManager;
import android.net.Uri;
@ -67,16 +66,12 @@ import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewStub;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
@ -110,7 +105,6 @@ public class MapActivity extends AccessibleActivity {
private List<DialogProvider> dialogProviders = new ArrayList<DialogProvider>(2);
private StateChangedListener<ApplicationMode> applicationModeListener;
private FrameLayout lockView;
private GpxImportHelper gpxImportHelper;
private WakeLockHelper wakeLockHelper;
private boolean intentLocation = false;
@ -147,43 +141,7 @@ public class MapActivity extends AccessibleActivity {
}
dashboardOnMap.createDashboardView();
if (app.isApplicationInitializing() || DashboardOnMap.staticVisible) {
dashboardOnMap.setDashboardVisibility(true);
}
if (app.isApplicationInitializing()) {
findViewById(R.id.init_progress).setVisibility(View.VISIBLE);
initListener = new AppInitializeListener() {
boolean openGlSetup = false;
@Override
public void onProgress(AppInitializer init, InitEvents event) {
String tn = init.getCurrentInitTaskName();
if (tn != null) {
((TextView) findViewById(R.id.ProgressMessage)).setText(tn);
}
// if(event == InitEvents.NATIVE_INITIALIZED) {
// setupOpenGLView();
// openGlSetup = true;
// }
if(event == InitEvents.MAPS_INITIALIZED) {
mapView.refreshMap(true);
}
}
@Override
public void onFinish(AppInitializer init) {
if(!openGlSetup) {
setupOpenGLView();
}
mapView.refreshMap(true);
findViewById(R.id.init_progress).setVisibility(View.GONE);
findViewById(R.id.drawer_layout).invalidate();
}
};
getMyApplication().checkApplicationIsBeingInitialized(this, initListener);
} else {
setupOpenGLView();
}
checkAppInitialization();
parseLaunchIntentLocation();
OsmAndMapSurfaceView surf = (OsmAndMapSurfaceView) findViewById(R.id.MapView);
@ -231,19 +189,53 @@ public class MapActivity extends AccessibleActivity {
}
addDialogProvider(mapActions);
OsmandPlugin.onMapActivityCreate(this);
if (lockView != null) {
((FrameLayout) mapView.getParent()).addView(lockView);
}
gpxImportHelper = new GpxImportHelper(this, getMyApplication(), getMapView());
mapActions.prepareStartOptionsMenu();
wakeLockHelper = new WakeLockHelper(getMyApplication());
if(System.currentTimeMillis() - tm > 50) {
System.err.println("OnCreate for MapActivity took " + (System.currentTimeMillis() - tm) + " ms");
}
}
private void checkAppInitialization() {
if (app.isApplicationInitializing() || DashboardOnMap.staticVisible) {
dashboardOnMap.setDashboardVisibility(true);
}
if (app.isApplicationInitializing()) {
findViewById(R.id.init_progress).setVisibility(View.VISIBLE);
initListener = new AppInitializeListener() {
boolean openGlSetup = false;
@Override
public void onProgress(AppInitializer init, InitEvents event) {
String tn = init.getCurrentInitTaskName();
if (tn != null) {
((TextView) findViewById(R.id.ProgressMessage)).setText(tn);
}
if(event == InitEvents.NATIVE_INITIALIZED) {
setupOpenGLView();
openGlSetup = true;
}
if(event == InitEvents.MAPS_INITIALIZED) {
mapView.refreshMap(true);
}
}
@Override
public void onFinish(AppInitializer init) {
if(!openGlSetup) {
setupOpenGLView();
}
mapView.refreshMap(true);
findViewById(R.id.init_progress).setVisibility(View.GONE);
findViewById(R.id.drawer_layout).invalidate();
}
};
getMyApplication().checkApplicationIsBeingInitialized(this, initListener);
} else {
setupOpenGLView();
}
}
private void setupOpenGLView() {
if (settings.USE_OPENGL_RENDER.get() && NativeCoreContext.isInit()) {
@ -262,23 +254,8 @@ public class MapActivity extends AccessibleActivity {
}
}
public void addLockView(FrameLayout lockView) {
this.lockView = lockView;
}
private void createProgressBarForRouting() {
FrameLayout parent = (FrameLayout) mapView.getParent();
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL | Gravity.TOP);
DisplayMetrics dm = getResources().getDisplayMetrics();
params.topMargin = (int) (60 * dm.density);
final ProgressBar pb = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal);
pb.setIndeterminate(false);
pb.setMax(100);
pb.setLayoutParams(params);
pb.setVisibility(View.GONE);
parent.addView(pb);
final ProgressBar pb = (ProgressBar) findViewById(R.id.map_horizontal_progress);
app.getRoutingHelper().setProgressBar(new RouteCalculationProgressCallback() {
@Override

View file

@ -29,6 +29,7 @@ import net.osmand.util.OpeningHoursParser;
import net.osmand.util.OpeningHoursParser.BasicOpeningHourRule;
import net.osmand.util.OpeningHoursParser.OpeningHours;
import net.osmand.util.OpeningHoursParser.OpeningHoursRule;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
@ -58,7 +59,7 @@ import android.widget.Toast;
public class EditingPOIActivity implements DialogProvider {
private final MapActivity ctx;
private final Activity activity;
private final OpenstreetmapUtil openstreetmapUtil;
private final OpenstreetmapUtil openstreetmapUtilToLoad;
private AutoCompleteTextView typeText;
@ -94,20 +95,20 @@ public class EditingPOIActivity implements DialogProvider {
public EditingPOIActivity(MapActivity uiContext){
this.ctx = uiContext;
this.activity = uiContext;
poiTypes = uiContext.getMyApplication().getPoiTypes();
allTranslatedSubTypes = poiTypes.getAllTranslatedNames();
settings = ((OsmandApplication) uiContext.getApplication()).getSettings();
if (settings.OFFLINE_EDITION.get() || !settings.isInternetConnectionAvailable(true)) {
this.openstreetmapUtil = new OpenstreetmapLocalUtil(ctx);
this.openstreetmapUtil = new OpenstreetmapLocalUtil(activity);
if (settings.isInternetConnectionAvailable(true)) {
this.openstreetmapUtilToLoad = new OpenstreetmapRemoteUtil(ctx, ctx.getMapView().getView());
this.openstreetmapUtilToLoad = new OpenstreetmapRemoteUtil(activity);
} else {
this.openstreetmapUtilToLoad = openstreetmapUtil;
}
} else {
this.openstreetmapUtil = new OpenstreetmapRemoteUtil(ctx, ctx.getMapView().getView());
this.openstreetmapUtil = new OpenstreetmapRemoteUtil(activity);
this.openstreetmapUtilToLoad= openstreetmapUtil;
}
}
@ -124,7 +125,7 @@ public class EditingPOIActivity implements DialogProvider {
if(n != null){
showPOIDialog(DIALOG_EDIT_POI, n, editA.getType(), editA.getSubType());
} else {
AccessibleToast.makeText(ctx, ctx.getString(R.string.poi_error_poi_not_found), Toast.LENGTH_SHORT).show();
AccessibleToast.makeText(activity, activity.getString(R.string.poi_error_poi_not_found), Toast.LENGTH_SHORT).show();
}
};
@ -141,7 +142,7 @@ public class EditingPOIActivity implements DialogProvider {
Amenity a = EntityParser.parseAmenity(n, type, subType, null, MapRenderingTypes.getDefault());
dialogBundle.putSerializable(KEY_AMENITY, a);
dialogBundle.putSerializable(KEY_AMENITY_NODE, n);
ctx.showDialog(dialogID);
activity.showDialog(dialogID);
}
public void showDeleteDialog(final Amenity a){
@ -152,32 +153,32 @@ public class EditingPOIActivity implements DialogProvider {
protected void onPostExecute(Node n) {
if(n == null){
AccessibleToast.makeText(ctx, ctx.getResources().getString(R.string.poi_error_poi_not_found), Toast.LENGTH_LONG).show();
AccessibleToast.makeText(activity, activity.getResources().getString(R.string.poi_error_poi_not_found), Toast.LENGTH_LONG).show();
return;
}
dialogBundle.putSerializable(KEY_AMENITY, a);
dialogBundle.putSerializable(KEY_AMENITY_NODE, n);
ctx.showDialog(DIALOG_DELETE_POI); //TODO from android 2.0 use showDialog(id,bundle)
activity.showDialog(DIALOG_DELETE_POI); //TODO from android 2.0 use showDialog(id,bundle)
};
}.execute(new Void[0]);
}
private void prepareDeleteDialog(Dialog dlg, Bundle args) {
Amenity a = (Amenity) args.getSerializable(KEY_AMENITY);
dlg.setTitle(MessageFormat.format(this.ctx.getMapView().getResources().getString(R.string.poi_remove_confirm_template),
dlg.setTitle(MessageFormat.format(this.activity.getResources().getString(R.string.poi_remove_confirm_template),
OsmAndFormatter.getPoiStringWithoutType(a, settings.usingEnglishNames())));
}
private Dialog createDeleteDialog(final Bundle args) {
Builder builder = new AlertDialog.Builder(ctx);
Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(R.string.poi_remove_title);
LinearLayout ll = new LinearLayout(ctx);
LinearLayout ll = new LinearLayout(activity);
ll.setPadding(4, 2, 4, 0);
ll.setOrientation(LinearLayout.VERTICAL);
final EditText comment = new EditText(ctx);
final EditText comment = new EditText(activity);
comment.setText(R.string.poi_remove_title);
ll.addView(comment);
final CheckBox closeChangeset = new CheckBox(ctx);
final CheckBox closeChangeset = new CheckBox(activity);
closeChangeset.setText(R.string.close_changeset);
ll.addView(closeChangeset);
builder.setView(ll);
@ -190,9 +191,9 @@ public class EditingPOIActivity implements DialogProvider {
commitNode(OsmPoint.Action.DELETE, n, openstreetmapUtil.getEntityInfo(), c, closeChangeset.isSelected(), new Runnable(){
@Override
public void run() {
AccessibleToast.makeText(ctx, ctx.getResources().getString(R.string.poi_remove_success), Toast.LENGTH_LONG).show();
if(ctx.getMapView() != null){
ctx.getMapView().refreshMap(true);
AccessibleToast.makeText(activity, activity.getResources().getString(R.string.poi_remove_success), Toast.LENGTH_LONG).show();
if(activity instanceof MapActivity){
((MapActivity) activity).getMapView().refreshMap(true);
}
}
});
@ -224,15 +225,15 @@ public class EditingPOIActivity implements DialogProvider {
}
private void addTagValueRow(final Node n, final TableLayout layout, String tg, String vl) {
final TableRow newTagRow = new TableRow(ctx);
final TableRow newTagRow = new TableRow(activity);
TableRow.LayoutParams tlp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
tlp.leftMargin = 5;
tlp.gravity = Gravity.CENTER;
newTagRow.setLayoutParams(tlp);
final AutoCompleteTextView tag = new AutoCompleteTextView(ctx);
final AutoCompleteTextView value = new AutoCompleteTextView(ctx);
final Button delete = new Button(ctx);
final AutoCompleteTextView tag = new AutoCompleteTextView(activity);
final AutoCompleteTextView value = new AutoCompleteTextView(activity);
final Button delete = new Button(activity);
tag.setLayoutParams(tlp);
if(tg != null) {
@ -248,13 +249,13 @@ public class EditingPOIActivity implements DialogProvider {
tagKeys.add(t.getValue());
}
}
ArrayAdapter<Object> adapter = new ArrayAdapter<Object>(ctx, R.layout.list_textview, tagKeys.toArray());
ArrayAdapter<Object> adapter = new ArrayAdapter<Object>(activity, R.layout.list_textview, tagKeys.toArray());
tag.setAdapter(adapter);
tag.setThreshold(1);
tag.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Builder builder = new AlertDialog.Builder(ctx);
Builder builder = new AlertDialog.Builder(activity);
final String[] tags = tagKeys.toArray(new String[tagKeys.size()]);
builder.setItems(tags, new Dialog.OnClickListener() {
@Override
@ -283,7 +284,7 @@ public class EditingPOIActivity implements DialogProvider {
// subCategories.add(s);
// }
// } ;
ArrayAdapter<Object> valueAdapter = new ArrayAdapter<Object>(ctx, R.layout.list_textview, subCategories.toArray());
ArrayAdapter<Object> valueAdapter = new ArrayAdapter<Object>(activity, R.layout.list_textview, subCategories.toArray());
value.setThreshold(1);
value.setAdapter(valueAdapter);
value.addTextChangedListener(new TextWatcher() {
@ -324,7 +325,7 @@ public class EditingPOIActivity implements DialogProvider {
}
private Dialog createPOIDialog(final int dialogID, Bundle args) {
final Dialog dlg = new Dialog(ctx);
final Dialog dlg = new Dialog(activity);
dlg.setContentView(R.layout.editing_poi);
dlg.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);;
@ -348,7 +349,7 @@ public class EditingPOIActivity implements DialogProvider {
@Override
public void onClick(View v) {
ctx.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://wiki.openstreetmap.org/wiki/Map_Features")));
activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://wiki.openstreetmap.org/wiki/Map_Features")));
}
});
linkToOsmDoc.setMovementMethod(LinkMovementMethod.getInstance());
@ -378,7 +379,7 @@ public class EditingPOIActivity implements DialogProvider {
openHoursButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
ctx.showDialog(DIALOG_OPENING_HOURS);
activity.showDialog(DIALOG_OPENING_HOURS);
}
});
typeText.addTextChangedListener(new TextWatcher(){
@ -408,7 +409,7 @@ public class EditingPOIActivity implements DialogProvider {
typeButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
ctx.showDialog(DIALOG_POI_TYPES);
activity.showDialog(DIALOG_POI_TYPES);
}
});
@ -451,7 +452,7 @@ public class EditingPOIActivity implements DialogProvider {
@Override
public void onClick(View v) {
//we must do remove, because there are two dialogs EDIT,CREATE using same variables!!
ctx.removeDialog(dialogID);
activity.removeDialog(dialogID);
}
});
((Button)dlg.findViewById(R.id.Commit)).setOnClickListener(new View.OnClickListener(){
@ -508,12 +509,12 @@ public class EditingPOIActivity implements DialogProvider {
new Runnable() {
@Override
public void run() {
AccessibleToast.makeText(ctx, MessageFormat.format(ctx.getResources().getString(R.string.poi_action_succeded_template), msg),
AccessibleToast.makeText(activity, MessageFormat.format(activity.getResources().getString(R.string.poi_action_succeded_template), msg),
Toast.LENGTH_LONG).show();
if (ctx.getMapView() != null) {
ctx.getMapView().refreshMap(true);
if (activity instanceof MapActivity) {
((MapActivity) activity).getMapView().refreshMap(true);
}
ctx.removeDialog(dialogID);
activity.removeDialog(dialogID);
}
});
}
@ -522,7 +523,7 @@ public class EditingPOIActivity implements DialogProvider {
private void showSubCategory(Amenity a) {
if(typeText.getText().length() == 0 && a.getType() != null){
ctx.showDialog(DIALOG_SUB_CATEGORIES);
activity.showDialog(DIALOG_SUB_CATEGORIES);
}
}
@ -533,7 +534,7 @@ public class EditingPOIActivity implements DialogProvider {
subCategories.add(s);
}
}
ArrayAdapter<Object> adapter = new ArrayAdapter<Object>(ctx, R.layout.list_textview, subCategories.toArray());
ArrayAdapter<Object> adapter = new ArrayAdapter<Object>(activity, R.layout.list_textview, subCategories.toArray());
typeText.setAdapter(adapter);
}
@ -547,7 +548,7 @@ public class EditingPOIActivity implements DialogProvider {
private Dialog createOpenHoursDlg(){
OpeningHours time = OpeningHoursParser.parseOpenedHours(openingHours.getText().toString());
if(time == null){
AccessibleToast.makeText(ctx, ctx.getString(R.string.opening_hours_not_supported), Toast.LENGTH_LONG).show();
AccessibleToast.makeText(activity, activity.getString(R.string.opening_hours_not_supported), Toast.LENGTH_LONG).show();
return null;
}
@ -564,21 +565,21 @@ public class EditingPOIActivity implements DialogProvider {
}
}
Builder builder = new AlertDialog.Builder(ctx);
final OpeningHoursView v = new OpeningHoursView(ctx);
Builder builder = new AlertDialog.Builder(activity);
final OpeningHoursView v = new OpeningHoursView(activity);
builder.setView(v.createOpeningHoursEditView(simple));
builder.setPositiveButton(ctx.getString(R.string.shared_string_apply), new DialogInterface.OnClickListener(){
builder.setPositiveButton(activity.getString(R.string.shared_string_apply), new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
OpeningHours oh = new OpeningHours((ArrayList<OpeningHoursRule>) v.getTime());
openingHours.setText(oh.toString());
ctx.removeDialog(DIALOG_OPENING_HOURS);
activity.removeDialog(DIALOG_OPENING_HOURS);
}
});
builder.setNegativeButton(ctx.getString(R.string.shared_string_cancel), new DialogInterface.OnClickListener() {
builder.setNegativeButton(activity.getString(R.string.shared_string_cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ctx.removeDialog(DIALOG_OPENING_HOURS);
activity.removeDialog(DIALOG_OPENING_HOURS);
}
});
return builder.create();
@ -589,14 +590,14 @@ public class EditingPOIActivity implements DialogProvider {
final boolean closeChangeSet,
final Runnable successAction) {
if (info == null && OsmPoint.Action.CREATE != action) {
AccessibleToast.makeText(ctx, ctx.getResources().getString(R.string.poi_error_info_not_loaded), Toast.LENGTH_LONG).show();
AccessibleToast.makeText(activity, activity.getResources().getString(R.string.poi_error_info_not_loaded), Toast.LENGTH_LONG).show();
return;
}
new AsyncTask<Void, Void, Node>() {
ProgressDialog progress;
@Override
protected void onPreExecute() {
progress = ProgressDialog.show(ctx, ctx.getString(R.string.uploading), ctx.getString(R.string.uploading_data));
progress = ProgressDialog.show(activity, activity.getString(R.string.uploading), activity.getString(R.string.uploading_data));
super.onPreExecute();
}
@Override
@ -625,7 +626,7 @@ public class EditingPOIActivity implements DialogProvider {
case DIALOG_DELETE_POI:
return createDeleteDialog(args);
case DIALOG_SUB_CATEGORIES: {
Builder builder = new AlertDialog.Builder(ctx);
Builder builder = new AlertDialog.Builder(activity);
final Amenity a = (Amenity) args.getSerializable(KEY_AMENITY);
final String[] subCats = poiTypes.getAllTranslatedNames(a.getType()).keySet().toArray(new String[0]);
builder.setItems(subCats, new DialogInterface.OnClickListener() {
@ -633,20 +634,20 @@ public class EditingPOIActivity implements DialogProvider {
public void onClick(DialogInterface dialog, int which) {
typeText.setText(subCats[which]);
a.setSubType(subCats[which]);
ctx.removeDialog(DIALOG_SUB_CATEGORIES);
activity.removeDialog(DIALOG_SUB_CATEGORIES);
}
});
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
ctx.removeDialog(DIALOG_SUB_CATEGORIES);
activity.removeDialog(DIALOG_SUB_CATEGORIES);
}
});
return builder.create();
}
case DIALOG_POI_TYPES: {
final Amenity a = (Amenity) args.getSerializable(KEY_AMENITY);
Builder builder = new AlertDialog.Builder(ctx);
Builder builder = new AlertDialog.Builder(activity);
final List<PoiCategory> categories = poiTypes.getCategories();
String[] vals = new String[categories.size()];
for (int i = 0; i < vals.length; i++) {
@ -661,13 +662,13 @@ public class EditingPOIActivity implements DialogProvider {
a.setSubType(""); //$NON-NLS-1$
updateType(a);
}
ctx.removeDialog(DIALOG_POI_TYPES);
activity.removeDialog(DIALOG_POI_TYPES);
}
});
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
ctx.removeDialog(DIALOG_POI_TYPES);
activity.removeDialog(DIALOG_POI_TYPES);
}
});
return builder.create();

View file

@ -46,11 +46,10 @@ import android.widget.Toast;
public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
private static final long NO_CHANGESET_ID = -1;
private final OsmandApplication ctx;
private final View view;
private EntityInfo entityInfo;
// reuse changeset
private long changeSetId = NO_CHANGESET_ID;
private long changeSetTimeStamp = NO_CHANGESET_ID;
@ -59,9 +58,8 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
private OsmandSettings settings;
public OpenstreetmapRemoteUtil(Context uiContext, View view){
public OpenstreetmapRemoteUtil(Context uiContext) {
this.ctx = ((OsmandApplication) uiContext.getApplicationContext());
this.view = view;
settings = ctx.getSettings();
}
@ -69,42 +67,41 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
public EntityInfo getEntityInfo() {
return entityInfo;
}
private static String getSiteApi()
{
private static String getSiteApi() {
final int deviceApiVersion = android.os.Build.VERSION.SDK_INT;
String RETURN_API;
if (deviceApiVersion >= android.os.Build.VERSION_CODES.GINGERBREAD) {
RETURN_API = "https://api.openstreetmap.org/";
}
else {
} else {
RETURN_API = "http://api.openstreetmap.org/";
}
// RETURN_API = "http://api06.dev.openstreetmap.org/";
// RETURN_API = "http://api06.dev.openstreetmap.org/";
return RETURN_API;
}
private final static String URL_TO_UPLOAD_GPX = getSiteApi() + "api/0.6/gpx/create";
public String uploadGPXFile(String tagstring, String description, String visibility, File f) {
String url = URL_TO_UPLOAD_GPX;
String url = URL_TO_UPLOAD_GPX;
Map<String, String> additionalData = new LinkedHashMap<String, String>();
additionalData.put("description", description);
additionalData.put("tags", tagstring);
additionalData.put("visibility", visibility);
return NetworkUtils.uploadFile(url, f, settings.USER_NAME.get()+":"+
settings.USER_PASSWORD.get(), "file", true, additionalData);
return NetworkUtils.uploadFile(url, f, settings.USER_NAME.get() + ":" + settings.USER_PASSWORD.get(), "file",
true, additionalData);
}
private String sendRequest(String url, String requestMethod, String requestBody, String userOperation, boolean doAuthenticate) {
private String sendRequest(String url, String requestMethod, String requestBody, String userOperation,
boolean doAuthenticate) {
log.info("Sending request " + url); //$NON-NLS-1$
try {
HttpURLConnection connection = NetworkUtils.getHttpURLConnection(url);
connection.setConnectTimeout(15000);
connection.setRequestMethod(requestMethod);
connection.setRequestProperty("User-Agent", Version.getFullVersion(ctx)); //$NON-NLS-1$
@ -127,7 +124,8 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
}
connection.connect();
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
String msg = userOperation + " " + ctx.getString(R.string.failed_op) + " : " + connection.getResponseMessage(); //$NON-NLS-1$//$NON-NLS-2$
String msg = userOperation
+ " " + ctx.getString(R.string.failed_op) + " : " + connection.getResponseMessage(); //$NON-NLS-1$//$NON-NLS-2$
log.error(msg);
showWarning(msg);
} else {
@ -140,7 +138,7 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
String s;
boolean f = true;
while ((s = in.readLine()) != null) {
if(!f){
if (!f) {
responseBody.append("\n"); //$NON-NLS-1$
} else {
f = false;
@ -153,20 +151,21 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
} catch (NullPointerException e) {
// that's tricky case why NPE is thrown to fix that problem httpClient could be used
String msg = ctx.getString(R.string.auth_failed);
log.error(msg , e);
log.error(msg, e);
showWarning(msg);
} catch (MalformedURLException e) {
log.error(userOperation + " " + ctx.getString(R.string.failed_op) , e); //$NON-NLS-1$
showWarning(MessageFormat.format(ctx.getResources().getString(R.string.shared_string_action_template) + ": " + ctx.getResources().getString(R.string.shared_string_unexpected_error), userOperation));
log.error(userOperation + " " + ctx.getString(R.string.failed_op), e); //$NON-NLS-1$
showWarning(MessageFormat.format(ctx.getResources().getString(R.string.shared_string_action_template)
+ ": " + ctx.getResources().getString(R.string.shared_string_unexpected_error), userOperation));
} catch (IOException e) {
log.error(userOperation + " " + ctx.getString(R.string.failed_op) , e); //$NON-NLS-1$
showWarning(MessageFormat.format(ctx.getResources().getString(R.string.shared_string_action_template) + ": " + ctx.getResources().getString(R.string.shared_string_io_error), userOperation));
log.error(userOperation + " " + ctx.getString(R.string.failed_op), e); //$NON-NLS-1$
showWarning(MessageFormat.format(ctx.getResources().getString(R.string.shared_string_action_template)
+ ": " + ctx.getResources().getString(R.string.shared_string_io_error), userOperation));
}
return null;
}
public long openChangeSet(String comment) {
long id = -1;
StringWriter writer = new StringWriter(256);
@ -193,19 +192,21 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
} catch (IOException e) {
log.error("Unhandled exception", e); //$NON-NLS-1$
}
String response = sendRequest(getSiteApi() + "api/0.6/changeset/create/", "PUT", writer.getBuffer().toString(), ctx.getString(R.string.opening_changeset), true); //$NON-NLS-1$ //$NON-NLS-2$
String response = sendRequest(
getSiteApi() + "api/0.6/changeset/create/", "PUT", writer.getBuffer().toString(), ctx.getString(R.string.opening_changeset), true); //$NON-NLS-1$ //$NON-NLS-2$
if (response != null && response.length() > 0) {
id = Long.parseLong(response);
}
return id;
}
private void writeNode(Node n, EntityInfo i, XmlSerializer ser, long changeSetId, String user) throws IllegalArgumentException, IllegalStateException, IOException{
private void writeNode(Node n, EntityInfo i, XmlSerializer ser, long changeSetId, String user)
throws IllegalArgumentException, IllegalStateException, IOException {
ser.startTag(null, "node"); //$NON-NLS-1$
ser.attribute(null, "id", n.getId()+""); //$NON-NLS-1$ //$NON-NLS-2$
ser.attribute(null, "lat", n.getLatitude()+""); //$NON-NLS-1$ //$NON-NLS-2$
ser.attribute(null, "lon", n.getLongitude()+""); //$NON-NLS-1$ //$NON-NLS-2$
ser.attribute(null, "id", n.getId() + ""); //$NON-NLS-1$ //$NON-NLS-2$
ser.attribute(null, "lat", n.getLatitude() + ""); //$NON-NLS-1$ //$NON-NLS-2$
ser.attribute(null, "lon", n.getLongitude() + ""); //$NON-NLS-1$ //$NON-NLS-2$
if (i != null) {
// ser.attribute(null, "timestamp", i.getETimestamp());
// ser.attribute(null, "uid", i.getUid());
@ -213,11 +214,12 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
ser.attribute(null, "visible", i.getVisible()); //$NON-NLS-1$
ser.attribute(null, "version", i.getVersion()); //$NON-NLS-1$
}
ser.attribute(null, "changeset", changeSetId+""); //$NON-NLS-1$ //$NON-NLS-2$
for(String k : n.getTagKeySet()){
ser.attribute(null, "changeset", changeSetId + ""); //$NON-NLS-1$ //$NON-NLS-2$
for (String k : n.getTagKeySet()) {
String val = n.getTag(k);
if (val.length() == 0) continue;
if (val.length() == 0)
continue;
ser.startTag(null, "tag"); //$NON-NLS-1$
ser.attribute(null, "k", k); //$NON-NLS-1$
ser.attribute(null, "v", val); //$NON-NLS-1$
@ -228,7 +230,7 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
private boolean isNewChangesetRequired() {
// first commit
if (changeSetId == NO_CHANGESET_ID){
if (changeSetId == NO_CHANGESET_ID) {
return true;
}
@ -242,12 +244,13 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
}
@Override
public Node commitNodeImpl(OsmPoint.Action action, final Node n, EntityInfo info, String comment, boolean closeChangeSet){
if (isNewChangesetRequired()){
public Node commitNodeImpl(OsmPoint.Action action, final Node n, EntityInfo info, String comment,
boolean closeChangeSet) {
if (isNewChangesetRequired()) {
changeSetId = openChangeSet(comment);
changeSetTimeStamp = System.currentTimeMillis();
}
if(changeSetId < 0){
if (changeSetId < 0) {
return null;
}
@ -259,7 +262,7 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
ser.setOutput(writer);
ser.startDocument("UTF-8", true); //$NON-NLS-1$
ser.startTag(null, "osmChange"); //$NON-NLS-1$
ser.attribute(null, "version", "0.6"); //$NON-NLS-1$ //$NON-NLS-2$
ser.attribute(null, "version", "0.6"); //$NON-NLS-1$ //$NON-NLS-2$
ser.attribute(null, "generator", Version.getAppName(ctx)); //$NON-NLS-1$
ser.startTag(null, OsmPoint.stringAction.get(action));
ser.attribute(null, "version", "0.6"); //$NON-NLS-1$ //$NON-NLS-2$
@ -271,9 +274,9 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
} catch (IOException e) {
log.error("Unhandled exception", e); //$NON-NLS-1$
}
String res = sendRequest(getSiteApi() + "api/0.6/changeset/"+changeSetId + "/upload", "POST", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String res = sendRequest(getSiteApi() + "api/0.6/changeset/" + changeSetId + "/upload", "POST", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
writer.getBuffer().toString(), ctx.getString(R.string.commiting_node), true);
log.debug(res+""); //$NON-NLS-1$
log.debug(res + ""); //$NON-NLS-1$
if (res != null) {
if (OsmPoint.Action.CREATE == action) {
long newId = n.getId();
@ -292,88 +295,94 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
}
return null;
} finally {
if(closeChangeSet) {
if (closeChangeSet) {
closeChangeSet();
}
}
}
@Override
public void closeChangeSet() {
if (changeSetId != NO_CHANGESET_ID) {
String response = sendRequest(getSiteApi() + "api/0.6/changeset/"+changeSetId+"/close", "PUT", "", ctx.getString(R.string.closing_changeset), true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
String response = sendRequest(
getSiteApi() + "api/0.6/changeset/" + changeSetId + "/close", "PUT", "", ctx.getString(R.string.closing_changeset), true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
log.info("Response : " + response); //$NON-NLS-1$
changeSetId = NO_CHANGESET_ID;
}
}
public EntityInfo loadNode(Node n) {
long nodeId = n.getId(); // >> 1;
try {
String res = sendRequest(getSiteApi() + "api/0.6/node/"+nodeId, "GET", null, ctx.getString(R.string.loading_poi_obj) + nodeId, false); //$NON-NLS-1$ //$NON-NLS-2$
if(res != null){
String res = sendRequest(
getSiteApi() + "api/0.6/node/" + nodeId, "GET", null, ctx.getString(R.string.loading_poi_obj) + nodeId, false); //$NON-NLS-1$ //$NON-NLS-2$
if (res != null) {
OsmBaseStorage st = new OsmBaseStorage();
st.parseOSM(new ByteArrayInputStream(res.getBytes("UTF-8")), null, null, true); //$NON-NLS-1$
EntityId id = new Entity.EntityId(EntityType.NODE, nodeId);
Node entity = (Node) st.getRegisteredEntities().get(id);
// merge non existing tags
for(String rtag : entity.getTagKeySet()) {
if(!n.getTagKeySet().contains(rtag)) {
for (String rtag : entity.getTagKeySet()) {
if (!n.getTagKeySet().contains(rtag)) {
n.putTag(rtag, entity.getTag(rtag));
}
}
entityInfo = st.getRegisteredEntityInfo().get(id);
return entityInfo;
}
} catch (IOException e) {
log.error("Loading node failed " + nodeId, e); //$NON-NLS-1$
AccessibleToast.makeText(ctx, ctx.getResources().getString(R.string.shared_string_io_error), Toast.LENGTH_LONG).show();
AccessibleToast.makeText(ctx, ctx.getResources().getString(R.string.shared_string_io_error),
Toast.LENGTH_LONG).show();
} catch (SAXException e) {
log.error("Loading node failed " + nodeId, e); //$NON-NLS-1$
AccessibleToast.makeText(ctx, ctx.getResources().getString(R.string.shared_string_io_error), Toast.LENGTH_LONG).show();
AccessibleToast.makeText(ctx, ctx.getResources().getString(R.string.shared_string_io_error),
Toast.LENGTH_LONG).show();
}
return null;
}
@Override
public Node loadNode(Amenity n) {
if(n.getId() % 2 == 1){
if (n.getId() % 2 == 1) {
// that's way id
return null;
}
long nodeId = n.getId() >> 1;
try {
String res = sendRequest(getSiteApi() + "api/0.6/node/"+nodeId, "GET", null, ctx.getString(R.string.loading_poi_obj) + nodeId, false); //$NON-NLS-1$ //$NON-NLS-2$
if(res != null){
String res = sendRequest(
getSiteApi() + "api/0.6/node/" + nodeId, "GET", null, ctx.getString(R.string.loading_poi_obj) + nodeId, false); //$NON-NLS-1$ //$NON-NLS-2$
if (res != null) {
OsmBaseStorage st = new OsmBaseStorage();
st.parseOSM(new ByteArrayInputStream(res.getBytes("UTF-8")), null, null, true); //$NON-NLS-1$
EntityId id = new Entity.EntityId(EntityType.NODE, nodeId);
Node entity = (Node) st.getRegisteredEntities().get(id);
entityInfo = st.getRegisteredEntityInfo().get(id);
// check whether this is node (because id of node could be the same as relation)
if(entity != null && MapUtils.getDistance(entity.getLatLon(), n.getLocation()) < 50){
// check whether this is node (because id of node could be the same as relation)
if (entity != null && MapUtils.getDistance(entity.getLatLon(), n.getLocation()) < 50) {
return entity;
}
return null;
}
} catch (Exception e) {
log.error("Loading node failed " + nodeId, e); //$NON-NLS-1$
ctx.runInUIThread(new Runnable() {
@Override
public void run() {
AccessibleToast.makeText(ctx, ctx.getResources().getString(R.string.shared_string_io_error), Toast.LENGTH_LONG).show();
AccessibleToast.makeText(ctx, ctx.getResources().getString(R.string.shared_string_io_error),
Toast.LENGTH_LONG).show();
}
});
}
return null;
}
private void showWarning(final String msg){
view.post(new Runnable(){
private void showWarning(final String msg) {
ctx.runInUIThread(new Runnable() {
@Override
public void run() {
AccessibleToast.makeText(ctx, msg, Toast.LENGTH_LONG).show();

View file

@ -17,7 +17,6 @@ import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.views.controls.MapControls;
import net.osmand.plus.views.controls.MapRouteInfoControl;
import net.osmand.plus.views.controls.MapRoutePreferencesControl;
import net.osmand.plus.views.corenative.NativeCoreContext;
@ -55,8 +54,6 @@ public class MapControlsLayer extends OsmandMapLayer {
// private RulerControl rulerControl;
// private List<MapControls> allControls = new ArrayList<MapControls>();
private float scaleCoefficient;
private SeekBar transparencyBar;
private LinearLayout transparencyBarLayout;
private static CommonPreference<Integer> settingsToTransparency;
@ -95,7 +92,6 @@ public class MapControlsLayer extends OsmandMapLayer {
@Override
public void initLayer(final OsmandMapTileView view) {
scaleCoefficient = view.getScaleCoefficient();
// TODO
// rulerControl = init(new RulerControl(zoomControls, mapActivity, showUIHandler, scaleCoefficient), parent,
// rightGravity);
@ -415,10 +411,6 @@ public class MapControlsLayer extends OsmandMapLayer {
}
protected void notifyClicked(MapControls m) {
notifyClicked();
}
protected void notifyClicked() {
stopCounter();
}
@ -453,16 +445,7 @@ public class MapControlsLayer extends OsmandMapLayer {
&& (!routeFollowingMode || settings.SHOW_ZOOM_BUTTONS_NAVIGATION.get());
// /////////////////////////////////////////////
// new update
boolean enabled = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation() != null;
boolean tracked = mapActivity.getMapViewTrackingUtilities().isMapLinkedToLocation();
if (!enabled) {
backToLocationControl.setIconColorId(R.color.icon_color_light);
} else if (tracked) {
backToLocationControl.setIconColorId(R.color.color_distance);
} else {
backToLocationControl.setIconColorId(R.color.color_white);
}
updateMyLocation();
menuControl.setIconResId(settings.USE_DASHBOARD_INSTEAD_OF_DRAWER.get() ? R.drawable.ic_dashboard_dark
: R.drawable.ic_navigation_drawer);
@ -527,6 +510,24 @@ public class MapControlsLayer extends OsmandMapLayer {
}
}
private void updateMyLocation() {
// final Drawable backToLoc = map.getResources().getDrawable(R.drawable.back_to_loc);
// final Drawable backToLocWhite = map.getResources().getDrawable(R.drawable.back_to_loc_white);
// final Drawable backToLocDisabled = map.getResources().getDrawable(R.drawable.la_backtoloc_disabled);
// final Drawable backToLocDisabledWhite = map.getResources().getDrawable(R.drawable.la_backtoloc_disabled_white);
// final Drawable backToLocTracked = map.getResources().getDrawable(R.drawable.back_to_loc_tracked);
// final Drawable backToLocTrackedWhite = map.getResources().getDrawable(R.drawable.back_to_loc_tracked_white);
boolean enabled = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation() != null;
boolean tracked = mapActivity.getMapViewTrackingUtilities().isMapLinkedToLocation();
if (!enabled) {
backToLocationControl.setIconColorId(R.color.icon_color_light);
} else if (tracked) {
backToLocationControl.setIconColorId(R.color.color_distance);
} else {
backToLocationControl.setIconColorId(R.color.color_white);
}
}
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
if (mapRouteInfoControlDialog.onSingleTap(point, tileBox)) {

View file

@ -38,6 +38,7 @@ import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
public class MapInfoLayer extends OsmandMapLayer {
@ -47,19 +48,16 @@ public class MapInfoLayer extends OsmandMapLayer {
private final RouteLayer routeLayer;
private OsmandMapTileView view;
private Paint paintText;
private Paint paintSubText;
private Paint paintSmallText;
private Paint paintSmallSubText;
private Paint paintImg;
private TopTextView topText;
private View progressBar;
// private Paint paintText;
// private Paint paintSubText;
// private Paint paintSmallText;
// private Paint paintSmallSubText;
// private Paint paintImg;
// private View progressBar;
//
// groups
private StackWidgetView rightStack;
private StackWidgetView leftStack;
private LinearLayout rightStack;
private LinearLayout leftStack;
private BaseMapWidget lanesControl;
private BaseMapWidget alarmControl;
private MapWidgetRegistry mapInfoControls;
@ -71,23 +69,6 @@ public class MapInfoLayer extends OsmandMapLayer {
this.routeLayer = layer;
}
public Paint getPaintSmallSubText() {
return paintSmallSubText;
}
public Paint getPaintText() {
return paintText;
}
public Paint getPaintSmallText() {
return paintSmallText;
}
public Paint getPaintSubText() {
return paintSubText;
}
public MonitoringInfoControl getMonitoringInfoControl() {
return monitoringServices;
}
@ -101,33 +82,33 @@ public class MapInfoLayer extends OsmandMapLayer {
this.view = view;
scaleCoefficient = view.getScaleCoefficient();
paintText = new Paint();
Paint paintText = new Paint();
paintText.setStyle(Style.FILL_AND_STROKE);
paintText.setColor(Color.BLACK);
paintText.setTextSize(23 * scaleCoefficient);
paintText.setAntiAlias(true);
paintText.setStrokeWidth(4);
paintSubText = new Paint();
Paint paintSubText = new Paint();
paintSubText.setStyle(Style.FILL_AND_STROKE);
paintSubText.setColor(Color.BLACK);
paintSubText.setTextSize(15 * scaleCoefficient);
paintSubText.setAntiAlias(true);
paintSmallText = new Paint();
Paint paintSmallText = new Paint();
paintSmallText.setStyle(Style.FILL_AND_STROKE);
paintSmallText.setColor(Color.BLACK);
paintSmallText.setTextSize(19 * scaleCoefficient);
paintSmallText.setAntiAlias(true);
paintSmallText.setStrokeWidth(4);
paintSmallSubText = new Paint();
Paint paintSmallSubText = new Paint();
paintSmallSubText.setStyle(Style.FILL_AND_STROKE);
paintSmallSubText.setColor(Color.BLACK);
paintSmallSubText.setTextSize(13 * scaleCoefficient);
paintSmallSubText.setAntiAlias(true);
paintImg = new Paint();
Paint paintImg = new Paint();
paintImg.setDither(true);
paintImg.setFilterBitmap(true);
paintImg.setAntiAlias(true);
@ -162,24 +143,22 @@ public class MapInfoLayer extends OsmandMapLayer {
NextTurnInfoWidget nextNextInfoControl = ric.createNextNextInfoControl(routingHelper, app, view.getSettings(),
paintSmallText, paintSmallSubText, true);
mapInfoControls.registerSideWidget(nextNextInfoControl, R.drawable.widget_next_turn, R.drawable.widget_next_turn, R.string.map_widget_next_next_turn, "next_next_turn",true, 15);
//MiniMapControl miniMap = ric.createMiniMapControl(routingHelper, view);
//mapInfoControls.registerSideWidget(miniMap, R.drawable.widget_next_turn, R.string.map_widget_mini_route, "mini_route", true, none, none, 20);
// right stack
TextInfoWidget intermediateDist = ric.createIntermediateDistanceControl(map, paintText, paintSubText);
TextInfoWidget intermediateDist = ric.createIntermediateDistanceControl(map);
mapInfoControls.registerSideWidget(intermediateDist, R.drawable.widget_intermediate, R.drawable.widget_intermediate, R.string.map_widget_intermediate_distance, "intermediate_distance", false, 3);
TextInfoWidget dist = ric.createDistanceControl(map, paintText, paintSubText);
TextInfoWidget dist = ric.createDistanceControl(map);
mapInfoControls.registerSideWidget(dist, R.drawable.widget_target, R.drawable.widget_target, R.string.map_widget_distance, "distance", false, 5);
TextInfoWidget time = ric.createTimeControl(map, paintText, paintSubText);
TextInfoWidget time = ric.createTimeControl(map);
mapInfoControls.registerSideWidget(time, R.drawable.widget_time, R.drawable.widget_time, R.string.map_widget_time, "time", false, 10);
TextInfoWidget speed = ric.createSpeedControl(map, paintText, paintSubText);
TextInfoWidget speed = ric.createSpeedControl(map);
mapInfoControls.registerSideWidget(speed, R.drawable.widget_speed, R.drawable.widget_speed, R.string.map_widget_speed, "speed", false, 15);
TextInfoWidget gpsInfo = mic.createGPSInfoControl(map, paintText, paintSubText);
TextInfoWidget gpsInfo = mic.createGPSInfoControl(map);
mapInfoControls.registerSideWidget(gpsInfo, R.drawable.widget_gps_info, R.drawable.widget_gps_info, R.string.map_widget_gps_info, "gps_info", false, 17);
TextInfoWidget maxspeed = ric.createMaxSpeedControl(map, paintText, paintSubText);
TextInfoWidget maxspeed = ric.createMaxSpeedControl(map);
mapInfoControls.registerSideWidget(maxspeed, R.drawable.widget_max_speed, R.drawable.widget_max_speed, R.string.map_widget_max_speed, "max_speed", false, 18);
TextInfoWidget alt = mic.createAltitudeControl(map, paintText, paintSubText);
TextInfoWidget alt = mic.createAltitudeControl(map);
mapInfoControls.registerSideWidget(alt, R.drawable.widget_altitude, R.drawable.widget_altitude, R.string.map_widget_altitude, "altitude", false, 20);
TextInfoWidget plainTime = ric.createPlainTimeControl(map, paintText, paintSubText);
TextInfoWidget plainTime = ric.createPlainTimeControl(map);
mapInfoControls.registerSideWidget(plainTime, R.drawable.widget_time_to_distance, R.drawable.widget_time_to_distance, R.string.map_widget_plain_time, "plain_time", false, 25);
// Register appearance widgets
@ -206,7 +185,7 @@ public class MapInfoLayer extends OsmandMapLayer {
// form measurement
ImageView iv = new ImageView(map);
iv.setImageDrawable(map.getResources().getDrawable(R.drawable.la_backtoloc_disabled));
rightStack = new StackWidgetView(view.getContext());
rightStack = map;
leftStack = new StackWidgetView(view.getContext());
// 2. Preparations
@ -409,7 +388,6 @@ public class MapInfoLayer extends OsmandMapLayer {
paintSmallText.setColor(textColor);
paintSmallSubText.setColor(textColor);
topText.setShadowColor(textShadowColor);
leftStack.setShadowColor(textShadowColor);
rightStack.setShadowColor(textShadowColor);
@ -458,21 +436,6 @@ public class MapInfoLayer extends OsmandMapLayer {
return progressBar;
}
private static class UpdateFrameLayout extends FrameLayout implements UpdateableWidget {
private ImageViewWidget widget;
private UpdateFrameLayout(Context c, ImageViewWidget widget) {
super(c);
this.widget = widget;
}
@Override
public boolean updateInfo(DrawSettings drawSettings) {
return widget.updateInfo(drawSettings);
}
}
public static String getStringPropertyName(Context ctx, String propertyName, String defValue) {
try {

View file

@ -985,14 +985,6 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
return view.getResources();
}
public ViewParent getParent() {
return view.getParent();
}
public View getView() {
return view;
}
public int getHeight() {
return view.getHeight();
}

View file

@ -1,224 +0,0 @@
package net.osmand.plus.views.controls;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.PointF;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageButton;
public abstract class MapControls {
protected MapActivity mapActivity;
protected float scaleCoefficient;
protected Handler showUIHandler;
protected int shadowColor;
private boolean visible;
private long delayTime;
protected int gravity = Gravity.BOTTOM | Gravity.RIGHT;
protected int margin;
protected int vmargin;
protected int width;
protected int height;
protected Runnable notifyClick;
private int extraVerticalMargin;
public MapControls(MapActivity mapActivity, Handler showUIHandler, float scaleCoefficient) {
this.mapActivity = mapActivity;
this.showUIHandler = showUIHandler;
this.scaleCoefficient = scaleCoefficient;
}
public void setGravity(int gravity) {
this.gravity = gravity;
}
public void setMargin(int margin) {
this.margin = margin;
}
public void setVerticalMargin(int vmargin) {
this.vmargin = vmargin;
}
protected ImageButton addImageButton(FrameLayout parent, int stringId, int resourceId) {
Context ctx = mapActivity;
ImageButton button = new ImageButton(ctx);
applyAttributes(ctx, parent, button, stringId, resourceId, 0);
return button;
}
public int getTotalVerticalMargin() {
return extraVerticalMargin + vmargin;
}
protected Button addButton(FrameLayout parent, int stringId, int resourceId) {
return addButton(parent, stringId, resourceId, 0);
}
protected Button addButton(FrameLayout parent, int stringId, int resourceId, int extraMargin) {
Context ctx = mapActivity;
Button button = new Button(ctx);
applyAttributes(ctx, parent, button, stringId, resourceId, extraMargin);
return button;
}
public void setNotifyClick(Runnable notifyClick) {
this.notifyClick = notifyClick;
}
protected void notifyClicked() {
if(notifyClick != null) {
notifyClick.run();
}
}
private void applyAttributes(Context ctx, FrameLayout parent, View button, int stringId, int resourceId,
int extraMargin) {
button.setContentDescription(ctx.getString(stringId));
button.setBackgroundResource(resourceId);
Drawable d = ctx.getResources().getDrawable(resourceId);
android.widget.FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(d.getMinimumWidth(), d.getMinimumHeight(),
gravity);
if((gravity & Gravity.LEFT) == Gravity.LEFT) {
params.leftMargin = margin + extraMargin;
} else {
params.rightMargin = margin + extraMargin;
}
if((gravity & Gravity.BOTTOM) == Gravity.BOTTOM) {
params.bottomMargin = vmargin + extraVerticalMargin;
} else {
params.topMargin = vmargin + extraVerticalMargin;
}
button.setLayoutParams(params);
parent.addView(button);
button.setEnabled(true);
mapActivity.accessibleContent.add(button);
}
public int getGravity() {
return gravity;
}
protected void removeButton(final FrameLayout layout, final View b) {
b.setVisibility(View.GONE);
if (layout.getHandler() != null){
layout.getHandler().post(new Runnable() {
@Override
public void run() {
layout.removeView(b);
}
});
}
mapActivity.accessibleContent.remove(b);
}
public void updateTextColor(int textColor, int shadowColor) {
this.shadowColor = shadowColor;
}
public final void init(FrameLayout layout) {
initControls(layout);
}
public final void show(FrameLayout layout) {
visible = true;
showControls(layout);
}
public final void showWithDelay(final FrameLayout layout, final long delay) {
this.delayTime = System.currentTimeMillis() + delay;
if(!visible) {
visible = true;
showControls(layout);
runWithDelay(layout, delay);
mapActivity.getMapView().refreshMap();
}
}
private void runWithDelay(final FrameLayout layout, final long delay) {
showUIHandler.postDelayed(new Runnable() {
@Override
public void run() {
long ctime = System.currentTimeMillis();
if(MapControls.this.delayTime <= ctime) {
if (MapControls.this.delayTime != 0) {
MapControls.this.delayTime = 0;
visible = false;
hideControls(layout);
mapActivity.getMapView().refreshMap();
}
} else {
runWithDelay(layout, MapControls.this.delayTime - ctime);
}
}
}, delay);
}
public final void hide(FrameLayout layout) {
if(this.delayTime == 0) {
visible = false;
hideControls(layout);
}
}
public final void forceHide(FrameLayout layout) {
delayTime = 0;
visible = false;
hideControls(layout);
mapActivity.getMapView().refreshMap();
}
public boolean isVisible() {
return visible;
}
protected boolean isLeft() {
return (Gravity.LEFT & gravity) == Gravity.LEFT;
}
public boolean isBottom() {
return (Gravity.BOTTOM & gravity) == Gravity.BOTTOM;
}
protected void initControls(FrameLayout layout) {
}
protected abstract void hideControls(FrameLayout layout);
protected abstract void showControls(FrameLayout layout);
public abstract void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode);
public boolean onTouchEvent(MotionEvent event, RotatedTileBox tileBox) {
return false;
}
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
return false;
}
public void setExtraVerticalMargin(int extraVerticalMargin) {
this.extraVerticalMargin = extraVerticalMargin;
}
public int getExtraVerticalMargin() {
return this.extraVerticalMargin;
}
}

View file

@ -16,7 +16,7 @@ import android.text.TextPaint;
import android.view.View;
import android.widget.FrameLayout;
public class RulerControl extends MapControls {
public class RulerControl {
//ruler and ruler label appeareance:
// Day view: color black, shadowColor white (transpparent skin or not)
@ -31,30 +31,19 @@ public class RulerControl extends MapControls {
TextPaint rulerTextPaint;
final static double screenRulerPercent = 0.25;
boolean isNightRemembered = false;
private MapActivity mapActivity;
private float scaleCoefficient;
public RulerControl(MapActivity mapActivity, Handler showUIHandler, float scaleCoefficient) {
super(mapActivity, showUIHandler, scaleCoefficient);
this.mapActivity = mapActivity;
this.scaleCoefficient = scaleCoefficient;
rulerTextPaint = new TextPaint();
rulerTextPaint.setTextSize(20 * scaleCoefficient);
rulerTextPaint.setAntiAlias(true);
rulerDrawable = mapActivity.getResources().getDrawable(R.drawable.ruler);
}
@Override
protected void hideControls(FrameLayout layout) {
}
@Override
public void updateTextColor(int textColor, int shadowColor) {
super.updateTextColor(textColor, shadowColor);
rulerTextPaint.setColor(textColor);
}
@Override
protected void showControls(FrameLayout layout) {
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings nightMode) {
if (!mapActivity.getMyApplication().getSettings().SHOW_RULER.get()) {
return;
@ -93,7 +82,7 @@ public class RulerControl extends MapControls {
if (cacheRulerText != null) {
Rect bounds = rulerDrawable.getBounds();
int bottom = (int) (view.getHeight() - vmargin);
int bottom = (int) (view.getHeight() );
if (bounds.bottom != bottom) {
bounds.bottom = bottom;
bounds.top = bounds.bottom - rulerDrawable.getMinimumHeight();

View file

@ -7,66 +7,57 @@ import net.osmand.plus.views.OsmandMapTileView;
public class AppearanceWidgetsFactory {
public static AppearanceWidgetsFactory INSTANCE = new AppearanceWidgetsFactory();
public static boolean POSITION_ON_THE_MAP = false;
public static AppearanceWidgetsFactory INSTANCE = new AppearanceWidgetsFactory();
public static boolean POSITION_ON_THE_MAP = false;
public void registerAppearanceWidgets(final MapActivity map, final MapInfoLayer mapInfoLayer,
final MapWidgetRegistry mapInfoControls) {
final OsmandMapTileView view = map.getMapView();
public void registerAppearanceWidgets(final MapActivity map, final MapInfoLayer mapInfoLayer,
final MapWidgetRegistry mapInfoControls) {
final OsmandMapTileView view = map.getMapView();
final MapWidgetRegistry.MapWidgetRegInfo showRuler = mapInfoControls.registerAppearanceWidget(0, 0,
// R.drawable.widget_ruler, R.drawable.widget_ruler,
R.string.map_widget_show_ruler, "showRuler", view.getSettings().SHOW_RULER);
showRuler.setStateChangeListener(new Runnable() {
@Override
public void run() {
view.getSettings().SHOW_RULER.set(!view.getSettings().SHOW_RULER.get());
view.refreshMap();
}
});
final MapWidgetRegistry.MapWidgetRegInfo showDestinationArrow = mapInfoControls.registerAppearanceWidget(0, 0,
// R.drawable.widget_ruler, R.drawable.widget_ruler,
R.string.map_widget_show_destination_arrow, "show_destination_arrow",
view.getSettings().SHOW_DESTINATION_ARROW);
showDestinationArrow.setStateChangeListener(new Runnable() {
@Override
public void run() {
view.getSettings().SHOW_DESTINATION_ARROW.set(!view.getSettings().SHOW_DESTINATION_ARROW.get());
mapInfoLayer.recreateControls();
}
});
final MapWidgetRegistry.MapWidgetRegInfo transparent = mapInfoControls.registerAppearanceWidget(0, 0,
// R.drawable.widget_ruler, R.drawable.widget_ruler,
R.string.map_widget_transparent, "transparent", view.getSettings().TRANSPARENT_MAP_THEME);
transparent.setStateChangeListener(new Runnable() {
@Override
public void run() {
view.getSettings().TRANSPARENT_MAP_THEME.set(!view.getSettings().TRANSPARENT_MAP_THEME.get());
mapInfoLayer.recreateControls();
}
});
final MapWidgetRegistry.MapWidgetRegInfo centerPosition = mapInfoControls.registerAppearanceWidget(0, 0,
// R.drawable.widget_position_marker, R.drawable.widget_position_marker
R.string.always_center_position_on_map, "centerPosition", view.getSettings().CENTER_POSITION_ON_MAP);
centerPosition.setStateChangeListener(new Runnable() {
@Override
public void run() {
view.getSettings().CENTER_POSITION_ON_MAP.set(!view.getSettings().CENTER_POSITION_ON_MAP.get());
map.updateApplicationModeSettings();
view.refreshMap(true);
mapInfoLayer.recreateControls();
}
});
}
// final MapWidgetRegistry.MapWidgetRegInfo displayViewDirections = mapInfoControls.registerAppearanceWidget(R.drawable.widget_viewing_direction, R.string.map_widget_view_direction,
// "viewDirection", view.getSettings().SHOW_VIEW_ANGLE);
// displayViewDirections.setStateChangeListener(new Runnable() {
// @Override
// public void run() {
// view.getSettings().SHOW_VIEW_ANGLE.set(!view.getSettings().SHOW_VIEW_ANGLE.get());
// map.getMapViewTrackingUtilities().updateSettings();
// }
// });
final MapWidgetRegistry.MapWidgetRegInfo showRuler = mapInfoControls.registerAppearanceWidget(0, 0, /*R.drawable.widget_ruler, R.drawable.widget_ruler, */R.string.map_widget_show_ruler,
"showRuler", view.getSettings().SHOW_RULER);
showRuler.setStateChangeListener(new Runnable() {
@Override
public void run() {
view.getSettings().SHOW_RULER.set(!view.getSettings().SHOW_RULER.get());
view.refreshMap();
}
});
final MapWidgetRegistry.MapWidgetRegInfo showDestinationArrow = mapInfoControls.registerAppearanceWidget(0, 0, /*R.drawable.widget_show_destination_arrow, R.drawable.widget_show_destination_arrow, */R.string.map_widget_show_destination_arrow,
"show_destination_arrow", view.getSettings().SHOW_DESTINATION_ARROW);
showDestinationArrow.setStateChangeListener(new Runnable() {
@Override
public void run() {
view.getSettings().SHOW_DESTINATION_ARROW.set(!view.getSettings().SHOW_DESTINATION_ARROW.get());
mapInfoLayer.recreateControls();
}
});
final MapWidgetRegistry.MapWidgetRegInfo transparent = mapInfoControls.registerAppearanceWidget(0, 0, /*R.drawable.widget_transparent_skin, R.drawable.widget_transparent_skin, */R.string.map_widget_transparent,
"transparent", view.getSettings().TRANSPARENT_MAP_THEME);
transparent.setStateChangeListener(new Runnable() {
@Override
public void run() {
view.getSettings().TRANSPARENT_MAP_THEME.set(!view.getSettings().TRANSPARENT_MAP_THEME.get());
mapInfoLayer.recreateControls();
}
});
final MapWidgetRegistry.MapWidgetRegInfo centerPosition = mapInfoControls.registerAppearanceWidget(0, 0, /*R.drawable.widget_position_marker, R.drawable.widget_position_marker,*/
R.string.always_center_position_on_map,
"centerPosition", view.getSettings().CENTER_POSITION_ON_MAP);
centerPosition.setStateChangeListener(new Runnable() {
@Override
public void run() {
view.getSettings().CENTER_POSITION_ON_MAP.set(!view.getSettings().CENTER_POSITION_ON_MAP.get());
map.updateApplicationModeSettings();
view.refreshMap(true);
mapInfoLayer.recreateControls();
}
});
}
}

View file

@ -8,7 +8,6 @@ import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmAndLocationProvider;
import net.osmand.plus.OsmAndLocationProvider.GPSInfo;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.activities.MapActivity;
@ -53,8 +52,8 @@ public class MapInfoWidgetsFactory {
this.scaleCoefficient = scaleCoefficient;
}
public TextInfoWidget createAltitudeControl(final MapActivity map, Paint paintText, Paint paintSubText) {
final TextInfoWidget altitudeControl = new TextInfoWidget(map, 0, paintText, paintSubText) {
public TextInfoWidget createAltitudeControl(final MapActivity map) {
final TextInfoWidget altitudeControl = new TextInfoWidget(map) {
private int cachedAlt = 0;
@Override
@ -87,10 +86,10 @@ public class MapInfoWidgetsFactory {
return altitudeControl;
}
public TextInfoWidget createGPSInfoControl(final MapActivity map, Paint paintText, Paint paintSubText) {
public TextInfoWidget createGPSInfoControl(final MapActivity map) {
final OsmandApplication app = map.getMyApplication();
final OsmAndLocationProvider loc = app.getLocationProvider();
final TextInfoWidget gpsInfoControl = new TextInfoWidget(map, 3, paintText, paintSubText) {
final TextInfoWidget gpsInfoControl = new TextInfoWidget(map) {
private int u = -1;
private int f = -1;
@ -178,46 +177,6 @@ public class MapInfoWidgetsFactory {
public ImageViewWidget createBackToLocation(final MapActivity map){
final Drawable backToLoc = map.getResources().getDrawable(R.drawable.back_to_loc);
final Drawable backToLocWhite = map.getResources().getDrawable(R.drawable.back_to_loc_white);
final Drawable backToLocDisabled = map.getResources().getDrawable(R.drawable.la_backtoloc_disabled);
final Drawable backToLocDisabledWhite = map.getResources().getDrawable(R.drawable.la_backtoloc_disabled_white);
final Drawable backToLocTracked = map.getResources().getDrawable(R.drawable.back_to_loc_tracked);
final Drawable backToLocTrackedWhite = map.getResources().getDrawable(R.drawable.back_to_loc_tracked_white);
ImageViewWidget backToLocation = new ImageViewWidget(map) {
Drawable lastDrawable = null;
@Override
public boolean updateInfo(DrawSettings drawSettings) {
boolean nightMode = drawSettings == null ? false : drawSettings.isNightMode();
boolean enabled = map.getMyApplication().getLocationProvider().getLastKnownLocation() != null;
boolean tracked = map.getMapViewTrackingUtilities().isMapLinkedToLocation();
Drawable d;
if(!enabled) {
d = nightMode ? backToLocDisabledWhite : backToLocDisabled;
} else if(tracked) {
d = nightMode ? backToLocTrackedWhite : backToLocTracked;
} else {
d = nightMode ? backToLocWhite : backToLoc;
}
if(d != lastDrawable) {
lastDrawable = d;
setImageDrawable(d);
}
return true;
}
};
backToLocation.setPadding((int) (5 * scaleCoefficient), 0, (int) (5 * scaleCoefficient), 0);
backToLocation.setImageDrawable(map.getResources().getDrawable(R.drawable.back_to_loc));
backToLocation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
map.getMapViewTrackingUtilities().backToLocationImpl();
}
});
return backToLocation;
}
private static boolean isScreenLocked = false;
private Drawable lockEnabled;
@ -279,16 +238,17 @@ public class MapInfoWidgetsFactory {
private void blinkIcon() {
lockView.setBackgroundDrawable(lockDisabled);
view.getView().postDelayed(new Runnable() {
@Override
public void run() {
lockView.setBackgroundDrawable(lockEnabled);
}
}, 300);
// TODO!
// map.postDelayed(new Runnable() {
// @Override
// public void run() {
// lockView.setBackgroundDrawable(lockEnabled);
// }
// }, 300);
}
});
final FrameLayout parent = (FrameLayout) view.getParent();
final FrameLayout parent = null; // TODO
lockView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

View file

@ -64,7 +64,8 @@ public class MapWidgetRegistry {
public void registerSideWidget(BaseMapWidget m, int drawableDark,int drawableLight, int messageId, String key, boolean left, int priorityOrder) {
public void registerSideWidget(TextInfoWidget widget, int drawableDark,int drawableLight,
int messageId, String key, boolean left, int priorityOrder) {
MapWidgetRegInfo ii = new MapWidgetRegInfo();
ii.key = key;
ii.visibleModes = new LinkedHashSet<ApplicationMode>();
@ -91,12 +92,12 @@ public class MapWidgetRegistry {
ii.visibleCollapsible.add(ms);
}
}
if (m != null)
m.setContentTitle(m.getContext().getString(messageId));
if (widget != null)
widget.setContentTitle(widget.getContext().getString(messageId));
ii.drawableDark = drawableDark;
ii.drawableLight = drawableLight;
ii.messageId = messageId;
ii.m = m;
ii.widget = widget;
ii.priorityOrder = priorityOrder;
if(left) {
this.left.add(ii);
@ -179,9 +180,9 @@ public class MapWidgetRegistry {
Set<MapWidgetRegInfo> st = left ? this.left : this.right;
for (MapWidgetRegInfo r : st) {
if (r.visibleCollapsible != null && r.visibleCollapsible.contains(appMode)) {
stack.addCollapsedView((BaseMapWidget) r.m);
stack.addCollapsedView((BaseMapWidget) r.widget);
} else if (r.visibleModes.contains(appMode)) {
stack.addStackView((BaseMapWidget) r.m);
stack.addStackView((BaseMapWidget) r.widget);
}
}
}
@ -224,7 +225,7 @@ public class MapWidgetRegistry {
public static class MapWidgetRegInfo implements Comparable<MapWidgetRegInfo> {
public View m;
public TextInfoWidget widget;
public int drawableDark;
public int drawableLight;
public int messageId;

View file

@ -226,13 +226,13 @@ public class RouteInfoWidgetsFactory {
return nextTurnInfo;
}
public TextInfoWidget createTimeControl(final MapActivity map, Paint paintText, Paint paintSubText){
public TextInfoWidget createTimeControl(final MapActivity map){
final RoutingHelper routingHelper = map.getRoutingHelper();
final Drawable time = map.getResources().getDrawable(R.drawable.widget_time);
final Drawable timeToGo = map.getResources().getDrawable(R.drawable.widget_time_to_distance);
final OsmandApplication ctx = map.getMyApplication();
final OsmandPreference<Boolean> showArrival = ctx.getSettings().SHOW_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME;
final TextInfoWidget leftTimeControl = new TextInfoWidget(map, 0, paintText, paintSubText) {
final TextInfoWidget leftTimeControl = new TextInfoWidget(map) {
private long cachedLeftTime = 0;
@Override
@ -246,7 +246,7 @@ public class RouteInfoWidgetsFactory {
long toFindTime = time * 1000 + System.currentTimeMillis();
if (Math.abs(toFindTime - cachedLeftTime) > 30000) {
cachedLeftTime = toFindTime;
setContentTitle(getContext().getString(R.string.access_arrival_time));
setContentTitle(map.getString(R.string.access_arrival_time));
if (DateFormat.is24HourFormat(ctx)) {
setText(DateFormat.format("k:mm", toFindTime).toString(), null); //$NON-NLS-1$
} else {
@ -260,7 +260,7 @@ public class RouteInfoWidgetsFactory {
cachedLeftTime = time;
int hours = time / (60 * 60);
int minutes = (time / 60) % 60;
setContentTitle(getContext().getString(R.string.map_widget_time));
setContentTitle(map.getString(R.string.map_widget_time));
setText(String.format("%d:%02d", hours, minutes), null); //$NON-NLS-1$
return true;
}
@ -281,7 +281,6 @@ public class RouteInfoWidgetsFactory {
public void onClick(View v) {
showArrival.set(!showArrival.get());
leftTimeControl.setImageDrawable(showArrival.get()? time : timeToGo);
leftTimeControl.requestLayout();
map.getMapView().refreshMap();
}
@ -292,10 +291,10 @@ public class RouteInfoWidgetsFactory {
}
public TextInfoWidget createPlainTimeControl(final MapActivity map, Paint paintText, Paint paintSubText){
public TextInfoWidget createPlainTimeControl(final MapActivity map){
final Drawable timeToGo = map.getResources().getDrawable(R.drawable.widget_time_to_distance);
final OsmandApplication ctx = map.getMyApplication();
final TextInfoWidget plainTimeControl = new TextInfoWidget(map, 0, paintText, paintSubText) {
final TextInfoWidget plainTimeControl = new TextInfoWidget(map) {
private long cachedLeftTime = 0;
@Override
@ -319,11 +318,11 @@ public class RouteInfoWidgetsFactory {
}
public TextInfoWidget createMaxSpeedControl(final MapActivity map, Paint paintText, Paint paintSubText) {
public TextInfoWidget createMaxSpeedControl(final MapActivity map) {
final RoutingHelper rh = map.getMyApplication().getRoutingHelper();
final OsmAndLocationProvider locationProvider = map.getMyApplication().getLocationProvider();
final MapViewTrackingUtilities trackingUtilities = map.getMapViewTrackingUtilities();
final TextInfoWidget speedControl = new TextInfoWidget(map, 3, paintText, paintSubText) {
final TextInfoWidget speedControl = new TextInfoWidget(map) {
private float cachedSpeed = 0;
@Override
@ -365,9 +364,9 @@ public class RouteInfoWidgetsFactory {
public TextInfoWidget createSpeedControl(final MapActivity map, Paint paintText, Paint paintSubText) {
public TextInfoWidget createSpeedControl(final MapActivity map) {
final OsmandApplication app = map.getMyApplication();
final TextInfoWidget speedControl = new TextInfoWidget(map, 3, paintText, paintSubText) {
final TextInfoWidget speedControl = new TextInfoWidget(map) {
private float cachedSpeed = 0;
@Override
@ -412,13 +411,12 @@ public class RouteInfoWidgetsFactory {
private float[] calculations = new float[1];
private int cachedMeters;
public DistanceToPointInfoControl(Context ctx, int leftMargin, Paint textPaint, Paint subtextPaint, Drawable d,
final OsmandMapTileView view) {
super(ctx, leftMargin, textPaint, subtextPaint);
this.view = view;
public DistanceToPointInfoControl(MapActivity ma, Drawable d) {
super(ma);
this.view = ma.getMapView();
setImageDrawable(d);
setText(null, null);
setOnClickListener(new OnClickListener() {
setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -471,10 +469,9 @@ public class RouteInfoWidgetsFactory {
}
}
public TextInfoWidget createDistanceControl(final MapActivity map, Paint paintText, Paint paintSubText) {
final OsmandMapTileView view = map.getMapView();
DistanceToPointInfoControl distanceControl = new DistanceToPointInfoControl(map, 0, paintText, paintSubText, map.getResources()
.getDrawable(R.drawable.widget_target), view) {
public TextInfoWidget createDistanceControl(final MapActivity map) {
DistanceToPointInfoControl distanceControl = new DistanceToPointInfoControl(map,map.getResources()
.getDrawable(R.drawable.widget_target)) {
@Override
public LatLon getPointToNavigate() {
TargetPoint p = map.getPointToNavigate();
@ -492,11 +489,10 @@ public class RouteInfoWidgetsFactory {
return distanceControl;
}
public TextInfoWidget createIntermediateDistanceControl(final MapActivity map, Paint paintText, Paint paintSubText) {
final OsmandMapTileView view = map.getMapView();
public TextInfoWidget createIntermediateDistanceControl(final MapActivity map) {
final TargetPointsHelper targets = map.getMyApplication().getTargetPointsHelper();
DistanceToPointInfoControl distanceControl = new DistanceToPointInfoControl(map, 0, paintText, paintSubText, map.getResources()
.getDrawable(R.drawable.widget_intermediate), view) {
DistanceToPointInfoControl distanceControl = new DistanceToPointInfoControl(map, map.getResources()
.getDrawable(R.drawable.widget_intermediate)) {
@Override
protected void click(OsmandMapTileView view) {

View file

@ -1,115 +1,101 @@
package net.osmand.plus.views.mapwidgets;
import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.R;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;
public class TextInfoWidget extends BaseMapWidget {
public class TextInfoWidget {
String text;
Paint textPaint;
String subtext;
Paint subtextPaint;
int leftMargin = 0;
private Drawable imageDrawable;
private float scaleCoefficient;
private String contentTitle;
private View view;
private ImageView imageView;
private TextView textView;
private TextView smallTextView;
public TextInfoWidget(Context ctx, int leftMargin, Paint textPaint, Paint subtextPaint) {
super(ctx);
scaleCoefficient = MapInfoLayer.scaleCoefficient;
this.leftMargin = leftMargin;
this.textPaint = textPaint;
this.subtextPaint = subtextPaint;
public TextInfoWidget(Activity activity) {
view = activity.getLayoutInflater().inflate(R.layout.map_hud_widget, null);
imageView = (ImageView) view.findViewById(R.id.widget_icon);
textView = (TextView) view.findViewById(R.id.widget_text);
smallTextView = (TextView) view.findViewById(R.id.widget_text_small);
}
public void setImageDrawable(Drawable imageDrawable) {
this.imageDrawable = imageDrawable;
}
public Drawable getImageDrawable() {
return imageDrawable;
}
@Override
protected void onWLayout(int w, int h) {
if (imageDrawable != null) {
// Unknown reason to add 3*scaleCoefficient
imageDrawable.setBounds(0, (int) (3 * scaleCoefficient), imageDrawable.getMinimumWidth(), imageDrawable.getMinimumHeight()
+ (int) (3 * scaleCoefficient));
if(imageDrawable != null) {
imageView.setImageDrawable(imageDrawable);
imageView.setVisibility(View.VISIBLE);
} else {
imageView.setVisibility(View.INVISIBLE);
}
}
public void setContentDescription(CharSequence text) {
if (contentTitle != null) {
view.setContentDescription(contentTitle + " " + text); //$NON-NLS-1$
} else {
view.setContentDescription(text);
}
}
public void setContentTitle(String text) {
contentTitle = text;
view.setContentDescription(text);
}
public void setText(String text, String subtext) {
this.text = text;
this.subtext = subtext;
if (text != null) {
if (subtext != null)
if (subtext != null) {
setContentDescription(text + " " + subtext); //$NON-NLS-1$
else setContentDescription(text);
} else {
} else {
setContentDescription(text);
}
} else if(subtext != null){
setContentDescription(subtext);
}
if(this.text != null && this.text.length() > 7) {
this.text = this.text.substring(0, 6) +"..";
// if(this.text != null && this.text.length() > 7) {
// this.text = this.text.substring(0, 6) +"..";
// }
if(text == null) {
textView.setText("");
} else {
textView.setText(text);
}
if(subtext == null) {
smallTextView.setText("");
} else {
smallTextView.setText(subtext);
}
updateVisibility(text != null);
requestLayout();
invalidate();
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// ignore attributes
int w = 0;
int h = 0;
if (text != null) {
if (imageDrawable != null) {
w += imageDrawable.getMinimumWidth() + 2 * scaleCoefficient;
}
w += leftMargin;
w += textPaint.measureText(text);
if (subtext != null) {
w += subtextPaint.measureText(subtext) + 2 * scaleCoefficient;
}
h = (int) (5 * scaleCoefficient + Math.max(textPaint.getTextSize(), subtextPaint.getTextSize()));
if (imageDrawable != null) {
h = Math.max(h, (int) (imageDrawable.getMinimumHeight()));
}
}
setWDimensions(w, h);
}
@Override
protected void onDraw(Canvas cv) {
super.onDraw(cv);
if (isVisible()) {
int margin = 0;
if (imageDrawable != null) {
imageDrawable.draw(cv);
margin = (int) (imageDrawable.getBounds().width() + 2 * scaleCoefficient);
}
margin += leftMargin;
drawShadowText(cv, text, margin, getWHeight() - 3 * scaleCoefficient, textPaint);
if (subtext != null) {
drawShadowText(cv, subtext, margin + 2 * scaleCoefficient + textPaint.measureText(text), getWHeight() - 3
* scaleCoefficient, subtextPaint);
}
}
}
public boolean isVisible() {
return text != null && (text.length() > 0 || subtext != null);
}
@Override
public boolean updateInfo(DrawSettings drawSettings) {
protected boolean updateVisibility(boolean visible) {
if (visible != (view.getVisibility() == View.VISIBLE)) {
if (visible) {
view.setVisibility(View.VISIBLE);
} else {
view.setVisibility(View.GONE);
}
view.invalidate();
return true;
}
return false;
}
public boolean isVisible() {
return view.getVisibility() == View.VISIBLE;
}
public boolean updateInfo(DrawSettings drawSettings) {
return false;
}
public void setOnClickListener(OnClickListener onClickListener) {
view.setOnClickListener(onClickListener);
}
}