blob: 14107084ee7e1891faa60507c12bdf511f5100c0 [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
The Android Open Source Projectc8f00b62008-10-21 07:00:00 -070019import android.content.Context;
The Android Open Source Project15a88802009-02-10 15:44:05 -080020import android.content.res.Resources;
21import android.graphics.drawable.Drawable;
The Android Open Source Projectc8f00b62008-10-21 07:00:00 -070022import android.view.LayoutInflater;
23import android.view.View;
24import android.view.ViewGroup;
The Android Open Source Project15a88802009-02-10 15:44:05 -080025import android.widget.BaseAdapter;
The Android Open Source Projectc8f00b62008-10-21 07:00:00 -070026import android.widget.TextView;
The Android Open Source Projectc8f00b62008-10-21 07:00:00 -070027
28import java.util.ArrayList;
The Android Open Source Projectc8f00b62008-10-21 07:00:00 -070029
30/**
The Android Open Source Project15a88802009-02-10 15:44:05 -080031 * Adapter showing the types of items that can be added to a {@link Workspace}.
The Android Open Source Projectc8f00b62008-10-21 07:00:00 -070032 */
The Android Open Source Project15a88802009-02-10 15:44:05 -080033public class AddAdapter extends BaseAdapter {
34
35 private final Launcher mLauncher;
The Android Open Source Projectc8f00b62008-10-21 07:00:00 -070036 private final LayoutInflater mInflater;
The Android Open Source Project15a88802009-02-10 15:44:05 -080037
38 private final ArrayList<ListItem> mItems = new ArrayList<ListItem>();
39
40 public static final int ITEM_APPLICATION = 0;
41 public static final int ITEM_SHORTCUT = 1;
42 public static final int ITEM_SEARCH = 2;
43 public static final int ITEM_GADGET = 3;
44 public static final int ITEM_LIVE_FOLDER = 4;
45 public static final int ITEM_FOLDER = 5;
46 public static final int ITEM_WALLPAPER = 6;
The Android Open Source Projectc8f00b62008-10-21 07:00:00 -070047
48 /**
The Android Open Source Project15a88802009-02-10 15:44:05 -080049 * Specific item in our list.
The Android Open Source Projectc8f00b62008-10-21 07:00:00 -070050 */
The Android Open Source Project15a88802009-02-10 15:44:05 -080051 public class ListItem {
52 public final CharSequence text;
53 public final Drawable image;
54 public final int actionTag;
The Android Open Source Projectc8f00b62008-10-21 07:00:00 -070055
The Android Open Source Project15a88802009-02-10 15:44:05 -080056 public ListItem(Resources res, int textResourceId, int imageResourceId, int actionTag) {
57 text = res.getString(textResourceId);
58 if (imageResourceId != -1) {
59 image = res.getDrawable(imageResourceId);
60 } else {
61 image = null;
The Android Open Source Projectc8f00b62008-10-21 07:00:00 -070062 }
The Android Open Source Project15a88802009-02-10 15:44:05 -080063 this.actionTag = actionTag;
The Android Open Source Projectc8f00b62008-10-21 07:00:00 -070064 }
65 }
66
The Android Open Source Project15a88802009-02-10 15:44:05 -080067 public AddAdapter(Launcher launcher) {
68 super();
69
The Android Open Source Projectc8f00b62008-10-21 07:00:00 -070070 mLauncher = launcher;
The Android Open Source Project15a88802009-02-10 15:44:05 -080071 mInflater = (LayoutInflater) mLauncher.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
72
73 // Create default actions
74 Resources res = launcher.getResources();
75
76 mItems.add(new ListItem(res, R.string.group_applications,
77 R.drawable.ic_launcher_application, ITEM_APPLICATION));
78
79 mItems.add(new ListItem(res, R.string.group_shortcuts,
80 R.drawable.ic_launcher_empty, ITEM_SHORTCUT));
81
82 mItems.add(new ListItem(res, R.string.group_search,
83 R.drawable.ic_search_gadget, ITEM_SEARCH));
84
85 mItems.add(new ListItem(res, R.string.group_gadgets,
86 R.drawable.ic_launcher_gadget, ITEM_GADGET));
87
88 mItems.add(new ListItem(res, R.string.group_live_folders,
89 R.drawable.ic_launcher_empty, ITEM_LIVE_FOLDER));
90
91 mItems.add(new ListItem(res, R.string.group_folder,
92 R.drawable.ic_launcher_folder, ITEM_FOLDER));
93
94 mItems.add(new ListItem(res, R.string.group_wallpapers,
95 R.drawable.ic_launcher_gallery, ITEM_WALLPAPER));
The Android Open Source Projectc8f00b62008-10-21 07:00:00 -070096
The Android Open Source Project15a88802009-02-10 15:44:05 -080097 }
The Android Open Source Projectc8f00b62008-10-21 07:00:00 -070098
The Android Open Source Project15a88802009-02-10 15:44:05 -080099 public View getView(int position, View convertView, ViewGroup parent) {
100 ListItem item = (ListItem) getItem(position);
101
102 if (convertView == null) {
103 convertView = mInflater.inflate(R.layout.add_list_item, parent, false);
The Android Open Source Projectc8f00b62008-10-21 07:00:00 -0700104 }
105
The Android Open Source Project15a88802009-02-10 15:44:05 -0800106 TextView textView = (TextView) convertView;
107 textView.setTag(item);
108 textView.setText(item.text);
109 textView.setCompoundDrawablesWithIntrinsicBounds(item.image, null, null, null);
110
111 return convertView;
The Android Open Source Projectc8f00b62008-10-21 07:00:00 -0700112 }
113
The Android Open Source Project15a88802009-02-10 15:44:05 -0800114 public int getCount() {
115 return mItems.size();
The Android Open Source Projectc8f00b62008-10-21 07:00:00 -0700116 }
117
The Android Open Source Project15a88802009-02-10 15:44:05 -0800118 public Object getItem(int position) {
119 return mItems.get(position);
The Android Open Source Projectc8f00b62008-10-21 07:00:00 -0700120 }
121
The Android Open Source Project15a88802009-02-10 15:44:05 -0800122 public long getItemId(int position) {
123 return position;
The Android Open Source Projectc8f00b62008-10-21 07:00:00 -0700124 }
The Android Open Source Project15a88802009-02-10 15:44:05 -0800125
The Android Open Source Projectc8f00b62008-10-21 07:00:00 -0700126}