blob: d0dd733a629ae6c599905da6666093a00e11c50f [file] [log] [blame]
Winson Chungb745afb2015-03-02 11:51:23 -08001package com.android.launcher3;
2
3import android.content.Context;
4import android.util.AttributeSet;
5import android.widget.FrameLayout;
6
7import java.util.ArrayList;
8import java.util.LinkedHashMap;
9import java.util.List;
10import java.util.Map;
11
12
13class SectionedWidgetsRow {
14 String section;
15 List<List<Object>> widgets;
16
17 public SectionedWidgetsRow(String sc) {
18 section = sc;
19 }
20}
21
22class SectionedWidgetsAlgorithm {
23 public List<SectionedWidgetsRow> computeSectionedWidgetRows(List<Object> sortedWidgets,
24 int widgetsPerRow) {
25 List<SectionedWidgetsRow> rows = new ArrayList<>();
26 LinkedHashMap<String, List<Object>> sections = computeSectionedApps(sortedWidgets);
27 for (Map.Entry<String, List<Object>> sectionEntry : sections.entrySet()) {
28 String section = sectionEntry.getKey();
29 SectionedWidgetsRow row = new SectionedWidgetsRow(section);
30 List<Object> widgets = sectionEntry.getValue();
31 int numRows = (int) Math.ceil((float) widgets.size() / widgetsPerRow);
32 for (int i = 0; i < numRows; i++) {
33 List<Object> widgetsInRow = new ArrayList<>();
34 int offset = i * widgetsPerRow;
35 for (int j = 0; j < widgetsPerRow; j++) {
36 widgetsInRow.add(widgets.get(offset + j));
37 }
38 row.widgets.add(widgetsInRow);
39 }
40 }
41 return rows;
42 }
43
44 private LinkedHashMap<String, List<Object>> computeSectionedApps(List<Object> sortedWidgets) {
45 LinkedHashMap<String, List<Object>> sections = new LinkedHashMap<>();
46 for (Object info : sortedWidgets) {
47 String section = getSection(info);
48 List<Object> sectionedWidgets = sections.get(section);
49 if (sectionedWidgets == null) {
50 sectionedWidgets = new ArrayList<>();
51 sections.put(section, sectionedWidgets);
52 }
53 sectionedWidgets.add(info);
54 }
55 return sections;
56 }
57
58 private String getSection(Object widgetOrShortcut) {
59 return "UNKNOWN";
60 }
61}
62
63/**
64 * The widgets list view container.
65 */
66public class WidgetsContainerView extends FrameLayout {
67
68
69 public WidgetsContainerView(Context context) {
70 this(context, null);
71 }
72
73 public WidgetsContainerView(Context context, AttributeSet attrs) {
74 this(context, attrs, 0);
75 }
76
77 public WidgetsContainerView(Context context, AttributeSet attrs, int defStyleAttr) {
78 this(context, attrs, defStyleAttr, 0);
79 }
80
81 public WidgetsContainerView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
82 super(context, attrs, defStyleAttr, defStyleRes);
83 }
84
85 @Override
86 protected void onFinishInflate() {
87 }
88}