summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/widget
diff options
context:
space:
mode:
authorTony Wickham <twickham@google.com>2017-03-20 17:12:24 -0700
committerTony <twickham@google.com>2017-03-30 16:35:56 -0700
commit26b1746593851e239bfff65ae7a69b809ad87b99 (patch)
tree4f5a73f3253d52304a0f105aa03c2a882038b14a /src/com/android/launcher3/widget
parent4a907d0f9d1c80661c086aa95a8509698f38b324 (diff)
downloadandroid_packages_apps_Trebuchet-26b1746593851e239bfff65ae7a69b809ad87b99.tar.gz
android_packages_apps_Trebuchet-26b1746593851e239bfff65ae7a69b809ad87b99.tar.bz2
android_packages_apps_Trebuchet-26b1746593851e239bfff65ae7a69b809ad87b99.zip
Add support for system shortcuts in popup container
- Currently the system shortcuts are just widgets and app info - As shortcuts, they live in ShortcutsItemView - They are populated either as icons only (if there are deep shortcuts) or as icons + text - Widgets are disabled until binding them is complete (we request for them to be bound on long-press now). We should revisit this. Bug: 34940468 Change-Id: Ia51d002c3b3ede87658bdab57abfc3eeca1ed242
Diffstat (limited to 'src/com/android/launcher3/widget')
-rw-r--r--src/com/android/launcher3/widget/WidgetCell.java10
-rw-r--r--src/com/android/launcher3/widget/WidgetsAndMore.java35
-rw-r--r--src/com/android/launcher3/widget/WidgetsContainerView.java7
-rw-r--r--src/com/android/launcher3/widget/WidgetsListAdapter.java23
4 files changed, 63 insertions, 12 deletions
diff --git a/src/com/android/launcher3/widget/WidgetCell.java b/src/com/android/launcher3/widget/WidgetCell.java
index 72effd471..40dbd523c 100644
--- a/src/com/android/launcher3/widget/WidgetCell.java
+++ b/src/com/android/launcher3/widget/WidgetCell.java
@@ -155,6 +155,10 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener {
}
public void applyPreview(Bitmap bitmap) {
+ applyPreview(bitmap, true);
+ }
+
+ public void applyPreview(Bitmap bitmap, boolean animate) {
if (bitmap != null) {
mWidgetImage.setBitmap(bitmap,
DrawableFactory.get(getContext()).getBadgeForUser(mItem.user, getContext()));
@@ -169,11 +173,15 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener {
}
public void ensurePreview() {
+ ensurePreview(true);
+ }
+
+ public void ensurePreview(boolean animate) {
if (mActiveRequest != null) {
return;
}
mActiveRequest = mWidgetPreviewLoader.getPreview(
- mItem, mPresetPreviewSize, mPresetPreviewSize, this);
+ mItem, mPresetPreviewSize, mPresetPreviewSize, this, animate);
}
@Override
diff --git a/src/com/android/launcher3/widget/WidgetsAndMore.java b/src/com/android/launcher3/widget/WidgetsAndMore.java
index 3ed2530b3..1aea534fd 100644
--- a/src/com/android/launcher3/widget/WidgetsAndMore.java
+++ b/src/com/android/launcher3/widget/WidgetsAndMore.java
@@ -46,12 +46,15 @@ import com.android.launcher3.dragndrop.DragController;
import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.model.WidgetItem;
import com.android.launcher3.userevent.nano.LauncherLogProto;
+import com.android.launcher3.util.PackageUserKey;
import com.android.launcher3.util.TouchController;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import static android.R.attr.bottom;
+
/**
* Bottom sheet for the "Widgets & more" long-press option.
*/
@@ -64,6 +67,7 @@ public class WidgetsAndMore extends AbstractFloatingView implements Insettable,
private float mTranslationYRange;
private Launcher mLauncher;
+ private ItemInfo mOriginalItemInfo;
private ObjectAnimator mOpenCloseAnimator;
private Interpolator mFastOutSlowInInterpolator;
private VerticalPullDetector.ScrollInterpolator mScrollInterpolator;
@@ -95,9 +99,25 @@ public class WidgetsAndMore extends AbstractFloatingView implements Insettable,
mTranslationYRange = mTranslationYClosed - mTranslationYOpen;
}
- public void populateAndShow(ItemInfo itemInfo, List<WidgetItem> widgets) {
- ((TextView) findViewById(R.id.title)).setText(itemInfo.title);
+ public void populateAndShow(ItemInfo itemInfo) {
+ mOriginalItemInfo = itemInfo;
+ ((TextView) findViewById(R.id.title)).setText(mOriginalItemInfo.title);
+
+ onWidgetsBound();
+
+ mWasNavBarLight = (mLauncher.getWindow().getDecorView().getSystemUiVisibility()
+ & View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR) != 0;
+ mLauncher.getDragLayer().addView(this);
+ measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
+ setTranslationY(mTranslationYClosed);
+ mIsOpen = false;
+ open(true);
+ }
+ @Override
+ protected void onWidgetsBound() {
+ List<WidgetItem> widgets = mLauncher.getWidgetsForPackageUser(new PackageUserKey(
+ mOriginalItemInfo.getTargetComponent().getPackageName(), mOriginalItemInfo.user));
List<WidgetItem> shortcuts = new ArrayList<>();
// Transfer configurable widgets to shortcuts
Iterator<WidgetItem> widgetsIter = widgets.iterator();
@@ -116,6 +136,9 @@ public class WidgetsAndMore extends AbstractFloatingView implements Insettable,
ViewGroup shortcutRow = (ViewGroup) findViewById(R.id.shortcuts);
ViewGroup shortcutCells = (ViewGroup) shortcutRow.findViewById(R.id.widgets_cell_list);
+ widgetCells.removeAllViews();
+ shortcutCells.removeAllViews();
+
for (int i = 0; i < widgets.size(); i++) {
addItemCell(widgetCells);
if (i < widgets.size() - 1) {
@@ -152,14 +175,6 @@ public class WidgetsAndMore extends AbstractFloatingView implements Insettable,
} else {
removeView(findViewById(R.id.shortcuts_header));
}
-
- mWasNavBarLight = (mLauncher.getWindow().getDecorView().getSystemUiVisibility()
- & View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR) != 0;
- mLauncher.getDragLayer().addView(this);
- measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
- setTranslationY(mTranslationYClosed);
- mIsOpen = false;
- open(true);
}
private void addDivider(ViewGroup parent) {
diff --git a/src/com/android/launcher3/widget/WidgetsContainerView.java b/src/com/android/launcher3/widget/WidgetsContainerView.java
index ba6ed41f6..4e296bf41 100644
--- a/src/com/android/launcher3/widget/WidgetsContainerView.java
+++ b/src/com/android/launcher3/widget/WidgetsContainerView.java
@@ -40,8 +40,11 @@ import com.android.launcher3.model.WidgetItem;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
import com.android.launcher3.util.MultiHashMap;
+import com.android.launcher3.util.PackageUserKey;
import com.android.launcher3.util.Thunk;
+import java.util.List;
+
/**
* The widgets list view container.
*/
@@ -243,6 +246,10 @@ public class WidgetsContainerView extends BaseContainerView
return mAdapter.getItemCount() == 0;
}
+ public List<WidgetItem> getWidgetsForPackageUser(PackageUserKey packageUserKey) {
+ return mAdapter.copyWidgetsForPackageUser(packageUserKey);
+ }
+
@Override
public void fillInLogContainerData(View v, ItemInfo info, Target target, Target targetParent) {
targetParent.containerType = ContainerType.WIDGETS;
diff --git a/src/com/android/launcher3/widget/WidgetsListAdapter.java b/src/com/android/launcher3/widget/WidgetsListAdapter.java
index 38210fc97..a1eb0ab12 100644
--- a/src/com/android/launcher3/widget/WidgetsListAdapter.java
+++ b/src/com/android/launcher3/widget/WidgetsListAdapter.java
@@ -22,7 +22,6 @@ import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import android.widget.LinearLayout;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.R;
@@ -32,10 +31,12 @@ import com.android.launcher3.model.PackageItemInfo;
import com.android.launcher3.model.WidgetItem;
import com.android.launcher3.util.LabelComparator;
import com.android.launcher3.util.MultiHashMap;
+import com.android.launcher3.util.PackageUserKey;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -99,6 +100,26 @@ public class WidgetsListAdapter extends Adapter<WidgetsRowViewHolder> {
return mEntries.get(pos).titleSectionName;
}
+ /**
+ * Copies and returns the widgets associated with the package and user of the ComponentKey.
+ */
+ public List<WidgetItem> copyWidgetsForPackageUser(PackageUserKey packageUserKey) {
+ for (WidgetListRowEntry entry : mEntries) {
+ if (entry.pkgItem.packageName.equals(packageUserKey.mPackageName)) {
+ ArrayList<WidgetItem> widgets = new ArrayList<>(entry.widgets);
+ // Remove widgets not associated with the correct user.
+ Iterator<WidgetItem> iterator = widgets.iterator();
+ while (iterator.hasNext()) {
+ if (!iterator.next().user.equals(packageUserKey.mUser)) {
+ iterator.remove();
+ }
+ }
+ return widgets.isEmpty() ? null : widgets;
+ }
+ }
+ return null;
+ }
+
@Override
public void onBindViewHolder(WidgetsRowViewHolder holder, int pos) {
WidgetListRowEntry entry = mEntries.get(pos);