Skip to content
This repository was archived by the owner on Nov 10, 2024. It is now read-only.

Commit 26a2150

Browse files
committed
Add Transition for show and dismiss ShowCaseView
1 parent c96e93e commit 26a2150

File tree

3 files changed

+47
-24
lines changed

3 files changed

+47
-24
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apply plugin: 'com.android.application'
33
android {
44
compileSdkVersion 26
55
defaultConfig {
6-
applicationId "parvane.ir.eram.showcaseview"
6+
applicationId "smartdevelop.ir.eram.showcaseview"
77
minSdkVersion 14
88
targetSdkVersion 25
99
versionCode 1

app/src/main/java/ir/smartdevelop/eram/showcaseview/MainActivity.java

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,45 @@
99

1010
public class MainActivity extends AppCompatActivity {
1111

12+
private View view;
13+
private ShowCaseTask showCaseTask;
14+
1215
@Override
1316
protected void onCreate(Bundle savedInstanceState) {
1417
super.onCreate(savedInstanceState);
1518
setContentView(R.layout.activity_main);
1619

17-
View view = findViewById(R.id.txt);
20+
view = findViewById(R.id.txt);
1821
view.setOnClickListener(new View.OnClickListener() {
1922
@Override
2023
public void onClick(View view) {
2124
Toast.makeText(MainActivity.this, "Clicked!", Toast.LENGTH_LONG).show();
2225
}
2326
});
2427

25-
new GuideView.Builder(this)
26-
.setTitle("Guide Title Text")
27-
.setContentText("Guide Description Text\n .....Guide Description Text\n .....Guide Description Text .....")
28-
.setGravity(GuideView.Gravity.AUTO)
29-
.setTargetView(view)
30-
.build()
31-
.show();
28+
showCaseTask = new ShowCaseTask();
29+
view.postDelayed(showCaseTask, 1000);
30+
31+
}
3232

33+
@Override
34+
protected void onDestroy() {
35+
super.onDestroy();
36+
if (showCaseTask != null)
37+
view.removeCallbacks(showCaseTask);
38+
}
3339

40+
class ShowCaseTask implements Runnable {
41+
42+
@Override
43+
public void run() {
44+
new GuideView.Builder(MainActivity.this)
45+
.setTitle("Guide Title Text")
46+
.setContentText("Guide Description Text\n .....Guide Description Text\n .....Guide Description Text .....")
47+
.setGravity(GuideView.Gravity.AUTO)
48+
.setTargetView(view)
49+
.build()
50+
.show();
51+
}
3452
}
3553
}

showcaseviewlib/src/main/java/smartdevelop/ir/eram/showcaseviewlib/GuideView.java

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package smartdevelop.ir.eram.showcaseviewlib;
22

33
import android.app.Activity;
4-
import android.app.Dialog;
54
import android.content.Context;
65
import android.graphics.Bitmap;
76
import android.graphics.Canvas;
@@ -18,7 +17,7 @@
1817
import android.view.View;
1918
import android.view.ViewGroup;
2019
import android.view.ViewTreeObserver;
21-
import android.view.Window;
20+
import android.view.animation.AlphaAnimation;
2221
import 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

Comments
 (0)