diff --git a/res/drawable-hdpi/transfer_controls_background.9.png b/res/drawable-hdpi/transfer_controls_background.9.png index 0e503fb512..c7b7f575f4 100644 Binary files a/res/drawable-hdpi/transfer_controls_background.9.png and b/res/drawable-hdpi/transfer_controls_background.9.png differ diff --git a/res/drawable-mdpi/transfer_controls_background.9.png b/res/drawable-mdpi/transfer_controls_background.9.png index 3e63204968..5e8b65b45d 100644 Binary files a/res/drawable-mdpi/transfer_controls_background.9.png and b/res/drawable-mdpi/transfer_controls_background.9.png differ diff --git a/res/drawable-xhdpi/transfer_controls_background.9.png b/res/drawable-xhdpi/transfer_controls_background.9.png index 8f4d75a97b..3721dc5202 100644 Binary files a/res/drawable-xhdpi/transfer_controls_background.9.png and b/res/drawable-xhdpi/transfer_controls_background.9.png differ diff --git a/res/drawable-xxhdpi/transfer_controls_background.9.png b/res/drawable-xxhdpi/transfer_controls_background.9.png index cdbc966d88..0fa81940ce 100644 Binary files a/res/drawable-xxhdpi/transfer_controls_background.9.png and b/res/drawable-xxhdpi/transfer_controls_background.9.png differ diff --git a/res/drawable-xxxhdpi/transfer_controls_background.9.png b/res/drawable-xxxhdpi/transfer_controls_background.9.png index 4aad138cfd..e349e74058 100644 Binary files a/res/drawable-xxxhdpi/transfer_controls_background.9.png and b/res/drawable-xxxhdpi/transfer_controls_background.9.png differ diff --git a/src/org/thoughtcrime/securesms/components/AnimatingToggle.java b/src/org/thoughtcrime/securesms/components/AnimatingToggle.java index 30b100b89a..293e07fd31 100644 --- a/src/org/thoughtcrime/securesms/components/AnimatingToggle.java +++ b/src/org/thoughtcrime/securesms/components/AnimatingToggle.java @@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.components; import android.content.Context; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.v4.view.animation.FastOutSlowInInterpolator; import android.util.AttributeSet; import android.view.View; import android.view.ViewGroup; @@ -32,6 +33,8 @@ public class AnimatingToggle extends FrameLayout { super(context, attrs, defStyleAttr); this.outAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.animation_toggle_out); this.inAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.animation_toggle_in); + this.outAnimation.setInterpolator(new FastOutSlowInInterpolator()); + this.inAnimation.setInterpolator(new FastOutSlowInInterpolator()); } @Override diff --git a/src/org/thoughtcrime/securesms/components/TransferControlView.java b/src/org/thoughtcrime/securesms/components/TransferControlView.java index 282a7ae6aa..19721b1e94 100644 --- a/src/org/thoughtcrime/securesms/components/TransferControlView.java +++ b/src/org/thoughtcrime/securesms/components/TransferControlView.java @@ -1,14 +1,17 @@ package org.thoughtcrime.securesms.components; import android.content.Context; +import android.graphics.PorterDuff.Mode; +import android.graphics.drawable.Drawable; +import android.os.Build.VERSION; +import android.os.Build.VERSION_CODES; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.v4.content.ContextCompat; import android.support.v4.view.animation.FastOutSlowInInterpolator; import android.util.AttributeSet; import android.view.View; import android.view.ViewGroup; -import android.view.animation.AlphaAnimation; -import android.view.animation.Animation; import android.widget.FrameLayout; import android.widget.TextView; @@ -34,8 +37,6 @@ public class TransferControlView extends FrameLayout { private final ProgressWheel progressWheel; private final TextView downloadDetails; - private final Animation inAnimation; - private final Animation outAnimation; private final int contractedWidth; private final int expandedWidth; @@ -50,18 +51,18 @@ public class TransferControlView extends FrameLayout { public TransferControlView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); inflate(context, R.layout.transfer_controls_view, this); - setBackgroundResource(R.drawable.transfer_controls_background); + + final Drawable background = ContextCompat.getDrawable(context, R.drawable.transfer_controls_background); + if (VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH) { + background.setColorFilter(0x66ffffff, Mode.MULTIPLY); + } + ViewUtil.setBackground(this, background); setVisibility(GONE); + this.progressWheel = ViewUtil.findById(this, R.id.progress_wheel); this.downloadDetails = ViewUtil.findById(this, R.id.download_details); this.contractedWidth = getResources().getDimensionPixelSize(R.dimen.transfer_controls_contracted_width); this.expandedWidth = getResources().getDimensionPixelSize(R.dimen.transfer_controls_expanded_width); - this.outAnimation = new AlphaAnimation(1f, 0f); - this.inAnimation = new AlphaAnimation(0f, 1f); - this.outAnimation.setInterpolator(new FastOutSlowInInterpolator()); - this.inAnimation.setInterpolator(new FastOutSlowInInterpolator()); - this.outAnimation.setDuration(TRANSITION_MS); - this.inAnimation.setDuration(TRANSITION_MS); } @Override protected void onAttachedToWindow() { @@ -115,16 +116,16 @@ public class TransferControlView extends FrameLayout { layoutParams.width = targetWidth; setLayoutParams(layoutParams); } else { - ViewUtil.animateOut(current, outAnimation); + ViewUtil.fadeOut(current, TRANSITION_MS); Animator anim = getWidthAnimator(sourceWidth, targetWidth); anim.start(); } if (view == null) { - ViewUtil.animateOut(this, outAnimation); + ViewUtil.fadeOut(this, TRANSITION_MS); } else { - ViewUtil.animateIn(this, inAnimation); - ViewUtil.animateIn(view, inAnimation); + ViewUtil.fadeIn(this, TRANSITION_MS); + ViewUtil.fadeIn(view, TRANSITION_MS); } current = view; diff --git a/src/org/thoughtcrime/securesms/util/ResUtil.java b/src/org/thoughtcrime/securesms/util/ResUtil.java index 0984f10819..7cd6ea8ca2 100644 --- a/src/org/thoughtcrime/securesms/util/ResUtil.java +++ b/src/org/thoughtcrime/securesms/util/ResUtil.java @@ -21,8 +21,12 @@ import android.content.Context; import android.content.res.Resources.Theme; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; +import android.os.Build.VERSION; +import android.os.Build.VERSION_CODES; import android.support.annotation.ArrayRes; import android.support.annotation.AttrRes; +import android.support.annotation.DrawableRes; +import android.support.v4.content.ContextCompat; import android.util.TypedValue; public class ResUtil { @@ -45,7 +49,7 @@ public class ResUtil { } public static Drawable getDrawable(Context c, @AttrRes int attr) { - return c.getResources().getDrawable(getDrawableRes(c, attr), c.getTheme()); + return ContextCompat.getDrawable(c, getDrawableRes(c, attr)); } public static int[] getResourceIds(Context c, @ArrayRes int array) { diff --git a/src/org/thoughtcrime/securesms/util/ViewUtil.java b/src/org/thoughtcrime/securesms/util/ViewUtil.java index 130ec2b7ff..849c76d8db 100644 --- a/src/org/thoughtcrime/securesms/util/ViewUtil.java +++ b/src/org/thoughtcrime/securesms/util/ViewUtil.java @@ -17,35 +17,29 @@ package org.thoughtcrime.securesms.util; import android.graphics.drawable.Drawable; -import android.support.annotation.DrawableRes; +import android.os.Build.VERSION; +import android.os.Build.VERSION_CODES; import android.support.annotation.IdRes; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.v4.view.animation.FastOutSlowInInterpolator; import android.text.TextUtils; import android.text.TextUtils.TruncateAt; import android.view.View; import android.view.ViewGroup; import android.view.ViewStub; +import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.widget.TextView; public class ViewUtil { - public static void setBackgroundSavingPadding(View v, Drawable drawable) { - final int paddingBottom = v.getPaddingBottom(); - final int paddingLeft = v.getPaddingLeft(); - final int paddingRight = v.getPaddingRight(); - final int paddingTop = v.getPaddingTop(); - v.setBackgroundDrawable(drawable); - v.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom); - } - - public static void setBackgroundSavingPadding(View v, @DrawableRes int resId) { - final int paddingBottom = v.getPaddingBottom(); - final int paddingLeft = v.getPaddingLeft(); - final int paddingRight = v.getPaddingRight(); - final int paddingTop = v.getPaddingTop(); - v.setBackgroundResource(resId); - v.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom); + @SuppressWarnings("deprecation") + public static void setBackground(final @NonNull View v, final @Nullable Drawable drawable) { + if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) { + v.setBackground(drawable); + } else { + v.setBackgroundDrawable(drawable); + } } public static void swapChildInPlace(ViewGroup parent, View toRemove, View toAdd, int defaultIndex) { @@ -75,10 +69,27 @@ public class ViewUtil { return (T) parent.findViewById(resId); } + private static Animation getAlphaAnimation(float from, float to, int duration) { + final Animation anim = new AlphaAnimation(from, to); + anim.setInterpolator(new FastOutSlowInInterpolator()); + anim.setDuration(duration); + return anim; + } + + public static void fadeIn(final @NonNull View view, final int duration) { + animateIn(view, getAlphaAnimation(0f, 1f, duration)); + } + + public static void fadeOut(final @NonNull View view, final int duration) { + animateOut(view, getAlphaAnimation(1f, 0f, duration)); + } + public static void animateOut(final @NonNull View view, final @NonNull Animation animation) { if (view.getVisibility() == View.GONE) return; view.clearAnimation(); + animation.reset(); + animation.setStartTime(0); animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) {} @Override public void onAnimationRepeat(Animation animation) {} @@ -92,7 +103,10 @@ public class ViewUtil { public static void animateIn(final @NonNull View view, final @NonNull Animation animation) { if (view.getVisibility() == View.VISIBLE) return; + view.clearAnimation(); + animation.reset(); + animation.setStartTime(0); view.setVisibility(View.VISIBLE); view.startAnimation(animation); }