Welcome to mirror list, hosted at ThFree Co, Russian Federation.

BasePlacePageAnimationController.java « placepage « widget « maps « mapswithme « com « src « android - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c402c8741e44da46120bdc29fec25e85a485ac00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package com.mapswithme.maps.widget.placepage;

import android.os.Build;
import android.support.annotation.NonNull;
import android.support.v4.view.GestureDetectorCompat;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.widget.ScrollView;

import com.mapswithme.maps.MWMApplication;
import com.mapswithme.maps.R;
import com.mapswithme.maps.bookmarks.data.MapObject;
import com.mapswithme.maps.widget.placepage.PlacePageView.State;

/**
 * Class is responsible for animations of PP(place page) and PPP(place page preview).
 */
public abstract class BasePlacePageAnimationController
{
  protected static final int DURATION = MWMApplication.get().getResources().getInteger(R.integer.anim_duration_default);
  protected static final boolean NO_ANIMATION = (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB);

  protected State mState = State.HIDDEN;

  protected PlacePageView mPlacePage;
  protected ViewGroup mPreview;
  protected ViewGroup mFrame;
  protected ScrollView mDetails;
  protected View mDetailsContent;
  protected ViewGroup mBookmarkDetails;
  protected ViewGroup mButtons;
  // Gestures
  protected GestureDetectorCompat mGestureDetector;
  protected boolean mIsGestureHandled;
  protected float mDownCoord;
  protected float mTouchSlop;
  // Visibility
  protected OnVisibilityChangedListener mVisibilityChangedListener;

  public interface OnVisibilityChangedListener
  {
    void onPreviewVisibilityChanged(boolean isVisible);

    void onPlacePageVisibilityChanged(boolean isVisible);
  }

  protected abstract void initGestureDetector();

  public BasePlacePageAnimationController(@NonNull PlacePageView placePage)
  {
    mPlacePage = placePage;
    mPreview = (ViewGroup) placePage.findViewById(R.id.pp__preview);
    mFrame = (ViewGroup) placePage.findViewById(R.id.pp__details_frame);
    mDetails = (ScrollView) placePage.findViewById(R.id.pp__details);
    mDetailsContent = mDetails.getChildAt(0);
    mBookmarkDetails = (ViewGroup) mFrame.findViewById(R.id.rl__bookmark_details);
    mButtons = (ViewGroup) placePage.findViewById(R.id.pp__buttons);
    initGestureDetector();

    mTouchSlop = ViewConfiguration.get(mPlacePage.getContext()).getScaledTouchSlop();
  }

  public void setState(State state, MapObject.MapObjectType type)
  {
    State newState = state;
    if (type == MapObject.MapObjectType.BOOKMARK && state == State.DETAILS)
      newState = State.BOOKMARK;

    if (newState != mState)
    {
      onStateChanged(mState, newState);
      mState = newState;
    }
  }

  protected abstract void onStateChanged(State currentState, State newState);

  public State getState()
  {
    return mState;
  }

  public void setOnVisibilityChangedListener(OnVisibilityChangedListener listener)
  {
    mVisibilityChangedListener = listener;
  }

  protected abstract boolean onInterceptTouchEvent(MotionEvent event);

  protected boolean onTouchEvent(@NonNull MotionEvent event)
  {
    return mGestureDetector.onTouchEvent(event);
  }

  protected void notifyVisibilityListener(boolean previewShown, boolean ppShown)
  {
    if (mVisibilityChangedListener != null)
    {
      mVisibilityChangedListener.onPreviewVisibilityChanged(previewShown);
      mVisibilityChangedListener.onPlacePageVisibilityChanged(ppShown);
    }
  }
}