1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-04 18:29:23 +02:00

CredentialProvider has been moved from NetworkCatalogActivity to AuthenticationActivity

This commit is contained in:
Nikolay Pultsin 2011-07-15 20:12:38 +01:00
parent 1f8c4a6f54
commit f0a082c3f9
2 changed files with 70 additions and 60 deletions

View file

@ -26,20 +26,79 @@ import android.view.View;
import android.widget.TextView;
import android.widget.Button;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.geometerplus.zlibrary.core.resources.ZLResource;
import org.geometerplus.zlibrary.core.network.ZLNetworkManager;
import org.geometerplus.zlibrary.core.options.ZLStringOption;
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";
final static String ERROR_KEY = "error";
final static String SHOW_SIGNUP_LINK_KEY = "showSignupLink";
private static final String AREA_KEY = "area";
private static final String HOST_KEY = "host";
static final String SCHEME_KEY = "scheme";
static final String USERNAME_KEY = "username";
static final String PASSWORD_KEY = "password";
static final String ERROR_KEY = "error";
static final String SHOW_SIGNUP_LINK_KEY = "showSignupLink";
static final int RESULT_SIGNUP = RESULT_FIRST_USER;
final static int RESULT_SIGNUP = RESULT_FIRST_USER;
static class CredentialsCreator implements ZLNetworkManager.CredentialsCreator {
private final Activity myActivity;
private final int myCode;
private volatile String myUsername;
private volatile String myPassword;
CredentialsCreator(Activity activity, int code) {
myActivity = activity;
myCode = code;
}
synchronized void onDataReceived(int resultCode, Intent data) {
if (resultCode == RESULT_OK && data != null) {
myUsername = data.getStringExtra(USERNAME_KEY);
myPassword = data.getStringExtra(PASSWORD_KEY);
}
notify();
}
public Credentials createCredentials(String scheme, AuthScope scope) {
if (!"basic".equalsIgnoreCase(scope.getScheme())) {
return null;
}
final Intent intent = new Intent();
final String host = scope.getHost();
final String area = scope.getRealm();
final ZLStringOption option = new ZLStringOption("username", host + ":" + area, "");
intent.setClass(myActivity, AuthenticationActivity.class);
intent.putExtra(HOST_KEY, host);
intent.putExtra(AREA_KEY, area);
intent.putExtra(SCHEME_KEY, scheme);
intent.putExtra(USERNAME_KEY, option.getValue());
myActivity.startActivityForResult(intent, myCode);
synchronized (this) {
try {
wait();
} catch (InterruptedException e) {
}
}
Credentials creds = null;
if (myUsername != null && myPassword != null) {
option.setValue(myUsername);
creds = new UsernamePasswordCredentials(myUsername, myPassword);
}
myUsername = null;
myPassword = null;
return creds;
}
}
private ZLResource myResource;