Search in sources :

Example 56 with DeviceProfile

use of com.android.launcher3.DeviceProfile in project android_packages_apps_Launcher3 by AOSPA.

the class PreviewSurfaceRenderer method loadModelData.

@WorkerThread
private void loadModelData() {
    final boolean migrated = doGridMigrationIfNecessary();
    final Context inflationContext;
    if (mWallpaperColors != null) {
        // Create a themed context, without affecting the main application context
        Context context = mContext.createDisplayContext(mDisplay);
        if (Utilities.ATLEAST_R) {
            context = context.createWindowContext(LayoutParams.TYPE_APPLICATION_OVERLAY, null);
        }
        LocalColorExtractor.newInstance(mContext).applyColorsOverride(context, mWallpaperColors);
        inflationContext = new ContextThemeWrapper(context, Themes.getActivityThemeRes(context, mWallpaperColors.getColorHints()));
    } else {
        inflationContext = new ContextThemeWrapper(mContext, Themes.getActivityThemeRes(mContext));
    }
    if (migrated) {
        PreviewContext previewContext = new PreviewContext(inflationContext, mIdp);
        new LoaderTask(LauncherAppState.getInstance(previewContext), null, new BgDataModel(), new ModelDelegate(), null) {

            @Override
            public void run() {
                DeviceProfile deviceProfile = mIdp.getDeviceProfile(previewContext);
                String query = LauncherSettings.Favorites.SCREEN + " = " + Workspace.FIRST_SCREEN_ID + " or " + LauncherSettings.Favorites.CONTAINER + " = " + LauncherSettings.Favorites.CONTAINER_HOTSEAT;
                if (deviceProfile.isTwoPanels) {
                    query += " or " + LauncherSettings.Favorites.SCREEN + " = " + Workspace.SECOND_SCREEN_ID;
                }
                loadWorkspace(new ArrayList<>(), LauncherSettings.Favorites.PREVIEW_CONTENT_URI, query);
                MAIN_EXECUTOR.execute(() -> {
                    renderView(previewContext, mBgDataModel, mWidgetProvidersMap);
                    mOnDestroyCallbacks.add(previewContext::onDestroy);
                });
            }
        }.run();
    } else {
        LauncherAppState.getInstance(inflationContext).getModel().loadAsync(dataModel -> {
            if (dataModel != null) {
                MAIN_EXECUTOR.execute(() -> renderView(inflationContext, dataModel, null));
            } else {
                Log.e(TAG, "Model loading failed");
            }
        });
    }
}
Also used : Context(android.content.Context) PreviewContext(com.android.launcher3.graphics.LauncherPreviewRenderer.PreviewContext) ModelDelegate(com.android.launcher3.model.ModelDelegate) DeviceProfile(com.android.launcher3.DeviceProfile) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) ContextThemeWrapper(android.view.ContextThemeWrapper) PreviewContext(com.android.launcher3.graphics.LauncherPreviewRenderer.PreviewContext) BgDataModel(com.android.launcher3.model.BgDataModel) ArrayList(java.util.ArrayList) LoaderTask(com.android.launcher3.model.LoaderTask) WorkerThread(androidx.annotation.WorkerThread)

Example 57 with DeviceProfile

use of com.android.launcher3.DeviceProfile in project android_packages_apps_Launcher3 by AOSPA.

the class PreviewBackground method setup.

public void setup(Context context, ActivityContext activity, View invalidateDelegate, int availableSpaceX, int topPadding) {
    mInvalidateDelegate = invalidateDelegate;
    TypedArray ta = context.getTheme().obtainStyledAttributes(R.styleable.FolderIconPreview);
    mDotColor = ta.getColor(R.styleable.FolderIconPreview_folderDotColor, 0);
    mStrokeColor = ta.getColor(R.styleable.FolderIconPreview_folderIconBorderColor, 0);
    mBgColor = ta.getColor(R.styleable.FolderIconPreview_folderPreviewColor, 0);
    ta.recycle();
    DeviceProfile grid = activity.getDeviceProfile();
    previewSize = grid.folderIconSizePx;
    basePreviewOffsetX = (availableSpaceX - previewSize) / 2;
    basePreviewOffsetY = topPadding + grid.folderIconOffsetYPx;
    // Stroke width is 1dp
    mStrokeWidth = context.getResources().getDisplayMetrics().density;
    if (DRAW_SHADOW) {
        float radius = getScaledRadius();
        float shadowRadius = radius + mStrokeWidth;
        int shadowColor = Color.argb(SHADOW_OPACITY, 0, 0, 0);
        mShadowShader = new RadialGradient(0, 0, 1, new int[] { shadowColor, Color.TRANSPARENT }, new float[] { radius / shadowRadius, 1 }, Shader.TileMode.CLAMP);
    }
    invalidate();
}
Also used : DeviceProfile(com.android.launcher3.DeviceProfile) TypedArray(android.content.res.TypedArray) RadialGradient(android.graphics.RadialGradient) Paint(android.graphics.Paint)

Example 58 with DeviceProfile

use of com.android.launcher3.DeviceProfile in project android_packages_apps_Launcher3 by AOSPA.

the class Folder method onFinishInflate.

@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    final DeviceProfile dp = mActivityContext.getDeviceProfile();
    final int paddingLeftRight = dp.folderContentPaddingLeftRight;
    mBackground = (GradientDrawable) ResourcesCompat.getDrawable(getResources(), R.drawable.round_rect_folder, getContext().getTheme());
    mContent = findViewById(R.id.folder_content);
    mContent.setPadding(paddingLeftRight, dp.folderContentPaddingTop, paddingLeftRight, 0);
    mContent.setFolder(this);
    mPageIndicator = findViewById(R.id.folder_page_indicator);
    mFolderName = findViewById(R.id.folder_name);
    mFolderName.setTextSize(TypedValue.COMPLEX_UNIT_PX, dp.folderLabelTextSizePx);
    if (mActivityContext.supportsIme()) {
        mFolderName.setOnBackKeyListener(this);
        mFolderName.setOnFocusChangeListener(this);
        mFolderName.setOnEditorActionListener(this);
        mFolderName.setSelectAllOnFocus(true);
        mFolderName.setInputType(mFolderName.getInputType() & ~InputType.TYPE_TEXT_FLAG_AUTO_CORRECT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_FLAG_CAP_WORDS);
        mFolderName.forceDisableSuggestions(true);
    } else {
        mFolderName.setEnabled(false);
    }
    mFooter = findViewById(R.id.folder_footer);
    mFooterHeight = getResources().getDimensionPixelSize(R.dimen.folder_label_height);
    if (Utilities.ATLEAST_R) {
        mKeyboardInsetAnimationCallback = new KeyboardInsetAnimationCallback(this);
        setWindowInsetsAnimationCallback(mKeyboardInsetAnimationCallback);
    }
}
Also used : DeviceProfile(com.android.launcher3.DeviceProfile) KeyboardInsetAnimationCallback(com.android.launcher3.anim.KeyboardInsetAnimationCallback) SuppressLint(android.annotation.SuppressLint)

Example 59 with DeviceProfile

use of com.android.launcher3.DeviceProfile in project android_packages_apps_Launcher3 by AOSPA.

the class FlingToDeleteHelper method isFlingingToDelete.

/**
 * Determines whether the user flung the current item to delete it.
 *
 * @return the vector at which the item was flung, or null if no fling was detected.
 */
private PointF isFlingingToDelete() {
    if (mVelocityTracker == null)
        return null;
    if (mDropTarget == null) {
        mDropTarget = (ButtonDropTarget) mLauncher.findViewById(R.id.delete_target_text);
    }
    if (mDropTarget == null || !mDropTarget.isDropEnabled())
        return null;
    ViewConfiguration config = ViewConfiguration.get(mLauncher);
    mVelocityTracker.computeCurrentVelocity(1000, config.getScaledMaximumFlingVelocity());
    PointF vel = new PointF(mVelocityTracker.getXVelocity(), mVelocityTracker.getYVelocity());
    float theta = MAX_FLING_DEGREES + 1;
    DeviceProfile deviceProfile = mLauncher.getDeviceProfile();
    if (mVelocityTracker.getYVelocity() < deviceProfile.flingToDeleteThresholdVelocity) {
        // Do a quick dot product test to ensure that we are flinging upwards
        PointF upVec = new PointF(0f, -1f);
        theta = getAngleBetweenVectors(vel, upVec);
    } else if (mLauncher.getDeviceProfile().isVerticalBarLayout() && mVelocityTracker.getXVelocity() < deviceProfile.flingToDeleteThresholdVelocity) {
        // Remove icon is on left side instead of top, so check if we are flinging to the left.
        PointF leftVec = new PointF(-1f, 0f);
        theta = getAngleBetweenVectors(vel, leftVec);
    }
    if (theta <= Math.toRadians(MAX_FLING_DEGREES)) {
        return vel;
    }
    return null;
}
Also used : ViewConfiguration(android.view.ViewConfiguration) DeviceProfile(com.android.launcher3.DeviceProfile) PointF(android.graphics.PointF)

Example 60 with DeviceProfile

use of com.android.launcher3.DeviceProfile in project android_packages_apps_Trebuchet by LineageOS.

the class AllAppsContainerView method setInsets.

@Override
public void setInsets(Rect insets) {
    mInsets.set(insets);
    DeviceProfile grid = mLauncher.getDeviceProfile();
    int leftRightPadding = grid.desiredWorkspaceLeftRightMarginPx + grid.cellLayoutPaddingLeftRightPx;
    for (int i = 0; i < mAH.length; i++) {
        mAH[i].padding.bottom = insets.bottom;
        mAH[i].padding.left = mAH[i].padding.right = leftRightPadding;
        mAH[i].applyPadding();
        mAH[i].setupOverlay();
    }
    ViewGroup.MarginLayoutParams mlp = (MarginLayoutParams) getLayoutParams();
    mlp.leftMargin = insets.left;
    mlp.rightMargin = insets.right;
    setLayoutParams(mlp);
    if (grid.isVerticalBarLayout()) {
        setPadding(grid.workspacePadding.left, 0, grid.workspacePadding.right, 0);
    } else {
        setPadding(0, 0, 0, 0);
    }
    InsettableFrameLayout.dispatchInsets(this, insets);
}
Also used : DeviceProfile(com.android.launcher3.DeviceProfile) ViewGroup(android.view.ViewGroup) Paint(android.graphics.Paint) Point(android.graphics.Point)

Aggregations

DeviceProfile (com.android.launcher3.DeviceProfile)333 Rect (android.graphics.Rect)123 Point (android.graphics.Point)83 InvariantDeviceProfile (com.android.launcher3.InvariantDeviceProfile)61 Paint (android.graphics.Paint)40 ArrayList (java.util.ArrayList)38 View (android.view.View)31 PagedOrientationHandler (com.android.launcher3.touch.PagedOrientationHandler)31 Context (android.content.Context)28 SuppressLint (android.annotation.SuppressLint)27 Size (android.util.Size)25 DragLayer (com.android.launcher3.dragndrop.DragLayer)25 ViewGroup (android.view.ViewGroup)23 Launcher (com.android.launcher3.Launcher)23 RecentsView (com.android.quickstep.views.RecentsView)23 RectF (android.graphics.RectF)22 PendingAnimation (com.android.launcher3.anim.PendingAnimation)22 FrameLayout (android.widget.FrameLayout)21 AnimatorPlaybackController (com.android.launcher3.anim.AnimatorPlaybackController)21 Drawable (android.graphics.drawable.Drawable)20