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

Commit

Permalink
added special Cling implementation to show an arrow (currently showin…
Browse files Browse the repository at this point in the history
…g hand until we get the assets). Fixed init method not respecting new configs and added scale of the cling to the configuration.
  • Loading branch information
Martin Marconcini committed Feb 13, 2014
1 parent a9ddf4a commit 9582e68
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 12 deletions.
52 changes: 40 additions & 12 deletions library/src/com/espian/showcaseview/ShowcaseView.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@
import com.espian.showcaseview.actionbar.ActionBarViewWrapper;
import com.espian.showcaseview.actionbar.reflection.BaseReflector;
import com.espian.showcaseview.anim.AnimationUtils;
import com.espian.showcaseview.drawing.ClingDrawer;
import com.espian.showcaseview.drawing.ClingDrawerImpl;
import com.espian.showcaseview.drawing.TextDrawer;
import com.espian.showcaseview.drawing.TextDrawerImpl;
import com.espian.showcaseview.drawing.*;
import com.espian.showcaseview.targets.Target;
import com.espian.showcaseview.utils.Calculator;
import com.espian.showcaseview.utils.PointAnimator;
Expand Down Expand Up @@ -80,7 +77,8 @@ public class ShowcaseView extends RelativeLayout

private final String buttonText;

private float scaleMultiplier = 1f;
private float scaleMultiplier = 0f;
// private float scaleMultiplier = 0.5f;
private TextDrawer mTextDrawer;
private ClingDrawer mShowcaseDrawer;

Expand All @@ -93,11 +91,14 @@ public Point getPoint() {

private boolean mHasNoTarget = false;

protected ShowcaseView(Context context, final boolean arrow) {
this(context, null, R.styleable.CustomTheme_showcaseViewStyle, arrow);
}
protected ShowcaseView(Context context) {
this(context, null, R.styleable.CustomTheme_showcaseViewStyle);
this(context, null, R.styleable.CustomTheme_showcaseViewStyle, false);
}

protected ShowcaseView(Context context, AttributeSet attrs, int defStyle) {
protected ShowcaseView(Context context, AttributeSet attrs, int defStyle, final boolean arrow) {
super(context, attrs, defStyle);

// Get the attributes for the ShowcaseView
Expand All @@ -107,6 +108,7 @@ protected ShowcaseView(Context context, AttributeSet attrs, int defStyle) {
mBackgroundColor = styled
.getInt(R.styleable.ShowcaseView_sv_backgroundColor, Color.argb(128, 80, 80, 80));
int showcaseColor = styled
// .getColor(R.styleable.ShowcaseView_sv_showcaseColor, Color.parseColor("#0b2033"));
.getColor(R.styleable.ShowcaseView_sv_showcaseColor, Color.parseColor("#33B5E5"));

int titleTextAppearance = styled
Expand All @@ -122,7 +124,11 @@ protected ShowcaseView(Context context, AttributeSet attrs, int defStyle) {
metricScale = getContext().getResources().getDisplayMetrics().density;
mEndButton = (Button) LayoutInflater.from(context).inflate(R.layout.showcase_button, null);

mShowcaseDrawer = new ClingDrawerImpl(getResources(), showcaseColor);
if (arrow) {
mShowcaseDrawer = new TwoArrowsClickDrawerImpl(getResources(), showcaseColor);
} else {
mShowcaseDrawer = new ClingDrawerImpl(getResources(), showcaseColor);
}

// TODO: This isn't ideal, ClingDrawer and Calculator interfaces should be separate
mTextDrawer = new TextDrawerImpl(metricScale, mShowcaseDrawer);
Expand All @@ -133,7 +139,7 @@ protected ShowcaseView(Context context, AttributeSet attrs, int defStyle) {
options.showcaseId = getId();
setConfigOptions(options);

init();
//init();
}

private void init() {
Expand All @@ -150,6 +156,7 @@ private void init() {
}

showcaseRadius = metricScale * INNER_CIRCLE_RADIUS;
scaleMultiplier = mOptions.scaleMultiplier;
setOnTouchListener(this);

if (!mOptions.noButton && mEndButton.getParent() == null) {
Expand Down Expand Up @@ -197,7 +204,7 @@ public void setShowcaseView(final View view) {
view.post(new Runnable() {
@Override
public void run() {
//init();
init();
Point viewPoint = Calculator.getShowcasePointFromView(view, getConfigOptions());
setShowcasePosition(viewPoint);
invalidate();
Expand Down Expand Up @@ -227,7 +234,7 @@ public void setShowcasePosition(int x, int y) {
}
showcaseX = x;
showcaseY = y;
//init();
init();
invalidate();
}

Expand Down Expand Up @@ -833,6 +840,22 @@ private static ShowcaseView insertShowcaseViewInternal(Target target, Activity a
sv.setText(title, detail);
return sv;
}
/**
* Internal insert method so all inserts are routed through one method
*/
private static ShowcaseView insertArrowShowcaseViewInternal(Target target, Activity activity, String title,
String detail, ConfigOptions options) {
ShowcaseView sv = new ShowcaseView(activity, true);
sv.setConfigOptions(options);
if (sv.getConfigOptions().insert == INSERT_TO_DECOR) {
((ViewGroup) activity.getWindow().getDecorView()).addView(sv);
} else {
((ViewGroup) activity.findViewById(android.R.id.content)).addView(sv);
}
sv.setShowcase(target);
sv.setText(title, detail);
return sv;
}

public static ShowcaseView insertShowcaseView(Target target, Activity activity) {
return insertShowcaseViewInternal(target, activity, null, null, null);
Expand All @@ -854,7 +877,11 @@ public static ShowcaseView insertShowcaseView(Target target, Activity activity,
return insertShowcaseViewInternal(target, activity, activity.getString(title), activity.getString(detail), options);
}

public static class ConfigOptions {
public static ShowcaseView insertArrowShowcaseView(Target target, Activity activity, String title, String detail, ConfigOptions options) {
return insertArrowShowcaseViewInternal(target, activity, title, detail, options);
}

public static class ConfigOptions {

public boolean block = true, noButton = false;
public boolean hideOnClickOutside = false;
Expand Down Expand Up @@ -900,6 +927,7 @@ public static class ConfigOptions {
* Whether the text should be centered or stretched in the available space
*/
public boolean centerText = false;
public float scaleMultiplier = 1.0f;
}

public float getScaleMultiplier() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.espian.showcaseview.drawing;

import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.PorterDuff;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.Log;
import com.github.espiandev.showcaseview.R;

/**
* User: martin
* Date: 2/12/14
* Time: 3:03 PM
*/
public class TwoArrowsClickDrawerImpl implements ClingDrawer {
private Drawable mShowcaseDrawable;
private Rect mShowcaseRect;
public TwoArrowsClickDrawerImpl(Resources resources, int showcaseColor) {
mShowcaseDrawable = resources.getDrawable(R.drawable.hand);
mShowcaseDrawable.setColorFilter(showcaseColor, PorterDuff.Mode.MULTIPLY);
}
@Override
public boolean calculateShowcaseRect(final float x, final float y) {
if (mShowcaseRect == null) {
mShowcaseRect = new Rect();
}
int cx = (int) x, cy = (int) y;
int dw = getShowcaseWidth();
int dh = getShowcaseHeight();
if (mShowcaseRect.left == cx - dw / 2) {
return false;
}
Log.d("ShowcaseView", "Recalculated");
mShowcaseRect.left = cx - dw / 2;
mShowcaseRect.top = cy - dh / 2;
mShowcaseRect.right = cx + dw / 2;
mShowcaseRect.bottom = cy + dh / 2;
return true;
}
public Rect getShowcaseRect() {
return mShowcaseRect;
}
@Override
public void drawShowcase(final Canvas canvas, final float x, final float y, final float scaleMultiplier, final float radius) {
Matrix mm = new Matrix();
mm.postScale(scaleMultiplier, scaleMultiplier, x, y);
canvas.setMatrix(mm);
mShowcaseDrawable.setBounds(mShowcaseRect);
mShowcaseDrawable.draw(canvas);
canvas.setMatrix(new Matrix());
}
@Override
public int getShowcaseWidth() {
return mShowcaseDrawable.getIntrinsicWidth();
}
@Override
public int getShowcaseHeight() {
return mShowcaseDrawable.getIntrinsicHeight();
}
}

0 comments on commit 9582e68

Please sign in to comment.