11package smartdevelop .ir .eram .showcaseviewlib ;
22
33import android .app .Activity ;
4- import android .app .Dialog ;
54import android .content .Context ;
65import android .graphics .Bitmap ;
76import android .graphics .Canvas ;
1817import android .view .View ;
1918import android .view .ViewGroup ;
2019import android .view .ViewTreeObserver ;
21- import android .view .Window ;
20+ import android .view .animation . AlphaAnimation ;
2221import android .widget .FrameLayout ;
2322
2423/**
@@ -38,6 +37,7 @@ public class GuideView extends FrameLayout {
3837 private Gravity mGravity ;
3938 int marginGuide ;
4039
40+ final int ANIMATION_DURATION = 600 ;
4141 final Paint emptyPaint = new Paint ();
4242 final Paint paintLine = new Paint ();
4343 final Paint paintCircle = new Paint ();
@@ -89,7 +89,6 @@ public void onGlobalLayout() {
8989 }
9090
9191
92-
9392 @ Override
9493 protected void onDraw (Canvas canvas ) {
9594 super .onDraw (canvas );
@@ -103,7 +102,7 @@ protected void onDraw(Canvas canvas) {
103102 float circleInnerSize = 4.5f * density ;
104103
105104
106- mPaint .setColor (0x99000000 );
105+ mPaint .setColor (0xdd000000 );
107106 mPaint .setStyle (Paint .Style .FILL );
108107 mPaint .setAntiAlias (true );
109108 tempCanvas .drawRect (canvas .getClipBounds (), mPaint );
@@ -125,24 +124,24 @@ protected void onDraw(Canvas canvas) {
125124
126125 marginGuide = (int ) (isTop ? 15 * density : -15 * density );
127126
128- float yLineAndCircle = (isTop ? rect .bottom : rect .top ) + marginGuide ;
127+ float startYLineAndCircle = (isTop ? rect .bottom : rect .top ) + marginGuide ;
129128 float xLine = (rect .left / 2 + rect .right / 2 );
130129 float cx = (target .getLeft () / 2 + target .getRight () / 2 );
130+ float stopY = (y + INDICATOR_HEIGHT * density );
131131
132- tempCanvas .drawLine (xLine , yLineAndCircle , xLine ,
133- y + INDICATOR_HEIGHT * density
132+ tempCanvas .drawLine (xLine , startYLineAndCircle , xLine ,
133+ stopY
134134 , paintLine );
135135
136- tempCanvas .drawCircle (cx , yLineAndCircle , circleSize , paintCircle );
137- tempCanvas .drawCircle (cx , yLineAndCircle , circleInnerSize , paintCircleInner );
136+ tempCanvas .drawCircle (cx , startYLineAndCircle , circleSize , paintCircle );
137+ tempCanvas .drawCircle (cx , startYLineAndCircle , circleInnerSize , paintCircleInner );
138138
139139
140140 targetPaint .setXfermode (XFERMODE_CLEAR );
141141 targetPaint .setAntiAlias (true );
142142
143143 tempCanvas .drawRoundRect (rect , 15 , 15 , targetPaint );
144144 canvas .drawBitmap (bitmap , 0 , 0 , emptyPaint );
145-
146145 }
147146 }
148147
@@ -156,6 +155,10 @@ public int getStatusBarHeight() {
156155 }
157156
158157 public void dismiss () {
158+ AlphaAnimation startAnimation = new AlphaAnimation (1f , 0f );
159+ startAnimation .setDuration (ANIMATION_DURATION );
160+ startAnimation .setFillAfter (true );
161+ this .startAnimation (startAnimation );
159162 ((ViewGroup ) ((Activity ) getContext ()).getWindow ().getDecorView ()).removeView (this );
160163 }
161164
@@ -222,7 +225,10 @@ public void show() {
222225 this .setClickable (false );
223226
224227 ((ViewGroup ) ((Activity ) getContext ()).getWindow ().getDecorView ()).addView (this );
225-
228+ AlphaAnimation startAnimation = new AlphaAnimation (0.2f , 1.0f );
229+ startAnimation .setDuration (ANIMATION_DURATION );
230+ startAnimation .setFillAfter (true );
231+ this .startAnimation (startAnimation );
226232
227233 }
228234
@@ -258,7 +264,6 @@ public void setContentTextSize(int size) {
258264 }
259265
260266
261-
262267 public static class Builder {
263268 private View targetView ;
264269 private String title , contentText ;
@@ -267,7 +272,7 @@ public static class Builder {
267272 private int titleTextSize ;
268273 private int contentTextSize ;
269274 private Spannable contentSpan ;
270- private Typeface titleTypeFace ,contentTypeFace ;
275+ private Typeface titleTypeFace , contentTypeFace ;
271276
272277 public Builder (Context context ) {
273278 this .context = context ;
@@ -342,10 +347,10 @@ public GuideView build() {
342347 guideView .setContentTextSize (contentTextSize );
343348 if (contentSpan != null )
344349 guideView .setContentSpan (contentSpan );
345- if (titleTypeFace != null ){
350+ if (titleTypeFace != null ) {
346351 guideView .setTitleTypeFace (titleTypeFace );
347352 }
348- if (contentTypeFace != null ){
353+ if (contentTypeFace != null ) {
349354 guideView .setContentTypeFace (contentTypeFace );
350355 }
351356 return guideView ;
0 commit comments