Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a589814d authored by Jon Miranda's avatar Jon Miranda
Browse files

Show instruction toast when user taps on drag handle.

Bug: 74369785
Change-Id: I7017266efcb0db70a8d151eed10442292cb61e70
parent f6a8f955
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -72,6 +72,11 @@
    <string name="notifications_header">Notifications</string>

    <!-- Drag and drop -->
    <!-- Message to tell the user to press and hold on a shortcut to add it [CHAR_LIMIT=50] -->
    <string name="long_press_shortcut_to_add">Touch &amp; hold to pick up a shortcut.</string>
    <!-- Accessibility spoken hint message in deep shortcut menu, which allows user to add a shortcut. Custom action is the label for additional accessibility actions available in this mode [CHAR_LIMIT=100] -->
    <string name="long_accessible_way_to_add_shortcut">Double-tap &amp; hold to pick up a shortcut or use custom actions.</string>

    <skip />
    <!-- Error message when user has filled a home screen -->
    <string name="out_of_space">No more room on this Home screen.</string>
+22 −4
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.Toast;

import com.android.launcher3.BubbleTextView;
import com.android.launcher3.R;
@@ -33,7 +34,9 @@ import com.android.launcher3.Utilities;
public class DeepShortcutTextView extends BubbleTextView {
    private final Rect mDragHandleBounds = new Rect();
    private final int mDragHandleWidth;
    private boolean mShouldPerformClick = true;
    private boolean mShowInstructionToast = false;

    private Toast mInstructionToast;

    public DeepShortcutTextView(Context context) {
        this(context, null, 0);
@@ -70,14 +73,29 @@ public class DeepShortcutTextView extends BubbleTextView {
    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
            // Ignore clicks on the drag handle (long clicks still start the drag).
            mShouldPerformClick = !mDragHandleBounds.contains((int) ev.getX(), (int) ev.getY());
            // Show toast if user touches the drag handle (long clicks still start the drag).
            mShowInstructionToast = mDragHandleBounds.contains((int) ev.getX(), (int) ev.getY());
        }
        return super.onTouchEvent(ev);
    }

    @Override
    public boolean performClick() {
        return mShouldPerformClick && super.performClick();
        if (mShowInstructionToast) {
            showToast();
            return true;
        }
        return super.performClick();
    }

    private void showToast() {
        if (mInstructionToast != null) {
            mInstructionToast.cancel();
        }
        CharSequence msg = Utilities.wrapForTts(
                getContext().getText(R.string.long_press_shortcut_to_add),
                getContext().getString(R.string.long_accessible_way_to_add_shortcut));
        mInstructionToast = Toast.makeText(getContext(), msg, Toast.LENGTH_SHORT);
        mInstructionToast.show();
    }
}