blob: 24c31ffcda2147231b0fedec5c8d1037ec18b1c5 [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
19import android.content.Context;
20import android.content.res.Resources;
21import android.graphics.drawable.Drawable;
22import android.view.LayoutInflater;
23import android.view.View;
24import android.view.ViewGroup;
25import android.widget.BaseAdapter;
26import android.widget.TextView;
27
28import java.util.ArrayList;
29
Romain Guyedcce092010-03-04 13:03:17 -080030import com.android.launcher.R;
31
The Android Open Source Project31dd5032009-03-03 19:32:27 -080032/**
33 * Adapter showing the types of items that can be added to a {@link Workspace}.
34 */
35public class AddAdapter extends BaseAdapter {
Romain Guy7c7a0732009-03-24 18:10:17 -070036
The Android Open Source Project31dd5032009-03-03 19:32:27 -080037 private final LayoutInflater mInflater;
38
39 private final ArrayList<ListItem> mItems = new ArrayList<ListItem>();
40
Jeffrey Sharkeya9cf26c2009-03-24 20:42:58 -070041 public static final int ITEM_SHORTCUT = 0;
42 public static final int ITEM_APPWIDGET = 1;
43 public static final int ITEM_LIVE_FOLDER = 2;
44 public static final int ITEM_WALLPAPER = 3;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080045
46 /**
47 * Specific item in our list.
48 */
49 public class ListItem {
50 public final CharSequence text;
51 public final Drawable image;
52 public final int actionTag;
53
54 public ListItem(Resources res, int textResourceId, int imageResourceId, int actionTag) {
55 text = res.getString(textResourceId);
56 if (imageResourceId != -1) {
57 image = res.getDrawable(imageResourceId);
58 } else {
59 image = null;
60 }
61 this.actionTag = actionTag;
62 }
63 }
64
65 public AddAdapter(Launcher launcher) {
66 super();
Romain Guy7c7a0732009-03-24 18:10:17 -070067
68 mInflater = (LayoutInflater) launcher.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
The Android Open Source Project31dd5032009-03-03 19:32:27 -080069
70 // Create default actions
71 Resources res = launcher.getResources();
72
The Android Open Source Project31dd5032009-03-03 19:32:27 -080073 mItems.add(new ListItem(res, R.string.group_shortcuts,
Romain Guy7c7a0732009-03-24 18:10:17 -070074 R.drawable.ic_launcher_shortcut, ITEM_SHORTCUT));
75
The Android Open Source Project31dd5032009-03-03 19:32:27 -080076 mItems.add(new ListItem(res, R.string.group_widgets,
The Android Open Source Project7376fae2009-03-11 12:11:58 -070077 R.drawable.ic_launcher_appwidget, ITEM_APPWIDGET));
The Android Open Source Project31dd5032009-03-03 19:32:27 -080078
79 mItems.add(new ListItem(res, R.string.group_live_folders,
Romain Guy28c706b2009-11-13 16:18:14 -080080 R.drawable.ic_launcher_folder, ITEM_LIVE_FOLDER));
The Android Open Source Project31dd5032009-03-03 19:32:27 -080081
The Android Open Source Project31dd5032009-03-03 19:32:27 -080082 mItems.add(new ListItem(res, R.string.group_wallpapers,
Daniel Sandler9a60d542009-10-06 12:57:42 -040083 R.drawable.ic_launcher_wallpaper, ITEM_WALLPAPER));
The Android Open Source Project31dd5032009-03-03 19:32:27 -080084
85 }
86
87 public View getView(int position, View convertView, ViewGroup parent) {
88 ListItem item = (ListItem) getItem(position);
89
90 if (convertView == null) {
91 convertView = mInflater.inflate(R.layout.add_list_item, parent, false);
92 }
93
94 TextView textView = (TextView) convertView;
95 textView.setTag(item);
96 textView.setText(item.text);
97 textView.setCompoundDrawablesWithIntrinsicBounds(item.image, null, null, null);
98
99 return convertView;
100 }
101
102 public int getCount() {
103 return mItems.size();
104 }
105
106 public Object getItem(int position) {
107 return mItems.get(position);
108 }
109
110 public long getItemId(int position) {
111 return position;
112 }
113
114}