That fuck shit the fascists are using
at master 81 lines 2.5 kB view raw
1package org.tm.archive.components; 2 3import android.content.Context; 4import android.util.AttributeSet; 5import android.view.View; 6import android.view.ViewGroup; 7import android.view.animation.Animation; 8import android.view.animation.AnimationUtils; 9import android.widget.FrameLayout; 10 11import androidx.annotation.NonNull; 12import androidx.annotation.Nullable; 13import androidx.interpolator.view.animation.FastOutSlowInInterpolator; 14 15import org.tm.archive.R; 16import org.tm.archive.util.ViewUtil; 17 18public class AnimatingToggle extends FrameLayout { 19 20 private View current; 21 private View previous; 22 private final Animation inAnimation; 23 private final Animation outAnimation; 24 25 public AnimatingToggle(Context context) { 26 this(context, null); 27 } 28 29 public AnimatingToggle(Context context, AttributeSet attrs) { 30 this(context, attrs, 0); 31 } 32 33 public AnimatingToggle(Context context, AttributeSet attrs, int defStyleAttr) { 34 super(context, attrs, defStyleAttr); 35 this.outAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.animation_toggle_out); 36 this.inAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.animation_toggle_in); 37 this.outAnimation.setInterpolator(new FastOutSlowInInterpolator()); 38 this.inAnimation.setInterpolator(new FastOutSlowInInterpolator()); 39 } 40 41 @Override 42 public void addView(@NonNull View child, int index, ViewGroup.LayoutParams params) { 43 super.addView(child, index, params); 44 45 if (!isInEditMode()) { 46 if (getChildCount() == 1) { 47 current = child; 48 child.setVisibility(View.VISIBLE); 49 } else { 50 child.setVisibility(View.GONE); 51 } 52 child.setClickable(false); 53 } 54 } 55 56 public void display(@Nullable View view) { 57 if (view == current && current.getVisibility() == View.VISIBLE) return; 58 if (previous != null && previous.getAnimation() == outAnimation) { 59 previous.clearAnimation(); 60 previous.setVisibility(View.GONE); 61 } 62 if (current != null) { 63 ViewUtil.animateOut(current, outAnimation, View.GONE); 64 } 65 if (view != null) { 66 ViewUtil.animateIn(view, inAnimation); 67 } 68 previous = current; 69 current = view; 70 } 71 72 public void displayQuick(@Nullable View view) { 73 if (view == current && current.getVisibility() == View.VISIBLE) return; 74 if (current != null) current.setVisibility(View.GONE); 75 if (view != null) { 76 view.setVisibility(View.VISIBLE); 77 view.clearAnimation(); 78 } 79 current = view; 80 } 81}