mirror of
https://github.com/TeamVanced/VancedMicroG
synced 2025-02-02 14:07:32 +01:00
Ask before loading sign-in website (#276)
This commit is contained in:
parent
01f154dcdb
commit
db7b721b1a
@ -19,7 +19,11 @@ package org.microg.gms.auth.login;
|
||||
import android.app.Activity;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.google.android.gms.R;
|
||||
|
||||
@ -32,6 +36,18 @@ public abstract class AssistantActivity extends Activity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.login_assistant);
|
||||
formatTitle();
|
||||
findViewById(R.id.next_button).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
onNextButtonClicked();
|
||||
}
|
||||
});
|
||||
findViewById(R.id.back_button).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
onBackButtonClicked();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void formatTitle() {
|
||||
@ -44,12 +60,52 @@ public abstract class AssistantActivity extends Activity {
|
||||
}
|
||||
}
|
||||
|
||||
public void setNextButtonText(@StringRes int res) {
|
||||
setNextButtonText(getText(res));
|
||||
}
|
||||
|
||||
public void setNextButtonText(CharSequence text) {
|
||||
if (text == null) {
|
||||
findViewById(R.id.next_button).setVisibility(View.GONE);
|
||||
} else {
|
||||
findViewById(R.id.next_button).setVisibility(View.VISIBLE);
|
||||
((Button) findViewById(R.id.next_button)).setText(text);
|
||||
}
|
||||
}
|
||||
|
||||
public void setBackButtonText(@StringRes int res) {
|
||||
setBackButtonText(getText(res));
|
||||
}
|
||||
|
||||
public void setBackButtonText(CharSequence text) {
|
||||
if (text == null) {
|
||||
findViewById(R.id.back_button).setVisibility(View.GONE);
|
||||
} else {
|
||||
findViewById(R.id.back_button).setVisibility(View.VISIBLE);
|
||||
((Button) findViewById(R.id.back_button)).setText(text);
|
||||
}
|
||||
}
|
||||
|
||||
protected void onNextButtonClicked() {
|
||||
|
||||
}
|
||||
|
||||
protected void onBackButtonClicked() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
formatTitle();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTitleChanged(CharSequence title, int color) {
|
||||
super.onTitleChanged(title, color);
|
||||
((TextView) findViewById(R.id.title)).setText(title);
|
||||
}
|
||||
|
||||
public int dpToPx(int dp) {
|
||||
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
|
||||
return Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
|
||||
|
@ -21,14 +21,19 @@ import android.accounts.AccountManager;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.v4.view.LayoutInflaterCompat;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
@ -86,6 +91,8 @@ public class LoginActivity extends AssistantActivity {
|
||||
private String accountType;
|
||||
private AccountManager accountManager;
|
||||
private InputMethodManager inputMethodManager;
|
||||
private ViewGroup authContent;
|
||||
private int state = 0;
|
||||
|
||||
@SuppressLint("AddJavascriptInterface")
|
||||
@Override
|
||||
@ -96,6 +103,7 @@ public class LoginActivity extends AssistantActivity {
|
||||
inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
|
||||
webView = createWebView(this);
|
||||
webView.addJavascriptInterface(new JsBridge(), "mm");
|
||||
authContent = (ViewGroup) findViewById(R.id.auth_content);
|
||||
((ViewGroup) findViewById(R.id.auth_root)).addView(webView);
|
||||
webView.setWebViewClient(new WebViewClient() {
|
||||
@Override
|
||||
@ -124,19 +132,50 @@ public class LoginActivity extends AssistantActivity {
|
||||
retrieveRtToken(getIntent().getStringExtra(EXTRA_TOKEN));
|
||||
}
|
||||
} else {
|
||||
CookieManager.getInstance().setAcceptCookie(true);
|
||||
if (SDK_INT >= LOLLIPOP) {
|
||||
CookieManager.getInstance().removeAllCookies(new ValueCallback<Boolean>() {
|
||||
@Override
|
||||
public void onReceiveValue(Boolean value) {
|
||||
start();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
//noinspection deprecation
|
||||
CookieManager.getInstance().removeAllCookie();
|
||||
start();
|
||||
}
|
||||
setMessage(R.string.auth_before_connect);
|
||||
setBackButtonText(android.R.string.cancel);
|
||||
setNextButtonText(R.string.auth_sign_in);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNextButtonClicked() {
|
||||
super.onNextButtonClicked();
|
||||
state++;
|
||||
if (state == 1) {
|
||||
init();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBackButtonClicked() {
|
||||
super.onBackButtonClicked();
|
||||
state--;
|
||||
if (state == -1) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
private void init() {
|
||||
setTitle(R.string.just_a_sec);
|
||||
setBackButtonText(null);
|
||||
setNextButtonText(null);
|
||||
View loading = getLayoutInflater().inflate(R.layout.login_assistant_loading, authContent, false);
|
||||
authContent.removeAllViews();
|
||||
authContent.addView(loading);
|
||||
setMessage(R.string.auth_connecting);
|
||||
CookieManager.getInstance().setAcceptCookie(true);
|
||||
if (SDK_INT >= LOLLIPOP) {
|
||||
CookieManager.getInstance().removeAllCookies(new ValueCallback<Boolean>() {
|
||||
@Override
|
||||
public void onReceiveValue(Boolean value) {
|
||||
start();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
//noinspection deprecation
|
||||
CookieManager.getInstance().removeAllCookie();
|
||||
start();
|
||||
}
|
||||
}
|
||||
|
||||
@ -200,13 +239,17 @@ public class LoginActivity extends AssistantActivity {
|
||||
}
|
||||
|
||||
private void showError(int errorRes) {
|
||||
((TextView) findViewById(R.id.title)).setText(R.string.sorry);
|
||||
setTitle(R.string.sorry);
|
||||
findViewById(R.id.progress_bar).setVisibility(View.INVISIBLE);
|
||||
setMessage(errorRes);
|
||||
}
|
||||
|
||||
private void setMessage(int res) {
|
||||
((TextView) findViewById(R.id.description_text)).setText(res);
|
||||
private void setMessage(@StringRes int res) {
|
||||
setMessage(getText(res));
|
||||
}
|
||||
|
||||
private void setMessage(CharSequence text) {
|
||||
((TextView) findViewById(R.id.description_text)).setText(text);
|
||||
}
|
||||
|
||||
private void loadLoginPage() {
|
||||
|
@ -15,33 +15,33 @@
|
||||
-->
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:id="@+id/auth_root"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/title_container"
|
||||
android:background="?attr/colorPrimary"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="64dp">
|
||||
android:layout_height="64dp"
|
||||
android:background="?attr/colorPrimary">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:textColor="@color/primary_text_default_material_dark"
|
||||
android:textSize="24sp"
|
||||
android:padding="18dp"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginRight="20dp"
|
||||
android:id="@+id/title"
|
||||
android:padding="18dp"
|
||||
android:text="@string/just_a_sec"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
android:textColor="@color/primary_text_default_material_dark"
|
||||
android:textSize="24sp"/>
|
||||
</RelativeLayout>
|
||||
|
||||
<FrameLayout
|
||||
@ -50,13 +50,49 @@
|
||||
android:layout_height="0dip"
|
||||
android:layout_weight="1">
|
||||
|
||||
<include layout="@layout/login_assistant_loading" />
|
||||
<TextView
|
||||
android:id="@+id/description_text"
|
||||
style="?attr/textAppearanceListItem"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginRight="20dp"
|
||||
android:padding="20dp"/>
|
||||
</FrameLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:background="#e4e7e9"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="54dp" />
|
||||
android:layout_height="54dip"
|
||||
android:background="#e4e7e9">
|
||||
|
||||
<Button
|
||||
android:id="@+id/back_button"
|
||||
style="?attr/buttonBarNegativeButtonStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="48dip"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:paddingLeft="38dp"
|
||||
android:paddingRight="38dp"
|
||||
android:textAllCaps="true"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
|
||||
android:textSize="16sp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/next_button"
|
||||
style="?attr/buttonBarPositiveButtonStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="48dip"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:paddingLeft="38dp"
|
||||
android:paddingRight="38dp"
|
||||
android:textAllCaps="true"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
|
||||
android:textSize="16sp"/>
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
|
||||
</RelativeLayout>
|
@ -25,7 +25,14 @@
|
||||
<string name="ask_service_permission_title"><xliff:g example="F-Droid">%1$s</xliff:g> would like to use:</string>
|
||||
<string name="account_manager_title">Google Account Manager</string>
|
||||
<string name="sorry">Sorry…</string>
|
||||
<string name="no_network_error_desc">"You don't have a network connection.
|
||||
<string name="auth_before_connect">"An app on your device is trying to sign in to a Google account.
|
||||
|
||||
If this was intentional, use the <b>Sign in</b> button to connect to Google’s sign-in page, if not, press <b>Cancel</b> to go back to the application that caused this dialog to show up."</string>
|
||||
<string name="auth_sign_in">Sign in</string>
|
||||
<string name="auth_connecting">"Your device is establishing an connection to Google’s servers to sign you in.
|
||||
|
||||
This can take a few seconds."</string>
|
||||
<string name="no_network_error_desc">"You don’t have a network connection.
|
||||
|
||||
This could be a temporary problem or your Android device may not be provisioned for data services. Try again when connected to a mobile network, or connect to a Wi-Fi network."</string>
|
||||
<string name="auth_general_error_desc">"There was a problem communicating with Google servers.
|
||||
|
Loading…
x
Reference in New Issue
Block a user