diff --git a/.gitignore b/.gitignore index cf2dbca..46d29ed 100644 --- a/.gitignore +++ b/.gitignore @@ -1,54 +1,8 @@ -# ndk generated files -**/obj/ - -# built application files -*.apk -*.ap_ - -# lint files -lint.xml - -# files for the dex VM -*.dex - -# Java class files -*.class - -# generated files -bin/ -gen/ -classes/ -gen-external-apklibs/ - -# maven output folder -target - -# Local configuration file (sdk path, etc) +build +.idea +.gradle +gradle local.properties +import-summary.txt +aFileChooser.iml -# Eclipse project files -.classpath -.project -.metadata -.settings - -# Proguard folder generated by Eclipse -proguard/ - -# IntelliJ files -*.iml -*.ipr -*.iws -.idea/ - -# OSX files -.DS_Store - -# Windows files -Thumbs.db - -# vi swap files -*.swp - -# backup files -*.bak \ No newline at end of file diff --git a/aFileChooser/.gitignore b/aFileChooser/.gitignore new file mode 100644 index 0000000..1d8441d --- /dev/null +++ b/aFileChooser/.gitignore @@ -0,0 +1,2 @@ +build +aFileChooser-aFileChooser.iml diff --git a/aFileChooser/build.gradle b/aFileChooser/build.gradle new file mode 100644 index 0000000..51feddf --- /dev/null +++ b/aFileChooser/build.gradle @@ -0,0 +1,22 @@ +apply plugin: 'com.android.library' + +android { + compileSdkVersion 19 + buildToolsVersion "24.0.1" + + defaultConfig { + minSdkVersion 7 + targetSdkVersion 7 + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' + } + } +} + +dependencies { + compile 'com.android.support:support-v4:19.1.0' +} diff --git a/aFileChooser/proguard.cfg b/aFileChooser/proguard.cfg deleted file mode 100644 index b1cdf17..0000000 --- a/aFileChooser/proguard.cfg +++ /dev/null @@ -1,40 +0,0 @@ --optimizationpasses 5 --dontusemixedcaseclassnames --dontskipnonpubliclibraryclasses --dontpreverify --verbose --optimizations !code/simplification/arithmetic,!field/*,!class/merging/* - --keep public class * extends android.app.Activity --keep public class * extends android.app.Application --keep public class * extends android.app.Service --keep public class * extends android.content.BroadcastReceiver --keep public class * extends android.content.ContentProvider --keep public class * extends android.app.backup.BackupAgentHelper --keep public class * extends android.preference.Preference --keep public class com.android.vending.licensing.ILicensingService - --keepclasseswithmembernames class * { - native ; -} - --keepclasseswithmembers class * { - public (android.content.Context, android.util.AttributeSet); -} - --keepclasseswithmembers class * { - public (android.content.Context, android.util.AttributeSet, int); -} - --keepclassmembers class * extends android.app.Activity { - public void *(android.view.View); -} - --keepclassmembers enum * { - public static **[] values(); - public static ** valueOf(java.lang.String); -} - --keep class * implements android.os.Parcelable { - public static final android.os.Parcelable$Creator *; -} diff --git a/aFileChooser/AndroidManifest.xml b/aFileChooser/src/main/AndroidManifest.xml similarity index 100% rename from aFileChooser/AndroidManifest.xml rename to aFileChooser/src/main/AndroidManifest.xml diff --git a/aFileChooser/src/com/ianhanniballake/localstorage/LocalStorageProvider.java b/aFileChooser/src/main/java/com/ianhanniballake/localstorage/LocalStorageProvider.java similarity index 100% rename from aFileChooser/src/com/ianhanniballake/localstorage/LocalStorageProvider.java rename to aFileChooser/src/main/java/com/ianhanniballake/localstorage/LocalStorageProvider.java diff --git a/aFileChooser/src/com/ipaulpro/afilechooser/FileChooserActivity.java b/aFileChooser/src/main/java/com/ipaulpro/afilechooser/FileChooserActivity.java similarity index 100% rename from aFileChooser/src/com/ipaulpro/afilechooser/FileChooserActivity.java rename to aFileChooser/src/main/java/com/ipaulpro/afilechooser/FileChooserActivity.java diff --git a/aFileChooser/src/com/ipaulpro/afilechooser/FileListAdapter.java b/aFileChooser/src/main/java/com/ipaulpro/afilechooser/FileListAdapter.java similarity index 100% rename from aFileChooser/src/com/ipaulpro/afilechooser/FileListAdapter.java rename to aFileChooser/src/main/java/com/ipaulpro/afilechooser/FileListAdapter.java diff --git a/aFileChooser/src/com/ipaulpro/afilechooser/FileListFragment.java b/aFileChooser/src/main/java/com/ipaulpro/afilechooser/FileListFragment.java similarity index 100% rename from aFileChooser/src/com/ipaulpro/afilechooser/FileListFragment.java rename to aFileChooser/src/main/java/com/ipaulpro/afilechooser/FileListFragment.java diff --git a/aFileChooser/src/com/ipaulpro/afilechooser/FileLoader.java b/aFileChooser/src/main/java/com/ipaulpro/afilechooser/FileLoader.java similarity index 100% rename from aFileChooser/src/com/ipaulpro/afilechooser/FileLoader.java rename to aFileChooser/src/main/java/com/ipaulpro/afilechooser/FileLoader.java diff --git a/aFileChooser/src/com/ipaulpro/afilechooser/utils/FileUtils.java b/aFileChooser/src/main/java/com/ipaulpro/afilechooser/utils/FileUtils.java similarity index 92% rename from aFileChooser/src/com/ipaulpro/afilechooser/utils/FileUtils.java rename to aFileChooser/src/main/java/com/ipaulpro/afilechooser/utils/FileUtils.java index 25c8008..3d13204 100644 --- a/aFileChooser/src/com/ipaulpro/afilechooser/utils/FileUtils.java +++ b/aFileChooser/src/main/java/com/ipaulpro/afilechooser/utils/FileUtils.java @@ -1,528 +1,548 @@ -/* - * Copyright (C) 2007-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 com.ipaulpro.afilechooser.utils; - -import android.content.ContentResolver; -import android.content.ContentUris; -import android.content.Context; -import android.content.Intent; -import android.database.Cursor; -import android.database.DatabaseUtils; -import android.graphics.Bitmap; -import android.net.Uri; -import android.os.Build; -import android.os.Environment; -import android.provider.DocumentsContract; -import android.provider.MediaStore; -import android.util.Log; -import android.webkit.MimeTypeMap; - -import com.ianhanniballake.localstorage.LocalStorageProvider; - -import java.io.File; -import java.io.FileFilter; -import java.text.DecimalFormat; -import java.util.Comparator; - -/** - * @version 2009-07-03 - * @author Peli - * @version 2013-12-11 - * @author paulburke (ipaulpro) - */ -public class FileUtils { - private FileUtils() {} //private constructor to enforce Singleton pattern - - /** TAG for log messages. */ - static final String TAG = "FileUtils"; - private static final boolean DEBUG = false; // Set to true to enable logging - - public static final String MIME_TYPE_AUDIO = "audio/*"; - public static final String MIME_TYPE_TEXT = "text/*"; - public static final String MIME_TYPE_IMAGE = "image/*"; - public static final String MIME_TYPE_VIDEO = "video/*"; - public static final String MIME_TYPE_APP = "application/*"; - - public static final String HIDDEN_PREFIX = "."; - - /** - * Gets the extension of a file name, like ".png" or ".jpg". - * - * @param uri - * @return Extension including the dot("."); "" if there is no extension; - * null if uri was null. - */ - public static String getExtension(String uri) { - if (uri == null) { - return null; - } - - int dot = uri.lastIndexOf("."); - if (dot >= 0) { - return uri.substring(dot); - } else { - // No extension. - return ""; - } - } - - /** - * @return Whether the URI is a local one. - */ - public static boolean isLocal(String url) { - if (url != null && !url.startsWith("http://") && !url.startsWith("https://")) { - return true; - } - return false; - } - - /** - * @return True if Uri is a MediaStore Uri. - * @author paulburke - */ - public static boolean isMediaUri(Uri uri) { - return "media".equalsIgnoreCase(uri.getAuthority()); - } - - /** - * Convert File into Uri. - * - * @param file - * @return uri - */ - public static Uri getUri(File file) { - if (file != null) { - return Uri.fromFile(file); - } - return null; - } - - /** - * Returns the path only (without file name). - * - * @param file - * @return - */ - public static File getPathWithoutFilename(File file) { - if (file != null) { - if (file.isDirectory()) { - // no file to be split off. Return everything - return file; - } else { - String filename = file.getName(); - String filepath = file.getAbsolutePath(); - - // Construct path without file name. - String pathwithoutname = filepath.substring(0, - filepath.length() - filename.length()); - if (pathwithoutname.endsWith("/")) { - pathwithoutname = pathwithoutname.substring(0, pathwithoutname.length() - 1); - } - return new File(pathwithoutname); - } - } - return null; - } - - /** - * @return The MIME type for the given file. - */ - public static String getMimeType(File file) { - - String extension = getExtension(file.getName()); - - if (extension.length() > 0) - return MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension.substring(1)); - - return "application/octet-stream"; - } - - /** - * @return The MIME type for the give Uri. - */ - public static String getMimeType(Context context, Uri uri) { - File file = new File(getPath(context, uri)); - return getMimeType(file); - } - - /** - * @param uri The Uri to check. - * @return Whether the Uri authority is {@link LocalStorageProvider}. - * @author paulburke - */ - public static boolean isLocalStorageDocument(Uri uri) { - return LocalStorageProvider.AUTHORITY.equals(uri.getAuthority()); - } - - /** - * @param uri The Uri to check. - * @return Whether the Uri authority is ExternalStorageProvider. - * @author paulburke - */ - public static boolean isExternalStorageDocument(Uri uri) { - return "com.android.externalstorage.documents".equals(uri.getAuthority()); - } - - /** - * @param uri The Uri to check. - * @return Whether the Uri authority is DownloadsProvider. - * @author paulburke - */ - public static boolean isDownloadsDocument(Uri uri) { - return "com.android.providers.downloads.documents".equals(uri.getAuthority()); - } - - /** - * @param uri The Uri to check. - * @return Whether the Uri authority is MediaProvider. - * @author paulburke - */ - public static boolean isMediaDocument(Uri uri) { - return "com.android.providers.media.documents".equals(uri.getAuthority()); - } - - /** - * @param uri The Uri to check. - * @return Whether the Uri authority is Google Photos. - */ - public static boolean isGooglePhotosUri(Uri uri) { - return "com.google.android.apps.photos.content".equals(uri.getAuthority()); - } - - /** - * Get the value of the data column for this Uri. This is useful for - * MediaStore Uris, and other file-based ContentProviders. - * - * @param context The context. - * @param uri The Uri to query. - * @param selection (Optional) Filter used in the query. - * @param selectionArgs (Optional) Selection arguments used in the query. - * @return The value of the _data column, which is typically a file path. - * @author paulburke - */ - public static String getDataColumn(Context context, Uri uri, String selection, - String[] selectionArgs) { - - Cursor cursor = null; - final String column = "_data"; - final String[] projection = { - column - }; - - try { - cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, - null); - if (cursor != null && cursor.moveToFirst()) { - if (DEBUG) - DatabaseUtils.dumpCursor(cursor); - - final int column_index = cursor.getColumnIndexOrThrow(column); - return cursor.getString(column_index); - } - } finally { - if (cursor != null) - cursor.close(); - } - return null; - } - - /** - * Get a file path from a Uri. This will get the the path for Storage Access - * Framework Documents, as well as the _data field for the MediaStore and - * other file-based ContentProviders.
- *
- * Callers should check whether the path is local before assuming it - * represents a local file. - * - * @param context The context. - * @param uri The Uri to query. - * @see #isLocal(String) - * @see #getFile(Context, Uri) - * @author paulburke - */ - public static String getPath(final Context context, final Uri uri) { - - if (DEBUG) - Log.d(TAG + " File -", - "Authority: " + uri.getAuthority() + - ", Fragment: " + uri.getFragment() + - ", Port: " + uri.getPort() + - ", Query: " + uri.getQuery() + - ", Scheme: " + uri.getScheme() + - ", Host: " + uri.getHost() + - ", Segments: " + uri.getPathSegments().toString() - ); - - final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; - - // DocumentProvider - if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) { - // LocalStorageProvider - if (isLocalStorageDocument(uri)) { - // The path is the id - return DocumentsContract.getDocumentId(uri); - } - // ExternalStorageProvider - else if (isExternalStorageDocument(uri)) { - final String docId = DocumentsContract.getDocumentId(uri); - final String[] split = docId.split(":"); - final String type = split[0]; - - if ("primary".equalsIgnoreCase(type)) { - return Environment.getExternalStorageDirectory() + "/" + split[1]; - } - - // TODO handle non-primary volumes - } - // DownloadsProvider - else if (isDownloadsDocument(uri)) { - - final String id = DocumentsContract.getDocumentId(uri); - final Uri contentUri = ContentUris.withAppendedId( - Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); - - return getDataColumn(context, contentUri, null, null); - } - // MediaProvider - else if (isMediaDocument(uri)) { - final String docId = DocumentsContract.getDocumentId(uri); - final String[] split = docId.split(":"); - final String type = split[0]; - - Uri contentUri = null; - if ("image".equals(type)) { - contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; - } else if ("video".equals(type)) { - contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; - } else if ("audio".equals(type)) { - contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; - } - - final String selection = "_id=?"; - final String[] selectionArgs = new String[] { - split[1] - }; - - return getDataColumn(context, contentUri, selection, selectionArgs); - } - } - // MediaStore (and general) - else if ("content".equalsIgnoreCase(uri.getScheme())) { - - // Return the remote address - if (isGooglePhotosUri(uri)) - return uri.getLastPathSegment(); - - return getDataColumn(context, uri, null, null); - } - // File - else if ("file".equalsIgnoreCase(uri.getScheme())) { - return uri.getPath(); - } - - return null; - } - - /** - * Convert Uri into File, if possible. - * - * @return file A local file that the Uri was pointing to, or null if the - * Uri is unsupported or pointed to a remote resource. - * @see #getPath(Context, Uri) - * @author paulburke - */ - public static File getFile(Context context, Uri uri) { - if (uri != null) { - String path = getPath(context, uri); - if (path != null && isLocal(path)) { - return new File(path); - } - } - return null; - } - - /** - * Get the file size in a human-readable string. - * - * @param size - * @return - * @author paulburke - */ - public static String getReadableFileSize(int size) { - final int BYTES_IN_KILOBYTES = 1024; - final DecimalFormat dec = new DecimalFormat("###.#"); - final String KILOBYTES = " KB"; - final String MEGABYTES = " MB"; - final String GIGABYTES = " GB"; - float fileSize = 0; - String suffix = KILOBYTES; - - if (size > BYTES_IN_KILOBYTES) { - fileSize = size / BYTES_IN_KILOBYTES; - if (fileSize > BYTES_IN_KILOBYTES) { - fileSize = fileSize / BYTES_IN_KILOBYTES; - if (fileSize > BYTES_IN_KILOBYTES) { - fileSize = fileSize / BYTES_IN_KILOBYTES; - suffix = GIGABYTES; - } else { - suffix = MEGABYTES; - } - } - } - return String.valueOf(dec.format(fileSize) + suffix); - } - - /** - * Attempt to retrieve the thumbnail of given File from the MediaStore. This - * should not be called on the UI thread. - * - * @param context - * @param file - * @return - * @author paulburke - */ - public static Bitmap getThumbnail(Context context, File file) { - return getThumbnail(context, getUri(file), getMimeType(file)); - } - - /** - * Attempt to retrieve the thumbnail of given Uri from the MediaStore. This - * should not be called on the UI thread. - * - * @param context - * @param uri - * @return - * @author paulburke - */ - public static Bitmap getThumbnail(Context context, Uri uri) { - return getThumbnail(context, uri, getMimeType(context, uri)); - } - - /** - * Attempt to retrieve the thumbnail of given Uri from the MediaStore. This - * should not be called on the UI thread. - * - * @param context - * @param uri - * @param mimeType - * @return - * @author paulburke - */ - public static Bitmap getThumbnail(Context context, Uri uri, String mimeType) { - if (DEBUG) - Log.d(TAG, "Attempting to get thumbnail"); - - if (!isMediaUri(uri)) { - Log.e(TAG, "You can only retrieve thumbnails for images and videos."); - return null; - } - - Bitmap bm = null; - if (uri != null) { - final ContentResolver resolver = context.getContentResolver(); - Cursor cursor = null; - try { - cursor = resolver.query(uri, null, null, null, null); - if (cursor.moveToFirst()) { - final int id = cursor.getInt(0); - if (DEBUG) - Log.d(TAG, "Got thumb ID: " + id); - - if (mimeType.contains("video")) { - bm = MediaStore.Video.Thumbnails.getThumbnail( - resolver, - id, - MediaStore.Video.Thumbnails.MINI_KIND, - null); - } - else if (mimeType.contains(FileUtils.MIME_TYPE_IMAGE)) { - bm = MediaStore.Images.Thumbnails.getThumbnail( - resolver, - id, - MediaStore.Images.Thumbnails.MINI_KIND, - null); - } - } - } catch (Exception e) { - if (DEBUG) - Log.e(TAG, "getThumbnail", e); - } finally { - if (cursor != null) - cursor.close(); - } - } - return bm; - } - - /** - * File and folder comparator. TODO Expose sorting option method - * - * @author paulburke - */ - public static Comparator sComparator = new Comparator() { - @Override - public int compare(File f1, File f2) { - // Sort alphabetically by lower case, which is much cleaner - return f1.getName().toLowerCase().compareTo( - f2.getName().toLowerCase()); - } - }; - - /** - * File (not directories) filter. - * - * @author paulburke - */ - public static FileFilter sFileFilter = new FileFilter() { - @Override - public boolean accept(File file) { - final String fileName = file.getName(); - // Return files only (not directories) and skip hidden files - return file.isFile() && !fileName.startsWith(HIDDEN_PREFIX); - } - }; - - /** - * Folder (directories) filter. - * - * @author paulburke - */ - public static FileFilter sDirFilter = new FileFilter() { - @Override - public boolean accept(File file) { - final String fileName = file.getName(); - // Return directories only and skip hidden directories - return file.isDirectory() && !fileName.startsWith(HIDDEN_PREFIX); - } - }; - - /** - * Get the Intent for selecting content to be used in an Intent Chooser. - * - * @return The intent for opening a file with Intent.createChooser() - * @author paulburke - */ - public static Intent createGetContentIntent() { - // Implicitly allow the user to select a particular kind of data - final Intent intent = new Intent(Intent.ACTION_GET_CONTENT); - // The MIME data type filter - intent.setType("*/*"); - // Only return URIs that can be opened with ContentResolver - intent.addCategory(Intent.CATEGORY_OPENABLE); - return intent; - } -} +/* + * Copyright (C) 2007-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 com.ipaulpro.afilechooser.utils; + +import android.content.ContentResolver; +import android.content.ContentUris; +import android.content.Context; +import android.content.Intent; +import android.database.Cursor; +import android.database.DatabaseUtils; +import android.graphics.Bitmap; +import android.net.Uri; +import android.os.Build; +import android.os.Environment; +import android.provider.DocumentsContract; +import android.provider.MediaStore; +import android.util.Log; +import android.webkit.MimeTypeMap; + +import com.ianhanniballake.localstorage.LocalStorageProvider; + +import java.io.File; +import java.io.FileFilter; +import java.text.DecimalFormat; +import java.util.Comparator; + +/** + * @author Peli + * @author paulburke (ipaulpro) + * @version 2013-12-11 + */ +public class FileUtils { + private FileUtils() { + } //private constructor to enforce Singleton pattern + + /** + * TAG for log messages. + */ + static final String TAG = "FileUtils"; + private static final boolean DEBUG = false; // Set to true to enable logging + + public static final String MIME_TYPE_AUDIO = "audio/*"; + public static final String MIME_TYPE_TEXT = "text/*"; + public static final String MIME_TYPE_IMAGE = "image/*"; + public static final String MIME_TYPE_VIDEO = "video/*"; + public static final String MIME_TYPE_APP = "application/*"; + + public static final String HIDDEN_PREFIX = "."; + + /** + * Gets the extension of a file name, like ".png" or ".jpg". + * + * @param uri + * @return Extension including the dot("."); "" if there is no extension; + * null if uri was null. + */ + public static String getExtension(String uri) { + if (uri == null) { + return null; + } + + int dot = uri.lastIndexOf("."); + if (dot >= 0) { + return uri.substring(dot); + } else { + // No extension. + return ""; + } + } + + /** + * @return Whether the URI is a local one. + */ + public static boolean isLocal(String url) { + if (url != null && !url.startsWith("http://") && !url.startsWith("https://")) { + return true; + } + return false; + } + + /** + * @return True if Uri is a MediaStore Uri. + * @author paulburke + */ + public static boolean isMediaUri(Uri uri) { + return "media".equalsIgnoreCase(uri.getAuthority()); + } + + /** + * Convert File into Uri. + * + * @param file + * @return uri + */ + public static Uri getUri(File file) { + if (file != null) { + return Uri.fromFile(file); + } + return null; + } + + /** + * Returns the path only (without file name). + * + * @param file + * @return + */ + public static File getPathWithoutFilename(File file) { + if (file != null) { + if (file.isDirectory()) { + // no file to be split off. Return everything + return file; + } else { + String filename = file.getName(); + String filepath = file.getAbsolutePath(); + + // Construct path without file name. + String pathwithoutname = filepath.substring(0, + filepath.length() - filename.length()); + if (pathwithoutname.endsWith("/")) { + pathwithoutname = pathwithoutname.substring(0, pathwithoutname.length() - 1); + } + return new File(pathwithoutname); + } + } + return null; + } + + /** + * @return The MIME type for the given file. + */ + public static String getMimeType(File file) { + + String extension = getExtension(file.getName()); + + if (extension.length() > 0) + return MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension.substring(1)); + + return "application/octet-stream"; + } + + /** + * @return The MIME type for the give Uri. + */ + public static String getMimeType(Context context, Uri uri) { + File file = new File(getPath(context, uri)); + return getMimeType(file); + } + + /** + * @param uri The Uri to check. + * @return Whether the Uri authority is {@link LocalStorageProvider}. + * @author paulburke + */ + public static boolean isLocalStorageDocument(Uri uri) { + return LocalStorageProvider.AUTHORITY.equals(uri.getAuthority()); + } + + /** + * @param uri The Uri to check. + * @return Whether the Uri authority is ExternalStorageProvider. + * @author paulburke + */ + public static boolean isExternalStorageDocument(Uri uri) { + return "com.android.externalstorage.documents".equals(uri.getAuthority()); + } + + /** + * @param uri The Uri to check. + * @return Whether the Uri authority is DownloadsProvider. + * @author paulburke + */ + public static boolean isDownloadsDocument(Uri uri) { + return "com.android.providers.downloads.documents".equals(uri.getAuthority()); + } + + /** + * @param uri The Uri to check. + * @return Whether the Uri authority is MediaProvider. + * @author paulburke + */ + public static boolean isMediaDocument(Uri uri) { + return "com.android.providers.media.documents".equals(uri.getAuthority()); + } + + /** + * @param uri The Uri to check. + * @return Whether the Uri authority is Google Photos. + */ + public static boolean isGooglePhotosUri(Uri uri) { + return "com.google.android.apps.photos.content".equals(uri.getAuthority()); + } + + /** + * Get the value of the data column for this Uri. This is useful for + * MediaStore Uris, and other file-based ContentProviders. + * + * @param context The context. + * @param uri The Uri to query. + * @param selection (Optional) Filter used in the query. + * @param selectionArgs (Optional) Selection arguments used in the query. + * @return The value of the _data column, which is typically a file path. + * @author paulburke + */ + public static String getDataColumn(Context context, Uri uri, String selection, + String[] selectionArgs) { + + Cursor cursor = null; + final String column = "_data"; + final String[] projection = { + column + }; + + try { + cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, + null); + if (cursor != null && cursor.moveToFirst()) { + if (DEBUG) + DatabaseUtils.dumpCursor(cursor); + + final int column_index = cursor.getColumnIndexOrThrow(column); + return cursor.getString(column_index); + } + } finally { + if (cursor != null) + cursor.close(); + } + return null; + } + + /** + * Get a file path from a Uri. This will get the the path for Storage Access + * Framework Documents, as well as the _data field for the MediaStore and + * other file-based ContentProviders.
+ *
+ * Callers should check whether the path is local before assuming it + * represents a local file. + * + * @param context The context. + * @param uri The Uri to query. + * @author paulburke + * @see #isLocal(String) + * @see #getFile(Context, Uri) + */ + public static String getPath(final Context context, final Uri uri) { + + if (DEBUG) + Log.d(TAG + " File -", + "Authority: " + uri.getAuthority() + + ", Fragment: " + uri.getFragment() + + ", Port: " + uri.getPort() + + ", Query: " + uri.getQuery() + + ", Scheme: " + uri.getScheme() + + ", Host: " + uri.getHost() + + ", Segments: " + uri.getPathSegments().toString() + ); + + final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; + + // DocumentProvider + if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) { + // LocalStorageProvider + if (isLocalStorageDocument(uri)) { + // The path is the id + return DocumentsContract.getDocumentId(uri); + } + // ExternalStorageProvider + else if (isExternalStorageDocument(uri)) { + final String docId = DocumentsContract.getDocumentId(uri); + final String[] split = docId.split(":"); + final String type = split[0]; + + if ("primary".equalsIgnoreCase(type)) { + return Environment.getExternalStorageDirectory() + "/" + split[1]; + } + + // TODO handle non-primary volumes + } + // DownloadsProvider + else if (isDownloadsDocument(uri)) { + + final String id = DocumentsContract.getDocumentId(uri); + final Uri contentUri = ContentUris.withAppendedId( + Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); + + return getDataColumn(context, contentUri, null, null); + } + // MediaProvider + else if (isMediaDocument(uri)) { + final String docId = DocumentsContract.getDocumentId(uri); + final String[] split = docId.split(":"); + final String type = split[0]; + + Uri contentUri = null; + if ("image".equals(type)) { + contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; + } else if ("video".equals(type)) { + contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; + } else if ("audio".equals(type)) { + contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; + } + + final String selection = "_id=?"; + final String[] selectionArgs = new String[]{ + split[1] + }; + + return getDataColumn(context, contentUri, selection, selectionArgs); + } + } + // MediaStore (and general) + else if ("content".equalsIgnoreCase(uri.getScheme())) { + + // Return the remote address + if (isGooglePhotosUri(uri)) + return uri.getLastPathSegment(); + + return getDataColumn(context, uri, null, null); + } + // File + else if ("file".equalsIgnoreCase(uri.getScheme())) { + return uri.getPath(); + } + + return null; + } + + /** + * Convert Uri into File, if possible. + * + * @return file A local file that the Uri was pointing to, or null if the + * Uri is unsupported or pointed to a remote resource. + * @author paulburke + * @see #getPath(Context, Uri) + */ + public static File getFile(Context context, Uri uri) { + if (uri != null) { + String path = getPath(context, uri); + if (path != null && isLocal(path)) { + return new File(path); + } + } + return null; + } + + /** + * Get the file size in a human-readable string. + * + * @param size + * @return + * @author paulburke + */ + public static String getReadableFileSize(int size) { + final int BYTES_IN_KILOBYTES = 1024; + final DecimalFormat dec = new DecimalFormat("###.#"); + final String KILOBYTES = " KB"; + final String MEGABYTES = " MB"; + final String GIGABYTES = " GB"; + float fileSize = 0; + String suffix = KILOBYTES; + + if (size > BYTES_IN_KILOBYTES) { + fileSize = size / BYTES_IN_KILOBYTES; + if (fileSize > BYTES_IN_KILOBYTES) { + fileSize = fileSize / BYTES_IN_KILOBYTES; + if (fileSize > BYTES_IN_KILOBYTES) { + fileSize = fileSize / BYTES_IN_KILOBYTES; + suffix = GIGABYTES; + } else { + suffix = MEGABYTES; + } + } + } + return String.valueOf(dec.format(fileSize) + suffix); + } + + /** + * Attempt to retrieve the thumbnail of given File from the MediaStore. This + * should not be called on the UI thread. + * + * @param context + * @param file + * @return + * @author paulburke + */ + public static Bitmap getThumbnail(Context context, File file) { + return getThumbnail(context, getUri(file), getMimeType(file)); + } + + /** + * Attempt to retrieve the thumbnail of given Uri from the MediaStore. This + * should not be called on the UI thread. + * + * @param context + * @param uri + * @return + * @author paulburke + */ + public static Bitmap getThumbnail(Context context, Uri uri) { + return getThumbnail(context, uri, getMimeType(context, uri)); + } + + /** + * Attempt to retrieve the thumbnail of given Uri from the MediaStore. This + * should not be called on the UI thread. + * + * @param context + * @param uri + * @param mimeType + * @return + * @author paulburke + */ + public static Bitmap getThumbnail(Context context, Uri uri, String mimeType) { + if (DEBUG) + Log.d(TAG, "Attempting to get thumbnail"); + + if (!isMediaUri(uri)) { + Log.e(TAG, "You can only retrieve thumbnails for images and videos."); + return null; + } + + Bitmap bm = null; + if (uri != null) { + final ContentResolver resolver = context.getContentResolver(); + Cursor cursor = null; + try { + cursor = resolver.query(uri, null, null, null, null); + if (cursor.moveToFirst()) { + final int id = cursor.getInt(0); + if (DEBUG) + Log.d(TAG, "Got thumb ID: " + id); + + if (mimeType.contains("video")) { + bm = MediaStore.Video.Thumbnails.getThumbnail( + resolver, + id, + MediaStore.Video.Thumbnails.MINI_KIND, + null); + } else if (mimeType.contains(FileUtils.MIME_TYPE_IMAGE)) { + bm = MediaStore.Images.Thumbnails.getThumbnail( + resolver, + id, + MediaStore.Images.Thumbnails.MINI_KIND, + null); + } + } + } catch (Exception e) { + if (DEBUG) + Log.e(TAG, "getThumbnail", e); + } finally { + if (cursor != null) + cursor.close(); + } + } + return bm; + } + + /** + * File and folder comparator. TODO Expose sorting option method + * + * @author paulburke + */ + public static Comparator sComparator = new Comparator() { + @Override + public int compare(File f1, File f2) { + // Sort alphabetically by lower case, which is much cleaner + return f1.getName().toLowerCase().compareTo( + f2.getName().toLowerCase()); + } + }; + + /** + * File (not directories) filter. + * + * @author paulburke + */ + public static FileFilter sFileFilter = new FileFilter() { + @Override + public boolean accept(File file) { + final String fileName = file.getName(); + // Return files only (not directories) and skip hidden files + return file.isFile() && !fileName.startsWith(HIDDEN_PREFIX); + } + }; + + /** + * Folder (directories) filter. + * + * @author paulburke + */ + public static FileFilter sDirFilter = new FileFilter() { + @Override + public boolean accept(File file) { + final String fileName = file.getName(); + // Return directories only and skip hidden directories + return file.isDirectory() && !fileName.startsWith(HIDDEN_PREFIX); + } + }; + + /** + * Get the Intent for selecting content to be used in an Intent Chooser. + * + * @return The intent for opening a file with Intent.createChooser() + * @author paulburke + */ + public static Intent createGetContentIntent() { +// // Implicitly allow the user to select a particular kind of data +// final Intent intent = new Intent(Intent.ACTION_GET_CONTENT); +// // The MIME data type filter +// intent.setType("*/*"); +// // Only return URIs that can be opened with ContentResolver +// intent.addCategory(Intent.CATEGORY_OPENABLE); +// return intent; + return createGetContentIntent(null); + } + + + /** + * Get the Intent for selecting content to be used in an Intent Chooser. + * + * @param type Set the type for intent. + * @return The intent for opening a file with Intent.createChooser() + * @author AlexZHOU + */ + public static Intent createGetContentIntent(final String type) { + // Implicitly allow the user to select a particular kind of data + final Intent intent = new Intent(Intent.ACTION_GET_CONTENT); + // The MIME data type filter + intent.setType(type != null ? type : "*/*"); + // Only return URIs that can be opened with ContentResolver + intent.addCategory(Intent.CATEGORY_OPENABLE); + return intent; + } +} diff --git a/aFileChooser/res/drawable-hdpi/ic_chooser.png b/aFileChooser/src/main/res/drawable-hdpi/ic_chooser.png similarity index 100% rename from aFileChooser/res/drawable-hdpi/ic_chooser.png rename to aFileChooser/src/main/res/drawable-hdpi/ic_chooser.png diff --git a/aFileChooser/res/drawable-hdpi/ic_file.png b/aFileChooser/src/main/res/drawable-hdpi/ic_file.png similarity index 100% rename from aFileChooser/res/drawable-hdpi/ic_file.png rename to aFileChooser/src/main/res/drawable-hdpi/ic_file.png diff --git a/aFileChooser/res/drawable-hdpi/ic_folder.png b/aFileChooser/src/main/res/drawable-hdpi/ic_folder.png similarity index 100% rename from aFileChooser/res/drawable-hdpi/ic_folder.png rename to aFileChooser/src/main/res/drawable-hdpi/ic_folder.png diff --git a/aFileChooser/res/drawable-hdpi/ic_provider.png b/aFileChooser/src/main/res/drawable-hdpi/ic_provider.png similarity index 100% rename from aFileChooser/res/drawable-hdpi/ic_provider.png rename to aFileChooser/src/main/res/drawable-hdpi/ic_provider.png diff --git a/aFileChooser/res/drawable-mdpi/ic_chooser.png b/aFileChooser/src/main/res/drawable-mdpi/ic_chooser.png similarity index 100% rename from aFileChooser/res/drawable-mdpi/ic_chooser.png rename to aFileChooser/src/main/res/drawable-mdpi/ic_chooser.png diff --git a/aFileChooser/res/drawable-mdpi/ic_file.png b/aFileChooser/src/main/res/drawable-mdpi/ic_file.png similarity index 100% rename from aFileChooser/res/drawable-mdpi/ic_file.png rename to aFileChooser/src/main/res/drawable-mdpi/ic_file.png diff --git a/aFileChooser/res/drawable-mdpi/ic_folder.png b/aFileChooser/src/main/res/drawable-mdpi/ic_folder.png similarity index 100% rename from aFileChooser/res/drawable-mdpi/ic_folder.png rename to aFileChooser/src/main/res/drawable-mdpi/ic_folder.png diff --git a/aFileChooser/res/drawable-mdpi/ic_provider.png b/aFileChooser/src/main/res/drawable-mdpi/ic_provider.png similarity index 100% rename from aFileChooser/res/drawable-mdpi/ic_provider.png rename to aFileChooser/src/main/res/drawable-mdpi/ic_provider.png diff --git a/aFileChooser/res/drawable-xhdpi/ic_chooser.png b/aFileChooser/src/main/res/drawable-xhdpi/ic_chooser.png similarity index 100% rename from aFileChooser/res/drawable-xhdpi/ic_chooser.png rename to aFileChooser/src/main/res/drawable-xhdpi/ic_chooser.png diff --git a/aFileChooser/res/drawable-xhdpi/ic_file.png b/aFileChooser/src/main/res/drawable-xhdpi/ic_file.png similarity index 100% rename from aFileChooser/res/drawable-xhdpi/ic_file.png rename to aFileChooser/src/main/res/drawable-xhdpi/ic_file.png diff --git a/aFileChooser/res/drawable-xhdpi/ic_folder.png b/aFileChooser/src/main/res/drawable-xhdpi/ic_folder.png similarity index 100% rename from aFileChooser/res/drawable-xhdpi/ic_folder.png rename to aFileChooser/src/main/res/drawable-xhdpi/ic_folder.png diff --git a/aFileChooser/res/drawable-xhdpi/ic_provider.png b/aFileChooser/src/main/res/drawable-xhdpi/ic_provider.png similarity index 100% rename from aFileChooser/res/drawable-xhdpi/ic_provider.png rename to aFileChooser/src/main/res/drawable-xhdpi/ic_provider.png diff --git a/aFileChooser/res/drawable-xxhdpi/ic_chooser.png b/aFileChooser/src/main/res/drawable-xxhdpi/ic_chooser.png similarity index 100% rename from aFileChooser/res/drawable-xxhdpi/ic_chooser.png rename to aFileChooser/src/main/res/drawable-xxhdpi/ic_chooser.png diff --git a/aFileChooser/res/drawable-xxhdpi/ic_file.png b/aFileChooser/src/main/res/drawable-xxhdpi/ic_file.png similarity index 100% rename from aFileChooser/res/drawable-xxhdpi/ic_file.png rename to aFileChooser/src/main/res/drawable-xxhdpi/ic_file.png diff --git a/aFileChooser/res/drawable-xxhdpi/ic_folder.png b/aFileChooser/src/main/res/drawable-xxhdpi/ic_folder.png similarity index 100% rename from aFileChooser/res/drawable-xxhdpi/ic_folder.png rename to aFileChooser/src/main/res/drawable-xxhdpi/ic_folder.png diff --git a/aFileChooser/res/drawable-xxhdpi/ic_provider.png b/aFileChooser/src/main/res/drawable-xxhdpi/ic_provider.png similarity index 100% rename from aFileChooser/res/drawable-xxhdpi/ic_provider.png rename to aFileChooser/src/main/res/drawable-xxhdpi/ic_provider.png diff --git a/aFileChooser/res/layout/file.xml b/aFileChooser/src/main/res/layout/file.xml similarity index 100% rename from aFileChooser/res/layout/file.xml rename to aFileChooser/src/main/res/layout/file.xml diff --git a/aFileChooser/res/values-ca/strings.xml b/aFileChooser/src/main/res/values-ca/strings.xml similarity index 100% rename from aFileChooser/res/values-ca/strings.xml rename to aFileChooser/src/main/res/values-ca/strings.xml diff --git a/aFileChooser/res/values-de/strings.xml b/aFileChooser/src/main/res/values-de/strings.xml similarity index 100% rename from aFileChooser/res/values-de/strings.xml rename to aFileChooser/src/main/res/values-de/strings.xml diff --git a/aFileChooser/res/values-es/strings.xml b/aFileChooser/src/main/res/values-es/strings.xml similarity index 100% rename from aFileChooser/res/values-es/strings.xml rename to aFileChooser/src/main/res/values-es/strings.xml diff --git a/aFileChooser/res/values-fr/strings.xml b/aFileChooser/src/main/res/values-fr/strings.xml similarity index 100% rename from aFileChooser/res/values-fr/strings.xml rename to aFileChooser/src/main/res/values-fr/strings.xml diff --git a/aFileChooser/res/values-ga/strings.xml b/aFileChooser/src/main/res/values-ga/strings.xml similarity index 100% rename from aFileChooser/res/values-ga/strings.xml rename to aFileChooser/src/main/res/values-ga/strings.xml diff --git a/aFileChooser/res/values-it/strings.xml b/aFileChooser/src/main/res/values-it/strings.xml similarity index 100% rename from aFileChooser/res/values-it/strings.xml rename to aFileChooser/src/main/res/values-it/strings.xml diff --git a/aFileChooser/res/values-ko/strings.xml b/aFileChooser/src/main/res/values-ko/strings.xml similarity index 100% rename from aFileChooser/res/values-ko/strings.xml rename to aFileChooser/src/main/res/values-ko/strings.xml diff --git a/aFileChooser/res/values-pl/strings.xml b/aFileChooser/src/main/res/values-pl/strings.xml similarity index 100% rename from aFileChooser/res/values-pl/strings.xml rename to aFileChooser/src/main/res/values-pl/strings.xml diff --git a/aFileChooser/res/values-pt-rBR/strings.xml b/aFileChooser/src/main/res/values-pt-rBR/strings.xml similarity index 100% rename from aFileChooser/res/values-pt-rBR/strings.xml rename to aFileChooser/src/main/res/values-pt-rBR/strings.xml diff --git a/aFileChooser/res/values-ru/strings.xml b/aFileChooser/src/main/res/values-ru/strings.xml similarity index 100% rename from aFileChooser/res/values-ru/strings.xml rename to aFileChooser/src/main/res/values-ru/strings.xml diff --git a/aFileChooser/res/values-v11/strings.xml b/aFileChooser/src/main/res/values-v11/strings.xml similarity index 100% rename from aFileChooser/res/values-v11/strings.xml rename to aFileChooser/src/main/res/values-v11/strings.xml diff --git a/aFileChooser/res/values-v19/bool.xml b/aFileChooser/src/main/res/values-v19/bool.xml similarity index 100% rename from aFileChooser/res/values-v19/bool.xml rename to aFileChooser/src/main/res/values-v19/bool.xml diff --git a/aFileChooser/res/values/bool.xml b/aFileChooser/src/main/res/values/bool.xml similarity index 100% rename from aFileChooser/res/values/bool.xml rename to aFileChooser/src/main/res/values/bool.xml diff --git a/aFileChooser/res/values/dimens.xml b/aFileChooser/src/main/res/values/dimens.xml similarity index 100% rename from aFileChooser/res/values/dimens.xml rename to aFileChooser/src/main/res/values/dimens.xml diff --git a/aFileChooser/res/values/strings.xml b/aFileChooser/src/main/res/values/strings.xml similarity index 100% rename from aFileChooser/res/values/strings.xml rename to aFileChooser/src/main/res/values/strings.xml diff --git a/aFileChooser/res/values/styles.xml b/aFileChooser/src/main/res/values/styles.xml similarity index 100% rename from aFileChooser/res/values/styles.xml rename to aFileChooser/src/main/res/values/styles.xml diff --git a/aFileChooser/res/xml/mimetypes.xml b/aFileChooser/src/main/res/xml/mimetypes.xml similarity index 97% rename from aFileChooser/res/xml/mimetypes.xml rename to aFileChooser/src/main/res/xml/mimetypes.xml index 972786d..062435f 100644 --- a/aFileChooser/res/xml/mimetypes.xml +++ b/aFileChooser/src/main/res/xml/mimetypes.xml @@ -1,89 +1,89 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/aFileChooserExample/.gitignore b/aFileChooserExample/.gitignore new file mode 100644 index 0000000..d524837 --- /dev/null +++ b/aFileChooserExample/.gitignore @@ -0,0 +1,2 @@ +build +aFileChooserExample.iml diff --git a/aFileChooserExample/build.gradle b/aFileChooserExample/build.gradle new file mode 100644 index 0000000..9b7f2fe --- /dev/null +++ b/aFileChooserExample/build.gradle @@ -0,0 +1,23 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 19 + buildToolsVersion "24.0.1" + + defaultConfig { + applicationId "com.ipaulpro.afilechooserexample" + minSdkVersion 7 + targetSdkVersion 19 + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' + } + } +} + +dependencies { + compile project(':aFileChooser') +} diff --git a/aFileChooserExample/proguard.cfg b/aFileChooserExample/proguard.cfg deleted file mode 100644 index b1cdf17..0000000 --- a/aFileChooserExample/proguard.cfg +++ /dev/null @@ -1,40 +0,0 @@ --optimizationpasses 5 --dontusemixedcaseclassnames --dontskipnonpubliclibraryclasses --dontpreverify --verbose --optimizations !code/simplification/arithmetic,!field/*,!class/merging/* - --keep public class * extends android.app.Activity --keep public class * extends android.app.Application --keep public class * extends android.app.Service --keep public class * extends android.content.BroadcastReceiver --keep public class * extends android.content.ContentProvider --keep public class * extends android.app.backup.BackupAgentHelper --keep public class * extends android.preference.Preference --keep public class com.android.vending.licensing.ILicensingService - --keepclasseswithmembernames class * { - native ; -} - --keepclasseswithmembers class * { - public (android.content.Context, android.util.AttributeSet); -} - --keepclasseswithmembers class * { - public (android.content.Context, android.util.AttributeSet, int); -} - --keepclassmembers class * extends android.app.Activity { - public void *(android.view.View); -} - --keepclassmembers enum * { - public static **[] values(); - public static ** valueOf(java.lang.String); -} - --keep class * implements android.os.Parcelable { - public static final android.os.Parcelable$Creator *; -} diff --git a/aFileChooserExample/AndroidManifest.xml b/aFileChooserExample/src/main/AndroidManifest.xml similarity index 100% rename from aFileChooserExample/AndroidManifest.xml rename to aFileChooserExample/src/main/AndroidManifest.xml diff --git a/aFileChooserExample/src/com/ipaulpro/afilechooserexample/FileChooserExampleActivity.java b/aFileChooserExample/src/main/java/com/ipaulpro/afilechooserexample/FileChooserExampleActivity.java similarity index 100% rename from aFileChooserExample/src/com/ipaulpro/afilechooserexample/FileChooserExampleActivity.java rename to aFileChooserExample/src/main/java/com/ipaulpro/afilechooserexample/FileChooserExampleActivity.java diff --git a/aFileChooserExample/res/drawable/ic_launcher.png b/aFileChooserExample/src/main/res/drawable/ic_launcher.png similarity index 100% rename from aFileChooserExample/res/drawable/ic_launcher.png rename to aFileChooserExample/src/main/res/drawable/ic_launcher.png diff --git a/aFileChooserExample/res/values-v11/themes.xml b/aFileChooserExample/src/main/res/values-v11/themes.xml similarity index 100% rename from aFileChooserExample/res/values-v11/themes.xml rename to aFileChooserExample/src/main/res/values-v11/themes.xml diff --git a/aFileChooserExample/res/values/strings.xml b/aFileChooserExample/src/main/res/values/strings.xml similarity index 100% rename from aFileChooserExample/res/values/strings.xml rename to aFileChooserExample/src/main/res/values/strings.xml diff --git a/aFileChooserExample/res/values/themes.xml b/aFileChooserExample/src/main/res/values/themes.xml similarity index 100% rename from aFileChooserExample/res/values/themes.xml rename to aFileChooserExample/src/main/res/values/themes.xml diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..305dc05 --- /dev/null +++ b/build.gradle @@ -0,0 +1,15 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +buildscript { + repositories { + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:2.2.0' + } +} + +allprojects { + repositories { + jcenter() + } +} diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..9d82f78 --- /dev/null +++ b/gradlew @@ -0,0 +1,160 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..8a0b282 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..28a6d28 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,2 @@ +include ':aFileChooser' +include ':aFileChooserExample'