summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/Folder.java
diff options
context:
space:
mode:
authorTyson Miller <tmiller@cyngn.com>2015-11-10 08:59:15 -0800
committerGerrit Code Review <gerrit@cyanogenmod.org>2016-01-28 17:00:28 -0800
commit7df0227f6a835641a3d41327a65845806ef070fb (patch)
tree3fcf92a1fba468facc675ad47accb08ec2f9f907 /src/com/android/launcher3/Folder.java
parent84dfd2a560442953af78aa77dbd6c909aed63589 (diff)
downloadandroid_packages_apps_Trebuchet-7df0227f6a835641a3d41327a65845806ef070fb.tar.gz
android_packages_apps_Trebuchet-7df0227f6a835641a3d41327a65845806ef070fb.tar.bz2
android_packages_apps_Trebuchet-7df0227f6a835641a3d41327a65845806ef070fb.zip
Port Remote Folder from 12.1 to 13.
Change-Id: If8cf9d5f054e8948ead702883b79f28db26c4d8b
Diffstat (limited to 'src/com/android/launcher3/Folder.java')
-rw-r--r--src/com/android/launcher3/Folder.java192
1 files changed, 106 insertions, 86 deletions
diff --git a/src/com/android/launcher3/Folder.java b/src/com/android/launcher3/Folder.java
index ccb12b62a..bcc274d9e 100644
--- a/src/com/android/launcher3/Folder.java
+++ b/src/com/android/launcher3/Folder.java
@@ -227,10 +227,6 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
mContent = (FolderPagedView) findViewById(R.id.folder_content);
mContent.setFolder(this);
- // We find out how tall footer wants to be (it is set to wrap_content), so that
- // we can allocate the appropriate amount of space for it.
- int measureSpec = MeasureSpec.UNSPECIFIED;
-
mFolderName = (ExtendedEditText) findViewById(R.id.folder_name);
mFolderName.setOnBackKeyListener(new ExtendedEditText.OnBackKeyListener() {
@Override
@@ -256,14 +252,9 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
mFolderName.setVisibility(View.GONE);
}
mFolderLock = (ImageView) findViewById(R.id.folder_lock);
- mFolderLock.measure(measureSpec, measureSpec);
mFolderLock.setOnClickListener(this);
- mFolderLockHeight = mFolderLock.getMeasuredHeight();
mFooter = findViewById(R.id.folder_footer);
-
- mFooter.measure(measureSpec, measureSpec);
- mFooterHeight = mFooter.getMeasuredHeight();
}
private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
@@ -458,7 +449,7 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
return mInfo;
}
- void bind(FolderInfo info) {
+ void bind(final FolderInfo info) {
mInfo = info;
ArrayList<ShortcutInfo> children = info.contents;
Collections.sort(children, ITEM_POS_COMPARATOR);
@@ -473,14 +464,6 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
LauncherModel.deleteItemFromDatabase(mLauncher, item);
}
- DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
- if (lp == null) {
- lp = new DragLayer.LayoutParams(0, 0);
- lp.customPosition = true;
- setLayoutParams(lp);
- }
- centerAboutIcon();
-
mItemsInvalidated = true;
updateTextViewFocus();
mInfo.addListener(this);
@@ -509,12 +492,13 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
* Creates a new UserFolder, inflated from R.layout.user_folder.
*
* @param context The application's context.
+ * @param root The {@link View} parent of this folder.
*
* @return A new UserFolder.
*/
@SuppressLint("InflateParams")
- static Folder fromXml(Launcher launcher) {
- return (Folder) launcher.getLayoutInflater().inflate(R.layout.user_folder, null);
+ static Folder fromXml(Launcher launcher, ViewGroup root) {
+ return (Folder) launcher.getLayoutInflater().inflate(R.layout.user_folder, root, false);
}
/**
@@ -542,6 +526,7 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
}
private void prepareFakeFolderIcon() {
+ mFolderIcon.destroyDrawingCache();
mFolderIcon.buildDrawingCache(true);
Bitmap fakeFolderIcon = Bitmap.createBitmap(mFolderIcon.getDrawingCache());
@@ -568,7 +553,7 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
fakeFolderIconView.setVisibility(View.INVISIBLE);
}
- public void animateOpen(Workspace workspace, int[] folderTouch) {
+ public void animateOpen() {
if (!(getParent() instanceof DragLayer)) return;
mContent.completePendingPageChanges();
@@ -581,7 +566,7 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
final Runnable onCompleteRunnable;
if (!Utilities.ATLEAST_LOLLIPOP) {
positionAndSizeAsIcon();
- centerAboutIcon();
+ calculatePivot();
PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1);
PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
@@ -599,11 +584,11 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
}
};
} else {
- centerAboutIcon();
+ calculatePivot();
AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
- int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
- int height = getFolderHeight();
+ int width = getMeasuredWidth();
+ int height = getMeasuredHeight();
float transX = - 0.075f * (width / 2 - getPivotX());
float transY = - 0.075f * (height / 2 - getPivotY());
@@ -1156,7 +1141,16 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
// Do nothing
}
+ /**
+ * @return true if contents should persist their status to the database.
+ */
+ protected boolean shouldUpdateContentsInDatabase() {
+ return true;
+ }
+
private void updateItemLocationsInDatabaseBatch() {
+ if (!shouldUpdateContentsInDatabase()) return;
+
ArrayList<View> list = getItemsInReadingOrder();
ArrayList<ItemInfo> items = new ArrayList<ItemInfo>();
for (int i = 0; i < list.size(); i++) {
@@ -1170,6 +1164,8 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
}
public void addItemLocationsInDatabase() {
+ if (!shouldUpdateContentsInDatabase()) return;
+
ArrayList<View> list = getItemsInReadingOrder();
for (int i = 0; i < list.size(); i++) {
View v = list.get(i);
@@ -1193,12 +1189,22 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
return mContent.isFull();
}
- private void centerAboutIcon() {
- DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
+ protected void calculatePivot() {
+ int width = getMeasuredWidth();
+ int height = getMeasuredHeight();
+
+ // If we haven't measured ourselves yet, force one now to determine our dimensions.
+ if (width <= 0 && height <= 0) {
+ measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
+ width = getMeasuredWidth();
+ height = getMeasuredHeight();
+ }
+
+ calculatePivot(width, height);
+ }
+ private void calculatePivot(int width, int height) {
DragLayer parent = (DragLayer) mLauncher.findViewById(R.id.drag_layer);
- int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
- int height = getFolderHeight();
float scale = parent.getDescendantRectRelativeToSelf(mFolderIcon, sTempRect);
@@ -1234,11 +1240,6 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
(1.0f * folderPivotX / width));
mFolderIconPivotY = (int) (mFolderIcon.getMeasuredHeight() *
(1.0f * folderPivotY / height));
-
- lp.width = width;
- lp.height = height;
- lp.x = left;
- lp.y = top;
}
float getPivotXForIconAnimation() {
@@ -1248,53 +1249,18 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
return mFolderIconPivotY;
}
- private int getContentAreaHeight() {
- DeviceProfile grid = mLauncher.getDeviceProfile();
- Rect workspacePadding = grid.getWorkspacePadding(mContent.mIsRtl);
- int maxContentAreaHeight = grid.availableHeightPx -
- workspacePadding.top - workspacePadding.bottom -
- mFooterHeight;
- int height = Math.min(maxContentAreaHeight,
- mContent.getDesiredHeight());
- return Math.max(height, MIN_CONTENT_DIMEN);
+ protected int getContentAreaHeight() {
+ return Math.max(mContent.getDesiredHeight(), MIN_CONTENT_DIMEN);
}
- private int getContentAreaWidth() {
+ protected int getContentAreaWidth() {
return Math.max(mContent.getDesiredWidth(), MIN_CONTENT_DIMEN);
}
- private int getFolderHeight() {
- return getFolderHeight(getContentAreaHeight());
- }
-
- private int getFolderHeight(int contentAreaHeight) {
- return getPaddingTop() + getPaddingBottom() + contentAreaHeight + mFooterHeight;
- }
-
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- int contentWidth = getContentAreaWidth();
- int contentHeight = getContentAreaHeight();
-
- int contentAreaWidthSpec = MeasureSpec.makeMeasureSpec(contentWidth, MeasureSpec.EXACTLY);
- int contentAreaHeightSpec = MeasureSpec.makeMeasureSpec(contentHeight, MeasureSpec.EXACTLY);
+ mContent.setFixedSize(getContentAreaWidth(), getContentAreaHeight());
- mContent.setFixedSize(contentWidth, contentHeight);
- mContentWrapper.measure(contentAreaWidthSpec, contentAreaHeightSpec);
-
- if (mContent.getChildCount() > 0) {
- int cellIconGap = (mContent.getPageAt(0).getCellWidth()
- - mLauncher.getDeviceProfile().iconSizePx) / 2;
- mFooter.setPadding(mContent.getPaddingLeft() + cellIconGap,
- mFooter.getPaddingTop(),
- mContent.getPaddingRight() + cellIconGap,
- mFooter.getPaddingBottom());
- }
- mFooter.measure(contentAreaWidthSpec,
- MeasureSpec.makeMeasureSpec(mFooterHeight, MeasureSpec.EXACTLY));
-
- int folderWidth = getPaddingLeft() + getPaddingRight() + contentWidth;
- int folderHeight = getFolderHeight(contentHeight);
- setMeasuredDimension(folderWidth, folderHeight);
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
/**
@@ -1445,8 +1411,10 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
currentDragView = mContent.createAndAddViewForRank(si, mEmptyCellRank);
// Actually move the item in the database if it was an external drag. Call this
// before creating the view, so that ShortcutInfo is updated appropriately.
- LauncherModel.addOrMoveItemInDatabase(
- mLauncher, si, mInfo.id, 0, si.cellX, si.cellY);
+ if (shouldUpdateContentsInDatabase()) {
+ LauncherModel.addOrMoveItemInDatabase(
+ mLauncher, si, mInfo.id, 0, si.cellX, si.cellY);
+ }
// We only need to update the locations if it doesn't get handled in #onDropCompleted.
if (d.dragSource != this) {
@@ -1509,8 +1477,11 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
if (mSuppressOnAdd) return;
mContent.createAndAddViewForRank(item, mContent.allocateRankForNewItem(item));
mItemsInvalidated = true;
- LauncherModel.addOrMoveItemInDatabase(
- mLauncher, item, mInfo.id, 0, item.cellX, item.cellY);
+
+ if (shouldUpdateContentsInDatabase()) {
+ LauncherModel.addOrMoveItemInDatabase(
+ mLauncher, item, mInfo.id, 0, item.cellX, item.cellY);
+ }
}
public void onRemove(ShortcutInfo item) {
@@ -1518,8 +1489,7 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
// If this item is being dragged from this open folder, we have already handled
// the work associated with removing the item, so we don't have to do anything here.
if (item == mCurrentDragInfo) return;
- View v = getViewForInfo(item);
- mContent.removeItem(v);
+ mContent.removeItem(getViewForInfo(item));
if (mState == STATE_ANIMATING) {
mRearrangeOnClose = true;
} else {
@@ -1530,14 +1500,64 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
}
}
- private View getViewForInfo(final ShortcutInfo item) {
- return mContent.iterateOverItems(new ItemOperator() {
+ @Override
+ public void onRemoveAll() {
+ // Clear the UX after folder contents are removed from the DB
+ removeViewsForItems(null);
+ mLauncher.closeFolder(this);
+ replaceFolderWithFinalItem();
+ }
- @Override
- public boolean evaluate(ItemInfo info, View view, View parent) {
- return info == item;
+ @Override
+ public void onRemoveAll(ArrayList<ShortcutInfo> items) {
+ removeViewsForItems(items);
+ if (mState == STATE_ANIMATING) {
+ mRearrangeOnClose = true;
+ } else {
+ rearrangeChildren();
+ }
+ if (mInfo.contents.isEmpty()) {
+ mLauncher.closeFolder(this);
+ }
+ replaceFolderWithFinalItem();
+ }
+
+ /**
+ * Remove all the supplied item views from this folder.
+ * @param items info of views to remove, or null if all views should be removed.
+ */
+ protected void removeViewsForItems(ArrayList<ShortcutInfo> items) {
+ mItemsInvalidated = true;
+ if (items == null) {
+ mContent.removeAllItems();
+ } else {
+ for (ShortcutInfo item : items) {
+ mContent.removeItem(getViewForInfo(item));
}
- });
+ }
+ }
+
+ /**
+ * Update the view tied to this shortcut.
+ * @param info updated info to be applied to view.
+ */
+ @SuppressWarnings("unused")
+ public void updateViewForInfo(final ShortcutInfo info) {
+ View v = getViewForInfo(info);
+ if (v != null & v instanceof BubbleTextView) {
+ ((BubbleTextView) v).reapplyItemInfo(info);
+
+ mItemsInvalidated = true;
+ }
+ }
+
+ public View getViewForInfo(ShortcutInfo item) {
+ View v = mContent.getChildAtRank(item.rank);
+ if (v != null && v.getTag() == item) {
+ return v;
+ }
+
+ return null;
}
public void onItemsChanged() {