blob: 42e2ec324c3a272b299ca7dd86c09f07103ce9a6 [file] [log] [blame]
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Daniel Sandler325dc232013-06-05 22:57:57 -040017package com.android.launcher3;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018
Winson Chung72b520c2013-12-10 01:17:03 +000019import android.content.ContentValues;
20
Winson Chung33231f52013-12-09 16:57:45 -080021import java.util.ArrayList;
22
The Android Open Source Project31dd5032009-03-03 19:32:27 -080023/**
24 * Represents a folder containing shortcuts or apps.
25 */
Anjali Koppal7b168a12014-03-04 17:16:11 -080026public class FolderInfo extends ItemInfo {
Adam Cohendf2cc412011-04-27 16:56:57 -070027
The Android Open Source Project31dd5032009-03-03 19:32:27 -080028 /**
29 * Whether this folder has been opened
30 */
31 boolean opened;
32
33 /**
Adam Cohendf2cc412011-04-27 16:56:57 -070034 * The apps and shortcuts
35 */
36 ArrayList<ShortcutInfo> contents = new ArrayList<ShortcutInfo>();
37
Adam Cohena9cf38f2011-05-02 15:36:58 -070038 ArrayList<FolderListener> listeners = new ArrayList<FolderListener>();
39
Michael Jurkac9d95c52011-08-29 14:03:34 -070040 FolderInfo() {
Adam Cohendf2cc412011-04-27 16:56:57 -070041 itemType = LauncherSettings.Favorites.ITEM_TYPE_FOLDER;
42 }
43
44 /**
45 * Add an app or shortcut
46 *
47 * @param item
48 */
49 public void add(ShortcutInfo item) {
50 contents.add(item);
Adam Cohena9cf38f2011-05-02 15:36:58 -070051 for (int i = 0; i < listeners.size(); i++) {
52 listeners.get(i).onAdd(item);
53 }
Adam Cohenac56cff2011-09-28 20:45:37 -070054 itemsChanged();
Adam Cohendf2cc412011-04-27 16:56:57 -070055 }
56
57 /**
58 * Remove an app or shortcut. Does not change the DB.
59 *
60 * @param item
61 */
62 public void remove(ShortcutInfo item) {
63 contents.remove(item);
Adam Cohena9cf38f2011-05-02 15:36:58 -070064 for (int i = 0; i < listeners.size(); i++) {
65 listeners.get(i).onRemove(item);
66 }
Adam Cohenac56cff2011-09-28 20:45:37 -070067 itemsChanged();
Adam Cohendf2cc412011-04-27 16:56:57 -070068 }
69
Adam Cohen76fc0852011-06-17 13:26:23 -070070 public void setTitle(CharSequence title) {
71 this.title = title;
72 for (int i = 0; i < listeners.size(); i++) {
73 listeners.get(i).onTitleChanged(title);
74 }
75 }
76
Adam Cohendf2cc412011-04-27 16:56:57 -070077 @Override
78 void onAddToDatabase(ContentValues values) {
79 super.onAddToDatabase(values);
80 values.put(LauncherSettings.Favorites.TITLE, title.toString());
81 }
Adam Cohena9cf38f2011-05-02 15:36:58 -070082
83 void addListener(FolderListener listener) {
84 listeners.add(listener);
85 }
86
87 void removeListener(FolderListener listener) {
88 if (listeners.contains(listener)) {
89 listeners.remove(listener);
90 }
91 }
92
Adam Cohen76078c42011-06-09 15:06:52 -070093 void itemsChanged() {
94 for (int i = 0; i < listeners.size(); i++) {
95 listeners.get(i).onItemsChanged();
96 }
97 }
98
Adam Cohen4eac29a2011-07-11 17:53:37 -070099 @Override
100 void unbind() {
101 super.unbind();
102 listeners.clear();
103 }
104
Adam Cohena9cf38f2011-05-02 15:36:58 -0700105 interface FolderListener {
106 public void onAdd(ShortcutInfo item);
107 public void onRemove(ShortcutInfo item);
Adam Cohen76fc0852011-06-17 13:26:23 -0700108 public void onTitleChanged(CharSequence title);
Adam Cohen76078c42011-06-09 15:06:52 -0700109 public void onItemsChanged();
Adam Cohena9cf38f2011-05-02 15:36:58 -0700110 }
Winson Chung64359a52013-07-08 17:17:08 -0700111
112 @Override
113 public String toString() {
114 return "FolderInfo(id=" + this.id + " type=" + this.itemType
115 + " container=" + this.container + " screen=" + screenId
116 + " cellX=" + cellX + " cellY=" + cellY + " spanX=" + spanX
117 + " spanY=" + spanY + " dropPos=" + dropPos + ")";
118 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800119}