Skip to content
This repository was archived by the owner on Nov 10, 2024. It is now read-only.

Changing text color feature #71

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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() {
Expand All @@ -130,21 +131,21 @@ 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);
}
}

backgroundRect.set(
getPaddingLeft(),
getPaddingTop(),
getWidth() - getPaddingRight(),
getHeight() - getPaddingBottom()
getPaddingLeft(),
getPaddingTop(),
getWidth() - getPaddingRight(),
getHeight() - getPaddingBottom()
);
if (isLandscape()) {
backgroundRect.offset(-getNavigationBarSize(), 0);
Expand All @@ -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();
Expand All @@ -176,8 +177,8 @@ private void startAnimationSize() {
});

final ValueAnimator linePositionAnimator = ValueAnimator.ofFloat(
stopY,
startYLineAndCircle
stopY,
startYLineAndCircle
);
linePositionAnimator.addUpdateListener(valueAnimator -> {
startYLineAndCircle = (float) linePositionAnimator.getAnimatedValue();
Expand Down Expand Up @@ -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:
Expand All @@ -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
);
}
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down