@@ -60,6 +60,12 @@ public class BlurLayout extends RelativeLayout {
60
60
61
61
private long mBlurDuration = DURATION ;
62
62
63
+ public enum HOVER_STATUS {
64
+ APPEARING , APPEARED , DISAPPEARING , DISAPPEARED
65
+ };
66
+
67
+ private HOVER_STATUS mHoverStatus = HOVER_STATUS .DISAPPEARED ;
68
+
63
69
public BlurLayout (Context context ) {
64
70
super (context );
65
71
}
@@ -72,7 +78,6 @@ public BlurLayout(Context context, AttributeSet attrs, int defStyle) {
72
78
super (context , attrs , defStyle );
73
79
}
74
80
75
-
76
81
@ Override
77
82
public boolean onTouchEvent (MotionEvent event ) {
78
83
return gestureDetector .onTouchEvent (event );
@@ -89,41 +94,85 @@ public boolean onDown(MotionEvent e) {
89
94
90
95
@ Override
91
96
public boolean onSingleTapUp (MotionEvent e ) {
92
- if (mHoverView != null ){
97
+ if (hover ())
98
+ return true ;
99
+ else
100
+ return super .onSingleTapConfirmed (e );
101
+ }
102
+ };
103
+
104
+ public void showHover (){
105
+ hover ();
106
+ }
93
107
94
- if (!mPlayingAnimators .isEmpty ()) return true ;
108
+ /**
109
+ * Let hover show.
110
+ * @return
111
+ */
112
+ private boolean hover (){
113
+ if (mHoverView == null ) return false ;
95
114
96
- removeView (mBlurImage );
97
- if (enableBlurBackground )
98
- addBlurImage ();
115
+ if (getHoverStatus () != HOVER_STATUS .DISAPPEARED || !mPlayingAnimators .isEmpty ()) return true ;
99
116
100
- if (mHoverView .getParent () != null ){
101
- ((ViewGroup )(mHoverView .getParent ())).removeView (mHoverView );
102
- }
117
+ removeView (mBlurImage );
118
+ if (enableBlurBackground )
119
+ addBlurImage ();
120
+
121
+ if (mHoverView .getParent () != null ){
122
+ ((ViewGroup )(mHoverView .getParent ())).removeView (mHoverView );
123
+ }
103
124
104
- addView (mHoverView , getFullParentSizeLayoutParams ());
125
+ addView (mHoverView , getFullParentSizeLayoutParams ());
105
126
106
- mHoverView .getViewTreeObserver ().addOnGlobalLayoutListener (new ViewTreeObserver .OnGlobalLayoutListener () {
107
- @ Override
108
- public void onGlobalLayout () {
127
+ mHoverView .getViewTreeObserver ().addOnGlobalLayoutListener (new ViewTreeObserver .OnGlobalLayoutListener () {
128
+ @ Override
129
+ public void onGlobalLayout () {
109
130
110
- startBlurImageAppearAnimator ();
131
+ startBlurImageAppearAnimator ();
111
132
112
- startHoverAppearAnimator ();
133
+ startHoverAppearAnimator ();
113
134
114
- startChildrenAppearAnimations ();
135
+ startChildrenAppearAnimations ();
115
136
116
- if (Build .VERSION .SDK_INT >= 16 )
117
- mHoverView .getViewTreeObserver ().removeOnGlobalLayoutListener (this );
118
- else
119
- mHoverView .getViewTreeObserver ().removeGlobalOnLayoutListener (this );
120
- }
121
- });
122
- return true ;
137
+ if (Build .VERSION .SDK_INT >= 16 )
138
+ mHoverView .getViewTreeObserver ().removeOnGlobalLayoutListener (this );
139
+ else
140
+ mHoverView .getViewTreeObserver ().removeGlobalOnLayoutListener (this );
123
141
}
124
- return super .onSingleTapConfirmed (e );
125
- }
126
- };
142
+ });
143
+ return true ;
144
+
145
+ }
146
+
147
+ /**
148
+ * Let hover view dismiss.
149
+ * Notice: only when hover view status is appeared, then, this may work.
150
+ */
151
+ public void dismissHover (){
152
+ if (getHoverStatus () != HOVER_STATUS .APPEARED || !mPlayingAnimators .isEmpty ())
153
+ return ;
154
+
155
+ startBlurImageDisappearAnimator ();
156
+
157
+ startHoverDisappearAnimator ();
158
+
159
+ startChildrenDisappearAnimations ();
160
+ }
161
+
162
+ public void toggleHover (){
163
+ if (getHoverStatus () == HOVER_STATUS .DISAPPEARED )
164
+ showHover ();
165
+ else if (getHoverStatus () == HOVER_STATUS .APPEARED )
166
+ dismissHover ();
167
+ }
168
+
169
+ /**
170
+ * get currently hover status.
171
+ * @return
172
+ */
173
+ public HOVER_STATUS getHoverStatus (){
174
+ return mHoverStatus ;
175
+ }
127
176
128
177
private void addBlurImage (){
129
178
Bitmap bm = Blur .apply (getContext (), Util .getViewBitmap (this ));
@@ -133,11 +182,19 @@ private void addBlurImage(){
133
182
this .addView (im );
134
183
}
135
184
185
+ /**
186
+ * set background blur duration.
187
+ * @param duration
188
+ */
136
189
public void setBlurDuration (long duration ){
137
190
if (duration > 100 )
138
191
mBlurDuration = duration ;
139
192
}
140
193
194
+ /**
195
+ * bind a hover view with BlurLayout.
196
+ * @param hover
197
+ */
141
198
public void setHoverView (final View hover ){
142
199
mHoverView = hover ;
143
200
@@ -150,13 +207,8 @@ public void setHoverView(final View hover){
150
207
@ Override
151
208
public void onClick (View v ) {
152
209
153
- if (!mPlayingAnimators .isEmpty ()) return ;
154
-
155
- startBlurImageDisappearAnimator ();
156
-
157
- startHoverDisappearAnimator ();
210
+ dismissHover ();
158
211
159
- startChildrenDisappearAnimations ();
160
212
}
161
213
});
162
214
}
@@ -291,6 +343,7 @@ public void removeDisappearListener(DisappearListener l){
291
343
public void onAnimationStart (Animator animation ) {
292
344
mAppearingAnimators .add (animation );
293
345
if (mAppearingAnimators .size () == 1 ){
346
+ mHoverStatus = HOVER_STATUS .APPEARING ;
294
347
for (AppearListener l : mAppearListeners ){
295
348
l .onStart ();
296
349
}
@@ -301,6 +354,7 @@ public void onAnimationStart(Animator animation) {
301
354
public void onAnimationEnd (Animator animation ) {
302
355
mAppearingAnimators .remove (animation );
303
356
if (mAppearListeners .isEmpty ()){
357
+ mHoverStatus = HOVER_STATUS .APPEARED ;
304
358
for (AppearListener l : mAppearListeners ){
305
359
l .onEnd ();
306
360
}
@@ -324,6 +378,7 @@ public void onAnimationStart(Animator animation) {
324
378
mDisappearingAnimators .add (animation );
325
379
if (mDisappearListeners .size () == 1 ){
326
380
for (DisappearListener l : mDisappearListeners ){
381
+ mHoverStatus = HOVER_STATUS .DISAPPEARING ;
327
382
l .onStart ();
328
383
}
329
384
}
@@ -333,6 +388,7 @@ public void onAnimationStart(Animator animation) {
333
388
public void onAnimationEnd (Animator animation ) {
334
389
mDisappearingAnimators .remove (animation );
335
390
if (mPlayingAnimators .isEmpty ()){
391
+ mHoverStatus = HOVER_STATUS .DISAPPEARED ;
336
392
removeView (mBlurImage );
337
393
removeView (mHoverView );
338
394
for (DisappearListener l : mDisappearListeners ){
0 commit comments