Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.

Commit 526f349

Browse files
committed
Add an animation to hide the chatBox on swipe
1 parent b408aef commit 526f349

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

app/src/main/java/com/zulip/android/activities/ZulipActivity.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
import com.zulip.android.R;
8686
import com.zulip.android.models.Stream;
8787
import com.zulip.android.networking.AsyncSend;
88+
import com.zulip.android.util.AnimationHelper;
8889
import com.zulip.android.util.SwipeRemoveLinearLayout;
8990
import com.zulip.android.util.ZLog;
9091
import com.zulip.android.ZulipApp;
@@ -162,8 +163,8 @@ public void onReceive(Context contenxt, Intent intent) {
162163
};
163164

164165
@Override
165-
public void removeChatBox() {
166-
chatBox.setVisibility(View.GONE);
166+
public void removeChatBox(boolean animToRight) {
167+
AnimationHelper.hideViewX(chatBox, animToRight);
167168
}
168169

169170
// Intent Extra constants
@@ -1263,7 +1264,7 @@ private boolean prepareSearchView(Menu menu) {
12631264
final android.support.v7.widget.SearchView searchView = (android.support.v7.widget.SearchView) MenuItemCompat.getActionView(mSearchMenuItem);
12641265
searchView.setSearchableInfo(searchManager.getSearchableInfo(new ComponentName(getApplicationContext(), ZulipActivity.class)));
12651266
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
1266-
((EditText) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text)).setHintTextColor(ContextCompat.getColor(this,R.color.colorTextPrimary));
1267+
((EditText) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text)).setHintTextColor(ContextCompat.getColor(this, R.color.colorTextPrimary));
12671268
searchView.setOnQueryTextListener(new android.support.v7.widget.SearchView.OnQueryTextListener() {
12681269
@Override
12691270
public boolean onQueryTextSubmit(String s) {

app/src/main/java/com/zulip/android/util/AnimationHelper.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.zulip.android.util;
22

33
import android.animation.Animator;
4+
import android.support.design.widget.AppBarLayout;
45
import android.support.v4.view.animation.FastOutSlowInInterpolator;
56
import android.view.View;
67
import android.view.ViewPropertyAnimator;
@@ -65,4 +66,33 @@ public void onAnimationRepeat(Animator animator) {
6566
});
6667
slideOutAnimator.start();
6768
}
69+
70+
public static void hideViewX(final View view, boolean animToRight) {
71+
ViewPropertyAnimator animator = view.animate()
72+
.translationX((animToRight) ? view.getWidth() : view.getWidth() * -1)
73+
.setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR)
74+
.setDuration(200);
75+
76+
animator.setListener(new Animator.AnimatorListener() {
77+
@Override
78+
public void onAnimationStart(Animator animator) {
79+
}
80+
81+
@Override
82+
public void onAnimationEnd(Animator animator) {
83+
view.setVisibility(View.GONE);
84+
view.setX(0);
85+
}
86+
87+
@Override
88+
public void onAnimationCancel(Animator animator) {
89+
}
90+
91+
@Override
92+
public void onAnimationRepeat(Animator animator) {
93+
}
94+
});
95+
animator.start();
96+
}
97+
6898
}

app/src/main/java/com/zulip/android/util/SwipeRemoveLinearLayout.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
4343
x2 = ev.getX();
4444
float deltaX = x2 - x1;
4545
if (Math.abs(deltaX) > MIN_DISTANCE) {
46-
leftToRightSwipeListen.removeChatBox();
46+
leftToRightSwipeListen.removeChatBox((deltaX > 0));
4747
return true;
4848
}
4949
break;
@@ -52,7 +52,7 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
5252
}
5353

5454
public interface leftToRightSwipeListener {
55-
void removeChatBox();
55+
void removeChatBox(boolean animToRight);
5656
}
5757

5858
public void registerToSwipeEvents(leftToRightSwipeListener listener) {

0 commit comments

Comments
 (0)