Add lock control

This commit is contained in:
Victor Shcherb 2012-07-31 22:16:54 +02:00
parent 00d23f7ad4
commit 8a449fb194
7 changed files with 148 additions and 98 deletions

View file

@ -9,6 +9,8 @@
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="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="map_widget_top_text">Street name</string>
<string name="map_widget_config">Configuration</string>

View file

@ -93,8 +93,17 @@ public class NavigationService extends Service implements LocationListener {
handler = new Handler();
settings = ((OsmandApplication) getApplication()).getSettings();
serviceOffInterval = settings.SERVICE_OFF_INTERVAL.get();
serviceOffProvider = settings.SERVICE_OFF_PROVIDER.get();
serviceError = settings.SERVICE_OFF_WAIT_INTERVAL.get();
// use only gps provider
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();
liveMonitoringHelper = ((OsmandApplication) getApplication()).getLiveMonitoringHelper();

View file

@ -1239,9 +1239,6 @@ public class OsmandSettings {
// this value string is synchronized with settings_pref.xml preference name
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
public final OsmandPreference<Integer> SERVICE_OFF_INTERVAL = new IntPreference("service_off_interval",
5 * 60 * 1000).makeGlobal();
@ -1249,10 +1246,6 @@ public class OsmandSettings {
public final CommonPreference<Boolean> SHOW_CURRENT_GPX_TRACK =
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();

View file

@ -12,7 +12,6 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.location.LocationManager;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
@ -118,14 +117,7 @@ public class OsmandBackgroundServicePlugin extends OsmandPlugin {
routeServiceEnabled.setKey(OsmandSettings.SERVICE_OFF_ENABLED);
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,
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));
}
}

View file

@ -5,15 +5,24 @@ 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.Rect;
import android.graphics.drawable.Drawable;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import android.widget.Toast;
public class LockInfoControl {
@ -53,6 +62,41 @@ public class LockInfoControl {
FrameLayout.LayoutParams fparams = new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT,
Gravity.CENTER);
transparentLockView.setLayoutParams(fparams);
transparentLockView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
int[] locs = new int[2];
lockView.getLocationOnScreen(locs);
int x = (int) event.getX() - locs[0];
int y = (int) event.getY() - locs[1];
transparentLockView.getLocationOnScreen(locs);
x += locs[0];
y += locs[1];
if(lockView.getWidth() >= x && x >= 0 &&
lockView.getHeight() >= y && y >= 0) {
showBgServiceQAction(lockView, view);
return true;
}
blinkIcon();
AccessibleToast.makeText(transparentLockView.getContext(), R.string.screen_is_locked, Toast.LENGTH_LONG)
.show();
return true;
}
return true;
}
private void blinkIcon() {
lockView.setBackgroundDrawable(lockDisabled);
view.postDelayed(new Runnable() {
@Override
public void run() {
lockView.setBackgroundDrawable(lockEnabled);
}
}, 300);
}
});
}
final FrameLayout parent = (FrameLayout) view.getParent();
final ActionItem lockScreenAction = new ActionItem();
@ -64,40 +108,6 @@ public class LockInfoControl {
public void onClick(View v) {
if (!isScreenLocked) {
parent.addView(transparentLockView);
transparentLockView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
int[] locs = new int[2];
lockView.getLocationOnScreen(locs);
int x = (int) event.getX() - locs[0];
int y = (int) event.getY() - locs[1];
transparentLockView.getLocationOnScreen(locs);
x += locs[0];
y += locs[1];
if(lockView.getWidth() >= x && x >= 0 &&
lockView.getHeight() >= y && y >= 0) {
showBgServiceQAction(lockView, view);
return true;
}
blinkIcon();
AccessibleToast.makeText(transparentLockView.getContext(), R.string.screen_is_locked, Toast.LENGTH_LONG)
.show();
return true;
}
return true;
}
private void blinkIcon() {
lockView.setBackgroundDrawable(lockDisabled);
view.postDelayed(new Runnable() {
@Override
public void run() {
lockView.setBackgroundDrawable(lockEnabled);
}
}, 300);
}
});
} else {
parent.removeView(transparentLockView);
}
@ -117,7 +127,7 @@ public class LockInfoControl {
public void onClick(View v) {
Intent serviceIntent = new Intent(view.getContext(), NavigationService.class);
if (view.getApplication().getNavigationService() == null) {
view.getContext().startService(serviceIntent);
startBgService(serviceIntent, view);
} else {
view.getContext().stopService(serviceIntent);
}
@ -128,47 +138,85 @@ public class LockInfoControl {
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);
final int secondsLength = OsmandBackgroundServicePlugin.SECONDS.length;
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());
intRadioGrp.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
settings.SERVICE_OFF_INTERVAL.set(checkedId);
parent.removeView(bgServiceView);
}
public static class ValueHolder<T> {
public T value;
}
private 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());
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
public void onStopTrackingTouch(SeekBar seekBar) {
}
@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);
}
});
}
}

View file

@ -71,6 +71,8 @@ public class MapInfoLayer extends OsmandMapLayer {
private MapInfoControls mapInfoControls;
private TopTextView topText;
private LockInfoControl lockInfoControl;
public MapInfoLayer(MapActivity map, RouteLayer layer){
this.map = map;
this.routeLayer = layer;
@ -117,6 +119,7 @@ public class MapInfoLayer extends OsmandMapLayer {
mapInfoControls = new MapInfoControls(map.getMyApplication().getSettings());
lockInfoControl = new LockInfoControl();
}
@ -136,6 +139,10 @@ public class MapInfoLayer extends OsmandMapLayer {
return paintSubText;
}
public LockInfoControl getLockInfoControl() {
return lockInfoControl;
}
public MapInfoControls getMapInfoControls() {
return mapInfoControls;
}
@ -210,7 +217,6 @@ public class MapInfoLayer extends OsmandMapLayer {
View config = createConfiguration();
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);
mapInfoControls.registerTopWidget(bgServiceView, R.drawable.lock_enabled, R.string.bg_service_screen_lock, "bgService", MapInfoControls.LEFT_CONTROL, all, 15);

View file

@ -198,8 +198,8 @@ public class RouteInfoControls {
// showMiniMap = true;
}
});
// initial state
// nextTurnInfo.setVisibility(View.GONE);
// initial state
nextTurnInfo.setVisibility(View.GONE);
return nextTurnInfo;
}