Add option to regenerate tracker id

This commit is contained in:
vshcherb 2014-05-29 01:34:49 +02:00
parent d7187b8c47
commit a8f0508a7d
5 changed files with 51 additions and 2 deletions

View file

@ -9,6 +9,8 @@
3. 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="osmo_regenerate_login_ids_confirm">Are you sure about regenerating personal ids? All devices, connected to you, won\'t be able to track you any more.</string>
<string name="osmo_regenerate_login_ids">Regenerate user id</string>
<string name="osmo_cancel_moving_target">Cancel moving target</string>
<string name="osmo_center_location">Center on the screen</string>
<string name="osmo_set_moving_target">Set as moving target</string>

View file

@ -29,6 +29,7 @@ public class ShareDialog {
private List<ShareType> share = new ArrayList<ShareType>();
private static final String ZXING_BARCODE_SCANNER_COMPONENT = "com.google.zxing.client.android"; //$NON-NLS-1$
private static final String ZXING_BARCODE_SCANNER_ACTIVITY = "com.google.zxing.client.android.ENCODE"; //$NON-NLS-1$
static final int ACTION = -1;
static final int VIEW = 0;
static final int EMAIL = 1;
static final int SMS = 2;
@ -45,11 +46,17 @@ public class ShareDialog {
return this;
}
public ShareDialog viewContent(String content){
share.add(new ShareType(content, VIEW));
return this;
}
public ShareDialog setAction(String content, Runnable r){
share.add(new ShareType(content, ACTION, r));
return this;
}
public ShareDialog shareURLOrText(String url, String shortExplanation, String longExplanation){
if(shortExplanation == null) {
shortExplanation = url;
@ -68,14 +75,23 @@ public class ShareDialog {
private static class ShareType {
public String content;
public int type;
private Runnable runnable;
public ShareType(String content, int type) {
this.content = content;
this.type = type;
}
public ShareType(String content, int action, Runnable r) {
this.content = content;
this.type = action;
this.runnable = r;
}
public String getShareName(Context ctx) {
if(type == VIEW) {
if(type == ACTION) {
return content;
} else if(type == VIEW) {
return ctx.getString(R.string.show_details);
} else if(type == EMAIL) {
return "Email";
@ -90,7 +106,9 @@ public class ShareDialog {
}
public void execute(Activity a, String title) {
if(type == VIEW) {
if(type == ACTION) {
runnable.run();
} else if(type == VIEW) {
Builder bld = new AlertDialog.Builder(a);
bld.setTitle(title);
bld.setMessage(content);

View file

@ -31,6 +31,7 @@ import android.os.Build;
import android.provider.Settings.Secure;
public class OsMoService implements OsMoReactor {
public static final String REGENERATE_CMD = "REGENERATE_TRACKER_ID";
private OsMoThread thread;
private List<OsMoReactor> listReactors = new java.util.concurrent.CopyOnWriteArrayList<OsMoReactor>();
private ConcurrentLinkedQueue<String> commands = new ConcurrentLinkedQueue<String>();

View file

@ -32,6 +32,7 @@ public class OsMoThread {
// private static String TRACKER_SERVER = "srv.osmo.mobi";
// private static int TRACKER_PORT = 3245;
private static final String PING_CMD = "P";
protected final static Log log = PlatformUtil.getLog(OsMoThread.class);
private static final long HEARTBEAT_DELAY = 100;
@ -290,6 +291,9 @@ public class OsMoThread {
}
}
continue;
} else if(header.equalsIgnoreCase(OsMoService.REGENERATE_CMD)) {
reconnect = true;
continue;
} else if(header.equalsIgnoreCase(PING_CMD)) {
pingSent = 0;
continue;

View file

@ -11,6 +11,8 @@ import net.osmand.plus.osmo.OsMoService.SessionInfo;
import net.osmand.util.Algorithms;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
@ -121,6 +123,7 @@ public class SettingsOsMoActivity extends SettingsBaseActivity {
} else {
ShareDialog dlg = new ShareDialog(this);
dlg.setTitle(getString(R.string.osmo_tracker_id));
dlg.setAction(getString(R.string.osmo_regenerate_login_ids), getRegenerateAction());
dlg.viewContent(ci.trackerId);
dlg.shareURLOrText(ci.trackerId, getString(R.string.osmo_tracker_id_share, ci.trackerId, ""), null);
dlg.showDialog();
@ -129,6 +132,27 @@ public class SettingsOsMoActivity extends SettingsBaseActivity {
return super.onPreferenceClick(preference);
}
private Runnable getRegenerateAction() {
return new Runnable() {
@Override
public void run() {
Builder bld = new AlertDialog.Builder(SettingsOsMoActivity.this);
bld.setMessage(R.string.osmo_regenerate_login_ids_confirm);
bld.setPositiveButton(R.string.default_buttons_yes, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final OsMoPlugin plugin = OsMoPlugin.getEnabledPlugin(OsMoPlugin.class);
plugin.getService().pushCommand(OsMoService.REGENERATE_CMD);
}
});
bld.setNegativeButton(R.string.default_buttons_no, null);
bld.show();
}
};
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean p = super.onPreferenceChange(preference, newValue);