diff --git a/.gitignore b/.gitignore index afbdab3..63d4a40 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,31 @@ -.gradle +# Built application files +*.apk +*.ap_ + +# Files for the Dalvik VM +*.dex + +# Java class files +*.class + +# Generated files +bin/ +gen/ + +# Gradle files +.gradle/ +build/ +/*/build/ /local.properties /.idea/workspace.xml /.idea/libraries .DS_Store -/build + +# Local configuration file (sdk path, etc) +local.properties + +# Proguard folder generated by Eclipse +proguard/ + +# Log Files +*.log diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d87b69a --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +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. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..2a6e790 --- /dev/null +++ b/README.md @@ -0,0 +1,117 @@ +# MultiImageSelector +Image selector for Android device. Support single choice and multi-choice. + +[中文文档](README_zh.md) + +###ART +![Example1](art/example_1.png) ![Select1](art/select_1.png) ![Select2](art/select_2.png) ![Select3](art/select_3.png) + +------------------- + +###Quick Start +* Step 0 +Add module `multi-image-selector` as your dependence. + +* Step 1 +Declare permission `android.permission.READ_EXTERNAL_STORAGE` in your `AndroidManifest.xml` . +Declare `MultiImageSelectorActivity` in your `AndroidManifest.xml` . + +* Step 2 +Call image selector activity in your code, eg. +``` 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); + +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 path = data.getStringArrayListExtra(MultiImageSelectorActivity.EXTRA_RESULT); + // do your logic .... + } + } +} +``` + +* Step 4 +No more steps, just enjoy. :) + +------------------- + +###Custom Activity Style +* Custome your own Activity +``` java +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` + +------------------- + +###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. \ No newline at end of file diff --git a/README_zh.md b/README_zh.md new file mode 100644 index 0000000..a119606 --- /dev/null +++ b/README_zh.md @@ -0,0 +1,117 @@ +# MultiImageSelector +仿微信实现多图选择。支持单选和多选两张模式 + +[English Doc](README.md) + +###截图 +![Example1](art/example_1.png) ![Select1](art/select_1.png) ![Select2](art/select_2.png) ![Select3](art/select_3.png) + +------------------- + +###快速开始 +* 第0步 +把模块 `multi-image-selector` 作为你的项目依赖添加到工程中. + +* 第1步 +在你的 `AndroidManifest.xml` 文件中添加权限 `android.permission.READ_EXTERNAL_STORAGE`. +别忘了同时在 `AndroidManifest.xml` 中声明 `MultiImageSelectorActivity` 这个Activity. + +* 第2步 +代码中调用,例如: +``` java +Intent intent = new Intent(mContext, MultiImageSelectorActivity.class); + +// 是否显示调用相机拍照 +intent.putExtra(MultiImageSelectorActivity.EXTRA_SHOW_CAMERA, true); + +// 最大图片选择数量 +intent.putExtra(MultiImageSelectorActivity.EXTRA_SELECT_COUNT, 9); + +// 设置模式 (支持 单选/MultiImageSelectorActivity.MODE_SINGLE 或者 多选/MultiImageSelectorActivity.MODE_MULTI) +intent.putExtra(MultiImageSelectorActivity.EXTRA_SELECT_MODE, MultiImageSelectorActivity.MODE_MULTI); + +startActivityForResult(intent, REQUEST_IMAGE); +``` + +* 第3步 +在你的 `onActivityResult` 方法中接受结果. 例如: +```java +@Override +protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if(requestCode == REQUEST_IMAGE){ + if(resultCode == RESULT_OK){ + // 获取返回的图片列表 + List path = data.getStringArrayListExtra(MultiImageSelectorActivity.EXTRA_RESULT); + // 处理你自己的逻辑 .... + } + } +} +``` + +* 第4步 +没第4步了,就这样就OK啦~ :) + +------------------- + +###自定义显示 +* 自定义Activity +``` java +class CustomerActivity extends Activity implements MultiImageSelectorFragment.Callback{ + @Override + protected void onCreate(Bundle savedInstanceState) { + // 你自己的逻辑... + Bundle bundle = new Bundle(); + bundle.putInt(MultiImageSelectorFragment.EXTRA_SELECT_COUNT, mDefaultCount); + bundle.putInt(MultiImageSelectorFragment.EXTRA_SELECT_MODE, mode); + olean(MultiImageSelectorFragment.EXTRA_SHOW_CAMERA, isShow); + // 添加主Fragment到Activity + getSupportFragmentManager().beginTransaction() + .add(R.id.image_grid, Fragment.instantiate(this, MultiImageSelectorFragment.class.getName(), bundle)) + .commit(); + } + @Override + public void onSingleImageSelected(String path) { + // 当选择模式设定为 单选/MODE_SINGLE, 这个方法就会接受到Fragment返回的数据 + } + + @Override + public void onImageSelected(String path) { + // 一个图片被选择是触发,这里可以自定义的自己的Actionbar行为 + } + + @Override + public void onImageUnselected(String path) { + // 一个图片被反选是触发,这里可以自定义的自己的Actionbar行为 + } + + @Override + public void onCameraShot(File imageFile) { + // 当设置了使用摄像头,用户拍照后会返回照片文件 + } +} +``` +* 具体可以参考`MultiImageSelectorActivity.java`的实现 + +------------------- + +###感谢 + +* [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. \ No newline at end of file diff --git a/art/example_1.png b/art/example_1.png new file mode 100644 index 0000000..a1e4450 Binary files /dev/null and b/art/example_1.png differ diff --git a/art/select_1.png b/art/select_1.png new file mode 100644 index 0000000..4b46ab9 Binary files /dev/null and b/art/select_1.png differ diff --git a/art/select_2.png b/art/select_2.png new file mode 100644 index 0000000..c421537 Binary files /dev/null and b/art/select_2.png differ diff --git a/art/select_3.png b/art/select_3.png new file mode 100644 index 0000000..37398af Binary files /dev/null and b/art/select_3.png differ