Skip to content

Commit 384ffd5

Browse files
author
Ahmed Yusuf
committed
version 1.0.6
1 parent d6b7d66 commit 384ffd5

File tree

9 files changed

+167
-40
lines changed

9 files changed

+167
-40
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,4 @@ _book
126126
*.epub
127127
*.mobi
128128
*.pdf
129+
/bintrayUpload.bat

.travis.yml

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
language: android
2-
jdk: oraclejdk7
3-
# Turn off caching to avoid any caching problems
4-
cache: false
5-
# Use the Travis Container-Based Infrastructure
62
sudo: false
7-
env:
8-
global:
9-
- ANDROID_API_LEVEL=23
10-
- ANDROID_BUILD_TOOLS_VERSION=23.0.2
11-
- ANDROID_ABI=armeabi-v7a
12-
- ADB_INSTALL_TIMEOUT=8 # minutes (2 minutes by default)
13-
3+
jdk: openjdk7
144
android:
155
components:
16-
- platform-tools
17-
- tools
18-
- build-tools-$ANDROID_BUILD_TOOLS_VERSION
19-
- android-$ANDROID_API_LEVEL
6+
- build-tools-23.0.2
7+
- extra-android-support
8+
- extra-android-m2repository
9+
- android-23
10+
licenses:
11+
- '.+'

README.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Global Utilities for Android
1212
#### Step 1: Add to project build.gradle
1313

1414
dependencies {
15-
compile 'me.a7madev.androidglobalutils:library:1.0.4'
15+
compile 'me.a7madev.androidglobalutils:library:1.0.5'
1616
}
1717

1818
#### Step 2: Import package in your java class
@@ -60,15 +60,30 @@ GlobalUtils Class
6060
: initProgressDialog
6161
> Initialize Progress Dialog
6262
63+
: dismissProgressDialog
64+
> Dismiss Progress Dialog
65+
6366
GlobalFileUtils Class
6467
----------
6568

66-
: openFileIntent
67-
> Open File using intent
68-
6969
: getMimeType
7070
> Get File Mime Type
7171
72+
: openFileIntent
73+
> Open File using intent (starts activity)
74+
75+
: getFileIntent
76+
> Return Intent to open any files
77+
78+
: getFilesListFromDirectory
79+
> Return list of files in a directory
80+
81+
82+
GlobalMediaUtils Class
83+
----------
84+
85+
: getMediaThumbnail
86+
> Get image or video thumbnail
7287
7388

7489
# License

library/build.gradle

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ android {
88
defaultConfig {
99
minSdkVersion 16
1010
targetSdkVersion 23
11-
versionCode 104
12-
versionName "1.0.4"
11+
versionCode 106
12+
versionName "1.0.6"
1313
}
1414
buildTypes {
1515
release {
@@ -23,6 +23,8 @@ dependencies {
2323
compile fileTree(dir: 'libs', include: ['*.jar'])
2424
testCompile 'junit:junit:4.12'
2525
compile 'com.android.support:appcompat-v7:23.1.1'
26+
compile 'com.android.support:design:23.1.1'
27+
compile 'com.android.support:support-v4:23.1.1'
2628
}
2729

2830
ext {
@@ -39,7 +41,7 @@ ext {
3941
artifact = 'library'
4042

4143
libraryDescription = 'Android Global Utilities Library'
42-
libraryVersion = '1.0.4'
44+
libraryVersion = '1.0.6'
4345

4446
developerId = 'a7madev'
4547
developerName = 'A7maDev'

library/src/main/java/me/a7madev/androidglobalutils/GlobalFileUtils.java

Lines changed: 67 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,12 @@
77
import android.webkit.MimeTypeMap;
88

99
import java.io.File;
10+
import java.util.ArrayList;
1011

1112
public class GlobalFileUtils {
1213

1314
public static final String TAG = GlobalFileUtils.class.getSimpleName();
1415

15-
/**
16-
* Open File using intent
17-
* @param context The context to use. Use application or activity context
18-
* @param file file object to be opened
19-
*/
20-
public static void openFileIntent(Context context, File file) {
21-
if(context != null && file.exists()) {
22-
try {
23-
Intent intent = new Intent(Intent.ACTION_VIEW);
24-
intent.setDataAndType(Uri.fromFile(file), getMimeType(context, Uri.fromFile(file)));
25-
context.startActivity(intent);
26-
} catch (Exception e) {
27-
GlobalUtils.logThis(TAG, "openFileIntent Exception", e);
28-
}
29-
}
30-
}
31-
3216
/**
3317
* Get File Mime Type
3418
* @param context The context to use. Use application or activity context
@@ -52,4 +36,70 @@ public static String getMimeType(Context context, Uri uri) {
5236
return mimeType;
5337
}
5438

39+
/**
40+
* Open File using intent
41+
* @param context The context to use. Use application or activity context
42+
* @param openFile file object to be opened
43+
*/
44+
45+
public static void openFileIntent(Context context, File openFile) {
46+
if(context != null && openFile.exists()) {
47+
try {
48+
Intent intent = getFileIntent(context, openFile);
49+
context.startActivity(intent);
50+
} catch (Exception e) {
51+
GlobalUtils.logThis(TAG, "openFileIntent Exception", e);
52+
}
53+
}
54+
}
55+
56+
/**
57+
* Return Intent to open any files
58+
* @param context The context to use. Use application or activity context
59+
* @param openFile file object to be opened
60+
*/
61+
public static Intent getFileIntent(Context context, File openFile) {
62+
Intent fileIntent = null;
63+
if(context != null && openFile.exists()) {
64+
try {
65+
fileIntent = new Intent(Intent.ACTION_VIEW);
66+
fileIntent.setDataAndType(Uri.fromFile(openFile), getMimeType(context, Uri.fromFile(openFile)));
67+
} catch (Exception e) {
68+
GlobalUtils.logThis(TAG, "getFileIntent Exception", e);
69+
}
70+
}
71+
return fileIntent;
72+
}
73+
74+
75+
/**
76+
* Return list of files in a directory
77+
* @param dir directory as File
78+
* @param acceptExtensions include all extensions to be listed: .png, .jpg, .mp4
79+
* @param includeDirectory include directory in the list?
80+
* @return Array list of files
81+
*/
82+
public static ArrayList<File> getFilesListFromDirectory(File dir, String[] acceptExtensions, boolean includeDirectory) {
83+
ArrayList<File> fileList = new ArrayList<>();
84+
File listFile[] = dir.listFiles();
85+
if (listFile != null && listFile.length > 0) {
86+
for (File aListFile : listFile) {
87+
if (aListFile.isDirectory()) {
88+
if(includeDirectory){
89+
fileList.add(aListFile);
90+
}
91+
getFilesListFromDirectory(aListFile, acceptExtensions, includeDirectory);
92+
} else {
93+
if(acceptExtensions != null && acceptExtensions.length > 0){
94+
for (String ext : acceptExtensions){
95+
if (aListFile.getName().endsWith(ext)) {
96+
fileList.add(aListFile);
97+
}
98+
}
99+
}
100+
}
101+
}
102+
}
103+
return fileList;
104+
}
55105
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package me.a7madev.androidglobalutils;
2+
3+
import android.graphics.Bitmap;
4+
import android.graphics.BitmapFactory;
5+
import android.media.ThumbnailUtils;
6+
import android.net.Uri;
7+
import android.provider.MediaStore;
8+
9+
import java.io.File;
10+
11+
public class GlobalMediaUtils {
12+
13+
public static final String TAG = GlobalMediaUtils.class.getSimpleName();
14+
15+
/**
16+
* Get image or video thumbnail
17+
* @param file Image
18+
* @return Bitmap bitmap object
19+
*/
20+
21+
public static Bitmap getMediaThumbnail(File file) {
22+
23+
Bitmap thumbBitmap;
24+
25+
thumbBitmap = ThumbnailUtils.createVideoThumbnail(file.getPath(), MediaStore.Images.Thumbnails.MICRO_KIND);
26+
27+
if(thumbBitmap == null){
28+
thumbBitmap = ThumbnailUtils.createVideoThumbnail(file.getPath(), MediaStore.Video.Thumbnails.MICRO_KIND);
29+
}
30+
31+
if(thumbBitmap == null){
32+
File image = new File(Uri.fromFile(file).getPath());
33+
34+
BitmapFactory.Options bounds = new BitmapFactory.Options();
35+
bounds.inJustDecodeBounds = true;
36+
BitmapFactory.decodeFile(image.getPath(), bounds);
37+
if ((bounds.outWidth == -1) || (bounds.outHeight == -1))
38+
return null;
39+
40+
int originalSize = (bounds.outHeight > bounds.outWidth) ? bounds.outHeight
41+
: bounds.outWidth;
42+
43+
BitmapFactory.Options opts = new BitmapFactory.Options();
44+
opts.inSampleSize = originalSize / 256;
45+
return BitmapFactory.decodeFile(image.getPath(), opts);
46+
}
47+
return thumbBitmap;
48+
}
49+
}

library/src/main/java/me/a7madev/androidglobalutils/GlobalUtils.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import java.util.Arrays;
2121
import java.util.List;
2222

23-
public class GlobalUtils {
23+
public class GlobalUtils implements GlobalUtilsInterface {
2424

2525
public static final String TAG = GlobalUtils.class.getSimpleName();
2626

@@ -246,4 +246,15 @@ public static ProgressDialog initProgressDialog(Context context, String message,
246246
}
247247
return loadingDialog;
248248
}
249+
250+
/**
251+
* Dismiss Progress Dialog
252+
* @param progressDialog Progress Dialog object
253+
*/
254+
public static void dismissProgressDialog(ProgressDialog progressDialog) {
255+
// dismiss the loading dialog
256+
if(progressDialog != null && progressDialog.isShowing()) {
257+
progressDialog.dismiss();
258+
}
259+
}
249260
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package me.a7madev.androidglobalutils;
2+
3+
public interface GlobalUtilsInterface {
4+
5+
}

library/src/test/java/me/a7madev/androidglobalutils/ExampleUnitTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import org.junit.Test;
44

5+
import me.a7madev.androidglobalutils.GlobalUtils;
6+
57
import static org.junit.Assert.*;
68

79
/**

0 commit comments

Comments
 (0)