diff --git a/res/layout/arrow_toast.xml b/res/layout/arrow_toast.xml index 2c97e8954b..0ec9981220 100644 --- a/res/layout/arrow_toast.xml +++ b/res/layout/arrow_toast.xml @@ -60,6 +60,5 @@ android:elevation="2dp" android:layout_width="10dp" android:layout_height="8dp" - android:layout_marginTop="-2dp" - android:layout_gravity="center_horizontal"/> + android:layout_marginTop="-2dp"/> diff --git a/src/com/android/launcher3/views/ArrowTipView.java b/src/com/android/launcher3/views/ArrowTipView.java index a7575d12ba..b4a6b141ce 100644 --- a/src/com/android/launcher3/views/ArrowTipView.java +++ b/src/com/android/launcher3/views/ArrowTipView.java @@ -125,11 +125,35 @@ public class ArrowTipView extends AbstractFloatingView { * Show Tip with specified string and Y location */ public ArrowTipView show(String text, int top) { + return show(text, Gravity.CENTER_HORIZONTAL, 0, top); + } + + /** + * Show the ArrowTipView (tooltip) center, start, or end aligned. + * + * @param text The text to be shown in the tooltip. + * @param gravity The gravity aligns the tooltip center, start, or end. + * @param arrowMarginStart The margin from start to place arrow (ignored if center) + * @param top The Y coordinate of the bottom of tooltip. + * @return The tooltip. + */ + public ArrowTipView show(String text, int gravity, int arrowMarginStart, int top) { ((TextView) findViewById(R.id.text)).setText(text); - mActivity.getDragLayer().addView(this); + ViewGroup parent = mActivity.getDragLayer(); + parent.addView(this); DragLayer.LayoutParams params = (DragLayer.LayoutParams) getLayoutParams(); - params.gravity = Gravity.CENTER_HORIZONTAL; + params.gravity = gravity; + LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) findViewById( + R.id.arrow).getLayoutParams(); + lp.gravity = gravity; + if (gravity == Gravity.END) { + lp.setMarginEnd(parent.getMeasuredWidth() - arrowMarginStart); + } else if (gravity == Gravity.START) { + lp.setMarginStart(arrowMarginStart); + } + requestLayout(); + params.leftMargin = mActivity.getDeviceProfile().workspacePadding.left; params.rightMargin = mActivity.getDeviceProfile().workspacePadding.right; post(() -> setY(top - getHeight()));