Advertisement
Guest User

Untitled

a guest
May 2nd, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. import android.support.design.widget.AppBarLayout;
  2.  
  3. /**
  4. * App bar collapsing state
  5. * @author Paulo Caldeira <paulo.caldeira@acin.pt>.
  6. */
  7. public abstract class AppBarStateChangeListener implements AppBarLayout.OnOffsetChangedListener {
  8. // State
  9. public enum State {
  10. EXPANDED,
  11. COLLAPSED,
  12. IDLE
  13. }
  14.  
  15. private State mCurrentState = State.IDLE;
  16.  
  17. @Override
  18. public final void onOffsetChanged(AppBarLayout appBarLayout, int i) {
  19. if (i == 0) {
  20. if (mCurrentState != State.EXPANDED) {
  21. onStateChanged(appBarLayout, State.EXPANDED);
  22. }
  23. mCurrentState = State.EXPANDED;
  24. } else if (Math.abs(i) >= appBarLayout.getTotalScrollRange()) {
  25. if (mCurrentState != State.COLLAPSED) {
  26. onStateChanged(appBarLayout, State.COLLAPSED);
  27. }
  28. mCurrentState = State.COLLAPSED;
  29. } else {
  30. if (mCurrentState != State.IDLE) {
  31. onStateChanged(appBarLayout, State.IDLE);
  32. }
  33. mCurrentState = State.IDLE;
  34. }
  35. }
  36.  
  37. /**
  38. * Notifies on state change
  39. * @param appBarLayout Layout
  40. * @param state Collapse state
  41. */
  42. public abstract void onStateChanged(AppBarLayout appBarLayout, State state);
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement