2 * Copyright (C) 2008 OpenIntents.org
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 package org.openintents.util;
\r
19 import java.util.List;
\r
21 import android.content.ComponentName;
\r
22 import android.content.Context;
\r
23 import android.content.Intent;
\r
24 import android.content.pm.PackageManager;
\r
25 import android.content.pm.ResolveInfo;
\r
26 import android.view.Menu;
\r
27 import android.view.MenuItem;
\r
30 * Adds intent options with icons.
\r
32 * This code is retrieved from this message:
\r
33 * http://groups.google.com/group/android-developers/browse_frm/thread/3fed25cdda765b02
\r
36 public class MenuIntentOptionsWithIcons {
\r
41 public MenuIntentOptionsWithIcons(Context context, Menu menu) {
\r
46 public int addIntentOptions(int group, int id, int categoryOrder,
\r
47 ComponentName caller, Intent[] specifics, Intent intent, int flags,
\r
48 MenuItem[] outSpecificItems) {
\r
49 PackageManager pm = mContext.getPackageManager();
\r
50 final List<ResolveInfo> lri = pm.queryIntentActivityOptions(caller,
\r
51 specifics, intent, 0);
\r
52 final int N = lri != null ? lri.size() : 0;
\r
53 if ((flags & Menu.FLAG_APPEND_TO_GROUP) == 0) {
\r
54 mMenu.removeGroup(group);
\r
56 for (int i = 0; i < N; i++) {
\r
57 final ResolveInfo ri = lri.get(i);
\r
58 Intent rintent = new Intent(ri.specificIndex < 0 ? intent
\r
59 : specifics[ri.specificIndex]);
\r
60 rintent.setComponent(new ComponentName(
\r
61 ri.activityInfo.applicationInfo.packageName,
\r
62 ri.activityInfo.name));
\r
63 final MenuItem item = mMenu.add(group, id, categoryOrder,
\r
64 ri.loadLabel(pm)).setIcon(ri.loadIcon(pm)).setIntent(
\r
66 if (outSpecificItems != null && ri.specificIndex >= 0) {
\r
67 outSpecificItems[ri.specificIndex] = item;
\r