2009-03-03 19:32:27 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2008 The Android Open Source Project
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-06-05 22:57:57 -04:00
|
|
|
package com.android.launcher3;
|
2009-03-03 19:32:27 -08:00
|
|
|
|
2013-12-10 01:17:03 +00:00
|
|
|
import android.content.ContentValues;
|
2014-04-30 03:02:21 +01:00
|
|
|
import android.content.Context;
|
|
|
|
|
|
|
|
|
|
import com.android.launcher3.compat.UserHandleCompat;
|
2013-12-10 01:17:03 +00:00
|
|
|
|
2013-12-09 16:57:45 -08:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
2009-03-03 19:32:27 -08:00
|
|
|
/**
|
|
|
|
|
* Represents a folder containing shortcuts or apps.
|
|
|
|
|
*/
|
2014-03-04 17:16:11 -08:00
|
|
|
public class FolderInfo extends ItemInfo {
|
2011-04-27 16:56:57 -07:00
|
|
|
|
2015-03-10 13:14:47 -07:00
|
|
|
public static final int NO_FLAGS = 0x00000000;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The folder is locked in sorted mode
|
|
|
|
|
*/
|
|
|
|
|
public static final int FLAG_ITEMS_SORTED = 0x00000001;
|
|
|
|
|
|
2015-04-08 18:13:46 -07:00
|
|
|
/**
|
|
|
|
|
* It is a work folder
|
|
|
|
|
*/
|
|
|
|
|
public static final int FLAG_WORK_FOLDER = 0x00000002;
|
|
|
|
|
|
2015-05-07 14:51:31 -07:00
|
|
|
/**
|
|
|
|
|
* The multi-page animation has run for this folder
|
|
|
|
|
*/
|
|
|
|
|
public static final int FLAG_MULTI_PAGE_ANIMATION = 0x00000004;
|
|
|
|
|
|
2015-03-10 13:14:47 -07:00
|
|
|
public int options;
|
|
|
|
|
|
2011-04-27 16:56:57 -07:00
|
|
|
/**
|
|
|
|
|
* The apps and shortcuts
|
|
|
|
|
*/
|
2015-04-08 18:13:46 -07:00
|
|
|
public ArrayList<ShortcutInfo> contents = new ArrayList<ShortcutInfo>();
|
2011-04-27 16:56:57 -07:00
|
|
|
|
2016-05-17 21:25:48 +00:00
|
|
|
ArrayList<FolderListener> listeners = new ArrayList<FolderListener>();
|
2011-05-02 15:36:58 -07:00
|
|
|
|
2015-04-08 18:13:46 -07:00
|
|
|
public FolderInfo() {
|
2011-04-27 16:56:57 -07:00
|
|
|
itemType = LauncherSettings.Favorites.ITEM_TYPE_FOLDER;
|
2014-04-30 03:02:21 +01:00
|
|
|
user = UserHandleCompat.myUserHandle();
|
2011-04-27 16:56:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add an app or shortcut
|
|
|
|
|
*
|
|
|
|
|
* @param item
|
|
|
|
|
*/
|
2016-04-05 15:59:05 -07:00
|
|
|
public void add(ShortcutInfo item, boolean animate) {
|
2011-04-27 16:56:57 -07:00
|
|
|
contents.add(item);
|
2016-05-17 21:25:48 +00:00
|
|
|
for (int i = 0; i < listeners.size(); i++) {
|
|
|
|
|
listeners.get(i).onAdd(item);
|
2011-05-02 15:36:58 -07:00
|
|
|
}
|
2016-04-05 15:59:05 -07:00
|
|
|
itemsChanged(animate);
|
2011-04-27 16:56:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove an app or shortcut. Does not change the DB.
|
|
|
|
|
*
|
|
|
|
|
* @param item
|
|
|
|
|
*/
|
2016-04-05 15:59:05 -07:00
|
|
|
public void remove(ShortcutInfo item, boolean animate) {
|
2011-04-27 16:56:57 -07:00
|
|
|
contents.remove(item);
|
2016-05-17 21:25:48 +00:00
|
|
|
for (int i = 0; i < listeners.size(); i++) {
|
|
|
|
|
listeners.get(i).onRemove(item);
|
2011-05-02 15:36:58 -07:00
|
|
|
}
|
2016-04-05 15:59:05 -07:00
|
|
|
itemsChanged(animate);
|
2011-04-27 16:56:57 -07:00
|
|
|
}
|
|
|
|
|
|
2016-05-17 21:25:48 +00:00
|
|
|
public void setTitle(CharSequence title) {
|
|
|
|
|
this.title = title;
|
|
|
|
|
for (int i = 0; i < listeners.size(); i++) {
|
|
|
|
|
listeners.get(i).onTitleChanged(title);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-27 16:56:57 -07:00
|
|
|
@Override
|
2014-04-30 03:02:21 +01:00
|
|
|
void onAddToDatabase(Context context, ContentValues values) {
|
|
|
|
|
super.onAddToDatabase(context, values);
|
2011-04-27 16:56:57 -07:00
|
|
|
values.put(LauncherSettings.Favorites.TITLE, title.toString());
|
2015-03-10 13:14:47 -07:00
|
|
|
values.put(LauncherSettings.Favorites.OPTIONS, options);
|
|
|
|
|
|
2011-04-27 16:56:57 -07:00
|
|
|
}
|
2011-05-02 15:36:58 -07:00
|
|
|
|
2016-05-17 21:25:48 +00:00
|
|
|
public void addListener(FolderListener listener) {
|
|
|
|
|
listeners.add(listener);
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-17 13:38:54 -07:00
|
|
|
public void removeListener(FolderListener listener) {
|
|
|
|
|
listeners.remove(listener);
|
2011-05-02 15:36:58 -07:00
|
|
|
}
|
|
|
|
|
|
2016-04-05 15:59:05 -07:00
|
|
|
public void itemsChanged(boolean animate) {
|
2016-05-17 21:25:48 +00:00
|
|
|
for (int i = 0; i < listeners.size(); i++) {
|
|
|
|
|
listeners.get(i).onItemsChanged(animate);
|
2011-06-09 15:06:52 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-15 16:47:43 -08:00
|
|
|
public interface FolderListener {
|
2016-05-17 21:25:48 +00:00
|
|
|
public void onAdd(ShortcutInfo item);
|
|
|
|
|
public void onRemove(ShortcutInfo item);
|
|
|
|
|
public void onTitleChanged(CharSequence title);
|
|
|
|
|
public void onItemsChanged(boolean animate);
|
2011-05-02 15:36:58 -07:00
|
|
|
}
|
2013-07-08 17:17:08 -07:00
|
|
|
|
2015-03-10 13:14:47 -07:00
|
|
|
public boolean hasOption(int optionFlag) {
|
|
|
|
|
return (options & optionFlag) != 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param option flag to set or clear
|
|
|
|
|
* @param isEnabled whether to set or clear the flag
|
|
|
|
|
* @param context if not null, save changes to the db.
|
|
|
|
|
*/
|
|
|
|
|
public void setOption(int option, boolean isEnabled, Context context) {
|
|
|
|
|
int oldOptions = options;
|
|
|
|
|
if (isEnabled) {
|
|
|
|
|
options |= option;
|
|
|
|
|
} else {
|
|
|
|
|
options &= ~option;
|
|
|
|
|
}
|
|
|
|
|
if (context != null && oldOptions != options) {
|
|
|
|
|
LauncherModel.updateItemInDatabase(context, this);
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|