README.md 6.1 KB
Newer Older
N
Nereo 已提交
1 2
# MultiImageSelector
Image selector for Android device. Support single choice and multi-choice.
N
add doc  
Nereo 已提交
3

N
Nereo 已提交
4 5
[![](https://jitpack.io/v/lovetuzitong/MultiImageSelector.svg)](https://jitpack.io/#lovetuzitong/MultiImageSelector)

N
add doc  
Nereo 已提交
6 7 8 9 10 11 12
[中文文档](README_zh.md)

###ART
![Example1](art/example_1.png) ![Select1](art/select_1.png) ![Select2](art/select_2.png) ![Select3](art/select_3.png)

-------------------

N
Nereo 已提交
13 14 15 16
###Run Demo

>./gradlew installDebug

N
add doc  
Nereo 已提交
17 18
###Quick Start
* Step 0
N
Nereo 已提交
19 20 21 22 23 24 25
Add module `multi-image-selector` as your dependence. in your `build.gradle` :
```java
repositories {
    maven { url "https://jitpack.io" }
}

dependencies {
N
Nereo 已提交
26
    compile 'com.github.lovetuzitong:MultiImageSelector:1.2'
N
Nereo 已提交
27 28
}
```
N
add doc  
Nereo 已提交
29 30

* Step 1 
N
Nereo 已提交
31
Set your `AndroidManifest.xml` as below:
N
Nereo 已提交
32
```xml
N
Nereo 已提交
33 34 35 36 37 38 39 40 41 42 43 44
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application

    ...

    <!--Image Selector Entry-->
    <activity
        android:configChanges="orientation|screenSize"
        android:name="me.nereo.multi_image_selector.MultiImageSelectorActivity" />
</application>
N
Nereo 已提交
45
```
N
add doc  
Nereo 已提交
46 47

* Step 2
N
Nereo 已提交
48 49 50 51 52
Call image selector simplest in your code, eg. ( From `version-1.1` )

``` java
// Multi image selector form an Activity
MultiImageSelector.create(Context)
N
Nereo 已提交
53
        .start(Activity, REQUEST_IMAGE);
N
Nereo 已提交
54 55 56 57 58 59 60 61 62 63
```

Detail Api.
``` java
MultiImageSelector.create(Context)
        .showCamera(boolean) // show camera or not. true by default
        .count(int) // max select image size, 9 by default. used width #.multi()
        .single() // single mode
        .multi() // multi mode, default mode;
        .origin(ArrayList<String>) // original select data set, used width #.multi()
N
Nereo 已提交
64
        .start(Activity/Fragment, REQUEST_IMAGE);
N
Nereo 已提交
65 66 67
```

Also support traditional `Intent` :
N
add doc  
Nereo 已提交
68 69 70 71 72 73 74 75
``` java
Intent intent = new Intent(mContext, MultiImageSelectorActivity.class);
// whether show camera
intent.putExtra(MultiImageSelectorActivity.EXTRA_SHOW_CAMERA, true);
// max select image amount
intent.putExtra(MultiImageSelectorActivity.EXTRA_SELECT_COUNT, 9);
// select mode (MultiImageSelectorActivity.MODE_SINGLE OR MultiImageSelectorActivity.MODE_MULTI)
intent.putExtra(MultiImageSelectorActivity.EXTRA_SELECT_MODE, MultiImageSelectorActivity.MODE_MULTI);
T
tunereo 已提交
76 77
// default select images (support array list)
intent.putStringArrayListExtra(MultiImageSelectorActivity.EXTRA_DEFAULT_SELECTED_LIST, defaultDataArray);
N
add doc  
Nereo 已提交
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
startActivityForResult(intent, REQUEST_IMAGE);
```

* Step 3
Receive result in your `onActivityResult` Method. eg.
```java
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if(requestCode == REQUEST_IMAGE){
        if(resultCode == RESULT_OK){
	        // Get the result list of select image paths
            List<String> path = data.getStringArrayListExtra(MultiImageSelectorActivity.EXTRA_RESULT);
            // do your logic ....
        }
    }
}
```

* Step 4
No more steps, just enjoy. :)

-------------------

###Custom Activity Style
* Custome your own Activity
N
Nereo 已提交
104
```java
N
add doc  
Nereo 已提交
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
class CustomerActivity extends Activity implements MultiImageSelectorFragment.Callback{
	@Override
    protected void onCreate(Bundle savedInstanceState) {
		// customer logic here...
		Bundle bundle = new Bundle();
        bundle.putInt(MultiImageSelectorFragment.EXTRA_SELECT_COUNT, mDefaultCount);
        bundle.putInt(MultiImageSelectorFragment.EXTRA_SELECT_MODE, mode);
        bundle.putBoolean(MultiImageSelectorFragment.EXTRA_SHOW_CAMERA, isShow);
        // Add fragment to your Activity
        getSupportFragmentManager().beginTransaction()
                .add(R.id.image_grid, Fragment.instantiate(this, MultiImageSelectorFragment.class.getName(), bundle))
                .commit();
	}
	@Override
    public void onSingleImageSelected(String path) {
        // When select mode set to MODE_SINGLE, this method will received result from fragment
    }

    @Override
    public void onImageSelected(String path) {
        // You can specify your ActionBar behavior here 
    }

    @Override
    public void onImageUnselected(String path) {
        // You can specify your ActionBar behavior here 
    }

    @Override
    public void onCameraShot(File imageFile) {
        // When user take phone by camera, this method will be called.
    }
}
```
* Take a glance of `MultiImageSelectorActivity.java`

-------------------

N
Nereo 已提交
143 144
###Change Log

N
Nereo 已提交
145
* 2016-5-18
N
Nereo 已提交
146 147 148
    1. Added. `JitPack` support
    2. Added. Convenient way to call image selector. See `Step 2`
    3. Fixed. Some NPE.
N
Nereo 已提交
149

T
tunereo 已提交
150 151 152 153 154 155
* 2016-1-19
    1. Fixed. cannot load some 0-size image
    2. Added. When take a new photo, notify media scanner
    3. Fixed. Can't take photo on RED-MI
    4. Fixed. Performance when show Camera-Icon

N
Nereo 已提交
156 157 158 159
* 2015-5-5
    1. Fixed. Can't display some images. (Issue by[sd6352051](https://github.com/sd6352051), [larry](https://github.com/18611480882))
    2. Fixed. `ListPopupWindow` can not fill parent
    3. Added. Add checked mask.
N
Nereo 已提交
160

N
Nereo 已提交
161 162 163 164 165 166
* 2015-4-16
    1. Fixed. Crack when rotate device. (Issue by [@Leminity](https://github.com/Leminity))
    2. Fixed. PopupListView position error. (Issue by [@Slock](https://github.com/Slock))
    3. Change. Demo application shortcut.
    4. Change. Readme file.

N
Nereo 已提交
167 168 169 170
* 2015-4-9
    1. Fixed. When set `EXTRA_SHOW_CAMERA` to `true`, the first grid item onclick event were messed.
    2. Add. Support initial selected image list.

N
Nereo 已提交
171 172
-------------------

N
add doc  
Nereo 已提交
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
###Thanks

* [square-picasso](https://github.com/square/picasso) A powerful image downloading and caching library for Android 

-------------------

###License
>The MIT License (MIT)

>Copyright (c) 2015 Nereo

>Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

>The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.