Skip to content

Commit fa26793

Browse files
committed
Added option to set Text by resource id
1 parent 12dda5d commit fa26793

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import android.support.annotation.DrawableRes;
4242
import android.support.annotation.IdRes;
4343
import android.support.annotation.LayoutRes;
44+
import android.support.annotation.StringRes;
4445
import android.view.Gravity;
4546
import android.view.LayoutInflater;
4647
import android.view.MotionEvent;
@@ -715,6 +716,17 @@ public Builder text(CharSequence text) {
715716
return this;
716717
}
717718

719+
/**
720+
* <div class="pt">Define o texto que sera exibido no <tt>TextView</tt> dentro do tooltip.</div>
721+
*
722+
* @param textRes <div class="pt">id do resource da String.</div>
723+
* @return this
724+
*/
725+
public Builder text(@StringRes int textRes) {
726+
this.text = context.getString(textRes);
727+
return this;
728+
}
729+
718730
/**
719731
* <div class="pt">Define para qual <tt>View</tt> o tooltip deve apontar. Importante ter certeza que esta <tt>View</tt> já esteja pronta e exibida na tela.</div>
720732
*

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ public void onShow(SimpleTooltip tooltip) {
9393
} else if (v.getId() == R.id.btn_simple) {
9494
new SimpleTooltip.Builder(this)
9595
.anchorView(v)
96-
.text(getString(R.string.btn_simple))
96+
.text(R.string.btn_simple)
9797
.gravity(Gravity.END)
9898
.build()
9999
.show();
100100

101101
} else if (v.getId() == R.id.btn_animated) {
102102
new SimpleTooltip.Builder(this)
103103
.anchorView(v)
104-
.text(getString(R.string.btn_animated))
104+
.text(R.string.btn_animated)
105105
.gravity(Gravity.TOP)
106106
.animated(true)
107107
.build()
@@ -110,7 +110,7 @@ public void onShow(SimpleTooltip tooltip) {
110110
} else if (v.getId() == R.id.btn_overlay) {
111111
new SimpleTooltip.Builder(this)
112112
.anchorView(v)
113-
.text(getString(R.string.btn_overlay))
113+
.text(R.string.btn_overlay)
114114
.gravity(Gravity.START)
115115
.animated(true)
116116
.transparentOverlay(false)
@@ -129,7 +129,7 @@ public void onShow(SimpleTooltip tooltip) {
129129
} else if (v.getId() == R.id.btn_outside) {
130130
new SimpleTooltip.Builder(this)
131131
.anchorView(v)
132-
.text(getString(R.string.btn_outside))
132+
.text(R.string.btn_outside)
133133
.gravity(Gravity.BOTTOM)
134134
.dismissOnOutsideTouch(true)
135135
.dismissOnInsideTouch(false)
@@ -139,7 +139,7 @@ public void onShow(SimpleTooltip tooltip) {
139139
} else if (v.getId() == R.id.btn_inside) {
140140
new SimpleTooltip.Builder(this)
141141
.anchorView(v)
142-
.text(getString(R.string.btn_inside))
142+
.text(R.string.btn_inside)
143143
.gravity(Gravity.START)
144144
.dismissOnOutsideTouch(false)
145145
.dismissOnInsideTouch(true)
@@ -149,7 +149,7 @@ public void onShow(SimpleTooltip tooltip) {
149149
} else if (v.getId() == R.id.btn_inside_modal) {
150150
new SimpleTooltip.Builder(this)
151151
.anchorView(v)
152-
.text(getString(R.string.btn_inside_modal))
152+
.text(R.string.btn_inside_modal)
153153
.gravity(Gravity.END)
154154
.dismissOnOutsideTouch(false)
155155
.dismissOnInsideTouch(true)
@@ -160,7 +160,7 @@ public void onShow(SimpleTooltip tooltip) {
160160
} else if (v.getId() == R.id.btn_modal_custom) {
161161
final SimpleTooltip tooltip = new SimpleTooltip.Builder(this)
162162
.anchorView(v)
163-
.text(getString(R.string.btn_modal_custom))
163+
.text(R.string.btn_modal_custom)
164164
.gravity(Gravity.TOP)
165165
.dismissOnOutsideTouch(false)
166166
.dismissOnInsideTouch(false)
@@ -178,7 +178,7 @@ public void onClick(View v2) {
178178
tooltip.dismiss();
179179
new SimpleTooltip.Builder(v.getContext())
180180
.anchorView(v)
181-
.text(getString(R.string.btn_next))
181+
.text(R.string.btn_next)
182182
.gravity(Gravity.BOTTOM)
183183
.build()
184184
.show();
@@ -189,7 +189,7 @@ public void onClick(View v2) {
189189
} else if (v.getId() == R.id.btn_no_arrow) {
190190
new SimpleTooltip.Builder(this)
191191
.anchorView(v)
192-
.text(getString(R.string.btn_no_arrow))
192+
.text(R.string.btn_no_arrow)
193193
.gravity(Gravity.START)
194194
.showArrow(false)
195195
.modal(true)
@@ -200,7 +200,7 @@ public void onClick(View v2) {
200200
} else if (v.getId() == R.id.btn_custom_arrow) {
201201
new SimpleTooltip.Builder(this)
202202
.anchorView(v)
203-
.text(getString(R.string.btn_custom_arrow))
203+
.text(R.string.btn_custom_arrow)
204204
.gravity(Gravity.END)
205205
.modal(true)
206206
.arrowDrawable(android.R.drawable.ic_media_previous)
@@ -226,7 +226,7 @@ public void onClick(View v2) {
226226
public void onClick(View v) {
227227
new SimpleTooltip.Builder(MainActivity.this)
228228
.anchorView(btnInDialog)
229-
.text(getString(R.string.btn_in_dialog))
229+
.text(R.string.btn_in_dialog)
230230
.gravity(Gravity.BOTTOM)
231231
.animated(true)
232232
.transparentOverlay(false)
@@ -244,7 +244,7 @@ public void onClick(View v) {
244244
} else if (v.getId() == R.id.btn_center) {
245245
new SimpleTooltip.Builder(this)
246246
.anchorView(v.getRootView())
247-
.text(getString(R.string.btn_center))
247+
.text(R.string.btn_center)
248248
.showArrow(false)
249249
.gravity(Gravity.CENTER)
250250
.build()

0 commit comments

Comments
 (0)