X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=apps%2Foi-filemanager%2FFileManager%2Fsrc%2Forg%2Fopenintents%2Futil%2FMenuIntentOptionsWithIcons.java;fp=apps%2Foi-filemanager%2FFileManager%2Fsrc%2Forg%2Fopenintents%2Futil%2FMenuIntentOptionsWithIcons.java;h=3474e5061bdacb8b4c4fb6664f76948948949a3a;hb=811a5a4a3091f65fef340acafe62d6355b13c44f;hp=0000000000000000000000000000000000000000;hpb=4401ca4aa1b3938939c6c371dfda57aa0652696f;p=android_pandora.git diff --git a/apps/oi-filemanager/FileManager/src/org/openintents/util/MenuIntentOptionsWithIcons.java b/apps/oi-filemanager/FileManager/src/org/openintents/util/MenuIntentOptionsWithIcons.java new file mode 100644 index 0000000..3474e50 --- /dev/null +++ b/apps/oi-filemanager/FileManager/src/org/openintents/util/MenuIntentOptionsWithIcons.java @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2008 OpenIntents.org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.openintents.util; + +import java.util.List; + +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; +import android.view.Menu; +import android.view.MenuItem; + +/** + * Adds intent options with icons. + * + * This code is retrieved from this message: + * http://groups.google.com/group/android-developers/browse_frm/thread/3fed25cdda765b02 + * + */ +public class MenuIntentOptionsWithIcons { + + Context mContext; + Menu mMenu; + + public MenuIntentOptionsWithIcons(Context context, Menu menu) { + mContext = context; + mMenu = menu; + } + + public int addIntentOptions(int group, int id, int categoryOrder, + ComponentName caller, Intent[] specifics, Intent intent, int flags, + MenuItem[] outSpecificItems) { + PackageManager pm = mContext.getPackageManager(); + final List lri = pm.queryIntentActivityOptions(caller, + specifics, intent, 0); + final int N = lri != null ? lri.size() : 0; + if ((flags & Menu.FLAG_APPEND_TO_GROUP) == 0) { + mMenu.removeGroup(group); + } + for (int i = 0; i < N; i++) { + final ResolveInfo ri = lri.get(i); + Intent rintent = new Intent(ri.specificIndex < 0 ? intent + : specifics[ri.specificIndex]); + rintent.setComponent(new ComponentName( + ri.activityInfo.applicationInfo.packageName, + ri.activityInfo.name)); + final MenuItem item = mMenu.add(group, id, categoryOrder, + ri.loadLabel(pm)).setIcon(ri.loadIcon(pm)).setIntent( + rintent); + if (outSpecificItems != null && ri.specificIndex >= 0) { + outSpecificItems[ri.specificIndex] = item; + } + } + return N; + } +}