Refactor lock info actions
This commit is contained in:
parent
367e233454
commit
d87021a8dc
6 changed files with 139 additions and 59 deletions
|
@ -7,8 +7,8 @@
|
|||
android:gravity="center_vertical|center_horizontal"
|
||||
android:paddingTop="0dip"
|
||||
android:paddingBottom="0dip"
|
||||
android:paddingLeft="20dip"
|
||||
android:paddingRight="20dip"
|
||||
android:paddingLeft="12dip"
|
||||
android:paddingRight="12dip"
|
||||
android:clickable="true"
|
||||
android:background="@drawable/quickaction_slider_btn">
|
||||
|
||||
|
|
|
@ -9,6 +9,10 @@
|
|||
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_mode_off">GPX rec</string>
|
||||
<string name="monitoring_mode_on">GPX off</string>
|
||||
<string name="bg_service_sleep_mode_off">Stop background</string>
|
||||
<string name="bg_service_sleep_mode_on">Run in background</string>
|
||||
<string name="gps_wakeup_interval">GPS wakeup interval : %s</string>
|
||||
<string name="int_continuosly">Continuously</string>
|
||||
<string name="screen_is_locked">To unlock screen press lock icon</string>
|
||||
|
@ -34,8 +38,6 @@
|
|||
<string name="map_widget_mini_route">Mini route map</string>
|
||||
<string name="bg_service_screen_lock">Lock screen</string>
|
||||
<string name="bg_service_screen_unlock">Unlock screen</string>
|
||||
<string name="bg_service_sleep_mode_off">Disable Sleep mode</string>
|
||||
<string name="bg_service_sleep_mode_on">Enable Sleep mode</string>
|
||||
<string name="bg_service_screen_lock_toast">The screen is locked</string>
|
||||
<string name="bg_service_interval">Set wake-up interval:</string>
|
||||
<string name="show_cameras_descr">Show speed cameras (may be forbidden in some countries)</string>
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package net.osmand.plus.background;
|
||||
|
||||
import net.londatiga.android.ActionItem;
|
||||
import net.londatiga.android.QuickAction;
|
||||
import net.osmand.plus.NavigationService;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
|
@ -7,20 +9,29 @@ import net.osmand.plus.OsmandSettings;
|
|||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.SettingsActivity;
|
||||
import net.osmand.plus.views.LockInfoControl.LockInfoControlActions;
|
||||
import net.osmand.plus.views.LockInfoControl.ValueHolder;
|
||||
import net.osmand.plus.views.LockInfoControl;
|
||||
import net.osmand.plus.views.MapInfoLayer;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.Preference.OnPreferenceChangeListener;
|
||||
import android.preference.PreferenceCategory;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.view.View;
|
||||
|
||||
public class OsmandBackgroundServicePlugin extends OsmandPlugin {
|
||||
public class OsmandBackgroundServicePlugin extends OsmandPlugin implements LockInfoControlActions {
|
||||
public static final int[] MINUTES = new int[]{2, 3, 5, 10, 15, 30, 45, 60, 90};
|
||||
public static final int[] SECONDS = new int[]{0, 30, 45, 60};
|
||||
private final static boolean REGISTER_BG_SETTINGS = false;
|
||||
private static final String ID = "osmand.backgroundservice";
|
||||
private OsmandSettings settings;
|
||||
private OsmandApplication app;
|
||||
|
@ -54,6 +65,15 @@ public class OsmandBackgroundServicePlugin extends OsmandPlugin {
|
|||
public void registerLayers(MapActivity activity) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateLayers(OsmandMapTileView mapView, MapActivity activity) {
|
||||
MapInfoLayer li = activity.getMapLayers().getMapInfoLayer();
|
||||
LockInfoControl lock = li.getLockInfoControl();
|
||||
if(lock != null && !lock.getLockActions().contains(this)) {
|
||||
lock.getLockActions().add(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void settingsActivityDestroy(final SettingsActivity activity){
|
||||
unregisterReceiver(activity);
|
||||
|
@ -76,6 +96,12 @@ public class OsmandBackgroundServicePlugin extends OsmandPlugin {
|
|||
|
||||
@Override
|
||||
public void settingsActivityCreate(final SettingsActivity activity, PreferenceScreen screen) {
|
||||
if(REGISTER_BG_SETTINGS) {
|
||||
registerBackgroundSettings(activity, screen);
|
||||
}
|
||||
}
|
||||
|
||||
private void registerBackgroundSettings(final SettingsActivity activity, PreferenceScreen screen) {
|
||||
PreferenceScreen grp = screen.getPreferenceManager().createPreferenceScreen(activity);
|
||||
grp.setTitle(R.string.osmand_service);
|
||||
grp.setSummary(R.string.osmand_service_descr);
|
||||
|
@ -120,4 +146,37 @@ public class OsmandBackgroundServicePlugin extends OsmandPlugin {
|
|||
grp.addPreference(activity.createTimeListPreference(settings.SERVICE_OFF_INTERVAL, SECONDS, MINUTES, 1000,
|
||||
R.string.background_service_int, R.string.background_service_int_descr));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLockActions(final QuickAction qa, final LockInfoControl li, final OsmandMapTileView view) {
|
||||
|
||||
final ActionItem bgServiceAction = new ActionItem();
|
||||
final boolean off = view.getApplication().getNavigationService() == null;
|
||||
bgServiceAction.setTitle(view.getResources().getString(!off? R.string.bg_service_sleep_mode_on : R.string.bg_service_sleep_mode_off));
|
||||
// bgServiceAction.setIcon(view.getResources().getDrawable(R.drawable.car_small));
|
||||
bgServiceAction.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final Intent serviceIntent = new Intent(view.getContext(), NavigationService.class);
|
||||
if (view.getApplication().getNavigationService() == null) {
|
||||
final ValueHolder<Integer> vs = new ValueHolder<Integer>();
|
||||
vs.value = view.getSettings().SERVICE_OFF_INTERVAL.get();
|
||||
li.showIntervalChooseDialog(view, view.getContext().getString(R.string.gps_wakeup_interval),
|
||||
view.getContext().getString(R.string.background_router_service), OsmandBackgroundServicePlugin.SECONDS, OsmandBackgroundServicePlugin.MINUTES,
|
||||
vs, new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
view.getSettings().SERVICE_OFF_INTERVAL.set(vs.value);
|
||||
view.getContext().startService(serviceIntent);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
view.getContext().stopService(serviceIntent);
|
||||
}
|
||||
qa.dismiss();
|
||||
}
|
||||
});
|
||||
qa.addActionItem(bgServiceAction);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package net.osmand.plus.monitoring;
|
|||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.londatiga.android.ActionItem;
|
||||
import net.londatiga.android.QuickAction;
|
||||
import net.osmand.LogUtil;
|
||||
import net.osmand.OsmAndFormatter;
|
||||
import net.osmand.plus.ContextMenuAdapter;
|
||||
|
@ -15,6 +17,10 @@ import net.osmand.plus.activities.ApplicationMode;
|
|||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.SavingTrackHelper;
|
||||
import net.osmand.plus.activities.SettingsActivity;
|
||||
import net.osmand.plus.background.OsmandBackgroundServicePlugin;
|
||||
import net.osmand.plus.views.LockInfoControl;
|
||||
import net.osmand.plus.views.LockInfoControl.LockInfoControlActions;
|
||||
import net.osmand.plus.views.LockInfoControl.ValueHolder;
|
||||
import net.osmand.plus.views.MapInfoControl;
|
||||
import net.osmand.plus.views.MapInfoLayer;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
|
@ -24,6 +30,7 @@ import org.apache.commons.logging.Log;
|
|||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.preference.Preference;
|
||||
|
@ -32,7 +39,7 @@ import android.preference.PreferenceCategory;
|
|||
import android.preference.PreferenceScreen;
|
||||
import android.view.View;
|
||||
|
||||
public class OsmandMonitoringPlugin extends OsmandPlugin {
|
||||
public class OsmandMonitoringPlugin extends OsmandPlugin implements LockInfoControlActions {
|
||||
private static final String ID = "osmand.monitoring";
|
||||
private OsmandSettings settings;
|
||||
private OsmandApplication app;
|
||||
|
@ -80,6 +87,10 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
|
|||
if(monitoringControl == null) {
|
||||
registerLayers(activity);
|
||||
}
|
||||
LockInfoControl lock = activity.getMapLayers().getMapInfoLayer().getLockInfoControl();
|
||||
if(lock != null && !lock.getLockActions().contains(this)) {
|
||||
lock.getLockActions().add(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -240,4 +251,35 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
|
|||
return monitoringControl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLockActions(final QuickAction qa, final LockInfoControl li, final OsmandMapTileView view) {
|
||||
final ActionItem bgServiceAction = new ActionItem();
|
||||
final boolean off = !view.getSettings().SAVE_TRACK_TO_GPX.get();
|
||||
bgServiceAction.setTitle(view.getResources().getString(off? R.string.monitoring_mode_off : R.string.monitoring_mode_on));
|
||||
bgServiceAction.setIcon(view.getResources().getDrawable(!off?R.drawable.monitoring_rec_big:R.drawable.monitoring_rec_inactive));
|
||||
bgServiceAction.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (off) {
|
||||
final ValueHolder<Integer> vs = new ValueHolder<Integer>();
|
||||
vs.value = view.getSettings().SAVE_TRACK_INTERVAL.get();
|
||||
li.showIntervalChooseDialog(view, view.getContext().getString(R.string.save_track_interval) + " : %s",
|
||||
view.getContext().getString(R.string.save_track_to_gpx), OsmandBackgroundServicePlugin.SECONDS, OsmandBackgroundServicePlugin.MINUTES,
|
||||
vs, new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
view.getSettings().SAVE_TRACK_INTERVAL.set(vs.value);
|
||||
view.getSettings().SAVE_TRACK_TO_GPX.set(true);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
view.getSettings().SAVE_TRACK_TO_GPX.set(false);
|
||||
}
|
||||
qa.dismiss();
|
||||
}
|
||||
});
|
||||
qa.addActionItem(bgServiceAction);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,17 +1,16 @@
|
|||
package net.osmand.plus.views;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.londatiga.android.ActionItem;
|
||||
import net.londatiga.android.QuickAction;
|
||||
import net.osmand.access.AccessibleToast;
|
||||
import net.osmand.plus.NavigationService;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.background.OsmandBackgroundServicePlugin;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.AlertDialog.Builder;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.Gravity;
|
||||
import android.view.MotionEvent;
|
||||
|
@ -31,6 +30,21 @@ public class LockInfoControl {
|
|||
private View transparentLockView;
|
||||
private Drawable lockEnabled;
|
||||
private Drawable lockDisabled;
|
||||
private List<LockInfoControlActions> lockActions = new ArrayList<LockInfoControl.LockInfoControlActions>();
|
||||
|
||||
public interface LockInfoControlActions {
|
||||
|
||||
public void addLockActions(QuickAction qa, LockInfoControl li, OsmandMapTileView view);
|
||||
}
|
||||
|
||||
public void addLockActions(LockInfoControlActions la){
|
||||
lockActions.add(la);
|
||||
}
|
||||
|
||||
|
||||
public List<LockInfoControlActions> getLockActions() {
|
||||
return lockActions;
|
||||
}
|
||||
|
||||
public ImageView createLockScreenWidget(final OsmandMapTileView view) {
|
||||
final ImageView lockView = new ImageView(view.getContext());
|
||||
|
@ -55,7 +69,7 @@ public class LockInfoControl {
|
|||
}
|
||||
|
||||
private void showBgServiceQAction(final ImageView lockView, final OsmandMapTileView view) {
|
||||
final QuickAction bgAction = new QuickAction(lockView);
|
||||
final QuickAction qa = new QuickAction(lockView);
|
||||
|
||||
if (transparentLockView == null) {
|
||||
transparentLockView = new FrameLayout(view.getContext());
|
||||
|
@ -112,30 +126,16 @@ public class LockInfoControl {
|
|||
parent.removeView(transparentLockView);
|
||||
}
|
||||
isScreenLocked = !isScreenLocked;
|
||||
bgAction.dismiss();
|
||||
qa.dismiss();
|
||||
updateLockIcon(view, lockView);
|
||||
}
|
||||
});
|
||||
bgAction.addActionItem(lockScreenAction);
|
||||
qa.addActionItem(lockScreenAction);
|
||||
|
||||
final ActionItem bgServiceAction = new ActionItem();
|
||||
final boolean off = view.getApplication().getNavigationService() == null;
|
||||
bgServiceAction.setTitle(view.getResources().getString(off? R.string.bg_service_sleep_mode_on : R.string.bg_service_sleep_mode_off));
|
||||
// bgServiceAction.setIcon(view.getResources().getDrawable(R.drawable.car_small)); //TODO icon
|
||||
bgServiceAction.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent serviceIntent = new Intent(view.getContext(), NavigationService.class);
|
||||
if (view.getApplication().getNavigationService() == null) {
|
||||
startBgService(serviceIntent, view);
|
||||
} else {
|
||||
view.getContext().stopService(serviceIntent);
|
||||
}
|
||||
bgAction.dismiss();
|
||||
}
|
||||
});
|
||||
bgAction.addActionItem(bgServiceAction);
|
||||
bgAction.show();
|
||||
for(LockInfoControlActions la : lockActions){
|
||||
la.addLockActions(qa, this, view);
|
||||
}
|
||||
qa.show();
|
||||
|
||||
}
|
||||
|
||||
|
@ -143,7 +143,7 @@ public class LockInfoControl {
|
|||
public T value;
|
||||
}
|
||||
|
||||
private void showIntervalChooseDialog(final OsmandMapTileView view, final String patternMsg,
|
||||
public void showIntervalChooseDialog(final OsmandMapTileView view, final String patternMsg,
|
||||
String startText, final int[] seconds, final int[] minutes, final ValueHolder<Integer> v, OnClickListener onclick){
|
||||
final Context ctx = view.getContext();
|
||||
Builder dlg = new AlertDialog.Builder(view.getContext());
|
||||
|
@ -206,17 +206,6 @@ public class LockInfoControl {
|
|||
dlg.setNegativeButton(R.string.default_buttons_cancel, null);
|
||||
dlg.show();
|
||||
}
|
||||
private void startBgService(final Intent serviceIntent, final OsmandMapTileView view) {
|
||||
final ValueHolder<Integer> v = new ValueHolder<Integer>();
|
||||
v.value = view.getSettings().SERVICE_OFF_INTERVAL.get();
|
||||
showIntervalChooseDialog(view, view.getContext().getString(R.string.gps_wakeup_interval),
|
||||
view.getContext().getString(R.string.bg_service_sleep_mode_on), OsmandBackgroundServicePlugin.SECONDS, OsmandBackgroundServicePlugin.MINUTES,
|
||||
v, new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
view.getSettings().SERVICE_OFF_INTERVAL.set(v.value);
|
||||
view.getContext().startService(serviceIntent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -488,28 +488,16 @@ public class MapInfoLayer extends OsmandMapLayer {
|
|||
}
|
||||
private View createGlobusAndProgress(){
|
||||
Drawable globusDrawable = view.getResources().getDrawable(R.drawable.globus);
|
||||
// FrameLayout fl = new FrameLayout(view.getContext());
|
||||
// FrameLayout.LayoutParams fparams = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||
ImageView globus = new ImageView(view.getContext());
|
||||
globus.setImageDrawable(globusDrawable);
|
||||
globus.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
map.getMapLayers().selectMapLayer(view);
|
||||
map.getMapLayers().openLayerSelectionDialog(view);
|
||||
//map.getMapLayers().selectMapLayer(view);
|
||||
}
|
||||
});
|
||||
return globus;
|
||||
// fl.addView(globus, fparams);
|
||||
// fparams = new FrameLayout.LayoutParams(globusDrawable.getMinimumWidth(), globusDrawable.getMinimumHeight());
|
||||
// progressBar = new View(view.getContext());
|
||||
// progressBar.setOnClickListener(new View.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(View v) {
|
||||
// map.getMapLayers().selectMapLayer(view);
|
||||
// }
|
||||
// });
|
||||
// fl.addView(progressBar, fparams);
|
||||
// return fl;
|
||||
}
|
||||
|
||||
private ImageView createBackToLocation(final MapActivity map){
|
||||
|
|
Loading…
Reference in a new issue