use of com.android.launcher3.model.data.ItemInfo in project Launcher3 by chislon.
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();
boolean[][] occupied = mOccupied;
if (!permanent) {
occupied = mTmpOccupied;
}
if (clc.indexOfChild(child) != -1) {
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
final ItemInfo info = (ItemInfo) child.getTag();
// We cancel any existing animations
if (mReorderAnimators.containsKey(lp)) {
mReorderAnimators.get(lp).cancel();
mReorderAnimators.remove(lp);
}
final int oldX = lp.x;
final int oldY = lp.y;
if (adjustOccupied) {
occupied[lp.cellX][lp.cellY] = false;
occupied[cellX][cellY] = true;
}
lp.isLockedToGrid = true;
if (permanent) {
lp.cellX = info.cellX = cellX;
lp.cellY = info.cellY = cellY;
} else {
lp.tmpCellX = cellX;
lp.tmpCellY = cellY;
}
clc.setupLp(lp);
lp.isLockedToGrid = false;
final int newX = lp.x;
final int newY = lp.y;
lp.x = oldX;
lp.y = oldY;
// Exit early if we're not actually moving the view
if (oldX == newX && oldY == newY) {
lp.isLockedToGrid = true;
return true;
}
ValueAnimator va = LauncherAnimUtils.ofFloat(child, 0f, 1f);
va.setDuration(duration);
mReorderAnimators.put(lp, va);
va.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float r = ((Float) animation.getAnimatedValue()).floatValue();
lp.x = (int) ((1 - r) * oldX + r * newX);
lp.y = (int) ((1 - r) * oldY + r * newY);
child.requestLayout();
}
});
va.addListener(new AnimatorListenerAdapter() {
boolean cancelled = false;
public void onAnimationEnd(Animator animation) {
// place just yet.
if (!cancelled) {
lp.isLockedToGrid = true;
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.model.data.ItemInfo in project android_packages_apps_Launcher3 by crdroidandroid.
the class HotseatEduController method showEdu.
void showEdu() {
int childCount = mHotseat.getShortcutsAndWidgets().getChildCount();
CellLayout cellLayout = mLauncher.getWorkspace().getScreenWithId(Workspace.FIRST_SCREEN_ID);
// hotseat is already empty and does not require migration. show edu tip
boolean requiresMigration = IntStream.range(0, childCount).anyMatch(i -> {
View v = mHotseat.getShortcutsAndWidgets().getChildAt(i);
return v != null && v.getTag() != null && ((ItemInfo) v.getTag()).container != LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION;
});
boolean canMigrateToFirstPage = cellLayout.makeSpaceForHotseatMigration(false);
if (requiresMigration && canMigrateToFirstPage) {
showDialog();
} else {
new ArrowTipView(mLauncher).show(mLauncher.getString(requiresMigration ? R.string.hotseat_tip_no_empty_slots : R.string.hotseat_auto_enrolled), mHotseat.getTop());
mLauncher.getStatsLogManager().logger().log(LAUNCHER_HOTSEAT_EDU_ONLY_TIP);
finishOnboarding();
}
}
use of com.android.launcher3.model.data.ItemInfo in project android_packages_apps_Launcher3 by crdroidandroid.
the class HotseatEduController method migrateToFolder.
/**
* This migration places all non folder items in the hotseat into a folder and then moves
* all folders in the hotseat to a workspace page that has enough empty spots.
*
* @return pageId that has accepted the items.
*/
private int migrateToFolder() {
ArrayDeque<FolderInfo> folders = new ArrayDeque<>();
ArrayList<WorkspaceItemInfo> putIntoFolder = new ArrayList<>();
// separate folders and items that can get in folders
for (int i = 0; i < mLauncher.getDeviceProfile().numShownHotseatIcons; i++) {
View view = mHotseat.getChildAt(i, 0);
if (view == null)
continue;
ItemInfo info = (ItemInfo) view.getTag();
if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_FOLDER) {
folders.add((FolderInfo) info);
} else if (info instanceof WorkspaceItemInfo && info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
putIntoFolder.add((WorkspaceItemInfo) info);
}
}
// create a temp folder and add non folder items to it
if (!putIntoFolder.isEmpty()) {
ItemInfo firstItem = putIntoFolder.get(0);
FolderInfo folderInfo = new FolderInfo();
mLauncher.getModelWriter().addItemToDatabase(folderInfo, firstItem.container, firstItem.screenId, firstItem.cellX, firstItem.cellY);
folderInfo.setTitle("", mLauncher.getModelWriter());
folderInfo.contents.addAll(putIntoFolder);
for (int i = 0; i < folderInfo.contents.size(); i++) {
ItemInfo item = folderInfo.contents.get(i);
item.rank = i;
mLauncher.getModelWriter().moveItemInDatabase(item, folderInfo.id, 0, item.cellX, item.cellY);
}
folders.add(folderInfo);
}
mNewItems.addAll(folders);
return placeFoldersInWorkspace(folders);
}
use of com.android.launcher3.model.data.ItemInfo in project android_packages_apps_Launcher3 by crdroidandroid.
the class HotseatPredictionController method pinPrediction.
/**
* Pins a predicted app icon into place.
*/
public void pinPrediction(ItemInfo info) {
PredictedAppIcon icon = (PredictedAppIcon) mHotseat.getChildAt(mHotseat.getCellXFromOrder(info.rank), mHotseat.getCellYFromOrder(info.rank));
if (icon == null) {
return;
}
WorkspaceItemInfo workspaceItemInfo = new WorkspaceItemInfo((WorkspaceItemInfo) info);
mLauncher.getModelWriter().addItemToDatabase(workspaceItemInfo, LauncherSettings.Favorites.CONTAINER_HOTSEAT, workspaceItemInfo.screenId, workspaceItemInfo.cellX, workspaceItemInfo.cellY);
ObjectAnimator.ofFloat(icon, SCALE_PROPERTY, 1, 0.8f, 1).start();
icon.pin(workspaceItemInfo);
mLauncher.getStatsLogManager().logger().withItemInfo(workspaceItemInfo).log(LAUNCHER_HOTSEAT_PREDICTION_PINNED);
}
use of com.android.launcher3.model.data.ItemInfo in project android_packages_apps_Launcher3 by crdroidandroid.
the class HotseatPredictionController method logLaunchedAppRankingInfo.
/**
* Logs rank info based on current list of predicted items
*/
public void logLaunchedAppRankingInfo(@NonNull ItemInfo itemInfo, InstanceId instanceId) {
ComponentName targetCN = itemInfo.getTargetComponent();
if (targetCN == null) {
return;
}
int rank = -1;
for (int i = mPredictedItems.size() - 1; i >= 0; i--) {
ItemInfo info = mPredictedItems.get(i);
if (targetCN.equals(info.getTargetComponent()) && itemInfo.user.equals(info.user)) {
rank = i;
break;
}
}
if (rank < 0) {
return;
}
int cardinality = 0;
for (PredictedAppIcon icon : getPredictedIcons()) {
ItemInfo info = (ItemInfo) icon.getTag();
cardinality |= 1 << info.screenId;
}
PredictedHotseatContainer.Builder containerBuilder = PredictedHotseatContainer.newBuilder();
containerBuilder.setCardinality(cardinality);
if (itemInfo.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION) {
containerBuilder.setIndex(rank);
}
mLauncher.getStatsLogManager().logger().withInstanceId(instanceId).withRank(rank).withContainerInfo(ContainerInfo.newBuilder().setPredictedHotseatContainer(containerBuilder).build()).log(LAUNCHER_HOTSEAT_RANKED);
}
Aggregations