diff --git a/ChangeLog b/ChangeLog
index f2b1bea2b..f02020b2b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,5 @@
===== 1.0.7 (Apr ??, 2011) =====
+* Basic authentication (for OPDS catalogs) has been implemented
* Fixed unexpected scrolling after brightness adjustment
* Fixed custom OPDS catalogs search
* Fixed freezes in library view
diff --git a/assets/resources/application/cs.xml b/assets/resources/application/cs.xml
index bda0756d0..5a12ec116 100644
--- a/assets/resources/application/cs.xml
+++ b/assets/resources/application/cs.xml
@@ -622,6 +622,7 @@
+
diff --git a/assets/resources/application/de.xml b/assets/resources/application/de.xml
index be42ea430..589b1bf38 100644
--- a/assets/resources/application/de.xml
+++ b/assets/resources/application/de.xml
@@ -609,6 +609,7 @@
+
diff --git a/assets/resources/application/en.xml b/assets/resources/application/en.xml
index 45e12881f..81915f3c5 100644
--- a/assets/resources/application/en.xml
+++ b/assets/resources/application/en.xml
@@ -621,6 +621,7 @@
+
diff --git a/assets/resources/application/fr.xml b/assets/resources/application/fr.xml
index 9457b4fd9..44f795e27 100644
--- a/assets/resources/application/fr.xml
+++ b/assets/resources/application/fr.xml
@@ -611,6 +611,7 @@
+
diff --git a/assets/resources/application/gl.xml b/assets/resources/application/gl.xml
index ee486580b..4fc1e831a 100644
--- a/assets/resources/application/gl.xml
+++ b/assets/resources/application/gl.xml
@@ -608,6 +608,7 @@
+
diff --git a/assets/resources/application/hu.xml b/assets/resources/application/hu.xml
index 0a111d164..30d756000 100644
--- a/assets/resources/application/hu.xml
+++ b/assets/resources/application/hu.xml
@@ -608,6 +608,7 @@
+
diff --git a/assets/resources/application/it.xml b/assets/resources/application/it.xml
index 245741912..c0201845c 100644
--- a/assets/resources/application/it.xml
+++ b/assets/resources/application/it.xml
@@ -608,6 +608,7 @@
+
diff --git a/assets/resources/application/nl.xml b/assets/resources/application/nl.xml
index 6864b6cd4..77abca8b4 100644
--- a/assets/resources/application/nl.xml
+++ b/assets/resources/application/nl.xml
@@ -608,6 +608,7 @@
+
diff --git a/assets/resources/application/ru.xml b/assets/resources/application/ru.xml
index 72ada3d78..5ccb65f76 100644
--- a/assets/resources/application/ru.xml
+++ b/assets/resources/application/ru.xml
@@ -607,6 +607,7 @@
+
diff --git a/assets/resources/application/th.xml b/assets/resources/application/th.xml
index 4b2da8982..bd96fcc37 100644
--- a/assets/resources/application/th.xml
+++ b/assets/resources/application/th.xml
@@ -608,6 +608,7 @@
+
diff --git a/assets/resources/application/uk.xml b/assets/resources/application/uk.xml
index 2038704db..6e7a4cef9 100644
--- a/assets/resources/application/uk.xml
+++ b/assets/resources/application/uk.xml
@@ -608,6 +608,7 @@
+
diff --git a/assets/resources/application/vi.xml b/assets/resources/application/vi.xml
index ab358bfad..6ea41a603 100644
--- a/assets/resources/application/vi.xml
+++ b/assets/resources/application/vi.xml
@@ -608,6 +608,7 @@
+
diff --git a/assets/resources/application/zh.xml b/assets/resources/application/zh.xml
index e2171b334..e79a8d9a6 100644
--- a/assets/resources/application/zh.xml
+++ b/assets/resources/application/zh.xml
@@ -608,6 +608,7 @@
+
diff --git a/res/layout/authentication.xml b/res/layout/authentication.xml
new file mode 100644
index 000000000..6074d6576
--- /dev/null
+++ b/res/layout/authentication.xml
@@ -0,0 +1,86 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/org/geometerplus/android/fbreader/network/AuthenticationActivity.java b/src/org/geometerplus/android/fbreader/network/AuthenticationActivity.java
new file mode 100644
index 000000000..c6f90d34c
--- /dev/null
+++ b/src/org/geometerplus/android/fbreader/network/AuthenticationActivity.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2010-2011 Geometer Plus
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+package org.geometerplus.android.fbreader.network;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.TextView;
+import android.widget.Button;
+
+import org.geometerplus.zlibrary.core.options.ZLStringOption;
+import org.geometerplus.zlibrary.core.resources.ZLResource;
+
+import org.geometerplus.zlibrary.ui.android.R;
+
+public class AuthenticationActivity extends Activity {
+ final static String AREA_KEY = "area";
+ final static String HOST_KEY = "host";
+ final static String SCHEME_KEY = "scheme";
+ final static String USERNAME_KEY = "username";
+ final static String PASSWORD_KEY = "password";
+
+ private ZLResource myResource;
+
+ @Override
+ public void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+ Thread.setDefaultUncaughtExceptionHandler(new org.geometerplus.zlibrary.ui.android.library.UncaughtExceptionHandler(this));
+ setContentView(R.layout.authentication);
+
+ final Intent intent = getIntent();
+ final String host = intent.getStringExtra(HOST_KEY);
+ final String area = intent.getStringExtra(AREA_KEY);
+
+ setTitle(area);
+
+ myResource = ZLResource.resource("dialog").getResource("AuthenticationDialog");
+ final ZLStringOption option = new ZLStringOption("username", host + ":" + area, "");
+
+ findTextView(R.id.authentication_subtitle).setText(host);
+ final TextView warningView = findTextView(R.id.authentication_unencrypted_warning);
+ if ("https".equalsIgnoreCase(intent.getStringExtra(SCHEME_KEY))) {
+ warningView.setVisibility(View.GONE);
+ } else {
+ warningView.setText(myResource.getResource("unencryptedWarning").getValue());
+ }
+ findTextView(R.id.authentication_username_label).setText(
+ myResource.getResource("login").getValue()
+ );
+ findTextView(R.id.authentication_password_label).setText(
+ myResource.getResource("password").getValue()
+ );
+
+ final TextView username = findTextView(R.id.authentication_username);
+ username.setText(option.getValue());
+
+ final ZLResource buttonResource = ZLResource.resource("dialog").getResource("button");
+
+ final Button okButton = findButton(R.id.authentication_ok_button);
+ okButton.setText(buttonResource.getResource("ok").getValue());
+ okButton.setOnClickListener(new Button.OnClickListener() {
+ public void onClick(View v) {
+ final Intent data = new Intent();
+ final String usernameString = username.getText().toString();
+ option.setValue(usernameString);
+ data.putExtra(
+ USERNAME_KEY,
+ usernameString
+ );
+ data.putExtra(
+ PASSWORD_KEY,
+ findTextView(R.id.authentication_password).getText().toString()
+ );
+ setResult(0, data);
+ finish();
+ }
+ });
+
+ final Button cancelButton = findButton(R.id.authentication_cancel_button);
+ cancelButton.setText(buttonResource.getResource("cancel").getValue());
+ cancelButton.setOnClickListener(new Button.OnClickListener() {
+ public void onClick(View v) {
+ finish();
+ }
+ });
+ }
+
+ private TextView findTextView(int resourceId) {
+ return (TextView)findViewById(resourceId);
+ }
+
+ private Button findButton(int resourceId) {
+ return (Button)findViewById(resourceId);
+ }
+}
diff --git a/src/org/geometerplus/android/fbreader/network/NetworkBaseActivity.java b/src/org/geometerplus/android/fbreader/network/NetworkBaseActivity.java
index 9dc5357aa..246a5fdec 100644
--- a/src/org/geometerplus/android/fbreader/network/NetworkBaseActivity.java
+++ b/src/org/geometerplus/android/fbreader/network/NetworkBaseActivity.java
@@ -19,6 +19,8 @@
package org.geometerplus.android.fbreader.network;
+import java.net.*;
+
import android.app.*;
import android.os.Bundle;
import android.view.*;
@@ -44,6 +46,8 @@ import org.geometerplus.fbreader.network.tree.SearchItemTree;
import org.geometerplus.android.fbreader.tree.ZLAndroidTree;
abstract class NetworkBaseActivity extends ListActivity implements NetworkView.EventListener {
+ protected static final int AUTHENTICATION_CODE = 1;
+
protected final ZLResource myResource = ZLResource.resource("networkView");
public BookDownloaderServiceConnection Connection;
@@ -61,15 +65,6 @@ abstract class NetworkBaseActivity extends ListActivity implements NetworkView.E
);
}
- @Override
- public void onDestroy() {
- if (Connection != null) {
- unbindService(Connection);
- Connection = null;
- }
- super.onDestroy();
- }
-
@Override
protected void onStart() {
super.onStart();
@@ -81,6 +76,47 @@ abstract class NetworkBaseActivity extends ListActivity implements NetworkView.E
NetworkView.Instance().addEventListener(this);
}
+ private final class MyAuthenticator extends Authenticator {
+ private volatile String myUsername;
+ private volatile String myPassword;
+
+ @Override
+ protected PasswordAuthentication getPasswordAuthentication() {
+ final Intent intent = new Intent();
+ intent.setClass(NetworkBaseActivity.this, AuthenticationActivity.class);
+ intent.putExtra(AuthenticationActivity.AREA_KEY, getRequestingPrompt());
+ intent.putExtra(AuthenticationActivity.HOST_KEY, getRequestingSite().getHostName());
+ intent.putExtra(AuthenticationActivity.SCHEME_KEY, getRequestingProtocol());
+ startActivityForResult(intent, AUTHENTICATION_CODE);
+ synchronized (this) {
+ try {
+ wait();
+ } catch (InterruptedException e) {
+ }
+ }
+ System.err.println("auth thread: " + Thread.currentThread());
+ PasswordAuthentication result = null;
+ if (myUsername != null && myPassword != null) {
+ result = new PasswordAuthentication(myUsername, myPassword.toCharArray());
+ }
+ myUsername = null;
+ myPassword = null;
+ return result;
+ }
+ }
+
+ private final MyAuthenticator myAuthenticator = new MyAuthenticator();
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ getListView().setOnCreateContextMenuListener(this);
+ onModelChanged(); // do the same update actions as upon onModelChanged
+
+ System.err.println("UI thread: " + Thread.currentThread());
+ Authenticator.setDefault(myAuthenticator);
+ }
+
@Override
protected void onStop() {
NetworkView.Instance().removeEventListener(this);
@@ -88,12 +124,26 @@ abstract class NetworkBaseActivity extends ListActivity implements NetworkView.E
}
@Override
- public void onResume() {
- super.onResume();
- getListView().setOnCreateContextMenuListener(this);
- onModelChanged(); // do the same update actions as upon onModelChanged
+ public void onDestroy() {
+ if (Connection != null) {
+ unbindService(Connection);
+ Connection = null;
+ }
+ super.onDestroy();
}
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (requestCode == AUTHENTICATION_CODE) {
+ synchronized (myAuthenticator) {
+ if (data != null) {
+ myAuthenticator.myUsername = data.getStringExtra(AuthenticationActivity.USERNAME_KEY);
+ myAuthenticator.myPassword = data.getStringExtra(AuthenticationActivity.PASSWORD_KEY);
+ }
+ myAuthenticator.notify();
+ }
+ }
+ }
// method from NetworkView.EventListener
public void onModelChanged() {
diff --git a/src/org/geometerplus/android/fbreader/network/NetworkCatalogActivity.java b/src/org/geometerplus/android/fbreader/network/NetworkCatalogActivity.java
index 29002cded..fddd88329 100644
--- a/src/org/geometerplus/android/fbreader/network/NetworkCatalogActivity.java
+++ b/src/org/geometerplus/android/fbreader/network/NetworkCatalogActivity.java
@@ -92,6 +92,9 @@ public class NetworkCatalogActivity extends NetworkBaseActivity implements UserR
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
+ default:
+ super.onActivityResult(requestCode, resultCode, data);
+ break;
case USER_REGISTRATION_REQUEST_CODE:
if (myTree instanceof NetworkCatalogTree &&
resultCode == RESULT_OK &&
diff --git a/src/org/geometerplus/android/fbreader/network/NetworkView.java b/src/org/geometerplus/android/fbreader/network/NetworkView.java
index 3ee1cd824..24953e498 100644
--- a/src/org/geometerplus/android/fbreader/network/NetworkView.java
+++ b/src/org/geometerplus/android/fbreader/network/NetworkView.java
@@ -20,7 +20,6 @@
package org.geometerplus.android.fbreader.network;
import java.util.*;
-import java.net.*;
import android.content.Context;
import android.content.Intent;
@@ -40,18 +39,6 @@ class NetworkView {
public static NetworkView Instance() {
if (ourInstance == null) {
ourInstance = new NetworkView();
- Authenticator.setDefault(new Authenticator() {
- @Override
- protected PasswordAuthentication getPasswordAuthentication() {
- System.err.println("getPasswordAuthentication");
- System.err.println(getRequestingSite().getHostName());
- System.err.println(getRequestingPrompt());
- System.err.println(getRequestingProtocol());
- final String username = "geometer";
- final String password = "XXXXXXXX";
- return new PasswordAuthentication(username, password.toCharArray());
- }
- });
}
return ourInstance;
}