This repository has been archived by the owner on Apr 24, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #306 from amlcurran/custom-showcase-drawer
Custom + material showcase drawer API
- Loading branch information
Showing
16 changed files
with
280 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
library/src/main/java/com/github/amlcurran/showcaseview/MaterialShowcaseDrawer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.github.amlcurran.showcaseview; | ||
|
||
import android.content.res.Resources; | ||
import android.graphics.Bitmap; | ||
import android.graphics.Canvas; | ||
import android.graphics.Paint; | ||
import android.graphics.PorterDuff; | ||
import android.graphics.PorterDuffXfermode; | ||
|
||
public class MaterialShowcaseDrawer implements ShowcaseDrawer { | ||
|
||
private final float radius; | ||
private final Paint basicPaint; | ||
private final Paint eraserPaint; | ||
private int backgroundColor; | ||
|
||
public MaterialShowcaseDrawer(Resources resources) { | ||
this.radius = resources.getDimension(R.dimen.showcase_radius_material); | ||
this.eraserPaint = new Paint(); | ||
this.eraserPaint.setColor(0xFFFFFF); | ||
this.eraserPaint.setAlpha(0); | ||
this.eraserPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY)); | ||
this.eraserPaint.setAntiAlias(true); | ||
this.basicPaint = new Paint(); | ||
} | ||
|
||
@Override | ||
public void setShowcaseColour(int color) { | ||
// no-op | ||
} | ||
|
||
@Override | ||
public void drawShowcase(Bitmap buffer, float x, float y, float scaleMultiplier) { | ||
Canvas bufferCanvas = new Canvas(buffer); | ||
bufferCanvas.drawCircle(x, y, radius, eraserPaint); | ||
} | ||
|
||
@Override | ||
public int getShowcaseWidth() { | ||
return (int) (radius * 2); | ||
} | ||
|
||
@Override | ||
public int getShowcaseHeight() { | ||
return (int) (radius * 2); | ||
} | ||
|
||
@Override | ||
public float getBlockedRadius() { | ||
return radius; | ||
} | ||
|
||
@Override | ||
public void setBackgroundColour(int backgroundColor) { | ||
this.backgroundColor = backgroundColor; | ||
} | ||
|
||
@Override | ||
public void erase(Bitmap bitmapBuffer) { | ||
bitmapBuffer.eraseColor(backgroundColor); | ||
} | ||
|
||
@Override | ||
public void drawToCanvas(Canvas canvas, Bitmap bitmapBuffer) { | ||
canvas.drawBitmap(bitmapBuffer, 0, 0, basicPaint); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
sample/src/main/java/com/github/amlcurran/showcaseview/sample/CustomShowcaseActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package com.github.amlcurran.showcaseview.sample; | ||
|
||
import android.app.Activity; | ||
import android.content.res.Resources; | ||
import android.graphics.Bitmap; | ||
import android.graphics.Canvas; | ||
import android.graphics.Paint; | ||
import android.graphics.PorterDuff; | ||
import android.graphics.PorterDuffXfermode; | ||
import android.graphics.RectF; | ||
import android.os.Bundle; | ||
|
||
import com.github.amlcurran.showcaseview.ShowcaseDrawer; | ||
import com.github.amlcurran.showcaseview.ShowcaseView; | ||
import com.github.amlcurran.showcaseview.targets.ViewTarget; | ||
|
||
public class CustomShowcaseActivity extends Activity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_custom_showcase); | ||
|
||
new ShowcaseView.Builder(this) | ||
.setTarget(new ViewTarget(R.id.imageView, this)) | ||
.setContentTitle(R.string.custom_text_painting_title) | ||
.setContentText(R.string.custom_text_painting_text) | ||
.setShowcaseDrawer(new CustomShowcaseView(getResources())) | ||
.build(); | ||
} | ||
|
||
private static class CustomShowcaseView implements ShowcaseDrawer { | ||
|
||
private final float width; | ||
private final float height; | ||
private final Paint eraserPaint; | ||
private final Paint basicPaint; | ||
private final int eraseColour; | ||
private final RectF renderRect; | ||
|
||
public CustomShowcaseView(Resources resources) { | ||
width = resources.getDimension(R.dimen.custom_showcase_width); | ||
height = resources.getDimension(R.dimen.custom_showcase_height); | ||
PorterDuffXfermode xfermode = new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY); | ||
eraserPaint = new Paint(); | ||
eraserPaint.setColor(0xFFFFFF); | ||
eraserPaint.setAlpha(0); | ||
eraserPaint.setXfermode(xfermode); | ||
eraserPaint.setAntiAlias(true); | ||
eraseColour = resources.getColor(R.color.custom_showcase_bg); | ||
basicPaint = new Paint(); | ||
renderRect = new RectF(); | ||
} | ||
|
||
@Override | ||
public void setShowcaseColour(int color) { | ||
eraserPaint.setColor(color); | ||
} | ||
|
||
@Override | ||
public void drawShowcase(Bitmap buffer, float x, float y, float scaleMultiplier) { | ||
Canvas bufferCanvas = new Canvas(buffer); | ||
renderRect.left = x - width / 2f; | ||
renderRect.right = x + width / 2f; | ||
renderRect.top = y - height / 2f; | ||
renderRect.bottom = y + height / 2f; | ||
bufferCanvas.drawRect(renderRect, eraserPaint); | ||
} | ||
|
||
@Override | ||
public int getShowcaseWidth() { | ||
return (int) width; | ||
} | ||
|
||
@Override | ||
public int getShowcaseHeight() { | ||
return (int) height; | ||
} | ||
|
||
@Override | ||
public float getBlockedRadius() { | ||
return width; | ||
} | ||
|
||
@Override | ||
public void setBackgroundColour(int backgroundColor) { | ||
// No-op, remove this from the API? | ||
} | ||
|
||
@Override | ||
public void erase(Bitmap bitmapBuffer) { | ||
bitmapBuffer.eraseColor(eraseColour); | ||
} | ||
|
||
@Override | ||
public void drawToCanvas(Canvas canvas, Bitmap bitmapBuffer) { | ||
canvas.drawBitmap(bitmapBuffer, 0, 0, basicPaint); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.