Save signature dirty state

This commit is contained in:
M66B 2021-07-02 22:35:41 +02:00
parent 16cc28f5df
commit 6ae0d5480d
2 changed files with 56 additions and 6 deletions

View File

@ -174,15 +174,15 @@ public class ActivitySignature extends ActivityBase {
}
}, this);
if (savedInstanceState != null)
etText.setRaw(savedInstanceState.getBoolean("fair:raw"));
style_bar.setVisibility(View.GONE);
setResult(RESULT_CANCELED, new Intent());
load(getIntent().getStringExtra("html"));
dirty = false;
if (savedInstanceState == null) {
load(getIntent().getStringExtra("html"));
dirty = false;
} else
dirty = savedInstanceState.getBoolean("fair:dirty");
}
@Override
@ -196,7 +196,7 @@ public class ActivitySignature extends ActivityBase {
@Override
protected void onSaveInstanceState(Bundle outState) {
outState.putBoolean("fair:raw", etText.isRaw());
outState.putBoolean("fair:dirty", dirty);
super.onSaveInstanceState(outState);
}

View File

@ -26,11 +26,14 @@ import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.Html;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.QuoteSpan;
import android.util.AttributeSet;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
@ -65,6 +68,19 @@ public class EditTextCompose extends FixedEditText {
Helper.setKeyboardIncognitoMode(this, context);
}
@Override
public Parcelable onSaveInstanceState() {
Parcelable superState = super.onSaveInstanceState();
return new SavedState(superState, this.raw);
}
@Override
public void onRestoreInstanceState(Parcelable state) {
SavedState savedState = (SavedState) state;
super.onRestoreInstanceState(savedState.getSuperState());
setRaw(savedState.getRaw());
}
@Override
protected void onAttachedToWindow() {
// Spellchecker workaround
@ -270,4 +286,38 @@ public class EditTextCompose extends FixedEditText {
interface ISelection {
void onSelected(boolean selection);
}
static class SavedState extends View.BaseSavedState {
private boolean raw;
private SavedState(Parcelable superState, boolean raw) {
super(superState);
this.raw = raw;
}
private SavedState(Parcel in) {
super(in);
raw = (in.readInt() != 0);
}
public boolean getRaw() {
return this.raw;
}
@Override
public void writeToParcel(Parcel destination, int flags) {
super.writeToParcel(destination, flags);
destination.writeInt(raw ? 1 : 0);
}
public static final Parcelable.Creator<SavedState> CREATOR = new Creator<SavedState>() {
public SavedState createFromParcel(Parcel in) {
return new SavedState(in);
}
public SavedState[] newArray(int size) {
return new SavedState[size];
}
};
}
}