The Android Open Source Project | c8f00b6 | 2008-10-21 07:00:00 -0700 | [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 | |
| 17 | package com.android.launcher; |
| 18 | |
The Android Open Source Project | c8f00b6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 19 | import android.content.Context; |
The Android Open Source Project | 15a8880 | 2009-02-10 15:44:05 -0800 | [diff] [blame] | 20 | import android.content.res.Resources; |
| 21 | import android.graphics.drawable.Drawable; |
The Android Open Source Project | c8f00b6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 22 | import android.view.LayoutInflater; |
| 23 | import android.view.View; |
| 24 | import android.view.ViewGroup; |
The Android Open Source Project | 15a8880 | 2009-02-10 15:44:05 -0800 | [diff] [blame] | 25 | import android.widget.BaseAdapter; |
The Android Open Source Project | c8f00b6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 26 | import android.widget.TextView; |
The Android Open Source Project | c8f00b6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 27 | |
| 28 | import java.util.ArrayList; |
The Android Open Source Project | c8f00b6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 29 | |
| 30 | /** |
The Android Open Source Project | 15a8880 | 2009-02-10 15:44:05 -0800 | [diff] [blame] | 31 | * Adapter showing the types of items that can be added to a {@link Workspace}. |
The Android Open Source Project | c8f00b6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 32 | */ |
The Android Open Source Project | 15a8880 | 2009-02-10 15:44:05 -0800 | [diff] [blame] | 33 | public class AddAdapter extends BaseAdapter { |
| 34 | |
| 35 | private final Launcher mLauncher; |
The Android Open Source Project | c8f00b6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 36 | private final LayoutInflater mInflater; |
The Android Open Source Project | 15a8880 | 2009-02-10 15:44:05 -0800 | [diff] [blame] | 37 | |
| 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 Project | c8f00b6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 47 | |
| 48 | /** |
The Android Open Source Project | 15a8880 | 2009-02-10 15:44:05 -0800 | [diff] [blame] | 49 | * Specific item in our list. |
The Android Open Source Project | c8f00b6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 50 | */ |
The Android Open Source Project | 15a8880 | 2009-02-10 15:44:05 -0800 | [diff] [blame] | 51 | public class ListItem { |
| 52 | public final CharSequence text; |
| 53 | public final Drawable image; |
| 54 | public final int actionTag; |
The Android Open Source Project | c8f00b6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 55 | |
The Android Open Source Project | 15a8880 | 2009-02-10 15:44:05 -0800 | [diff] [blame] | 56 | 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 Project | c8f00b6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 62 | } |
The Android Open Source Project | 15a8880 | 2009-02-10 15:44:05 -0800 | [diff] [blame] | 63 | this.actionTag = actionTag; |
The Android Open Source Project | c8f00b6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 64 | } |
| 65 | } |
| 66 | |
The Android Open Source Project | 15a8880 | 2009-02-10 15:44:05 -0800 | [diff] [blame] | 67 | public AddAdapter(Launcher launcher) { |
| 68 | super(); |
| 69 | |
The Android Open Source Project | c8f00b6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 70 | mLauncher = launcher; |
The Android Open Source Project | 15a8880 | 2009-02-10 15:44:05 -0800 | [diff] [blame] | 71 | 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 Project | c8f00b6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 96 | |
The Android Open Source Project | 15a8880 | 2009-02-10 15:44:05 -0800 | [diff] [blame] | 97 | } |
The Android Open Source Project | c8f00b6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 98 | |
The Android Open Source Project | 15a8880 | 2009-02-10 15:44:05 -0800 | [diff] [blame] | 99 | 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 Project | c8f00b6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 104 | } |
| 105 | |
The Android Open Source Project | 15a8880 | 2009-02-10 15:44:05 -0800 | [diff] [blame] | 106 | 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 Project | c8f00b6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 112 | } |
| 113 | |
The Android Open Source Project | 15a8880 | 2009-02-10 15:44:05 -0800 | [diff] [blame] | 114 | public int getCount() { |
| 115 | return mItems.size(); |
The Android Open Source Project | c8f00b6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 116 | } |
| 117 | |
The Android Open Source Project | 15a8880 | 2009-02-10 15:44:05 -0800 | [diff] [blame] | 118 | public Object getItem(int position) { |
| 119 | return mItems.get(position); |
The Android Open Source Project | c8f00b6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 120 | } |
| 121 | |
The Android Open Source Project | 15a8880 | 2009-02-10 15:44:05 -0800 | [diff] [blame] | 122 | public long getItemId(int position) { |
| 123 | return position; |
The Android Open Source Project | c8f00b6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 124 | } |
The Android Open Source Project | 15a8880 | 2009-02-10 15:44:05 -0800 | [diff] [blame] | 125 | |
The Android Open Source Project | c8f00b6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 126 | } |