diff --git a/README.md b/README.md index c781bc5..ce33cf8 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,21 @@ new GuideView.Builder(MainActivity.this) .show(); ``` +## Set Text and background color +```java +new GuideView.Builder(MainActivity.this) + .setTitle("Guide Title Text") + .setTitleTextColor(Color.RED) // optional - default is Color.BLACK + .setContentText("Guide Description Text\n .....Guide Description Text\n .....Guide Description Text .....") + .setContentTextColor(Color.GREEN) // optional - default is Color.BLACK + .setMessageBackgroundColor(Color.BLACK) // optional - default is Color.WHITE. Can be Color.TRANSPARENT + .setGravity(Gravity.CENTER) + .setTargetView(view1) + .setDismissType(DismissType.outSide) //optional - default dismissible by TargetView + .build() + .show(); +``` + ### DismissType Attribute | Type | Description | diff --git a/app/src/main/java/ir/smartdevelop/eram/showcaseview/MainActivity.java b/app/src/main/java/ir/smartdevelop/eram/showcaseview/MainActivity.java index 144875b..1b85b31 100644 --- a/app/src/main/java/ir/smartdevelop/eram/showcaseview/MainActivity.java +++ b/app/src/main/java/ir/smartdevelop/eram/showcaseview/MainActivity.java @@ -1,5 +1,6 @@ package ir.smartdevelop.eram.showcaseview; +import android.graphics.Color; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; @@ -52,10 +53,11 @@ protected void onCreate(Bundle savedInstanceState) { builder.setTargetView(view4).build(); break; case R.id.view4: - builder.setTargetView(view5).build(); + builder.setTargetView(view5).setContentTextColor(Color.GREEN).build(); break; case R.id.view5: - builder.setTargetView(view6).build(); + builder.setTargetView(view6).setTitleTextColor(Color.RED) + .setMessageBackgroundColor(Color.BLACK).build(); break; case R.id.view6: return; diff --git a/showcaseviewlib/src/main/java/smartdevelop/ir/eram/showcaseviewlib/GuideMessageView.java b/showcaseviewlib/src/main/java/smartdevelop/ir/eram/showcaseviewlib/GuideMessageView.java index 4005562..302cb44 100644 --- a/showcaseviewlib/src/main/java/smartdevelop/ir/eram/showcaseviewlib/GuideMessageView.java +++ b/showcaseviewlib/src/main/java/smartdevelop/ir/eram/showcaseviewlib/GuideMessageView.java @@ -52,6 +52,7 @@ class GuideMessageView extends LinearLayout { mTitleTextView.setGravity(Gravity.CENTER); mTitleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_TITLE_TEXT_SIZE); mTitleTextView.setTextColor(Color.BLACK); + mTitleTextView.setBackgroundColor(Color.TRANSPARENT); addView( mTitleTextView, new LayoutParams( @@ -62,6 +63,7 @@ class GuideMessageView extends LinearLayout { mContentTextView = new TextView(context); mContentTextView.setTextColor(Color.BLACK); + mContentTextView.setBackgroundColor(Color.TRANSPARENT); mContentTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_CONTENT_TEXT_SIZE); mContentTextView.setPadding(padding, paddingBottom, padding, padding); mContentTextView.setGravity(Gravity.CENTER); @@ -82,6 +84,16 @@ public void setTitle(String title) { mTitleTextView.setText(title); } + public void setTitleTextColor(int color) { + mTitleTextView.setTextColor(color); + } + + public void setContentColor(int color) { + mContentTextView.setTextColor(color); + } + + + public void setContentText(String content) { mContentTextView.setText(content); } diff --git a/showcaseviewlib/src/main/java/smartdevelop/ir/eram/showcaseviewlib/GuideView.java b/showcaseviewlib/src/main/java/smartdevelop/ir/eram/showcaseviewlib/GuideView.java index 956ee5d..b69e4e7 100644 --- a/showcaseviewlib/src/main/java/smartdevelop/ir/eram/showcaseviewlib/GuideView.java +++ b/showcaseviewlib/src/main/java/smartdevelop/ir/eram/showcaseviewlib/GuideView.java @@ -53,6 +53,7 @@ public class GuideView extends FrameLayout { private static final int CIRCLE_INNER_INDICATOR_COLOR = 0xffcccccc; private static final int CIRCLE_INDICATOR_COLOR = Color.WHITE; private static final int LINE_INDICATOR_COLOR = Color.WHITE; + private static final int DEFAULT_MESSAGE_BACKGROUND_COLOR = Color.WHITE; private final Paint selfPaint = new Paint(); private final Paint paintLine = new Paint(); @@ -100,19 +101,19 @@ private GuideView(Context context, View view) { mMessageView = new GuideMessageView(getContext()); mMessageView.setPadding( - messageViewPadding, - messageViewPadding, - messageViewPadding, - messageViewPadding + messageViewPadding, + messageViewPadding, + messageViewPadding, + messageViewPadding ); - mMessageView.setColor(Color.WHITE); + mMessageView.setColor(DEFAULT_MESSAGE_BACKGROUND_COLOR); addView( - mMessageView, - new LayoutParams( - ViewGroup.LayoutParams.WRAP_CONTENT, - ViewGroup.LayoutParams.WRAP_CONTENT - ) + mMessageView, + new LayoutParams( + ViewGroup.LayoutParams.WRAP_CONTENT, + ViewGroup.LayoutParams.WRAP_CONTENT + ) ); ViewTreeObserver.OnGlobalLayoutListener layoutListener = new ViewTreeObserver.OnGlobalLayoutListener() { @@ -130,10 +131,10 @@ public void onGlobalLayout() { int[] locationTarget = new int[2]; target.getLocationOnScreen(locationTarget); targetRect = new RectF( - locationTarget[0], - locationTarget[1], - locationTarget[0] + target.getWidth(), - locationTarget[1] + target.getHeight() + locationTarget[0], + locationTarget[1], + locationTarget[0] + target.getWidth(), + locationTarget[1] + target.getHeight() ); if (isLandscape()) { targetRect.offset(-getStatusBarHeight(), 0); @@ -141,10 +142,10 @@ public void onGlobalLayout() { } backgroundRect.set( - getPaddingLeft(), - getPaddingTop(), - getWidth() - getPaddingRight(), - getHeight() - getPaddingBottom() + getPaddingLeft(), + getPaddingTop(), + getWidth() - getPaddingRight(), + getHeight() - getPaddingBottom() ); if (isLandscape()) { backgroundRect.offset(-getNavigationBarSize(), 0); @@ -166,8 +167,8 @@ public void onGlobalLayout() { private void startAnimationSize() { if (!isPerformedAnimationSize) { final ValueAnimator circleSizeAnimator = ValueAnimator.ofFloat( - 0f, - circleIndicatorSizeFinal + 0f, + circleIndicatorSizeFinal ); circleSizeAnimator.addUpdateListener(valueAnimator -> { circleIndicatorSize = (float) circleSizeAnimator.getAnimatedValue(); @@ -176,8 +177,8 @@ private void startAnimationSize() { }); final ValueAnimator linePositionAnimator = ValueAnimator.ofFloat( - stopY, - startYLineAndCircle + stopY, + startYLineAndCircle ); linePositionAnimator.addUpdateListener(valueAnimator -> { startYLineAndCircle = (float) linePositionAnimator.getAnimatedValue(); @@ -276,10 +277,10 @@ protected void onDraw(final Canvas canvas) { canvas.drawLine(x, startYLineAndCircle, x, stopY, paintLine); canvas.drawCircle(x, startYLineAndCircle, circleIndicatorSize, paintCircle); canvas.drawCircle( - x, - startYLineAndCircle, - circleInnerIndicatorSize, - paintCircleInner + x, + startYLineAndCircle, + circleInnerIndicatorSize, + paintCircleInner ); break; case arrow: @@ -306,10 +307,10 @@ protected void onDraw(final Canvas canvas) { canvas.drawPath(((Targetable) target).guidePath(), targetPaint); } else { canvas.drawRoundRect( - targetRect, - RADIUS_SIZE_TARGET_RECT, - RADIUS_SIZE_TARGET_RECT, - targetPaint + targetRect, + RADIUS_SIZE_TARGET_RECT, + RADIUS_SIZE_TARGET_RECT, + targetPaint ); } } @@ -430,8 +431,8 @@ private Point resolveMessageViewLocation() { public void show() { this.setLayoutParams(new ViewGroup.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.MATCH_PARENT + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT )); this.setClickable(false); ((ViewGroup) ((Activity) getContext()).getWindow().getDecorView()).addView(this); @@ -470,6 +471,18 @@ public void setContentTextSize(int size) { mMessageView.setContentTextSize(size); } + public void setTitleTextColor(int color) { + mMessageView.setTitleTextColor(color); + } + + public void setContentTextColor(int color) { + mMessageView.setContentColor(color); + } + + public void setMessageBackgroundColor(int color) { + mMessageView.setColor(color); + } + public static class Builder { private View targetView; @@ -483,6 +496,9 @@ public static class Builder { private GuideListener guideListener; private int titleTextSize; private int contentTextSize; + private int titleColor; + private int contentTextColor; + private int messageBackgroundColor = -2; private float lineIndicatorHeight; private float lineIndicatorWidthSize; private float circleIndicatorSize; @@ -660,6 +676,35 @@ public Builder setPointerType(PointerType pointerType) { return this; } + /** + * this method defining the type of pointer + * + * @param color should come from Color and cannot be Color.TRANSPARENT constant, example: Color.WHITE + */ + public Builder setTitleTextColor(int color) { + this.titleColor = color; + return this; + } + + /** + * this method defining the type of pointer + * + * @param color should come from Color and cannot be Color.TRANSPARENT constant, example: Color.WHITE + */ + public Builder setContentTextColor(int color) { + this.contentTextColor = color; + return this; + } + + /** + * this method defining the type of pointer + * + * @param color should come from Color and cannot be -2 (no constant is assigned to this number), example: Color.TRANSPARENT + */ + public Builder setMessageBackgroundColor(int color) { + this.messageBackgroundColor = color; + return this; + } public GuideView build() { GuideView guideView = new GuideView(context, targetView); guideView.mGravity = gravity != null ? gravity : Gravity.auto; @@ -704,6 +749,15 @@ public GuideView build() { if (strokeCircleWidth != 0) { guideView.strokeCircleWidth = strokeCircleWidth * density; } + if (titleColor != 0) { + guideView.setTitleTextColor(titleColor); + } + if (contentTextColor != 0) { + guideView.setContentTextColor(contentTextColor); + } + if (messageBackgroundColor != -2) { + guideView.setMessageBackgroundColor(messageBackgroundColor); + } return guideView; }