cleaned up captcha dialog

This commit is contained in:
Daniel Gultsch 2016-04-28 20:13:58 +02:00
parent 5021b9a5dd
commit 51753a1d39
3 changed files with 71 additions and 55 deletions

View file

@ -892,65 +892,55 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
} }
@Override @Override
public void onCaptchaRequested(final Account account, final String id, final Data data, public void onCaptchaRequested(final Account account, final String id, final Data data, final Bitmap captcha) {
final Bitmap captcha) {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
final ImageView view = new ImageView(this);
final LinearLayout layout = new LinearLayout(this);
final EditText input = new EditText(this);
view.setImageBitmap(captcha);
view.setScaleType(ImageView.ScaleType.FIT_CENTER);
input.setHint(getString(R.string.captcha_hint));
layout.setOrientation(LinearLayout.VERTICAL);
layout.addView(view);
layout.addView(input);
builder.setTitle(getString(R.string.captcha_required));
builder.setView(layout);
builder.setPositiveButton(getString(R.string.ok),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String rc = input.getText().toString();
data.put("username", account.getUsername());
data.put("password", account.getPassword());
data.put("ocr", rc);
data.submit();
if (xmppConnectionServiceBound) {
xmppConnectionService.sendCreateAccountWithCaptchaPacket(
account, id, data);
}
}
});
builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (xmppConnectionService != null) {
xmppConnectionService.sendCreateAccountWithCaptchaPacket(account, null, null);
}
}
});
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
if (xmppConnectionService != null) {
xmppConnectionService.sendCreateAccountWithCaptchaPacket(account, null, null);
}
}
});
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
if ((mCaptchaDialog != null) && mCaptchaDialog.isShowing()) { if ((mCaptchaDialog != null) && mCaptchaDialog.isShowing()) {
mCaptchaDialog.dismiss(); mCaptchaDialog.dismiss();
} }
final AlertDialog.Builder builder = new AlertDialog.Builder(EditAccountActivity.this);
final View view = getLayoutInflater().inflate(R.layout.captcha, null);
final ImageView imageView = (ImageView) view.findViewById(R.id.captcha);
final EditText input = (EditText) view.findViewById(R.id.input);
imageView.setImageBitmap(captcha);
builder.setTitle(getString(R.string.captcha_required));
builder.setView(view);
builder.setPositiveButton(getString(R.string.ok),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String rc = input.getText().toString();
data.put("username", account.getUsername());
data.put("password", account.getPassword());
data.put("ocr", rc);
data.submit();
if (xmppConnectionServiceBound) {
xmppConnectionService.sendCreateAccountWithCaptchaPacket(
account, id, data);
}
}
});
builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (xmppConnectionService != null) {
xmppConnectionService.sendCreateAccountWithCaptchaPacket(account, null, null);
}
}
});
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
if (xmppConnectionService != null) {
xmppConnectionService.sendCreateAccountWithCaptchaPacket(account, null, null);
}
}
});
mCaptchaDialog = builder.create(); mCaptchaDialog = builder.create();
mCaptchaDialog.show(); mCaptchaDialog.show();
} }

View file

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/captcha"
android:layout_gravity="center_horizontal"/>
<EditText
android:id="@+id/input"
android:layout_marginTop="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textNoSuggestions"
android:textColor="@color/black87"
android:textColorHint="@color/black54"
android:textSize="?attr/TextSizeBody"
android:hint="@string/captcha_hint">
<requestFocus />
</EditText>
</LinearLayout>

View file

@ -557,9 +557,8 @@
<string name="server_side_mam_prefs">Server-side archiving preferences</string> <string name="server_side_mam_prefs">Server-side archiving preferences</string>
<string name="fetching_mam_prefs">Fetching archiving preferences. Please wait…</string> <string name="fetching_mam_prefs">Fetching archiving preferences. Please wait…</string>
<string name="unable_to_fetch_mam_prefs">Unable to fetch archiving preferences</string> <string name="unable_to_fetch_mam_prefs">Unable to fetch archiving preferences</string>
<string name="captcha_ocr">Captcha text</string>
<string name="captcha_required">Captcha required</string> <string name="captcha_required">Captcha required</string>
<string name="captcha_hint">enter the text from the image</string> <string name="captcha_hint">Enter the text from the image above</string>
<string name="certificate_chain_is_not_trusted">Certificate chain is not trusted</string> <string name="certificate_chain_is_not_trusted">Certificate chain is not trusted</string>
<string name="jid_does_not_match_certificate">Jabber ID does not match certificate</string> <string name="jid_does_not_match_certificate">Jabber ID does not match certificate</string>
<string name="action_renew_certificate">Renew certificate</string> <string name="action_renew_certificate">Renew certificate</string>