replaced copied AOSP code with own implementation
This commit is contained in:
parent
0218bd5565
commit
b96f054424
@ -1,62 +1,26 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!-- Copyright (C) 2008 The Android Open Source Project
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
>
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
<TextView
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:text="@string/username"
|
|
||||||
android:layout_marginTop="12dip"
|
|
||||||
android:layout_marginLeft="20dip"
|
|
||||||
android:layout_marginRight="20dip" />
|
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/username_edit"
|
android:id="@+id/username"
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:scrollHorizontally="true"
|
|
||||||
android:inputType="text"
|
|
||||||
android:layout_marginLeft="20dip"
|
|
||||||
android:layout_marginRight="20dip"
|
|
||||||
android:layout_marginBottom="12dip"
|
|
||||||
android:singleLine="true"
|
|
||||||
android:imeOptions="actionNext" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_width="wrap_content"
|
android:layout_marginTop="16dp"
|
||||||
android:text="@string/password"
|
android:layout_marginLeft="4dp"
|
||||||
android:layout_marginLeft="20dip"
|
android:layout_marginRight="4dp"
|
||||||
android:layout_marginRight="20dip" />
|
android:layout_marginBottom="4dp"
|
||||||
|
android:hint="@string/username" />
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/password_edit"
|
android:id="@+id/password"
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:scrollHorizontally="true"
|
|
||||||
android:inputType="textPassword"
|
android:inputType="textPassword"
|
||||||
android:layout_marginLeft="20dip"
|
android:layout_width="match_parent"
|
||||||
android:layout_marginRight="20dip"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="12dip"
|
android:layout_marginTop="4dp"
|
||||||
android:singleLine="true"
|
android:layout_marginLeft="4dp"
|
||||||
android:imeOptions="actionDone" />
|
android:layout_marginRight="4dp"
|
||||||
</LinearLayout>
|
android:layout_marginBottom="16dp"
|
||||||
|
android:hint="@string/password"/>
|
||||||
|
</LinearLayout>
|
@ -219,22 +219,11 @@
|
|||||||
<string name="msg_copied">Copied to clipboard…</string>
|
<string name="msg_copied">Copied to clipboard…</string>
|
||||||
<string name="notice_do_not_show_again">Do not show again</string>
|
<string name="notice_do_not_show_again">Do not show again</string>
|
||||||
|
|
||||||
<!-- Sign-in dialog -->
|
|
||||||
<string name="sign_in_to">Sign in to %1$s %2$s"</string>
|
<string name="sign_in_to">Sign in to %1$s %2$s"</string>
|
||||||
<!-- Prompt for an input box that allows the user to enter their login name -->
|
<string name="username">Username</string>
|
||||||
<string name="username">Name</string>
|
|
||||||
<!-- Prompt for an input box that allows the user to enter their password -->
|
|
||||||
<string name="password">Password</string>
|
<string name="password">Password</string>
|
||||||
<!-- The label on the "sign in" button -->
|
<string name="sign_in_action">Sign in</string>
|
||||||
<string name="action">Sign in</string>
|
|
||||||
<!-- The name of the add bookmark page activity.-->
|
|
||||||
<string name="bookmarks_add_page">Save bookmark</string>
|
|
||||||
<!-- The name of the bookmarks and history search suggestion source. -->
|
|
||||||
<string name="bookmarks_search">Browser</string>
|
|
||||||
<!-- Label for a cancel button. It is used for multiple cancel buttons in different contexts -->
|
|
||||||
<string name="cancel">Cancel</string>
|
<string name="cancel">Cancel</string>
|
||||||
<!-- Label for a confirm button. Used in multiple contexts. -->
|
|
||||||
<string name="ok">OK</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,166 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2010 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package com.cradle.iitc_mobile;
|
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.view.KeyEvent;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.WindowManager;
|
|
||||||
import android.view.inputmethod.EditorInfo;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import android.widget.TextView.OnEditorActionListener;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* HTTP authentication dialog.
|
|
||||||
*/
|
|
||||||
public class HttpAuthenticationDialog {
|
|
||||||
|
|
||||||
private final Context mContext;
|
|
||||||
|
|
||||||
private final String mHost;
|
|
||||||
private final String mRealm;
|
|
||||||
|
|
||||||
private AlertDialog mDialog;
|
|
||||||
private TextView mUsernameView;
|
|
||||||
private TextView mPasswordView;
|
|
||||||
|
|
||||||
private OkListener mOkListener;
|
|
||||||
private CancelListener mCancelListener;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an HTTP authentication dialog.
|
|
||||||
*/
|
|
||||||
public HttpAuthenticationDialog(Context context, String host, String realm) {
|
|
||||||
mContext = context;
|
|
||||||
mHost = host;
|
|
||||||
mRealm = realm;
|
|
||||||
createDialog();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getUsername() {
|
|
||||||
return mUsernameView.getText().toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getPassword() {
|
|
||||||
return mPasswordView.getText().toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the listener that will be notified when the user submits the credentials.
|
|
||||||
*/
|
|
||||||
public void setOkListener(OkListener okListener) {
|
|
||||||
mOkListener = okListener;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the listener that will be notified when the user cancels the authentication
|
|
||||||
* dialog.
|
|
||||||
*/
|
|
||||||
public void setCancelListener(CancelListener cancelListener) {
|
|
||||||
mCancelListener = cancelListener;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shows the dialog.
|
|
||||||
*/
|
|
||||||
public void show() {
|
|
||||||
mDialog.show();
|
|
||||||
mUsernameView.requestFocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hides, recreates, and shows the dialog. This can be used to handle configuration changes.
|
|
||||||
*/
|
|
||||||
public void reshow() {
|
|
||||||
String username = getUsername();
|
|
||||||
String password = getPassword();
|
|
||||||
int focusId = mDialog.getCurrentFocus().getId();
|
|
||||||
mDialog.dismiss();
|
|
||||||
createDialog();
|
|
||||||
mDialog.show();
|
|
||||||
if (username != null) {
|
|
||||||
mUsernameView.setText(username);
|
|
||||||
}
|
|
||||||
if (password != null) {
|
|
||||||
mPasswordView.setText(password);
|
|
||||||
}
|
|
||||||
if (focusId != 0) {
|
|
||||||
mDialog.findViewById(focusId).requestFocus();
|
|
||||||
} else {
|
|
||||||
mUsernameView.requestFocus();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createDialog() {
|
|
||||||
LayoutInflater factory = LayoutInflater.from(mContext);
|
|
||||||
View v = factory.inflate(R.layout.http_authentication, null);
|
|
||||||
mUsernameView = (TextView) v.findViewById(R.id.username_edit);
|
|
||||||
mPasswordView = (TextView) v.findViewById(R.id.password_edit);
|
|
||||||
mPasswordView.setOnEditorActionListener(new OnEditorActionListener() {
|
|
||||||
@Override
|
|
||||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
|
||||||
if (actionId == EditorInfo.IME_ACTION_DONE) {
|
|
||||||
mDialog.getButton(AlertDialog.BUTTON_POSITIVE).performClick();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
String title = mContext.getText(R.string.sign_in_to).toString();
|
|
||||||
title = String.format(title, mHost, mRealm);
|
|
||||||
|
|
||||||
mDialog = new AlertDialog.Builder(mContext)
|
|
||||||
.setTitle(title)
|
|
||||||
.setIconAttribute(android.R.attr.alertDialogIcon)
|
|
||||||
.setView(v)
|
|
||||||
.setPositiveButton(R.string.action, new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int whichButton) {
|
|
||||||
if (mOkListener != null) {
|
|
||||||
mOkListener.onOk(mHost, mRealm, getUsername(), getPassword());
|
|
||||||
}
|
|
||||||
}})
|
|
||||||
.setNegativeButton(R.string.cancel,new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int whichButton) {
|
|
||||||
if (mCancelListener != null) mCancelListener.onCancel();
|
|
||||||
}})
|
|
||||||
.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
|
||||||
public void onCancel(DialogInterface dialog) {
|
|
||||||
if (mCancelListener != null) mCancelListener.onCancel();
|
|
||||||
}})
|
|
||||||
.create();
|
|
||||||
|
|
||||||
// Make the IME appear when the dialog is displayed if applicable.
|
|
||||||
mDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface for listeners that are notified when the user submits the credentials.
|
|
||||||
*/
|
|
||||||
public interface OkListener {
|
|
||||||
void onOk(String host, String realm, String username, String password);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface for listeners that are notified when the user cancels the dialog.
|
|
||||||
*/
|
|
||||||
public interface CancelListener {
|
|
||||||
void onCancel();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +1,8 @@
|
|||||||
package com.cradle.iitc_mobile;
|
package com.cradle.iitc_mobile;
|
||||||
|
|
||||||
import android.app.ActionBar;
|
import android.app.AlertDialog;
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
@ -8,11 +10,14 @@ 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.webkit.HttpAuthHandler;
|
import android.webkit.HttpAuthHandler;
|
||||||
import android.webkit.SslErrorHandler;
|
import android.webkit.SslErrorHandler;
|
||||||
import android.webkit.WebResourceResponse;
|
import android.webkit.WebResourceResponse;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
import android.webkit.WebViewClient;
|
import android.webkit.WebViewClient;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
@ -176,7 +181,8 @@ public class IITC_WebViewClient extends WebViewClient {
|
|||||||
String username = null;
|
String username = null;
|
||||||
String password = null;
|
String password = null;
|
||||||
|
|
||||||
boolean reuseHttpAuthUsernamePassword
|
|
||||||
|
final boolean reuseHttpAuthUsernamePassword
|
||||||
= handler.useHttpAuthUsernamePassword();
|
= handler.useHttpAuthUsernamePassword();
|
||||||
|
|
||||||
if (reuseHttpAuthUsernamePassword && view != null) {
|
if (reuseHttpAuthUsernamePassword && view != null) {
|
||||||
@ -190,24 +196,35 @@ 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 {
|
||||||
HttpAuthenticationDialog dialog = new HttpAuthenticationDialog(mIitc, host, realm);
|
createSignInDialog(handler, host, realm).show();
|
||||||
|
|
||||||
dialog.setOkListener(new HttpAuthenticationDialog.OkListener() {
|
|
||||||
public void onOk(String host, String realm, String username, String password) {
|
|
||||||
handler.proceed(username, password);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
dialog.setCancelListener(new HttpAuthenticationDialog.CancelListener() {
|
|
||||||
public void onCancel() {
|
|
||||||
handler.cancel();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
dialog.show();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Dialog createSignInDialog(final HttpAuthHandler handler, final String host, final String realm) {
|
||||||
|
final AlertDialog.Builder builder = new AlertDialog.Builder(mIitc);
|
||||||
|
final LayoutInflater inflater = mIitc.getLayoutInflater();
|
||||||
|
|
||||||
|
final View v = inflater.inflate(R.layout.http_authentication, null);
|
||||||
|
final TextView user = (TextView) v.findViewById(R.id.username);
|
||||||
|
final TextView pass = (TextView) v.findViewById(R.id.password);
|
||||||
|
final String title = String.format(mIitc.getResources().getString(R.string.sign_in_to), host, realm);
|
||||||
|
|
||||||
|
builder.setView(v)
|
||||||
|
.setTitle(title)
|
||||||
|
.setPositiveButton(R.string.sign_in_action, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
handler.proceed(user.getText().toString(), pass.getText().toString());
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
handler.cancel();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return builder.create();
|
||||||
|
}
|
||||||
|
|
||||||
public void reset() {
|
public void reset() {
|
||||||
mIitcInjected = false;
|
mIitcInjected = false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user