blob: 85a792f4b43d53df1f438a260c1611539cc04054 [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;
Kenny Guyed131872014-04-30 03:02:21 +010020import android.content.Context;
21
22import com.android.launcher3.compat.UserHandleCompat;
Winson Chung72b520c2013-12-10 01:17:03 +000023
Winson Chung33231f52013-12-09 16:57:45 -080024import java.util.ArrayList;
Sameer Padalabe3e4102014-04-21 19:36:14 -070025import java.util.Arrays;
Winson Chung33231f52013-12-09 16:57:45 -080026
The Android Open Source Project31dd5032009-03-03 19:32:27 -080027/**
28 * Represents a folder containing shortcuts or apps.
29 */
Anjali Koppal7b168a12014-03-04 17:16:11 -080030public class FolderInfo extends ItemInfo {
Adam Cohendf2cc412011-04-27 16:56:57 -070031
The Android Open Source Project31dd5032009-03-03 19:32:27 -080032 /**
33 * Whether this folder has been opened
34 */
35 boolean opened;
36
37 /**
Adam Cohendf2cc412011-04-27 16:56:57 -070038 * The apps and shortcuts
39 */
40 ArrayList<ShortcutInfo> contents = new ArrayList<ShortcutInfo>();
41
Adam Cohena9cf38f2011-05-02 15:36:58 -070042 ArrayList<FolderListener> listeners = new ArrayList<FolderListener>();
43
Michael Jurkac9d95c52011-08-29 14:03:34 -070044 FolderInfo() {
Adam Cohendf2cc412011-04-27 16:56:57 -070045 itemType = LauncherSettings.Favorites.ITEM_TYPE_FOLDER;
Kenny Guyed131872014-04-30 03:02:21 +010046 user = UserHandleCompat.myUserHandle();
Adam Cohendf2cc412011-04-27 16:56:57 -070047 }
48
49 /**
50 * Add an app or shortcut
51 *
52 * @param item
53 */
54 public void add(ShortcutInfo item) {
55 contents.add(item);
Adam Cohena9cf38f2011-05-02 15:36:58 -070056 for (int i = 0; i < listeners.size(); i++) {
57 listeners.get(i).onAdd(item);
58 }
Adam Cohenac56cff2011-09-28 20:45:37 -070059 itemsChanged();
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 Cohenac56cff2011-09-28 20:45:37 -070072 itemsChanged();
Adam Cohendf2cc412011-04-27 16:56:57 -070073 }
74
Adam Cohen76fc0852011-06-17 13:26:23 -070075 public void setTitle(CharSequence title) {
76 this.title = title;
77 for (int i = 0; i < listeners.size(); i++) {
78 listeners.get(i).onTitleChanged(title);
79 }
80 }
81
Adam Cohendf2cc412011-04-27 16:56:57 -070082 @Override
Kenny Guyed131872014-04-30 03:02:21 +010083 void onAddToDatabase(Context context, ContentValues values) {
84 super.onAddToDatabase(context, values);
Adam Cohendf2cc412011-04-27 16:56:57 -070085 values.put(LauncherSettings.Favorites.TITLE, title.toString());
86 }
Adam Cohena9cf38f2011-05-02 15:36:58 -070087
88 void addListener(FolderListener listener) {
89 listeners.add(listener);
90 }
91
92 void removeListener(FolderListener listener) {
93 if (listeners.contains(listener)) {
94 listeners.remove(listener);
95 }
96 }
97
Adam Cohen76078c42011-06-09 15:06:52 -070098 void itemsChanged() {
99 for (int i = 0; i < listeners.size(); i++) {
100 listeners.get(i).onItemsChanged();
101 }
102 }
103
Adam Cohen4eac29a2011-07-11 17:53:37 -0700104 @Override
105 void unbind() {
106 super.unbind();
107 listeners.clear();
108 }
109
Adam Cohena9cf38f2011-05-02 15:36:58 -0700110 interface FolderListener {
111 public void onAdd(ShortcutInfo item);
112 public void onRemove(ShortcutInfo item);
Adam Cohen76fc0852011-06-17 13:26:23 -0700113 public void onTitleChanged(CharSequence title);
Adam Cohen76078c42011-06-09 15:06:52 -0700114 public void onItemsChanged();
Adam Cohena9cf38f2011-05-02 15:36:58 -0700115 }
Winson Chung64359a52013-07-08 17:17:08 -0700116
117 @Override
118 public String toString() {
119 return "FolderInfo(id=" + this.id + " type=" + this.itemType
120 + " container=" + this.container + " screen=" + screenId
121 + " cellX=" + cellX + " cellY=" + cellY + " spanX=" + spanX
Sameer Padalabe3e4102014-04-21 19:36:14 -0700122 + " spanY=" + spanY + " dropPos=" + Arrays.toString(dropPos) + ")";
Winson Chung64359a52013-07-08 17:17:08 -0700123 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800124}