mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 21:29:54 +01:00
[android] Save attached (but not sent) image on screen rotation
This commit is contained in:
@@ -4,9 +4,12 @@ import android.content.ClipData;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.annotation.UiThread;
|
import android.support.annotation.UiThread;
|
||||||
import android.support.design.widget.FloatingActionButton;
|
import android.support.design.widget.FloatingActionButton;
|
||||||
|
import android.support.v4.view.AbsSavedState;
|
||||||
import android.support.v7.graphics.Palette;
|
import android.support.v7.graphics.Palette;
|
||||||
import android.support.v7.widget.AppCompatImageButton;
|
import android.support.v7.widget.AppCompatImageButton;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
@@ -35,6 +38,7 @@ import static android.content.Intent.EXTRA_ALLOW_MULTIPLE;
|
|||||||
import static android.graphics.Color.BLACK;
|
import static android.graphics.Color.BLACK;
|
||||||
import static android.graphics.Color.WHITE;
|
import static android.graphics.Color.WHITE;
|
||||||
import static android.os.Build.VERSION.SDK_INT;
|
import static android.os.Build.VERSION.SDK_INT;
|
||||||
|
import static android.support.v4.view.AbsSavedState.EMPTY_STATE;
|
||||||
import static android.support.v7.app.AppCompatDelegate.MODE_NIGHT_YES;
|
import static android.support.v7.app.AppCompatDelegate.MODE_NIGHT_YES;
|
||||||
import static android.support.v7.app.AppCompatDelegate.getDefaultNightMode;
|
import static android.support.v7.app.AppCompatDelegate.getDefaultNightMode;
|
||||||
import static android.view.View.GONE;
|
import static android.view.View.GONE;
|
||||||
@@ -92,15 +96,19 @@ class TextInputAttachmentController implements TextWatcher {
|
|||||||
if (resultData == null) return;
|
if (resultData == null) return;
|
||||||
if (resultData.getData() != null) {
|
if (resultData.getData() != null) {
|
||||||
imageUris = singletonList(resultData.getData());
|
imageUris = singletonList(resultData.getData());
|
||||||
|
onNewUris();
|
||||||
} else if (SDK_INT >= 18 && resultData.getClipData() != null) {
|
} else if (SDK_INT >= 18 && resultData.getClipData() != null) {
|
||||||
ClipData clipData = resultData.getClipData();
|
ClipData clipData = resultData.getClipData();
|
||||||
imageUris = new ArrayList<>(clipData.getItemCount());
|
imageUris = new ArrayList<>(clipData.getItemCount());
|
||||||
for (int i = 0; i < clipData.getItemCount(); i++) {
|
for (int i = 0; i < clipData.getItemCount(); i++) {
|
||||||
imageUris.add(clipData.getItemAt(i).getUri());
|
imageUris.add(clipData.getItemAt(i).getUri());
|
||||||
}
|
}
|
||||||
} else {
|
onNewUris();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onNewUris() {
|
||||||
|
if (imageUris.isEmpty()) return;
|
||||||
showImageButton(false);
|
showImageButton(false);
|
||||||
editText.setHint(R.string.image_caption_hint);
|
editText.setHint(R.string.image_caption_hint);
|
||||||
imageLayout.setVisibility(VISIBLE);
|
imageLayout.setVisibility(VISIBLE);
|
||||||
@@ -208,4 +216,51 @@ class TextInputAttachmentController implements TextWatcher {
|
|||||||
showImageButton(true);
|
showImageButton(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Parcelable onSaveInstanceState(@Nullable Parcelable superState) {
|
||||||
|
SavedState state =
|
||||||
|
new SavedState(superState == null ? EMPTY_STATE : superState);
|
||||||
|
state.imageUris = imageUris;
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Parcelable onRestoreInstanceState(Parcelable inState) {
|
||||||
|
SavedState state = (SavedState) inState;
|
||||||
|
imageUris = state.imageUris;
|
||||||
|
onNewUris();
|
||||||
|
return state.getSuperState();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SavedState extends AbsSavedState {
|
||||||
|
private List<Uri> imageUris;
|
||||||
|
|
||||||
|
private SavedState(Parcelable superState) {
|
||||||
|
super(superState);
|
||||||
|
}
|
||||||
|
|
||||||
|
private SavedState(Parcel in) {
|
||||||
|
super(in);
|
||||||
|
//noinspection unchecked
|
||||||
|
imageUris = in.readArrayList(Uri.class.getClassLoader());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel out, int flags) {
|
||||||
|
super.writeToParcel(out, flags);
|
||||||
|
out.writeList(imageUris);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Parcelable.Creator<SavedState> CREATOR
|
||||||
|
= new Parcelable.Creator<SavedState>() {
|
||||||
|
public SavedState createFromParcel(Parcel in) {
|
||||||
|
return new SavedState(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SavedState[] newArray(int size) {
|
||||||
|
return new SavedState[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import android.content.res.TypedArray;
|
|||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
import android.os.Parcelable;
|
||||||
import android.support.annotation.CallSuper;
|
import android.support.annotation.CallSuper;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.annotation.StringRes;
|
import android.support.annotation.StringRes;
|
||||||
@@ -77,6 +78,7 @@ public class TextInputView extends KeyboardAwareLinearLayout {
|
|||||||
setOrientation(VERTICAL);
|
setOrientation(VERTICAL);
|
||||||
setLayoutTransition(new LayoutTransition());
|
setLayoutTransition(new LayoutTransition());
|
||||||
inflateLayout(context);
|
inflateLayout(context);
|
||||||
|
setSaveEnabled(true);
|
||||||
if (!isInEditMode()) setUpViews(context, attrs);
|
if (!isInEditMode()) setUpViews(context, attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,6 +120,27 @@ public class TextInputView extends KeyboardAwareLinearLayout {
|
|||||||
sendButton.setOnClickListener(v -> onSendButtonClicked());
|
sendButton.setOnClickListener(v -> onSendButtonClicked());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
protected Parcelable onSaveInstanceState() {
|
||||||
|
Parcelable superState = super.onSaveInstanceState();
|
||||||
|
if (attachmentController != null) {
|
||||||
|
superState = attachmentController.onSaveInstanceState(superState);
|
||||||
|
}
|
||||||
|
return superState;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onRestoreInstanceState(Parcelable state) {
|
||||||
|
if (attachmentController != null) {
|
||||||
|
Parcelable outState =
|
||||||
|
attachmentController.onRestoreInstanceState(state);
|
||||||
|
super.onRestoreInstanceState(outState);
|
||||||
|
} else {
|
||||||
|
super.onRestoreInstanceState(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setListener(TextInputListener listener) {
|
public void setListener(TextInputListener listener) {
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user