Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
compileSdkVersion 25
buildToolsVersion '25.0.3'

defaultConfig {
applicationId "me.nereo.multiimageselector"
minSdkVersion 12
targetSdkVersion 23
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
Expand All @@ -21,6 +21,6 @@ android {

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:appcompat-v7:25.3.1'
compile project(':multi-image-selector')
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.android.tools.build:gradle:2.3.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed May 18 11:49:16 CST 2016
#Tue Jun 27 18:33:07 PHT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
8 changes: 4 additions & 4 deletions multi-image-selector/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
compileSdkVersion 25
buildToolsVersion '25.0.3'

defaultConfig {
minSdkVersion 12
targetSdkVersion 23
targetSdkVersion 25
versionCode 1
versionName "1.1"
}
Expand All @@ -22,6 +22,6 @@ android {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.squareup.picasso:picasso:2.4.0'
}
10 changes: 10 additions & 0 deletions multi-image-selector/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@
android:configChanges="orientation|screenSize"
android:name="me.nereo.multi_image_selector.MultiImageSelectorActivity" />

<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/mis_provider_paths"/>
</provider>

</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.content.FileProvider;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
Expand All @@ -23,22 +24,32 @@
* Updated by nereo on 2016/5/18.
*/
public class MultiImageSelectorActivity extends AppCompatActivity
implements MultiImageSelectorFragment.Callback{
implements MultiImageSelectorFragment.Callback {

// Single choice
public static final int MODE_SINGLE = 0;
// Multi choice
public static final int MODE_MULTI = 1;

/** Max image size,int,{@link #DEFAULT_IMAGE_SIZE} by default */
/**
* Max image size,int,{@link #DEFAULT_IMAGE_SIZE} by default
*/
public static final String EXTRA_SELECT_COUNT = "max_select_count";
/** Select mode,{@link #MODE_MULTI} by default */
/**
* Select mode,{@link #MODE_MULTI} by default
*/
public static final String EXTRA_SELECT_MODE = "select_count_mode";
/** Whether show camera,true by default */
/**
* Whether show camera,true by default
*/
public static final String EXTRA_SHOW_CAMERA = "show_camera";
/** Result data set,ArrayList&lt;String&gt;*/
/**
* Result data set,ArrayList&lt;String&gt;
*/
public static final String EXTRA_RESULT = "select_result";
/** Original data set */
/**
* Original data set
*/
public static final String EXTRA_DEFAULT_SELECTED_LIST = "default_list";
// Default image size
private static final int DEFAULT_IMAGE_SIZE = 9;
Expand All @@ -58,7 +69,7 @@ protected void onCreate(Bundle savedInstanceState) {
}

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
if(toolbar != null){
if (toolbar != null) {
setSupportActionBar(toolbar);
}

Expand All @@ -71,33 +82,33 @@ protected void onCreate(Bundle savedInstanceState) {
mDefaultCount = intent.getIntExtra(EXTRA_SELECT_COUNT, DEFAULT_IMAGE_SIZE);
final int mode = intent.getIntExtra(EXTRA_SELECT_MODE, MODE_MULTI);
final boolean isShow = intent.getBooleanExtra(EXTRA_SHOW_CAMERA, true);
if(mode == MODE_MULTI && intent.hasExtra(EXTRA_DEFAULT_SELECTED_LIST)) {
if (mode == MODE_MULTI && intent.hasExtra(EXTRA_DEFAULT_SELECTED_LIST)) {
resultList = intent.getStringArrayListExtra(EXTRA_DEFAULT_SELECTED_LIST);
}

mSubmitButton = (Button) findViewById(R.id.commit);
if(mode == MODE_MULTI){
if (mode == MODE_MULTI) {
updateDoneText(resultList);
mSubmitButton.setVisibility(View.VISIBLE);
mSubmitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(resultList != null && resultList.size() >0){
if (resultList != null && resultList.size() > 0) {
// Notify success
Intent data = new Intent();
data.putStringArrayListExtra(EXTRA_RESULT, resultList);
setResult(RESULT_OK, data);
}else{
} else {
setResult(RESULT_CANCELED);
}
finish();
}
});
}else{
} else {
mSubmitButton.setVisibility(View.GONE);
}

if(savedInstanceState == null){
if (savedInstanceState == null) {
Bundle bundle = new Bundle();
bundle.putInt(MultiImageSelectorFragment.EXTRA_SELECT_COUNT, mDefaultCount);
bundle.putInt(MultiImageSelectorFragment.EXTRA_SELECT_MODE, mode);
Expand All @@ -108,7 +119,6 @@ public void onClick(View view) {
.add(R.id.image_grid, Fragment.instantiate(this, MultiImageSelectorFragment.class.getName(), bundle))
.commit();
}

}

@Override
Expand All @@ -124,14 +134,15 @@ public boolean onOptionsItemSelected(MenuItem item) {

/**
* Update done button by select image data
*
* @param resultList selected image data
*/
private void updateDoneText(ArrayList<String> resultList){
private void updateDoneText(ArrayList<String> resultList) {
int size = 0;
if(resultList == null || resultList.size()<=0){
if (resultList == null || resultList.size() <= 0) {
mSubmitButton.setText(R.string.mis_action_done);
mSubmitButton.setEnabled(false);
}else{
} else {
size = resultList.size();
mSubmitButton.setEnabled(true);
}
Expand All @@ -150,25 +161,30 @@ public void onSingleImageSelected(String path) {

@Override
public void onImageSelected(String path) {
if(!resultList.contains(path)) {
if (!resultList.contains(path)) {
resultList.add(path);
}
updateDoneText(resultList);
}

@Override
public void onImageUnselected(String path) {
if(resultList.contains(path)){
if (resultList.contains(path)) {
resultList.remove(path);
}
updateDoneText(resultList);
}

@Override
public void onCameraShot(File imageFile) {
if(imageFile != null) {
if (imageFile != null) {
// notify system the image has change
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(imageFile)));

final Uri fileUri = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ?
FileProvider.getUriForFile(this, getPackageName().concat(".provider"), imageFile)
: Uri.fromFile(imageFile);

sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, fileUri));

Intent data = new Intent();
resultList.add(imageFile.getAbsolutePath());
Expand All @@ -177,4 +193,4 @@ public void onCameraShot(File imageFile) {
finish();
}
}
}
}
Loading