Search in sources :

Example 11 with Folder

use of com.android.launcher3.tapl.Folder in project android_packages_apps_Launcher3 by crdroidandroid.

the class Folder method onFocusChange.

@Override
public void onFocusChange(View v, boolean hasFocus) {
    if (v == mFolderName) {
        if (hasFocus) {
            mFromLabelState = mInfo.getFromLabelState();
            mFromTitle = mInfo.title;
            startEditingFolderName();
        } else {
            StatsLogger statsLogger = mStatsLogManager.logger().withItemInfo(mInfo).withFromState(mFromLabelState);
            // If the folder label is suggested, it is logged to improve prediction model.
            // When both old and new labels are logged together delimiter is used.
            StringJoiner labelInfoBuilder = new StringJoiner(FOLDER_LABEL_DELIMITER);
            if (mFromLabelState.equals(FromState.FROM_SUGGESTED)) {
                labelInfoBuilder.add(mFromTitle);
            }
            ToState toLabelState;
            if (mFromTitle != null && mFromTitle.equals(mInfo.title)) {
                toLabelState = ToState.UNCHANGED;
            } else {
                toLabelState = mInfo.getToLabelState();
                if (toLabelState.toString().startsWith("TO_SUGGESTION")) {
                    labelInfoBuilder.add(mInfo.title);
                }
            }
            statsLogger.withToState(toLabelState);
            if (labelInfoBuilder.length() > 0) {
                statsLogger.withEditText(labelInfoBuilder.toString());
            }
            statsLogger.log(LAUNCHER_FOLDER_LABEL_UPDATED);
            mFolderName.dispatchBackKey();
        }
    }
}
Also used : StatsLogger(com.android.launcher3.logging.StatsLogManager.StatsLogger) ToState(com.android.launcher3.logger.LauncherAtom.ToState) StringJoiner(java.util.StringJoiner)

Example 12 with Folder

use of com.android.launcher3.tapl.Folder in project android_packages_apps_Launcher3 by crdroidandroid.

the class DragLayer method onInterceptHoverEvent.

@Override
public boolean onInterceptHoverEvent(MotionEvent ev) {
    if (mActivity == null || mActivity.getWorkspace() == null) {
        return false;
    }
    AbstractFloatingView topView = AbstractFloatingView.getTopOpenView(mActivity);
    if (!(topView instanceof Folder)) {
        return false;
    } else {
        AccessibilityManager accessibilityManager = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
        if (accessibilityManager.isTouchExplorationEnabled()) {
            Folder currentFolder = (Folder) topView;
            final int action = ev.getAction();
            boolean isOverFolderOrSearchBar;
            switch(action) {
                case MotionEvent.ACTION_HOVER_ENTER:
                    isOverFolderOrSearchBar = isEventOverView(topView, ev) || isEventOverAccessibleDropTargetBar(ev);
                    if (!isOverFolderOrSearchBar) {
                        sendTapOutsideFolderAccessibilityEvent(currentFolder.isEditingName());
                        mHoverPointClosesFolder = true;
                        return true;
                    }
                    mHoverPointClosesFolder = false;
                    break;
                case MotionEvent.ACTION_HOVER_MOVE:
                    isOverFolderOrSearchBar = isEventOverView(topView, ev) || isEventOverAccessibleDropTargetBar(ev);
                    if (!isOverFolderOrSearchBar && !mHoverPointClosesFolder) {
                        sendTapOutsideFolderAccessibilityEvent(currentFolder.isEditingName());
                        mHoverPointClosesFolder = true;
                        return true;
                    } else if (!isOverFolderOrSearchBar) {
                        return true;
                    }
                    mHoverPointClosesFolder = false;
            }
        }
    }
    return false;
}
Also used : AccessibilityManager(android.view.accessibility.AccessibilityManager) Folder(com.android.launcher3.folder.Folder) AbstractFloatingView(com.android.launcher3.AbstractFloatingView)

Example 13 with Folder

use of com.android.launcher3.tapl.Folder in project android_packages_apps_Launcher3 by crdroidandroid.

the class DragView method setItemInfo.

/**
 * Initialize {@code #mIconDrawable} if the item can be represented using
 * an {@link AdaptiveIconDrawable} or {@link FolderAdaptiveIcon}.
 */
@TargetApi(Build.VERSION_CODES.O)
public void setItemInfo(final ItemInfo info) {
    if (info.itemType != LauncherSettings.Favorites.ITEM_TYPE_APPLICATION && info.itemType != LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT && info.itemType != LauncherSettings.Favorites.ITEM_TYPE_FOLDER) {
        return;
    }
    // Load the adaptive icon on a background thread and add the view in ui thread.
    MODEL_EXECUTOR.getHandler().postAtFrontOfQueue(() -> {
        Object[] outObj = new Object[1];
        int w = mWidth;
        int h = mHeight;
        Drawable dr = Utilities.getFullDrawable(mLauncher, info, w, h, outObj);
        if (dr instanceof AdaptiveIconDrawable) {
            int blurMargin = (int) mLauncher.getResources().getDimension(R.dimen.blur_size_medium_outline) / 2;
            Rect bounds = new Rect(0, 0, w, h);
            bounds.inset(blurMargin, blurMargin);
            // Badge is applied after icon normalization so the bounds for badge should not
            // be scaled down due to icon normalization.
            Rect badgeBounds = new Rect(bounds);
            mBadge = getBadge(mLauncher, info, outObj[0]);
            mBadge.setBounds(badgeBounds);
            // Do not draw the background in case of folder as its translucent
            final boolean shouldDrawBackground = !(dr instanceof FolderAdaptiveIcon);
            try (LauncherIcons li = LauncherIcons.obtain(mLauncher)) {
                // drawable to be normalized
                Drawable nDr;
                if (shouldDrawBackground) {
                    nDr = dr;
                } else {
                    // Since we just want the scale, avoid heavy drawing operations
                    nDr = new AdaptiveIconDrawable(new ColorDrawable(Color.BLACK), null);
                }
                Utilities.scaleRectAboutCenter(bounds, li.getNormalizer().getScale(nDr, null, null, null));
            }
            AdaptiveIconDrawable adaptiveIcon = (AdaptiveIconDrawable) dr;
            // Shrink very tiny bit so that the clip path is smaller than the original bitmap
            // that has anti aliased edges and shadows.
            Rect shrunkBounds = new Rect(bounds);
            Utilities.scaleRectAboutCenter(shrunkBounds, 0.98f);
            adaptiveIcon.setBounds(shrunkBounds);
            final Path mask = adaptiveIcon.getIconMask();
            mTranslateX = new SpringFloatValue(DragView.this, w * AdaptiveIconDrawable.getExtraInsetFraction());
            mTranslateY = new SpringFloatValue(DragView.this, h * AdaptiveIconDrawable.getExtraInsetFraction());
            bounds.inset((int) (-bounds.width() * AdaptiveIconDrawable.getExtraInsetFraction()), (int) (-bounds.height() * AdaptiveIconDrawable.getExtraInsetFraction()));
            mBgSpringDrawable = adaptiveIcon.getBackground();
            if (mBgSpringDrawable == null) {
                mBgSpringDrawable = new ColorDrawable(Color.TRANSPARENT);
            }
            mBgSpringDrawable.setBounds(bounds);
            mFgSpringDrawable = adaptiveIcon.getForeground();
            if (mFgSpringDrawable == null) {
                mFgSpringDrawable = new ColorDrawable(Color.TRANSPARENT);
            }
            mFgSpringDrawable.setBounds(bounds);
            new Handler(Looper.getMainLooper()).post(() -> mOnDragStartCallback.add(() -> {
                // TODO: Consider fade-in animation
                // Assign the variable on the UI thread to avoid race conditions.
                mScaledMaskPath = mask;
                // Avoid relayout as we do not care about children affecting layout
                removeAllViewsInLayout();
                if (info.isDisabled()) {
                    FastBitmapDrawable d = new FastBitmapDrawable((Bitmap) null);
                    d.setIsDisabled(true);
                    mBgSpringDrawable.setColorFilter(d.getColorFilter());
                    mFgSpringDrawable.setColorFilter(d.getColorFilter());
                    mBadge.setColorFilter(d.getColorFilter());
                }
                invalidate();
            }));
        }
    });
}
Also used : Path(android.graphics.Path) Rect(android.graphics.Rect) AdaptiveIconDrawable(android.graphics.drawable.AdaptiveIconDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) PictureDrawable(android.graphics.drawable.PictureDrawable) Handler(android.os.Handler) Point(android.graphics.Point) FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) Bitmap(android.graphics.Bitmap) ColorDrawable(android.graphics.drawable.ColorDrawable) LauncherIcons(com.android.launcher3.icons.LauncherIcons) AdaptiveIconDrawable(android.graphics.drawable.AdaptiveIconDrawable) TargetApi(android.annotation.TargetApi)

Example 14 with Folder

use of com.android.launcher3.tapl.Folder in project android_packages_apps_Launcher3 by crdroidandroid.

the class BgDataModel method removeItem.

public synchronized void removeItem(Context context, Iterable<? extends ItemInfo> items) {
    ArraySet<UserHandle> updatedDeepShortcuts = new ArraySet<>();
    for (ItemInfo item : items) {
        switch(item.itemType) {
            case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
                folders.remove(item.id);
                if (FeatureFlags.IS_STUDIO_BUILD) {
                    for (ItemInfo info : itemsIdMap) {
                        if (info.container == item.id) {
                            // We are deleting a folder which still contains items that
                            // think they are contained by that folder.
                            String msg = "deleting a folder (" + item + ") which still " + "contains items (" + info + ")";
                            Log.e(TAG, msg);
                        }
                    }
                }
                workspaceItems.remove(item);
                break;
            case LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT:
                {
                    updatedDeepShortcuts.add(item.user);
                // Fall through.
                }
            case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
            case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
                workspaceItems.remove(item);
                break;
            case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
            case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET:
                appWidgets.remove(item);
                break;
        }
        itemsIdMap.remove(item.id);
    }
    updatedDeepShortcuts.forEach(user -> updateShortcutPinnedState(context, user));
}
Also used : ArraySet(android.util.ArraySet) ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) UserHandle(android.os.UserHandle)

Example 15 with Folder

use of com.android.launcher3.tapl.Folder in project android_packages_apps_Launcher3 by crdroidandroid.

the class KeyboardDragAndDropView method getNextSelection.

/**
 * Focus finding logic:
 * Collect all virtual nodes in reading order (used for forward and backwards).
 * Then find the closest view by comparing the distances spatially. Since it is a move
 * operation. consider all cell sizes to be approximately of the same size.
 */
private VirtualNodeInfo getNextSelection(int direction) {
    // Collect all virtual nodes
    mDelegates.clear();
    mNodes.clear();
    Folder openFolder = Folder.getOpen(mLauncher);
    PagedView pv = openFolder == null ? mLauncher.getWorkspace() : openFolder.getContent();
    int count = pv.getPageCount();
    for (int i = 0; i < count; i++) {
        mDelegates.add(((CellLayout) pv.getChildAt(i)).getDragAndDropAccessibilityDelegate());
    }
    if (openFolder == null) {
        mDelegates.add(pv.getNextPage() + 1, mLauncher.getHotseat().getDragAndDropAccessibilityDelegate());
    }
    mDelegates.forEach(delegate -> {
        mIntList.clear();
        delegate.getVisibleVirtualViews(mIntList);
        mIntList.forEach(id -> mNodes.add(new VirtualNodeInfo(delegate, id)));
    });
    if (mNodes.isEmpty()) {
        return null;
    }
    int index = mNodes.indexOf(mCurrentSelection);
    if (mCurrentSelection == null || index < 0) {
        return null;
    }
    int totalNodes = mNodes.size();
    final ToIntBiFunction<Rect, Rect> majorAxis;
    final ToIntFunction<Rect> minorAxis;
    switch(direction) {
        case View.FOCUS_RIGHT:
            majorAxis = (source, dest) -> dest.left - source.left;
            minorAxis = Rect::centerY;
            break;
        case View.FOCUS_LEFT:
            majorAxis = (source, dest) -> source.left - dest.left;
            minorAxis = Rect::centerY;
            break;
        case View.FOCUS_UP:
            majorAxis = (source, dest) -> source.top - dest.top;
            minorAxis = Rect::centerX;
            break;
        case View.FOCUS_DOWN:
            majorAxis = (source, dest) -> dest.top - source.top;
            minorAxis = Rect::centerX;
            break;
        case View.FOCUS_FORWARD:
            return mNodes.get((index + 1) % totalNodes);
        case View.FOCUS_BACKWARD:
            return mNodes.get((index + totalNodes - 1) % totalNodes);
        default:
            // Unknown direction
            return null;
    }
    mCurrentSelection.populate(mTempNodeInfo).getBoundsInScreen(mTempRect);
    float minWeight = Float.MAX_VALUE;
    VirtualNodeInfo match = null;
    for (int i = 0; i < totalNodes; i++) {
        VirtualNodeInfo node = mNodes.get(i);
        node.populate(mTempNodeInfo).getBoundsInScreen(mTempRect2);
        int majorAxisWeight = majorAxis.applyAsInt(mTempRect, mTempRect2);
        if (majorAxisWeight <= 0) {
            continue;
        }
        int minorAxisWeight = minorAxis.applyAsInt(mTempRect2) - minorAxis.applyAsInt(mTempRect);
        float weight = majorAxisWeight * majorAxisWeight + minorAxisWeight * minorAxisWeight * MINOR_AXIS_WEIGHT;
        if (weight < minWeight) {
            minWeight = weight;
            match = node;
        }
    }
    return match;
}
Also used : Rect(android.graphics.Rect) PagedView(com.android.launcher3.PagedView) Folder(com.android.launcher3.folder.Folder)

Aggregations

View (android.view.View)119 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)112 FolderInfo (com.android.launcher3.model.data.FolderInfo)93 ItemInfo (com.android.launcher3.model.data.ItemInfo)86 Point (android.graphics.Point)83 FolderIcon (com.android.launcher3.folder.FolderIcon)83 Folder (com.android.launcher3.folder.Folder)82 AppWidgetHostView (android.appwidget.AppWidgetHostView)80 SuppressLint (android.annotation.SuppressLint)73 DragView (com.android.launcher3.dragndrop.DragView)64 PendingAppWidgetHostView (com.android.launcher3.widget.PendingAppWidgetHostView)64 Rect (android.graphics.Rect)63 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)61 BubbleTextView (com.android.launcher3.BubbleTextView)56 ArrayList (java.util.ArrayList)49 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)47 Animator (android.animation.Animator)40 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)40 Drawable (android.graphics.drawable.Drawable)37 CellLayout (com.android.launcher3.CellLayout)37