[android] Added icons for google and fb.
BIN
android/res/drawable-hdpi/ic_login_fb.png
Normal file
After Width: | Height: | Size: 212 B |
BIN
android/res/drawable-hdpi/ic_login_google.png
Normal file
After Width: | Height: | Size: 1 KiB |
BIN
android/res/drawable-mdpi/ic_login_fb.png
Normal file
After Width: | Height: | Size: 173 B |
BIN
android/res/drawable-mdpi/ic_login_google.png
Normal file
After Width: | Height: | Size: 690 B |
BIN
android/res/drawable-xhdpi/ic_login_fb.png
Normal file
After Width: | Height: | Size: 242 B |
BIN
android/res/drawable-xhdpi/ic_login_google.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
android/res/drawable-xxhdpi/ic_login_fb.png
Normal file
After Width: | Height: | Size: 301 B |
BIN
android/res/drawable-xxhdpi/ic_login_google.png
Normal file
After Width: | Height: | Size: 1.9 KiB |
BIN
android/res/drawable-xxxhdpi/ic_login_fb.png
Normal file
After Width: | Height: | Size: 369 B |
BIN
android/res/drawable-xxxhdpi/ic_login_google.png
Normal file
After Width: | Height: | Size: 2.6 KiB |
86
android/res/layout/fragment_osm_login.xml
Normal file
|
@ -0,0 +1,86 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
style="@style/MwmWidget.ToolbarStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="@color/bg_cards"
|
||||
android:gravity="end|center_vertical"
|
||||
android:theme="@style/MwmWidget.ToolbarTheme.Light"
|
||||
tools:ignore="UnusedAttribute"/>
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/bg_cards"
|
||||
android:fillViewport="true"
|
||||
tools:ignore="DuplicateIds">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="@dimen/margin_base"
|
||||
tools:ignore="ScrollViewSize">
|
||||
|
||||
<com.mapswithme.maps.widget.CustomTextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/base_block_size"
|
||||
android:layout_marginTop="@dimen/margin_base">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/osm_username"
|
||||
style="@style/MwmWidget.Editor.FieldLayout.EditText"
|
||||
android:hint="Email address or username"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body1"/>
|
||||
|
||||
</com.mapswithme.maps.widget.CustomTextInputLayout>
|
||||
|
||||
<com.mapswithme.maps.widget.CustomTextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/base_block_size"
|
||||
android:layout_marginBottom="@dimen/margin_base"
|
||||
android:layout_marginTop="@dimen/margin_base">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/osm_password"
|
||||
style="@style/MwmWidget.Editor.FieldLayout.EditText"
|
||||
android:hint="Password"
|
||||
android:inputType="textPassword"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body1"/>
|
||||
|
||||
</com.mapswithme.maps.widget.CustomTextInputLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/login_osm"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/editor_auth_btn_height"
|
||||
android:layout_marginBottom="@dimen/margin_base"
|
||||
android:background="?buttonAccent"
|
||||
android:text="Log in"
|
||||
android:textAllCaps="true"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body1.Light"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/lost_password"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="right"
|
||||
android:background="?clickableBackground"
|
||||
android:padding="@dimen/margin_half"
|
||||
android:text="Lost password"
|
||||
android:textAllCaps="true"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body3"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
||||
</LinearLayout>
|
232
android/src/com/mapswithme/maps/editor/OsmAuthFragment.java
Normal file
|
@ -0,0 +1,232 @@
|
|||
package com.mapswithme.maps.editor;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.net.UrlQuerySanitizer;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.Size;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.widget.EditText;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.base.BaseMwmToolbarFragment;
|
||||
import com.mapswithme.maps.widget.ToolbarController;
|
||||
import com.mapswithme.util.Constants;
|
||||
import com.mapswithme.util.Graphics;
|
||||
import com.mapswithme.maps.widget.InputWebView;
|
||||
import com.mapswithme.util.ThemeUtils;
|
||||
import com.mapswithme.util.Utils;
|
||||
import com.mapswithme.util.concurrency.ThreadPool;
|
||||
import com.mapswithme.util.concurrency.UiThread;
|
||||
|
||||
public class OsmAuthFragment extends BaseMwmToolbarFragment implements View.OnClickListener
|
||||
{
|
||||
protected static class AuthToolbarController extends ToolbarController
|
||||
{
|
||||
public AuthToolbarController(View root, Activity activity)
|
||||
{
|
||||
super(root, activity);
|
||||
mToolbar.setNavigationIcon(Graphics.tint(activity, ThemeUtils.getResource(activity, R.attr.homeAsUpIndicator)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpClick()
|
||||
{
|
||||
super.onUpClick();
|
||||
}
|
||||
}
|
||||
|
||||
private EditText mEtLogin;
|
||||
private EditText mEtPassword;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
|
||||
{
|
||||
return inflater.inflate(R.layout.fragment_auth_editor, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
mToolbarController.setTitle("Log In");
|
||||
view.findViewById(R.id.login_osm).setOnClickListener(this);
|
||||
mEtLogin = (EditText) view.findViewById(R.id.osm_username);
|
||||
mEtPassword = (EditText) view.findViewById(R.id.osm_password);
|
||||
view.findViewById(R.id.login_facebook).setOnClickListener(this);
|
||||
view.findViewById(R.id.login_google).setOnClickListener(this);
|
||||
view.findViewById(R.id.lost_password).setOnClickListener(this);
|
||||
view.findViewById(R.id.register).setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ToolbarController onCreateToolbarController(@NonNull View root)
|
||||
{
|
||||
return new AuthToolbarController(root, getActivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
// TODO show/hide spinners
|
||||
switch (v.getId())
|
||||
{
|
||||
case R.id.login_osm:
|
||||
loginOsm();
|
||||
break;
|
||||
case R.id.login_facebook:
|
||||
loginWebview(true);
|
||||
break;
|
||||
case R.id.login_google:
|
||||
loginWebview(false);
|
||||
break;
|
||||
case R.id.lost_password:
|
||||
recoverPassword();
|
||||
break;
|
||||
case R.id.register:
|
||||
register();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void loginOsm()
|
||||
{
|
||||
final String username = mEtLogin.getText().toString();
|
||||
final String password = mEtPassword.getText().toString();
|
||||
|
||||
ThreadPool.getWorker().execute(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
final String[] auth;
|
||||
auth = OsmOAuth.nativeAuthWithPassword(username, password);
|
||||
|
||||
UiThread.run(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (!isAdded())
|
||||
return;
|
||||
|
||||
processAuth(auth);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void processAuth(@Size(2) String[] auth)
|
||||
{
|
||||
if (auth == null)
|
||||
{
|
||||
if (isAdded())
|
||||
{
|
||||
new AlertDialog.Builder(getActivity()).setTitle("Auth error!")
|
||||
.setPositiveButton(android.R.string.ok, null).show();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
OsmOAuth.setAuthorization(auth[0], auth[1]);
|
||||
Utils.navigateToParent(getActivity());
|
||||
}
|
||||
|
||||
private void loginWebview(final boolean facebook)
|
||||
{
|
||||
final WebView webview = new InputWebView(getActivity());
|
||||
final AlertDialog dialog = new AlertDialog.Builder(getActivity()).setView(webview).create();
|
||||
|
||||
ThreadPool.getWorker().execute(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
// TODO(@yunikkk): auth can be nullptr in case of errors.
|
||||
// Need to handle it in UI.
|
||||
// [url, key, secret]
|
||||
final String[] auth = facebook ? OsmOAuth.nativeGetFacebookAuthUrl()
|
||||
: OsmOAuth.nativeGetGoogleAuthUrl();
|
||||
|
||||
UiThread.run(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (isAdded())
|
||||
loadWebviewAuth(dialog, webview, auth);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private void loadWebviewAuth(final AlertDialog dialog, final WebView webview, @Size(3) final String[] auth)
|
||||
{
|
||||
final String authUrl = auth[0];
|
||||
webview.setWebViewClient(new WebViewClient()
|
||||
{
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, String url)
|
||||
{
|
||||
if (OsmOAuth.shouldReloadWebviewUrl(url))
|
||||
{
|
||||
webview.loadUrl(authUrl);
|
||||
}
|
||||
else if (url.contains(OsmOAuth.URL_PARAM_VERIFIER))
|
||||
{
|
||||
UrlQuerySanitizer sanitizer = new UrlQuerySanitizer();
|
||||
sanitizer.setAllowUnregisteredParamaters(true);
|
||||
sanitizer.parseUrl(url);
|
||||
final String verifier = sanitizer.getValue(OsmOAuth.URL_PARAM_VERIFIER);
|
||||
finishWebviewAuth(auth[1], auth[2], verifier);
|
||||
dialog.cancel();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
webview.loadUrl(authUrl);
|
||||
}
|
||||
|
||||
private void finishWebviewAuth(final String key, final String secret, final String verifier)
|
||||
{
|
||||
ThreadPool.getWorker().execute(new Runnable() {
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
final String[] auth = OsmOAuth.nativeAuthWithWebviewToken(key, secret, verifier);
|
||||
UiThread.run(new Runnable() {
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
processAuth(auth);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void recoverPassword()
|
||||
{
|
||||
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.Url.OSM_RECOVER_PASSWORD)));
|
||||
}
|
||||
|
||||
private void register()
|
||||
{
|
||||
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.Url.OSM_REGISTER)));
|
||||
}
|
||||
}
|