();
30 | }
31 |
32 | public void put(String type, String extension) {
33 | // Convert extensions to lower case letters for easier comparison
34 | extension = extension.toLowerCase();
35 |
36 | mMimeTypes.put(type, extension);
37 | }
38 |
39 | public String getMimeType(String filename) {
40 |
41 | String extension = FileUtils.getExtension(filename);
42 |
43 | // Let's check the official map first. Webkit has a nice extension-to-MIME map.
44 | // Be sure to remove the first character from the extension, which is the "." character.
45 | if (extension.length() > 0) {
46 | String webkitMimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension.substring(1));
47 |
48 | if (webkitMimeType != null) {
49 | // Found one. Let's take it!
50 | return webkitMimeType;
51 | }
52 | }
53 |
54 | // Convert extensions to lower case letters for easier comparison
55 | extension = extension.toLowerCase();
56 |
57 | String mimetype = mMimeTypes.get(extension);
58 |
59 | return mimetype;
60 | }
61 |
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/src/org/openintents/intents/AboutMiniIntents.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008-2009 OpenIntents.org
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 org.openintents.intents;
18 |
19 | /**
20 | * Intents definition belonging to OI About.
21 | *
22 | * @version 2009-Jan-08
23 | *
24 | * @author pjv
25 | * @author Peli
26 | *
27 | */
28 | public final class AboutMiniIntents {
29 |
30 | /**
31 | * Empty, preventing instantiation.
32 | */
33 | private AboutMiniIntents() {
34 | //Empty, preventing instantiation.
35 | }
36 |
37 | /**
38 | * Activity Action: Show an about dialog to display
39 | * information about the application.
40 | *
41 | * The application information is retrieved from the
42 | * application's manifest. In order to send the package
43 | * you have to launch this activity through
44 | * startActivityForResult().
45 | *
46 | * Alternatively, you can specify the package name
47 | * manually through the extra EXTRA_PACKAGE.
48 | *
49 | * All data can be replaced using optional intent extras.
50 | *
51 | *
52 | * Constant Value: "org.openintents.action.SHOW_ABOUT_DIALOG"
53 | *
54 | */
55 | public static final String ACTION_SHOW_ABOUT_DIALOG =
56 | "org.openintents.action.SHOW_ABOUT_DIALOG";
57 |
58 | /**
59 | * Optional intent extra: Specify your application package name.
60 | *
61 | * If you start the About dialog through startActivityForResult()
62 | * then the application package is sent automatically and does
63 | * not need to be supplied here.
64 | *
65 | *
66 | * Constant Value: "org.openintents.extra.PACKAGE_NAME"
67 | *
68 | */
69 | public static final String EXTRA_PACKAGE_NAME =
70 | "org.openintents.extra.PACKAGE_NAME";
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/src/org/openintents/intents/FileManagerIntents.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 OpenIntents.org
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 org.openintents.intents;
18 |
19 | // Version Dec 9, 2008
20 |
21 |
22 | /**
23 | * Provides OpenIntents actions, extras, and categories used by providers.
24 | * These specifiers extend the standard Android specifiers.
25 | */
26 | public final class FileManagerIntents {
27 |
28 | /**
29 | * Activity Action: Pick a file through the file manager, or let user
30 | * specify a custom file name.
31 | * Data is the current file name or file name suggestion.
32 | * Returns a new file name as file URI in data.
33 | *
34 | * Constant Value: "org.openintents.action.PICK_FILE"
35 | */
36 | public static final String ACTION_PICK_FILE = "org.openintents.action.PICK_FILE";
37 |
38 | /**
39 | * Activity Action: Pick a directory through the file manager, or let user
40 | * specify a custom file name.
41 | * Data is the current directory name or directory name suggestion.
42 | * Returns a new directory name as file URI in data.
43 | *
44 | * Constant Value: "org.openintents.action.PICK_DIRECTORY"
45 | */
46 | public static final String ACTION_PICK_DIRECTORY = "org.openintents.action.PICK_DIRECTORY";
47 |
48 | /**
49 | * The title to display.
50 | *
51 | * This is shown in the title bar of the file manager.
52 | *
53 | * Constant Value: "org.openintents.extra.TITLE"
54 | */
55 | public static final String EXTRA_TITLE = "org.openintents.extra.TITLE";
56 |
57 | /**
58 | * The text on the button to display.
59 | *
60 | * Depending on the use, it makes sense to set this to "Open" or "Save".
61 | *
62 | * Constant Value: "org.openintents.extra.BUTTON_TEXT"
63 | */
64 | public static final String EXTRA_BUTTON_TEXT = "org.openintents.extra.BUTTON_TEXT";
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/src/org/openintents/util/IntentUtils.java:
--------------------------------------------------------------------------------
1 |
2 |
3 | /**
4 | * Original method retrieved from:
5 | * http://android-developers.blogspot.com/2009/01/can-i-use-this-intent.html
6 | */
7 | package org.openintents.util;
8 |
9 | import java.util.List;
10 |
11 | import android.content.Context;
12 | import android.content.Intent;
13 | import android.content.pm.PackageManager;
14 | import android.content.pm.ResolveInfo;
15 |
16 | /**
17 | *
18 | * @author romainguy
19 | * @author Peli
20 | *
21 | */
22 | public class IntentUtils {
23 |
24 | /**
25 | * Indicates whether the specified action can be used as an intent. This
26 | * method queries the package manager for installed packages that can
27 | * respond to the specified intent. If no suitable package is
28 | * found, this method returns false.
29 | *
30 | * @param context The application's environment.
31 | * @param intent The Intent to check for availability.
32 | *
33 | * @return True if an Intent with the specified action can be sent and
34 | * responded to, false otherwise.
35 | */
36 | public static boolean isIntentAvailable(final Context context, final Intent intent) {
37 | final PackageManager packageManager = context.getPackageManager();
38 | List list =
39 | packageManager.queryIntentActivities(intent,
40 | PackageManager.MATCH_DEFAULT_ONLY);
41 | return list.size() > 0;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/org/openintents/util/MenuIntentOptionsWithIcons.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 OpenIntents.org
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 org.openintents.util;
18 |
19 | import java.util.List;
20 |
21 | import android.content.ComponentName;
22 | import android.content.Context;
23 | import android.content.Intent;
24 | import android.content.pm.PackageManager;
25 | import android.content.pm.ResolveInfo;
26 | import android.view.Menu;
27 | import android.view.MenuItem;
28 |
29 | /**
30 | * Adds intent options with icons.
31 | *
32 | * This code is retrieved from this message:
33 | * http://groups.google.com/group/android-developers/browse_frm/thread/3fed25cdda765b02
34 | *
35 | */
36 | public class MenuIntentOptionsWithIcons {
37 |
38 | Context mContext;
39 | Menu mMenu;
40 |
41 | public MenuIntentOptionsWithIcons(Context context, Menu menu) {
42 | mContext = context;
43 | mMenu = menu;
44 | }
45 |
46 | public int addIntentOptions(int group, int id, int categoryOrder,
47 | ComponentName caller, Intent[] specifics, Intent intent, int flags,
48 | MenuItem[] outSpecificItems) {
49 | PackageManager pm = mContext.getPackageManager();
50 | final List lri = pm.queryIntentActivityOptions(caller,
51 | specifics, intent, 0);
52 | final int N = lri != null ? lri.size() : 0;
53 | if ((flags & Menu.FLAG_APPEND_TO_GROUP) == 0) {
54 | mMenu.removeGroup(group);
55 | }
56 | for (int i = 0; i < N; i++) {
57 | final ResolveInfo ri = lri.get(i);
58 | Intent rintent = new Intent(ri.specificIndex < 0 ? intent
59 | : specifics[ri.specificIndex]);
60 | rintent.setComponent(new ComponentName(
61 | ri.activityInfo.applicationInfo.packageName,
62 | ri.activityInfo.name));
63 | final MenuItem item = mMenu.add(group, id, categoryOrder,
64 | ri.loadLabel(pm)).setIcon(ri.loadIcon(pm)).setIntent(
65 | rintent);
66 | if (outSpecificItems != null && ri.specificIndex >= 0) {
67 | outSpecificItems[ri.specificIndex] = item;
68 | }
69 | }
70 | return N;
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/org/openintents/util/VersionUtils.java:
--------------------------------------------------------------------------------
1 | package org.openintents.util;
2 |
3 | import android.content.Context;
4 | import android.content.pm.PackageInfo;
5 | import android.content.pm.PackageManager;
6 | import android.util.Log;
7 |
8 | /**
9 | *
10 | * @version 2009-01-15
11 | * @author Peli
12 | *
13 | */
14 | public class VersionUtils {
15 |
16 | private static final String TAG = "VersionUtils";
17 |
18 | /**
19 | * Get current version number.
20 | *
21 | * @return
22 | */
23 | public static String getVersionNumber(Context context) {
24 | String version = "?";
25 | try {
26 | PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
27 | version = pi.versionName;
28 | } catch (PackageManager.NameNotFoundException e) {
29 | Log.e(TAG, "Package name not found", e);
30 | };
31 | return version;
32 | }
33 |
34 | /**
35 | * Get application name.
36 | *
37 | * @return
38 | */
39 | public static String getApplicationName(Context context) {
40 | String name = "?";
41 | try {
42 | PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
43 | name = context.getString(pi.applicationInfo.labelRes);
44 | } catch (PackageManager.NameNotFoundException e) {
45 | Log.e(TAG, "Package name not found", e);
46 | };
47 | return name;
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------