small changes, refactoring, etc
This commit is contained in:
parent
b96f054424
commit
18fe655c82
@ -1,26 +1,29 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:orientation="vertical"
|
android:id="@+id/dialog_http_authentication"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/username"
|
android:id="@+id/username"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="16dp"
|
android:layout_marginBottom="4dp"
|
||||||
android:layout_marginLeft="4dp"
|
android:layout_marginLeft="4dp"
|
||||||
android:layout_marginRight="4dp"
|
android:layout_marginRight="4dp"
|
||||||
android:layout_marginBottom="4dp"
|
android:layout_marginTop="16dp"
|
||||||
android:hint="@string/username" />
|
android:hint="@string/username"/>
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/password"
|
android:id="@+id/password"
|
||||||
android:inputType="textPassword"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="4dp"
|
android:layout_marginBottom="16dp"
|
||||||
android:layout_marginLeft="4dp"
|
android:layout_marginLeft="4dp"
|
||||||
android:layout_marginRight="4dp"
|
android:layout_marginRight="4dp"
|
||||||
android:layout_marginBottom="16dp"
|
android:layout_marginTop="4dp"
|
||||||
android:hint="@string/password"/>
|
android:hint="@string/password"
|
||||||
|
android:inputType="textPassword"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
@ -223,7 +223,6 @@
|
|||||||
<string name="username">Username</string>
|
<string name="username">Username</string>
|
||||||
<string name="password">Password</string>
|
<string name="password">Password</string>
|
||||||
<string name="sign_in_action">Sign in</string>
|
<string name="sign_in_action">Sign in</string>
|
||||||
<string name="cancel">Cancel</string>
|
|
||||||
|
|
||||||
<string name="tab_map">Locate</string>
|
<string name="tab_map">Locate</string>
|
||||||
<string name="tab_share">Share</string>
|
<string name="tab_share">Share</string>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.cradle.iitc_mobile;
|
package com.cradle.iitc_mobile;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
@ -10,7 +11,6 @@ import android.net.http.SslError;
|
|||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.webkit.HttpAuthHandler;
|
import android.webkit.HttpAuthHandler;
|
||||||
import android.webkit.SslErrorHandler;
|
import android.webkit.SslErrorHandler;
|
||||||
@ -176,17 +176,15 @@ public class IITC_WebViewClient extends WebViewClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceivedHttpAuthRequest(WebView view, final HttpAuthHandler handler,
|
public void onReceivedHttpAuthRequest(final WebView view, final HttpAuthHandler handler, final String host,
|
||||||
final String host, final String realm) {
|
final String realm) {
|
||||||
String username = null;
|
String username = null;
|
||||||
String password = null;
|
String password = null;
|
||||||
|
|
||||||
|
final boolean reuseHttpAuthUsernamePassword = handler.useHttpAuthUsernamePassword();
|
||||||
final boolean reuseHttpAuthUsernamePassword
|
|
||||||
= handler.useHttpAuthUsernamePassword();
|
|
||||||
|
|
||||||
if (reuseHttpAuthUsernamePassword && view != null) {
|
if (reuseHttpAuthUsernamePassword && view != null) {
|
||||||
String[] credentials = view.getHttpAuthUsernamePassword(host, realm);
|
final String[] credentials = view.getHttpAuthUsernamePassword(host, realm);
|
||||||
if (credentials != null && credentials.length == 2) {
|
if (credentials != null && credentials.length == 2) {
|
||||||
username = credentials[0];
|
username = credentials[0];
|
||||||
password = credentials[1];
|
password = credentials[1];
|
||||||
@ -196,33 +194,47 @@ public class IITC_WebViewClient extends WebViewClient {
|
|||||||
if (username != null && password != null) {
|
if (username != null && password != null) {
|
||||||
handler.proceed(username, password);
|
handler.proceed(username, password);
|
||||||
} else {
|
} else {
|
||||||
createSignInDialog(handler, host, realm).show();
|
createSignInDialog(handler, host, realm, username, password).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Dialog createSignInDialog(final HttpAuthHandler handler, final String host, final String realm) {
|
@SuppressLint("InflateParams")
|
||||||
final AlertDialog.Builder builder = new AlertDialog.Builder(mIitc);
|
// no other way for AlertDialog
|
||||||
final LayoutInflater inflater = mIitc.getLayoutInflater();
|
public Dialog createSignInDialog(final HttpAuthHandler handler, final String host, final String realm,
|
||||||
|
final String username, final String password) {
|
||||||
|
final View v = mIitc.getLayoutInflater().inflate(R.layout.dialog_http_authentication, null);
|
||||||
|
final TextView tvUsername = (TextView) v.findViewById(R.id.username);
|
||||||
|
final TextView tvPassword = (TextView) v.findViewById(R.id.password);
|
||||||
|
final String title = String.format(mIitc.getString(R.string.sign_in_to), host, realm);
|
||||||
|
|
||||||
final View v = inflater.inflate(R.layout.http_authentication, null);
|
if (username != null)
|
||||||
final TextView user = (TextView) v.findViewById(R.id.username);
|
tvUsername.setText(username);
|
||||||
final TextView pass = (TextView) v.findViewById(R.id.password);
|
if (password != null)
|
||||||
final String title = String.format(mIitc.getResources().getString(R.string.sign_in_to), host, realm);
|
tvPassword.setText(password);
|
||||||
|
|
||||||
builder.setView(v)
|
return new AlertDialog.Builder(mIitc)
|
||||||
|
.setView(v)
|
||||||
.setTitle(title)
|
.setTitle(title)
|
||||||
|
.setCancelable(true)
|
||||||
.setPositiveButton(R.string.sign_in_action, new DialogInterface.OnClickListener() {
|
.setPositiveButton(R.string.sign_in_action, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(final DialogInterface dialog, final int id) {
|
||||||
handler.proceed(user.getText().toString(), pass.getText().toString());
|
handler.proceed(tvUsername.getText().toString(), tvPassword.getText().toString());
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
@Override
|
||||||
|
public void onClick(final DialogInterface dialog, final int id) {
|
||||||
|
dialog.cancel();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||||
|
@Override
|
||||||
|
public void onCancel(final DialogInterface dialog) {
|
||||||
handler.cancel();
|
handler.cancel();
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
return builder.create();
|
.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reset() {
|
public void reset() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user