diff options
Diffstat (limited to 'src/com/android/launcher3/Folder.java')
-rw-r--r-- | src/com/android/launcher3/Folder.java | 134 |
1 files changed, 97 insertions, 37 deletions
diff --git a/src/com/android/launcher3/Folder.java b/src/com/android/launcher3/Folder.java index d10be4efc..4cc328c5a 100644 --- a/src/com/android/launcher3/Folder.java +++ b/src/com/android/launcher3/Folder.java @@ -62,7 +62,9 @@ import android.widget.ScrollView; import android.widget.TextView; import com.android.launcher3.FolderInfo.FolderListener; +import com.android.launcher3.compat.UserHandleCompat; import com.android.launcher3.settings.SettingsProvider; +import com.cyngn.RemoteFolder.RemoteFolderUpdater; import java.util.ArrayList; import java.util.Collections; @@ -232,7 +234,7 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList mContent.setGridSize(0, 0); mContent.getShortcutsAndWidgets().setMotionEventSplittingEnabled(false); mContent.setInvertIfRtl(true); - mFolderNameLockContainer = findViewById(R.id.folder_name_lock_container); + mFolderName = (FolderEditText) findViewById(R.id.folder_name); mFolderName.setFolder(this); mFolderName.setOnFocusChangeListener(this); @@ -257,11 +259,15 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList mFolderName.setVisibility(View.GONE); } + mFolderNameLockContainer = findViewById(R.id.folder_name_lock_container); mFolderLock = (ImageView) findViewById(R.id.folder_lock); - mFolderLock.measure(measureSpec, measureSpec); - mFolderLock.setOnClickListener(this); - mFolderLockHeight = mFolderLock.getMeasuredHeight(); + // Could be null if this Folder an instance of the RemoteFolder subclass + if (mFolderLock != null) { + mFolderLock.measure(measureSpec, measureSpec); + mFolderLock.setOnClickListener(this); + mFolderLockHeight = mFolderLock.getMeasuredHeight(); + } DisplayMetrics displayMetrics = this.getResources().getDisplayMetrics(); mScreenWidth = displayMetrics.widthPixels; } @@ -476,39 +482,73 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList } } - void bind(FolderInfo info) { + void bind(final FolderInfo info) { mInfo = info; - ArrayList<ShortcutInfo> children = info.contents; - ArrayList<ShortcutInfo> overflow = new ArrayList<ShortcutInfo>(); - setupContentForNumItems(children.size()); - placeInReadingOrder(children); - int count = 0; - for (int i = 0; i < children.size(); i++) { - ShortcutInfo child = (ShortcutInfo) children.get(i); - if (createAndAddShortcut(child) == null) { - overflow.add(child); - } else { - count++; + final ArrayList<ShortcutInfo> children = info.contents; + + if (info.subType == FolderInfo.REMOTE_SUBTYPE && children.isEmpty()) { + final int count = 6; + RemoteFolderUpdater updater = mLauncher.getRemoteFolderUpdaterInstance(); + updater.requestSync(getContext(), count, new RemoteFolderUpdater.RemoteFolderUpdateListener() { + @Override + public void onSuccess(List<RemoteFolderUpdater.RemoteFolderInfo> remoteFolderInfoList) { + children.clear(); + for (RemoteFolderUpdater.RemoteFolderInfo remoteFolderInfo : remoteFolderInfoList) { + ShortcutInfo shortcutInfo = new ShortcutInfo(remoteFolderInfo.getIntent(), + remoteFolderInfo.getTitle(), + remoteFolderInfo.getTitle(), + remoteFolderInfo.getIcon(), + UserHandleCompat.myUserHandle()); + children.add(shortcutInfo); + + View child = mLauncher.createShortcut(R.layout.application, mContent, + shortcutInfo); + remoteFolderInfo.setRecommendationData(child); + LauncherModel.addOrMoveItemInDatabase(mLauncher, shortcutInfo, info.container, + info.screenId, info.cellX, info.cellY); + } + info.contents = children; + bind(info); + } + + @Override + public void onFailure(String error) { + Log.e(TAG, "Failed to sync data for the remote folder's shortcuts. Reason: " + error); + setupContentForNumItems(count); + } + }); + } else { + ArrayList<ShortcutInfo> overflow = new ArrayList<ShortcutInfo>(); + setupContentForNumItems(children.size()); + placeInReadingOrder(children); + int count = 0; + for (int i = 0; i < children.size(); i++) { + ShortcutInfo child = (ShortcutInfo) children.get(i); + if (createAndAddShortcut(child) == null) { + overflow.add(child); + } else { + count++; + } } - } - // We rearrange the items in case there are any empty gaps - setupContentForNumItems(count); + // We rearrange the items in case there are any empty gaps + setupContentForNumItems(count); - // If our folder has too many items we prune them from the list. This is an issue - // when upgrading from the old Folders implementation which could contain an unlimited - // number of items. - for (ShortcutInfo item: overflow) { - mInfo.remove(item); - LauncherModel.deleteItemFromDatabase(mLauncher, item); - } + // If our folder has too many items we prune them from the list. This is an issue + // when upgrading from the old Folders implementation which could contain an unlimited + // number of items. + for (ShortcutInfo item: overflow) { + mInfo.remove(item); + LauncherModel.deleteItemFromDatabase(mLauncher, item); + } - mItemsInvalidated = true; - updateTextViewFocus(); - mInfo.addListener(this); + mItemsInvalidated = true; + updateTextViewFocus(); + mInfo.addListener(this); - setFolderName(); - updateItemLocationsInDatabase(); + setFolderName(); + updateItemLocationsInDatabase(); + } } public void setFolderName() { @@ -658,12 +698,19 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList Animator circReveal = LauncherAnimUtils.createCircularReveal(this, circX, circY, 0, mScreenWidth); - final View[] alphaViewSet = new View[] { mFolderNameLockContainer, - mContent, mFolderName, mFolderLock }; + final View[] alphaViewSet; + if (mInfo.subType == FolderInfo.REMOTE_SUBTYPE) { + alphaViewSet = new View[] { mContent, mFolderName }; + } else { + alphaViewSet = new View[] { mFolderNameLockContainer, + mContent, mFolderName, mFolderLock }; + } + for (View view : alphaViewSet) { view.setAlpha(0f); } + circReveal.setDuration(150); circReveal.addListener(new AnimatorListenerAdapter() { @Override @@ -1371,15 +1418,15 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList centerAboutIcon(); } - private int getContentAreaHeight() { + 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() { + protected int getFolderHeight() { int height = getPaddingTop() + getPaddingBottom() + mFolderNameHeight + getContentAreaHeight(); return height; @@ -1405,8 +1452,10 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList mFolderName.measure(contentAreaWidthSpec, MeasureSpec.makeMeasureSpec( mFolderNameHeight, MeasureSpec.EXACTLY)); } + mFolderNameLockContainer.measure(contentAreaWidthSpec, - MeasureSpec.makeMeasureSpec(mFolderNameHeight,MeasureSpec.EXACTLY)); + MeasureSpec.makeMeasureSpec(mFolderNameHeight, MeasureSpec.EXACTLY)); + setMeasuredDimension(width, height); } @@ -1468,6 +1517,10 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList } private void replaceFolderWithFinalItem() { + if (mInfo.subType == FolderInfo.REMOTE_SUBTYPE) { + return; + } + if (mInfo.hidden && getItemCount() >= 1) { return; } @@ -1626,6 +1679,13 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList createAndAddShortcut(item); LauncherModel.addOrMoveItemInDatabase( mLauncher, item, mInfo.id, 0, item.cellX, item.cellY); + + // If this is a Remote Folder, we need to register each view with our updater for click handling. + if (mInfo.subType == FolderInfo.REMOTE_SUBTYPE) { + RemoteFolderUpdater updater = mLauncher.getModel().getRemoteFolderUpdaterInstance(); + updater.registerViewForInteraction(getViewForInfo(item), item.getIntent()); + } + } public void onRemove(ShortcutInfo item) { |