blob: 61745dda0e86374b7d8d159ec0f1476a4d5bdbdd [file] [log] [blame]
The Android Open Source Projectc8f00b62008-10-21 07:00:00 -07001/*
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
17package com.android.launcher;
18
19import java.io.ByteArrayOutputStream;
20import java.io.IOException;
21
22import android.content.ContentValues;
23import android.graphics.Bitmap;
The Android Open Source Projectc8f00b62008-10-21 07:00:00 -070024import android.util.Log;
25
The Android Open Source Projectc8f00b62008-10-21 07:00:00 -070026/**
27 * Represents an item in the launcher.
28 */
29class ItemInfo {
30
31 static final int NO_ID = -1;
32
33 /**
34 * The id in the settings database for this item
35 */
36 long id = NO_ID;
37
38 /**
The Android Open Source Projectd097a182008-12-17 18:05:58 -080039 * One of {@link LauncherSettings.Favorites#ITEM_TYPE_APPLICATION},
40 * {@link LauncherSettings.Favorites#ITEM_TYPE_SHORTCUT},
41 * {@link LauncherSettings.Favorites#ITEM_TYPE_USER_FOLDER},
42 * {@link LauncherSettings.Favorites#ITEM_TYPE_WIDGET_CLOCK},
43 * {@link LauncherSettings.Favorites#ITEM_TYPE_WIDGET_SEARCH} or
44 * {@link LauncherSettings.Favorites#ITEM_TYPE_WIDGET_PHOTO_FRAME},
The Android Open Source Projectc8f00b62008-10-21 07:00:00 -070045 */
46 int itemType;
47
48 /**
49 * The id of the container that holds this item. For the desktop, this will be
The Android Open Source Projectd097a182008-12-17 18:05:58 -080050 * {@link LauncherSettings.Favorites#CONTAINER_DESKTOP}. For the all applications folder it
The Android Open Source Projectc8f00b62008-10-21 07:00:00 -070051 * will be {@link #NO_ID} (since it is not stored in the settings DB). For user folders
52 * it will be the id of the folder.
53 */
54 long container = NO_ID;
55
56 /**
57 * Iindicates the screen in which the shortcut appears.
58 */
59 int screen = -1;
60
61 /**
62 * Indicates the X position of the associated cell.
63 */
64 int cellX = -1;
65
66 /**
67 * Indicates the Y position of the associated cell.
68 */
69 int cellY = -1;
70
71 /**
72 * Indicates the X cell span.
73 */
74 int spanX = 1;
75
76 /**
77 * Indicates the Y cell span.
78 */
79 int spanY = 1;
80
81 ItemInfo() {
82 }
83
84 ItemInfo(ItemInfo info) {
85 id = info.id;
86 cellX = info.cellX;
87 cellY = info.cellY;
88 spanX = info.spanX;
89 spanY = info.spanY;
90 screen = info.screen;
91 itemType = info.itemType;
92 container = info.container;
93 }
94
95 /**
96 * Write the fields of this item to the DB
97 *
98 * @param values
99 */
100 void onAddToDatabase(ContentValues values) {
The Android Open Source Projectd097a182008-12-17 18:05:58 -0800101 values.put(LauncherSettings.Favorites.ITEM_TYPE, itemType);
102 values.put(LauncherSettings.Favorites.CONTAINER, container);
103 values.put(LauncherSettings.Favorites.SCREEN, screen);
104 values.put(LauncherSettings.Favorites.CELLX, cellX);
105 values.put(LauncherSettings.Favorites.CELLY, cellY);
106 values.put(LauncherSettings.Favorites.SPANX, spanX);
107 values.put(LauncherSettings.Favorites.SPANY, spanY);
The Android Open Source Projectc8f00b62008-10-21 07:00:00 -0700108 }
109
110 static void writeBitmap(ContentValues values, Bitmap bitmap) {
111 if (bitmap != null) {
112 // Try go guesstimate how much space the icon will take when serialized
113 // to avoid unnecessary allocations/copies during the write.
114 int size = bitmap.getWidth() * bitmap.getHeight() * 4;
115 ByteArrayOutputStream out = new ByteArrayOutputStream(size);
116 try {
117 bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
118 out.flush();
119 out.close();
120
The Android Open Source Projectd097a182008-12-17 18:05:58 -0800121 values.put(LauncherSettings.Favorites.ICON, out.toByteArray());
The Android Open Source Projectc8f00b62008-10-21 07:00:00 -0700122 } catch (IOException e) {
123 Log.w("Favorite", "Could not write icon");
124 }
125 }
126 }
127
128}