diff --git a/res/drawable/conversation_attachment_close_circle.xml b/res/drawable/conversation_attachment_close_circle.xml index 2b799c02db..6231cb8fb3 100644 --- a/res/drawable/conversation_attachment_close_circle.xml +++ b/res/drawable/conversation_attachment_close_circle.xml @@ -9,7 +9,7 @@ - + diff --git a/res/layout/conversation_activity.xml b/res/layout/conversation_activity.xml index 250901350a..fd6e1786b3 100644 --- a/res/layout/conversation_activity.xml +++ b/res/layout/conversation_activity.xml @@ -29,7 +29,6 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" - android:paddingTop="10dp" android:background="?android:windowBackground" android:visibility="gone"> @@ -41,13 +40,6 @@ android:contentDescription="@string/conversation_activity__attachment_thumbnail" app:backgroundColorHint="?conversation_background" /> - - - + - + + diff --git a/res/layout/thumbnail_view_progress_wheel.xml b/res/layout/thumbnail_view_progress_wheel.xml new file mode 100644 index 0000000000..6aeefdf7b2 --- /dev/null +++ b/res/layout/thumbnail_view_progress_wheel.xml @@ -0,0 +1,12 @@ + + diff --git a/res/layout/thumbnail_view_remove_button.xml b/res/layout/thumbnail_view_remove_button.xml new file mode 100644 index 0000000000..2ef239b575 --- /dev/null +++ b/res/layout/thumbnail_view_remove_button.xml @@ -0,0 +1,6 @@ + + diff --git a/src/org/thoughtcrime/securesms/components/ThumbnailView.java b/src/org/thoughtcrime/securesms/components/ThumbnailView.java index 41e77c6c0a..492ff0f1a6 100644 --- a/src/org/thoughtcrime/securesms/components/ThumbnailView.java +++ b/src/org/thoughtcrime/securesms/components/ThumbnailView.java @@ -5,6 +5,7 @@ import android.app.Activity; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Color; +import android.os.Build; import android.os.Build.VERSION; import android.os.Build.VERSION_CODES; import android.support.annotation.NonNull; @@ -16,6 +17,7 @@ import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; import android.widget.FrameLayout; +import android.widget.ImageButton; import android.widget.ImageView; import com.bumptech.glide.DrawableTypeRequest; @@ -37,6 +39,7 @@ import org.thoughtcrime.securesms.mms.SlideDeck; import org.thoughtcrime.securesms.util.FutureTaskListener; import org.thoughtcrime.securesms.util.ListenableFutureTask; import org.thoughtcrime.securesms.util.Util; +import org.thoughtcrime.securesms.util.ViewUtil; import de.greenrobot.event.EventBus; import ws.com.google.android.mms.pdu.PduPart; @@ -47,6 +50,7 @@ public class ThumbnailView extends FrameLayout { private boolean showProgress = true; private ImageView image; private ProgressWheel progress; + private ImageView removeButton; private int backgroundColorHint; private int radius; @@ -68,8 +72,7 @@ public class ThumbnailView extends FrameLayout { super(context, attrs, defStyle); inflate(context, R.layout.thumbnail_view, this); radius = getResources().getDimensionPixelSize(R.dimen.message_bubble_corner_radius); - image = (ImageView) findViewById(R.id.thumbnail_image); - progress = (ProgressWheel) findViewById(R.id.progress_wheel); + image = (ImageView) findViewById(R.id.thumbnail_image); if (attrs != null) { TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ThumbnailView, 0, 0); @@ -78,6 +81,15 @@ public class ThumbnailView extends FrameLayout { } } + @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { + super.onLayout(changed, left, top, right, bottom); + if (removeButton != null) { + final int paddingHorizontal = removeButton.getWidth() / 2; + final int paddingVertical = removeButton.getHeight() / 2; + image.setPadding(paddingHorizontal, paddingVertical, paddingHorizontal, 0); + } + } + @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); if (!EventBus.getDefault().isRegistered(this)) EventBus.getDefault().registerSticky(this); @@ -88,12 +100,26 @@ public class ThumbnailView extends FrameLayout { EventBus.getDefault().unregister(this); } + private ProgressWheel getProgressWheel() { + if (progress == null) progress = ViewUtil.inflateStub(this, R.id.progress_wheel_stub); + return progress; + } + + private void hideProgressWheel() { + if (progress != null) progress.setVisibility(GONE); + } + + private ImageView getRemoveButton() { + if (removeButton == null) removeButton = ViewUtil.inflateStub(this, R.id.remove_button_stub); + return removeButton; + } + @SuppressWarnings("unused") public void onEventAsync(final PartProgressEvent event) { if (this.slide != null && event.partId.equals(this.slide.getPart().getPartId())) { Util.runOnMain(new Runnable() { @Override public void run() { - progress.setInstantProgress(((float)event.progress) / event.total); + getProgressWheel().setInstantProgress(((float)event.progress) / event.total); if (event.progress >= event.total) animateOutProgress(); } }); @@ -115,7 +141,7 @@ public class ThumbnailView extends FrameLayout { String slideId = id + "::" + timestamp; if (!slideId.equals(this.slideId)) { - progress.setVisibility(GONE); + hideProgressWheel(); image.setImageDrawable(null); this.slide = null; this.slideId = slideId; @@ -138,10 +164,10 @@ public class ThumbnailView extends FrameLayout { this.slide = slide; if (slide.isInProgress() && showProgress) { - progress.spin(); - progress.setVisibility(VISIBLE); + getProgressWheel().spin(); + getProgressWheel().setVisibility(VISIBLE); } else { - progress.setVisibility(GONE); + hideProgressWheel(); } buildGlideRequest(slide, masterSecret).into(image); setOnClickListener(new ThumbnailClickDispatcher(thumbnailClickListener, slide)); @@ -151,13 +177,17 @@ public class ThumbnailView extends FrameLayout { this.thumbnailClickListener = listener; } + public void setRemoveClickListener(OnClickListener listener) { + getRemoveButton().setOnClickListener(listener); + } + public void clear() { if (isContextValid()) Glide.clear(this); } public void setShowProgress(boolean showProgress) { this.showProgress = showProgress; - if (progress.getVisibility() == View.VISIBLE && !showProgress) { + if (progress != null && progress.getVisibility() == View.VISIBLE && !showProgress) { animateOutProgress(); } } @@ -221,16 +251,17 @@ public class ThumbnailView extends FrameLayout { } private void animateOutProgress() { + if (progress == null) return; AlphaAnimation animation = new AlphaAnimation(1f, 0f); animation.setDuration(200); animation.setAnimationListener(new AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { - progress.setVisibility(View.GONE); + getProgressWheel().setVisibility(View.GONE); } }); - progress.startAnimation(animation); + getProgressWheel().startAnimation(animation); } private class SlideDeckListener implements FutureTaskListener { @@ -300,7 +331,7 @@ public class ThumbnailView extends FrameLayout { } } - private static class PduThumbnailSetListener implements RequestListener { + private class PduThumbnailSetListener implements RequestListener { private PduPart part; public PduThumbnailSetListener(@NonNull PduPart part) { @@ -318,6 +349,11 @@ public class ThumbnailView extends FrameLayout { Log.w(TAG, "onResourceReady() for a Bitmap. Saving."); part.setThumbnail(((GlideBitmapDrawable)resource).getBitmap()); } + if (resource.getIntrinsicWidth() < resource.getIntrinsicHeight()) { + getRemoveButton().setPadding(0, 0, (getWidth() - resource.getIntrinsicWidth()) / 2, 0); + } else { + getRemoveButton().setPadding(0, (getHeight() - resource.getIntrinsicHeight()) / 2, 0, 0); + } return false; } } diff --git a/src/org/thoughtcrime/securesms/mms/AttachmentManager.java b/src/org/thoughtcrime/securesms/mms/AttachmentManager.java index a88ee81cd8..bb0168b911 100644 --- a/src/org/thoughtcrime/securesms/mms/AttachmentManager.java +++ b/src/org/thoughtcrime/securesms/mms/AttachmentManager.java @@ -29,7 +29,6 @@ import android.util.Log; import android.view.View; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; -import android.widget.ImageView; import android.widget.Toast; import org.thoughtcrime.securesms.R; @@ -48,7 +47,6 @@ public class AttachmentManager { private final Context context; private final View attachmentView; private final ThumbnailView thumbnail; - private final ImageView removeButton; private final SlideDeck slideDeck; private final AttachmentListener attachmentListener; @@ -57,12 +55,11 @@ public class AttachmentManager { public AttachmentManager(Activity view, AttachmentListener listener) { this.attachmentView = view.findViewById(R.id.attachment_editor); this.thumbnail = (ThumbnailView)view.findViewById(R.id.attachment_thumbnail); - this.removeButton = (ImageView)view.findViewById(R.id.remove_image_button); this.slideDeck = new SlideDeck(); this.context = view; this.attachmentListener = listener; - this.removeButton.setOnClickListener(new RemoveButtonListener()); + thumbnail.setRemoveClickListener(new RemoveButtonListener()); } public void clear() { @@ -76,7 +73,6 @@ public class AttachmentManager { attachmentView.setVisibility(View.GONE); attachmentListener.onAttachmentChanged(); } - }); attachmentView.startAnimation(animation); diff --git a/src/org/thoughtcrime/securesms/util/ViewUtil.java b/src/org/thoughtcrime/securesms/util/ViewUtil.java index 4a88dfdb23..8e41190b80 100644 --- a/src/org/thoughtcrime/securesms/util/ViewUtil.java +++ b/src/org/thoughtcrime/securesms/util/ViewUtil.java @@ -18,12 +18,14 @@ package org.thoughtcrime.securesms.util; import android.graphics.drawable.Drawable; import android.support.annotation.DrawableRes; +import android.support.annotation.IdRes; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.text.TextUtils; import android.text.TextUtils.TruncateAt; import android.view.View; import android.view.ViewGroup; +import android.view.ViewStub; import android.widget.TextView; public class ViewUtil { @@ -61,4 +63,9 @@ public class ViewUtil { TruncateAt.END); } } + + @SuppressWarnings("unchecked") + public static T inflateStub(@NonNull View parent, @IdRes int stubId) { + return (T)((ViewStub)parent.findViewById(stubId)).inflate(); + } }