mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-24 02:25:19 +00:00
Fix for toggle behavior during rapid clear/fill cycles.
Fixes #3235 Closes #3239 // FREEBIE
This commit is contained in:
parent
9475cd765a
commit
1251629997
@ -1189,8 +1189,13 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|||||||
calculateCharactersRemaining();
|
calculateCharactersRemaining();
|
||||||
|
|
||||||
if (composeText.getText().length() == 0 || beforeLength == 0) {
|
if (composeText.getText().length() == 0 || beforeLength == 0) {
|
||||||
|
composeText.postDelayed(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
updateToggleButtonState();
|
updateToggleButtonState();
|
||||||
}
|
}
|
||||||
|
}, 50);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -14,6 +14,8 @@ public class AnimatingToggle extends FrameLayout {
|
|||||||
|
|
||||||
private static final int SPEED_MILLIS = 200;
|
private static final int SPEED_MILLIS = 200;
|
||||||
|
|
||||||
|
private View current;
|
||||||
|
|
||||||
public AnimatingToggle(Context context) {
|
public AnimatingToggle(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
@ -30,14 +32,18 @@ public class AnimatingToggle extends FrameLayout {
|
|||||||
public void addView(@NonNull View child, int index, ViewGroup.LayoutParams params) {
|
public void addView(@NonNull View child, int index, ViewGroup.LayoutParams params) {
|
||||||
super.addView(child, index, params);
|
super.addView(child, index, params);
|
||||||
|
|
||||||
if (getChildCount() == 1) child.setVisibility(View.VISIBLE);
|
if (getChildCount() == 1) {
|
||||||
else child.setVisibility(View.GONE);
|
current = child;
|
||||||
|
child.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
child.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void display(View view) {
|
public void display(View view) {
|
||||||
if (view.getVisibility() == View.VISIBLE) return;
|
if (view == current) return;
|
||||||
|
|
||||||
int oldViewIndex = getVisibleViewIndex();
|
int oldViewIndex = getViewIndex(current);
|
||||||
int newViewIndex = getViewIndex(view);
|
int newViewIndex = getViewIndex(view);
|
||||||
|
|
||||||
int sign;
|
int sign;
|
||||||
@ -48,14 +54,13 @@ public class AnimatingToggle extends FrameLayout {
|
|||||||
TranslateAnimation oldViewAnimation = createTranslation(0.0f, sign * 1.0f);
|
TranslateAnimation oldViewAnimation = createTranslation(0.0f, sign * 1.0f);
|
||||||
TranslateAnimation newViewAnimation = createTranslation(sign * -1.0f, 0.0f);
|
TranslateAnimation newViewAnimation = createTranslation(sign * -1.0f, 0.0f);
|
||||||
|
|
||||||
animateOut(oldViewIndex, oldViewAnimation);
|
animateOut(current, oldViewAnimation);
|
||||||
animateIn(newViewIndex, newViewAnimation);
|
animateIn(view, newViewAnimation);
|
||||||
|
|
||||||
|
current = view;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void animateOut(int viewIndex, TranslateAnimation animation) {
|
private void animateOut(final View view, TranslateAnimation animation) {
|
||||||
final View view = getChildAt(viewIndex);
|
|
||||||
|
|
||||||
animation.setInterpolator(new FastOutSlowInInterpolator());
|
|
||||||
animation.setAnimationListener(new Animation.AnimationListener() {
|
animation.setAnimationListener(new Animation.AnimationListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onAnimationStart(Animation animation) {
|
public void onAnimationStart(Animation animation) {
|
||||||
@ -74,21 +79,12 @@ public class AnimatingToggle extends FrameLayout {
|
|||||||
view.startAnimation(animation);
|
view.startAnimation(animation);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void animateIn(int viewIndex, TranslateAnimation animation) {
|
private void animateIn(View view, TranslateAnimation animation) {
|
||||||
animation.setInterpolator(new FastOutSlowInInterpolator());
|
animation.setInterpolator(new FastOutSlowInInterpolator());
|
||||||
final View view = getChildAt(viewIndex);
|
|
||||||
view.setVisibility(View.VISIBLE);
|
view.setVisibility(View.VISIBLE);
|
||||||
view.startAnimation(animation);
|
view.startAnimation(animation);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getVisibleViewIndex() {
|
|
||||||
for (int i=0;i<getChildCount();i++) {
|
|
||||||
if (getChildAt(i).getVisibility() == View.VISIBLE) return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new AssertionError("No visible view?");
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getViewIndex(View view) {
|
private int getViewIndex(View view) {
|
||||||
for (int i=0;i<getChildCount();i++) {
|
for (int i=0;i<getChildCount();i++) {
|
||||||
if (getChildAt(i) == view) return i;
|
if (getChildAt(i) == view) return i;
|
||||||
@ -104,6 +100,7 @@ public class AnimatingToggle extends FrameLayout {
|
|||||||
Animation.RELATIVE_TO_SELF, endY);
|
Animation.RELATIVE_TO_SELF, endY);
|
||||||
|
|
||||||
translateAnimation.setDuration(SPEED_MILLIS);
|
translateAnimation.setDuration(SPEED_MILLIS);
|
||||||
|
translateAnimation.setInterpolator(new FastOutSlowInInterpolator());
|
||||||
|
|
||||||
return translateAnimation;
|
return translateAnimation;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user