diff --git a/library/src/main/java/com/github/amlcurran/showcaseview/Calculator.java b/library/src/main/java/com/github/amlcurran/showcaseview/Calculator.java
deleted file mode 100644
index 78fba6f2a..000000000
--- a/library/src/main/java/com/github/amlcurran/showcaseview/Calculator.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright 2014 Alex Curran
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.github.amlcurran.showcaseview;
-
-import android.graphics.Point;
-import android.view.View;
-
-/**
- * Calculates various items for use with ShowcaseView
- */
-class Calculator {
-
- static Point getShowcasePointFromView(View view) {
- Point result = new Point();
- result.x = view.getLeft() + view.getWidth() / 2;
- result.y = view.getTop() + view.getHeight() / 2;
- return result;
- }
-
-}
diff --git a/library/src/main/java/com/github/amlcurran/showcaseview/ShowcaseView.java b/library/src/main/java/com/github/amlcurran/showcaseview/ShowcaseView.java
index 8f80168cc..c55916ea2 100644
--- a/library/src/main/java/com/github/amlcurran/showcaseview/ShowcaseView.java
+++ b/library/src/main/java/com/github/amlcurran/showcaseview/ShowcaseView.java
@@ -34,7 +34,6 @@
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
-import android.view.ViewTreeObserver;
import android.widget.Button;
import android.widget.RelativeLayout;
@@ -112,9 +111,6 @@ protected ShowcaseView(Context context, AttributeSet attrs, int defStyle, boolea
showcaseAreaCalculator = new ShowcaseAreaCalculator();
shotStateStore = new ShotStateStore(context);
- getViewTreeObserver().addOnPreDrawListener(new CalculateTextOnPreDraw());
- getViewTreeObserver().addOnGlobalLayoutListener(new UpdateOnGlobalLayout());
-
// Get the attributes for the ShowcaseView
final TypedArray styled = context.getTheme()
.obtainStyledAttributes(attrs, R.styleable.ShowcaseView, R.attr.showcaseViewStyle,
@@ -173,6 +169,7 @@ void setShowcasePosition(int x, int y) {
showcaseX = x - positionInWindow[0];
showcaseY = y - positionInWindow[1];
//init();
+ recalculateText();
invalidate();
}
@@ -212,7 +209,6 @@ private void updateBitmap() {
bitmapBuffer.recycle();
}
bitmapBuffer = Bitmap.createBitmap(getMeasuredWidth(), getMeasuredHeight(), Bitmap.Config.ARGB_8888);
-
}
}
@@ -310,7 +306,6 @@ protected void dispatchDraw(Canvas canvas) {
@Override
public void hide() {
- clearBitmap();
// If the type is set to one-shot, store that it has shot
shotStateStore.storeShot();
mEventListener.onShowcaseViewHide(this);
@@ -330,6 +325,7 @@ this, fadeOutMillis, new AnimationEndListener() {
@Override
public void onAnimationEnd() {
setVisibility(View.GONE);
+ clearBitmap();
isShowing = false;
mEventListener.onShowcaseViewDidHide(ShowcaseView.this);
}
@@ -340,10 +336,17 @@ public void onAnimationEnd() {
@Override
public void show() {
isShowing = true;
+ if (canUpdateBitmap()) {
+ updateBitmap();
+ }
mEventListener.onShowcaseViewShow(this);
fadeInShowcase();
}
+ private boolean canUpdateBitmap() {
+ return getMeasuredHeight() > 0 && getMeasuredWidth() > 0;
+ }
+
private void fadeInShowcase() {
animationFactory.fadeInView(
this, fadeInMillis,
@@ -805,25 +808,6 @@ private void tintButton(int showcaseColor, boolean tintButton) {
}
}
- private class UpdateOnGlobalLayout implements ViewTreeObserver.OnGlobalLayoutListener {
-
- @Override
- public void onGlobalLayout() {
- if (!shotStateStore.hasShot()) {
- updateBitmap();
- }
- }
- }
-
- private class CalculateTextOnPreDraw implements ViewTreeObserver.OnPreDrawListener {
-
- @Override
- public boolean onPreDraw() {
- recalculateText();
- return true;
- }
- }
-
private OnClickListener hideOnClickListener = new OnClickListener() {
@Override
public void onClick(View v) {
diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml
index 7f8349a66..19d207823 100644
--- a/sample/src/main/AndroidManifest.xml
+++ b/sample/src/main/AndroidManifest.xml
@@ -36,6 +36,8 @@
+
+
diff --git a/sample/src/main/java/com/github/amlcurran/showcaseview/sample/MemoryManagementTesting.java b/sample/src/main/java/com/github/amlcurran/showcaseview/sample/MemoryManagementTesting.java
index 3e73d87bb..201aca5e4 100644
--- a/sample/src/main/java/com/github/amlcurran/showcaseview/sample/MemoryManagementTesting.java
+++ b/sample/src/main/java/com/github/amlcurran/showcaseview/sample/MemoryManagementTesting.java
@@ -19,21 +19,43 @@
import android.app.Activity;
import android.os.Bundle;
-public class MemoryManagementTesting extends Activity {
+import com.github.amlcurran.showcaseview.OnShowcaseEventListener;
+import com.github.amlcurran.showcaseview.ShowcaseView;
+import com.github.amlcurran.showcaseview.targets.ViewTarget;
+
+public class MemoryManagementTesting extends Activity implements OnShowcaseEventListener {
+
+ int currentShowcase = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
+ showcase();
+ }
+
+ private void showcase() {
+ new ShowcaseView.Builder(this)
+ .withMaterialShowcase()
+ .setContentText(String.format("Showing %1$d", currentShowcase))
+ .setTarget(new ViewTarget(R.id.buttonBlocked, this))
+ .setShowcaseEventListener(this)
+ .build();
+ }
+
+ @Override
+ public void onShowcaseViewHide(ShowcaseView showcaseView) {
-// ShowcaseViews showcaseViews = new ShowcaseViews(this);
-//
-// ShowcaseViews.ItemViewProperties properties = new ShowcaseViews.ItemViewProperties(
-// R.id.buttonBlocked, R.string.showcase_like_title, R.string.showcase_like_message
-// );
-//
-// showcaseViews.addView(properties).addView(properties).addView(properties).addView(properties)
-// .addView(properties).addView(properties).show();
+ }
+
+ @Override
+ public void onShowcaseViewDidHide(ShowcaseView showcaseView) {
+ currentShowcase++;
+ showcase();
+ }
+
+ @Override
+ public void onShowcaseViewShow(ShowcaseView showcaseView) {
}
}
diff --git a/sample/src/main/java/com/github/amlcurran/showcaseview/sample/SampleActivity.java b/sample/src/main/java/com/github/amlcurran/showcaseview/sample/SampleActivity.java
index bae61fd1e..aa91597e4 100644
--- a/sample/src/main/java/com/github/amlcurran/showcaseview/sample/SampleActivity.java
+++ b/sample/src/main/java/com/github/amlcurran/showcaseview/sample/SampleActivity.java
@@ -140,6 +140,9 @@ public void onItemClick(AdapterView> adapterView, View view, int position, lon
case 4:
startActivity(new Intent(this, CustomShowcaseActivity.class));
break;
+ case 5:
+ startActivity(new Intent(this, MemoryManagementTesting.class));
+ break;
}
}
@@ -150,7 +153,8 @@ private static class HardcodedListAdapter extends ArrayAdapter {
R.string.title_animations,
R.string.title_single_shot,
R.string.custom_text,
- R.string.custom_showcase_title//, R.string.title_memory
+ R.string.custom_showcase_title,
+ R.string.title_memory
};
private static final int[] SUMMARY_RES_IDS = new int[] {
@@ -158,7 +162,8 @@ private static class HardcodedListAdapter extends ArrayAdapter {
R.string.sum_animations,
R.string.sum_single_shot,
R.string.custom_text_summary,
- R.string.custom_showcase_summary//, R.string.sum_memory
+ R.string.custom_showcase_summary,
+ R.string.sum_memory
};
public HardcodedListAdapter(Context context) {
diff --git a/sample/src/main/res/layout/activity_memory.xml b/sample/src/main/res/layout/activity_memory.xml
new file mode 100644
index 000000000..e1610428f
--- /dev/null
+++ b/sample/src/main/res/layout/activity_memory.xml
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file