From 61daa4aac3074a4bcbffc3f9f2ee24bb88180be7 Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Mon, 27 Mar 2017 15:44:38 +0300 Subject: [PATCH] Fix #3217 --- .../activities/actions/StartGPSStatus.java | 9 ++- .../monitoring/OsmandMonitoringPlugin.java | 16 +++-- .../mapwidgets/MapInfoWidgetsFactory.java | 71 +------------------ 3 files changed, 18 insertions(+), 78 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/actions/StartGPSStatus.java b/OsmAnd/src/net/osmand/plus/activities/actions/StartGPSStatus.java index 267187b1bc..be0f3e86f7 100644 --- a/OsmAnd/src/net/osmand/plus/activities/actions/StartGPSStatus.java +++ b/OsmAnd/src/net/osmand/plus/activities/actions/StartGPSStatus.java @@ -22,6 +22,7 @@ import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; +import net.osmand.AndroidUtils; import net.osmand.plus.R; import net.osmand.plus.Version; import net.osmand.plus.activities.MapActivity; @@ -105,11 +106,14 @@ public class StartGPSStatus extends OsmAndAction { builder.setTitle(R.string.gps_status); LinearLayout ll = new LinearLayout(activity); final ListView lv = new ListView(activity); - lv.setPadding(7, 3, 7, 0); + final int dp24 = AndroidUtils.dpToPx(mapActivity, 24f); + final int dp12 = AndroidUtils.dpToPx(mapActivity, 12f); + final int dp8 = AndroidUtils.dpToPx(mapActivity, 8f); + lv.setPadding(0, dp8, 0, dp8); final CheckBox cb = new CheckBox(activity); cb.setText(R.string.shared_string_remember_my_choice); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); - lp.setMargins(7, 10, 7, 0); + lp.setMargins(dp24, dp8, dp8, dp24); cb.setLayoutParams(lp); final int layout = R.layout.list_menu_item_native; @@ -118,6 +122,7 @@ public class StartGPSStatus extends OsmAndAction { public View getView(int position, View convertView, ViewGroup parent) { View v = mapActivity.getLayoutInflater().inflate(layout, null); TextView tv = (TextView)v.findViewById(R.id.title); + tv.setPadding(dp12, 0, dp24, 0); tv.setText(getItem(position).stringRes); v.findViewById(R.id.toggle_item).setVisibility(View.INVISIBLE); return v; diff --git a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java index 2681bf4b86..9ef36172e0 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java @@ -17,6 +17,7 @@ import android.widget.SeekBar; import android.widget.SeekBar.OnSeekBarChangeListener; import android.widget.TextView; +import net.osmand.AndroidUtils; import net.osmand.Location; import net.osmand.ValueHolder; import net.osmand.plus.ApplicationMode; @@ -235,7 +236,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin { AlertDialog.Builder bld = new AlertDialog.Builder(map); final TIntArrayList items = new TIntArrayList(); - if(wasTrackMonitored) { + if (wasTrackMonitored) { items.add(R.string.gpx_monitoring_stop); items.add(R.string.gpx_start_new_segment); if(settings.LIVE_MONITORING.get()) { @@ -247,7 +248,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin { } else { items.add(R.string.gpx_monitoring_start); } - if(app.getSavingTrackHelper().hasDataToSave()) { + if (app.getSavingTrackHelper().hasDataToSave()) { items.add(R.string.save_current_track); } String[] strings = new String[items.size()]; @@ -392,13 +393,14 @@ public class OsmandMonitoringPlugin extends OsmandPlugin { final String patternMsg, final int[] seconds, final int[] minutes, final ValueHolder choice, final ValueHolder v, DisplayMetrics dm) { LinearLayout ll = new LinearLayout(uiCtx); + final int dp24 = AndroidUtils.dpToPx(uiCtx, 24f); + final int dp8 = AndroidUtils.dpToPx(uiCtx, 8f); final TextView tv = new TextView(uiCtx); - tv.setPadding((int)(7 * dm.density), (int)(3 * dm.density), (int)(7* dm.density), 0); + tv.setPadding(dp24, dp8 * 2, dp24, dp8); tv.setText(String.format(patternMsg, uiCtx.getString(R.string.int_continuosly))); - - + SeekBar sp = new SeekBar(uiCtx); - sp.setPadding((int)(7 * dm.density), (int)(5 * dm.density), (int)(7* dm.density), 0); + sp.setPadding(dp24 + dp8, dp8, dp24 + dp8, dp8); final int secondsLength = seconds.length; final int minutesLength = minutes.length; sp.setMax(secondsLength + minutesLength - 1); @@ -452,7 +454,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin { cb.setText(R.string.shared_string_remember_my_choice); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); - lp.setMargins((int)(7* dm.density), (int)(10* dm.density), (int)(7* dm.density), 0); + lp.setMargins(dp24, dp8 * 2, dp24, 0); cb.setLayoutParams(lp); cb.setOnCheckedChangeListener(new OnCheckedChangeListener() { diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java index 2bfbf4c103..f575ee2155 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java @@ -1,30 +1,21 @@ package net.osmand.plus.views.mapwidgets; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; import android.graphics.drawable.Drawable; -import android.support.v7.app.AlertDialog; -import android.util.DisplayMetrics; import android.view.View; import android.view.View.OnClickListener; -import android.view.WindowManager; import android.widget.ImageButton; import android.widget.ImageView; -import android.widget.LinearLayout; import android.widget.TextView; + import net.osmand.Location; -import net.osmand.ValueHolder; import net.osmand.binary.RouteDataObject; import net.osmand.plus.CurrentPositionHelper; -import net.osmand.plus.NavigationService; 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; import net.osmand.plus.activities.actions.StartGPSStatus; import net.osmand.plus.dashboard.DashboardOnMap.DashboardType; @@ -33,7 +24,6 @@ import net.osmand.plus.helpers.WaypointDialogHelper; import net.osmand.plus.helpers.WaypointHelper; import net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper; import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu; -import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.routing.RouteDirectionInfo; import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.views.OsmandMapLayer.DrawSettings; @@ -110,64 +100,7 @@ public class MapInfoWidgetsFactory { gpsInfoControl.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { - if (app.getNavigationService() != null) { - AlertDialog.Builder dlg = new AlertDialog.Builder(map); - dlg.setTitle(app.getString(R.string.sleep_mode_stop_dialog)); - - //Show currently active wake-up interval - int soi = app.getNavigationService().getServiceOffInterval(); - if (soi == 0) { - dlg.setMessage(app.getString(R.string.gps_wake_up_timer) + ": " + app.getString(R.string.int_continuosly)); - } else if (soi <= 90000) { - dlg.setMessage(app.getString(R.string.gps_wake_up_timer) + ": " + Integer.toString(soi / 1000) + " " + app.getString(R.string.int_seconds)); - } else { - dlg.setMessage(app.getString(R.string.gps_wake_up_timer) + ": " + Integer.toString(soi / 1000 / 60) + " " + app.getString(R.string.int_min)); - } - - dlg.setPositiveButton(app.getString(R.string.keep_navigation_service), null); - dlg.setNegativeButton(app.getString(R.string.stop_navigation_service), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - Intent serviceIntent = new Intent(app, NavigationService.class); - app.stopService(serviceIntent); - } - }); - dlg.show(); - - } else { - final ValueHolder vs = new ValueHolder(); - vs.value = 0; - final AlertDialog[] dlgshow = new AlertDialog[1]; - AlertDialog.Builder dlg = new AlertDialog.Builder(map); - dlg.setTitle(app.getString(R.string.enable_sleep_mode)); - WindowManager mgr = (WindowManager) map.getSystemService(Context.WINDOW_SERVICE); - DisplayMetrics dm = new DisplayMetrics(); - mgr.getDefaultDisplay().getMetrics(dm); - LinearLayout ll = OsmandMonitoringPlugin.createIntervalChooseLayout(map, - app.getString(R.string.gps_wake_up_timer) + " : %s", - OsmandMonitoringPlugin.SECONDS, - OsmandMonitoringPlugin.MINUTES, - null, vs, dm); - if (Version.isGpsStatusEnabled(app)) { - dlg.setNeutralButton(R.string.gps_status, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - new StartGPSStatus(map).run(); - } - }); - } - dlg.setView(ll); - dlg.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - app.startNavigationService(NavigationService.USED_BY_WAKE_UP, vs.value); - } - }); - dlg.setNegativeButton(R.string.shared_string_cancel, null); - dlgshow[0] = dlg.show(); - - } - + new StartGPSStatus(map).run(); } }); return gpsInfoControl;