summaryrefslogtreecommitdiffstats
path: root/src/com/google/android/canvas/data/Cluster.java
blob: ab6aaedccbabbf6bf6c9f3efe07a4b0a9d09c6d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
// Copyright 2012 Google Inc. All Rights Reserved.

package com.google.android.canvas.data;

import android.content.Intent;
import android.net.Uri;

import java.util.ArrayList;
import java.util.List;

/**
 * Represents a home screen cluster.
 */
public class Cluster {

    private long mId;
    private String mName;
    private CharSequence mDisplayName;
    private int mImportance;
    private int mVisibleCount;
    private boolean mImageCropAllowed;
    private long mCacheTimeMs;
    private Intent mIntent;

    private List<ClusterItem> mClusterItems;

    /**
     * An item displayed inside a cluster.
     */
    public static class ClusterItem {
        private Uri mImageUri;

        ClusterItem(Uri imageUri) {
            mImageUri = imageUri;
        }

        public Uri getImageUri() {
            return mImageUri;
        }

        @Override
        public String toString() {
            StringBuilder builder = new StringBuilder();
            builder.append("imageUri: ").append(mImageUri);
            return builder.toString();
        }
    }

    public Cluster() {
        mClusterItems = new ArrayList<ClusterItem>();
        mImageCropAllowed = true;
    }

    public long getId() {
        return mId;
    }

    public String getName() {
        return mName;
    }

    public CharSequence getDisplayName() {
        return mDisplayName;
    }

    public int getImportance() {
        return mImportance;
    }

    public int getVisibleCount() {
        return mVisibleCount;
    }

    public boolean isImageCropAllowed() {
        return mImageCropAllowed;
    }

    public long getCacheTimeMs() {
        return mCacheTimeMs;
    }

    public Intent getIntent() {
        return mIntent;
    }

    public int getItemCount() {
        return mClusterItems.size();
    }

    public ClusterItem getItem(int position) {
        if (position >= 0 && position < mClusterItems.size()) {
            return mClusterItems.get(position);
        }
        return null;
    }

    void addClusterItem(ClusterItem item) {
        mClusterItems.add(item);
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append("id: ").append(mId)
                .append(", name: ").append(mName)
                .append(", displayName: ").append(mDisplayName)
                .append(", importance: ").append(mImportance)
                .append(", visibleCount: ").append(mVisibleCount)
                .append(", imageCropAllowed: ").append(mImageCropAllowed)
                .append(", cacheTimeMs: ").append(mCacheTimeMs)
                .append(", intent: ").append(mIntent.toUri(0));
        return builder.toString();
    }

    /**
     * Builds cluster objects.
     */
    public static class Builder {
        private long mId;
        private String mName;
        private CharSequence mDisplayName;
        private int mImportance;
        private int mVisibleCount;
        private boolean mImageCropAllowed;
        private long mCacheTimeMs;
        private Intent mIntent;

        private List<ClusterItem> mClusterItems;

        public Cluster build() {
            Cluster cluster = new Cluster();
            cluster.mId = mId;
            cluster.mName = mName;
            cluster.mDisplayName = mDisplayName;
            cluster.mImportance = mImportance;
            cluster.mVisibleCount = mVisibleCount;
            cluster.mImageCropAllowed = mImageCropAllowed;
            cluster.mIntent = mIntent;
            cluster.mCacheTimeMs = mCacheTimeMs;
            cluster.mClusterItems.addAll(mClusterItems);
            return cluster;
        }

        public Builder() {
            mClusterItems = new ArrayList<ClusterItem>();
            mImageCropAllowed = true;
        }

        public Builder id(long id) {
            mId = id;
            return this;
        }

        public Builder name(String name) {
            mName = name;
            return this;
        }

        public Builder displayName(CharSequence displayName) {
            mDisplayName = displayName;
            return this;
        }

        public Builder importance(int importance) {
            mImportance = importance;
            return this;
        }

        public Builder visibleCount(int visibleCount) {
            mVisibleCount = visibleCount;
            return this;
        }

        public Builder imageCropAllowed(boolean allowed) {
            mImageCropAllowed = allowed;
            return this;
        }

        public Builder cacheTimeMs(long cacheTimeMs) {
            mCacheTimeMs = cacheTimeMs;
            return this;
        }

        public Builder intent(Intent intent) {
            mIntent = intent;
            return this;
        }

        public Builder addItem(Uri imageUri) {
            ClusterItem item = new ClusterItem(imageUri);
            mClusterItems.add(item);
            return this;
        }
    }
}