diff --git a/.idea/compiler.xml b/.idea/compiler.xml
deleted file mode 100644
index e36ad0b..0000000
--- a/.idea/compiler.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml
deleted file mode 100644
index e7bedf3..0000000
--- a/.idea/copyright/profiles_settings.xml
+++ /dev/null
@@ -1,3 +0,0 @@
-
-
-
\ No newline at end of file
diff --git a/.idea/dictionaries/lenovo.xml b/.idea/dictionaries/lenovo.xml
deleted file mode 100644
index 58ff6e1..0000000
--- a/.idea/dictionaries/lenovo.xml
+++ /dev/null
@@ -1,3 +0,0 @@
-
-
-
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
deleted file mode 100644
index 97626ba..0000000
--- a/.idea/encodings.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 05be158..13c4629 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,8 +1,5 @@
-
-
-
@@ -27,36 +24,26 @@
-
-
-
-
-
-
-
-
-
-
- Abstraction issues
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+ 1.8
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
index 94a25f7..35eb1dd 100644
--- a/.idea/vcs.xml
+++ b/.idea/vcs.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/README.md b/README.md
index b1a2300..bc3f224 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
# MediaPickerProject
-
+[![](https://jitpack.io/v/Achenglove/MediaPickerPoject.svg)](https://jitpack.io/#Achenglove/MediaPickerPoject)
仿微信视频图片选择器,代码撸的非常简洁清爽好改,支持cordova调用。
同类的库很多很多,但都过于强大而笨重,代码不容易在特别短的时间里面改动,所以我创建了这个简单而轻量的库。
@@ -21,6 +21,8 @@ repositories {
dependencies {
compile 'com.dmcBig:mediapicker:+'
+
+ 或者implementation 'com.github.Achenglove:MediaPickerPoject:v1.0.1'
}
```
diff --git a/app/build.gradle b/app/build.gradle
index 2c3f38e..b3eee33 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,8 +1,8 @@
apply plugin: 'com.android.application'
android {
- compileSdkVersion 25
- buildToolsVersion '25.0.1'
+ compileSdkVersion 26
+ buildToolsVersion '26.0.2'
defaultConfig {
applicationId "dmc.mediapickerpoject"
minSdkVersion 16
@@ -24,7 +24,7 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
- compile 'com.android.support:appcompat-v7:25.3.1'
+ compile 'com.android.support:appcompat-v7:27.0.2'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile project(':mediapicker')
diff --git a/app/src/main/java/dmc/mediapickerpoject/MainActivity.java b/app/src/main/java/dmc/mediapickerpoject/MainActivity.java
index 2865687..3ae95c9 100644
--- a/app/src/main/java/dmc/mediapickerpoject/MainActivity.java
+++ b/app/src/main/java/dmc/mediapickerpoject/MainActivity.java
@@ -43,10 +43,10 @@ public void onClick(View v) {
ArrayList select;
void go(){
Intent intent =new Intent(MainActivity.this, PickerActivity.class);
- intent.putExtra(PickerConfig.SELECT_MODE,PickerConfig.PICKER_IMAGE_VIDEO);//default image and video (Optional)
- long maxSize=188743680L;//long long long
- intent.putExtra(PickerConfig.MAX_SELECT_SIZE,maxSize); //default 180MB (Optional)
- intent.putExtra(PickerConfig.MAX_SELECT_COUNT,15); //default 40 (Optional)
+ intent.putExtra(PickerConfig.SELECT_MODE,PickerConfig.PICKER_VIDEO);//default image and video (Optional)
+ PickerConfig.setMaxSize(10485760L);//设置最大选着文件
+ intent.putExtra(PickerConfig.MAX_SELECT_SIZE,PickerConfig.getMaxSize()); //default 180MB (Optional)
+ intent.putExtra(PickerConfig.MAX_SELECT_COUNT,1); //default 40 (Optional)
intent.putExtra(PickerConfig.DEFAULT_SELECTED_LIST,select); // (Optional)
MainActivity.this.startActivityForResult(intent,200);
}
diff --git a/build.gradle b/build.gradle
index 1d974ef..cf7362d 100644
--- a/build.gradle
+++ b/build.gradle
@@ -3,9 +3,11 @@
buildscript {
repositories {
jcenter()
+ google()
+ mavenCentral()
}
dependencies {
- classpath 'com.android.tools.build:gradle:2.3.1'
+ classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
// NOTE: Do not place your application dependencies here; they belong
@@ -17,6 +19,13 @@ buildscript {
allprojects {
repositories {
jcenter()
+ maven { url "https://jitpack.io" }
+ mavenCentral()
+ maven { url "https://dl.bintray.com/thelasterstar/maven/" }
+ maven {
+ url "https://maven.google.com"
+ }
+ google()
}
}
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index d8b8094..f44ce7a 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
diff --git a/mediapicker/build.gradle b/mediapicker/build.gradle
index c33b7ad..acebdcd 100644
--- a/mediapicker/build.gradle
+++ b/mediapicker/build.gradle
@@ -10,8 +10,8 @@ properties.load(project.rootProject.file('local.properties').newDataInputStream(
version = "3.0" //发布版本号
group = "com.dmcBig" //最终引用形式,如compile 'com.**;
android {
- compileSdkVersion 25
- buildToolsVersion "25.0.2"
+ compileSdkVersion 26
+ buildToolsVersion '26.0.2'
defaultConfig {
minSdkVersion 16
@@ -31,15 +31,17 @@ android {
}
dependencies {
- compile fileTree(include: ['*.jar'], dir: 'libs')
- compile 'com.android.support:appcompat-v7:25.3.1'
+ implementation fileTree(include: ['*.jar'], dir: 'libs')
+ //noinspection GradleCompatible
+ implementation 'com.android.support:appcompat-v7:27.0.2'
testCompile 'junit:junit:4.12'
- compile 'com.android.support:recyclerview-v7:25.3.1'
- compile 'com.github.bumptech.glide:glide:4.0.0'
- compile 'com.android.support:support-v4:25.3.1'
- annotationProcessor 'com.github.bumptech.glide:compiler:4.0.0'
- compile 'pub.devrel:easypermissions:1.0.0'
- compile 'com.github.chrisbanes.photoview:library:1.2.4'
+ implementation 'com.android.support:recyclerview-v7:26.1.0'
+ implementation 'com.github.bumptech.glide:glide:4.5.0'
+ implementation 'com.android.support:support-v4:26.1.0'
+ annotationProcessor 'com.github.bumptech.glide:compiler:4.5.0'
+ implementation 'pub.devrel:easypermissions:1.0.0'
+ implementation 'com.github.chrisbanes.photoview:library:1.2.4'
+
}
bintray {
diff --git a/mediapicker/src/main/java/com/dmcbig/mediapicker/PickerConfig.java b/mediapicker/src/main/java/com/dmcbig/mediapicker/PickerConfig.java
index 7f5434c..4692c93 100644
--- a/mediapicker/src/main/java/com/dmcbig/mediapicker/PickerConfig.java
+++ b/mediapicker/src/main/java/com/dmcbig/mediapicker/PickerConfig.java
@@ -19,7 +19,7 @@ public class PickerConfig {
*/
public static final String MAX_SELECT_SIZE = "max_select_size";
- public static final long DEFAULT_SELECTED_MAX_SIZE = 188743680;
+ public static long DEFAULT_SELECTED_MAX_SIZE = 188743680;
/**
* 图片选择模式,默认选视频和图片
@@ -45,4 +45,16 @@ public class PickerConfig {
public static final int PICKER_IMAGE_VIDEO = 101;
public static int GridSpanCount = 3;
public static int GridSpace = 4;
+
+ public static void setMaxSize(long MaxSize){
+// "B";
+// 1024 + "KB";
+// 1048576 + "MB";
+// 1073741824 + "GB";
+
+ DEFAULT_SELECTED_MAX_SIZE=MaxSize;
+ }
+ public static long getMaxSize(){
+ return DEFAULT_SELECTED_MAX_SIZE;
+ }
}
diff --git a/mediapicker/src/main/java/com/dmcbig/mediapicker/adapter/MediaGridAdapter.java b/mediapicker/src/main/java/com/dmcbig/mediapicker/adapter/MediaGridAdapter.java
index 172e63c..51e2d79 100644
--- a/mediapicker/src/main/java/com/dmcbig/mediapicker/adapter/MediaGridAdapter.java
+++ b/mediapicker/src/main/java/com/dmcbig/mediapicker/adapter/MediaGridAdapter.java
@@ -49,7 +49,7 @@ public MediaGridAdapter(ArrayList list, Context context, ArrayList
public class MyViewHolder extends RecyclerView.ViewHolder {
public ImageView media_image, check_image;
public View mask_view;
- public TextView textView_size;
+ public TextView textView_size,textView_duration;
public RelativeLayout gif_info;
public RelativeLayout video_info;
@@ -61,6 +61,7 @@ public MyViewHolder(View view) {
video_info = (RelativeLayout) view.findViewById(R.id.video_info);
gif_info = (RelativeLayout) view.findViewById(R.id.gif_info);
textView_size = (TextView) view.findViewById(R.id.textView_size);
+ textView_duration = (TextView) view.findViewById(R.id.textView_duration);
itemView.setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getItemWidth())); //让图片是个正方形
}
}
@@ -89,6 +90,7 @@ public void onBindViewHolder(final MyViewHolder holder, int position) {
holder.gif_info.setVisibility(View.INVISIBLE);
holder.video_info.setVisibility(View.VISIBLE);
holder.textView_size.setText(fileUtils.getSizeByUnit(media.size));
+ holder.textView_duration.setText(fileUtils.timeParseMinute(media.duration));
} else {
holder.video_info.setVisibility(View.INVISIBLE);
holder.gif_info.setVisibility(".gif".equalsIgnoreCase(media.extension) ? View.VISIBLE : View.INVISIBLE);
diff --git a/mediapicker/src/main/java/com/dmcbig/mediapicker/data/MediaLoader.java b/mediapicker/src/main/java/com/dmcbig/mediapicker/data/MediaLoader.java
index b2dfc63..a417b35 100644
--- a/mediapicker/src/main/java/com/dmcbig/mediapicker/data/MediaLoader.java
+++ b/mediapicker/src/main/java/com/dmcbig/mediapicker/data/MediaLoader.java
@@ -21,6 +21,7 @@
*/
public class MediaLoader extends LoaderM implements LoaderManager.LoaderCallbacks {
+ private static final String DURATION = "duration";
String[] MEDIA_PROJECTION = {
MediaStore.Files.FileColumns.DATA,
MediaStore.Files.FileColumns.DISPLAY_NAME,
@@ -28,7 +29,8 @@ public class MediaLoader extends LoaderM implements LoaderManager.LoaderCallback
MediaStore.Files.FileColumns.MEDIA_TYPE,
MediaStore.Files.FileColumns.SIZE,
MediaStore.Files.FileColumns._ID,
- MediaStore.Files.FileColumns.PARENT};
+ MediaStore.Files.FileColumns.PARENT,
+ DURATION};
Context mContext;
DataCallback mLoader;
@@ -72,12 +74,13 @@ public void onLoadFinished(Loader loader, Object o) {
long dateTime = cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.DATE_ADDED));
int mediaType = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.MEDIA_TYPE));
long size = cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.SIZE));
+ long duration = cursor.getLong(cursor.getColumnIndexOrThrow(DURATION));
int id = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns._ID));
if (size < 1) continue;
if(path == null || path.equals("")) continue;
String dirName = getParent(path);
- Media media = new Media(path, name, dateTime, mediaType, size, id, dirName);
+ Media media = new Media(path, name, dateTime, mediaType, size,duration, id, dirName);
allFolder.addMedias(media);
if (mediaType == 3) {
allVideoDir.addMedias(media);
diff --git a/mediapicker/src/main/java/com/dmcbig/mediapicker/data/VideoLoader.java b/mediapicker/src/main/java/com/dmcbig/mediapicker/data/VideoLoader.java
index 40d2a1b..5ad6986 100644
--- a/mediapicker/src/main/java/com/dmcbig/mediapicker/data/VideoLoader.java
+++ b/mediapicker/src/main/java/com/dmcbig/mediapicker/data/VideoLoader.java
@@ -22,6 +22,7 @@
*/
public class VideoLoader extends LoaderM implements LoaderManager.LoaderCallbacks {
+ private static final String DURATION = "duration";
String[] MEDIA_PROJECTION = {
MediaStore.Files.FileColumns.DATA,
MediaStore.Files.FileColumns.DISPLAY_NAME,
@@ -29,7 +30,8 @@ public class VideoLoader extends LoaderM implements LoaderManager.LoaderCallback
MediaStore.Files.FileColumns.MEDIA_TYPE,
MediaStore.Files.FileColumns.SIZE,
MediaStore.Files.FileColumns._ID,
- MediaStore.Files.FileColumns.PARENT};
+ MediaStore.Files.FileColumns.PARENT,
+ DURATION};
Context mContext;
DataCallback mLoader;
@@ -69,12 +71,13 @@ public void onLoadFinished(Loader loader, Object o) {
long dateTime = cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.DATE_ADDED));
int mediaType = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.MEDIA_TYPE));
long size = cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.SIZE));
+ long duration = cursor.getLong(cursor.getColumnIndexOrThrow(DURATION));
int id = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns._ID));
if (size < 1) continue;
if (path == null || path.equals("")) continue;
String dirName = getParent(path);
- Media media = new Media(path, name, dateTime, mediaType, size, id, dirName);
+ Media media = new Media(path, name, dateTime, mediaType, size,duration, id, dirName);
allFolder.addMedias(media);
int index = hasDir(folders, dirName);
diff --git a/mediapicker/src/main/java/com/dmcbig/mediapicker/entity/Media.java b/mediapicker/src/main/java/com/dmcbig/mediapicker/entity/Media.java
index 00d4e2b..112b364 100644
--- a/mediapicker/src/main/java/com/dmcbig/mediapicker/entity/Media.java
+++ b/mediapicker/src/main/java/com/dmcbig/mediapicker/entity/Media.java
@@ -15,6 +15,7 @@ public class Media implements Parcelable {
public long time;
public int mediaType;
public long size;
+ public long duration;
public int id;
public String parentDir;
@@ -32,7 +33,21 @@ public Media(String path, String name, long time, int mediaType, long size, int
this.id = id;
this.parentDir = parentDir;
}
-
+ public Media(String path, String name, long time, int mediaType, long size,long duration, int id, String parentDir) {
+ this.path = path;
+ this.name = name;
+ if (!TextUtils.isEmpty(name) && name.indexOf(".") != -1) {
+ this.extension = name.substring(name.lastIndexOf("."), name.length());
+ } else {
+ this.extension = "null";
+ }
+ this.time = time;
+ this.mediaType = mediaType;
+ this.size = size;
+ this.duration = duration;
+ this.id = id;
+ this.parentDir = parentDir;
+ }
@Override
public int describeContents() {
@@ -47,6 +62,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(this.time);
dest.writeInt(this.mediaType);
dest.writeLong(this.size);
+ dest.writeLong(this.duration);
dest.writeInt(this.id);
dest.writeString(this.parentDir);
}
@@ -58,6 +74,7 @@ protected Media(Parcel in) {
this.time = in.readLong();
this.mediaType = in.readInt();
this.size = in.readLong();
+ this.duration = in.readLong();
this.id = in.readInt();
this.parentDir = in.readString();
}
diff --git a/mediapicker/src/main/java/com/dmcbig/mediapicker/utils/FileUtils.java b/mediapicker/src/main/java/com/dmcbig/mediapicker/utils/FileUtils.java
index 032921c..9f57747 100644
--- a/mediapicker/src/main/java/com/dmcbig/mediapicker/utils/FileUtils.java
+++ b/mediapicker/src/main/java/com/dmcbig/mediapicker/utils/FileUtils.java
@@ -13,6 +13,8 @@
import java.io.File;
import java.io.IOException;
import java.text.DecimalFormat;
+import java.text.SimpleDateFormat;
+import java.util.Formatter;
import java.util.Locale;
import static android.os.Environment.MEDIA_MOUNTED;
@@ -59,7 +61,7 @@ public static File getCacheDirectory(Context context) {
return getCacheDirectory(context, true);
}
- public static String getRealPathFromURI(Context context,Uri contentURI) {
+ public static String getRealPathFromURI(Context context, Uri contentURI) {
String result;
Cursor cursor = context.getContentResolver().query(contentURI, null, null, null, null);
if (cursor == null) { // Source is Dropbox or other similar local file path
@@ -170,6 +172,48 @@ public static String fileSize(long size) {
}
+ private static SimpleDateFormat msFormat = new SimpleDateFormat("mm:ss");
+ /**
+ * MS turn every minute
+ *
+ * @param duration Millisecond
+ * @return Every minute
+ */
+ public static String c(long duration) {
+ String time = "";
+ if (duration > 1000) {
+ time = timeParseMinute(duration);
+ } else {
+ long minute = duration / 60000;
+ long seconds = duration % 60000;
+ long second = Math.round((float) seconds / 1000);
+ if (minute < 10) {
+ time += "0";
+ }
+ time += minute + ":";
+ if (second < 10) {
+ time += "0";
+ }
+ time += second;
+ }
+ return time;
+ }
+
+ /**
+ * MS turn every minute
+ *
+ * @param duration Millisecond
+ * @return Every minute
+ */
+ public static String timeParseMinute(long duration) {
+ try {
+ return msFormat.format(duration);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return "0:00";
+ }
+ }
+
/**
* To find out the extension of required object in given uri
* Solution by http://stackoverflow.com/a/36514823/1171484
diff --git a/mediapicker/src/main/res/drawable-xhdpi/video_icon.png b/mediapicker/src/main/res/drawable-xhdpi/video_icon.png
new file mode 100644
index 0000000..86e6d48
Binary files /dev/null and b/mediapicker/src/main/res/drawable-xhdpi/video_icon.png differ
diff --git a/mediapicker/src/main/res/layout/media_view_item.xml b/mediapicker/src/main/res/layout/media_view_item.xml
index 442a1b7..caae010 100644
--- a/mediapicker/src/main/res/layout/media_view_item.xml
+++ b/mediapicker/src/main/res/layout/media_view_item.xml
@@ -29,6 +29,7 @@
android:layout_gravity="bottom"
android:layout_height="wrap_content">
+
+