2015-05-18 17:26:32 +00:00
|
|
|
package org.thoughtcrime.securesms.components;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.support.annotation.NonNull;
|
2015-09-08 01:08:44 +00:00
|
|
|
import android.support.annotation.Nullable;
|
2015-09-18 00:53:09 +00:00
|
|
|
import android.support.v4.view.animation.FastOutSlowInInterpolator;
|
2015-05-18 17:26:32 +00:00
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.view.animation.Animation;
|
2015-07-01 00:45:39 +00:00
|
|
|
import android.view.animation.AnimationUtils;
|
2015-05-18 17:26:32 +00:00
|
|
|
import android.widget.FrameLayout;
|
|
|
|
|
2019-07-24 02:30:23 +00:00
|
|
|
import network.loki.messenger.R;
|
2015-09-10 04:05:21 +00:00
|
|
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
2015-07-01 00:45:39 +00:00
|
|
|
|
2015-05-18 17:26:32 +00:00
|
|
|
public class AnimatingToggle extends FrameLayout {
|
|
|
|
|
2015-05-22 20:30:34 +00:00
|
|
|
private View current;
|
|
|
|
|
2015-09-10 04:05:21 +00:00
|
|
|
private final Animation inAnimation;
|
|
|
|
private final Animation outAnimation;
|
|
|
|
|
2015-05-18 17:26:32 +00:00
|
|
|
public AnimatingToggle(Context context) {
|
2015-09-10 04:05:21 +00:00
|
|
|
this(context, null);
|
2015-05-18 17:26:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public AnimatingToggle(Context context, AttributeSet attrs) {
|
2015-09-10 04:05:21 +00:00
|
|
|
this(context, attrs, 0);
|
2015-05-18 17:26:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public AnimatingToggle(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
|
|
super(context, attrs, defStyleAttr);
|
2015-09-10 04:05:21 +00:00
|
|
|
this.outAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.animation_toggle_out);
|
|
|
|
this.inAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.animation_toggle_in);
|
2015-09-18 00:53:09 +00:00
|
|
|
this.outAnimation.setInterpolator(new FastOutSlowInInterpolator());
|
|
|
|
this.inAnimation.setInterpolator(new FastOutSlowInInterpolator());
|
2015-05-18 17:26:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void addView(@NonNull View child, int index, ViewGroup.LayoutParams params) {
|
|
|
|
super.addView(child, index, params);
|
|
|
|
|
2015-05-22 20:30:34 +00:00
|
|
|
if (getChildCount() == 1) {
|
|
|
|
current = child;
|
|
|
|
child.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
child.setVisibility(View.GONE);
|
|
|
|
}
|
2015-07-01 00:45:39 +00:00
|
|
|
child.setClickable(false);
|
2015-05-18 17:26:32 +00:00
|
|
|
}
|
|
|
|
|
2015-09-08 01:08:44 +00:00
|
|
|
public void display(@Nullable View view) {
|
2015-05-22 20:30:34 +00:00
|
|
|
if (view == current) return;
|
2015-11-18 22:52:26 +00:00
|
|
|
if (current != null) ViewUtil.animateOut(current, outAnimation, View.GONE);
|
2015-09-10 04:05:21 +00:00
|
|
|
if (view != null) ViewUtil.animateIn(view, inAnimation);
|
2015-05-18 17:26:32 +00:00
|
|
|
|
2015-05-22 20:30:34 +00:00
|
|
|
current = view;
|
|
|
|
}
|
2015-10-21 22:32:29 +00:00
|
|
|
|
|
|
|
public void displayQuick(@Nullable View view) {
|
|
|
|
if (view == current) return;
|
|
|
|
if (current != null) current.setVisibility(View.GONE);
|
|
|
|
if (view != null) view.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
current = view;
|
|
|
|
}
|
2015-05-18 17:26:32 +00:00
|
|
|
}
|