Add registration to osmo
This commit is contained in:
parent
a8f91a3dc8
commit
72f0bb34d0
4 changed files with 108 additions and 4 deletions
|
@ -9,6 +9,7 @@
|
|||
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_not_signed_in">OsMo login failed</string>
|
||||
<string name="osmo_gpx_points_downloaded">OsMo points %1$s downloaded.</string>
|
||||
<string name="osmo_auto_connect_descr">Automatically connect to the service after application startup</string>
|
||||
<string name="osmo_auto_connect">Auto-connect</string>
|
||||
|
|
|
@ -63,15 +63,19 @@ import android.text.style.ForegroundColorSpan;
|
|||
import android.util.DisplayMetrics;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ExpandableListView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.Spinner;
|
||||
|
@ -557,7 +561,7 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
shareSession();
|
||||
return true;
|
||||
} else if (item.getItemId() == CREATE_GROUP) {
|
||||
createGroup();
|
||||
createGroup(true);
|
||||
return true;
|
||||
} else {
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
@ -624,6 +628,94 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
}
|
||||
|
||||
private void signin() {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(R.string.osmo_sign_in);
|
||||
String message = "";
|
||||
if(app.getSettings().OSMO_USER_PWD.get() != null) {
|
||||
message = getString(R.string.osmo_credentials_not_valid) +"\n";
|
||||
}
|
||||
message += getString(R.string.osmo_create_groups_confirm);
|
||||
LinearLayout ll = new LinearLayout(this);
|
||||
ll.setOrientation(LinearLayout.VERTICAL);
|
||||
ll.setPadding(5, 5, 5, 5);
|
||||
TextView tv = new TextView(this);
|
||||
tv.setText(message);
|
||||
tv.setTextSize(17);
|
||||
ll.addView(tv);
|
||||
setSupportProgressBarIndeterminateVisibility(true);
|
||||
final WebView wv = new WebView(this);
|
||||
wv.loadUrl(OsMoService.SIGN_IN_URL + app.getSettings().OSMO_DEVICE_KEY.get());
|
||||
ll.addView(wv);
|
||||
final EditText et = new EditText(this);
|
||||
et.setVisibility(View.GONE);
|
||||
ll.addView(et);
|
||||
builder.setView(ll);
|
||||
wv.setFocusable(true);
|
||||
wv.setFocusableInTouchMode(true);
|
||||
wv.requestFocus(View.FOCUS_DOWN);
|
||||
wv.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
case MotionEvent.ACTION_UP:
|
||||
if (!v.hasFocus()) {
|
||||
v.requestFocus();
|
||||
}
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
final AlertDialog dlg = builder.show();
|
||||
|
||||
wv.setWebViewClient(new WebViewClient() {
|
||||
|
||||
@Override
|
||||
public void onPageFinished(WebView view, String url) {
|
||||
setSupportProgressBarIndeterminateVisibility(false);
|
||||
wv.requestFocus(View.FOCUS_DOWN);
|
||||
}
|
||||
public boolean shouldOverrideUrlLoading(WebView view, String url){
|
||||
if (url.contains(OsMoService.SIGNED_IN_CONTAINS)) {
|
||||
Uri data = Uri.parse(url);
|
||||
String user = data.getQueryParameter("u");
|
||||
String pwd = data.getQueryParameter("p");
|
||||
app.getSettings().OSMO_USER_NAME.set(user);
|
||||
app.getSettings().OSMO_USER_PWD.set(pwd);
|
||||
osMoPlugin.getService().reconnectToServer();
|
||||
createGroupWithDelay(3000);
|
||||
dlg.dismiss();
|
||||
return true;
|
||||
}
|
||||
return false; // then it is not handled by default action
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void createGroupWithDelay(final int delay) {
|
||||
if(delay <= 0) {
|
||||
app.showToastMessage(R.string.osmo_not_signed_in);
|
||||
setSupportProgressBarIndeterminateVisibility(false);
|
||||
return;
|
||||
}
|
||||
setSupportProgressBarIndeterminateVisibility(true);
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if(osMoPlugin.getService().getRegisteredUserName() == null) {
|
||||
createGroupWithDelay(delay - 700);
|
||||
} else {
|
||||
setSupportProgressBarIndeterminateVisibility(false);
|
||||
createGroup(true);
|
||||
}
|
||||
}
|
||||
}, delay);
|
||||
}
|
||||
|
||||
protected void signin2() {
|
||||
Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(R.string.osmo_sign_in);
|
||||
String message = "";
|
||||
|
@ -646,8 +738,8 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
builder.show();
|
||||
}
|
||||
|
||||
private void createGroup() {
|
||||
if(osMoPlugin.getService().getRegisteredUserName() == null) {
|
||||
private void createGroup(boolean check) {
|
||||
if(osMoPlugin.getService().getRegisteredUserName() == null && check) {
|
||||
signin();
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -276,6 +276,9 @@ public class OsMoGroupsStorage {
|
|||
if(userName != null && userName.length() > 0) {
|
||||
return userName;
|
||||
}
|
||||
if(name == null) {
|
||||
return "";
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@ public class OsMoService implements OsMoReactor {
|
|||
private static final Log log = PlatformUtil.getLog(OsMoService.class);
|
||||
public static final String SHARE_TRACKER_URL = "http://z.osmo.mobi/connect?id=";
|
||||
public static final String SHARE_GROUP_URL = "http://z.osmo.mobi/join?id=";
|
||||
public static final String SIGNED_IN_CONTAINS = "z.osmo.mobi/login";
|
||||
public static final String TRACK_URL = "http://osmo.mobi/u/";
|
||||
private String lastRegistrationError = null;
|
||||
private OsMoPlugin plugin;
|
||||
|
@ -161,11 +162,12 @@ public class OsMoService implements OsMoReactor {
|
|||
public String hostName;
|
||||
public String port;
|
||||
public String token;
|
||||
public String uid;
|
||||
public String username;
|
||||
// after auth
|
||||
public String protocol = "";
|
||||
public String groupTrackerId;
|
||||
public String trackerId;
|
||||
public String username;
|
||||
public long serverTimeDelta;
|
||||
public long motdTimestamp;
|
||||
|
||||
|
@ -237,6 +239,12 @@ public class OsMoService implements OsMoReactor {
|
|||
|
||||
SessionInfo si = new SessionInfo();
|
||||
String a = obj.getString("address");
|
||||
if(obj.has("name")) {
|
||||
si.username = obj.getString("name");
|
||||
}
|
||||
if(obj.has("uid")) {
|
||||
si.uid = obj.getString("uid");
|
||||
}
|
||||
int i = a.indexOf(':');
|
||||
si.hostName = a.substring(0, i);
|
||||
si.port = a.substring(i + 1);
|
||||
|
|
Loading…
Reference in a new issue