use of com.android.launcher3.R in project android_packages_apps_Launcher3 by crdroidandroid.
the class ArrowPopup method inflateAndAdd.
/**
* Utility method for inflating and adding a view
*/
public <R extends View> R inflateAndAdd(int resId, ViewGroup container, int index) {
View view = mInflater.inflate(resId, container, false);
container.addView(view, index);
return (R) view;
}
use of com.android.launcher3.R in project android_packages_apps_Launcher3 by crdroidandroid.
the class CellLayout method animateChildToPosition.
public boolean animateChildToPosition(final View child, int cellX, int cellY, int duration, int delay, boolean permanent, boolean adjustOccupied) {
ShortcutAndWidgetContainer clc = getShortcutsAndWidgets();
if (clc.indexOfChild(child) != -1 && (child instanceof Reorderable)) {
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
final ItemInfo info = (ItemInfo) child.getTag();
final Reorderable item = (Reorderable) child;
// We cancel any existing animations
if (mReorderAnimators.containsKey(lp)) {
mReorderAnimators.get(lp).cancel();
mReorderAnimators.remove(lp);
}
if (adjustOccupied) {
GridOccupancy occupied = permanent ? mOccupied : mTmpOccupied;
occupied.markCells(lp.cellX, lp.cellY, lp.cellHSpan, lp.cellVSpan, false);
occupied.markCells(cellX, cellY, lp.cellHSpan, lp.cellVSpan, true);
}
// Compute the new x and y position based on the new cellX and cellY
// We leverage the actual layout logic in the layout params and hence need to modify
// state and revert that state.
final int oldX = lp.x;
final int oldY = lp.y;
lp.isLockedToGrid = true;
if (permanent) {
lp.cellX = info.cellX = cellX;
lp.cellY = info.cellY = cellY;
} else {
lp.tmpCellX = cellX;
lp.tmpCellY = cellY;
}
clc.setupLp(child);
final int newX = lp.x;
final int newY = lp.y;
lp.x = oldX;
lp.y = oldY;
lp.isLockedToGrid = false;
// End compute new x and y
item.getReorderPreviewOffset(mTmpPointF);
final float initPreviewOffsetX = mTmpPointF.x;
final float initPreviewOffsetY = mTmpPointF.y;
final float finalPreviewOffsetX = newX - oldX;
final float finalPreviewOffsetY = newY - oldY;
// Exit early if we're not actually moving the view
if (finalPreviewOffsetX == 0 && finalPreviewOffsetY == 0 && initPreviewOffsetX == 0 && initPreviewOffsetY == 0) {
lp.isLockedToGrid = true;
return true;
}
ValueAnimator va = ValueAnimator.ofFloat(0f, 1f);
va.setDuration(duration);
mReorderAnimators.put(lp, va);
va.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float r = (Float) animation.getAnimatedValue();
float x = (1 - r) * initPreviewOffsetX + r * finalPreviewOffsetX;
float y = (1 - r) * initPreviewOffsetY + r * finalPreviewOffsetY;
item.setReorderPreviewOffset(x, y);
}
});
va.addListener(new AnimatorListenerAdapter() {
boolean cancelled = false;
public void onAnimationEnd(Animator animation) {
// place just yet.
if (!cancelled) {
lp.isLockedToGrid = true;
item.setReorderPreviewOffset(0, 0);
child.requestLayout();
}
if (mReorderAnimators.containsKey(lp)) {
mReorderAnimators.remove(lp);
}
}
public void onAnimationCancel(Animator animation) {
cancelled = true;
}
});
va.setStartDelay(delay);
va.start();
return true;
}
return false;
}
use of com.android.launcher3.R in project android_packages_apps_Launcher3 by crdroidandroid.
the class AppWidgetResizeFrame method onLayout.
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
if (Utilities.ATLEAST_Q) {
for (int i = 0; i < HANDLE_COUNT; i++) {
View dragHandle = mDragHandles[i];
mSystemGestureExclusionRects.get(i).set(dragHandle.getLeft(), dragHandle.getTop(), dragHandle.getRight(), dragHandle.getBottom());
}
setSystemGestureExclusionRects(mSystemGestureExclusionRects);
}
}
use of com.android.launcher3.R in project android_packages_apps_Launcher3 by crdroidandroid.
the class BaseDragLayer method onLayout.
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
int count = getChildCount();
for (int i = 0; i < count; i++) {
View child = getChildAt(i);
final FrameLayout.LayoutParams flp = (FrameLayout.LayoutParams) child.getLayoutParams();
if (flp instanceof LayoutParams) {
final LayoutParams lp = (LayoutParams) flp;
if (lp.customPosition) {
child.layout(lp.x, lp.y, lp.x + lp.width, lp.y + lp.height);
}
}
}
}
use of com.android.launcher3.R in project Launcher3 by chislon.
the class CellLayout method onDraw.
@Override
protected void onDraw(Canvas canvas) {
// backgrounds
if (mBackgroundAlpha > 0.0f) {
Drawable bg;
if (mUseActiveGlowBackground) {
// In the mini case, we draw the active_glow bg *over* the active background
bg = mActiveGlowBackground;
} else {
bg = mNormalBackground;
}
bg.setAlpha((int) (mBackgroundAlpha * mBackgroundAlphaMultiplier * 255));
bg.setBounds(mBackgroundRect);
bg.draw(canvas);
}
final Paint paint = mDragOutlinePaint;
for (int i = 0; i < mDragOutlines.length; i++) {
final float alpha = mDragOutlineAlphas[i];
if (alpha > 0) {
final Rect r = mDragOutlines[i];
mTempRect.set(r);
Utilities.scaleRectAboutCenter(mTempRect, getChildrenScale());
final Bitmap b = (Bitmap) mDragOutlineAnims[i].getTag();
paint.setAlpha((int) (alpha + .5f));
canvas.drawBitmap(b, null, mTempRect, paint);
}
}
// requires an expanded clip rect (due to the glow's blur radius)
if (mPressedOrFocusedIcon != null) {
final int padding = mPressedOrFocusedIcon.getPressedOrFocusedBackgroundPadding();
final Bitmap b = mPressedOrFocusedIcon.getPressedOrFocusedBackground();
if (b != null) {
int offset = getMeasuredWidth() - getPaddingLeft() - getPaddingRight() - (mCountX * mCellWidth);
int left = getPaddingLeft() + (int) Math.ceil(offset / 2f);
int top = getPaddingTop();
canvas.drawBitmap(b, mPressedOrFocusedIcon.getLeft() + left - padding, mPressedOrFocusedIcon.getTop() + top - padding, null);
}
}
if (DEBUG_VISUALIZE_OCCUPIED) {
int[] pt = new int[2];
ColorDrawable cd = new ColorDrawable(Color.RED);
cd.setBounds(0, 0, mCellWidth, mCellHeight);
for (int i = 0; i < mCountX; i++) {
for (int j = 0; j < mCountY; j++) {
if (mOccupied[i][j]) {
cellToPoint(i, j, pt);
canvas.save();
canvas.translate(pt[0], pt[1]);
cd.draw(canvas);
canvas.restore();
}
}
}
}
int previewOffset = FolderRingAnimator.sPreviewSize;
// The folder outer / inner ring image(s)
LauncherAppState app = LauncherAppState.getInstance();
DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
for (int i = 0; i < mFolderOuterRings.size(); i++) {
FolderRingAnimator fra = mFolderOuterRings.get(i);
Drawable d;
int width, height;
cellToPoint(fra.mCellX, fra.mCellY, mTempLocation);
View child = getChildAt(fra.mCellX, fra.mCellY);
if (child != null) {
int centerX = mTempLocation[0] + mCellWidth / 2;
int centerY = mTempLocation[1] + previewOffset / 2 + child.getPaddingTop() + grid.folderBackgroundOffset;
// Draw outer ring, if it exists
if (FolderIcon.HAS_OUTER_RING) {
d = FolderRingAnimator.sSharedOuterRingDrawable;
width = (int) (fra.getOuterRingSize() * getChildrenScale());
height = width;
canvas.save();
canvas.translate(centerX - width / 2, centerY - height / 2);
d.setBounds(0, 0, width, height);
d.draw(canvas);
canvas.restore();
}
// Draw inner ring
d = FolderRingAnimator.sSharedInnerRingDrawable;
width = (int) (fra.getInnerRingSize() * getChildrenScale());
height = width;
canvas.save();
canvas.translate(centerX - width / 2, centerY - width / 2);
d.setBounds(0, 0, width, height);
d.draw(canvas);
canvas.restore();
}
}
if (mFolderLeaveBehindCell[0] >= 0 && mFolderLeaveBehindCell[1] >= 0) {
Drawable d = FolderIcon.sSharedFolderLeaveBehind;
int width = d.getIntrinsicWidth();
int height = d.getIntrinsicHeight();
cellToPoint(mFolderLeaveBehindCell[0], mFolderLeaveBehindCell[1], mTempLocation);
View child = getChildAt(mFolderLeaveBehindCell[0], mFolderLeaveBehindCell[1]);
if (child != null) {
int centerX = mTempLocation[0] + mCellWidth / 2;
int centerY = mTempLocation[1] + previewOffset / 2 + child.getPaddingTop() + grid.folderBackgroundOffset;
canvas.save();
canvas.translate(centerX - width / 2, centerY - width / 2);
d.setBounds(0, 0, width, height);
d.draw(canvas);
canvas.restore();
}
}
}
Aggregations