();
+ }
+
+ /* I think the type and extension names are switched (type contains .png, extension contains x/y),
+ * but maybe it's on purpouse, so I won't change it.
+ */
+ public void put(String type, String extension, int icon){
+ put(type, extension);
+ mIcons.put(extension, icon);
+ }
+
+ public void put(String type, String extension) {
+ // Convert extensions to lower case letters for easier comparison
+ extension = extension.toLowerCase();
+
+ mMimeTypes.put(type, extension);
+ }
+
+ public String getMimeType(String filename) {
+
+ String extension = FileUtils.getExtension(filename);
+
+ // Let's check the official map first. Webkit has a nice extension-to-MIME map.
+ // Be sure to remove the first character from the extension, which is the "." character.
+ if (extension.length() > 0) {
+ String webkitMimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension.substring(1));
+
+ if (webkitMimeType != null) {
+ // Found one. Let's take it!
+ return webkitMimeType;
+ }
+ }
+
+ // Convert extensions to lower case letters for easier comparison
+ extension = extension.toLowerCase();
+
+ String mimetype = mMimeTypes.get(extension);
+
+ if(mimetype==null) mimetype = "*/*";
+
+ return mimetype;
+ }
+
+ public int getIcon(String mimetype){
+ Integer iconResId = mIcons.get(mimetype);
+ if(iconResId == null)
+ return 0; // Invalid identifier
+ return iconResId;
+ }
+}
diff --git a/src/org/openintents/intents/FileManagerIntents.java b/src/org/openintents/intents/FileManagerIntents.java
index 14e46cf..f0cfc9d 100644
--- a/src/org/openintents/intents/FileManagerIntents.java
+++ b/src/org/openintents/intents/FileManagerIntents.java
@@ -1,66 +1,83 @@
-/*
- * 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.intents;
-
-// Version Dec 9, 2008
-
-
-/**
- * Provides OpenIntents actions, extras, and categories used by providers.
- * These specifiers extend the standard Android specifiers.
- */
-public final class FileManagerIntents {
-
- /**
- * Activity Action: Pick a file through the file manager, or let user
- * specify a custom file name.
- * Data is the current file name or file name suggestion.
- * Returns a new file name as file URI in data.
- *
- * Constant Value: "org.openintents.action.PICK_FILE"
- */
- public static final String ACTION_PICK_FILE = "org.openintents.action.PICK_FILE";
-
- /**
- * Activity Action: Pick a directory through the file manager, or let user
- * specify a custom file name.
- * Data is the current directory name or directory name suggestion.
- * Returns a new directory name as file URI in data.
- *
- * Constant Value: "org.openintents.action.PICK_DIRECTORY"
- */
- public static final String ACTION_PICK_DIRECTORY = "org.openintents.action.PICK_DIRECTORY";
-
- /**
- * The title to display.
- *
- * This is shown in the title bar of the file manager.
- *
- * Constant Value: "org.openintents.extra.TITLE"
- */
- public static final String EXTRA_TITLE = "org.openintents.extra.TITLE";
-
- /**
- * The text on the button to display.
- *
- * Depending on the use, it makes sense to set this to "Open" or "Save".
- *
- * Constant Value: "org.openintents.extra.BUTTON_TEXT"
- */
- public static final String EXTRA_BUTTON_TEXT = "org.openintents.extra.BUTTON_TEXT";
-
-}
+/*
+ * 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.intents;
+
+import android.content.Intent;
+
+// Version Dec 9, 2008
+
+
+/**
+ * Provides OpenIntents actions, extras, and categories used by providers.
+ * These specifiers extend the standard Android specifiers.
+ */
+public final class FileManagerIntents {
+
+ /**
+ * Activity Action: Pick a file through the file manager, or let user
+ * specify a custom file name.
+ * Data is the current file name or file name suggestion.
+ * Returns a new file name as file URI in data.
+ *
+ * Constant Value: "org.openintents.action.PICK_FILE"
+ */
+ public static final String ACTION_PICK_FILE = "org.openintents.action.PICK_FILE";
+
+ /**
+ * Activity Action: Pick a directory through the file manager, or let user
+ * specify a custom file name.
+ * Data is the current directory name or directory name suggestion.
+ * Returns a new directory name as file URI in data.
+ *
+ * Constant Value: "org.openintents.action.PICK_DIRECTORY"
+ */
+ public static final String ACTION_PICK_DIRECTORY = "org.openintents.action.PICK_DIRECTORY";
+
+ /**
+ * Activity Action: Move, copy or delete after select entries.
+ * Data is the current directory name or directory name suggestion.
+ *
+ * Constant Value: "org.openintents.action.MULTI_SELECT"
+ */
+ public static final String ACTION_MULTI_SELECT = "org.openintents.action.MULTI_SELECT";
+
+ /**
+ * The title to display.
+ *
+ * This is shown in the title bar of the file manager.
+ *
+ * Constant Value: "org.openintents.extra.TITLE"
+ */
+ public static final String EXTRA_TITLE = "org.openintents.extra.TITLE";
+
+ /**
+ * The text on the button to display.
+ *
+ * Depending on the use, it makes sense to set this to "Open" or "Save".
+ *
+ * Constant Value: "org.openintents.extra.BUTTON_TEXT"
+ */
+ public static final String EXTRA_BUTTON_TEXT = "org.openintents.extra.BUTTON_TEXT";
+
+ /**
+ * Flag indicating to show only writeable files and folders.
+ *
+ * Constant Value: "org.openintents.extra.WRITEABLE_ONLY"
+ */
+ public static final String EXTRA_WRITEABLE_ONLY = "org.openintents.extra.WRITEABLE_ONLY";
+
+}
diff --git a/src/org/openintents/util/IntentUtils.java b/src/org/openintents/util/IntentUtils.java
index 40af900..e4f71b9 100644
--- a/src/org/openintents/util/IntentUtils.java
+++ b/src/org/openintents/util/IntentUtils.java
@@ -1,43 +1,43 @@
-
-
-/**
- * Original method retrieved from:
- * http://android-developers.blogspot.com/2009/01/can-i-use-this-intent.html
- */
-package org.openintents.util;
-
-import java.util.List;
-
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-
-/**
- *
- * @author romainguy
- * @author Peli
- *
- */
-public class IntentUtils {
-
- /**
- * Indicates whether the specified action can be used as an intent. This
- * method queries the package manager for installed packages that can
- * respond to the specified intent. If no suitable package is
- * found, this method returns false.
- *
- * @param context The application's environment.
- * @param intent The Intent to check for availability.
- *
- * @return True if an Intent with the specified action can be sent and
- * responded to, false otherwise.
- */
- public static boolean isIntentAvailable(final Context context, final Intent intent) {
- final PackageManager packageManager = context.getPackageManager();
- List list =
- packageManager.queryIntentActivities(intent,
- PackageManager.MATCH_DEFAULT_ONLY);
- return list.size() > 0;
- }
-}
+
+
+/**
+ * Original method retrieved from:
+ * http://android-developers.blogspot.com/2009/01/can-i-use-this-intent.html
+ */
+package org.openintents.util;
+
+import java.util.List;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+
+/**
+ *
+ * @author romainguy
+ * @author Peli
+ *
+ */
+public class IntentUtils {
+
+ /**
+ * Indicates whether the specified action can be used as an intent. This
+ * method queries the package manager for installed packages that can
+ * respond to the specified intent. If no suitable package is
+ * found, this method returns false.
+ *
+ * @param context The application's environment.
+ * @param intent The Intent to check for availability.
+ *
+ * @return True if an Intent with the specified action can be sent and
+ * responded to, false otherwise.
+ */
+ public static boolean isIntentAvailable(final Context context, final Intent intent) {
+ final PackageManager packageManager = context.getPackageManager();
+ List list =
+ packageManager.queryIntentActivities(intent,
+ PackageManager.MATCH_DEFAULT_ONLY);
+ return list.size() > 0;
+ }
+}
diff --git a/src/org/openintents/util/MenuIntentOptionsWithIcons.java b/src/org/openintents/util/MenuIntentOptionsWithIcons.java
index c451b02..3474e50 100644
--- a/src/org/openintents/util/MenuIntentOptionsWithIcons.java
+++ b/src/org/openintents/util/MenuIntentOptionsWithIcons.java
@@ -1,72 +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;
- }
-}
+/*
+ * 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;
+ }
+}
diff --git a/src/org/openintents/util/VersionUtils.java b/src/org/openintents/util/VersionUtils.java
index f86a30b..714cfbb 100644
--- a/src/org/openintents/util/VersionUtils.java
+++ b/src/org/openintents/util/VersionUtils.java
@@ -1,50 +1,123 @@
-package org.openintents.util;
-
-import android.content.Context;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager;
-import android.util.Log;
-
-/**
- *
- * @version 2009-01-15
- * @author Peli
- *
- */
-public class VersionUtils {
-
- private static final String TAG = "VersionUtils";
-
- /**
- * Get current version number.
- *
- * @return
- */
- public static String getVersionNumber(Context context) {
- String version = "?";
- try {
- PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
- version = pi.versionName;
- } catch (PackageManager.NameNotFoundException e) {
- Log.e(TAG, "Package name not found", e);
- };
- return version;
- }
-
- /**
- * Get application name.
- *
- * @return
- */
- public static String getApplicationName(Context context) {
- String name = "?";
- try {
- PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
- name = context.getString(pi.applicationInfo.labelRes);
- } catch (PackageManager.NameNotFoundException e) {
- Log.e(TAG, "Package name not found", e);
- };
- return name;
- }
-
-}
+/*
+ * Copyright (C) 2007-2009 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 android.content.Context;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.os.Build;
+import android.util.Log;
+
+/**
+ *
+ * @version 2011-01-22
+ * @author Peli
+ *
+ */
+public class VersionUtils {
+
+ private static final String TAG = "VersionUtils";
+
+ /**
+ * Get current version code.
+ *
+ * @return
+ */
+ public static int getVersionCode(Context context) {
+ int version = 0;
+ try {
+ PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
+ version = pi.versionCode;
+ } catch (PackageManager.NameNotFoundException e) {
+ Log.e(TAG, "Package name not found", e);
+ };
+ return version;
+ }
+
+ /**
+ * Get current version number.
+ *
+ * @return
+ */
+ public static String getVersionNumber(Context context) {
+ String version = "?";
+ try {
+ PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
+ version = pi.versionName;
+ } catch (PackageManager.NameNotFoundException e) {
+ Log.e(TAG, "Package name not found", e);
+ };
+ return version;
+ }
+
+ /**
+ * Get application name.
+ *
+ * Since API level 4 this routine could be replaced by
+ * appname = getString(getApplicationInfo().labelRes);
+ *
+ * @return
+ */
+ public static String getApplicationName(Context context) {
+ String name = "?";
+ try {
+ PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
+ name = context.getString(pi.applicationInfo.labelRes);
+ } catch (PackageManager.NameNotFoundException e) {
+ Log.e(TAG, "Package name not found", e);
+ };
+ return name;
+ }
+
+ /**
+ * Get application icon.
+ *
+ * Since API level 4 this routine could be replaced by
+ * icon = getApplicationInfo().icon;
+ *
+ * @return
+ */
+ public static int getApplicationIcon(Context context) {
+ int icon = 0;
+ try {
+ PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
+ icon = pi.applicationInfo.icon;
+ } catch (PackageManager.NameNotFoundException e) {
+ Log.e(TAG, "Package name not found", e);
+ };
+ return icon;
+ }
+
+ /**
+ * Indicates whether a specific package with minimum version code is available.
+ */
+ public static boolean isPackageAvailable(final Context context, final String packageName,
+ final int minVersionCode) {
+ boolean result = false;
+ try {
+ PackageInfo pi = context.getPackageManager().getPackageInfo(
+ packageName, 0);
+ if (pi.versionCode >= minVersionCode) {
+ result = true;
+ }
+ } catch (PackageManager.NameNotFoundException e) {
+
+ }
+ return result;
+ }
+}