use of org.geometerplus.fbreader.network.NetworkLibrary in project FBReaderJ by geometer.
the class AuthenticationActivity method onCreate.
@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);
final String username = intent.getStringExtra(USERNAME_KEY);
final String error = intent.getStringExtra(ERROR_KEY);
myCustomAuthentication = intent.getBooleanExtra(CUSTOM_AUTH_KEY, false);
if (myCustomAuthentication) {
myLink = Util.networkLibrary(this).getLinkByUrl(String.valueOf(intent.getData()));
if (myLink == null) {
finish();
return;
}
setResult(RESULT_CANCELED, Util.intentByLink(new Intent(), myLink));
} else {
myLink = null;
setResult(RESULT_CANCELED);
}
myOnSuccessRunnable = ourOnSuccessRunnableMap.remove(intent.getLongExtra(RUNNABLE_KEY, -1));
myResource = ZLResource.resource("dialog").getResource("AuthenticationDialog");
setTitle(host != null ? host : myResource.getResource("title").getValue());
if (area != null && !"".equals(area)) {
findTextView(R.id.authentication_subtitle).setText(area);
} else {
findTextView(R.id.authentication_subtitle).setVisibility(View.GONE);
}
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());
myUsernameView = findTextView(R.id.authentication_username);
myUsernameView.setText(username);
setError(error);
final ZLResource buttonResource = ZLResource.resource("dialog").getResource("button");
final View buttonsView = findViewById(R.id.authentication_buttons);
myOkButton = (Button) buttonsView.findViewById(R.id.ok_button);
myOkButton.setText(buttonResource.getResource("ok").getValue());
myOkButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
final String username = myUsernameView.getText().toString();
final String password = findTextView(R.id.authentication_password).getText().toString();
if (myCustomAuthentication) {
runCustomAuthentication(username, password);
} else {
finishOk(username, password);
}
}
});
final Button cancelButton = (Button) buttonsView.findViewById(R.id.cancel_button);
cancelButton.setText(buttonResource.getResource("cancel").getValue());
cancelButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
runOnUiThread(new Runnable() {
public void run() {
if (myLink != null) {
final NetworkAuthenticationManager mgr = myLink.authenticationManager();
if (mgr.mayBeAuthorised(false)) {
mgr.logOut();
}
}
final NetworkLibrary library = Util.networkLibrary(AuthenticationActivity.this);
library.invalidateVisibility();
library.synchronize();
}
});
finish();
}
});
}
use of org.geometerplus.fbreader.network.NetworkLibrary in project FBReaderJ by geometer.
the class AuthenticationActivity method runCustomAuthentication.
private void runCustomAuthentication(final String username, final String password) {
final NetworkAuthenticationManager mgr = myLink.authenticationManager();
final Runnable runnable = new Runnable() {
public void run() {
try {
mgr.authorise(username, password);
if (mgr.needsInitialization()) {
mgr.initialize();
}
finishOk(username, password);
if (myOnSuccessRunnable != null) {
myOnSuccessRunnable.run();
}
final NetworkLibrary library = Util.networkLibrary(AuthenticationActivity.this);
library.invalidateVisibility();
library.synchronize();
} catch (final ZLNetworkException e) {
mgr.logOut();
runOnUiThread(new Runnable() {
public void run() {
setError(e.getMessage());
}
});
}
}
};
UIUtil.wait("authentication", runnable, this);
}
Aggregations