Update login functionality
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 360 B |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 278 B |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 409 B |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 548 B |
|
@ -32,45 +32,7 @@
|
|||
android:text="@string/osmo_start_service"/>
|
||||
</LinearLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/osmo_log_off_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/dashboard_parking_left_margin"
|
||||
android:layout_marginRight="@dimen/dashboard_parking_left_margin"
|
||||
android:minHeight="@dimen/osmo_header_height">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/osmo_user_name_text_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:text="@string/anonymous_user"
|
||||
android:textAppearance="?android:attr/textAppearance"/>
|
||||
|
||||
<Switch
|
||||
android:id="@+id/osmo_login_logoff"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:focusable="false"
|
||||
android:gravity="center_vertical"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/osmo_login_hint_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toRightOf="@id/osmo_user_name_text_view"
|
||||
android:minHeight="0dp"
|
||||
android:minWidth="0dp"
|
||||
android:text="\?"
|
||||
android:textAppearance="?android:attr/textAppearance"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
|
||||
<Switch
|
||||
android:id="@+id/enable_tracker"
|
||||
android:layout_width="fill_parent"
|
||||
|
|
|
@ -33,45 +33,6 @@
|
|||
android:text="@string/osmo_start_service"/>
|
||||
</LinearLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/osmo_log_off_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/dashboard_parking_left_margin"
|
||||
android:layout_marginRight="@dimen/dashboard_parking_left_margin"
|
||||
android:minHeight="@dimen/osmo_header_height">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/osmo_user_name_text_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:text="@string/anonymous_user"
|
||||
android:textAppearance="?android:attr/textAppearance"/>
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/osmo_login_logoff"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:focusable="false"
|
||||
android:gravity="center_vertical"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/osmo_login_hint_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toRightOf="@id/osmo_user_name_text_view"
|
||||
android:minHeight="0dp"
|
||||
android:minWidth="0dp"
|
||||
android:text="\?"
|
||||
android:textAppearance="?android:attr/textAppearance"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/enable_tracker"
|
||||
android:layout_width="fill_parent"
|
||||
|
|
|
@ -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="shared_string_logoff">Log Off</string>
|
||||
<string name="rendering_attr_hideHouseNumbers_name">Hide house numbers</string>
|
||||
<string name="application_dir_change_warning3">Do you want OsmAnd to also copy its data files to the new destination?</string>
|
||||
<string name="specified_directiory_not_writeable">Maps could not be created in specified directory</string>
|
||||
|
|
|
@ -3,10 +3,48 @@
|
|||
*/
|
||||
package net.osmand.plus.osmo;
|
||||
|
||||
import gnu.trove.list.array.TIntArrayList;
|
||||
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.Location;
|
||||
import net.osmand.access.AccessibleToast;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.NavigationService;
|
||||
import net.osmand.plus.OsmAndConstants;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener;
|
||||
import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.TargetPointsHelper;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
|
||||
import net.osmand.plus.activities.OsmandExpandableListActivity;
|
||||
import net.osmand.plus.activities.actions.ShareDialog;
|
||||
import net.osmand.plus.base.MapViewTrackingUtilities;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
import net.osmand.plus.helpers.ColorDialogs;
|
||||
import net.osmand.plus.osmo.OsMoGroups.OsMoGroupsUIListener;
|
||||
import net.osmand.plus.osmo.OsMoGroupsStorage.OsMoDevice;
|
||||
import net.osmand.plus.osmo.OsMoGroupsStorage.OsMoGroup;
|
||||
import net.osmand.plus.osmo.OsMoService.SessionInfo;
|
||||
import net.osmand.util.MapUtils;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.AlertDialog.Builder;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnCancelListener;
|
||||
|
@ -29,6 +67,7 @@ import android.os.Handler;
|
|||
import android.os.Message;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.support.v7.view.ActionMode;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.Editable;
|
||||
import android.text.Spannable;
|
||||
import android.text.TextUtils;
|
||||
|
@ -60,43 +99,6 @@ import android.widget.ScrollView;
|
|||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.Location;
|
||||
import net.osmand.access.AccessibleToast;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.NavigationService;
|
||||
import net.osmand.plus.OsmAndConstants;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.TargetPointsHelper;
|
||||
import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener;
|
||||
import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
|
||||
import net.osmand.plus.activities.OsmandExpandableListActivity;
|
||||
import net.osmand.plus.activities.actions.ShareDialog;
|
||||
import net.osmand.plus.base.MapViewTrackingUtilities;
|
||||
import net.osmand.plus.helpers.ColorDialogs;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
import net.osmand.plus.osmo.OsMoGroups.OsMoGroupsUIListener;
|
||||
import net.osmand.plus.osmo.OsMoGroupsStorage.OsMoDevice;
|
||||
import net.osmand.plus.osmo.OsMoGroupsStorage.OsMoGroup;
|
||||
import net.osmand.plus.osmo.OsMoService.SessionInfo;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import gnu.trove.list.array.TIntArrayList;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -115,6 +117,7 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
protected static final int SETTINGS_ID = 9;
|
||||
protected static final int SETTINGS_DEV_ID = 10;
|
||||
protected static final int TRACK_DEV_ID = 11;
|
||||
protected static final int LOGIN_ID = 12;
|
||||
public static final int LIST_REFRESH_MSG_ID = OsmAndConstants.UI_HANDLER_SEARCH + 30;
|
||||
public static final long RECENT_THRESHOLD = 60000;
|
||||
private boolean joinGroup;
|
||||
|
@ -276,18 +279,6 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
}
|
||||
|
||||
|
||||
CompoundButton login = (CompoundButton) header.findViewById(R.id.osmo_login_logoff);
|
||||
login.setChecked(osMoPlugin.getService().isLoggedIn());
|
||||
login.setOnCheckedChangeListener(new LoginOnCheckedChangeListener());
|
||||
|
||||
Button hintBtn = (Button) header.findViewById(R.id.osmo_login_hint_button);
|
||||
hintBtn.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
showHint();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setupFooter() {
|
||||
|
@ -336,37 +327,19 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
lastUpdateTime = last;
|
||||
blink(status, big, small);
|
||||
}
|
||||
View logOffLayout = header.findViewById(R.id.osmo_log_off_layout);
|
||||
CompoundButton login = (CompoundButton) header.findViewById(R.id.osmo_login_logoff);
|
||||
supportInvalidateOptionsMenu();
|
||||
if(service.isConnected()) {
|
||||
header.findViewById(R.id.motd).setVisibility(View.VISIBLE);
|
||||
header.findViewById(R.id.enable_tracker).setVisibility(View.VISIBLE);
|
||||
|
||||
logOffLayout.setVisibility(View.VISIBLE);
|
||||
TextView userNameTextView = (TextView) header.findViewById(R.id.osmo_user_name_text_view);
|
||||
Button hintBtn = (Button) header.findViewById(R.id.osmo_login_hint_button);
|
||||
if (service.isLoggedIn()) {
|
||||
String text = getString(R.string.logged_as, app.getSettings().OSMO_USER_NAME.get());
|
||||
userNameTextView.setText(text);
|
||||
hintBtn.setVisibility(View.GONE);
|
||||
if (!login.isChecked()) {
|
||||
login.setOnCheckedChangeListener(null);
|
||||
login.setChecked(true);
|
||||
login.setOnCheckedChangeListener(new LoginOnCheckedChangeListener());
|
||||
}
|
||||
getSupportActionBar().setTitle(app.getSettings().OSMO_USER_NAME.get());
|
||||
} else {
|
||||
userNameTextView.setText(R.string.anonymous_user);
|
||||
hintBtn.setVisibility(View.VISIBLE);
|
||||
if (login.isChecked()) {
|
||||
login.setOnCheckedChangeListener(null);
|
||||
login.setChecked(false);
|
||||
login.setOnCheckedChangeListener(new LoginOnCheckedChangeListener());
|
||||
}
|
||||
getSupportActionBar().setTitle(R.string.anonymous_user);
|
||||
}
|
||||
} else {
|
||||
header.findViewById(R.id.motd).setVisibility(View.GONE);
|
||||
header.findViewById(R.id.enable_tracker).setVisibility(View.GONE);
|
||||
logOffLayout.setVisibility(View.GONE);
|
||||
getSupportActionBar().setTitle(R.string.osmo);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -690,6 +663,9 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
} else if (item.getItemId() == SETTINGS_ID) {
|
||||
startActivity(new Intent(this, SettingsOsMoActivity.class));
|
||||
return true;
|
||||
} else if (item.getItemId() == LOGIN_ID) {
|
||||
loginDialog();
|
||||
return true;
|
||||
} else if (item.getItemId() == SHARE_SESSION) {
|
||||
shareSession();
|
||||
return true;
|
||||
|
@ -701,6 +677,26 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
}
|
||||
}
|
||||
|
||||
private void loginDialog() {
|
||||
if (!osMoPlugin.getService().isLoggedIn()) {
|
||||
setSupportProgressBarIndeterminateVisibility(true);
|
||||
signinPost(false);
|
||||
} else {
|
||||
Builder bld = new AlertDialog.Builder(this);
|
||||
String text = getString(R.string.logged_as, app.getSettings().OSMO_USER_NAME.get());
|
||||
bld.setMessage(text);
|
||||
bld.setPositiveButton(R.string.shared_string_ok, null);
|
||||
bld.setNegativeButton(R.string.shared_string_logoff, new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
logoff();
|
||||
}
|
||||
});
|
||||
bld.show();
|
||||
}
|
||||
}
|
||||
|
||||
private void shareSession() {
|
||||
Builder bld = new AlertDialog.Builder(this);
|
||||
bld.setItems(new String[] {
|
||||
|
@ -764,22 +760,44 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
signinPost(true);
|
||||
}
|
||||
|
||||
|
||||
static int getResIdFromAttribute(final Activity activity, final int attr) {
|
||||
if (attr == 0)
|
||||
return 0;
|
||||
final TypedValue typedvalueattr = new TypedValue();
|
||||
activity.getTheme().resolveAttribute(attr, typedvalueattr, true);
|
||||
return typedvalueattr.resourceId;
|
||||
}
|
||||
private void signinPost(final boolean createGroup) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(R.string.osmo_sign_in);
|
||||
final Dialog dialog = new Dialog(this,
|
||||
app.getSettings().isLightContent() ?
|
||||
R.style.OsmandLightTheme:
|
||||
R.style.OsmandDarkTheme);
|
||||
LinearLayout ll = new LinearLayout(this);
|
||||
ll.setOrientation(LinearLayout.VERTICAL);
|
||||
ll.setPadding(5, 5, 5, 5);
|
||||
Toolbar tb = new Toolbar(this);
|
||||
tb.setClickable(true);
|
||||
Drawable back = ((OsmandApplication)getApplication()).getIconsCache().getIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
|
||||
tb.setNavigationIcon(back);
|
||||
tb.setTitle(R.string.osmo_sign_in);
|
||||
tb.setBackgroundColor(getResources().getColor( getResIdFromAttribute(this, R.attr.pstsTabBackground)));
|
||||
tb.setTitleTextColor(getResources().getColor(getResIdFromAttribute(this, R.attr.pstsTextColor)));
|
||||
tb.setNavigationOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(final View v) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
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);
|
||||
ScrollView scrollView = new ScrollView(this);
|
||||
scrollView.addView(ll);
|
||||
builder.setView(scrollView);
|
||||
int pad = (int) getResources().getDimension(R.dimen.list_content_padding);
|
||||
// scrollView.setPadding(pad, pad, pad, pad);
|
||||
ll.addView(tb);
|
||||
ll.addView(scrollView);
|
||||
scrollView.addView(wv);
|
||||
dialog.setContentView(ll);
|
||||
wv.setFocusable(true);
|
||||
wv.setFocusableInTouchMode(true);
|
||||
wv.requestFocus(View.FOCUS_DOWN);
|
||||
|
@ -798,8 +816,8 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
}
|
||||
});
|
||||
|
||||
builder.setCancelable(true);
|
||||
builder.setOnCancelListener(new OnCancelListener() {
|
||||
dialog.setCancelable(true);
|
||||
dialog.setOnCancelListener(new OnCancelListener() {
|
||||
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
|
@ -809,8 +827,7 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
}
|
||||
}
|
||||
});
|
||||
final AlertDialog dlg = builder.show();
|
||||
|
||||
dialog.show();
|
||||
wv.setWebViewClient(new WebViewClient() {
|
||||
|
||||
@Override
|
||||
|
@ -831,7 +848,7 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
} else {
|
||||
updateStatus();
|
||||
}
|
||||
dlg.dismiss();
|
||||
dialog.dismiss();
|
||||
return true;
|
||||
}
|
||||
return false; // then it is not handled by default action
|
||||
|
@ -1029,11 +1046,24 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
builder.create().show();
|
||||
AndroidUtils.softKeyboardDelayed(tracker);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
OsMoService service = osMoPlugin.getService();
|
||||
MenuItem log = menu.findItem(LOGIN_ID);
|
||||
if (log != null) {
|
||||
log.setVisible(service.isConnected());
|
||||
}
|
||||
return super.onPrepareOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
menu.clear();
|
||||
Menu oldMenu = menu;
|
||||
addLoginActionMenu(oldMenu);
|
||||
createMenuItem(oldMenu, SETTINGS_ID, R.string.shared_string_settings, R.drawable.ic_action_settings,
|
||||
MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
|
||||
boolean portrait = AndroidUiHelper.isOrientationPortrait(this);
|
||||
if (portrait) {
|
||||
menu = getClearToolbar(true).getMenu();
|
||||
|
@ -1049,12 +1079,29 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
createMenuItem(menu, CREATE_GROUP, R.string.osmo_create_group,
|
||||
R.drawable.ic_group_add,
|
||||
MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
|
||||
createMenuItem(oldMenu, SETTINGS_ID, R.string.shared_string_settings,
|
||||
R.drawable.ic_action_settings,
|
||||
MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
|
||||
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
private void addLoginActionMenu(Menu oldMenu) {
|
||||
OsMoService service = osMoPlugin.getService();
|
||||
String text;
|
||||
if (service.isLoggedIn()) {
|
||||
text = getString(R.string.logged_as, app.getSettings().OSMO_USER_NAME.get());
|
||||
} else {
|
||||
text = getString(R.string.anonymous_user);
|
||||
}
|
||||
MenuItem menuItem = oldMenu.add(0, LOGIN_ID, 0, text);
|
||||
menuItem.setIcon(R.drawable.ic_person);
|
||||
menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
return onOptionsItemSelected(item);
|
||||
}
|
||||
});
|
||||
MenuItemCompat.setShowAsAction(menuItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
|
||||
}
|
||||
|
||||
public void startLongRunningOperation(String operation) {
|
||||
this.operation = operation;
|
||||
setSupportProgressBarIndeterminateVisibility(true);
|
||||
|
@ -1568,20 +1615,7 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
builder.show();
|
||||
}
|
||||
|
||||
private class LoginOnCheckedChangeListener implements OnCheckedChangeListener {
|
||||
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (isChecked) {
|
||||
if (!osMoPlugin.getService().isLoggedIn()) {
|
||||
setSupportProgressBarIndeterminateVisibility(true);
|
||||
signinPost(false);
|
||||
}
|
||||
} else {
|
||||
logoff();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void handleConnect() {
|
||||
app.runInUIThread(new Runnable() {
|
||||
|
|