The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1 | /* |
| 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 Onorato | a590252 | 2009-07-30 13:37:37 -0700 | [diff] [blame] | 17 | package com.android.launcher2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 18 | |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 19 | import java.util.ArrayList; |
| 20 | |
| 21 | import android.content.ContentValues; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * Represents a folder containing shortcuts or apps. |
| 25 | */ |
| 26 | class FolderInfo extends ItemInfo { |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 27 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 28 | /** |
| 29 | * Whether this folder has been opened |
| 30 | */ |
| 31 | boolean opened; |
| 32 | |
| 33 | /** |
| 34 | * The folder name. |
| 35 | */ |
| 36 | CharSequence title; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 37 | |
| 38 | /** |
| 39 | * The apps and shortcuts |
| 40 | */ |
| 41 | ArrayList<ShortcutInfo> contents = new ArrayList<ShortcutInfo>(); |
| 42 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 43 | ArrayList<FolderListener> listeners = new ArrayList<FolderListener>(); |
| 44 | |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 45 | FolderInfo() { |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 46 | itemType = LauncherSettings.Favorites.ITEM_TYPE_FOLDER; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Add an app or shortcut |
| 51 | * |
| 52 | * @param item |
| 53 | */ |
| 54 | public void add(ShortcutInfo item) { |
| 55 | contents.add(item); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 56 | for (int i = 0; i < listeners.size(); i++) { |
| 57 | listeners.get(i).onAdd(item); |
| 58 | } |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Remove an app or shortcut. Does not change the DB. |
| 63 | * |
| 64 | * @param item |
| 65 | */ |
| 66 | public void remove(ShortcutInfo item) { |
| 67 | contents.remove(item); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 68 | for (int i = 0; i < listeners.size(); i++) { |
| 69 | listeners.get(i).onRemove(item); |
| 70 | } |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 73 | public void setTitle(CharSequence title) { |
| 74 | this.title = title; |
| 75 | for (int i = 0; i < listeners.size(); i++) { |
| 76 | listeners.get(i).onTitleChanged(title); |
| 77 | } |
| 78 | } |
| 79 | |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 80 | @Override |
| 81 | void onAddToDatabase(ContentValues values) { |
| 82 | super.onAddToDatabase(values); |
| 83 | values.put(LauncherSettings.Favorites.TITLE, title.toString()); |
| 84 | } |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 85 | |
| 86 | void addListener(FolderListener listener) { |
| 87 | listeners.add(listener); |
| 88 | } |
| 89 | |
| 90 | void removeListener(FolderListener listener) { |
| 91 | if (listeners.contains(listener)) { |
| 92 | listeners.remove(listener); |
| 93 | } |
| 94 | } |
| 95 | |
Adam Cohen | 76078c4 | 2011-06-09 15:06:52 -0700 | [diff] [blame] | 96 | void itemsChanged() { |
| 97 | for (int i = 0; i < listeners.size(); i++) { |
| 98 | listeners.get(i).onItemsChanged(); |
| 99 | } |
| 100 | } |
| 101 | |
Adam Cohen | 4eac29a | 2011-07-11 17:53:37 -0700 | [diff] [blame] | 102 | @Override |
| 103 | void unbind() { |
| 104 | super.unbind(); |
| 105 | listeners.clear(); |
| 106 | } |
| 107 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 108 | interface FolderListener { |
| 109 | public void onAdd(ShortcutInfo item); |
| 110 | public void onRemove(ShortcutInfo item); |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 111 | public void onTitleChanged(CharSequence title); |
Adam Cohen | 76078c4 | 2011-06-09 15:06:52 -0700 | [diff] [blame] | 112 | public void onItemsChanged(); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 113 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 114 | } |