summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/widget/WidgetsListAdapter.java
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2017-02-07 13:11:17 -0800
committerSunny Goyal <sunnygoyal@google.com>2017-02-09 10:16:22 -0800
commitd5d5e22715c19c361d264693929c15c4325e80fa (patch)
treede664e7f61c2088de817483d57860a83a1f87228 /src/com/android/launcher3/widget/WidgetsListAdapter.java
parentdb7b82960a54b85510aaeba2f543b37b4dc59fc8 (diff)
downloadandroid_packages_apps_Trebuchet-d5d5e22715c19c361d264693929c15c4325e80fa.tar.gz
android_packages_apps_Trebuchet-d5d5e22715c19c361d264693929c15c4325e80fa.tar.bz2
android_packages_apps_Trebuchet-d5d5e22715c19c361d264693929c15c4325e80fa.zip
Updating widget tray theme
Using standard theme attributes rather than custom color codes, so that it plays nice with system theme changes. Bug: 34819119 Bug: 34897402 Bug: 21446746 Change-Id: I265fba3ceae8873650fd09e4704838d313155e83
Diffstat (limited to 'src/com/android/launcher3/widget/WidgetsListAdapter.java')
-rw-r--r--src/com/android/launcher3/widget/WidgetsListAdapter.java44
1 files changed, 27 insertions, 17 deletions
diff --git a/src/com/android/launcher3/widget/WidgetsListAdapter.java b/src/com/android/launcher3/widget/WidgetsListAdapter.java
index 60e6e2ac2..38210fc97 100644
--- a/src/com/android/launcher3/widget/WidgetsListAdapter.java
+++ b/src/com/android/launcher3/widget/WidgetsListAdapter.java
@@ -113,20 +113,27 @@ public class WidgetsListAdapter extends Adapter<WidgetsRowViewHolder> {
// Add more views.
// if there are too many, hide them.
- int diff = infoList.size() - row.getChildCount();
-
- if (diff > 0) {
- for (int i = 0; i < diff; i++) {
- WidgetCell widget = (WidgetCell) mLayoutInflater.inflate(
- R.layout.widget_cell, row, false);
-
- // set up touch.
- widget.setOnClickListener(mIconClickListener);
- widget.setOnLongClickListener(mIconLongClickListener);
- row.addView(widget);
+ int expectedChildCount = infoList.size() + Math.max(0, infoList.size() - 1);
+ int childCount = row.getChildCount();
+
+ if (expectedChildCount > childCount) {
+ for (int i = childCount ; i < expectedChildCount; i++) {
+ if ((i & 1) == 1) {
+ // Add a divider for odd index
+ mLayoutInflater.inflate(R.layout.widget_list_divider, row);
+ } else {
+ // Add cell for even index
+ WidgetCell widget = (WidgetCell) mLayoutInflater.inflate(
+ R.layout.widget_cell, row, false);
+
+ // set up touch.
+ widget.setOnClickListener(mIconClickListener);
+ widget.setOnLongClickListener(mIconLongClickListener);
+ row.addView(widget);
+ }
}
- } else if (diff < 0) {
- for (int i=infoList.size() ; i < row.getChildCount(); i++) {
+ } else if (expectedChildCount < childCount) {
+ for (int i = expectedChildCount ; i < childCount; i++) {
row.getChildAt(i).setVisibility(View.GONE);
}
}
@@ -136,10 +143,14 @@ public class WidgetsListAdapter extends Adapter<WidgetsRowViewHolder> {
// Bind the view in the widget horizontal tray region.
for (int i=0; i < infoList.size(); i++) {
- WidgetCell widget = (WidgetCell) row.getChildAt(i);
+ WidgetCell widget = (WidgetCell) row.getChildAt(2*i);
widget.applyFromCellItem(infoList.get(i), mWidgetPreviewLoader);
widget.ensurePreview();
widget.setVisibility(View.VISIBLE);
+
+ if (i > 0) {
+ row.getChildAt(2*i - 1).setVisibility(View.VISIBLE);
+ }
}
}
@@ -151,11 +162,10 @@ public class WidgetsListAdapter extends Adapter<WidgetsRowViewHolder> {
ViewGroup container = (ViewGroup) mLayoutInflater.inflate(
R.layout.widgets_list_row_view, parent, false);
- LinearLayout cellList = (LinearLayout) container.findViewById(R.id.widgets_cell_list);
// if the end padding is 0, then container view (horizontal scroll view) doesn't respect
// the end of the linear layout width + the start padding and doesn't allow scrolling.
- cellList.setPaddingRelative(mIndent, 0, 1, 0);
+ container.findViewById(R.id.widgets_cell_list).setPaddingRelative(mIndent, 0, 1, 0);
return new WidgetsRowViewHolder(container);
}
@@ -163,7 +173,7 @@ public class WidgetsListAdapter extends Adapter<WidgetsRowViewHolder> {
@Override
public void onViewRecycled(WidgetsRowViewHolder holder) {
int total = holder.cellContainer.getChildCount();
- for (int i = 0; i < total; i++) {
+ for (int i = 0; i < total; i+=2) {
WidgetCell widget = (WidgetCell) holder.cellContainer.getChildAt(i);
widget.clear();
}