The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1 | /* |
| 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 Onorato | a590252 | 2009-07-30 13:37:37 -0700 | [diff] [blame] | 17 | package com.android.launcher2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 18 | |
| 19 | import android.content.Context; |
| 20 | import android.content.res.Resources; |
| 21 | import android.graphics.drawable.Drawable; |
| 22 | import android.view.LayoutInflater; |
| 23 | import android.view.View; |
| 24 | import android.view.ViewGroup; |
| 25 | import android.widget.BaseAdapter; |
| 26 | import android.widget.TextView; |
| 27 | |
| 28 | import java.util.ArrayList; |
| 29 | |
Romain Guy | edcce09 | 2010-03-04 13:03:17 -0800 | [diff] [blame] | 30 | import com.android.launcher.R; |
| 31 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 32 | /** |
| 33 | * Adapter showing the types of items that can be added to a {@link Workspace}. |
| 34 | */ |
| 35 | public class AddAdapter extends BaseAdapter { |
Romain Guy | 7c7a073 | 2009-03-24 18:10:17 -0700 | [diff] [blame] | 36 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 37 | private final LayoutInflater mInflater; |
Winson Chung | 5a80835 | 2011-06-27 19:08:49 -0700 | [diff] [blame] | 38 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 39 | private final ArrayList<ListItem> mItems = new ArrayList<ListItem>(); |
Winson Chung | 5a80835 | 2011-06-27 19:08:49 -0700 | [diff] [blame] | 40 | |
Jeffrey Sharkey | a9cf26c | 2009-03-24 20:42:58 -0700 | [diff] [blame] | 41 | public static final int ITEM_SHORTCUT = 0; |
| 42 | public static final int ITEM_APPWIDGET = 1; |
Winson Chung | 55b6550 | 2011-05-26 12:03:43 -0700 | [diff] [blame] | 43 | public static final int ITEM_APPLICATION = 2; |
Jeffrey Sharkey | a9cf26c | 2009-03-24 20:42:58 -0700 | [diff] [blame] | 44 | public static final int ITEM_WALLPAPER = 3; |
Winson Chung | 5a80835 | 2011-06-27 19:08:49 -0700 | [diff] [blame] | 45 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 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; |
Winson Chung | 5a80835 | 2011-06-27 19:08:49 -0700 | [diff] [blame] | 53 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 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 Guy | 7c7a073 | 2009-03-24 18:10:17 -0700 | [diff] [blame] | 67 | |
| 68 | mInflater = (LayoutInflater) launcher.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
Winson Chung | 5a80835 | 2011-06-27 19:08:49 -0700 | [diff] [blame] | 69 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 70 | // Create default actions |
| 71 | Resources res = launcher.getResources(); |
Winson Chung | 5a80835 | 2011-06-27 19:08:49 -0700 | [diff] [blame] | 72 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 73 | mItems.add(new ListItem(res, R.string.group_wallpapers, |
Daniel Sandler | 9a60d54 | 2009-10-06 12:57:42 -0400 | [diff] [blame] | 74 | R.drawable.ic_launcher_wallpaper, ITEM_WALLPAPER)); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | public View getView(int position, View convertView, ViewGroup parent) { |
| 78 | ListItem item = (ListItem) getItem(position); |
Winson Chung | 5a80835 | 2011-06-27 19:08:49 -0700 | [diff] [blame] | 79 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 80 | if (convertView == null) { |
| 81 | convertView = mInflater.inflate(R.layout.add_list_item, parent, false); |
| 82 | } |
Winson Chung | 5a80835 | 2011-06-27 19:08:49 -0700 | [diff] [blame] | 83 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 84 | TextView textView = (TextView) convertView; |
| 85 | textView.setTag(item); |
| 86 | textView.setText(item.text); |
| 87 | textView.setCompoundDrawablesWithIntrinsicBounds(item.image, null, null, null); |
Winson Chung | 5a80835 | 2011-06-27 19:08:49 -0700 | [diff] [blame] | 88 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 89 | return convertView; |
| 90 | } |
| 91 | |
| 92 | public int getCount() { |
| 93 | return mItems.size(); |
| 94 | } |
| 95 | |
| 96 | public Object getItem(int position) { |
| 97 | return mItems.get(position); |
| 98 | } |
| 99 | |
| 100 | public long getItemId(int position) { |
| 101 | return position; |
| 102 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 103 | } |