Add lock control
This commit is contained in:
parent
00d23f7ad4
commit
8a449fb194
7 changed files with 148 additions and 98 deletions
|
@ -9,6 +9,8 @@
|
||||||
1. All your modified/created strings are in the top of the file (to make easier find what's translated).
|
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
|
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="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>
|
<string name="screen_is_locked">To unlock screen press lock icon</string>
|
||||||
<string name="map_widget_top_text">Street name</string>
|
<string name="map_widget_top_text">Street name</string>
|
||||||
<string name="map_widget_config">Configuration</string>
|
<string name="map_widget_config">Configuration</string>
|
||||||
|
|
|
@ -93,8 +93,17 @@ public class NavigationService extends Service implements LocationListener {
|
||||||
handler = new Handler();
|
handler = new Handler();
|
||||||
settings = ((OsmandApplication) getApplication()).getSettings();
|
settings = ((OsmandApplication) getApplication()).getSettings();
|
||||||
serviceOffInterval = settings.SERVICE_OFF_INTERVAL.get();
|
serviceOffInterval = settings.SERVICE_OFF_INTERVAL.get();
|
||||||
serviceOffProvider = settings.SERVICE_OFF_PROVIDER.get();
|
// use only gps provider
|
||||||
serviceError = settings.SERVICE_OFF_WAIT_INTERVAL.get();
|
serviceOffProvider = LocationManager.GPS_PROVIDER;
|
||||||
|
serviceError = serviceOffInterval / 5;
|
||||||
|
// 1. not more than 12 mins
|
||||||
|
serviceError = Math.min(serviceError, 12 * 60 * 1000);
|
||||||
|
// 2. not less than 30 seconds
|
||||||
|
serviceError = Math.max(serviceError, 30 * 1000);
|
||||||
|
// 3. not more than serviceOffInterval
|
||||||
|
serviceError = Math.min(serviceError, serviceOffInterval);
|
||||||
|
|
||||||
|
|
||||||
savingTrackHelper = ((OsmandApplication) getApplication()).getSavingTrackHelper();
|
savingTrackHelper = ((OsmandApplication) getApplication()).getSavingTrackHelper();
|
||||||
liveMonitoringHelper = ((OsmandApplication) getApplication()).getLiveMonitoringHelper();
|
liveMonitoringHelper = ((OsmandApplication) getApplication()).getLiveMonitoringHelper();
|
||||||
|
|
||||||
|
|
|
@ -1239,9 +1239,6 @@ public class OsmandSettings {
|
||||||
// this value string is synchronized with settings_pref.xml preference name
|
// this value string is synchronized with settings_pref.xml preference name
|
||||||
public static final String SERVICE_OFF_ENABLED = "service_off_enabled"; //$NON-NLS-1$
|
public static final String SERVICE_OFF_ENABLED = "service_off_enabled"; //$NON-NLS-1$
|
||||||
|
|
||||||
// this value string is synchronized with settings_pref.xml preference name
|
|
||||||
public final OsmandPreference<String> SERVICE_OFF_PROVIDER = new StringPreference("service_off_provider", LocationManager.GPS_PROVIDER).makeGlobal();
|
|
||||||
|
|
||||||
// this value string is synchronized with settings_pref.xml preference name
|
// this value string is synchronized with settings_pref.xml preference name
|
||||||
public final OsmandPreference<Integer> SERVICE_OFF_INTERVAL = new IntPreference("service_off_interval",
|
public final OsmandPreference<Integer> SERVICE_OFF_INTERVAL = new IntPreference("service_off_interval",
|
||||||
5 * 60 * 1000).makeGlobal();
|
5 * 60 * 1000).makeGlobal();
|
||||||
|
@ -1249,10 +1246,6 @@ public class OsmandSettings {
|
||||||
public final CommonPreference<Boolean> SHOW_CURRENT_GPX_TRACK =
|
public final CommonPreference<Boolean> SHOW_CURRENT_GPX_TRACK =
|
||||||
new BooleanPreference("show_current_gpx_track", false).makeGlobal().cache();
|
new BooleanPreference("show_current_gpx_track", false).makeGlobal().cache();
|
||||||
|
|
||||||
// this value string is synchronized with settings_pref.xml preference name
|
|
||||||
public final OsmandPreference<Integer> SERVICE_OFF_WAIT_INTERVAL = new IntPreference("service_off_wait_interval",
|
|
||||||
90 * 1000).makeGlobal();
|
|
||||||
|
|
||||||
public final OsmandPreference<String> CONTRIBUTION_INSTALL_APP_DATE = new StringPreference("CONTRIBUTION_INSTALL_APP_DATE", null).makeGlobal();
|
public final OsmandPreference<String> CONTRIBUTION_INSTALL_APP_DATE = new StringPreference("CONTRIBUTION_INSTALL_APP_DATE", null).makeGlobal();
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.location.LocationManager;
|
|
||||||
import android.preference.CheckBoxPreference;
|
import android.preference.CheckBoxPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.Preference.OnPreferenceChangeListener;
|
import android.preference.Preference.OnPreferenceChangeListener;
|
||||||
|
@ -118,14 +117,7 @@ public class OsmandBackgroundServicePlugin extends OsmandPlugin {
|
||||||
routeServiceEnabled.setKey(OsmandSettings.SERVICE_OFF_ENABLED);
|
routeServiceEnabled.setKey(OsmandSettings.SERVICE_OFF_ENABLED);
|
||||||
grp.addPreference(routeServiceEnabled);
|
grp.addPreference(routeServiceEnabled);
|
||||||
|
|
||||||
String[] entries = new String[]{app.getString(R.string.gps_provider), app.getString(R.string.network_provider)};
|
|
||||||
String[] entrieValues = new String[]{LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER};
|
|
||||||
grp.addPreference(activity.createListPreference(settings.SERVICE_OFF_PROVIDER, entries, entrieValues,
|
|
||||||
R.string.background_service_provider, R.string.background_service_provider_descr));
|
|
||||||
|
|
||||||
grp.addPreference(activity.createTimeListPreference(settings.SERVICE_OFF_INTERVAL, SECONDS, MINUTES, 1000,
|
grp.addPreference(activity.createTimeListPreference(settings.SERVICE_OFF_INTERVAL, SECONDS, MINUTES, 1000,
|
||||||
R.string.background_service_int, R.string.background_service_int_descr));
|
R.string.background_service_int, R.string.background_service_int_descr));
|
||||||
grp.addPreference(activity.createTimeListPreference(settings.SERVICE_OFF_WAIT_INTERVAL,new int[]{15, 30, 45, 60, 90}, new int[]{2, 3, 5, 10}, 1000,
|
|
||||||
R.string.background_service_wait_int, R.string.background_service_wait_int_descr));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,15 +5,24 @@ import net.londatiga.android.QuickAction;
|
||||||
import net.osmand.access.AccessibleToast;
|
import net.osmand.access.AccessibleToast;
|
||||||
import net.osmand.plus.NavigationService;
|
import net.osmand.plus.NavigationService;
|
||||||
import net.osmand.plus.R;
|
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.content.Intent;
|
||||||
import android.graphics.Rect;
|
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
import android.widget.LinearLayout.LayoutParams;
|
import android.widget.LinearLayout.LayoutParams;
|
||||||
|
import android.widget.SeekBar;
|
||||||
|
import android.widget.SeekBar.OnSeekBarChangeListener;
|
||||||
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
public class LockInfoControl {
|
public class LockInfoControl {
|
||||||
|
@ -53,17 +62,6 @@ public class LockInfoControl {
|
||||||
FrameLayout.LayoutParams fparams = new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT,
|
FrameLayout.LayoutParams fparams = new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT,
|
||||||
Gravity.CENTER);
|
Gravity.CENTER);
|
||||||
transparentLockView.setLayoutParams(fparams);
|
transparentLockView.setLayoutParams(fparams);
|
||||||
}
|
|
||||||
final FrameLayout parent = (FrameLayout) view.getParent();
|
|
||||||
final ActionItem lockScreenAction = new ActionItem();
|
|
||||||
lockScreenAction.setTitle(view.getResources().getString(
|
|
||||||
isScreenLocked ? R.string.bg_service_screen_unlock : R.string.bg_service_screen_lock));
|
|
||||||
lockScreenAction.setIcon(view.getResources().getDrawable(isScreenLocked ? R.drawable.lock_enabled : R.drawable.lock_disabled));
|
|
||||||
lockScreenAction.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
if (!isScreenLocked) {
|
|
||||||
parent.addView(transparentLockView);
|
|
||||||
transparentLockView.setOnTouchListener(new View.OnTouchListener() {
|
transparentLockView.setOnTouchListener(new View.OnTouchListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouch(View v, MotionEvent event) {
|
public boolean onTouch(View v, MotionEvent event) {
|
||||||
|
@ -97,7 +95,19 @@ public class LockInfoControl {
|
||||||
}
|
}
|
||||||
}, 300);
|
}, 300);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
final FrameLayout parent = (FrameLayout) view.getParent();
|
||||||
|
final ActionItem lockScreenAction = new ActionItem();
|
||||||
|
lockScreenAction.setTitle(view.getResources().getString(
|
||||||
|
isScreenLocked ? R.string.bg_service_screen_unlock : R.string.bg_service_screen_lock));
|
||||||
|
lockScreenAction.setIcon(view.getResources().getDrawable(isScreenLocked ? R.drawable.lock_enabled : R.drawable.lock_disabled));
|
||||||
|
lockScreenAction.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (!isScreenLocked) {
|
||||||
|
parent.addView(transparentLockView);
|
||||||
} else {
|
} else {
|
||||||
parent.removeView(transparentLockView);
|
parent.removeView(transparentLockView);
|
||||||
}
|
}
|
||||||
|
@ -117,7 +127,7 @@ public class LockInfoControl {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
Intent serviceIntent = new Intent(view.getContext(), NavigationService.class);
|
Intent serviceIntent = new Intent(view.getContext(), NavigationService.class);
|
||||||
if (view.getApplication().getNavigationService() == null) {
|
if (view.getApplication().getNavigationService() == null) {
|
||||||
view.getContext().startService(serviceIntent);
|
startBgService(serviceIntent, view);
|
||||||
} else {
|
} else {
|
||||||
view.getContext().stopService(serviceIntent);
|
view.getContext().stopService(serviceIntent);
|
||||||
}
|
}
|
||||||
|
@ -128,47 +138,85 @@ public class LockInfoControl {
|
||||||
bgAction.show();
|
bgAction.show();
|
||||||
|
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
private void createIntervalRadioGrp(final QuickAction mQuickAction, OsmandMapTileView view) {
|
|
||||||
final OsmandSettings settings = view.getSettings();
|
|
||||||
LayoutInflater inflater = (LayoutInflater) view.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
||||||
final View bgServiceView = inflater.inflate(R.layout.background_service_int, null);
|
|
||||||
final FrameLayout parent = (FrameLayout) view.getParent();
|
|
||||||
FrameLayout.LayoutParams fparams = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER);
|
|
||||||
fparams.setMargins(0, 30, 0, 30);
|
|
||||||
bgServiceView.setLayoutParams(fparams);
|
|
||||||
bgServiceView.setPadding(20, 5, 20, 5);
|
|
||||||
parent.addView(bgServiceView);
|
|
||||||
|
|
||||||
RadioGroup intRadioGrp = (RadioGroup) bgServiceView.findViewById(R.id.wake_up_int_grp);
|
public static class ValueHolder<T> {
|
||||||
final int secondsLength = OsmandBackgroundServicePlugin.SECONDS.length;
|
public T value;
|
||||||
final int minutesLength = OsmandBackgroundServicePlugin.MINUTES.length;
|
|
||||||
final int[] SECONDS = OsmandBackgroundServicePlugin.SECONDS;
|
|
||||||
final int[] MINUTES = OsmandBackgroundServicePlugin.MINUTES;
|
|
||||||
|
|
||||||
final RadioButton[] intButtons = new RadioButton[minutesLength + secondsLength];
|
|
||||||
for (int i = 0; i < secondsLength; i++) {
|
|
||||||
intButtons[i] = new RadioButton(view.getContext());
|
|
||||||
intButtons[i].setText(SECONDS[i] + " " + view.getContext().getString(R.string.int_seconds));
|
|
||||||
intButtons[i].setTextColor(Color.BLACK);
|
|
||||||
intButtons[i].setId(SECONDS[i] * 1000);
|
|
||||||
intRadioGrp.addView(intButtons[i]);
|
|
||||||
}
|
|
||||||
for (int i = secondsLength; i < secondsLength + minutesLength; i++) {
|
|
||||||
intButtons[i] = new RadioButton(view.getContext());
|
|
||||||
intButtons[i].setText(MINUTES[i-secondsLength] + " " + view.getContext().getString(R.string.int_min));
|
|
||||||
intButtons[i].setTextColor(Color.BLACK);
|
|
||||||
intButtons[i].setId(MINUTES[i-secondsLength] * 60 * 1000);
|
|
||||||
intRadioGrp.addView(intButtons[i]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
intRadioGrp.check(settings.SERVICE_OFF_INTERVAL.get());
|
private void showIntervalChooseDialog(final OsmandMapTileView view, final String patternMsg,
|
||||||
intRadioGrp.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
|
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());
|
||||||
|
dlg.setTitle(startText);
|
||||||
|
LinearLayout ll = new LinearLayout(view.getContext());
|
||||||
|
final TextView tv = new TextView(view.getContext());
|
||||||
|
tv.setPadding(7, 3, 7, 0);
|
||||||
|
tv.setText(String.format(patternMsg, ctx.getString(R.string.int_continuosly)));
|
||||||
|
SeekBar sp = new SeekBar(view.getContext());
|
||||||
|
sp.setPadding(7, 5, 7, 0);
|
||||||
|
final int secondsLength = seconds.length;
|
||||||
|
final int minutesLength = minutes.length;
|
||||||
|
sp.setMax(secondsLength + minutesLength - 1);
|
||||||
|
sp.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCheckedChanged(RadioGroup group, int checkedId) {
|
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||||
settings.SERVICE_OFF_INTERVAL.set(checkedId);
|
}
|
||||||
parent.removeView(bgServiceView);
|
@Override
|
||||||
|
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||||
|
String s;
|
||||||
|
if(progress == 0) {
|
||||||
|
s = ctx.getString(R.string.int_continuosly);
|
||||||
|
} else {
|
||||||
|
if(progress < secondsLength) {
|
||||||
|
s = seconds[progress] + ctx.getString(R.string.int_seconds);
|
||||||
|
v.value = seconds[progress] * 1000;
|
||||||
|
} else {
|
||||||
|
s = minutes[progress - secondsLength] + ctx.getString(R.string.int_min);
|
||||||
|
v.value = minutes[progress - secondsLength] * 60 * 1000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tv.setText(String.format(patternMsg, s));
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} */
|
|
||||||
|
for(int i=0; i<secondsLength +minutesLength - 1; i++) {
|
||||||
|
if(i < secondsLength) {
|
||||||
|
if(v.value <= seconds[i] * 1000) {
|
||||||
|
sp.setProgress(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(v.value <= minutes[i - secondsLength] * 1000 * 60) {
|
||||||
|
sp.setProgress(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ll.setOrientation(LinearLayout.VERTICAL);
|
||||||
|
ll.addView(tv);
|
||||||
|
ll.addView(sp);
|
||||||
|
dlg.setView(ll);
|
||||||
|
dlg.setPositiveButton(R.string.default_buttons_ok, onclick);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,6 +71,8 @@ public class MapInfoLayer extends OsmandMapLayer {
|
||||||
private MapInfoControls mapInfoControls;
|
private MapInfoControls mapInfoControls;
|
||||||
private TopTextView topText;
|
private TopTextView topText;
|
||||||
|
|
||||||
|
private LockInfoControl lockInfoControl;
|
||||||
|
|
||||||
public MapInfoLayer(MapActivity map, RouteLayer layer){
|
public MapInfoLayer(MapActivity map, RouteLayer layer){
|
||||||
this.map = map;
|
this.map = map;
|
||||||
this.routeLayer = layer;
|
this.routeLayer = layer;
|
||||||
|
@ -117,6 +119,7 @@ public class MapInfoLayer extends OsmandMapLayer {
|
||||||
|
|
||||||
|
|
||||||
mapInfoControls = new MapInfoControls(map.getMyApplication().getSettings());
|
mapInfoControls = new MapInfoControls(map.getMyApplication().getSettings());
|
||||||
|
lockInfoControl = new LockInfoControl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -136,6 +139,10 @@ public class MapInfoLayer extends OsmandMapLayer {
|
||||||
return paintSubText;
|
return paintSubText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LockInfoControl getLockInfoControl() {
|
||||||
|
return lockInfoControl;
|
||||||
|
}
|
||||||
|
|
||||||
public MapInfoControls getMapInfoControls() {
|
public MapInfoControls getMapInfoControls() {
|
||||||
return mapInfoControls;
|
return mapInfoControls;
|
||||||
}
|
}
|
||||||
|
@ -210,7 +217,6 @@ public class MapInfoLayer extends OsmandMapLayer {
|
||||||
View config = createConfiguration();
|
View config = createConfiguration();
|
||||||
mapInfoControls.registerTopWidget(config, R.drawable.widget_config, R.string.map_widget_config, "config", MapInfoControls.RIGHT_CONTROL, all, 10).required(ApplicationMode.values());
|
mapInfoControls.registerTopWidget(config, R.drawable.widget_config, R.string.map_widget_config, "config", MapInfoControls.RIGHT_CONTROL, all, 10).required(ApplicationMode.values());
|
||||||
|
|
||||||
LockInfoControl lockInfoControl = new LockInfoControl();
|
|
||||||
ImageView bgServiceView = lockInfoControl.createLockScreenWidget(view);
|
ImageView bgServiceView = lockInfoControl.createLockScreenWidget(view);
|
||||||
mapInfoControls.registerTopWidget(bgServiceView, R.drawable.lock_enabled, R.string.bg_service_screen_lock, "bgService", MapInfoControls.LEFT_CONTROL, all, 15);
|
mapInfoControls.registerTopWidget(bgServiceView, R.drawable.lock_enabled, R.string.bg_service_screen_lock, "bgService", MapInfoControls.LEFT_CONTROL, all, 15);
|
||||||
|
|
||||||
|
|
|
@ -199,7 +199,7 @@ public class RouteInfoControls {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// initial state
|
// initial state
|
||||||
// nextTurnInfo.setVisibility(View.GONE);
|
nextTurnInfo.setVisibility(View.GONE);
|
||||||
return nextTurnInfo;
|
return nextTurnInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue