Search in sources :

Example 81 with Background

use of com.android.launcher3.tapl.Background in project android_packages_apps_404Launcher by P-404.

the class FloatingIconView method getFloatingIconView.

/**
 * Creates a floating icon view for {@param originalView}.
 * @param originalView The view to copy
 * @param hideOriginal If true, it will hide {@param originalView} while this view is visible.
 *                     Else, we will not draw anything in this view.
 * @param positionOut Rect that will hold the size and position of v.
 * @param isOpening True if this view replaces the icon for app open animation.
 */
public static FloatingIconView getFloatingIconView(Launcher launcher, View originalView, boolean hideOriginal, RectF positionOut, boolean isOpening) {
    final DragLayer dragLayer = launcher.getDragLayer();
    ViewGroup parent = (ViewGroup) dragLayer.getParent();
    FloatingIconView view = launcher.getViewCache().getView(R.layout.floating_icon_view, launcher, parent);
    view.recycle();
    // Get the drawable on the background thread
    boolean shouldLoadIcon = originalView.getTag() instanceof ItemInfo && hideOriginal;
    if (shouldLoadIcon) {
        if (sIconLoadResult != null && sIconLoadResult.itemInfo == originalView.getTag()) {
            view.mIconLoadResult = sIconLoadResult;
        } else {
            view.mIconLoadResult = fetchIcon(launcher, originalView, (ItemInfo) originalView.getTag(), isOpening);
        }
        view.setOriginalDrawableBackground(view.mIconLoadResult.btvDrawable);
    }
    sIconLoadResult = null;
    view.mIsVerticalBarLayout = launcher.getDeviceProfile().isVerticalBarLayout();
    view.mIsOpening = isOpening;
    view.mOriginalIcon = originalView;
    view.mPositionOut = positionOut;
    // Match the position of the original view.
    view.matchPositionOf(launcher, originalView, isOpening, positionOut);
    // We need to add it to the overlay, but keep it invisible until animation starts..
    view.setVisibility(INVISIBLE);
    parent.addView(view);
    dragLayer.addView(view.mListenerView);
    view.mListenerView.setListener(view::fastFinish);
    view.mEndRunnable = () -> {
        view.mEndRunnable = null;
        if (hideOriginal) {
            if (isOpening) {
                setIconAndDotVisible(originalView, true);
                view.finish(dragLayer);
            } else {
                originalView.setVisibility(VISIBLE);
                if (originalView instanceof IconLabelDotView) {
                    setIconAndDotVisible(originalView, true);
                }
                view.finish(dragLayer);
            }
        } else {
            view.finish(dragLayer);
        }
    };
    // the icon is not left in a hidden state.
    if (shouldLoadIcon) {
        view.checkIconResult(originalView);
    }
    return view;
}
Also used : DragLayer(com.android.launcher3.dragndrop.DragLayer) ItemInfo(com.android.launcher3.model.data.ItemInfo) ViewGroup(android.view.ViewGroup)

Example 82 with Background

use of com.android.launcher3.tapl.Background in project android_packages_apps_404Launcher by P-404.

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_SEARCH_ACTION && 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(mActivity, info, w, h, outObj);
        if (dr instanceof AdaptiveIconDrawable) {
            int blurMargin = (int) mActivity.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(mActivity, 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(mActivity)) {
                // 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 83 with Background

use of com.android.launcher3.tapl.Background in project android_packages_apps_404Launcher by P-404.

the class QuickstepTransitionManager method getBackgroundAnimator.

/**
 * Returns animator that controls depth/blur of the background.
 */
private ObjectAnimator getBackgroundAnimator() {
    // When launching an app from overview that doesn't map to a task, we still want to just
    // blur the wallpaper instead of the launcher surface as well
    boolean allowBlurringLauncher = mLauncher.getStateManager().getState() != OVERVIEW;
    DepthController depthController = mLauncher.getDepthController();
    ObjectAnimator backgroundRadiusAnim = ObjectAnimator.ofFloat(depthController, DEPTH, BACKGROUND_APP.getDepth(mLauncher)).setDuration(APP_LAUNCH_DURATION);
    if (allowBlurringLauncher) {
        final SurfaceControl dimLayer;
        if (BlurUtils.supportsBlursOnWindows()) {
            // Create a temporary effect layer, that lives on top of launcher, so we can apply
            // the blur to it. The EffectLayer will be fullscreen, which will help with caching
            // optimizations on the SurfaceFlinger side:
            // - Results would be able to be cached as a texture
            // - There won't be texture allocation overhead, because EffectLayers don't have
            // buffers
            ViewRootImpl viewRootImpl = mLauncher.getDragLayer().getViewRootImpl();
            SurfaceControl parent = viewRootImpl != null ? viewRootImpl.getSurfaceControl() : null;
            dimLayer = new SurfaceControl.Builder().setName("Blur layer").setParent(parent).setOpaque(false).setHidden(false).setEffectLayer().build();
        } else {
            dimLayer = null;
        }
        depthController.setSurface(dimLayer);
        backgroundRadiusAnim.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationStart(Animator animation) {
                depthController.setIsInLaunchTransition(true);
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                depthController.setIsInLaunchTransition(false);
                depthController.setSurface(null);
                if (dimLayer != null) {
                    new SurfaceControl.Transaction().remove(dimLayer).apply();
                }
            }
        });
    }
    return backgroundRadiusAnim;
}
Also used : ViewRootImpl(android.view.ViewRootImpl) ValueAnimator(android.animation.ValueAnimator) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ObjectAnimator(android.animation.ObjectAnimator) SurfaceControl(android.view.SurfaceControl) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) DepthController(com.android.launcher3.statehandlers.DepthController)

Example 84 with Background

use of com.android.launcher3.tapl.Background in project android_packages_apps_404Launcher by P-404.

the class ModelWriter method addItemToDatabase.

/**
 * Add an item to the database in a specified container. Sets the container, screen, cellX and
 * cellY fields of the item. Also assigns an ID to the item.
 */
public void addItemToDatabase(final ItemInfo item, int container, int screenId, int cellX, int cellY) {
    updateItemInfoProps(item, container, screenId, cellX, cellY);
    final ContentResolver cr = mContext.getContentResolver();
    item.id = Settings.call(cr, Settings.METHOD_NEW_ITEM_ID).getInt(Settings.EXTRA_VALUE);
    notifyOtherCallbacks(c -> c.bindItems(Collections.singletonList(item), false));
    ModelVerifier verifier = new ModelVerifier();
    final StackTraceElement[] stackTrace = new Throwable().getStackTrace();
    MODEL_EXECUTOR.execute(() -> {
        // Write the item on background thread, as some properties might have been updated in
        // the background.
        final ContentWriter writer = new ContentWriter(mContext);
        item.onAddToDatabase(writer);
        writer.put(Favorites._ID, item.id);
        cr.insert(Favorites.CONTENT_URI, writer.getValues(mContext));
        synchronized (mBgDataModel) {
            checkItemInfoLocked(item.id, item, stackTrace);
            mBgDataModel.addItem(mContext, item, true);
            verifier.verifyModel();
        }
    });
}
Also used : ContentWriter(com.android.launcher3.util.ContentWriter) ContentResolver(android.content.ContentResolver)

Example 85 with Background

use of com.android.launcher3.tapl.Background in project android_packages_apps_404Launcher by P-404.

the class AbstractLauncherUiTest method checkLauncherIntegrity.

private void checkLauncherIntegrity(Launcher launcher, ContainerType expectedContainerType) {
    if (launcher != null) {
        final StateManager<LauncherState> stateManager = launcher.getStateManager();
        final LauncherState stableState = stateManager.getCurrentStableState();
        assertTrue("Stable state != state: " + stableState.getClass().getSimpleName() + ", " + stateManager.getState().getClass().getSimpleName(), stableState == stateManager.getState());
        final boolean isResumed = launcher.hasBeenResumed();
        final boolean isStarted = launcher.isStarted();
        checkLauncherState(launcher, expectedContainerType, isResumed, isStarted);
        final int ordinal = stableState.ordinal;
        switch(expectedContainerType) {
            case WORKSPACE:
            case WIDGETS:
                {
                    assertTrue("Launcher is not resumed in state: " + expectedContainerType, isResumed);
                    assertTrue(TestProtocol.stateOrdinalToString(ordinal), ordinal == TestProtocol.NORMAL_STATE_ORDINAL);
                    break;
                }
            case ALL_APPS:
                {
                    assertTrue("Launcher is not resumed in state: " + expectedContainerType, isResumed);
                    assertTrue(TestProtocol.stateOrdinalToString(ordinal), ordinal == TestProtocol.ALL_APPS_STATE_ORDINAL);
                    break;
                }
            case OVERVIEW:
                {
                    checkLauncherStateInOverview(launcher, expectedContainerType, isStarted, isResumed);
                    assertTrue(TestProtocol.stateOrdinalToString(ordinal), ordinal == TestProtocol.OVERVIEW_STATE_ORDINAL);
                    break;
                }
            case BACKGROUND:
                {
                    assertTrue("Launcher is resumed in state: " + expectedContainerType, !isResumed);
                    assertTrue(TestProtocol.stateOrdinalToString(ordinal), ordinal == TestProtocol.NORMAL_STATE_ORDINAL);
                    break;
                }
            default:
                throw new IllegalArgumentException("Illegal container: " + expectedContainerType);
        }
    } else {
        assertTrue("Container type is not BACKGROUND or FALLBACK_OVERVIEW: " + expectedContainerType, expectedContainerType == ContainerType.BACKGROUND || expectedContainerType == ContainerType.FALLBACK_OVERVIEW);
    }
}
Also used : LauncherState(com.android.launcher3.LauncherState)

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