Skip to content

Commit bf9d92b

Browse files
committed
improved the animate hand method
1 parent f950ff8 commit bf9d92b

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

library/src/com/github/espiandev/showcaseview/ShowcaseView.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,6 @@ private void init() {
145145
mBackupButton.setOnClickListener(this);
146146
addView(mBackupButton);
147147
}
148-
149-
mHandy = ((LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.handy, null);
150-
addView(mHandy);
151-
ViewHelper.setAlpha(mHandy, 0f);
152-
153148
}
154149

155150
/**
@@ -444,6 +439,9 @@ private boolean makeVoidedRect() {
444439
}
445440

446441
public AnimatorSet animateGesture(float offsetStartX, float offsetStartY, float offsetEndX, float offsetEndY) {
442+
mHandy = ((LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.handy, null);
443+
addView(mHandy);
444+
ViewHelper.setAlpha(mHandy, 0f);
447445

448446
ObjectAnimator alphaIn = ObjectAnimator.ofFloat(mHandy, "alpha", 0f, 1f).setDuration(500);
449447

@@ -460,8 +458,16 @@ public AnimatorSet animateGesture(float offsetStartX, float offsetStartY, float
460458

461459
AnimatorSet as = new AnimatorSet();
462460
as.play(setUpX).with(setUpY).before(alphaIn).before(moveX).with(moveY).before(alphaOut);
463-
return as;
461+
as.start();
464462

463+
Handler handler = new Handler();
464+
Runnable runnable = new Runnable() {
465+
@Override
466+
public void run() {
467+
removeView(mHandy);
468+
}
469+
};
470+
handler.postDelayed(runnable, 3000);
465471
}
466472

467473
@Override
@@ -596,6 +602,10 @@ public void setText(int titleText, int subText) {
596602
* @return a View representing the ghostly hand
597603
*/
598604
public View getHand() {
605+
final View mHandy = ((LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.handy, null);
606+
addView(mHandy);
607+
ViewHelper.setAlpha(mHandy, 0f);
608+
599609
return mHandy;
600610
}
601611

sample/src/com/github/espiandev/showcaseview/sample/SampleActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void onCreate(Bundle savedInstanceState) {
3838
@Override
3939
public void onClick(View view) {
4040
if (sv.isShown()) {
41-
sv.animateGesture(0, 0, 0, -400).start();
41+
sv.animateGesture(0, 0, 0, -400);
4242
} else {
4343
startActivity(new Intent(this, ActionItemsSampleActivity.class));
4444
}

0 commit comments

Comments
 (0)