use of com.android.launcher3.DeviceProfile in project android_packages_apps_Launcher3 by AOSPA.
the class RecentsView method updateOrientationHandler.
private void updateOrientationHandler(boolean forceRecreateDragLayerControllers) {
// Handle orientation changes.
PagedOrientationHandler oldOrientationHandler = mOrientationHandler;
mOrientationHandler = mOrientationState.getOrientationHandler();
mIsRtl = mOrientationHandler.getRecentsRtlSetting(getResources());
setLayoutDirection(mIsRtl ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR);
mClearAllButton.setLayoutDirection(mIsRtl ? View.LAYOUT_DIRECTION_LTR : View.LAYOUT_DIRECTION_RTL);
mClearAllButton.setRotation(mOrientationHandler.getDegreesRotated());
if (forceRecreateDragLayerControllers || !mOrientationHandler.equals(oldOrientationHandler)) {
// Changed orientations, update controllers so they intercept accordingly.
mActivity.getDragLayer().recreateControllers();
onOrientationChanged();
}
boolean isInLandscape = mOrientationState.getTouchRotation() != ROTATION_0 || mOrientationState.getRecentsActivityRotation() != ROTATION_0;
mActionsView.updateHiddenFlags(HIDDEN_NON_ZERO_ROTATION, !mOrientationState.isRecentsActivityRotationAllowed() && isInLandscape);
// Update TaskView's DeviceProfile dependent layout.
updateChildTaskOrientations();
// Recalculate DeviceProfile dependent layout.
updateSizeAndPadding();
requestLayout();
// Reapply the current page to update page scrolls.
setCurrentPage(mCurrentPage);
}
use of com.android.launcher3.DeviceProfile in project android_packages_apps_Launcher3 by AOSPA.
the class RecentsView method setInsets.
@Override
public void setInsets(Rect insets) {
mInsets.set(insets);
// Update DeviceProfile dependant state.
DeviceProfile dp = mActivity.getDeviceProfile();
setOverviewGridEnabled(mActivity.getStateManager().getState().displayOverviewTasksAsGrid(dp));
setPageSpacing(dp.overviewPageSpacing);
// Propagate DeviceProfile change event.
runActionOnRemoteHandles(remoteTargetHandle -> remoteTargetHandle.getTaskViewSimulator().setDp(dp));
mActionsView.setDp(dp);
mOrientationState.setDeviceProfile(dp);
// Update RecentsView and TaskView's DeviceProfile dependent layout.
updateOrientationHandler();
}
use of com.android.launcher3.DeviceProfile in project android_packages_apps_Launcher3 by AOSPA.
the class DatabaseWidgetPreviewLoader method generateWidgetPreview.
/**
* Generates the widget preview from either the {@link WidgetManagerHelper} or cache
* and add badge at the bottom right corner.
*
* @param info information about the widget
* @param maxPreviewWidth width of the preview on either workspace or tray
* @param preScaledWidthOut return the width of the returned bitmap
*/
public Bitmap generateWidgetPreview(LauncherAppWidgetProviderInfo info, int maxPreviewWidth, int[] preScaledWidthOut) {
// Load the preview image if possible
if (maxPreviewWidth < 0)
maxPreviewWidth = Integer.MAX_VALUE;
Drawable drawable = null;
if (info.previewImage != 0) {
try {
drawable = info.loadPreviewImage(mContext, 0);
} catch (OutOfMemoryError e) {
Log.w(TAG, "Error loading widget preview for: " + info.provider, e);
// During OutOfMemoryError, the previous heap stack is not affected. Catching
// an OOM error here should be safe & not affect other parts of launcher.
drawable = null;
}
if (drawable != null) {
drawable = mutateOnMainThread(drawable);
} else {
Log.w(TAG, "Can't load widget preview drawable 0x" + Integer.toHexString(info.previewImage) + " for provider: " + info.provider);
}
}
final boolean widgetPreviewExists = (drawable != null);
final int spanX = info.spanX;
final int spanY = info.spanY;
int previewWidth;
int previewHeight;
DeviceProfile dp = ActivityContext.lookupContext(mContext).getDeviceProfile();
if (widgetPreviewExists && drawable.getIntrinsicWidth() > 0 && drawable.getIntrinsicHeight() > 0) {
previewWidth = drawable.getIntrinsicWidth();
previewHeight = drawable.getIntrinsicHeight();
} else {
Size widgetSize = WidgetSizes.getWidgetPaddedSizePx(mContext, info.provider, dp, spanX, spanY);
previewWidth = widgetSize.getWidth();
previewHeight = widgetSize.getHeight();
}
if (preScaledWidthOut != null) {
preScaledWidthOut[0] = previewWidth;
}
// Scale to fit width only - let the widget preview be clipped in the
// vertical dimension
final float scale = previewWidth > maxPreviewWidth ? (maxPreviewWidth / (float) (previewWidth)) : 1f;
if (scale != 1f) {
previewWidth = Math.max((int) (scale * previewWidth), 1);
previewHeight = Math.max((int) (scale * previewHeight), 1);
}
final int previewWidthF = previewWidth;
final int previewHeightF = previewHeight;
final Drawable drawableF = drawable;
return BitmapRenderer.createHardwareBitmap(previewWidth, previewHeight, c -> {
// Draw the scaled preview into the final bitmap
if (widgetPreviewExists) {
drawableF.setBounds(0, 0, previewWidthF, previewHeightF);
drawableF.draw(c);
} else {
RectF boxRect;
// Draw horizontal and vertical lines to represent individual columns.
final Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
if (Utilities.ATLEAST_S) {
boxRect = new RectF(/* left= */
0, /* top= */
0, /* right= */
previewWidthF, /* bottom= */
previewHeightF);
p.setStyle(Paint.Style.FILL);
p.setColor(Color.WHITE);
float roundedCorner = mContext.getResources().getDimension(android.R.dimen.system_app_widget_background_radius);
c.drawRoundRect(boxRect, roundedCorner, roundedCorner, p);
} else {
boxRect = drawBoxWithShadow(c, previewWidthF, previewHeightF);
}
p.setStyle(Paint.Style.STROKE);
p.setStrokeWidth(mContext.getResources().getDimension(R.dimen.widget_preview_cell_divider_width));
p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
float t = boxRect.left;
float tileSize = boxRect.width() / spanX;
for (int i = 1; i < spanX; i++) {
t += tileSize;
c.drawLine(t, 0, t, previewHeightF, p);
}
t = boxRect.top;
tileSize = boxRect.height() / spanY;
for (int i = 1; i < spanY; i++) {
t += tileSize;
c.drawLine(0, t, previewWidthF, t, p);
}
// Draw icon in the center.
try {
Drawable icon = LauncherAppState.getInstance(mContext).getIconCache().getFullResIcon(info.provider.getPackageName(), info.icon);
if (icon != null) {
int appIconSize = dp.iconSizePx;
int iconSize = (int) Math.min(appIconSize * scale, Math.min(boxRect.width(), boxRect.height()));
icon = mutateOnMainThread(icon);
int hoffset = (previewWidthF - iconSize) / 2;
int yoffset = (previewHeightF - iconSize) / 2;
icon.setBounds(hoffset, yoffset, hoffset + iconSize, yoffset + iconSize);
icon.draw(c);
}
} catch (Resources.NotFoundException e) {
}
}
});
}
use of com.android.launcher3.DeviceProfile in project android_packages_apps_Launcher3 by AOSPA.
the class PendingAppWidgetHostView method updateDrawableBounds.
private void updateDrawableBounds() {
DeviceProfile grid = mLauncher.getDeviceProfile();
int paddingTop = getPaddingTop();
int paddingBottom = getPaddingBottom();
int paddingLeft = getPaddingLeft();
int paddingRight = getPaddingRight();
int minPadding = getResources().getDimensionPixelSize(R.dimen.pending_widget_min_padding);
int availableWidth = getWidth() - paddingLeft - paddingRight - 2 * minPadding;
int availableHeight = getHeight() - paddingTop - paddingBottom - 2 * minPadding;
if (mSettingIconDrawable == null) {
int maxSize = grid.iconSizePx;
int size = Math.min(maxSize, Math.min(availableWidth, availableHeight));
mRect.set(0, 0, size, size);
mRect.offsetTo((getWidth() - mRect.width()) / 2, (getHeight() - mRect.height()) / 2);
mCenterDrawable.setBounds(mRect);
} else {
float iconSize = Math.max(0, Math.min(availableWidth, availableHeight));
// Use twice the setting size factor, as the setting is drawn at a corner and the
// icon is drawn in the center.
float settingIconScaleFactor = 1 + SETUP_ICON_SIZE_FACTOR * 2;
int maxSize = Math.max(availableWidth, availableHeight);
if (iconSize * settingIconScaleFactor > maxSize) {
// There is an overlap
iconSize = maxSize / settingIconScaleFactor;
}
int actualIconSize = (int) Math.min(iconSize, grid.iconSizePx);
// Icon top when we do not draw the text
int iconTop = (getHeight() - actualIconSize) / 2;
mSetupTextLayout = null;
if (availableWidth > 0) {
// Recreate the setup text.
mSetupTextLayout = new StaticLayout(getResources().getText(R.string.gadget_complete_setup_text), mPaint, availableWidth, Layout.Alignment.ALIGN_CENTER, 1, 0, true);
int textHeight = mSetupTextLayout.getHeight();
// Extra icon size due to the setting icon
float minHeightWithText = textHeight + actualIconSize * settingIconScaleFactor + grid.iconDrawablePaddingPx;
if (minHeightWithText < availableHeight) {
// We can draw the text as well
iconTop = (getHeight() - textHeight - grid.iconDrawablePaddingPx - actualIconSize) / 2;
} else {
// We can't draw the text. Let the iconTop be same as before.
mSetupTextLayout = null;
}
}
mRect.set(0, 0, actualIconSize, actualIconSize);
mRect.offset((getWidth() - actualIconSize) / 2, iconTop);
mCenterDrawable.setBounds(mRect);
mRect.left = paddingLeft + minPadding;
mRect.right = mRect.left + (int) (SETUP_ICON_SIZE_FACTOR * actualIconSize);
mRect.top = paddingTop + minPadding;
mRect.bottom = mRect.top + (int) (SETUP_ICON_SIZE_FACTOR * actualIconSize);
mSettingIconDrawable.setBounds(mRect);
if (mSetupTextLayout != null) {
// Set up position for dragging the text
mRect.left = paddingLeft + minPadding;
mRect.top = mCenterDrawable.getBounds().bottom + grid.iconDrawablePaddingPx;
}
}
}
use of com.android.launcher3.DeviceProfile in project android_packages_apps_Launcher3 by AOSPA.
the class PendingItemDragHelper method startDrag.
/**
* Starts the drag for the pending item associated with the view.
*
* @param previewBounds The bounds where the image was displayed,
* {@link WidgetImageView#getBitmapBounds()}
* @param previewBitmapWidth The actual width of the bitmap displayed in the view.
* @param previewViewWidth The width of {@link WidgetImageView} displaying the preview
* @param screenPos Position of {@link WidgetImageView} on the screen
*/
public void startDrag(Rect previewBounds, int previewBitmapWidth, int previewViewWidth, Point screenPos, DragSource source, DragOptions options) {
if (TestProtocol.sDebugTracing) {
Log.d(TestProtocol.NO_DROP_TARGET, "3");
}
final Launcher launcher = Launcher.getLauncher(mView.getContext());
LauncherAppState app = LauncherAppState.getInstance(launcher);
Drawable preview = null;
final int previewWidth;
final int previewHeight;
final float scale;
final Point dragOffset;
final Rect dragRegion;
mEstimatedCellSize = launcher.getWorkspace().estimateItemSize(mAddInfo);
DraggableView draggableView;
if (mAddInfo instanceof PendingAddWidgetInfo) {
PendingAddWidgetInfo createWidgetInfo = (PendingAddWidgetInfo) mAddInfo;
int maxWidth = Math.min((int) (previewBitmapWidth * MAX_WIDGET_SCALE), mEstimatedCellSize[0]);
int[] previewSizeBeforeScale = new int[1];
if (mRemoteViewsPreview != null) {
mAppWidgetHostViewPreview = new LauncherAppWidgetHostView(launcher);
mAppWidgetHostViewPreview.setAppWidget(/* appWidgetId= */
-1, ((PendingAddWidgetInfo) mAddInfo).info);
DeviceProfile deviceProfile = launcher.getDeviceProfile();
Rect padding = new Rect();
mAppWidgetHostViewPreview.getWidgetInset(deviceProfile, padding);
mAppWidgetHostViewPreview.setPadding(padding.left, padding.top, padding.right, padding.bottom);
mAppWidgetHostViewPreview.updateAppWidget(/* remoteViews= */
mRemoteViewsPreview);
Size widgetSizes = WidgetSizes.getWidgetPaddedSizePx(launcher, mAddInfo.componentName, deviceProfile, mAddInfo.spanX, mAddInfo.spanY);
mAppWidgetHostViewPreview.measure(MeasureSpec.makeMeasureSpec(widgetSizes.getWidth(), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(widgetSizes.getHeight(), MeasureSpec.EXACTLY));
mAppWidgetHostViewPreview.setClipChildren(false);
mAppWidgetHostViewPreview.setClipToPadding(false);
mAppWidgetHostViewPreview.setScaleToFit(mRemoteViewsPreviewScale);
}
if (mAppWidgetHostViewPreview != null) {
previewSizeBeforeScale[0] = mAppWidgetHostViewPreview.getMeasuredWidth();
launcher.getDragController().addDragListener(new AppWidgetHostViewDragListener(launcher));
}
if (preview == null && mAppWidgetHostViewPreview == null) {
Drawable p = new FastBitmapDrawable(new DatabaseWidgetPreviewLoader(launcher).generateWidgetPreview(createWidgetInfo.info, maxWidth, previewSizeBeforeScale));
if (RoundedCornerEnforcement.isRoundedCornerEnabled()) {
p = new RoundDrawableWrapper(p, mEnforcedRoundedCornersForWidget);
}
preview = p;
}
if (previewSizeBeforeScale[0] < previewBitmapWidth) {
// The icon has extra padding around it.
int padding = (previewBitmapWidth - previewSizeBeforeScale[0]) / 2;
if (previewBitmapWidth > previewViewWidth) {
padding = padding * previewViewWidth / previewBitmapWidth;
}
previewBounds.left += padding;
previewBounds.right -= padding;
}
if (mAppWidgetHostViewPreview != null) {
previewWidth = mAppWidgetHostViewPreview.getMeasuredWidth();
previewHeight = mAppWidgetHostViewPreview.getMeasuredHeight();
} else {
previewWidth = preview.getIntrinsicWidth();
previewHeight = preview.getIntrinsicHeight();
}
scale = previewBounds.width() / (float) previewWidth;
launcher.getDragController().addDragListener(new WidgetHostViewLoader(launcher, mView));
dragOffset = null;
dragRegion = null;
draggableView = DraggableView.ofType(DraggableView.DRAGGABLE_WIDGET);
} else {
PendingAddShortcutInfo createShortcutInfo = (PendingAddShortcutInfo) mAddInfo;
Drawable icon = createShortcutInfo.activityInfo.getFullResIcon(app.getIconCache());
LauncherIcons li = LauncherIcons.obtain(launcher);
preview = new FastBitmapDrawable(li.createScaledBitmapWithoutShadow(icon, 0));
previewWidth = preview.getIntrinsicWidth();
previewHeight = preview.getIntrinsicHeight();
li.recycle();
scale = ((float) launcher.getDeviceProfile().iconSizePx) / previewWidth;
dragOffset = new Point(previewPadding / 2, previewPadding / 2);
// Create a preview same as the workspace cell size and draw the icon at the
// appropriate position.
DeviceProfile dp = launcher.getDeviceProfile();
int iconSize = dp.iconSizePx;
int padding = launcher.getResources().getDimensionPixelSize(R.dimen.widget_preview_shortcut_padding);
previewBounds.left += padding;
previewBounds.top += padding;
dragRegion = new Rect();
dragRegion.left = (mEstimatedCellSize[0] - iconSize) / 2;
dragRegion.right = dragRegion.left + iconSize;
dragRegion.top = (mEstimatedCellSize[1] - iconSize - dp.iconTextSizePx - dp.iconDrawablePaddingPx) / 2;
dragRegion.bottom = dragRegion.top + iconSize;
draggableView = DraggableView.ofType(DraggableView.DRAGGABLE_ICON);
}
int dragLayerX = screenPos.x + previewBounds.left + (int) ((scale * previewWidth - previewWidth) / 2);
int dragLayerY = screenPos.y + previewBounds.top + (int) ((scale * previewHeight - previewHeight) / 2);
// Start the drag
if (mAppWidgetHostViewPreview != null) {
launcher.getDragController().startDrag(mAppWidgetHostViewPreview, draggableView, dragLayerX, dragLayerY, source, mAddInfo, dragOffset, dragRegion, scale, scale, options);
} else {
launcher.getDragController().startDrag(preview, draggableView, dragLayerX, dragLayerY, source, mAddInfo, dragOffset, dragRegion, scale, scale, options);
}
}
Aggregations