diff --git a/.gitignore b/.gitignore index 63d4a40..22ee828 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,9 @@ + +# Created by https://www.gitignore.io/api/indows,android,gradle,intellij,eclipse,java + +#!! ERROR: indows is undefined. Use list command to see defined gitignore types !!# + +### Android ### # Built application files *.apk *.ap_ @@ -11,15 +17,11 @@ # Generated files bin/ gen/ +out/ # Gradle files .gradle/ build/ -/*/build/ -/local.properties -/.idea/workspace.xml -/.idea/libraries -.DS_Store # Local configuration file (sdk path, etc) local.properties @@ -29,3 +31,146 @@ proguard/ # Log Files *.log + +# Android Studio Navigation editor temp files +.navigation/ + +# Android Studio captures folder +captures/ + +# Intellij +*.iml + +### Android Patch ### +gen-external-apklibs + + +### Gradle ### +.gradle +build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Cache of project +.gradletasknamecache + +# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 +# gradle/wrapper/gradle-wrapper.properties + + +### Intellij ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff: +.idea/workspace.xml +.idea/tasks.xml +.idea/dictionaries +.idea/vcs.xml +.idea/jsLibraryMappings.xml + +# Sensitive or high-churn files: +.idea/dataSources.ids +.idea/dataSources.xml +.idea/sqlDataSources.xml +.idea/dynamic.xml +.idea/uiDesigner.xml + +# Gradle: +.idea/gradle.xml +.idea/libraries + +# Mongo Explorer plugin: +.idea/mongoSettings.xml + +## File-based project format: +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + + +### Eclipse ### + +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.settings/ +.loadpath + +# Eclipse Core +.project + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# PyDev specific (Python IDE for Eclipse) +*.pydevproject + +# CDT-specific (C/C++ Development Tooling) +.cproject + +# JDT-specific (Eclipse Java Development Tools) +.classpath + +# Java annotation processor (APT) +.factorypath + +# PDT-specific (PHP Development Tools) +.buildpath + +# sbteclipse plugin +.target + +# Tern plugin +.tern-project + +# TeXlipse plugin +.texlipse + +# STS (Spring Tool Suite) +.springBeans + +# Code Recommenders +.recommenders/ + + +### Java ### +*.class + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.ear + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 217af47..96cc43e 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,7 +1,6 @@ - - - + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml index e206d70..97626ba 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -1,5 +1,6 @@ - - - + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 85a6c64..5dea0cc 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -5,15 +5,22 @@ + - - + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..f81bcc0 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,1121 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..3b31283 --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 9076de5..bd62ec5 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,8 +3,47 @@ - + + + + + + + + + + + + + + + - - + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index 16aeed6..c1e8f28 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -4,8 +4,7 @@ - + - - + \ No newline at end of file diff --git a/.idea/qaplug_profiles.xml b/.idea/qaplug_profiles.xml new file mode 100644 index 0000000..2cf250a --- /dev/null +++ b/.idea/qaplug_profiles.xml @@ -0,0 +1,14 @@ + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml deleted file mode 100644 index 922003b..0000000 --- a/.idea/scopes/scope_settings.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml index def6a6a..94a25f7 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,7 +1,6 @@ - + - - + \ No newline at end of file diff --git a/MultiImageSelector.iml b/MultiImageSelector.iml index 8935ebd..f4dae0c 100644 --- a/MultiImageSelector.iml +++ b/MultiImageSelector.iml @@ -1,19 +1,19 @@ - + - + - + - - + \ No newline at end of file diff --git a/README.md b/README.md index f901482..5ea3ace 100644 --- a/README.md +++ b/README.md @@ -1,135 +1,116 @@ # MultiImageSelector -Image selector for Android device. Support single choice and multi-choice. +Image selector for Android which supports single and multiple choices. +This library developed by [lovetuzitong](https://github.com/lovetuzitong) originally but in Chinese language and poor English. I continue the development to improve this great library. -[中文文档](README_zh.md) - -###ART +## Screenshots ![Example1](art/example_1.png) ![Select1](art/select_1.png) ![Select2](art/select_2.png) ![Select3](art/select_3.png) -------------------- - -###Run Demo +## Features +* Multiple and single choices +* Take photo +* Limit selecting photos ->./gradlew installDebug +## Quick Start +* Add module `multi-image-selector` as your dependence. +* Declare permission `android.permission.READ_EXTERNAL_STORAGE` in your `AndroidManifest.xml`. +* Declare `MultiImageSelectorActivity` in your `AndroidManifest.xml`. -###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` . ```xml ``` -* Step 2 -Call image selector activity in your code, eg. -``` java -Intent intent = new Intent(mContext, MultiImageSelectorActivity.class); +* Call image selector activity in your code, eg. +```java +Intent intent = new Intent(context, MultiImageSelectorActivity.class); -// whether show camera +// Whether show camera intent.putExtra(MultiImageSelectorActivity.EXTRA_SHOW_CAMERA, true); -// max select image amount +// Max select image amount intent.putExtra(MultiImageSelectorActivity.EXTRA_SELECT_COUNT, 9); -// select mode (MultiImageSelectorActivity.MODE_SINGLE OR MultiImageSelectorActivity.MODE_MULTI) +// Select mode (MultiImageSelectorActivity.MODE_SINGLE OR MultiImageSelectorActivity.MODE_MULTI) intent.putExtra(MultiImageSelectorActivity.EXTRA_SELECT_MODE, MultiImageSelectorActivity.MODE_MULTI); +// Whether log (true by default) +intent.putExtra(MultiImageSelectorActivity.EXTRA_LOG, false); + startActivityForResult(intent, REQUEST_IMAGE); ``` -* Step 3 -Receive result in your `onActivityResult` Method. eg. +* 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 .... + // Get the list of selected images paths + List paths = data.getStringArrayListExtra(MultiImageSelectorActivity.EXTRA_RESULT); + // Do your logic... + } + else { + // Result has canceled } } } ``` -* Step 4 -No more steps, just enjoy. :) - -------------------- - -###Custom Activity Style -* Custome your own Activity +## Extend MultiImageSelectorActivity ```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 +public class MySelector extends MultiImageSelectorActivity { + @Override + public void onCameraShot(File imageFile) { + super.onCameraShot(imageFile); } @Override public void onImageSelected(String path) { - // You can specify your ActionBar behavior here + super.onImageSelected(path); } @Override public void onImageUnselected(String path) { - // You can specify your ActionBar behavior here + super.onImageUnselected(path); } @Override - public void onCameraShot(File imageFile) { - // When user take phone by camera, this method will be called. + public void onSingleImageSelected(String path) { + super.onSingleImageSelected(path); } } ``` -* Take a glance of `MultiImageSelectorActivity.java` - -------------------- - -###Change Log -* 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. +*Note:* When you extend `MultiImageSelectorActivity` you must declare your activity in the `AndroidManifest.xml` and step 3 of quick start can be ignored. -* 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. +## Changelog +* September 23, 2015 + 1. Improve the sample application -* 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. +* September 22, 2015 + 1. Whether log or not + 2. Minor improvements -------------------- +* May 5, 2015 + 1. Fixed: Can't display some images. (Reported by [sd6352051](https://github.com/sd6352051), [larry](https://github.com/18611480882)) + 2. Fixed: `ListPopupWindow` can not fill parent + 3. Added: Add checked mask. -###Thanks +* April 9, 2015 + 1. Fixed: When set `EXTRA_SHOW_CAMERA` to `true`, the first grid item `onclick` event were messed. + 2. Added: Support initial selected image list. -* [square-picasso](https://github.com/square/picasso) A powerful image downloading and caching library for Android +* April 4, 2015 + 1. Fixed: Crack when rotate device. (Reported by [@Leminity](https://github.com/Leminity)) + 2. Fixed: `PopupListView` position error. (Reported by [@Slock](https://github.com/Slock)) + 3. Changed: Demo application shortcut. -------------------- +## Thanks +* [square/picasso](https://github.com/square/picasso) A powerful image downloading and caching library for Android -###License +## License >The MIT License (MIT) >Copyright (c) 2015 Nereo @@ -142,4 +123,4 @@ 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 +copies or substantial portions of the Software. diff --git a/README_zh.md b/README_zh.md deleted file mode 100644 index b6ba2cc..0000000 --- a/README_zh.md +++ /dev/null @@ -1,146 +0,0 @@ -# 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) - -------------------- - -###运行DEMO - ->./gradlew installDebug - -###快速开始 -* 第0步 -把模块 `multi-image-selector` 作为你的项目依赖添加到工程中. - -* 第1步 -在你的 `AndroidManifest.xml` 文件中添加权限 `android.permission.READ_EXTERNAL_STORAGE`. -别忘了同时在 `AndroidManifest.xml` 中声明 `MultiImageSelectorActivity` 这个Activity. -```xml - -``` - -* 第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`的实现 - -------------------- - -###更新日志 - -* 2015-5-5 - 1. 修复. 某些图片无法显示. (Issue by[sd6352051](https://github.com/sd6352051), [larry](https://github.com/18611480882)) - 2. 修复. `ListPopupWindow` 无法填充父控件 - 3. 新增. 选中的遮罩效果. - -* 2015-4-16 - 1. 修复. 旋转设备时,程序会崩溃. (Issue by [@Leminity](https://github.com/Leminity)) - 2. 修复. 文件夹PopupListView位置错误. (Issue by [@Slock](https://github.com/Slock)) - 3. 更改. 演示程序截图. - 4. 更改. Readme 文件. - -* 2015-4-9 - 1. 修复. 当设置 `EXTRA_SHOW_CAMERA` 为 `true` 时, 点击第一个Item会混乱的问题. - 2. 新增. 支持初始化图片选择设定。 - - -------------------- - -###感谢 - -* [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/app/app.iml b/app/app.iml index 46168ca..e497a9c 100644 --- a/app/app.iml +++ b/app/app.iml @@ -1,5 +1,5 @@ - + @@ -12,9 +12,9 @@ - + - + @@ -33,13 +33,13 @@ - + - + @@ -47,6 +47,13 @@ + + + + + + + @@ -61,35 +68,41 @@ + + + + + + + - + - + - + + - - - - + - - + + + - + - + + - - - + + + - - + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 5c156f5..4534ad2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,15 +1,14 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 22 - buildToolsVersion "22.0.1" - + compileSdkVersion 23 + buildToolsVersion '23.0.2' defaultConfig { applicationId "me.nereo.multiimageselector" minSdkVersion 12 - targetSdkVersion 22 - versionCode 1 - versionName "1.0" + targetSdkVersion 23 + versionCode 5 + versionName '1.4' } buildTypes { release { @@ -17,10 +16,13 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } + productFlavors { + } } dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') - compile 'com.android.support:appcompat-v7:22.0.0' - compile project(':multi-image-selector') + compile 'com.android.support:appcompat-v7:23.1.1' + compile 'com.jakewharton:butterknife:7.0.1' + compile project(':library') } diff --git a/app/src/androidTest/java/me/nereo/multiimageselector/ApplicationTest.java b/app/src/androidTest/java/me/nereo/multiimageselector/ApplicationTest.java deleted file mode 100644 index e8fcd41..0000000 --- a/app/src/androidTest/java/me/nereo/multiimageselector/ApplicationTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package me.nereo.multiimageselector; - -import android.app.Application; -import android.test.ApplicationTestCase; - -/** - * Testing Fundamentals - */ -public class ApplicationTest extends ApplicationTestCase { - public ApplicationTest() { - super(Application.class); - } -} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index fdccbb1..b38db63 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,29 +1,29 @@ - + - + + + android:theme="@style/AppTheme"> + android:label="@string/app_name"> - + - + - - + android:name="me.nereo.multi_image_selector.MultiImageSelectorActivity" + android:configChanges="orientation|screenSize"/> diff --git a/app/src/main/java/me/nereo/multiimageselector/MainActivity.java b/app/src/main/java/me/nereo/multiimageselector/MainActivity.java index 2b7d23f..78e9991 100644 --- a/app/src/main/java/me/nereo/multiimageselector/MainActivity.java +++ b/app/src/main/java/me/nereo/multiimageselector/MainActivity.java @@ -1,134 +1,112 @@ package me.nereo.multiimageselector; import android.content.Intent; -import android.support.v7.app.ActionBarActivity; import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; import android.text.TextUtils; -import android.util.Log; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; +import android.widget.Button; import android.widget.EditText; +import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.TextView; import java.util.ArrayList; -import java.util.List; +import butterknife.Bind; +import butterknife.ButterKnife; +import butterknife.OnClick; import me.nereo.multi_image_selector.MultiImageSelectorActivity; +import me.nereo.multi_image_selector.utils.Constants; -public class MainActivity extends ActionBarActivity { +public class MainActivity extends AppCompatActivity { private static final int REQUEST_IMAGE = 2; - - private TextView mResultText; - private RadioGroup mChoiceMode, mShowCamera; - private EditText mRequestNum; - + @Bind(R.id.button) + Button button; + @Bind(R.id.choice_mode) + RadioGroup mChoiceMode; + @Bind(R.id.request_num) + EditText mRequestNum; + @Bind(R.id.result) + TextView mResult; + @Bind(R.id.show_camera) + RadioGroup mShowCamera; + @Bind(R.id.multi) + RadioButton multi; + @Bind(R.id.no_show) + RadioButton noShow; + @Bind(R.id.show) + RadioButton show; + @Bind(R.id.single) + RadioButton single; private ArrayList mSelectPath; + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (requestCode == REQUEST_IMAGE) { + if (resultCode == RESULT_OK) { + mSelectPath = data.getStringArrayListExtra(Constants.EXTRA_RESULT); + StringBuilder sb = new StringBuilder(); + for (String p : mSelectPath) { + sb.append(p); + sb.append("\n"); + } + mResult.setText(sb.toString()); + } + } + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - - mResultText = (TextView) findViewById(R.id.result); - mChoiceMode = (RadioGroup) findViewById(R.id.choice_mode); - mShowCamera = (RadioGroup) findViewById(R.id.show_camera); - mRequestNum = (EditText) findViewById(R.id.request_num); + ButterKnife.bind(this); mChoiceMode.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup radioGroup, int checkedId) { - if(checkedId == R.id.multi){ + if (checkedId == R.id.multi) { mRequestNum.setEnabled(true); - }else{ + } else { mRequestNum.setEnabled(false); mRequestNum.setText(""); } } }); - - findViewById(R.id.button).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - - int selectedMode = MultiImageSelectorActivity.MODE_MULTI; - - if(mChoiceMode.getCheckedRadioButtonId() == R.id.single){ - selectedMode = MultiImageSelectorActivity.MODE_SINGLE; - }else{ - selectedMode = MultiImageSelectorActivity.MODE_MULTI; - } - - boolean showCamera = mShowCamera.getCheckedRadioButtonId() == R.id.show; - - int maxNum = 9; - if(!TextUtils.isEmpty(mRequestNum.getText())){ - maxNum = Integer.valueOf(mRequestNum.getText().toString()); - } - - Intent intent = new Intent(MainActivity.this, MultiImageSelectorActivity.class); - // 是否显示拍摄图片 - intent.putExtra(MultiImageSelectorActivity.EXTRA_SHOW_CAMERA, showCamera); - // 最大可选择图片数量 - intent.putExtra(MultiImageSelectorActivity.EXTRA_SELECT_COUNT, maxNum); - // 选择模式 - intent.putExtra(MultiImageSelectorActivity.EXTRA_SELECT_MODE, selectedMode); - // 默认选择 - if(mSelectPath != null && mSelectPath.size()>0){ - intent.putExtra(MultiImageSelectorActivity.EXTRA_DEFAULT_SELECTED_LIST, mSelectPath); - } - startActivityForResult(intent, REQUEST_IMAGE); - - } - }); - -/* findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Intent intent = new Intent(MainActivity.this, GestureImageActivity.class); - startActivity(intent); - } - });*/ } - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - if(requestCode == REQUEST_IMAGE){ - if(resultCode == RESULT_OK){ - mSelectPath = data.getStringArrayListExtra(MultiImageSelectorActivity.EXTRA_RESULT); - StringBuilder sb = new StringBuilder(); - for(String p: mSelectPath){ - sb.append(p); - sb.append("\n"); - } - mResultText.setText(sb.toString()); - } - } - } + @OnClick(R.id.button) + public void onButtonClick() { + int selectedMode; - @Override - public boolean onCreateOptionsMenu(Menu menu) { - // Inflate the menu; this adds items to the action bar if it is present. - getMenuInflater().inflate(R.menu.menu_main, menu); - return true; - } + if (mChoiceMode.getCheckedRadioButtonId() == R.id.single) { + selectedMode = Constants.MODE_SINGLE; + } else { + selectedMode = Constants.MODE_MULTI; + } - @Override - public boolean onOptionsItemSelected(MenuItem item) { - // Handle action bar item clicks here. The action bar will - // automatically handle clicks on the Home/Up button, so long - // as you specify a parent activity in AndroidManifest.xml. - int id = item.getItemId(); + boolean showCamera = mShowCamera.getCheckedRadioButtonId() == R.id.show; - //noinspection SimplifiableIfStatement - if (id == R.id.action_settings) { - return true; + int maxNum = 9; + if (!TextUtils.isEmpty(mRequestNum.getText())) { + maxNum = Integer.valueOf(mRequestNum.getText().toString()); } - return super.onOptionsItemSelected(item); + Intent intent = new Intent(MainActivity.this, MultiImageSelectorActivity.class); + // 是否显示拍摄图片 + intent.putExtra(Constants.EXTRA_SHOW_CAMERA, showCamera); + // 最大可选择图片数量 + intent.putExtra(Constants.EXTRA_SELECT_COUNT, !mRequestNum.getText().toString().isEmpty() ? + Integer + .parseInt(mRequestNum.getText().toString()) : Constants.DEFAULT_SELECTING_COUNT); + // 选择模式 + intent.putExtra(Constants.EXTRA_SELECT_MODE, selectedMode); + // 默认选择 + if (mSelectPath != null && mSelectPath.size() > 0) { + intent.putExtra(Constants.EXTRA_DEFAULT_SELECTED_LIST, mSelectPath); + } + startActivityForResult(intent, REQUEST_IMAGE); } } diff --git a/app/src/main/res/drawable-hdpi/ic_camera.png b/app/src/main/res/drawable-hdpi/ic_camera.png new file mode 100644 index 0000000..558b547 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_camera.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_camera.png b/app/src/main/res/drawable-mdpi/ic_camera.png new file mode 100644 index 0000000..8edb547 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_camera.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_camera.png b/app/src/main/res/drawable-xhdpi/ic_camera.png new file mode 100644 index 0000000..e688ca9 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_camera.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_camera.png b/app/src/main/res/drawable-xxhdpi/ic_camera.png new file mode 100644 index 0000000..1e5be05 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_camera.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_camera.png b/app/src/main/res/drawable-xxxhdpi/ic_camera.png new file mode 100644 index 0000000..e94b235 Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_camera.png differ diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index a87f667..b4e0f53 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,91 +1,96 @@ + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" + android:paddingBottom="@dimen/activity_vertical_margin" + android:paddingLeft="@dimen/activity_horizontal_margin" + android:paddingRight="@dimen/activity_horizontal_margin" + android:paddingTop="@dimen/activity_vertical_margin" + tools:context=".MainActivity"> + android:textSize="16sp" + android:textStyle="bold"/> + android:layout_height="wrap_content" + android:checkedButton="@+id/multi" + android:orientation="vertical"> + android:layout_height="wrap_content" + android:checked="true" + android:text="@string/mode_single"/> + + android:layout_height="wrap_content" + android:text="@string/mode_multi"/> - + + android:textSize="16sp" + android:textStyle="bold"/> + android:layout_height="wrap_content" + android:enabled="false" + android:hint="@string/hint_default_amount" + android:inputType="number"/> + android:textSize="16sp" + android:textStyle="bold"/> + android:layout_height="wrap_content" + android:checkedButton="@+id/show" + android:orientation="vertical"> + android:layout_height="wrap_content" + android:text="@string/enable"/> + + android:layout_height="wrap_content" + android:text="@string/disable"/>