Search in sources :

Example 81 with DeviceProfile

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

the class WindowTransformSwipeHandler method doLogGesture.

private void doLogGesture(GestureEndTarget endTarget) {
    DeviceProfile dp = mDp;
    if (dp == null || mDownPos == null) {
        // We probably never received an animation controller, skip logging.
        return;
    }
    int pageIndex = endTarget == LAST_TASK ? LOG_NO_OP_PAGE_INDEX : mRecentsView.getNextPage();
    UserEventDispatcher.newInstance(mContext).logStateChangeAction(mLogAction, mLogDirection, (int) mDownPos.x, (int) mDownPos.y, ContainerType.NAVBAR, ContainerType.APP, endTarget.containerType, pageIndex);
}
Also used : DeviceProfile(com.android.launcher3.DeviceProfile)

Example 82 with DeviceProfile

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

the class PortraitStatesTouchController method getHotseatTop.

public static int getHotseatTop(Launcher launcher) {
    DeviceProfile dp = launcher.getDeviceProfile();
    int hotseatHeight = dp.hotseatBarSizePx + dp.getInsets().bottom;
    return launcher.getDragLayer().getHeight() - hotseatHeight;
}
Also used : DeviceProfile(com.android.launcher3.DeviceProfile)

Example 83 with DeviceProfile

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

the class CellLayout method visualizeDropLocation.

void visualizeDropLocation(View v, DragPreviewProvider outlineProvider, int cellX, int cellY, int spanX, int spanY, boolean resize, DropTarget.DragObject dragObject) {
    final int oldDragCellX = mDragCell[0];
    final int oldDragCellY = mDragCell[1];
    if (outlineProvider == null || outlineProvider.generatedDragOutline == null) {
        return;
    }
    Bitmap dragOutline = outlineProvider.generatedDragOutline;
    if (cellX != oldDragCellX || cellY != oldDragCellY) {
        Point dragOffset = dragObject.dragView.getDragVisualizeOffset();
        Rect dragRegion = dragObject.dragView.getDragRegion();
        mDragCell[0] = cellX;
        mDragCell[1] = cellY;
        final int oldIndex = mDragOutlineCurrent;
        mDragOutlineAnims[oldIndex].animateOut();
        mDragOutlineCurrent = (oldIndex + 1) % mDragOutlines.length;
        Rect r = mDragOutlines[mDragOutlineCurrent];
        if (resize) {
            cellToRect(cellX, cellY, spanX, spanY, r);
            if (v instanceof LauncherAppWidgetHostView) {
                DeviceProfile profile = mActivity.getWallpaperDeviceProfile();
                Utilities.shrinkRect(r, profile.appWidgetScale.x, profile.appWidgetScale.y);
            }
        } else {
            // Find the top left corner of the rect the object will occupy
            final int[] topLeft = mTmpPoint;
            cellToPoint(cellX, cellY, topLeft);
            int left = topLeft[0];
            int top = topLeft[1];
            if (v != null && dragOffset == null) {
                // When drawing the drag outline, it did not account for margin offsets
                // added by the view's parent.
                MarginLayoutParams lp = (MarginLayoutParams) v.getLayoutParams();
                left += lp.leftMargin;
                top += lp.topMargin;
                // Offsets due to the size difference between the View and the dragOutline.
                // There is a size difference to account for the outer blur, which may lie
                // outside the bounds of the view.
                top += ((mCellHeight * spanY) - dragOutline.getHeight()) / 2;
                // We center about the x axis
                left += ((mCellWidth * spanX) - dragOutline.getWidth()) / 2;
            } else {
                if (dragOffset != null && dragRegion != null) {
                    // Center the drag region *horizontally* in the cell and apply a drag
                    // outline offset
                    left += dragOffset.x + ((mCellWidth * spanX) - dragRegion.width()) / 2;
                    int cHeight = getShortcutsAndWidgets().getCellContentHeight();
                    int cellPaddingY = (int) Math.max(0, ((mCellHeight - cHeight) / 2f));
                    top += dragOffset.y + cellPaddingY;
                } else {
                    // Center the drag outline in the cell
                    left += ((mCellWidth * spanX) - dragOutline.getWidth()) / 2;
                    top += ((mCellHeight * spanY) - dragOutline.getHeight()) / 2;
                }
            }
            r.set(left, top, left + dragOutline.getWidth(), top + dragOutline.getHeight());
        }
        Utilities.scaleRectAboutCenter(r, mChildScale);
        mDragOutlineAnims[mDragOutlineCurrent].setTag(dragOutline);
        mDragOutlineAnims[mDragOutlineCurrent].animateIn();
        if (dragObject.stateAnnouncer != null) {
            dragObject.stateAnnouncer.announce(getItemMoveDescription(cellX, cellY));
        }
    }
}
Also used : Bitmap(android.graphics.Bitmap) Rect(android.graphics.Rect) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) Point(android.graphics.Point) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Example 84 with DeviceProfile

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

the class LayoutUtils method calculateTaskSize.

@AnyThread
public static void calculateTaskSize(Context context, DeviceProfile dp, float extraVerticalSpace, @MultiWindowStrategy int multiWindowStrategy, Rect outRect) {
    float taskWidth, taskHeight, paddingHorz;
    Resources res = context.getResources();
    Rect insets = dp.getInsets();
    if (dp.isMultiWindowMode) {
        if (multiWindowStrategy == MULTI_WINDOW_STRATEGY_HALF_SCREEN) {
            DeviceProfile fullDp = dp.getFullScreenProfile();
            // Use availableWidthPx and availableHeightPx instead of widthPx and heightPx to
            // account for system insets
            taskWidth = fullDp.availableWidthPx;
            taskHeight = fullDp.availableHeightPx;
            float halfDividerSize = res.getDimension(R.dimen.multi_window_task_divider_size) / 2;
            if (fullDp.isLandscape) {
                taskWidth = taskWidth / 2 - halfDividerSize;
            } else {
                taskHeight = taskHeight / 2 - halfDividerSize;
            }
        } else {
            // multiWindowStrategy == MULTI_WINDOW_STRATEGY_DEVICE_PROFILE
            taskWidth = dp.widthPx;
            taskHeight = dp.heightPx;
        }
        paddingHorz = res.getDimension(R.dimen.multi_window_task_card_horz_space);
    } else {
        taskWidth = dp.availableWidthPx;
        taskHeight = dp.availableHeightPx;
        paddingHorz = res.getDimension(dp.isVerticalBarLayout() ? R.dimen.landscape_task_card_horz_space : R.dimen.portrait_task_card_horz_space);
    }
    float topIconMargin = res.getDimension(R.dimen.task_thumbnail_top_margin);
    float paddingVert = res.getDimension(R.dimen.task_card_vert_space);
    // Note this should be same as dp.availableWidthPx and dp.availableHeightPx unless
    // we override the insets ourselves.
    int launcherVisibleWidth = dp.widthPx - insets.left - insets.right;
    int launcherVisibleHeight = dp.heightPx - insets.top - insets.bottom;
    float availableHeight = launcherVisibleHeight - topIconMargin - extraVerticalSpace - paddingVert;
    float availableWidth = launcherVisibleWidth - paddingHorz;
    float scale = Math.min(availableWidth / taskWidth, availableHeight / taskHeight);
    float outWidth = scale * taskWidth;
    float outHeight = scale * taskHeight;
    // Center in the visible space
    float x = insets.left + (launcherVisibleWidth - outWidth) / 2;
    float y = insets.top + Math.max(topIconMargin, (launcherVisibleHeight - extraVerticalSpace - outHeight) / 2);
    outRect.set(Math.round(x), Math.round(y), Math.round(x) + Math.round(outWidth), Math.round(y) + Math.round(outHeight));
}
Also used : DeviceProfile(com.android.launcher3.DeviceProfile) Rect(android.graphics.Rect) Resources(android.content.res.Resources) AnyThread(androidx.annotation.AnyThread)

Example 85 with DeviceProfile

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

the class InvariantDeviceProfile method initGrid.

private String initGrid(Context context, String gridName) {
    DefaultDisplay.Info displayInfo = DefaultDisplay.INSTANCE.get(context).getInfo();
    Point smallestSize = new Point(displayInfo.smallestSize);
    Point largestSize = new Point(displayInfo.largestSize);
    // This guarantees that width < height
    float minWidthDps = Utilities.dpiFromPx(Math.min(smallestSize.x, smallestSize.y), displayInfo.metrics);
    float minHeightDps = Utilities.dpiFromPx(Math.min(largestSize.x, largestSize.y), displayInfo.metrics);
    Point realSize = new Point(displayInfo.realSize);
    // The real size never changes. smallSide and largeSide will remain the
    // same in any orientation.
    int smallSide = Math.min(realSize.x, realSize.y);
    int largeSide = max(realSize.x, realSize.y);
    // We want a list of all options as well as the list of filtered options. This allows us
    // to have a consistent UI for areas that the grid size change should not affect
    // ie. All Apps should be consistent between grid sizes.
    ArrayList<DisplayOption> allOptions = new ArrayList<>();
    ArrayList<DisplayOption> filteredOptions = new ArrayList<>();
    getPredefinedDeviceProfiles(context, gridName, filteredOptions, allOptions);
    if (allOptions.isEmpty() && filteredOptions.isEmpty()) {
        throw new RuntimeException("No display option with canBeDefault=true");
    }
    // Sort the profiles based on the closeness to the device size
    Comparator<DisplayOption> comparator = (a, b) -> Float.compare(dist(minWidthDps, minHeightDps, a.minWidthDps, a.minHeightDps), dist(minWidthDps, minHeightDps, b.minWidthDps, b.minHeightDps));
    // Calculate the device profiles as if there is no grid override.
    Collections.sort(allOptions, comparator);
    DisplayOption interpolatedDisplayOption = invDistWeightedInterpolate(minWidthDps, minHeightDps, allOptions);
    initGridOption(context, allOptions, interpolatedDisplayOption, displayInfo.metrics);
    // Create IDP with no grid override values.
    InvariantDeviceProfile originalIDP = new InvariantDeviceProfile(this);
    originalIDP.landscapeProfile = new DeviceProfile(context, this, null, smallestSize, largestSize, largeSide, smallSide, true, /* isLandscape */
    false);
    originalIDP.portraitProfile = new DeviceProfile(context, this, null, smallestSize, largestSize, smallSide, largeSide, false, /* isLandscape */
    false);
    if (filteredOptions.isEmpty()) {
        filteredOptions = allOptions;
        landscapeProfile = originalIDP.landscapeProfile;
        portraitProfile = originalIDP.portraitProfile;
    } else {
        Collections.sort(filteredOptions, comparator);
        interpolatedDisplayOption = invDistWeightedInterpolate(minWidthDps, minHeightDps, filteredOptions);
        initGridOption(context, filteredOptions, interpolatedDisplayOption, displayInfo.metrics);
        numAllAppsColumns = originalIDP.numAllAppsColumns;
        landscapeProfile = new DeviceProfile(context, this, originalIDP, smallestSize, largestSize, largeSide, smallSide, true, /* isLandscape */
        false);
        portraitProfile = new DeviceProfile(context, this, originalIDP, smallestSize, largestSize, smallSide, largeSide, false, /* isLandscape */
        false);
    }
    GridOption closestProfile = filteredOptions.get(0).grid;
    if (!closestProfile.name.equals(gridName)) {
        Utilities.getPrefs(context).edit().putString(KEY_IDP_GRID_NAME, closestProfile.name).apply();
    }
    // for the intended parallax effects
    if (context.getResources().getConfiguration().smallestScreenWidthDp >= 720) {
        defaultWallpaperSize = new Point((int) (largeSide * wallpaperTravelToScreenWidthRatio(largeSide, smallSide)), largeSide);
    } else {
        defaultWallpaperSize = new Point(max(smallSide * 2, largeSide), largeSide);
    }
    ComponentName cn = new ComponentName(context.getPackageName(), getClass().getName());
    defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null);
    return closestProfile.name;
}
Also used : Context(android.content.Context) Rect(android.graphics.Rect) APPLY_CONFIG_AT_RUNTIME(com.android.launcher3.config.FeatureFlags.APPLY_CONFIG_AT_RUNTIME) XmlResourceParser(android.content.res.XmlResourceParser) Intent(android.content.Intent) IconShape(com.android.launcher3.graphics.IconShape) TypedArray(android.content.res.TypedArray) ArrayList(java.util.ArrayList) DefaultDisplay(com.android.launcher3.util.DefaultDisplay) Utilities.getDevicePrefs(com.android.launcher3.Utilities.getDevicePrefs) AttributeSet(android.util.AttributeSet) AppWidgetHostView(android.appwidget.AppWidgetHostView) MAIN_EXECUTOR(com.android.launcher3.util.Executors.MAIN_EXECUTOR) TargetApi(android.annotation.TargetApi) Log(android.util.Log) IconShapeManager(com.saggitt.omega.adaptive.IconShapeManager) XmlPullParser(org.xmlpull.v1.XmlPullParser) IntArray(com.android.launcher3.util.IntArray) MainThreadInitializedObject(com.android.launcher3.util.MainThreadInitializedObject) GRID_OPTIONS_PREFERENCE_KEY(com.saggitt.omega.settings.SettingsActivity.GRID_OPTIONS_PREFERENCE_KEY) Xml(android.util.Xml) ComponentName(android.content.ComponentName) Point(android.graphics.Point) TextUtils(android.text.TextUtils) IOException(java.io.IOException) BroadcastReceiver(android.content.BroadcastReceiver) DisplayMetrics(android.util.DisplayMetrics) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) SparseArray(android.util.SparseArray) Nullable(androidx.annotation.Nullable) ConfigMonitor(com.android.launcher3.util.ConfigMonitor) PackageManagerHelper.getPackageFilter(com.android.launcher3.util.PackageManagerHelper.getPackageFilter) TypedValue(android.util.TypedValue) OmegaPreferences(com.saggitt.omega.OmegaPreferences) Configuration(android.content.res.Configuration) Math.max(java.lang.Math.max) Themes(com.android.launcher3.util.Themes) Comparator(java.util.Comparator) VisibleForTesting(androidx.annotation.VisibleForTesting) Collections(java.util.Collections) Resources(android.content.res.Resources) DefaultDisplay(com.android.launcher3.util.DefaultDisplay) ArrayList(java.util.ArrayList) Point(android.graphics.Point) Point(android.graphics.Point) ComponentName(android.content.ComponentName)

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