blob: 61fa7e574164053f9a20e1bc7af45b7eaf6efd71 [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;
Sameer Padalabe3e4102014-04-21 19:36:14 -070022import java.util.Arrays;
Winson Chung33231f52013-12-09 16:57:45 -080023
The Android Open Source Project31dd5032009-03-03 19:32:27 -080024/**
25 * Represents a folder containing shortcuts or apps.
26 */
Anjali Koppal7b168a12014-03-04 17:16:11 -080027public class FolderInfo extends ItemInfo {
Adam Cohendf2cc412011-04-27 16:56:57 -070028
The Android Open Source Project31dd5032009-03-03 19:32:27 -080029 /**
30 * Whether this folder has been opened
31 */
32 boolean opened;
33
34 /**
Adam Cohendf2cc412011-04-27 16:56:57 -070035 * The apps and shortcuts
36 */
37 ArrayList<ShortcutInfo> contents = new ArrayList<ShortcutInfo>();
38
Adam Cohena9cf38f2011-05-02 15:36:58 -070039 ArrayList<FolderListener> listeners = new ArrayList<FolderListener>();
40
Michael Jurkac9d95c52011-08-29 14:03:34 -070041 FolderInfo() {
Adam Cohendf2cc412011-04-27 16:56:57 -070042 itemType = LauncherSettings.Favorites.ITEM_TYPE_FOLDER;
43 }
44
45 /**
46 * Add an app or shortcut
47 *
48 * @param item
49 */
50 public void add(ShortcutInfo item) {
51 contents.add(item);
Adam Cohena9cf38f2011-05-02 15:36:58 -070052 for (int i = 0; i < listeners.size(); i++) {
53 listeners.get(i).onAdd(item);
54 }
Adam Cohenac56cff2011-09-28 20:45:37 -070055 itemsChanged();
Adam Cohendf2cc412011-04-27 16:56:57 -070056 }
57
58 /**
59 * Remove an app or shortcut. Does not change the DB.
60 *
61 * @param item
62 */
63 public void remove(ShortcutInfo item) {
64 contents.remove(item);
Adam Cohena9cf38f2011-05-02 15:36:58 -070065 for (int i = 0; i < listeners.size(); i++) {
66 listeners.get(i).onRemove(item);
67 }
Adam Cohenac56cff2011-09-28 20:45:37 -070068 itemsChanged();
Adam Cohendf2cc412011-04-27 16:56:57 -070069 }
70
Adam Cohen76fc0852011-06-17 13:26:23 -070071 public void setTitle(CharSequence title) {
72 this.title = title;
73 for (int i = 0; i < listeners.size(); i++) {
74 listeners.get(i).onTitleChanged(title);
75 }
76 }
77
Adam Cohendf2cc412011-04-27 16:56:57 -070078 @Override
79 void onAddToDatabase(ContentValues values) {
80 super.onAddToDatabase(values);
81 values.put(LauncherSettings.Favorites.TITLE, title.toString());
82 }
Adam Cohena9cf38f2011-05-02 15:36:58 -070083
84 void addListener(FolderListener listener) {
85 listeners.add(listener);
86 }
87
88 void removeListener(FolderListener listener) {
89 if (listeners.contains(listener)) {
90 listeners.remove(listener);
91 }
92 }
93
Adam Cohen76078c42011-06-09 15:06:52 -070094 void itemsChanged() {
95 for (int i = 0; i < listeners.size(); i++) {
96 listeners.get(i).onItemsChanged();
97 }
98 }
99
Adam Cohen4eac29a2011-07-11 17:53:37 -0700100 @Override
101 void unbind() {
102 super.unbind();
103 listeners.clear();
104 }
105
Adam Cohena9cf38f2011-05-02 15:36:58 -0700106 interface FolderListener {
107 public void onAdd(ShortcutInfo item);
108 public void onRemove(ShortcutInfo item);
Adam Cohen76fc0852011-06-17 13:26:23 -0700109 public void onTitleChanged(CharSequence title);
Adam Cohen76078c42011-06-09 15:06:52 -0700110 public void onItemsChanged();
Adam Cohena9cf38f2011-05-02 15:36:58 -0700111 }
Winson Chung64359a52013-07-08 17:17:08 -0700112
113 @Override
114 public String toString() {
115 return "FolderInfo(id=" + this.id + " type=" + this.itemType
116 + " container=" + this.container + " screen=" + screenId
117 + " cellX=" + cellX + " cellY=" + cellY + " spanX=" + spanX
Sameer Padalabe3e4102014-04-21 19:36:14 -0700118 + " spanY=" + spanY + " dropPos=" + Arrays.toString(dropPos) + ")";
Winson Chung64359a52013-07-08 17:17:08 -0700119 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800120}