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.content.Context;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.v4.view.animation.FastOutSlowInInterpolator;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -32,6 +33,8 @@ public class AnimatingToggle extends FrameLayout {
|
|||||||
super(context, attrs, defStyleAttr);
|
super(context, attrs, defStyleAttr);
|
||||||
this.outAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.animation_toggle_out);
|
this.outAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.animation_toggle_out);
|
||||||
this.inAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.animation_toggle_in);
|
this.inAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.animation_toggle_in);
|
||||||
|
this.outAnimation.setInterpolator(new FastOutSlowInInterpolator());
|
||||||
|
this.inAnimation.setInterpolator(new FastOutSlowInInterpolator());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,14 +1,17 @@
|
|||||||
package org.thoughtcrime.securesms.components;
|
package org.thoughtcrime.securesms.components;
|
||||||
|
|
||||||
import android.content.Context;
|
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.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.support.v4.view.animation.FastOutSlowInInterpolator;
|
import android.support.v4.view.animation.FastOutSlowInInterpolator;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.animation.AlphaAnimation;
|
|
||||||
import android.view.animation.Animation;
|
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
@ -34,8 +37,6 @@ public class TransferControlView extends FrameLayout {
|
|||||||
|
|
||||||
private final ProgressWheel progressWheel;
|
private final ProgressWheel progressWheel;
|
||||||
private final TextView downloadDetails;
|
private final TextView downloadDetails;
|
||||||
private final Animation inAnimation;
|
|
||||||
private final Animation outAnimation;
|
|
||||||
private final int contractedWidth;
|
private final int contractedWidth;
|
||||||
private final int expandedWidth;
|
private final int expandedWidth;
|
||||||
|
|
||||||
@ -50,18 +51,18 @@ public class TransferControlView extends FrameLayout {
|
|||||||
public TransferControlView(Context context, AttributeSet attrs, int defStyleAttr) {
|
public TransferControlView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
super(context, attrs, defStyleAttr);
|
super(context, attrs, defStyleAttr);
|
||||||
inflate(context, R.layout.transfer_controls_view, this);
|
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);
|
setVisibility(GONE);
|
||||||
|
|
||||||
this.progressWheel = ViewUtil.findById(this, R.id.progress_wheel);
|
this.progressWheel = ViewUtil.findById(this, R.id.progress_wheel);
|
||||||
this.downloadDetails = ViewUtil.findById(this, R.id.download_details);
|
this.downloadDetails = ViewUtil.findById(this, R.id.download_details);
|
||||||
this.contractedWidth = getResources().getDimensionPixelSize(R.dimen.transfer_controls_contracted_width);
|
this.contractedWidth = getResources().getDimensionPixelSize(R.dimen.transfer_controls_contracted_width);
|
||||||
this.expandedWidth = getResources().getDimensionPixelSize(R.dimen.transfer_controls_expanded_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() {
|
@Override protected void onAttachedToWindow() {
|
||||||
@ -115,16 +116,16 @@ public class TransferControlView extends FrameLayout {
|
|||||||
layoutParams.width = targetWidth;
|
layoutParams.width = targetWidth;
|
||||||
setLayoutParams(layoutParams);
|
setLayoutParams(layoutParams);
|
||||||
} else {
|
} else {
|
||||||
ViewUtil.animateOut(current, outAnimation);
|
ViewUtil.fadeOut(current, TRANSITION_MS);
|
||||||
Animator anim = getWidthAnimator(sourceWidth, targetWidth);
|
Animator anim = getWidthAnimator(sourceWidth, targetWidth);
|
||||||
anim.start();
|
anim.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (view == null) {
|
if (view == null) {
|
||||||
ViewUtil.animateOut(this, outAnimation);
|
ViewUtil.fadeOut(this, TRANSITION_MS);
|
||||||
} else {
|
} else {
|
||||||
ViewUtil.animateIn(this, inAnimation);
|
ViewUtil.fadeIn(this, TRANSITION_MS);
|
||||||
ViewUtil.animateIn(view, inAnimation);
|
ViewUtil.fadeIn(view, TRANSITION_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
current = view;
|
current = view;
|
||||||
|
@ -21,8 +21,12 @@ import android.content.Context;
|
|||||||
import android.content.res.Resources.Theme;
|
import android.content.res.Resources.Theme;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.graphics.drawable.Drawable;
|
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.ArrayRes;
|
||||||
import android.support.annotation.AttrRes;
|
import android.support.annotation.AttrRes;
|
||||||
|
import android.support.annotation.DrawableRes;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
|
|
||||||
public class ResUtil {
|
public class ResUtil {
|
||||||
@ -45,7 +49,7 @@ public class ResUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Drawable getDrawable(Context c, @AttrRes int attr) {
|
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) {
|
public static int[] getResourceIds(Context c, @ArrayRes int array) {
|
||||||
|
@ -17,35 +17,29 @@
|
|||||||
package org.thoughtcrime.securesms.util;
|
package org.thoughtcrime.securesms.util;
|
||||||
|
|
||||||
import android.graphics.drawable.Drawable;
|
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.IdRes;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.v4.view.animation.FastOutSlowInInterpolator;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.text.TextUtils.TruncateAt;
|
import android.text.TextUtils.TruncateAt;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.ViewStub;
|
import android.view.ViewStub;
|
||||||
|
import android.view.animation.AlphaAnimation;
|
||||||
import android.view.animation.Animation;
|
import android.view.animation.Animation;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
public class ViewUtil {
|
public class ViewUtil {
|
||||||
public static void setBackgroundSavingPadding(View v, Drawable drawable) {
|
@SuppressWarnings("deprecation")
|
||||||
final int paddingBottom = v.getPaddingBottom();
|
public static void setBackground(final @NonNull View v, final @Nullable Drawable drawable) {
|
||||||
final int paddingLeft = v.getPaddingLeft();
|
if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
|
||||||
final int paddingRight = v.getPaddingRight();
|
v.setBackground(drawable);
|
||||||
final int paddingTop = v.getPaddingTop();
|
} else {
|
||||||
v.setBackgroundDrawable(drawable);
|
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void swapChildInPlace(ViewGroup parent, View toRemove, View toAdd, int defaultIndex) {
|
public static void swapChildInPlace(ViewGroup parent, View toRemove, View toAdd, int defaultIndex) {
|
||||||
@ -75,10 +69,27 @@ public class ViewUtil {
|
|||||||
return (T) parent.findViewById(resId);
|
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) {
|
public static void animateOut(final @NonNull View view, final @NonNull Animation animation) {
|
||||||
if (view.getVisibility() == View.GONE) return;
|
if (view.getVisibility() == View.GONE) return;
|
||||||
|
|
||||||
view.clearAnimation();
|
view.clearAnimation();
|
||||||
|
animation.reset();
|
||||||
|
animation.setStartTime(0);
|
||||||
animation.setAnimationListener(new Animation.AnimationListener() {
|
animation.setAnimationListener(new Animation.AnimationListener() {
|
||||||
@Override public void onAnimationStart(Animation animation) {}
|
@Override public void onAnimationStart(Animation animation) {}
|
||||||
@Override public void onAnimationRepeat(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) {
|
public static void animateIn(final @NonNull View view, final @NonNull Animation animation) {
|
||||||
if (view.getVisibility() == View.VISIBLE) return;
|
if (view.getVisibility() == View.VISIBLE) return;
|
||||||
|
|
||||||
view.clearAnimation();
|
view.clearAnimation();
|
||||||
|
animation.reset();
|
||||||
|
animation.setStartTime(0);
|
||||||
view.setVisibility(View.VISIBLE);
|
view.setVisibility(View.VISIBLE);
|
||||||
view.startAnimation(animation);
|
view.startAnimation(animation);
|
||||||
}
|
}
|
||||||
|