Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 675 B After Width: | Height: | Size: 694 B |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 3.0 KiB |
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 3.0 KiB |
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
|