1919import android .content .Context ;
2020import android .graphics .Typeface ;
2121import android .support .annotation .IntDef ;
22+ import android .support .annotation .NonNull ;
2223import android .support .annotation .Nullable ;
2324import android .support .annotation .StyleRes ;
24- import android .text .Spannable ;
2525import android .view .View ;
2626import android .view .ViewGroup ;
2727
@@ -51,10 +51,10 @@ public class ToolTip {
5151 public static final int GRAVITY_LEFT = 1 ;
5252 public static final int GRAVITY_RIGHT = 2 ;
5353
54- private Context mContext ;
55- private View mAnchorView ;
56- private ViewGroup mRootViewGroup ;
57- private String mMessage ;
54+ private @ NonNull Context mContext ;
55+ private @ NonNull View mAnchorView ;
56+ private @ NonNull ViewGroup mRootViewGroup ;
57+ private @ NonNull CharSequence mMessage ;
5858 private @ Position int mPosition ;
5959 private @ Align int mAlign ;
6060 private int mOffsetX ;
@@ -63,9 +63,8 @@ public class ToolTip {
6363 private int mBackgroundColor ;
6464 private float mElevation ;
6565 private @ Gravity int mTextGravity ;
66- private Spannable mSpannableMessage ;
6766 private @ StyleRes int mTextAppearanceStyle ;
68- private Typeface mTypeface ;
67+ private @ Nullable Typeface mTypeface ;
6968
7069 public ToolTip (Builder builder ){
7170 mContext = builder .mContext ;
@@ -81,24 +80,27 @@ public ToolTip(Builder builder){
8180 mBackgroundColor = builder .mBackgroundColor ;
8281 mElevation = builder .mElevation ;
8382 mTextGravity = builder .mTextGravity ;
84- mSpannableMessage = builder .mSpannableMessage ;
8583 mTextAppearanceStyle = builder .mTextAppearanceStyle ;
8684 mTypeface = builder .mTypeface ;
8785 }
8886
87+ @ NonNull
8988 public Context getContext () {
9089 return mContext ;
9190 }
9291
92+ @ NonNull
9393 public View getAnchorView () {
9494 return mAnchorView ;
9595 }
9696
97+ @ NonNull
9798 public ViewGroup getRootView () {
9899 return mRootViewGroup ;
99100 }
100101
101- public String getMessage () {
102+ @ NonNull
103+ public CharSequence getMessage () {
102104 return mMessage ;
103105 }
104106
@@ -172,6 +174,7 @@ public Typeface getTypeface() {
172174 return mTypeface ;
173175 }
174176
177+ @ NonNull
175178 public int getTextGravity (){
176179 int gravity ;
177180 switch (mTextGravity ){
@@ -190,15 +193,11 @@ public int getTextGravity(){
190193 return gravity ;
191194 }
192195
193- public Spannable getSpannableMessage () {
194- return mSpannableMessage ;
195- }
196-
197196 public static class Builder {
198- private Context mContext ;
199- private View mAnchorView ;
200- private ViewGroup mRootViewGroup ;
201- private String mMessage ;
197+ private @ NonNull Context mContext ;
198+ private @ NonNull View mAnchorView ;
199+ private @ NonNull ViewGroup mRootViewGroup ;
200+ private @ NonNull CharSequence mMessage ;
202201 private @ Position int mPosition ;
203202 private @ Align int mAlign ;
204203 private int mOffsetX ;
@@ -207,48 +206,28 @@ public static class Builder {
207206 private int mBackgroundColor ;
208207 private float mElevation ;
209208 private @ Gravity int mTextGravity ;
210- private Spannable mSpannableMessage ;
211209 private @ StyleRes int mTextAppearanceStyle ;
212- private Typeface mTypeface ;
210+ private @ Nullable Typeface mTypeface ;
213211
214212
215213 /**
214+ * Creates the tooltip builder with message and required parameters to show tooltip.
216215 *
217216 * @param context context
218217 * @param anchorView the view which near it we want to put the tip
219218 * @param root a class extends ViewGroup which the created tip view will be added to
220- * @param message message to show
221- * @param position put the tip above / below / left to / right to
219+ * @param message message to show. Note: This allows normal text and spannable text with spanned styles.
220+ * @param position put the tip above / below / left to / right to anchor view.
222221 */
223- public Builder (Context context , View anchorView , ViewGroup root , String message , @ Position int position ){
222+ public Builder (@ NonNull Context context ,
223+ @ NonNull View anchorView ,
224+ @ NonNull ViewGroup root ,
225+ @ NonNull CharSequence message ,
226+ @ Position int position ) {
224227 mContext = context ;
225228 mAnchorView = anchorView ;
226229 mRootViewGroup = root ;
227230 mMessage = message ;
228- mSpannableMessage = null ;
229- mPosition = position ;
230- mAlign = ALIGN_CENTER ;
231- mOffsetX = 0 ;
232- mOffsetY = 0 ;
233- mArrow = true ;
234- mBackgroundColor = context .getResources ().getColor (R .color .colorBackground );
235- mTextGravity = GRAVITY_LEFT ;
236- mTextAppearanceStyle = R .style .TooltipDefaultStyle ;
237- }
238-
239- /**
240- * @param context context
241- * @param anchorView the view which near it we want to put the tip
242- * @param root a class extends ViewGroup which the created tip view will be added to
243- * @param message spannable message to show
244- * @param position put the tip above / below / left to / right to
245- */
246- public Builder (Context context , View anchorView , ViewGroup root , Spannable message , @ Position int position ) {
247- mContext = context ;
248- mAnchorView = anchorView ;
249- mRootViewGroup = root ;
250- mMessage = null ;
251- mSpannableMessage = message ;
252231 mPosition = position ;
253232 mAlign = ALIGN_CENTER ;
254233 mOffsetX = 0 ;
@@ -259,11 +238,13 @@ public Builder(Context context, View anchorView, ViewGroup root, Spannable messa
259238 mTextAppearanceStyle = R .style .TooltipDefaultStyle ;
260239 }
261240
241+ @ NonNull
262242 public Builder setPosition (@ Position int position ){
263243 mPosition = position ;
264244 return this ;
265245 }
266246
247+ @ NonNull
267248 public Builder setAlign (@ Align int align ){
268249 mAlign = align ;
269250 return this ;
@@ -273,6 +254,7 @@ public Builder setAlign(@Align int align){
273254 * @param offset offset to move the tip on x axis after tip was positioned
274255 * @return offset
275256 */
257+ @ NonNull
276258 public Builder setOffsetX (int offset ){
277259 mOffsetX = offset ;
278260 return this ;
@@ -282,41 +264,49 @@ public Builder setOffsetX(int offset){
282264 * @param offset offset to move the tip on y axis after tip was positioned
283265 * @return offset
284266 */
267+ @ NonNull
285268 public Builder setOffsetY (int offset ){
286269 mOffsetY = offset ;
287270 return this ;
288271 }
289272
273+ @ NonNull
290274 public Builder withArrow (boolean value ){
291275 mArrow = value ;
292276 return this ;
293277 }
294278
279+ @ NonNull
295280 public Builder setBackgroundColor (int color ){
296281 mBackgroundColor = color ;
297282 return this ;
298283 }
299284
285+ @ NonNull
300286 public Builder setElevation (float elevation ){
301287 mElevation = elevation ;
302288 return this ;
303289 }
304290
291+ @ NonNull
305292 public Builder setGravity (@ Gravity int gravity ){
306293 mTextGravity = gravity ;
307294 return this ;
308295 }
309296
297+ @ NonNull
310298 public Builder setTextAppearance (@ StyleRes int textAppearance ) {
311299 mTextAppearanceStyle = textAppearance ;
312300 return this ;
313301 }
314302
315- public Builder setTypeface (Typeface typeface ) {
303+ @ NonNull
304+ public Builder setTypeface (@ NonNull Typeface typeface ) {
316305 mTypeface = typeface ;
317306 return this ;
318307 }
319308
309+ @ NonNull
320310 public ToolTip build (){
321311 return new ToolTip (this );
322312 }
0 commit comments