OsmandMonitoringPlugin info control added, new icons added, bufixes

This commit is contained in:
aFedasenka 2012-07-07 22:54:47 +02:00
parent 192ce77509
commit 3735eaa88a
6 changed files with 99 additions and 42 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

View file

@ -9,6 +9,9 @@
1. All your modified/created strings are in the top of the file (to make easier find what's translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="monitoring_info_control">Info Control</string>
<string name="monitoring_info_control_desc">Show monitoring state on the info pane</string>
<string name="global_app_allocated_memory_descr">Allocated memory %1$s MB (Android limit %2$s MB, Dalvik %3$s MB).</string>
<string name="global_app_allocated_memory">Allocated memory</string>
<string name="native_app_allocated_memory_descr">Total native memory allocated by app %1$s MB (Dalvik %2$s MB, other %3$s MB).

View file

@ -578,6 +578,8 @@ public class OsmandSettings {
public final CommonPreference<String> LIVE_MONITORING_URL = new StringPreference("live_monitoring_url",
"http://example.com?lat={0}&lon={1}&timestamp={2}&hdop={3}&altitude={4}&speed={5}").makeGlobal();
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<Boolean> SHOW_MONITORING_CONTROL = new BooleanPreference("show_monitoring_control", false).makeProfile();
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<Boolean> SHOW_OSM_BUGS = new BooleanPreference("show_osm_bugs", false).makeGlobal();

View file

@ -12,6 +12,7 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.activities.SettingsActivity;
import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.TextInfoControl;
import org.apache.commons.logging.Log;
@ -22,20 +23,31 @@ import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceCategory;
import android.preference.PreferenceScreen;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Interpolator;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
public class OsmandMonitoringPlugin extends OsmandPlugin {
private static final String ID = "osmand.monitoring";
private OsmandSettings settings;
private OsmandApplication app;
private TextInfoControl monitoringControl;
private static final Log log = LogUtil.getLog(OsmandMonitoringPlugin.class);
private TextInfoControl monitoringControl;
private Drawable monitoring_rec;
private Drawable monitoring;
private Paint paintText;
private Paint paintSubText;
private MapInfoLayer mapInfoLayer;
private Handler uiHandler;
public OsmandMonitoringPlugin(OsmandApplication app) {
this.app = app;
@ -54,24 +66,42 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
public String getId() {
return ID;
}
@Override
public String getDescription() {
return app.getString(R.string.osmand_monitoring_description);
}
@Override
public String getName() {
return app.getString(R.string.monitor_preferences);
}
@Override
public void registerLayers(MapActivity activity) {
MapInfoLayer mapInfoLayer = ((MapActivity)activity).getMapLayers().getMapInfoLayer();
if ((mapInfoLayer != null) && (monitoringControl == null))
mapInfoLayer.addRightStack(createMonitoringControl(activity));
//create if needed a textInfoControl
createMonitoringControl(activity);
//if right-stack has already been added -> return;
if (monitoringControl.getParent() != null) {
return;
}
//if right-stack has not yet been added -> add right-stack;
mapInfoLayer = activity.getMapLayers().getMapInfoLayer();
if (mapInfoLayer != null) {
mapInfoLayer.addRightStack(monitoringControl);
}
}
@Override
public void registerMapContextMenuActions(final MapActivity mapActivity, final double latitude, final double longitude, ContextMenuAdapter adapter,
Object selectedObj) {
public void updateLayers(OsmandMapTileView mapView, MapActivity activity) {
registerLayers(activity);
}
@Override
public void registerMapContextMenuActions(final MapActivity mapActivity,
final double latitude, final double longitude,
ContextMenuAdapter adapter, Object selectedObj) {
OnContextMenuClick listener = new OnContextMenuClick() {
@Override
public void onContextMenuClick(int resId, int pos, boolean isChecked, DialogInterface dialog) {
@ -82,7 +112,6 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
};
adapter.registerItem(R.string.context_menu_item_add_waypoint, R.drawable.list_activities_gpx_waypoint, listener, -1);
}
@Override
public void settingsActivityCreate(final SettingsActivity activity, PreferenceScreen screen) {
@ -102,11 +131,14 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
cat.setTitle(R.string.save_track_to_gpx);
grp.addPreference(cat);
cat.addPreference(activity.createCheckBoxPreference(settings.SAVE_TRACK_TO_GPX, R.string.save_track_to_gpx,
cat.addPreference(activity.createCheckBoxPreference(
settings.SAVE_TRACK_TO_GPX, R.string.save_track_to_gpx,
R.string.save_track_to_gpx_descrp));
cat.addPreference(activity.createTimeListPreference(settings.SAVE_TRACK_INTERVAL, new int[] { 1, 2, 3, 5, 10, 15, 20, 30 },
new int[] { 1, 2, 3, 5 }, 1, R.string.save_track_interval, R.string.save_track_interval_descr));
cat.addPreference(activity.createTimeListPreference(
settings.SAVE_TRACK_INTERVAL, new int[] { 1, 2, 3, 5, 10, 15,
20, 30 }, new int[] { 1, 2, 3, 5 }, 1,
R.string.save_track_interval,
R.string.save_track_interval_descr));
Preference pref = new Preference(activity);
pref.setTitle(R.string.save_current_track);
@ -125,23 +157,35 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
}
});
cat.addPreference(pref);
CheckBoxPreference infoControlPreference = activity
.createCheckBoxPreference(settings.SHOW_MONITORING_CONTROL,
R.string.monitoring_info_control,
R.string.monitoring_info_control_desc);
cat.addPreference(infoControlPreference);
cat = new PreferenceCategory(activity);
cat.setTitle(R.string.live_monitoring);
grp.addPreference(cat);
cat.addPreference(activity.createCheckBoxPreference(settings.LIVE_MONITORING, R.string.live_monitoring,
cat.addPreference(activity.createCheckBoxPreference(
settings.LIVE_MONITORING, R.string.live_monitoring,
R.string.live_monitoring_descr));
cat.addPreference(activity.createEditTextPreference(settings.LIVE_MONITORING_URL, R.string.live_monitoring_url,
cat.addPreference(activity.createEditTextPreference(
settings.LIVE_MONITORING_URL, R.string.live_monitoring_url,
R.string.live_monitoring_url_descr));
cat.addPreference(activity.createTimeListPreference(settings.LIVE_MONITORING_INTERVAL, new int[] { 1, 2, 3, 5, 10, 15, 20, 30 },
new int[] { 1, 2, 3, 5 }, 1, R.string.live_monitoring_interval, R.string.live_monitoring_interval_descr));
cat.addPreference(activity.createTimeListPreference(
settings.LIVE_MONITORING_INTERVAL, new int[] { 1, 2, 3, 5, 10,
15, 20, 30 }, new int[] { 1, 2, 3, 5 }, 1,
R.string.live_monitoring_interval,
R.string.live_monitoring_interval_descr));
}
private void saveCurrentTracks(final SavingTrackHelper helper, final SettingsActivity activity) {
activity.progressDlg = ProgressDialog.show(activity, activity.getString(R.string.saving_gpx_tracks), activity.getString(R.string.saving_gpx_tracks), true);
activity.progressDlg = ProgressDialog.show(activity,
activity.getString(R.string.saving_gpx_tracks),
activity.getString(R.string.saving_gpx_tracks), true);
final ProgressDialogImplementation impl = new ProgressDialogImplementation(activity.progressDlg);
impl.setRunnable("SavingGPX", new Runnable() { //$NON-NLS-1$
@Override
@ -161,55 +205,63 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
}
/**
* @return the control to be added on a MapInfoLayer
* creates (if it wasn't created previously) the control to be added on a MapInfoLayer
* that shows a monitoring state (recorded/stopped)
*/
private TextInfoControl createMonitoringControl(final MapActivity mapActivity) {
private void createMonitoringControl(final MapActivity mapActivity) {
if (monitoringControl != null) {
monitoringControl.updateInfo();
return;
}
paintText = new Paint();
paintText.setStyle(Style.FILL_AND_STROKE);
paintText.setColor(Color.BLACK);
paintText.setTextSize(23 * MapInfoLayer.scaleCoefficient);
paintText.setAntiAlias(true);
paintText.setStrokeWidth(4);
paintSubText = new Paint();
paintSubText.setStyle(Style.FILL_AND_STROKE);
paintSubText.setColor(Color.BLACK);
paintSubText.setTextSize(15 * MapInfoLayer.scaleCoefficient);
paintSubText.setAntiAlias(true);
final Drawable monitoring_rec = mapActivity.getMapView().getResources().getDrawable(R.drawable.monitoring_rec);
final Drawable monitoring = mapActivity.getMapView().getResources().getDrawable(R.drawable.monitoring);
monitoringControl = new TextInfoControl(mapActivity, 0, paintText, paintSubText) {
@Override
public boolean updateInfo() {
//TODO
if (settings.SAVE_TRACK_TO_GPX.get()) {
setImageDrawable(monitoring);
return true;
}
setImageDrawable(monitoring_rec);
setText(getMonitoringControlTxt(), null);
setImageDrawable(getMonitoringControlImg(mapActivity));
return true;
}
};
monitoringControl.updateInfo();
monitoringControl.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Boolean isTrackMonitored = settings.SAVE_TRACK_TO_GPX.get();
boolean isTrackMonitored = settings.SAVE_TRACK_TO_GPX.get();
settings.SAVE_TRACK_TO_GPX.set(!isTrackMonitored);
if (isTrackMonitored) {
monitoringControl.setImageDrawable(monitoring);
monitoringControl.setText("rec", null);
return;
}
monitoringControl.setImageDrawable(monitoring_rec);
monitoringControl.setText("pause", null);
monitoringControl.updateInfo();
}
});
monitoringControl.setText("rec", null);
monitoringControl.setImageDrawable(monitoring);
return monitoringControl;
});
}
}
private String getMonitoringControlTxt() {
if (!settings.SHOW_MONITORING_CONTROL.get())
return null;
if(settings.SAVE_TRACK_TO_GPX.get())
return "pause ";
return "record";
}
private Drawable getMonitoringControlImg(MapActivity mapActivity) {
if (monitoring_rec == null)
monitoring_rec = mapActivity.getMapView().getResources().getDrawable(R.drawable.monitoring_rec_big);
if (monitoring == null)
monitoring = mapActivity.getMapView().getResources().getDrawable(R.drawable.monitoring_rec_inactive);
if (settings.SAVE_TRACK_TO_GPX.get())
return monitoring_rec;
return monitoring;
}
}