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

Commit 464509b3 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Merging widget item click listener to default click listener

> Also removing check for dragHandle, since dragHandle is already removed

Bug: 307306823
Test: atest Launcher3Tests
Flag: N/A
Change-Id: I0b452dd1fbccf15ed686370471e8866b179fd77e
parent eb293135
Loading
Loading
Loading
Loading

res/drawable/ic_drag_handle.xml

deleted100644 → 0
+0 −27
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2016 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="@dimen/deep_shortcut_drag_handle_size"
        android:height="@dimen/deep_shortcut_drag_handle_size"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0"
        android:tint="?android:attr/textColorPrimary" >

    <path
        android:pathData="M20,9H4v2h16V9z M4,15h16v-2H4V15z"
        android:fillColor="@android:color/white" />
</vector>
 No newline at end of file
+0 −1
Original line number Diff line number Diff line
@@ -290,7 +290,6 @@
    <dimen name="popup_single_item_radius">100dp</dimen>
    <dimen name="popup_smaller_radius">4dp</dimen>
    <dimen name="deep_shortcut_drawable_padding">16dp</dimen>
    <dimen name="deep_shortcut_drag_handle_size">16dp</dimen>
    <dimen name="popup_padding_start">10dp</dimen>
    <dimen name="popup_padding_end">14dp</dimen>
    <dimen name="popup_vertical_padding">4dp</dimen>
+2 −43
Original line number Diff line number Diff line
@@ -17,13 +17,11 @@
package com.android.launcher3.shortcuts;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.Toast;

import com.android.launcher3.BubbleTextView;
import com.android.launcher3.R;
@@ -33,11 +31,6 @@ import com.android.launcher3.Utilities;
 * A {@link BubbleTextView} that has the shortcut icon on the left and drag handle on the right.
 */
public class DeepShortcutTextView extends BubbleTextView {
    private final Rect mDragHandleBounds = new Rect();
    private final int mDragHandleWidth;
    private boolean mShowInstructionToast = false;

    private Toast mInstructionToast;

    private boolean mShowLoadingState;
    private Drawable mLoadingStatePlaceholder;
@@ -53,23 +46,12 @@ public class DeepShortcutTextView extends BubbleTextView {

    public DeepShortcutTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);

        Resources resources = getResources();
        mDragHandleWidth = resources.getDimensionPixelSize(R.dimen.popup_padding_end)
                + resources.getDimensionPixelSize(R.dimen.deep_shortcut_drag_handle_size)
                + resources.getDimensionPixelSize(R.dimen.deep_shortcut_drawable_padding) / 2;
        showLoadingState(true);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        mDragHandleBounds.set(0, 0, mDragHandleWidth, getMeasuredHeight());
        if (!Utilities.isRtl(getResources())) {
            mDragHandleBounds.offset(getMeasuredWidth() - mDragHandleBounds.width(), 0);
        }

        setLoadingBounds();
    }

@@ -80,10 +62,10 @@ public class DeepShortcutTextView extends BubbleTextView {
        mLoadingStateBounds.set(
                0,
                0,
                getMeasuredWidth() - mDragHandleWidth - getPaddingStart(),
                getMeasuredWidth() - getPaddingEnd() - getPaddingStart(),
                mLoadingStatePlaceholder.getIntrinsicHeight());
        mLoadingStateBounds.offset(
                Utilities.isRtl(getResources()) ? mDragHandleWidth : getPaddingStart(),
                Utilities.isRtl(getResources()) ? getPaddingEnd() : getPaddingStart(),
                (int) ((getMeasuredHeight() - mLoadingStatePlaceholder.getIntrinsicHeight())
                        / 2.0f)
        );
@@ -106,22 +88,10 @@ public class DeepShortcutTextView extends BubbleTextView {

    @Override
    protected boolean shouldIgnoreTouchDown(float x, float y) {
        // Show toast if user touches the drag handle (long clicks still start the drag).
        mShowInstructionToast = mDragHandleBounds.contains((int) x, (int) y);

        // assume the whole view as clickable
        return false;
    }

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

    @Override
    public void onDraw(Canvas canvas) {
        if (!mShowLoadingState) {
@@ -155,15 +125,4 @@ public class DeepShortcutTextView extends BubbleTextView {

        invalidate();
    }

    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();
    }
}
+13 −0
Original line number Diff line number Diff line
@@ -61,7 +61,10 @@ import com.android.launcher3.testing.shared.TestProtocol;
import com.android.launcher3.util.ItemInfoMatcher;
import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.views.FloatingIconView;
import com.android.launcher3.views.Snackbar;
import com.android.launcher3.widget.LauncherAppWidgetProviderInfo;
import com.android.launcher3.widget.PendingAddShortcutInfo;
import com.android.launcher3.widget.PendingAddWidgetInfo;
import com.android.launcher3.widget.PendingAppWidgetHostView;
import com.android.launcher3.widget.WidgetAddFlowHandler;
import com.android.launcher3.widget.WidgetManagerHelper;
@@ -107,6 +110,16 @@ public class ItemClickHandler {
            }
        } else if (tag instanceof ItemClickProxy) {
            ((ItemClickProxy) tag).onItemClicked(v);
        } else if (tag instanceof PendingAddShortcutInfo) {
            CharSequence msg = Utilities.wrapForTts(
                    launcher.getText(R.string.long_press_shortcut_to_add),
                    launcher.getString(R.string.long_accessible_way_to_add_shortcut));
            Snackbar.show(launcher, msg, null);
        } else if (tag instanceof PendingAddWidgetInfo) {
            CharSequence msg = Utilities.wrapForTts(
                    launcher.getText(R.string.long_press_widget_to_add),
                    launcher.getString(R.string.long_accessible_way_to_add));
            Snackbar.show(launcher, msg, null);
        }
    }

+9 −8
Original line number Diff line number Diff line
@@ -66,8 +66,8 @@ public class Snackbar extends AbstractFloatingView {
    }

    /** Show a snackbar with just a label. */
    public static <T extends Context & ActivityContext> void show(T activity, String labelString,
            Runnable onDismissed) {
    public static void show(
            ActivityContext activity, CharSequence labelString, Runnable onDismissed) {
        show(activity, labelString, NO_ID, onDismissed, null);
    }

@@ -76,21 +76,21 @@ public class Snackbar extends AbstractFloatingView {
            int actionStringResId, Runnable onDismissed, @Nullable Runnable onActionClicked) {
        show(
                activity,
                activity.getResources().getString(labelStringResId),
                activity.getResources().getText(labelStringResId),
                actionStringResId,
                onDismissed,
                onActionClicked);
    }

    /** Show a snackbar with a label and action. */
    public static <T extends Context & ActivityContext> void show(T activity, String labelString,
    public static void show(ActivityContext activity, CharSequence labelString,
            int actionStringResId, Runnable onDismissed, @Nullable Runnable onActionClicked) {
        closeOpenViews(activity, true, TYPE_SNACKBAR);
        Snackbar snackbar = new Snackbar(activity, null);
        Snackbar snackbar = new Snackbar((Context) activity, null);
        // Set some properties here since inflated xml only contains the children.
        snackbar.setOrientation(HORIZONTAL);
        snackbar.setGravity(Gravity.CENTER_VERTICAL);
        Resources res = activity.getResources();
        Resources res = snackbar.getResources();
        snackbar.setElevation(res.getDimension(R.dimen.snackbar_elevation));
        int padding = res.getDimensionPixelSize(R.dimen.snackbar_padding);
        snackbar.setPadding(padding, padding, padding, padding);
@@ -143,7 +143,8 @@ public class Snackbar extends AbstractFloatingView {
            actionView.setVisibility(GONE);
        }

        int totalContentWidth = (int) (labelView.getPaint().measureText(labelString) + actionWidth)
        int totalContentWidth = (int) (labelView.getPaint().measureText(labelString.toString())
                    + actionWidth)
                + labelView.getPaddingRight() + labelView.getPaddingLeft()
                + padding * 2;
        if (totalContentWidth > params.width) {
@@ -177,7 +178,7 @@ public class Snackbar extends AbstractFloatingView {
                .setDuration(SHOW_DURATION_MS)
                .setInterpolator(Interpolators.ACCELERATE_DECELERATE)
                .start();
        int timeout = AccessibilityManagerCompat.getRecommendedTimeoutMillis(activity,
        int timeout = AccessibilityManagerCompat.getRecommendedTimeoutMillis(snackbar.getContext(),
                TIMEOUT_DURATION_MS, FLAG_CONTENT_TEXT | FLAG_CONTENT_CONTROLS);
        snackbar.postDelayed(() -> snackbar.close(true), timeout);
    }
Loading