replaced copied AOSP code with own implementation

This commit is contained in:
Philipp Schaefer 2014-07-21 20:47:40 +02:00
parent 0218bd5565
commit b96f054424
4 changed files with 53 additions and 249 deletions

View File

@ -1,62 +1,26 @@
<?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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<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" />
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/username_edit"
android:layout_height="wrap_content"
android:id="@+id/username"
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_width="wrap_content"
android:text="@string/password"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip" />
android:layout_marginTop="16dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginBottom="4dp"
android:hint="@string/username" />
<EditText
android:id="@+id/password_edit"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:scrollHorizontally="true"
android:id="@+id/password"
android:inputType="textPassword"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:layout_marginBottom="12dip"
android:singleLine="true"
android:imeOptions="actionDone" />
</LinearLayout>
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginBottom="16dp"
android:hint="@string/password"/>
</LinearLayout>

View File

@ -219,22 +219,11 @@
<string name="msg_copied">Copied to clipboard…</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>
<!-- Prompt for an input box that allows the user to enter their login name -->
<string name="username">Name</string>
<!-- Prompt for an input box that allows the user to enter their password -->
<string name="username">Username</string>
<string name="password">Password</string>
<!-- The label on the "sign in" button -->
<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="sign_in_action">Sign in</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_share">Share</string>

View File

@ -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();
}
}

View File

@ -1,6 +1,8 @@
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.SharedPreferences;
import android.net.Uri;
@ -8,11 +10,14 @@ import android.net.http.SslError;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.webkit.HttpAuthHandler;
import android.webkit.SslErrorHandler;
import android.webkit.WebResourceResponse;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;
import java.io.ByteArrayInputStream;
import java.util.LinkedList;
@ -176,7 +181,8 @@ public class IITC_WebViewClient extends WebViewClient {
String username = null;
String password = null;
boolean reuseHttpAuthUsernamePassword
final boolean reuseHttpAuthUsernamePassword
= handler.useHttpAuthUsernamePassword();
if (reuseHttpAuthUsernamePassword && view != null) {
@ -190,24 +196,35 @@ public class IITC_WebViewClient extends WebViewClient {
if (username != null && password != null) {
handler.proceed(username, password);
} else {
HttpAuthenticationDialog dialog = new HttpAuthenticationDialog(mIitc, host, realm);
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();
createSignInDialog(handler, host, realm).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() {
mIitcInjected = false;
}