diff --git a/mobile/res/layout/http_authentication.xml b/mobile/res/layout/http_authentication.xml
index 7309f27c..5e68469b 100644
--- a/mobile/res/layout/http_authentication.xml
+++ b/mobile/res/layout/http_authentication.xml
@@ -1,62 +1,26 @@
-
-
-
-
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
-
-
-
+ android:layout_marginTop="16dp"
+ android:layout_marginLeft="4dp"
+ android:layout_marginRight="4dp"
+ android:layout_marginBottom="4dp"
+ android:hint="@string/username" />
-
-
+ 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"/>
+
\ No newline at end of file
diff --git a/mobile/res/values/strings.xml b/mobile/res/values/strings.xml
index 56802e6c..defcd13f 100644
--- a/mobile/res/values/strings.xml
+++ b/mobile/res/values/strings.xml
@@ -219,22 +219,11 @@
Copied to clipboard…
Do not show again
-
Sign in to %1$s %2$s"
-
- Name
-
+ Username
Password
-
- Sign in
-
- Save bookmark
-
- Browser
-
+ Sign in
Cancel
-
- OK
Locate
Share
diff --git a/mobile/src/com/cradle/iitc_mobile/HttpAuthenticationDialog.java b/mobile/src/com/cradle/iitc_mobile/HttpAuthenticationDialog.java
deleted file mode 100644
index 1b92aac5..00000000
--- a/mobile/src/com/cradle/iitc_mobile/HttpAuthenticationDialog.java
+++ /dev/null
@@ -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();
- }
-}
diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java b/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java
index c5b036a9..ef029793 100644
--- a/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java
+++ b/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java
@@ -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;
}