+++ /dev/null
-/* \r
- * Copyright (C) 2008 OpenIntents.org\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openintents.util;\r
-\r
-import java.util.List;\r
-\r
-import android.content.ComponentName;\r
-import android.content.Context;\r
-import android.content.Intent;\r
-import android.content.pm.PackageManager;\r
-import android.content.pm.ResolveInfo;\r
-import android.view.Menu;\r
-import android.view.MenuItem;\r
-\r
-/**\r
- * Adds intent options with icons.\r
- * \r
- * This code is retrieved from this message:\r
- * http://groups.google.com/group/android-developers/browse_frm/thread/3fed25cdda765b02\r
- * \r
- */\r
-public class MenuIntentOptionsWithIcons {\r
-\r
- Context mContext;\r
- Menu mMenu;\r
-\r
- public MenuIntentOptionsWithIcons(Context context, Menu menu) {\r
- mContext = context;\r
- mMenu = menu;\r
- }\r
-\r
- public int addIntentOptions(int group, int id, int categoryOrder,\r
- ComponentName caller, Intent[] specifics, Intent intent, int flags,\r
- MenuItem[] outSpecificItems) {\r
- PackageManager pm = mContext.getPackageManager();\r
- final List<ResolveInfo> lri = pm.queryIntentActivityOptions(caller,\r
- specifics, intent, 0);\r
- final int N = lri != null ? lri.size() : 0;\r
- if ((flags & Menu.FLAG_APPEND_TO_GROUP) == 0) {\r
- mMenu.removeGroup(group);\r
- }\r
- for (int i = 0; i < N; i++) {\r
- final ResolveInfo ri = lri.get(i);\r
- Intent rintent = new Intent(ri.specificIndex < 0 ? intent\r
- : specifics[ri.specificIndex]);\r
- rintent.setComponent(new ComponentName(\r
- ri.activityInfo.applicationInfo.packageName,\r
- ri.activityInfo.name));\r
- final MenuItem item = mMenu.add(group, id, categoryOrder,\r
- ri.loadLabel(pm)).setIcon(ri.loadIcon(pm)).setIntent(\r
- rintent);\r
- if (outSpecificItems != null && ri.specificIndex >= 0) {\r
- outSpecificItems[ri.specificIndex] = item;\r
- }\r
- }\r
- return N;\r
- }\r
-}\r