|
7 | 7 | import java.util.concurrent.Callable;
|
8 | 8 | import java.util.ArrayList;
|
9 | 9 |
|
| 10 | +import android.animation.Animator; |
10 | 11 | import android.annotation.SuppressLint;
|
11 | 12 | import android.annotation.TargetApi;
|
12 | 13 | import android.app.AlertDialog;
|
|
28 | 29 | import android.graphics.drawable.Drawable;
|
29 | 30 | import android.os.Build;
|
30 | 31 | import android.os.Bundle;
|
| 32 | +import android.os.CountDownTimer; |
31 | 33 | import android.os.Handler;
|
| 34 | +import android.support.design.widget.AppBarLayout; |
32 | 35 | import android.support.design.widget.FloatingActionButton;
|
33 | 36 | import android.support.v4.app.ActionBarDrawerToggle;
|
34 | 37 | import android.support.v4.app.FragmentManager;
|
35 | 38 | import android.support.v4.app.FragmentTransaction;
|
36 | 39 | import android.support.v4.content.ContextCompat;
|
37 | 40 | import android.support.v4.view.GravityCompat;
|
38 | 41 | import android.support.v4.view.MenuItemCompat;
|
| 42 | +import android.support.v4.view.animation.FastOutSlowInInterpolator; |
39 | 43 | import android.support.v4.widget.DrawerLayout;
|
40 | 44 | import android.support.v4.widget.SimpleCursorAdapter;
|
41 | 45 | import android.support.v7.app.AppCompatActivity;
|
|
45 | 49 | import android.view.Menu;
|
46 | 50 | import android.view.MenuItem;
|
47 | 51 | import android.view.View;
|
| 52 | +import android.view.ViewPropertyAnimator; |
| 53 | +import android.view.animation.Interpolator; |
48 | 54 | import android.view.inputmethod.InputMethodManager;
|
49 | 55 | import android.widget.AdapterView;
|
50 | 56 | import android.widget.AdapterView.OnItemClickListener;
|
@@ -110,8 +116,12 @@ public class ZulipActivity extends AppCompatActivity implements
|
110 | 116 | private DrawerLayout drawerLayout;
|
111 | 117 | private ActionBarDrawerToggle drawerToggle;
|
112 | 118 | ExpandableListView streamsDrawer;
|
| 119 | + private static final Interpolator FAST_OUT_SLOW_IN_INTERPOLATOR = new FastOutSlowInInterpolator(); |
113 | 120 | private LinearLayout chatBox;
|
114 | 121 | private FloatingActionButton fab;
|
| 122 | + private CountDownTimer fabHidder; |
| 123 | + private boolean hideFABBlocked = false; |
| 124 | + private static final int HIDE_FAB_AFTER_SEC = 5; |
115 | 125 |
|
116 | 126 | private HashMap<String, Bitmap> gravatars = new HashMap<>();
|
117 | 127 |
|
@@ -496,7 +506,93 @@ private Cursor makePeopleNameCursor(CharSequence name) throws SQLException {
|
496 | 506 | private void setupFab() {
|
497 | 507 | fab = (FloatingActionButton) findViewById(R.id.fab);
|
498 | 508 | chatBox = (LinearLayout) findViewById(R.id.messageBoxContainer);
|
| 509 | + fabHidder = new CountDownTimer(HIDE_FAB_AFTER_SEC * 1000, HIDE_FAB_AFTER_SEC * 1000) { |
| 510 | + public void onTick(long millisUntilFinished) { |
| 511 | + } |
| 512 | + |
| 513 | + public void onFinish() { |
| 514 | + if (!hideFABBlocked) { |
| 515 | + displayFAB(true); |
| 516 | + displayChatBox(false); |
| 517 | + } else { |
| 518 | + start(); |
| 519 | + } |
| 520 | + } |
| 521 | + }; |
| 522 | + } |
| 523 | + |
| 524 | + public void displayChatBox(boolean show) { |
| 525 | + if (show) { |
| 526 | + showView(chatBox); |
| 527 | + } else { |
| 528 | + hideView(chatBox); |
| 529 | + } |
| 530 | + } |
| 531 | + |
| 532 | + public void displayFAB(boolean show) { |
| 533 | + if (show) { |
| 534 | + showView(fab); |
| 535 | + } else { |
| 536 | + hideView(fab); |
| 537 | + } |
499 | 538 | }
|
| 539 | + |
| 540 | + private void hideView(final View view) { |
| 541 | + ViewPropertyAnimator animator = view.animate() |
| 542 | + .translationY((view instanceof AppBarLayout) ? -1 * view.getHeight() : view.getHeight()) |
| 543 | + .setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR) |
| 544 | + .setDuration(200); |
| 545 | + |
| 546 | + animator.setListener(new Animator.AnimatorListener() { |
| 547 | + @Override |
| 548 | + public void onAnimationStart(Animator animator) { |
| 549 | + } |
| 550 | + |
| 551 | + @Override |
| 552 | + public void onAnimationEnd(Animator animator) { |
| 553 | + view.setVisibility(View.GONE); |
| 554 | + } |
| 555 | + |
| 556 | + @Override |
| 557 | + public void onAnimationCancel(Animator animator) { |
| 558 | + } |
| 559 | + |
| 560 | + @Override |
| 561 | + public void onAnimationRepeat(Animator animator) { |
| 562 | + } |
| 563 | + }); |
| 564 | + animator.start(); |
| 565 | + } |
| 566 | + |
| 567 | + private void showView(final View view) { |
| 568 | + ViewPropertyAnimator animator = view.animate() |
| 569 | + .translationY(0) |
| 570 | + .setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR) |
| 571 | + .setDuration(200); |
| 572 | + |
| 573 | + animator.setListener(new Animator.AnimatorListener() { |
| 574 | + @Override |
| 575 | + public void onAnimationStart(Animator animator) { |
| 576 | + view.setVisibility(View.VISIBLE); |
| 577 | + } |
| 578 | + |
| 579 | + @Override |
| 580 | + public void onAnimationEnd(Animator animator) { |
| 581 | + |
| 582 | + } |
| 583 | + |
| 584 | + @Override |
| 585 | + public void onAnimationCancel(Animator animator) { |
| 586 | + |
| 587 | + } |
| 588 | + |
| 589 | + @Override |
| 590 | + public void onAnimationRepeat(Animator animator) { |
| 591 | + } |
| 592 | + }); |
| 593 | + animator.start(); |
| 594 | + } |
| 595 | + |
500 | 596 | public void setupListViewAdapter() {
|
501 | 597 | ExpandableStreamDrawerAdapter streamsDrawerAdapter = null;
|
502 | 598 | Callable<Cursor> streamsGenerator = new Callable<Cursor>() {
|
|
0 commit comments