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

Commit 3ef27689 authored by Sunny Goyal's avatar Sunny Goyal Committed by Android (Google) Code Review
Browse files

Merge "Simplyfing SystemShortcut rendering" into main

parents 7eceb5b1 9f226dff
Loading
Loading
Loading
Loading
+33 −2
Original line number Diff line number Diff line
@@ -31,6 +31,8 @@ import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.core.content.FileProvider;
@@ -45,6 +47,9 @@ import com.android.launcher3.popup.SystemShortcut;
import com.android.launcher3.views.ActivityContext;

import java.io.File;
import java.util.Collections;
import java.util.Set;
import java.util.WeakHashMap;

/**
 * Defines the Share system shortcut and its factory.
@@ -112,6 +117,9 @@ public final class AppSharing {
        private final PopupDataProvider mPopupDataProvider;
        private final boolean mSharingEnabledForUser;

        private final Set<View> mBoundViews = Collections.newSetFromMap(new WeakHashMap<>());
        private boolean mIsEnabled = true;

        public Share(Launcher target, ItemInfo itemInfo, View originalView) {
            super(R.drawable.ic_share, R.string.app_share_drop_target_label, target, itemInfo,
                    originalView);
@@ -127,11 +135,24 @@ public final class AppSharing {
            }
        }

        @Override
        public void setIconAndLabelFor(View iconView, TextView labelView) {
            super.setIconAndLabelFor(iconView, labelView);
            mBoundViews.add(iconView);
            mBoundViews.add(labelView);
        }

        @Override
        public void setIconAndContentDescriptionFor(ImageView view) {
            super.setIconAndContentDescriptionFor(view);
            mBoundViews.add(view);
        }

        @Override
        public void onClick(View view) {
            ActivityContext.lookupContext(view.getContext())
                    .getStatsLogManager().logger().log(LAUNCHER_SYSTEM_SHORTCUT_APP_SHARE_TAP);
            if (!isEnabled()) {
            if (!mIsEnabled) {
                showCannotShareToast(view.getContext());
                return;
            }
@@ -179,7 +200,6 @@ public final class AppSharing {
                return;
            }
            checkShareability(/* requestUpdateIfUnknown */ false);
            mTarget.runOnUiThread(mPopupDataProvider::redrawSystemShortcuts);
        }

        private void checkShareability(boolean requestUpdateIfUnknown) {
@@ -209,6 +229,17 @@ public final class AppSharing {
            int duration = Toast.LENGTH_SHORT;
            Toast.makeText(context, text, duration).show();
        }

        public void setEnabled(boolean isEnabled) {
            if (mIsEnabled != isEnabled) {
                mIsEnabled = isEnabled;
                mBoundViews.forEach(v -> v.setEnabled(isEnabled));
            }
        }

        public boolean isEnabled() {
            return mIsEnabled;
        }
    }

    /**
+0 −8
Original line number Diff line number Diff line
@@ -40,7 +40,6 @@ import com.android.launcher3.model.data.WorkspaceItemInfo;
import com.android.launcher3.notification.NotificationListener;
import com.android.launcher3.popup.PopupContainerWithArrow;
import com.android.launcher3.popup.PopupDataProvider;
import com.android.launcher3.popup.PopupLiveUpdateHandler;
import com.android.launcher3.popup.SystemShortcut;
import com.android.launcher3.shortcuts.DeepShortcutView;
import com.android.launcher3.splitscreen.SplitShortcut;
@@ -166,13 +165,6 @@ public class TaskbarPopupController implements TaskbarControllers.LoggableTaskba
                    R.layout.popup_container, context.getDragLayer(), false);
        container.populateAndShowRows(icon, deepShortcutCount, systemShortcuts);

        container.addOnAttachStateChangeListener(
                new PopupLiveUpdateHandler<BaseTaskbarContext>(context, container) {
                    @Override
                    protected void showPopupContainerForIcon(BubbleTextView originalIcon) {
                        showForIcon(originalIcon);
                    }
                });
        // TODO (b/198438631): configure for taskbar/context
        container.setPopupItemDragHandler(new TaskbarPopupItemDragHandler());
        mControllers.taskbarDragController.addDragListener(container);
+0 −5
Original line number Diff line number Diff line
@@ -87,9 +87,4 @@ public class LauncherPopupLiveUpdateHandler extends PopupLiveUpdateHandler<Launc
            }
        }
    }

    @Override
    protected void showPopupContainerForIcon(BubbleTextView originalIcon) {
        PopupContainerWithArrow.showForIcon(originalIcon);
    }
}
+0 −10
Original line number Diff line number Diff line
@@ -241,13 +241,6 @@ public class PopupDataProvider implements NotificationListener.NotificationsChan
        writer.println(prefix + "\tmPackageUserToDotInfos:" + mPackageUserToDotInfos);
    }

    /**
     * Tells the listener that the system shortcuts have been updated, causing them to be redrawn.
     */
    public void redrawSystemShortcuts() {
        mChangeListener.onSystemShortcutsUpdated();
    }

    public interface PopupDataChangeListener {

        PopupDataChangeListener INSTANCE = new PopupDataChangeListener() { };
@@ -256,8 +249,5 @@ public class PopupDataProvider implements NotificationListener.NotificationsChan

        /** A callback to get notified when recommended widgets are bound. */
        default void onRecommendedWidgetsBound() { }

        /** A callback to get notified when system shortcuts have been updated. */
        default void onSystemShortcutsUpdated() { }
    }
}
+0 −9
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.launcher3.popup;
import android.content.Context;
import android.view.View;

import com.android.launcher3.BubbleTextView;
import com.android.launcher3.views.ActivityContext;

/**
@@ -56,12 +55,4 @@ public abstract class PopupLiveUpdateHandler<T extends Context & ActivityContext
            popupDataProvider.setChangeListener(null);
        }
    }

    @Override
    public void onSystemShortcutsUpdated() {
        mPopupContainerWithArrow.close(true);
        showPopupContainerForIcon(mPopupContainerWithArrow.getOriginalIcon());
    }

    protected abstract void showPopupContainerForIcon(BubbleTextView originalIcon);
}
Loading