Skip to content

Commit 262172e

Browse files
Merge pull request #114 from Alfons109/issue-112-rounded-corner
issue-112-support-for-rounded-corner
2 parents fb07e89 + f6154a1 commit 262172e

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
@@ -125,6 +125,7 @@ public class SimpleTooltip implements PopupWindow.OnDismissListener {
125125
private int width;
126126
private int height;
127127
private boolean mIgnoreOverlay;
128+
private float cornerRadius;
128129

129130

130131
private SimpleTooltip(Builder builder) {
@@ -160,6 +161,7 @@ private SimpleTooltip(Builder builder) {
160161
mIgnoreOverlay = builder.ignoreOverlay;
161162
this.width = builder.width;
162163
this.height = builder.height;
164+
this.cornerRadius = builder.cornerRadius;
163165
init();
164166
}
165167

@@ -230,7 +232,7 @@ private void createOverlay() {
230232
if (mIgnoreOverlay) {
231233
return;
232234
}
233-
mOverlay = mTransparentOverlay ? new View(mContext) : new OverlayView(mContext, mAnchorView, mHighlightShape, mOverlayOffset,mOverlayWindowBackgroundColor);
235+
mOverlay = mTransparentOverlay ? new View(mContext) : new OverlayView(mContext, mAnchorView, mHighlightShape, mOverlayOffset,mOverlayWindowBackgroundColor, cornerRadius);
234236
if (mOverlayMatchParent)
235237
mOverlay.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
236238
else
@@ -602,6 +604,7 @@ public static class Builder {
602604
private float arrowHeight;
603605
private float arrowWidth;
604606
private boolean focusable;
607+
private float cornerRadius;
605608
private int highlightShape = OverlayView.HIGHLIGHT_SHAPE_OVAL;
606609
private int width = ViewGroup.LayoutParams.WRAP_CONTENT;
607610
private int height = ViewGroup.LayoutParams.WRAP_CONTENT;
@@ -661,7 +664,7 @@ public SimpleTooltip build() throws IllegalArgumentException {
661664
if (arrowHeight == 0)
662665
arrowHeight = context.getResources().getDimension(mDefaultArrowHeightRes);
663666
}
664-
if (highlightShape < 0 || highlightShape > OverlayView.HIGHLIGHT_SHAPE_RECTANGULAR) {
667+
if (highlightShape < 0 || highlightShape > OverlayView.HIGHLIGHT_SHAPE_RECTANGULAR_ROUNDED) {
665668
highlightShape = OverlayView.HIGHLIGHT_SHAPE_OVAL;
666669
}
667670
if (overlayOffset < 0) {
@@ -1101,6 +1104,11 @@ public Builder highlightShape(int highlightShape) {
11011104
return this;
11021105
}
11031106

1107+
public Builder cornerRadius(float radius) {
1108+
this.cornerRadius = radius;
1109+
return this;
1110+
}
1111+
11041112
/**
11051113
* <div class="pt">Tamanho da margem entre {@link Builder#anchorView(View)} e a borda do Shape de destaque.
11061114
* 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)