Search in sources :

Example 96 with Background

use of com.android.launcher3.tapl.Background in project Neo-Launcher by NeoApplications.

the class TaskThumbnailView method updateThumbnailMatrix.

private void updateThumbnailMatrix() {
    boolean isRotated = false;
    mClipBottom = -1;
    if (mBitmapShader != null && mThumbnailData != null) {
        float scale = mThumbnailData.scale;
        Rect thumbnailInsets = mThumbnailData.insets;
        final float thumbnailWidth = mThumbnailData.thumbnail.getWidth() - (thumbnailInsets.left + thumbnailInsets.right) * scale;
        final float thumbnailHeight = mThumbnailData.thumbnail.getHeight() - (thumbnailInsets.top + thumbnailInsets.bottom) * scale;
        final float thumbnailScale;
        final DeviceProfile profile = mActivity.getDeviceProfile();
        if (getMeasuredWidth() == 0) {
            // If we haven't measured , skip the thumbnail drawing and only draw the background
            // color
            thumbnailScale = 0f;
        } else {
            final Configuration configuration = getContext().getResources().getConfiguration();
            // Rotate the screenshot if not in multi-window mode
            isRotated = FeatureFlags.OVERVIEW_USE_SCREENSHOT_ORIENTATION && configuration.orientation != mThumbnailData.orientation && !mActivity.isInMultiWindowMode() && mThumbnailData.windowingMode == WINDOWING_MODE_FULLSCREEN;
            // Scale the screenshot to always fit the width of the card.
            thumbnailScale = isRotated ? getMeasuredWidth() / thumbnailHeight : getMeasuredWidth() / thumbnailWidth;
        }
        if (isRotated) {
            int rotationDir = profile.isVerticalBarLayout() && !profile.isSeascape() ? -1 : 1;
            mMatrix.setRotate(90 * rotationDir);
            int newLeftInset = rotationDir == 1 ? thumbnailInsets.bottom : thumbnailInsets.top;
            int newTopInset = rotationDir == 1 ? thumbnailInsets.left : thumbnailInsets.right;
            mClippedInsets.offsetTo(newLeftInset * scale, newTopInset * scale);
            if (rotationDir == -1) {
                // Crop the right/bottom side of the screenshot rather than left/top
                float excessHeight = thumbnailWidth * thumbnailScale - getMeasuredHeight();
                mClippedInsets.offset(0, excessHeight);
            }
            mMatrix.postTranslate(-mClippedInsets.left, -mClippedInsets.top);
            // Move the screenshot to the thumbnail window (rotation moved it out).
            if (rotationDir == 1) {
                mMatrix.postTranslate(mThumbnailData.thumbnail.getHeight(), 0);
            } else {
                mMatrix.postTranslate(0, mThumbnailData.thumbnail.getWidth());
            }
        } else {
            mClippedInsets.offsetTo(thumbnailInsets.left * scale, thumbnailInsets.top * scale);
            mMatrix.setTranslate(-mClippedInsets.left, -mClippedInsets.top);
        }
        final float widthWithInsets;
        final float heightWithInsets;
        if (isRotated) {
            widthWithInsets = mThumbnailData.thumbnail.getHeight() * thumbnailScale;
            heightWithInsets = mThumbnailData.thumbnail.getWidth() * thumbnailScale;
        } else {
            widthWithInsets = mThumbnailData.thumbnail.getWidth() * thumbnailScale;
            heightWithInsets = mThumbnailData.thumbnail.getHeight() * thumbnailScale;
        }
        mClippedInsets.left *= thumbnailScale;
        mClippedInsets.top *= thumbnailScale;
        mClippedInsets.right = widthWithInsets - mClippedInsets.left - getMeasuredWidth();
        mClippedInsets.bottom = heightWithInsets - mClippedInsets.top - getMeasuredHeight();
        mMatrix.postScale(thumbnailScale, thumbnailScale);
        mBitmapShader.setLocalMatrix(mMatrix);
        float bitmapHeight = Math.max((isRotated ? thumbnailWidth : thumbnailHeight) * thumbnailScale, 0);
        if (Math.round(bitmapHeight) < getMeasuredHeight()) {
            mClipBottom = bitmapHeight;
        }
        mPaint.setShader(mBitmapShader);
    }
    mRotated = isRotated;
    invalidate();
    // Update can be called from {@link #onSizeChanged} during layout, post handling of overlay
    // as overlay could modify the views in the overlay as a side effect of its update.
    post(this::updateOverlay);
}
Also used : DeviceProfile(com.android.launcher3.DeviceProfile) Rect(android.graphics.Rect) Configuration(android.content.res.Configuration) Paint(android.graphics.Paint)

Example 97 with Background

use of com.android.launcher3.tapl.Background in project Neo-Launcher by NeoApplications.

the class PopupContainerWithArrow method initializeSystemShortcut.

private void initializeSystemShortcut(int resId, ViewGroup container, SystemShortcut info) {
    View view = inflateAndAdd(resId, container, getInsertIndexForSystemShortcut(container, info));
    if (view instanceof DeepShortcutView) {
        // Expanded system shortcut, with both icon and text shown on white background.
        final DeepShortcutView shortcutView = (DeepShortcutView) view;
        info.setIconAndLabelFor(shortcutView.getIconView(), shortcutView.getBubbleText());
    } else if (view instanceof ImageView) {
        // Only the system shortcut icon shows on a gray background header.
        info.setIconAndContentDescriptionFor((ImageView) view);
    }
    view.setTag(info);
    view.setOnClickListener(info.getOnClickListener(mLauncher, (ItemInfo) mOriginalIcon.getTag()));
}
Also used : ItemInfo(com.android.launcher3.ItemInfo) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) BubbleTextView(com.android.launcher3.BubbleTextView) View(android.view.View) NotificationItemView(com.android.launcher3.notification.NotificationItemView) DeepShortcutView(com.android.launcher3.shortcuts.DeepShortcutView) AbstractFloatingView(com.android.launcher3.AbstractFloatingView) DragView(com.android.launcher3.dragndrop.DragView) DeepShortcutView(com.android.launcher3.shortcuts.DeepShortcutView)

Example 98 with Background

use of com.android.launcher3.tapl.Background in project Neo-Launcher by NeoApplications.

the class TaplTestsQuickstep method testQuickSwitchFromApp.

@Test
@NavigationModeSwitch
@PortraitLandscape
public void testQuickSwitchFromApp() throws Exception {
    startTestActivity(2);
    startTestActivity(3);
    startTestActivity(4);
    Background background = getAndAssertBackground();
    background.quickSwitchToPreviousApp();
    assertTrue("The first app we should have quick switched to is not running", isTestActivityRunning(3));
    background = getAndAssertBackground();
    background.quickSwitchToPreviousApp();
    if (mLauncher.getNavigationModel() == NavigationModel.THREE_BUTTON) {
        // 3-button mode toggles between 2 apps, rather than going back further.
        assertTrue("Second quick switch should have returned to the first app.", isTestActivityRunning(4));
    } else {
        assertTrue("The second app we should have quick switched to is not running", isTestActivityRunning(2));
    }
    getAndAssertBackground();
}
Also used : Background(com.android.launcher3.tapl.Background) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test) NavigationModeSwitch(com.android.quickstep.NavigationModeSwitchRule.NavigationModeSwitch)

Example 99 with Background

use of com.android.launcher3.tapl.Background in project Neo-Launcher by NeoApplications.

the class TaplTestsQuickstep method testBackground.

@Test
@NavigationModeSwitch
@PortraitLandscape
public void testBackground() throws Exception {
    startAppFast(resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR));
    final Background background = getAndAssertBackground();
    assertNotNull("Background.switchToOverview() returned null", background.switchToOverview());
    assertTrue("Launcher internal state didn't switch to Overview", isInState(LauncherState.OVERVIEW));
}
Also used : Background(com.android.launcher3.tapl.Background) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test) NavigationModeSwitch(com.android.quickstep.NavigationModeSwitchRule.NavigationModeSwitch)

Example 100 with Background

use of com.android.launcher3.tapl.Background in project Neo-Launcher by NeoApplications.

the class FolderAnimationManager method getAnimator.

/**
 * Prepares the Folder for animating between open / closed states.
 */
public AnimatorSet getAnimator() {
    final DragLayer.LayoutParams lp = (DragLayer.LayoutParams) mFolder.getLayoutParams();
    ClippedFolderIconLayoutRule rule = mFolderIcon.getLayoutRule();
    final List<BubbleTextView> itemsInPreview = getPreviewIconsOnPage(0);
    // Match position of the FolderIcon
    final Rect folderIconPos = new Rect();
    float scaleRelativeToDragLayer = mLauncher.getDragLayer().getDescendantRectRelativeToSelf(mFolderIcon, folderIconPos);
    int scaledRadius = mPreviewBackground.getScaledRadius();
    float initialSize = (scaledRadius * 2) * scaleRelativeToDragLayer;
    // Match size/scale of icons in the preview
    float previewScale = rule.scaleForItem(itemsInPreview.size());
    float previewSize = rule.getIconSize() * previewScale;
    Log.d("FolderAnimation", "Items " + itemsInPreview.get(0));
    float initialScale = previewSize / itemsInPreview.get(0).getIconSize() * scaleRelativeToDragLayer;
    final float finalScale = 1f;
    float scale = mIsOpening ? initialScale : finalScale;
    mFolder.setPivotX(0);
    mFolder.setPivotY(0);
    // Scale the contents of the folder.
    mFolder.mContent.setScaleX(scale);
    mFolder.mContent.setScaleY(scale);
    mFolder.mContent.setPivotX(0);
    mFolder.mContent.setPivotY(0);
    mFolder.mFooter.setScaleX(scale);
    mFolder.mFooter.setScaleY(scale);
    mFolder.mFooter.setPivotX(0);
    mFolder.mFooter.setPivotY(0);
    // We want to create a small X offset for the preview items, so that they follow their
    // expected path to their final locations. ie. an icon should not move right, if it's final
    // location is to its left. This value is arbitrarily defined.
    int previewItemOffsetX = (int) (previewSize / 2);
    if (Utilities.isRtl(mContext.getResources())) {
        previewItemOffsetX = (int) (lp.width * initialScale - initialSize - previewItemOffsetX);
    }
    final int paddingOffsetX = (int) (mContent.getPaddingLeft() * initialScale);
    final int paddingOffsetY = (int) (mContent.getPaddingTop() * initialScale);
    int initialX = folderIconPos.left + mFolder.getPaddingLeft() + mPreviewBackground.getOffsetX() - paddingOffsetX - previewItemOffsetX;
    int initialY = folderIconPos.top + mFolder.getPaddingTop() + mPreviewBackground.getOffsetY() - paddingOffsetY;
    final float xDistance = initialX - lp.x;
    final float yDistance = initialY - lp.y;
    // Set up the Folder background.
    final int finalColor = ColorUtils.setAlphaComponent(Themes.getAttrColor(mContext, R.attr.folderFillColor), 255);
    final int initialColor = setColorAlphaBound(finalColor, mPreviewBackground.getBackgroundAlpha());
    mFolderBackground.mutate();
    mFolderBackground.setColor(mIsOpening ? initialColor : finalColor);
    // Set up the reveal animation that clips the Folder.
    int totalOffsetX = paddingOffsetX + previewItemOffsetX;
    Rect startRect = new Rect(totalOffsetX, paddingOffsetY, Math.round((totalOffsetX + initialSize)), Math.round((paddingOffsetY + initialSize)));
    Rect endRect = new Rect(0, 0, lp.width, lp.height);
    float finalRadius = ResourceUtils.pxFromDp(2, mContext.getResources().getDisplayMetrics());
    // Create the animators.
    AnimatorSet a = new AnimatorSet();
    // Initialize the Folder items' text.
    PropertyResetListener colorResetListener = new PropertyResetListener<>(TEXT_ALPHA_PROPERTY, 1f);
    for (BubbleTextView icon : mFolder.getItemsOnPage(mFolder.mContent.getCurrentPage())) {
        if (mIsOpening) {
            icon.setTextVisibility(false);
        }
        ObjectAnimator anim = icon.createTextAlphaAnimator(mIsOpening);
        anim.addListener(colorResetListener);
        play(a, anim);
    }
    play(a, getAnimator(mFolder, View.TRANSLATION_X, xDistance, 0f));
    play(a, getAnimator(mFolder, View.TRANSLATION_Y, yDistance, 0f));
    play(a, getAnimator(mFolder.mContent, SCALE_PROPERTY, initialScale, finalScale));
    play(a, getAnimator(mFolder.mFooter, SCALE_PROPERTY, initialScale, finalScale));
    play(a, getAnimator(mFolderBackground, "color", initialColor, finalColor));
    play(a, mFolderIcon.mFolderName.createTextAlphaAnimator(!mIsOpening));
    play(a, getShape().createRevealAnimator(mFolder, startRect, endRect, finalRadius, !mIsOpening));
    // Fade in the folder name, as the text can overlap the icons when grid size is small.
    mFolder.mFolderName.setAlpha(mIsOpening ? 0f : 1f);
    play(a, getAnimator(mFolder.mFolderName, View.ALPHA, 0, 1), mIsOpening ? FOLDER_NAME_ALPHA_DURATION : 0, mIsOpening ? mDuration - FOLDER_NAME_ALPHA_DURATION : FOLDER_NAME_ALPHA_DURATION);
    // Translate the footer so that it tracks the bottom of the content.
    float normalHeight = mFolder.getContentAreaHeight();
    float scaledHeight = normalHeight * initialScale;
    float diff = normalHeight - scaledHeight;
    play(a, getAnimator(mFolder.mFooter, View.TRANSLATION_Y, -diff, 0f));
    // Animate the elevation midway so that the shadow is not noticeable in the background.
    int midDuration = mDuration / 2;
    Animator z = getAnimator(mFolder, View.TRANSLATION_Z, -mFolder.getElevation(), 0);
    play(a, z, mIsOpening ? midDuration : 0, midDuration);
    // Store clip variables
    CellLayout cellLayout = mContent.getCurrentCellLayout();
    boolean folderClipChildren = mFolder.getClipChildren();
    boolean folderClipToPadding = mFolder.getClipToPadding();
    boolean contentClipChildren = mContent.getClipChildren();
    boolean contentClipToPadding = mContent.getClipToPadding();
    boolean cellLayoutClipChildren = cellLayout.getClipChildren();
    boolean cellLayoutClipPadding = cellLayout.getClipToPadding();
    mFolder.setClipChildren(false);
    mFolder.setClipToPadding(false);
    mContent.setClipChildren(false);
    mContent.setClipToPadding(false);
    cellLayout.setClipChildren(false);
    cellLayout.setClipToPadding(false);
    a.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            mFolder.setTranslationX(0.0f);
            mFolder.setTranslationY(0.0f);
            mFolder.setTranslationZ(0.0f);
            mFolder.mContent.setScaleX(1f);
            mFolder.mContent.setScaleY(1f);
            mFolder.mFooter.setScaleX(1f);
            mFolder.mFooter.setScaleY(1f);
            mFolder.mFooter.setTranslationX(0f);
            mFolder.mFolderName.setAlpha(1f);
            mFolder.setClipChildren(folderClipChildren);
            mFolder.setClipToPadding(folderClipToPadding);
            mContent.setClipChildren(contentClipChildren);
            mContent.setClipToPadding(contentClipToPadding);
            cellLayout.setClipChildren(cellLayoutClipChildren);
            cellLayout.setClipToPadding(cellLayoutClipPadding);
        }
    });
    // animators may use a different interpolator.
    for (Animator animator : a.getChildAnimations()) {
        animator.setInterpolator(mFolderInterpolator);
    }
    int radiusDiff = scaledRadius - mPreviewBackground.getRadius();
    addPreviewItemAnimators(a, initialScale / scaleRelativeToDragLayer, // difference to keep the preview items centered.
    previewItemOffsetX + radiusDiff, radiusDiff);
    return a;
}
Also used : Rect(android.graphics.Rect) ObjectAnimator(android.animation.ObjectAnimator) PropertyResetListener(com.android.launcher3.anim.PropertyResetListener) AnimatorSet(android.animation.AnimatorSet) DragLayer(com.android.launcher3.dragndrop.DragLayer) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) CellLayout(com.android.launcher3.CellLayout) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) BubbleTextView(com.android.launcher3.BubbleTextView)

Aggregations

View (android.view.View)48 Point (android.graphics.Point)39 Rect (android.graphics.Rect)39 ItemInfo (com.android.launcher3.model.data.ItemInfo)29 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)29 ObjectAnimator (android.animation.ObjectAnimator)28 Background (com.android.launcher3.tapl.Background)28 DragView (com.android.launcher3.dragndrop.DragView)26 DragLayer (com.android.launcher3.dragndrop.DragLayer)25 Animator (android.animation.Animator)24 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)24 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)24 Drawable (android.graphics.drawable.Drawable)23 ArrayList (java.util.ArrayList)23 ViewGroup (android.view.ViewGroup)22 ColorDrawable (android.graphics.drawable.ColorDrawable)21 Handler (android.os.Handler)21 FolderIcon (com.android.launcher3.folder.FolderIcon)21 DeepShortcutView (com.android.launcher3.shortcuts.DeepShortcutView)21 Bitmap (android.graphics.Bitmap)20