@@ -82,6 +82,7 @@ public class SimpleTooltip implements PopupWindow.OnDismissListener {
8282 private OnShowListener mOnShowListener ;
8383 private PopupWindow mPopupWindow ;
8484 private final int mGravity ;
85+ private final int mArrowDirection ;
8586 private final boolean mDismissOnInsideTouch ;
8687 private final boolean mDismissOnOutsideTouch ;
8788 private final boolean mModal ;
@@ -112,6 +113,7 @@ public class SimpleTooltip implements PopupWindow.OnDismissListener {
112113 private SimpleTooltip (Builder builder ) {
113114 mContext = builder .context ;
114115 mGravity = builder .gravity ;
116+ mArrowDirection = builder .arrowDirection ;
115117 mDismissOnInsideTouch = builder .dismissOnInsideTouch ;
116118 mDismissOnOutsideTouch = builder .dismissOnOutsideTouch ;
117119 mModal = builder .modal ;
@@ -227,23 +229,25 @@ private void configContentView() {
227229
228230 LinearLayout linearLayout = new LinearLayout (mContext );
229231 linearLayout .setLayoutParams (new ViewGroup .LayoutParams (ViewGroup .LayoutParams .WRAP_CONTENT , ViewGroup .LayoutParams .WRAP_CONTENT ));
230- linearLayout .setOrientation (mGravity == Gravity . START || mGravity == Gravity . END ? LinearLayout .HORIZONTAL : LinearLayout .VERTICAL );
232+ linearLayout .setOrientation (mArrowDirection == ArrowDrawable . LEFT || mArrowDirection == ArrowDrawable . RIGHT ? LinearLayout .HORIZONTAL : LinearLayout .VERTICAL );
231233 int layoutPadding = (int ) (mAnimated ? mAnimationPadding : 0 );
232234 linearLayout .setPadding (layoutPadding , layoutPadding , layoutPadding , layoutPadding );
233235
234236 if (mShowArrow ) {
235237 mArrowView = new ImageView (mContext );
236238 mArrowView .setImageDrawable (mArrowDrawable );
237239 LinearLayout .LayoutParams arrowLayoutParams ;
238- if (mGravity == Gravity .TOP || mGravity == Gravity .BOTTOM ) {
240+
241+ if (mArrowDirection == ArrowDrawable .TOP || mArrowDirection == ArrowDrawable .BOTTOM ) {
239242 arrowLayoutParams = new LinearLayout .LayoutParams ((int ) mArrowWidth , (int ) mArrowHeight , 0 );
240243 } else {
241244 arrowLayoutParams = new LinearLayout .LayoutParams ((int ) mArrowHeight , (int ) mArrowWidth , 0 );
242245 }
246+
243247 arrowLayoutParams .gravity = Gravity .CENTER ;
244248 mArrowView .setLayoutParams (arrowLayoutParams );
245249
246- if (mGravity == Gravity . TOP || mGravity == Gravity . START ) {
250+ if (mArrowDirection == ArrowDrawable . BOTTOM || mArrowDirection == ArrowDrawable . RIGHT ) {
247251 linearLayout .addView (mContentView );
248252 linearLayout .addView (mArrowView );
249253 } else {
@@ -388,7 +392,7 @@ public void onGlobalLayout() {
388392 RectF achorRect = SimpleTooltipUtils .calculeRectOnScreen (mAnchorView );
389393 RectF contentViewRect = SimpleTooltipUtils .calculeRectOnScreen (mContentLayout );
390394 float x , y ;
391- if (mGravity == Gravity . BOTTOM || mGravity == Gravity . TOP ) {
395+ if (mArrowDirection == ArrowDrawable . TOP || mArrowDirection == ArrowDrawable . BOTTOM ) {
392396 x = mContentLayout .getPaddingLeft () + SimpleTooltipUtils .pxFromDp (2 );
393397 float centerX = (contentViewRect .width () / 2f ) - (mArrowView .getWidth () / 2f );
394398 float newX = centerX - (contentViewRect .centerX () - achorRect .centerX ());
@@ -400,7 +404,7 @@ public void onGlobalLayout() {
400404 }
401405 }
402406 y = mArrowView .getTop ();
403- y = y + (mGravity == Gravity . TOP ? -1 : +1 );
407+ y = y + (mArrowDirection == ArrowDrawable . BOTTOM ? -1 : +1 );
404408 } else {
405409 y = mContentLayout .getPaddingTop () + SimpleTooltipUtils .pxFromDp (2 );
406410 float centerY = (contentViewRect .height () / 2f ) - (mArrowView .getHeight () / 2f );
@@ -413,7 +417,7 @@ public void onGlobalLayout() {
413417 }
414418 }
415419 x = mArrowView .getLeft ();
416- x = x + (mGravity == Gravity . START ? -1 : +1 );
420+ x = x + (mArrowDirection == ArrowDrawable . RIGHT ? -1 : +1 );
417421 }
418422 SimpleTooltipUtils .setX (mArrowView , (int ) x );
419423 SimpleTooltipUtils .setY (mArrowView , (int ) y );
@@ -519,6 +523,7 @@ public static class Builder {
519523 private int textViewId = android .R .id .text1 ;
520524 private CharSequence text = "" ;
521525 private View anchorView ;
526+ private int arrowDirection = ArrowDrawable .AUTO ;
522527 private int gravity = Gravity .BOTTOM ;
523528 private boolean transparentOverlay = true ;
524529 private float maxWidth ;
@@ -559,10 +564,6 @@ public SimpleTooltip build() throws IllegalArgumentException {
559564 if (arrowColor == 0 ) {
560565 arrowColor = SimpleTooltipUtils .getColor (context , mDefaultArrowColorRes );
561566 }
562- if (arrowDrawable == null ) {
563- int arrowDirection = SimpleTooltipUtils .tooltipGravityToArrowDirection (gravity );
564- arrowDrawable = new ArrowDrawable (arrowColor , arrowDirection );
565- }
566567 if (margin < 0 ) {
567568 margin = context .getResources ().getDimension (mDefaultMarginRes );
568569 }
@@ -579,6 +580,10 @@ public SimpleTooltip build() throws IllegalArgumentException {
579580 animated = false ;
580581 }
581582 if (showArrow ) {
583+ if (arrowDirection == ArrowDrawable .AUTO )
584+ arrowDirection = SimpleTooltipUtils .tooltipGravityToArrowDirection (gravity );
585+ if (arrowDrawable == null )
586+ arrowDrawable = new ArrowDrawable (arrowColor , arrowDirection );
582587 if (arrowWidth == 0 )
583588 arrowWidth = context .getResources ().getDimension (mDefaultArrowWidthRes );
584589 if (arrowHeight == 0 )
@@ -734,6 +739,20 @@ public Builder gravity(int gravity) {
734739 return this ;
735740 }
736741
742+ /**
743+ * <div class="pt">Define a direção em que a seta será criada.
744+ * As opções existentes são <tt>ArrowDrawable.LEFT</tt>, <tt>ArrowDrawable.TOP</tt>, <tt>ArrowDrawable.RIGHT</tt>, <tt>ArrowDrawable.BOTTOM</tt> e <tt>ArrowDrawable.AUTO</tt>.
745+ * O padrão é <tt>ArrowDrawable.AUTO</tt>. <br>
746+ * Esta opção deve ser utilizada em conjunto com <tt>Builder#showArrow(true)</tt>.</div>
747+ *
748+ * @param arrowDirection <div class="pt">direção em que a seta será criada.</div>
749+ * @return this
750+ */
751+ public Builder arrowDirection (int arrowDirection ) {
752+ this .arrowDirection = arrowDirection ;
753+ return this ;
754+ }
755+
737756 /**
738757 * <div class="pt">Define se o fundo da tela será escurecido ou transparente enquanto o tooltip estiver aberto. Padrão é <tt>true</tt>.</div>
739758 *
0 commit comments