Skip to content

Commit d0f5b3a

Browse files
Merge pull request #14 from volser/master
Added Gravity.CENTER orientation
2 parents 4da1fc3 + 0224d5b commit d0f5b3a

File tree

6 files changed

+26
-3
lines changed

6 files changed

+26
-3
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
jcenter()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:2.1.0'
8+
classpath 'com.android.tools.build:gradle:2.1.2'
99
// NOTE: Do not place your application dependencies here; they belong
1010
// in the individual module build.gradle files
1111
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,12 @@ private PointF calculePopupLocation() {
202202
location.x = anchorCenter.x - mPopupWindow.getContentView().getWidth() / 2f;
203203
location.y = anchorRect.bottom + mMargin;
204204
break;
205+
case Gravity.CENTER:
206+
location.x = anchorCenter.x - mPopupWindow.getContentView().getWidth() / 2f;
207+
location.y = anchorCenter.y - mPopupWindow.getContentView().getHeight() / 2f;
208+
break;
205209
default:
206-
throw new IllegalArgumentException("Gravity must have be START, END, TOP or BOTTOM.");
210+
throw new IllegalArgumentException("Gravity must have be CENTER, START, END, TOP or BOTTOM.");
207211
}
208212

209213
return location;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,10 @@ public static int tooltipGravityToArrowDirection(int tooltipGravity) {
8989
return ArrowDrawable.BOTTOM;
9090
case Gravity.BOTTOM:
9191
return ArrowDrawable.TOP;
92+
case Gravity.CENTER:
93+
return ArrowDrawable.TOP;
9294
default:
93-
throw new IllegalArgumentException("Gravity must have be START, END, TOP or BOTTOM.");
95+
throw new IllegalArgumentException("Gravity must have be CENTER, START, END, TOP or BOTTOM.");
9496
}
9597
}
9698

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ protected void onCreate(Bundle savedInstanceState) {
6565
findViewById(R.id.btn_no_arrow).setOnClickListener(this);
6666
findViewById(R.id.btn_custom_arrow).setOnClickListener(this);
6767
findViewById(R.id.btn_dialog).setOnClickListener(this);
68+
findViewById(R.id.btn_center).setOnClickListener(this);
6869
}
6970

7071
@Override
@@ -240,6 +241,14 @@ public void onClick(View v) {
240241
dialog.dismiss();
241242
}
242243
});
244+
} else if (v.getId() == R.id.btn_center) {
245+
new SimpleTooltip.Builder(this)
246+
.anchorView(v.getRootView())
247+
.text(getString(R.string.btn_center))
248+
.showArrow(false)
249+
.gravity(Gravity.CENTER)
250+
.build()
251+
.show();
243252
}
244253
}
245254
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@
105105
android:layout_height="wrap_content"
106106
android:layout_gravity="center"
107107
android:text="@string/btn_dialog" />
108+
109+
<Button
110+
android:id="@+id/btn_center"
111+
android:layout_width="wrap_content"
112+
android:layout_height="wrap_content"
113+
android:layout_gravity="center"
114+
android:text="@string/btn_center" />
108115
</LinearLayout>
109116
</ScrollView>
110117

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@
1616
<string name="btn_in_dialog">Tooltip em Dialog</string>
1717
<string name="btn_close">Fechar</string>
1818
<string name="btn_dialog">Em dialog</string>
19+
<string name="btn_center">Center</string>
1920
</resources>

0 commit comments

Comments
 (0)