Skip to content

Commit f6154a1

Browse files
committed
issue-112
- added support for rounded corner overlay
1 parent 27a3269 commit f6154a1

File tree

5 files changed

+38
-3
lines changed

5 files changed

+38
-3
lines changed

library/src/main/java/io/github/douglasjunior/androidSimpleTooltip/OverlayView.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class OverlayView extends View {
4646

4747
public static final int HIGHLIGHT_SHAPE_OVAL = 0;
4848
public static final int HIGHLIGHT_SHAPE_RECTANGULAR = 1;
49+
public static final int HIGHLIGHT_SHAPE_RECTANGULAR_ROUNDED = 2;
4950
private static final int mDefaultOverlayAlphaRes = R.integer.simpletooltip_overlay_alpha;
5051

5152

@@ -56,13 +57,15 @@ public class OverlayView extends View {
5657
private final int highlightShape;
5758
private final float mOffset;
5859
private final int overlayWindowBackground;
60+
private final float cornerRadius;
5961

60-
OverlayView(Context context, View anchorView, int highlightShape, float offset,int overlayWindowBackground) {
62+
OverlayView(Context context, View anchorView, int highlightShape, float offset,int overlayWindowBackground, float cornerRadius) {
6163
super(context);
6264
this.mAnchorView = anchorView;
6365
this.mOffset = offset;
6466
this.highlightShape = highlightShape;
6567
this.overlayWindowBackground=overlayWindowBackground;
68+
this.cornerRadius = cornerRadius;
6669
}
6770

6871
@Override
@@ -106,6 +109,8 @@ private void createWindowFrame() {
106109

107110
if (highlightShape == HIGHLIGHT_SHAPE_RECTANGULAR) {
108111
osCanvas.drawRect(rect, paint);
112+
} else if (highlightShape == HIGHLIGHT_SHAPE_RECTANGULAR_ROUNDED) {
113+
osCanvas.drawRoundRect(rect, cornerRadius, cornerRadius, paint);
109114
} else {
110115
osCanvas.drawOval(rect, paint);
111116
}

library/src/main/java/io/github/douglasjunior/androidSimpleTooltip/SimpleTooltip.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ public class SimpleTooltip implements PopupWindow.OnDismissListener {
123123
private int width;
124124
private int height;
125125
private boolean mIgnoreOverlay;
126+
private float cornerRadius;
126127

127128

128129
private SimpleTooltip(Builder builder) {
@@ -158,6 +159,7 @@ private SimpleTooltip(Builder builder) {
158159
mIgnoreOverlay = builder.ignoreOverlay;
159160
this.width = builder.width;
160161
this.height = builder.height;
162+
this.cornerRadius = builder.cornerRadius;
161163
init();
162164
}
163165

@@ -224,7 +226,7 @@ private void createOverlay() {
224226
if (mIgnoreOverlay) {
225227
return;
226228
}
227-
mOverlay = mTransparentOverlay ? new View(mContext) : new OverlayView(mContext, mAnchorView, mHighlightShape, mOverlayOffset,mOverlayWindowBackgroundColor);
229+
mOverlay = mTransparentOverlay ? new View(mContext) : new OverlayView(mContext, mAnchorView, mHighlightShape, mOverlayOffset,mOverlayWindowBackgroundColor, cornerRadius);
228230
if (mOverlayMatchParent)
229231
mOverlay.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
230232
else
@@ -571,6 +573,7 @@ public static class Builder {
571573
private float arrowHeight;
572574
private float arrowWidth;
573575
private boolean focusable;
576+
private float cornerRadius;
574577
private int highlightShape = OverlayView.HIGHLIGHT_SHAPE_OVAL;
575578
private int width = ViewGroup.LayoutParams.WRAP_CONTENT;
576579
private int height = ViewGroup.LayoutParams.WRAP_CONTENT;
@@ -629,7 +632,7 @@ public SimpleTooltip build() throws IllegalArgumentException {
629632
if (arrowHeight == 0)
630633
arrowHeight = context.getResources().getDimension(mDefaultArrowHeightRes);
631634
}
632-
if (highlightShape < 0 || highlightShape > OverlayView.HIGHLIGHT_SHAPE_RECTANGULAR) {
635+
if (highlightShape < 0 || highlightShape > OverlayView.HIGHLIGHT_SHAPE_RECTANGULAR_ROUNDED) {
633636
highlightShape = OverlayView.HIGHLIGHT_SHAPE_OVAL;
634637
}
635638
if (overlayOffset < 0) {
@@ -1069,6 +1072,11 @@ public Builder highlightShape(int highlightShape) {
10691072
return this;
10701073
}
10711074

1075+
public Builder cornerRadius(float radius) {
1076+
this.cornerRadius = radius;
1077+
return this;
1078+
}
1079+
10721080
/**
10731081
* <div class="pt">Tamanho da margem entre {@link Builder#anchorView(View)} e a borda do Shape de destaque.
10741082
* Este valor sobrescreve <tt>{@link R.dimen.simpletooltip_overlay_offset}</tt></div>

sample/src/main/java/io/github/douglasjunior/androidSimpleTooltip/sample/MainActivity.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ protected void onCreate(Bundle savedInstanceState) {
7171
findViewById(R.id.btn_dialog).setOnClickListener(this);
7272
findViewById(R.id.btn_center).setOnClickListener(this);
7373
findViewById(R.id.btn_overlay_rect).setOnClickListener(this);
74+
findViewById(R.id.btn_overlay_rect_rounded).setOnClickListener(this);
7475
}
7576

7677
@Override
@@ -261,6 +262,19 @@ public void onClick(View v) {
261262
.animated(true)
262263
.transparentOverlay(false)
263264
.highlightShape(OverlayView.HIGHLIGHT_SHAPE_RECTANGULAR)
265+
.cornerRadius(20)
266+
.overlayOffset(0)
267+
.build()
268+
.show();
269+
} else if (v.getId() == R.id.btn_overlay_rect_rounded) {
270+
new SimpleTooltip.Builder(this)
271+
.anchorView(v)
272+
.text(R.string.btn_overlay_rect_rounded)
273+
.gravity(Gravity.END)
274+
.animated(true)
275+
.transparentOverlay(false)
276+
.highlightShape(OverlayView.HIGHLIGHT_SHAPE_RECTANGULAR_ROUNDED)
277+
.cornerRadius(20)
264278
.overlayOffset(0)
265279
.build()
266280
.show();

sample/src/main/res/layout/activity_main.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@
120120
android:layout_height="wrap_content"
121121
android:layout_gravity="start"
122122
android:text="@string/btn_overlay_rect" />
123+
124+
<Button
125+
android:id="@+id/btn_overlay_rect_rounded"
126+
android:layout_width="wrap_content"
127+
android:layout_height="wrap_content"
128+
android:layout_gravity="start"
129+
android:text="@string/btn_overlay_rect_rounded" />
123130
</LinearLayout>
124131
</ScrollView>
125132

sample/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@
2020
<string name="btn_dialog">Inside dialog</string>
2121
<string name="btn_center">Screen center</string>
2222
<string name="btn_overlay_rect">Overlay Rect</string>
23+
<string name="btn_overlay_rect_rounded">Overlay Rect Rounded</string>
2324

2425
</resources>

0 commit comments

Comments
 (0)