blob: 0f8b9e06fee36a0e40ba27c4a3ee81381fe1ce78 [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
Joe Onoratoa5902522009-07-30 13:37:37 -070017package com.android.launcher2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018
Adam Cohendf2cc412011-04-27 16:56:57 -070019import java.util.ArrayList;
20
21import android.content.ContentValues;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080022
23/**
24 * Represents a folder containing shortcuts or apps.
25 */
26class 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 /**
34 * The folder name.
35 */
36 CharSequence title;
Adam Cohendf2cc412011-04-27 16:56:57 -070037
38 /**
39 * The apps and shortcuts
40 */
41 ArrayList<ShortcutInfo> contents = new ArrayList<ShortcutInfo>();
42
Adam Cohena9cf38f2011-05-02 15:36:58 -070043 ArrayList<FolderListener> listeners = new ArrayList<FolderListener>();
44
Michael Jurkab60fd0e2011-08-29 14:02:47 -070045 FolderInfo(String whereCreated) {
46 super(whereCreated);
Adam Cohendf2cc412011-04-27 16:56:57 -070047 itemType = LauncherSettings.Favorites.ITEM_TYPE_FOLDER;
48 }
49
50 /**
51 * Add an app or shortcut
52 *
53 * @param item
54 */
55 public void add(ShortcutInfo item) {
56 contents.add(item);
Adam Cohena9cf38f2011-05-02 15:36:58 -070057 for (int i = 0; i < listeners.size(); i++) {
58 listeners.get(i).onAdd(item);
59 }
Adam Cohendf2cc412011-04-27 16:56:57 -070060 }
61
62 /**
63 * Remove an app or shortcut. Does not change the DB.
64 *
65 * @param item
66 */
67 public void remove(ShortcutInfo item) {
68 contents.remove(item);
Adam Cohena9cf38f2011-05-02 15:36:58 -070069 for (int i = 0; i < listeners.size(); i++) {
70 listeners.get(i).onRemove(item);
71 }
Adam Cohendf2cc412011-04-27 16:56:57 -070072 }
73
Adam Cohen76fc0852011-06-17 13:26:23 -070074 public void setTitle(CharSequence title) {
75 this.title = title;
76 for (int i = 0; i < listeners.size(); i++) {
77 listeners.get(i).onTitleChanged(title);
78 }
79 }
80
Adam Cohendf2cc412011-04-27 16:56:57 -070081 @Override
82 void onAddToDatabase(ContentValues values) {
83 super.onAddToDatabase(values);
84 values.put(LauncherSettings.Favorites.TITLE, title.toString());
85 }
Adam Cohena9cf38f2011-05-02 15:36:58 -070086
87 void addListener(FolderListener listener) {
88 listeners.add(listener);
89 }
90
91 void removeListener(FolderListener listener) {
92 if (listeners.contains(listener)) {
93 listeners.remove(listener);
94 }
95 }
96
Adam Cohen76078c42011-06-09 15:06:52 -070097 void itemsChanged() {
98 for (int i = 0; i < listeners.size(); i++) {
99 listeners.get(i).onItemsChanged();
100 }
101 }
102
Adam Cohen4eac29a2011-07-11 17:53:37 -0700103 @Override
104 void unbind() {
105 super.unbind();
106 listeners.clear();
107 }
108
Adam Cohena9cf38f2011-05-02 15:36:58 -0700109 interface FolderListener {
110 public void onAdd(ShortcutInfo item);
111 public void onRemove(ShortcutInfo item);
Adam Cohen76fc0852011-06-17 13:26:23 -0700112 public void onTitleChanged(CharSequence title);
Adam Cohen76078c42011-06-09 15:06:52 -0700113 public void onItemsChanged();
Adam Cohena9cf38f2011-05-02 15:36:58 -0700114 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800115}