Signature save changes

This commit is contained in:
M66B 2021-05-09 08:22:16 +02:00
parent d88d158f64
commit 6439d6d107
1 changed files with 41 additions and 0 deletions

View File

@ -32,8 +32,10 @@ import android.text.Editable;
import android.text.Html;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.style.ImageSpan;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@ -53,6 +55,8 @@ import com.google.android.material.snackbar.Snackbar;
import org.jsoup.nodes.Document;
import java.util.Objects;
public class ActivitySignature extends ActivityBase {
private ViewGroup view;
private EditTextCompose etText;
@ -131,6 +135,43 @@ public class ActivitySignature extends ActivityBase {
}
});
addKeyPressedListener(new IKeyPressedListener() {
@Override
public boolean onKeyPressed(KeyEvent event) {
return false;
}
@Override
public boolean onBackPressed() {
String prev = getIntent().getStringExtra("html");
String current = getHtml();
boolean dirty = !Objects.equals(prev, current) &&
!(TextUtils.isEmpty(prev) && TextUtils.isEmpty(current));
if (dirty)
new AlertDialog.Builder(ActivitySignature.this)
.setTitle(R.string.title_ask_save)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
save();
finish();
}
})
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
})
.show();
else
finish();
return true;
}
}, this);
if (savedInstanceState != null)
etText.setRaw(savedInstanceState.getBoolean("fair:raw"));