fix gingerbread view issues

Closes #4085
// FREEBIE
This commit is contained in:
Jake McGinty
2015-09-17 17:53:09 -07:00
committed by Moxie Marlinspike
parent 6ae38d0718
commit 9ea53d7b1e
9 changed files with 55 additions and 33 deletions

View File

@@ -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);
}