Skip to content
This repository has been archived by the owner on Apr 24, 2018. It is now read-only.

Commit

Permalink
Merge pull request #320 from amlcurran/multi-showcase
Browse files Browse the repository at this point in the history
Fix memory management issues
  • Loading branch information
amlcurran committed Nov 12, 2015
2 parents 4ff73d3 + 0e6a8b4 commit 790d91c
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 70 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -173,6 +169,7 @@ void setShowcasePosition(int x, int y) {
showcaseX = x - positionInWindow[0];
showcaseY = y - positionInWindow[1];
//init();
recalculateText();
invalidate();
}

Expand Down Expand Up @@ -212,7 +209,6 @@ private void updateBitmap() {
bitmapBuffer.recycle();
}
bitmapBuffer = Bitmap.createBitmap(getMeasuredWidth(), getMeasuredHeight(), Bitmap.Config.ARGB_8888);

}
}

Expand Down Expand Up @@ -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);
Expand All @@ -330,6 +325,7 @@ this, fadeOutMillis, new AnimationEndListener() {
@Override
public void onAnimationEnd() {
setVisibility(View.GONE);
clearBitmap();
isShowing = false;
mEventListener.onShowcaseViewDidHide(ShowcaseView.this);
}
Expand All @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

<activity android:name=".animations.AnimationSampleActivity" />

<activity android:name=".MemoryManagementTesting" />

<activity android:name=".SingleShotActivity" />

<activity android:name=".CustomTextActivity" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand All @@ -150,15 +153,17 @@ 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[] {
R.string.sum_action_items,
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) {
Expand Down
36 changes: 36 additions & 0 deletions sample/src/main/res/layout/activity_memory.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!--
~ 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.
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">

<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:id="@+id/toolbar"
android:layout_height="wrap_content"/>

<Button
android:id="@+id/buttonBlocked"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:minWidth="96dp"
android:layout_margin="16dp"
android:layout_gravity="center_horizontal" />

</LinearLayout>

0 comments on commit 790d91c

Please sign in to comment.