├── .gitignore
├── .idea
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
└── runConfigurations.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── wxxiaomi
│ │ └── ming
│ │ └── webviewcachemodule
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── assets
│ │ ├── js
│ │ │ └── JsBridge.js
│ │ └── test1.html
│ ├── java
│ │ └── com
│ │ │ └── wxxiaomi
│ │ │ └── ming
│ │ │ └── webviewcachemodule
│ │ │ ├── MainActivity.java
│ │ │ ├── TAG.java
│ │ │ ├── common
│ │ │ ├── BaseWebActivity.java
│ │ │ ├── GlideImageLoader.java
│ │ │ ├── PicTakeUtil.java
│ │ │ └── util
│ │ │ │ ├── CacheEngine.java
│ │ │ │ ├── CompressUtil.java
│ │ │ │ └── DiskCache.java
│ │ │ ├── version_1
│ │ │ └── Version_1_Activity.java
│ │ │ ├── version_2
│ │ │ └── Version_2_Activity.java
│ │ │ ├── version_3
│ │ │ └── Compress_Cache_Base64_Activity.java
│ │ │ └── version_4
│ │ │ └── StreamActivity.java
│ └── res
│ │ ├── layout
│ │ ├── activity_compress__cache__base64_.xml
│ │ ├── activity_main.xml
│ │ ├── activity_stream.xml
│ │ ├── activity_version_1_.xml
│ │ └── activity_version_2_.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── wxxiaomi
│ └── ming
│ └── webviewcachemodule
│ └── ExampleUnitTest.java
├── build.gradle
├── gallerypick
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── yancy
│ │ └── gallerypick
│ │ └── ApplicationTest.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── yancy
│ │ └── gallerypick
│ │ ├── activity
│ │ ├── BaseActivity.java
│ │ └── GalleryPickActivity.java
│ │ ├── adapter
│ │ ├── FolderAdapter.java
│ │ ├── MiniPhotoAdapter.java
│ │ └── PhotoAdapter.java
│ │ ├── bean
│ │ ├── FolderInfo.java
│ │ └── PhotoInfo.java
│ │ ├── config
│ │ ├── GalleryConfig.java
│ │ └── GalleryPick.java
│ │ ├── inter
│ │ ├── IHandlerCallBack.java
│ │ └── ImageLoader.java
│ │ ├── utils
│ │ ├── AppUtils.java
│ │ ├── FileUtils.java
│ │ ├── ScreenUtils.java
│ │ ├── SystemBarTintManager.java
│ │ ├── UCropUtils.java
│ │ └── UIUtils.java
│ │ └── widget
│ │ ├── FolderListPopupWindow.java
│ │ ├── GalleryImageView.java
│ │ └── GalleryPickView.java
│ └── res
│ ├── anim
│ ├── in_fade.xml
│ └── out_fade.xml
│ ├── layout
│ ├── gallery_item_camera.xml
│ ├── gallery_item_folder.xml
│ ├── gallery_item_photo.xml
│ ├── gallery_main.xml
│ ├── gallery_mini.xml
│ ├── gallery_mini_item.xml
│ ├── gallery_popup_folder.xml
│ └── gallery_title.xml
│ ├── mipmap-hdpi
│ ├── gallery_pick_back_black.png
│ ├── gallery_pick_back_white.png
│ ├── gallery_pick_camera.png
│ ├── gallery_pick_dropdown_black.png
│ ├── gallery_pick_dropdown_white.png
│ ├── gallery_pick_photo.png
│ ├── gallery_pick_select_checked.png
│ ├── gallery_pick_select_unchecked.png
│ └── gallery_pick_selected.png
│ ├── mipmap-mdpi
│ ├── gallery_pick_back_black.png
│ ├── gallery_pick_back_white.png
│ ├── gallery_pick_camera.png
│ ├── gallery_pick_dropdown_black.png
│ ├── gallery_pick_dropdown_white.png
│ ├── gallery_pick_photo.png
│ ├── gallery_pick_select_checked.png
│ ├── gallery_pick_select_unchecked.png
│ └── gallery_pick_selected.png
│ ├── mipmap-xhdpi
│ ├── gallery_pick_back_black.png
│ ├── gallery_pick_back_white.png
│ ├── gallery_pick_camera.png
│ ├── gallery_pick_dropdown_black.png
│ ├── gallery_pick_dropdown_white.png
│ ├── gallery_pick_photo.png
│ ├── gallery_pick_select_checked.png
│ ├── gallery_pick_select_unchecked.png
│ └── gallery_pick_selected.png
│ ├── mipmap-xxhdpi
│ ├── gallery_pick_back_black.png
│ ├── gallery_pick_back_white.png
│ ├── gallery_pick_camera.png
│ ├── gallery_pick_dropdown_black.png
│ ├── gallery_pick_dropdown_white.png
│ ├── gallery_pick_photo.png
│ ├── gallery_pick_select_checked.png
│ ├── gallery_pick_select_unchecked.png
│ └── gallery_pick_selected.png
│ ├── mipmap-xxxhdpi
│ ├── gallery_pick_back_black.png
│ ├── gallery_pick_back_white.png
│ ├── gallery_pick_camera.png
│ ├── gallery_pick_dropdown_black.png
│ ├── gallery_pick_dropdown_white.png
│ ├── gallery_pick_photo.png
│ ├── gallery_pick_select_checked.png
│ ├── gallery_pick_select_unchecked.png
│ └── gallery_pick_selected.png
│ ├── values-v19
│ └── styles.xml
│ ├── values-v21
│ └── styles.xml
│ └── values
│ ├── colors.xml
│ ├── strings.xml
│ └── styles.xml
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
19 |
20 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ps: 排版和图片再github显示不怎么一致,如果看得不爽请移步csdn:
2 | http://blog.csdn.net/qq122627018/article/details/53351781
3 | # 前言
4 | 先讲讲为什么会有这篇blog,话说前几天做个模块,要求是这样的:
5 | 做一个webview的页面,功能类似于微信发朋友圈一样,要求能上传本地图片到webview中进行展示,并按用户喜好添加和删除,当用户点击发布的时候,将这些图片上传至阿里云oss,收到oss响应后封装页面信息提交给服务器
6 |
7 | # 技术要点
8 |
9 | 1. webview与native的交互
10 | 2. webview显示客户端本地图片的方式
11 | 3. webview加载大量图片的问题(优化方案)
12 | 4. 自定义关于webview的缓存系统
13 |
14 | # webview与native的交互
15 | 关于交互其实网上有很多文章,在之前我也写过一篇关于webview与native交互方案的blog:[ Android混合开发的入门和方案](http://blog.csdn.net/qq122627018/article/details/52207600)
16 | 因此在这个demo中我采用的也是JsBridge的方式来让webview与native进行通信,所以主要提一下其中一些坑:
17 |
18 | 1. 使用JsBridge的方式,在子线程是无法发送消息给WebView的
19 | 2. 如果webview要加载本地文件,必须设置mWebView.getSettings().setAllowFileAccess(true);
20 | 3. 如果html文件存在于服务器中,就算你按照第二点设置了,那webview也无法读取本地文件,会报not allowed to load local resource(解决办法后面我会给出),这个坑异常深!!!
21 | 4. 使用base64编码来让webview中img便签加载编码后的图片的异常(大坑)
22 |
23 | # webview显示客户端本地图片的方式
24 | ## 直接设置
25 | 拿到本地文件的路径,然后拼装
便签,设置其src属性为"file://"+路径,webview就会自动去找此地址("file://"是属性webview的一种协议,就像我们的http协议的道理)
26 |
27 | ```
28 | //imgPaths是我们选择的那些图片的本地路径
29 | private void adapterH5Data(List imgPaths){
30 | String result = "";
31 | //拼装标签
32 | for(int i=0;i";
34 | }
35 | //发送给webview容器
36 | mWebView.callHandler("adapter",result,null);
37 | }
38 | ```
39 | 那么在我们的html文件中,有一个这样的方法:
40 |
41 | ```
42 | function adapter(pars){
43 | //直接把native拼装好的html添加到id为info_img的便签里面
44 | $("#info_img").prepend(pars);
45 | }
46 | ```
47 |
48 | ## Base64编码
49 | base64编码大家应该都有接触过,还记得宝宝当年刚撸项目的时候,图片上传就是利用app把图片转化为base64,然后把这段字符串发送给服务器接收再进行解码,差点把老师气吐血。
50 | 那么这个方案,就是把目标路径的文件,通过base64编码编写成字符串,然后设置到img便签的src属性,这样img便可以显示出图片。
51 |
52 | ```
53 | /**
54 | * 在这里必须使用多线程,因为base64对图片进行编码非常耗时,
55 | * 所以必须在子线程并且多线程处理每张图片的编码
56 | * RxJava的线程切换(这里暂时还没有使用多线程)
57 | * @param imgPaths
58 | */
59 | private void adapterH5Data(final List imgPaths) {
60 | Observable.create(new Observable.OnSubscribe() {
61 | @Override
62 | public void call(Subscriber super String> subscriber) {
63 | for (int i = 0; i < imgPaths.size(); i++) {
64 | String result = "";
65 | String item = imgPaths.get(i);
66 | Log.i("wang","item:"+item);
67 | String s = Base64.encodeToString(getBytes(item), Base64.NO_WRAP);
68 | result += "
";
69 | subscriber.onNext(result);
70 | }
71 | }
72 | })
73 | .subscribeOn(Schedulers.io())
74 | .observeOn(AndroidSchedulers.mainThread())
75 | .subscribe(new Action1() {
76 | @Override
77 | public void call(String result) {
78 | size++;
79 | tv.setText("编码完成:"+size+"张");
80 | mWebView.callHandler("adapter", result, null);
81 | }
82 | })
83 | ;
84 | }
85 | ```
86 |
87 | ## 方案的对比
88 | 图一为第一种方案,图二为第二种方案
89 |  
90 |
91 | 1. 其实还有通过shouldInterceptRequest方法来显示图片,在这里其实跟第一种方案的原理一样(放到后面讲)
92 | 2. 总体来说第一种方案的速度是比较快的,但是第一种方案有一个缺点就是如果是服务器的html的文件,是无法读取本地文件的
93 | 3. 上面写的第二种方案只是一个入门级的,对比第一种方案唯一的优点是就算是非本地的文件也可以读取,但是总体速度非常慢
94 |
95 | # 优化
96 | 很明显,上面的俩种方案都只是一个入门级的方案,根本走不上台面,缺点:
97 |
98 | - 本地图片没有经过压缩,直接放在webview中,如果图片比较多,会导致oom
99 | - 由上面的截图也可以看出从选完照片到webview显示,速度还是非常慢的,卡顿的感觉非常明显
100 | - 无法适应我们的需求,有时候html是在服务器上面的,有时候是存在本地的,无法做到统一处理
101 | 那么下面介绍我的第三种方案
102 |
103 | ## 多线程工作+压缩+缓存+base64编码
104 | ps:本来压缩想单独做个demo出来的,后面发现压缩模块如果没有缓存模块一起合作的化,每次加载图片都要进行压缩,非常恐怖哈哈!
105 | 这里讲一下主要思路:
106 |
107 | - 每当我们拿到本地图片的路径之后,把这个路径md5之后当作key,检查缓存中是否存在:
108 | - 不存在:调用压缩模块对次路径的图片进行压缩,压缩完成再存入缓存中,再返回压缩后的文件的byte数组
109 | - 存在:直接返回
110 |
111 | 在这里我的缓存系统是使用RxJAva+DiskLruCache实现的:
112 |
113 | ```
114 | /**
115 | * 获取本地的图片
116 | * 先从硬盘获取,如果硬盘获取不到
117 | * 再拿图片进行压缩,再存到硬盘缓存
118 | * 然后返回
119 | * @param path
120 | * @return
121 | */
122 | public Observable getLocalImg(final String path){
123 | Observable diskCache = DiskCache.getInstance().getDiskCache(path);
124 | //存入缓存的操作,先压缩,再缓存,CompressUtil是图片压缩工具类
125 | Observable doCache = CompressUtil.compressImg(path, 100, 100)
126 | .flatMap(new Func1>() {
127 | @Override
128 | public Observable call(final byte[] bytes) {
129 | return DiskCache.getInstance().toDiskCache(path, bytes);
130 | }
131 | });
132 | //使用concat操作符来实现先调用diskCache,再调用doCache
133 | return Observable.concat(diskCache,doCache)
134 | .first(new Func1() {
135 | @Override
136 | public Boolean call(byte[] bytes) {
137 | return bytes != null;
138 | }
139 | });
140 | }
141 | ```
142 | 上面是缓存系统的核心代码,避免太多代码太混乱。其中关于压缩模块的代码,DiskLruCache工具类的代码可以直接看demo。
143 | 拿到本地图片路径之后的操作:
144 |
145 | ```
146 | private void adapter(List photoList) {
147 | CacheEngine.getInstance().getLocalImgsMany2(photoList)
148 | .flatMap((Fun1) (bytes) -> { return byte2Base64(bytes); })
149 | .ObserverOn(AndroidSchedulers.mainThread())
150 | .subscribe((Action1)(result) -> { sendToH5(result) });
151 | ```
152 |
153 | 然后就是关于多线程的实现,使用RxJava一个最大的亮点就是线程切换,在发出每个源数据的时候,只需要调用subscribeOn(Schedulers.newThread())即可,如果要看具体实现请移步demo,下面是效果:
154 | 
155 | 这个方案大体的思想就是这样的,总体的速度提升了超级多(后面有截图对比),下面看看第四种方案
156 |
157 | ## 压缩+缓存+流
158 | 从上面第二种方案可以看出,base64编码多么消耗资源(很慢),只能说base64能绕过尽量绕过,我们都知道,webview在访问每一个连接的时候,都必须要经过shouldInterceptRequest这个方法:
159 |
160 | ```
161 | /**
162 | * 自定义的WebViewClient
163 | */
164 | protected class MyWebViewClient extends BridgeWebViewClient {
165 | public MyWebViewClient(BridgeWebView webView) {
166 | super(webView);
167 | }
168 |
169 | @Override
170 | public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
171 | return super.shouldInterceptRequest(view, request);
172 | }
173 | }
174 | ```
175 | WebResourceResponse就是返回给webview的资源,然后在WebResourceResponse 有这样一个构造函数:
176 |
177 | ```
178 | public WebResourceResponse(String mimeType, String encoding, InputStream data) {
179 | throw new RuntimeException("Stub!");
180 | }
181 | ```
182 | 通过传入一个流InputStream来实现发送数据流给webview,那么我现在的思路是这样的:
183 |
184 | - 取得本地图片路径之后,直接跟第一种方案一样生成img便签,例如:
185 | `
`
186 | - 然后在webview加载到此标签的时候,就会被shouldInterceptRequest方法拦截
187 | - 那么此时我们要解析含有"file://"的url,解析本地路径地址
188 | - 调用我们的缓存系统,传入此path, (缓存+压缩)系统返回byte[],解析成inputStream
189 | - 构造WebResourceResponse返回
190 |
191 | 那么核心的代码就是:
192 | ```
193 | //自定义的WebViewClient,重载shouldInterceptRequest方法
194 | class MyWebViewClient extends BridgeWebViewClient {
195 | public MyWebViewClient(BridgeWebView webView) {
196 | super(webView);
197 | }
198 | @Override
199 | public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
200 | String key = "http://localhost";
201 | final WebResourceResponse[] response = {null};
202 | if(url.contains(key)){
203 | //拿到文件地址
204 | String imgPath = url.replace(key,"");
205 | CacheEngine.getInstance().getLocalImgInMain(imgPath)
206 | .subscribe(new Action1() {
207 | @Override
208 | public void call(byte[] bytes) {
209 | response[0] = new WebResourceResponse("image/png", "UTF-8", new ByteArrayInputStream(bytes));
210 | }
211 | });
212 | return response[0];
213 | }else {
214 | return super.shouldInterceptRequest(view, url);
215 | }
216 | }
217 | }
218 | ```
219 | ps:细心的朋友可能发现了的key是"http://localhost"而不是"file:///",这是因为如果是在服务器的html文件后者会被webview主动拦截了,不会经过shouldInterceptRequest方法,所以我们假装成http协议就行了(这是我暂时的解决办法,如果有更好的可以提出来哈)
220 | ## 方案的对比
221 | (图一为第三种方案。图四为第四种方案)
222 |  
223 |
224 | # 总结
225 | 总体来说个人比较喜欢第四种解决方式,因为搭配缓存系统不仅可以做到本地图片的压缩+缓存,还可以做到网络图片的缓存,只需要通过前缀名来判断是哪种图片即可,而且shouldInterceptRequest方法默认是在io线程工作的,就算你的图片有多大都不会阻塞主线程。另外有一个点要说的就是,上面我的缓存系统只用到了硬盘缓存,其实还可以再加一层内存缓存,那样效果就真的完美了(不过因为这种情景下图片的再利用率不高,所以没做内存缓存,如果是网络图片的加载的话,就很有必要使用内存缓存了)
226 | 文章中的代码(start哦谢谢):[github地址](https://github.com/122627018/WebViewCacheModule)
227 |
228 | -
229 |
230 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.0"
6 | defaultConfig {
7 | applicationId "com.wxxiaomi.ming.webviewcachemodule"
8 | minSdkVersion 16
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | repositories {
23 | jcenter()
24 | maven { url "https://jitpack.io" }
25 | }
26 |
27 | dependencies {
28 | compile fileTree(dir: 'libs', include: ['*.jar'])
29 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
30 | exclude group: 'com.android.support', module: 'support-annotations'
31 | })
32 | compile 'com.android.support:appcompat-v7:25.0.0'
33 | testCompile 'junit:junit:4.12'
34 | compile 'com.github.lzyzsd:jsbridge:1.0.4'
35 | compile 'io.reactivex:rxjava:1.0.14'
36 | compile 'io.reactivex:rxandroid:1.0.1'
37 | compile 'com.github.bumptech.glide:glide:3.6.1'
38 | compile 'com.jakewharton:disklrucache:2.0.2'
39 | compile project(path: ':gallerypick')
40 | }
41 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\work\Android\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/wxxiaomi/ming/webviewcachemodule/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.wxxiaomi.ming.webviewcachemodule;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.wxxiaomi.ming.webviewcachemodule", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/assets/js/JsBridge.js:
--------------------------------------------------------------------------------
1 | function connectWebViewJavascriptBridge(callback) {
2 | if (window.WebViewJavascriptBridge) {
3 | callback(WebViewJavascriptBridge)
4 | } else {
5 | document.addEventListener(
6 | 'WebViewJavascriptBridgeReady'
7 | , function() {
8 | callback(WebViewJavascriptBridge)
9 | },
10 | false
11 | );
12 | }
13 | }
14 |
15 | function registerBridge(MyInitCallback,registerCallBack){
16 | connectWebViewJavascriptBridge(function(bridge){
17 | bridge.init(MyInitCallback);
18 | registerCallBack(bridge);
19 |
20 | });
21 | }
22 |
23 | function showLog(data){
24 | window.WebViewJavascriptBridge.callHandler(
25 | 'showLog'
26 | , data
27 | , null
28 | );
29 | }
30 |
31 |
--------------------------------------------------------------------------------
/app/src/main/assets/test1.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
13 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
31 |
33 |
36 |
39 |
40 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wxxiaomi/ming/webviewcachemodule/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.wxxiaomi.ming.webviewcachemodule;
2 |
3 | import android.content.Intent;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 | import android.view.View;
7 | import android.widget.Button;
8 |
9 | import com.wxxiaomi.ming.webviewcachemodule.version_1.Version_1_Activity;
10 | import com.wxxiaomi.ming.webviewcachemodule.version_2.Version_2_Activity;
11 | import com.wxxiaomi.ming.webviewcachemodule.version_3.Compress_Cache_Base64_Activity;
12 | import com.wxxiaomi.ming.webviewcachemodule.version_4.StreamActivity;
13 |
14 | /**
15 | *
16 | */
17 | public class MainActivity extends AppCompatActivity implements View.OnClickListener {
18 |
19 | private Button btn_1;
20 | private Button btn_2;
21 | private Button btn_3;
22 | private Button btn_4;
23 | private Button btn_5;
24 |
25 | @Override
26 | protected void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | setContentView(R.layout.activity_main);
29 | btn_1 = (Button) findViewById(R.id.btn_1);
30 | btn_1.setOnClickListener(this);
31 | btn_2 = (Button) findViewById(R.id.btn_2);
32 | btn_2.setOnClickListener(this);
33 | btn_3 = (Button) findViewById(R.id.btn_3);
34 | btn_3.setOnClickListener(this);
35 | btn_4 = (Button) findViewById(R.id.btn_4);
36 | btn_4.setOnClickListener(this);
37 | btn_5 = (Button) findViewById(R.id.btn_5);
38 | btn_5.setOnClickListener(this);
39 | }
40 |
41 | @Override
42 | public void onClick(View view) {
43 | Intent intent = null;
44 | switch (view.getId()){
45 |
46 | case R.id.btn_1:
47 | intent = new Intent(this, Version_1_Activity.class);
48 | startActivity(intent);
49 | break;
50 | case R.id.btn_2:
51 | intent = new Intent(this, Version_2_Activity.class);
52 | startActivity(intent);
53 | break;
54 | case R.id.btn_3:
55 | intent = new Intent(this, Compress_Cache_Base64_Activity.class);
56 | startActivity(intent);
57 | break;
58 | case R.id.btn_4:
59 | intent = new Intent(this, StreamActivity.class);
60 | startActivity(intent);
61 | break;
62 | // case R.id.btn_1:
63 | // Intent intent = new Intent(this, Version_1_Activity.class);
64 | // startActivity(intent);
65 | // break;
66 | }
67 | }
68 |
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wxxiaomi/ming/webviewcachemodule/TAG.java:
--------------------------------------------------------------------------------
1 | package com.wxxiaomi.ming.webviewcachemodule;
2 |
3 | /**
4 | * Created by Mr.W on 2016/11/26.
5 | * E-maiil:122627018@qq.com
6 | * github:https://github.com/122627018
7 | */
8 |
9 | public class TAG {
10 | public final static String TAG = "SUN";
11 | }
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wxxiaomi/ming/webviewcachemodule/common/BaseWebActivity.java:
--------------------------------------------------------------------------------
1 | package com.wxxiaomi.ming.webviewcachemodule.common;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.util.Log;
6 | import android.view.MenuItem;
7 | import android.webkit.WebResourceRequest;
8 | import android.webkit.WebResourceResponse;
9 | import android.webkit.WebView;
10 |
11 | import com.github.lzyzsd.jsbridge.BridgeHandler;
12 | import com.github.lzyzsd.jsbridge.BridgeWebView;
13 | import com.github.lzyzsd.jsbridge.BridgeWebViewClient;
14 | import com.github.lzyzsd.jsbridge.CallBackFunction;
15 | import java.util.HashMap;
16 | import java.util.Map;
17 |
18 | /**
19 | * Created by 12262 on 2016/11/12.
20 | * webview的基础activity,用于webview的初始化
21 | * 不能含有toolbar,toolbar的初始化应该是在simpleActivity中
22 | */
23 | public abstract class BaseWebActivity extends AppCompatActivity {
24 | protected BridgeWebView mWebView;
25 |
26 |
27 | @Override
28 | public void onCreate(Bundle savedInstanceState) {
29 |
30 | super.onCreate(savedInstanceState);
31 | int webViewId = initViewAndReutrnWebViewId(savedInstanceState);
32 | mWebView = (BridgeWebView) findViewById(webViewId);
33 | mWebView.setWebViewClient(new MyWebViewClient(mWebView));
34 |
35 | initWebView();
36 | initCommonMethod();
37 | }
38 |
39 | protected void initCommonMethod() {
40 | mWebView.registerHandler("showLog", new BridgeHandler() {
41 | @Override
42 | public void handler(String data, CallBackFunction function) {
43 | Log.i("wang","js->showLog:"+data);
44 | }
45 | });
46 | }
47 |
48 | /**
49 | * 自定义的WebViewClient
50 | */
51 | protected class MyWebViewClient extends BridgeWebViewClient {
52 | public MyWebViewClient(BridgeWebView webView) {
53 | super(webView);
54 | }
55 |
56 | @Override
57 | public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
58 | return super.shouldInterceptRequest(view, request);
59 | }
60 | }
61 |
62 | protected abstract int initViewAndReutrnWebViewId(Bundle savedInstanceState);
63 | protected abstract void initWebView();
64 |
65 | @Override
66 | public boolean onOptionsItemSelected(MenuItem item)
67 | {
68 | // TODO Auto-generated method stub
69 | if(item.getItemId() == android.R.id.home)
70 | {
71 | finish();
72 | return true;
73 | }
74 | return super.onOptionsItemSelected(item);
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wxxiaomi/ming/webviewcachemodule/common/GlideImageLoader.java:
--------------------------------------------------------------------------------
1 | package com.wxxiaomi.ming.webviewcachemodule.common;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 |
6 | import com.bumptech.glide.Glide;
7 | import com.wxxiaomi.ming.webviewcachemodule.R;
8 | import com.yancy.gallerypick.inter.ImageLoader;
9 | import com.yancy.gallerypick.widget.GalleryImageView;
10 |
11 |
12 | /**
13 | * Created by 12262 on 2016/11/23.
14 | * 加载图片的工具
15 | */
16 | public class GlideImageLoader implements ImageLoader {
17 | @Override
18 | public void displayImage(Activity activity, Context context, String path, GalleryImageView galleryImageView, int width, int height) {
19 | Glide.with(context)
20 | .load(path)
21 | .placeholder(R.mipmap.gallery_pick_photo)
22 | .centerCrop()
23 | .into(galleryImageView);
24 | }
25 |
26 | @Override
27 | public void clearMemoryCache() {
28 |
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wxxiaomi/ming/webviewcachemodule/common/PicTakeUtil.java:
--------------------------------------------------------------------------------
1 | package com.wxxiaomi.ming.webviewcachemodule.common;
2 |
3 | import android.Manifest;
4 | import android.app.Activity;
5 | import android.content.Context;
6 | import android.content.pm.PackageManager;
7 | import android.support.v4.app.ActivityCompat;
8 | import android.support.v4.content.ContextCompat;
9 | import android.widget.Toast;
10 |
11 | import com.yancy.gallerypick.config.GalleryConfig;
12 | import com.yancy.gallerypick.config.GalleryPick;
13 | import com.yancy.gallerypick.inter.IHandlerCallBack;
14 |
15 | import java.util.ArrayList;
16 | import java.util.List;
17 |
18 | /**
19 | * Created by Mr.W on 2016/11/25.
20 | * E-maiil:122627018@qq.com
21 | * github:https://github.com/122627018
22 | * 从本地取照片的一个工具类
23 | */
24 | public class PicTakeUtil {
25 | private Context context;
26 | private GalleryConfig galleryConfig;
27 | private List path = new ArrayList<>();
28 | public PicTakeUtil(Context context){
29 | this.context = context;
30 | galleryConfig = new GalleryConfig.Builder()
31 | .imageLoader(new GlideImageLoader()) // ImageLoader 加载框架(必填)
32 | .pathList(path) // 记录已选的图片
33 | .multiSelect(false) // 是否多选 默认:false
34 | .multiSelect(false, 9) // 配置是否多选的同时 配置多选数量 默认:false , 9
35 | .maxSize(9) // 配置多选时 的多选数量。 默认:9
36 | .crop(false) // 快捷开启裁剪功能,仅当单选 或直接开启相机时有效
37 | .crop(false, 1, 1, 500, 500) // 配置裁剪功能的参数, 默认裁剪比例 1:1
38 | .isShowCamera(true) // 是否现实相机按钮 默认:false
39 | .filePath("/Gallery/Pictures") // 图片存放路径
40 | .build();
41 | galleryConfig.getBuilder().isShowCamera(true).build();
42 | }
43 |
44 | public void takePicture(IHandlerCallBack iHandlerCallBack){
45 | galleryConfig.getBuilder().multiSelect(true).build();
46 | galleryConfig.getBuilder().crop(false).build();
47 | galleryConfig.getBuilder().iHandlerCallBack(iHandlerCallBack);
48 | openTakeWindow();
49 | }
50 |
51 | public void openTakeWindow(){
52 | galleryConfig.getBuilder().isOpenCamera(false).build();
53 | if (ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
54 | if (ActivityCompat.shouldShowRequestPermissionRationale((Activity)context, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
55 | Toast.makeText(context, "请在 设置-应用管理 中开启此应用的储存授权。", Toast.LENGTH_SHORT).show();
56 | } else {
57 | ActivityCompat.requestPermissions((Activity)context, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 8);
58 | }
59 | } else {
60 | GalleryPick.getInstance().setGalleryConfig(galleryConfig).open((Activity)context);
61 |
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wxxiaomi/ming/webviewcachemodule/common/util/CacheEngine.java:
--------------------------------------------------------------------------------
1 | package com.wxxiaomi.ming.webviewcachemodule.common.util;
2 |
3 | import android.util.Log;
4 |
5 |
6 | import java.util.List;
7 |
8 | import rx.Observable;
9 | import rx.functions.Func1;
10 |
11 | /**
12 | * Created by 12262 on 2016/11/25.
13 | * 缓存的处理服务
14 | */
15 |
16 | public class CacheEngine {
17 | private CacheEngine(){};
18 | private static CacheEngine INSTANCE;
19 | public static CacheEngine getInstance(){
20 | if(INSTANCE==null){
21 | synchronized (CacheEngine.class){
22 | INSTANCE = new CacheEngine();
23 | }
24 | }
25 | return INSTANCE;
26 | }
27 |
28 | /**
29 | * 获取本地的图片
30 | * 先从硬盘获取,如果硬盘获取不到
31 | * 再拿图片进行压缩,再存到硬盘缓存
32 | * 然后返回
33 | * @param path
34 | * @return
35 | */
36 | public Observable getLocalImg(final String path){
37 | Observable diskCache = DiskCache.getInstance().getDiskCache(path);
38 | Observable doCache = CompressUtil.compressImg(path, 100, 100)
39 | .flatMap(new Func1>() {
40 | @Override
41 | public Observable call(final byte[] bytes) {
42 | return DiskCache.getInstance().toDiskCache(path, bytes);
43 | }
44 | });
45 | return Observable.concat(diskCache,doCache)
46 | .first(new Func1() {
47 | @Override
48 | public Boolean call(byte[] bytes) {
49 | return bytes != null;
50 | }
51 | });
52 | }
53 |
54 | /**
55 | * 获取本地的图片
56 | * 先从硬盘获取,如果硬盘获取不到
57 | * 再拿图片进行压缩,再存到硬盘缓存
58 | * 然后返回
59 | * @param path
60 | * @return
61 | */
62 | public Observable getLocalImgInMain(final String path){
63 | Observable diskCache = DiskCache.getInstance().getDiskCacheInMain(path);
64 | return Observable.concat(diskCache,getDoCache(path))
65 | .first(new Func1() {
66 | @Override
67 | public Boolean call(byte[] bytes) {
68 | return bytes != null;
69 | }
70 | });
71 | }
72 |
73 | /**
74 | * 对图片做压缩并缓存的一个操作
75 | * @param path
76 | * @return
77 | */
78 | public Observable getDoCache(final String path){
79 | return CompressUtil.compressImgInMain(path, 100, 100)
80 | .flatMap(new Func1>() {
81 | @Override
82 | public Observable call(final byte[] bytes) {
83 | Log.i("wang","CacheEngine-getLocalImg-doCache.currentThread:"+Thread.currentThread().getName());
84 | return DiskCache.getInstance().toDiskCacheInMain(path, bytes);
85 | }
86 | });
87 | }
88 |
89 | /**
90 | * 从本地数据取一些图片,分发多个源发送
91 | * @param path
92 | * @return
93 | */
94 | public Observable getLocalImgsMany2(final List path){
95 | return Observable.from(path)
96 | .flatMap(new Func1>() {
97 | @Override
98 | public Observable call(String s) {
99 | return getLocalImg(s);
100 | }
101 | });
102 | }
103 |
104 | /**
105 | * 从本地数据取一些图片,合并在一个源里面一起发送
106 | * @param path
107 | * @return
108 | */
109 | // public Observable> getLocalImgs(final List path){
110 | // List> list = new ArrayList<>();
111 | // final List result = new ArrayList<>();
112 | // for(String item : path){
113 | // Observable localImg = getLocalImg(item);
114 | // list.add(localImg);
115 | // }
116 | // return Observable.zip(list, new FuncN>() {
117 | // @Override
118 | // public List call(Object... args) {
119 | // for(Object item : args){
120 | // result.add((byte[])item);
121 | // }
122 | // return result;
123 | // }
124 | // });
125 | // }
126 |
127 | /**
128 | * 从本地数据取一些图片,分发多个源发送
129 | * @param path
130 | * @return
131 | */
132 | // public Observable getLocalImgsMany(final List path){
133 | // Log.i("wang","CacheEngine-getLocalImgsMany.currentThread:"+Thread.currentThread().getName());
134 | // List> list = new ArrayList<>();
135 | // for(String item : path){
136 | // Observable localImg = getLocalImg(item);
137 | // list.add(localImg);
138 | // }
139 | //
140 | // return Observable.merge(list)
141 | // .subscribeOn(Schedulers.newThread())
142 | // ;
143 | //
144 | // }
145 |
146 |
147 |
148 | }
149 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wxxiaomi/ming/webviewcachemodule/common/util/CompressUtil.java:
--------------------------------------------------------------------------------
1 | package com.wxxiaomi.ming.webviewcachemodule.common.util;
2 |
3 |
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Matrix;
7 | import android.media.ExifInterface;
8 | import android.util.Base64;
9 | import android.util.Log;
10 |
11 | import java.io.ByteArrayOutputStream;
12 | import java.io.IOException;
13 | import java.util.regex.Matcher;
14 | import java.util.regex.Pattern;
15 |
16 | import rx.Observable;
17 | import rx.Subscriber;
18 | import rx.schedulers.Schedulers;
19 |
20 | /**
21 | * 1、避免内存过多的压缩方法:
22 | * 归根结底,图片是要显示在界面组件上的,所以还是要用到bitmap,
23 | * 从上面可得出Bitmap的在内存中的大小只和图片尺寸和色彩模式有关,
24 | * 那么要想改变Bitmap在内存中的大小,要么改变尺寸,要么改变色彩模式。
25 | * 2、避免上传浪费流量的压缩方法:
26 | * 改变图片尺寸,改变色彩模式,改变图片质量都行。正常情况下,先改变图片尺寸和色彩模式,再改变图片质量
27 | */
28 | public class CompressUtil {
29 |
30 |
31 | /**
32 | * 传入指定的图片地址,然后进行压缩,并返回byte
33 | * 需要注意的是:最好的新的线程做压缩工作,因为这是耗时操作
34 | *
35 | * @param srcPath
36 | * @param rqsW
37 | * @param rqsH
38 | * @return
39 | */
40 | public final static Observable compressImg(final String srcPath, final int rqsW, final int rqsH) {
41 | return
42 | Observable.create(new Observable.OnSubscribe() {
43 | @Override
44 | public void call(Subscriber super byte[]> subscriber) {
45 | Bitmap bitmap = compressBitmap(srcPath, rqsW, rqsH);
46 | int degree = getDegress(srcPath);
47 | try {
48 | if (degree != 0) bitmap = rotateBitmap(bitmap, degree);
49 | ByteArrayOutputStream bos = new ByteArrayOutputStream();
50 | bitmap.compress(Bitmap.CompressFormat.PNG, 70, bos);
51 | byte[] bytes = bos.toByteArray();
52 | subscriber.onNext(bytes);
53 | } catch (Exception e) {
54 | e.printStackTrace();
55 | }
56 | }
57 | })
58 | .subscribeOn(Schedulers.newThread())
59 | ;
60 | }
61 |
62 |
63 | /**
64 | * 将img的byte数据通过base64编码转化为字符串
65 | *
66 | * @param par
67 | * @return
68 | */
69 | public static Observable byte2Base64(final byte[] par) {
70 | return Observable.create(new Observable.OnSubscribe() {
71 | @Override
72 | public void call(Subscriber super String> subscriber) {
73 | Log.i("cache", "处理数据的线程currentThread:" + Thread.currentThread().getName());
74 | String temp = Base64.encodeToString(par, Base64.DEFAULT);
75 | Pattern p = Pattern.compile("\\s*|\t|\r|\n");
76 | Matcher m = p.matcher(temp);
77 | temp = m.replaceAll("");
78 | String img = "
";
79 | subscriber.onNext(img);
80 | subscriber.onCompleted();
81 | }
82 | }).subscribeOn(Schedulers.newThread());
83 | }
84 |
85 | /**
86 | * rotate the bitmap
87 | *
88 | * @param bitmap
89 | * @param degress
90 | * @return
91 | */
92 | public static Bitmap rotateBitmap(Bitmap bitmap, int degress) {
93 | if (bitmap != null) {
94 | Matrix m = new Matrix();
95 | m.postRotate(degress);
96 | bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, true);
97 | return bitmap;
98 | }
99 | return bitmap;
100 | }
101 |
102 | /**
103 | * 压缩指定路径的图片,并得到图片对象
104 | *
105 | * @param path bitmap source path
106 | * @return Bitmap {@link android.graphics.Bitmap}
107 | */
108 | public final static Bitmap compressBitmap(String path, int rqsW, int rqsH) {
109 | final BitmapFactory.Options options = new BitmapFactory.Options();
110 | options.inJustDecodeBounds = true;
111 | BitmapFactory.decodeFile(path, options);
112 | options.inSampleSize = caculateInSampleSize(options, rqsW, rqsH);
113 | options.inJustDecodeBounds = false;
114 | return BitmapFactory.decodeFile(path, options);
115 | }
116 |
117 |
118 | /**
119 | * caculate the bitmap sampleSize
120 | * 计算bitmap的尺寸
121 | *
122 | * @return
123 | */
124 | public final static int caculateInSampleSize(BitmapFactory.Options options, int rqsW, int rqsH) {
125 | final int height = options.outHeight;
126 | final int width = options.outWidth;
127 | int inSampleSize = 1;
128 | if (rqsW == 0 || rqsH == 0) return 1;
129 | if (height > rqsH || width > rqsW) {
130 | final int heightRatio = Math.round((float) height / (float) rqsH);
131 | final int widthRatio = Math.round((float) width / (float) rqsW);
132 | inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
133 | }
134 | return inSampleSize;
135 | }
136 |
137 | /**
138 | * 得到指定路径图片的options
139 | *
140 | * @param srcPath
141 | * @return Options {@link android.graphics.BitmapFactory.Options}
142 | */
143 | public final static BitmapFactory.Options getBitmapOptions(String srcPath) {
144 | BitmapFactory.Options options = new BitmapFactory.Options();
145 | options.inJustDecodeBounds = true;
146 | BitmapFactory.decodeFile(srcPath, options);
147 | return options;
148 | }
149 |
150 |
151 | /**
152 | * get the orientation of the bitmap {@link android.media.ExifInterface}
153 | * 获取bitmap的方向信息
154 | *
155 | * @param path
156 | * @return
157 | */
158 | public final static int getDegress(String path) {
159 | int degree = 0;
160 | try {
161 | ExifInterface exifInterface = new ExifInterface(path);
162 | int orientation = exifInterface.getAttributeInt(
163 | ExifInterface.TAG_ORIENTATION,
164 | ExifInterface.ORIENTATION_NORMAL);
165 | switch (orientation) {
166 | case ExifInterface.ORIENTATION_ROTATE_90:
167 | degree = 90;
168 | break;
169 | case ExifInterface.ORIENTATION_ROTATE_180:
170 | degree = 180;
171 | break;
172 | case ExifInterface.ORIENTATION_ROTATE_270:
173 | degree = 270;
174 | break;
175 | }
176 | } catch (IOException e) {
177 | e.printStackTrace();
178 | }
179 | return degree;
180 | }
181 |
182 | public static Observable compressImgInMain(final String srcPath, final int rqsW, final int rqsH) {
183 | return
184 | Observable.create(new Observable.OnSubscribe() {
185 | @Override
186 | public void call(Subscriber super byte[]> subscriber) {
187 | Bitmap bitmap = compressBitmap(srcPath, rqsW, rqsH);
188 | int degree = getDegress(srcPath);
189 | try {
190 | if (degree != 0) bitmap = rotateBitmap(bitmap, degree);
191 | ByteArrayOutputStream bos = new ByteArrayOutputStream();
192 | bitmap.compress(Bitmap.CompressFormat.PNG, 70, bos);
193 | byte[] bytes = bos.toByteArray();
194 | subscriber.onNext(bytes);
195 | } catch (Exception e) {
196 | e.printStackTrace();
197 | }
198 | }
199 | });
200 | }
201 | }
202 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wxxiaomi/ming/webviewcachemodule/common/util/DiskCache.java:
--------------------------------------------------------------------------------
1 | package com.wxxiaomi.ming.webviewcachemodule.common.util;
2 |
3 | import android.content.Context;
4 | import android.content.pm.PackageInfo;
5 | import android.content.pm.PackageManager;
6 | import android.os.Environment;
7 | import android.util.Log;
8 |
9 | import com.jakewharton.disklrucache.DiskLruCache;
10 | import com.wxxiaomi.ming.webviewcachemodule.TAG;
11 |
12 | import java.io.BufferedInputStream;
13 | import java.io.BufferedOutputStream;
14 | import java.io.ByteArrayInputStream;
15 | import java.io.ByteArrayOutputStream;
16 | import java.io.File;
17 | import java.io.IOException;
18 | import java.io.InputStream;
19 | import java.io.OutputStream;
20 | import java.security.MessageDigest;
21 | import java.security.NoSuchAlgorithmException;
22 |
23 | import rx.Observable;
24 | import rx.Subscriber;
25 | import rx.schedulers.Schedulers;
26 |
27 | /**
28 | * Created by 12262 on 2016/11/24.
29 | * DiskLruCache
30 | */
31 | public class DiskCache {
32 | private Context context;
33 | DiskLruCache mDiskLruCache = null;
34 | public static DiskCache INSTANCE;
35 |
36 | private DiskCache() {
37 | }
38 |
39 | public static DiskCache getInstance() {
40 | if (INSTANCE == null) {
41 | synchronized (DiskCache.class) {
42 | INSTANCE = new DiskCache();
43 | }
44 | }
45 | return INSTANCE;
46 | }
47 |
48 |
49 | public void open(Context context) {
50 | try {
51 | this.context = context;
52 | File cacheDir = getDiskCacheDir(context, "bitmap");
53 | if (!cacheDir.exists()) {
54 | cacheDir.mkdirs();
55 | }
56 | //第一个参数指定的是数据的缓存地址,
57 | // 第二个参数指定当前应用程序的版本号,
58 | // 第三个参数指定同一个key可以对应多少个缓存文件,基本都是传1,
59 | // 第四个参数指定最多可以缓存多少字节的数据。
60 | mDiskLruCache = DiskLruCache.open(cacheDir, getAppVersion(context), 1, 10 * 1024 * 1024);
61 | } catch (IOException e) {
62 | e.printStackTrace();
63 | }
64 | }
65 |
66 | public Observable toDiskCache(final String path, final byte[] obj) {
67 | return Observable.create(new Observable.OnSubscribe() {
68 | @Override
69 | public void call(Subscriber super byte[]> subscriber) {
70 | String key = hashKeyForDisk(path);
71 |
72 | BufferedInputStream in = null;
73 | BufferedOutputStream out = null;
74 | try {
75 | DiskLruCache.Snapshot snapshot1 = mDiskLruCache.get(key);
76 | if (snapshot1 == null) {
77 | Log.i(TAG.TAG, "将数据存入缓存");
78 | DiskLruCache.Editor editor = mDiskLruCache.edit(key);
79 |
80 | in = new BufferedInputStream(new ByteArrayInputStream(obj), 8 * 1024);
81 | OutputStream outputStream = editor.newOutputStream(0);
82 | out = new BufferedOutputStream(outputStream, 8 * 1024);
83 | int b;
84 | while ((b = in.read()) != -1) {
85 | out.write(b);
86 | }
87 | editor.commit();
88 | } else {
89 | Log.i(TAG.TAG, "数据已存在缓存中,不需要再次插入");
90 | }
91 | subscriber.onNext(obj);
92 | subscriber.onCompleted();
93 |
94 | } catch (IOException e) {
95 | e.printStackTrace();
96 | subscriber.onError(e);
97 | } finally {
98 | try {
99 | if (out != null) {
100 | out.close();
101 | }
102 | if (in != null) {
103 | in.close();
104 | }
105 | } catch (final IOException e) {
106 | e.printStackTrace();
107 | }
108 | }
109 | }
110 | })
111 | .subscribeOn(Schedulers.newThread())
112 | ;
113 | }
114 |
115 |
116 | public Observable getDiskCache(final String url) {
117 | return Observable.create(new Observable.OnSubscribe() {
118 | @Override
119 | public void call(Subscriber super byte[]> subscriber) {
120 | try {
121 | Log.i(TAG.TAG, "从硬盘取数据的线程.currentThread:" + Thread.currentThread().getName());
122 | String key = hashKeyForDisk(url);
123 | DiskLruCache.Snapshot snapShot = mDiskLruCache.get(key);
124 | if (snapShot != null) {
125 | Log.i(TAG.TAG, "从硬盘取到缓存");
126 | InputStream is = snapShot.getInputStream(0);
127 | ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
128 | byte[] buff = new byte[100];
129 | int rc = 0;
130 | while ((rc = is.read(buff, 0, 100)) > 0) {
131 | swapStream.write(buff, 0, rc);
132 | }
133 | byte[] in2b = swapStream.toByteArray();
134 | subscriber.onNext(in2b);
135 | } else {
136 | subscriber.onNext(null);
137 | }
138 | subscriber.onCompleted();
139 | } catch (Exception e) {
140 | e.printStackTrace();
141 | subscriber.onError(null);
142 | }
143 | }
144 | })
145 | .subscribeOn(Schedulers.newThread())
146 | ;
147 | }
148 |
149 | /**
150 | * 获取版本号
151 | *
152 | * @param context
153 | * @return
154 | */
155 | public int getAppVersion(Context context) {
156 | try {
157 | PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
158 | return info.versionCode;
159 | } catch (PackageManager.NameNotFoundException e) {
160 | e.printStackTrace();
161 | }
162 | return 1;
163 | }
164 |
165 |
166 | /**
167 | * 获取缓存位置
168 | *
169 | * @param context
170 | * @param uniqueName
171 | * @return
172 | */
173 | public File getDiskCacheDir(Context context, String uniqueName) {
174 | String cachePath;
175 | if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
176 | || !Environment.isExternalStorageRemovable()) {
177 | cachePath = context.getExternalCacheDir().getPath();
178 | } else {
179 | cachePath = context.getCacheDir().getPath();
180 | }
181 | return new File(cachePath + File.separator + uniqueName);
182 | }
183 |
184 | /**
185 | * 用来将字符串进行MD5编码
186 | *
187 | * @param key
188 | * @return
189 | */
190 | public String hashKeyForDisk(String key) {
191 | String cacheKey;
192 | try {
193 | final MessageDigest mDigest = MessageDigest.getInstance("MD5");
194 | mDigest.update(key.getBytes());
195 | cacheKey = bytesToHexString(mDigest.digest());
196 | } catch (NoSuchAlgorithmException e) {
197 | cacheKey = String.valueOf(key.hashCode());
198 | }
199 | return cacheKey;
200 | }
201 |
202 | private String bytesToHexString(byte[] bytes) {
203 | StringBuilder sb = new StringBuilder();
204 | for (int i = 0; i < bytes.length; i++) {
205 | String hex = Integer.toHexString(0xFF & bytes[i]);
206 | if (hex.length() == 1) {
207 | sb.append('0');
208 | }
209 | sb.append(hex);
210 | }
211 | return sb.toString();
212 | }
213 |
214 | public Observable getDiskCacheInMain(final String path) {
215 | return Observable.create(new Observable.OnSubscribe() {
216 | @Override
217 | public void call(Subscriber super byte[]> subscriber) {
218 | try {
219 | Log.i("cache", "从硬盘取数据的线程.currentThread:" + Thread.currentThread().getName());
220 | String key = hashKeyForDisk(path);
221 | DiskLruCache.Snapshot snapShot = mDiskLruCache.get(key);
222 | if (snapShot != null) {
223 | InputStream is = snapShot.getInputStream(0);
224 | ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
225 | byte[] buff = new byte[100];
226 | int rc = 0;
227 | while ((rc = is.read(buff, 0, 100)) > 0) {
228 | swapStream.write(buff, 0, rc);
229 | }
230 | byte[] in2b = swapStream.toByteArray();
231 | subscriber.onNext(in2b);
232 | } else {
233 | subscriber.onNext(null);
234 | }
235 | subscriber.onCompleted();
236 | } catch (Exception e) {
237 | e.printStackTrace();
238 | subscriber.onError(null);
239 | }
240 | }
241 | });
242 | }
243 |
244 | public Observable toDiskCacheInMain(final String path, final byte[] obj) {
245 | return Observable.create(new Observable.OnSubscribe() {
246 | @Override
247 | public void call(Subscriber super byte[]> subscriber) {
248 | String key = hashKeyForDisk(path);
249 |
250 | BufferedInputStream in = null;
251 | BufferedOutputStream out = null;
252 | try {
253 | DiskLruCache.Snapshot snapshot1 = mDiskLruCache.get(key);
254 | if (snapshot1 == null) {
255 | Log.i("wang", "存入缓存");
256 | DiskLruCache.Editor editor = mDiskLruCache.edit(key);
257 |
258 | in = new BufferedInputStream(new ByteArrayInputStream(obj), 8 * 1024);
259 | OutputStream outputStream = editor.newOutputStream(0);
260 | out = new BufferedOutputStream(outputStream, 8 * 1024);
261 | int b;
262 | while ((b = in.read()) != -1) {
263 | out.write(b);
264 | }
265 | editor.commit();
266 | } else {
267 | Log.i("wang", "已经存在,不用存入缓存了");
268 | }
269 | subscriber.onNext(obj);
270 | subscriber.onCompleted();
271 |
272 | } catch (IOException e) {
273 | e.printStackTrace();
274 | subscriber.onError(e);
275 | } finally {
276 | try {
277 | if (out != null) {
278 | out.close();
279 | }
280 | if (in != null) {
281 | in.close();
282 | }
283 | } catch (final IOException e) {
284 | e.printStackTrace();
285 | }
286 | }
287 | }
288 | })
289 | ;
290 | }
291 | }
292 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wxxiaomi/ming/webviewcachemodule/version_1/Version_1_Activity.java:
--------------------------------------------------------------------------------
1 | package com.wxxiaomi.ming.webviewcachemodule.version_1;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 | import android.util.Log;
6 | import android.view.View;
7 | import android.widget.Button;
8 |
9 | import com.wxxiaomi.ming.webviewcachemodule.R;
10 | import com.wxxiaomi.ming.webviewcachemodule.common.BaseWebActivity;
11 | import com.wxxiaomi.ming.webviewcachemodule.common.PicTakeUtil;
12 | import com.yancy.gallerypick.inter.IHandlerCallBack;
13 |
14 | import java.util.List;
15 |
16 | /**
17 | * Created by Mr.W on ${DATE}.
18 | * E-maiil:122627018@qq.com
19 | * github:https://github.com/122627018
20 | * 模拟从本地取得照片地址,并在webview中加载
21 | */
22 | public class Version_1_Activity extends BaseWebActivity {
23 | private Button btn;
24 | private PicTakeUtil util;
25 | private String path = "/storage/sdcard0/demo.jpg";
26 |
27 | @Override
28 | protected int initViewAndReutrnWebViewId(Bundle savedInstanceState) {
29 | setContentView(R.layout.activity_version_1_);
30 | btn = (Button) findViewById(R.id.btn);
31 | btn.setOnClickListener(new View.OnClickListener() {
32 | @Override
33 | public void onClick(View view) {
34 | // adapterH5();
35 | takePicture();
36 | }
37 | });
38 | return R.id.web_view;
39 | }
40 |
41 | private void takePicture() {
42 | util = new PicTakeUtil(this);
43 | util.takePicture(new IHandlerCallBack() {
44 | @Override
45 | public void onStart() {
46 |
47 | }
48 |
49 | @Override
50 | public void onSuccess(List photoList) {
51 | for(String item : photoList){
52 | Log.i("wang","item:"+item);
53 | }
54 | adapterH5Data(photoList);
55 |
56 | }
57 |
58 | @Override
59 | public void onCancel() {
60 |
61 | }
62 |
63 | @Override
64 | public void onFinish() {
65 |
66 | }
67 |
68 | @Override
69 | public void onError() {
70 |
71 | }
72 | });
73 | }
74 |
75 | private void adapterH5Data(List imgPaths){
76 | String result = "";
77 | for(int i=0;i";
79 | }
80 | Log.i("wang","result:"+result);
81 | mWebView.callHandler("adapter",result,null);
82 | }
83 |
84 | private void adapterH5(){
85 | String result = "";
86 | for(int i=0;i<20;i++){
87 | result += "
";
88 | }
89 | Log.i("wang","result:"+result);
90 | mWebView.callHandler("adapter",result,null);
91 | }
92 |
93 | @Override
94 | protected void initWebView() {
95 | mWebView.loadUrl("file:///android_asset/test1.html");
96 | mWebView.getSettings().setAllowFileAccess(true);
97 | // util = new PicTakeUtil(this);
98 | }
99 |
100 | @Override
101 | protected void onDestroy() {
102 | super.onDestroy();
103 |
104 | mWebView.removeAllViews();
105 | mWebView.destroy();
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wxxiaomi/ming/webviewcachemodule/version_2/Version_2_Activity.java:
--------------------------------------------------------------------------------
1 | package com.wxxiaomi.ming.webviewcachemodule.version_2;
2 |
3 | import android.os.Bundle;
4 | import android.util.Base64;
5 | import android.util.Log;
6 | import android.view.View;
7 | import android.widget.Button;
8 | import android.widget.TextView;
9 |
10 | import com.wxxiaomi.ming.webviewcachemodule.R;
11 | import com.wxxiaomi.ming.webviewcachemodule.common.BaseWebActivity;
12 | import com.wxxiaomi.ming.webviewcachemodule.common.PicTakeUtil;
13 | import com.yancy.gallerypick.inter.IHandlerCallBack;
14 |
15 | import java.io.ByteArrayOutputStream;
16 | import java.io.File;
17 | import java.io.FileInputStream;
18 | import java.io.FileNotFoundException;
19 | import java.io.IOException;
20 | import java.util.List;
21 |
22 | import rx.Observable;
23 | import rx.Subscriber;
24 | import rx.android.schedulers.AndroidSchedulers;
25 | import rx.functions.Action1;
26 | import rx.schedulers.Schedulers;
27 |
28 | /**
29 | * Created by Mr.W on ${DATE}.
30 | * E-maiil:122627018@qq.com
31 | * github:https://github.com/122627018
32 | * 模拟从本地取得照片地址,并在webview中加载
33 | */
34 | public class Version_2_Activity extends BaseWebActivity {
35 |
36 | private Button btn;
37 | private PicTakeUtil util;
38 | private TextView tv;
39 | private int size = 0;
40 |
41 |
42 | @Override
43 | protected int initViewAndReutrnWebViewId(Bundle savedInstanceState) {
44 | setContentView(R.layout.activity_version_2_);
45 | tv = (TextView) findViewById(R.id.tv);
46 | tv.setText("建议不要选择太多相片");
47 | btn = (Button) findViewById(R.id.btn);
48 | btn.setOnClickListener(new View.OnClickListener() {
49 | @Override
50 | public void onClick(View view) {
51 | takePicture();
52 | }
53 | });
54 | return R.id.web_view;
55 | }
56 |
57 | private void takePicture() {
58 | tv.setText("正在编码");
59 | util = new PicTakeUtil(this);
60 | util.takePicture(new IHandlerCallBack() {
61 | @Override
62 | public void onStart() {
63 | }
64 | @Override
65 | public void onSuccess(List photoList) {
66 | adapterH5Data(photoList);
67 | }
68 | @Override
69 | public void onCancel() {
70 |
71 | }
72 | @Override
73 | public void onFinish() {
74 |
75 | }
76 | @Override
77 | public void onError() {
78 |
79 | }
80 | });
81 | }
82 |
83 | /**
84 | * 在这里必须使用多线程,因为base64对图片进行编码非常耗时,
85 | * 所以必须在子线程并且多线程处理每张图片的编码
86 | * RxJava的线程切换(这里暂时还没有使用多线程)
87 | * @param imgPaths
88 | */
89 | private void adapterH5Data(final List imgPaths) {
90 | Observable.create(new Observable.OnSubscribe() {
91 | @Override
92 | public void call(Subscriber super String> subscriber) {
93 | for (int i = 0; i < imgPaths.size(); i++) {
94 | String result = "";
95 | String item = imgPaths.get(i);
96 | Log.i("wang","item:"+item);
97 | String s = Base64.encodeToString(getBytes(item), Base64.NO_WRAP);
98 | result += "
";
99 | subscriber.onNext(result);
100 | }
101 | }
102 | })
103 | .subscribeOn(Schedulers.io())
104 | .observeOn(AndroidSchedulers.mainThread())
105 | .subscribe(new Action1() {
106 | @Override
107 | public void call(String s) {
108 | size++;
109 | tv.setText("编码完成:"+size+"张");
110 | mWebView.callHandler("adapter", s, null);
111 | }
112 | })
113 | ;
114 | }
115 |
116 |
117 | @Override
118 | protected void initWebView() {
119 | mWebView.loadUrl("file:///android_asset/test1.html");
120 | mWebView.getSettings().setAllowFileAccess(true);
121 |
122 | }
123 |
124 | /**
125 | * 获得指定文件的byte数组
126 | */
127 | private byte[] getBytes(String filePath) {
128 | byte[] buffer = null;
129 | try {
130 | File file = new File(filePath);
131 | FileInputStream fis = new FileInputStream(file);
132 | ByteArrayOutputStream bos = new ByteArrayOutputStream(1000);
133 | byte[] b = new byte[1000];
134 | int n;
135 | while ((n = fis.read(b)) != -1) {
136 | bos.write(b, 0, n);
137 | }
138 | fis.close();
139 | bos.close();
140 | buffer = bos.toByteArray();
141 | } catch (FileNotFoundException e) {
142 | e.printStackTrace();
143 | } catch (IOException e) {
144 | e.printStackTrace();
145 | }
146 | return buffer;
147 | }
148 |
149 | }
150 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wxxiaomi/ming/webviewcachemodule/version_3/Compress_Cache_Base64_Activity.java:
--------------------------------------------------------------------------------
1 | package com.wxxiaomi.ming.webviewcachemodule.version_3;
2 |
3 | import android.os.Bundle;
4 | import android.util.Base64;
5 | import android.util.Log;
6 | import android.view.View;
7 | import android.widget.Button;
8 |
9 | import com.wxxiaomi.ming.webviewcachemodule.R;
10 | import com.wxxiaomi.ming.webviewcachemodule.TAG;
11 | import com.wxxiaomi.ming.webviewcachemodule.common.BaseWebActivity;
12 | import com.wxxiaomi.ming.webviewcachemodule.common.PicTakeUtil;
13 | import com.wxxiaomi.ming.webviewcachemodule.common.util.CacheEngine;
14 | import com.wxxiaomi.ming.webviewcachemodule.common.util.DiskCache;
15 | import com.yancy.gallerypick.inter.IHandlerCallBack;
16 |
17 | import java.util.List;
18 |
19 | import rx.Observable;
20 | import rx.Subscriber;
21 | import rx.android.schedulers.AndroidSchedulers;
22 | import rx.functions.Action1;
23 | import rx.functions.Func1;
24 | import rx.schedulers.Schedulers;
25 |
26 | /**
27 | * Created by Mr.W on ${DATE}.
28 | * E-maiil:122627018@qq.com
29 | * github:https://github.com/122627018
30 | * 使用压缩+缓存+base64编码完成(多线程工作)
31 | */
32 | public class Compress_Cache_Base64_Activity extends BaseWebActivity {
33 | private Button btn;
34 | private PicTakeUtil util;
35 |
36 |
37 | @Override
38 | protected int initViewAndReutrnWebViewId(Bundle savedInstanceState) {
39 | setContentView(R.layout.activity_compress__cache__base64_);
40 | setContentView(R.layout.activity_version_2_);
41 | btn = (Button) findViewById(R.id.btn);
42 | btn.setOnClickListener(new View.OnClickListener() {
43 | @Override
44 | public void onClick(View view) {
45 | takePicture();
46 | }
47 | });
48 | DiskCache.getInstance().open(getApplicationContext());
49 | return R.id.web_view;
50 | }
51 |
52 | @Override
53 | protected void initWebView() {
54 | mWebView.loadUrl("file:///android_asset/test1.html");
55 | mWebView.getSettings().setAllowFileAccess(true);
56 | }
57 |
58 | private void takePicture() {
59 | util = new PicTakeUtil(this);
60 | util.takePicture(new IHandlerCallBack() {
61 | @Override
62 | public void onStart() {
63 | }
64 |
65 | @Override
66 | public void onSuccess(List photoList) {
67 | adapter(photoList);
68 | }
69 |
70 | @Override
71 | public void onCancel() {
72 |
73 | }
74 |
75 | @Override
76 | public void onFinish() {
77 |
78 | }
79 |
80 | @Override
81 | public void onError() {
82 |
83 | }
84 | });
85 | }
86 |
87 | private void adapter(List photoList) {
88 | CacheEngine.getInstance().getLocalImgsMany2(photoList)
89 | .flatMap(new Func1>() {
90 | @Override
91 | public Observable call(byte[] bytes) {
92 | return byte2base64(bytes);
93 | }
94 | })
95 | .observeOn(AndroidSchedulers.mainThread())
96 | .subscribe(new Action1() {
97 | @Override
98 | public void call(String s) {
99 | sendToH5(s);
100 | }
101 | });
102 | }
103 |
104 | private void sendToH5(String s) {
105 | String result = "
";
106 | mWebView.callHandler("adapter",result,null);
107 | }
108 |
109 | public Observable byte2base64(final byte[] bytes) {
110 | return
111 | Observable.create(new Observable.OnSubscribe() {
112 | @Override
113 | public void call(Subscriber super String> subscriber) {
114 | Log.i(com.wxxiaomi.ming.webviewcachemodule.TAG.TAG,"我在编码,我的线程:"+Thread.currentThread().getName());
115 | String s = Base64.encodeToString(bytes, Base64.NO_WRAP);
116 | subscriber.onNext(s);
117 | }
118 | })
119 | .subscribeOn(Schedulers.newThread())
120 | ;
121 | }
122 |
123 | }
124 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wxxiaomi/ming/webviewcachemodule/version_4/StreamActivity.java:
--------------------------------------------------------------------------------
1 | package com.wxxiaomi.ming.webviewcachemodule.version_4;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 | import android.util.Log;
6 | import android.view.View;
7 | import android.webkit.WebResourceResponse;
8 | import android.webkit.WebView;
9 | import android.widget.Button;
10 |
11 | import com.github.lzyzsd.jsbridge.BridgeHandler;
12 | import com.github.lzyzsd.jsbridge.BridgeWebView;
13 | import com.github.lzyzsd.jsbridge.BridgeWebViewClient;
14 | import com.github.lzyzsd.jsbridge.CallBackFunction;
15 | import com.wxxiaomi.ming.webviewcachemodule.R;
16 | import com.wxxiaomi.ming.webviewcachemodule.common.PicTakeUtil;
17 | import com.wxxiaomi.ming.webviewcachemodule.common.util.CacheEngine;
18 | import com.wxxiaomi.ming.webviewcachemodule.common.util.DiskCache;
19 | import com.yancy.gallerypick.inter.IHandlerCallBack;
20 |
21 | import java.io.ByteArrayInputStream;
22 | import java.util.List;
23 |
24 | import rx.functions.Action1;
25 |
26 | public class StreamActivity extends AppCompatActivity {
27 | protected BridgeWebView mWebView;
28 | private Button btn;
29 | private PicTakeUtil util;
30 |
31 | @Override
32 | protected void onCreate(Bundle savedInstanceState) {
33 | super.onCreate(savedInstanceState);
34 | setContentView(R.layout.activity_stream);
35 | mWebView = (BridgeWebView) findViewById(R.id.web_view);
36 | mWebView.setWebViewClient(new MyWebViewClient(mWebView));
37 | mWebView.loadUrl("file:///android_asset/test1.html");
38 | mWebView.getSettings().setAllowFileAccess(true);
39 | btn = (Button) findViewById(R.id.btn);
40 | btn.setOnClickListener(new View.OnClickListener() {
41 | @Override
42 | public void onClick(View view) {
43 | takePicture();
44 | }
45 | });
46 | DiskCache.getInstance().open(getApplicationContext());
47 | }
48 |
49 | private void takePicture() {
50 | util = new PicTakeUtil(this);
51 | util.takePicture(new IHandlerCallBack() {
52 | @Override
53 | public void onStart() {
54 | }
55 |
56 | @Override
57 | public void onSuccess(List photoList) {
58 | adapter(photoList);
59 | }
60 |
61 | @Override
62 | public void onCancel() {
63 |
64 | }
65 |
66 | @Override
67 | public void onFinish() {
68 |
69 | }
70 |
71 | @Override
72 | public void onError() {
73 |
74 | }
75 | });
76 | }
77 |
78 | private void adapter(List photoList) {
79 | String result = "";
80 | for(int i=0;i";
82 | }
83 | mWebView.callHandler("adapter",result,null);
84 | }
85 |
86 |
87 | class MyWebViewClient extends BridgeWebViewClient {
88 | public MyWebViewClient(BridgeWebView webView) {
89 | super(webView);
90 | }
91 | @Override
92 | public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
93 | String key = "http://localhost";
94 | final WebResourceResponse[] response = {null};
95 | if(url.contains(key)){
96 | String imgPath = url.replace(key,"");
97 | CacheEngine.getInstance().getLocalImgInMain(imgPath)
98 | .subscribe(new Action1() {
99 | @Override
100 | public void call(byte[] bytes) {
101 | response[0] = new WebResourceResponse("image/png", "UTF-8", new ByteArrayInputStream(bytes));
102 | }
103 | });
104 | return response[0];
105 | }else {
106 | return super.shouldInterceptRequest(view, url);
107 | }
108 | }
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_compress__cache__base64_.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
18 |
23 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
19 |
24 |
29 |
34 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_stream.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
18 |
23 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_version_1_.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
18 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_version_2_.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
18 |
23 |
27 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | WebViewCacheModule
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/wxxiaomi/ming/webviewcachemodule/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.wxxiaomi.ming.webviewcachemodule;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.2.1'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/gallerypick/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/gallerypick/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | group='com.github.Yancy'
4 |
5 | android {
6 | compileSdkVersion 25
7 | buildToolsVersion '25.0.0'
8 | resourcePrefix "GalleryPick" //这个随便填
9 |
10 | defaultConfig {
11 | minSdkVersion 16
12 | targetSdkVersion 12
13 | versionCode 1
14 | versionName "1.0.0"
15 | }
16 |
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 |
24 | lintOptions {
25 | abortOnError false
26 | }
27 | }
28 |
29 | dependencies {
30 | compile 'com.android.support:appcompat-v7:25.0.0'
31 | compile 'com.android.support:recyclerview-v7:25.0.0'
32 | compile 'com.yalantis:ucrop:2.2.0'
33 | }
34 |
35 | // 指定编码
36 | tasks.withType(JavaCompile) {
37 | options.encoding = "UTF-8"
38 | }
39 |
40 | // 打包源码
41 | task sourcesJar(type: Jar) {
42 | from android.sourceSets.main.java.srcDirs
43 | classifier = 'sources'
44 | }
45 | task javadoc(type: Javadoc) {
46 | options.encoding = "utf-8"
47 | source = android.sourceSets.main.java.srcDirs
48 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
49 | }
50 | task javadocJar(type: Jar, dependsOn: javadoc) {
51 | classifier = 'javadoc'
52 | from javadoc.destinationDir
53 | }
54 | artifacts {
55 | archives javadocJar
56 | archives sourcesJar
57 | }
--------------------------------------------------------------------------------
/gallerypick/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\Tools\Android-SDK\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/gallerypick/src/androidTest/java/com/yancy/gallerypick/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.yancy.gallerypick;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/gallerypick/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
12 |
13 |
18 |
19 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/gallerypick/src/main/java/com/yancy/gallerypick/activity/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.yancy.gallerypick.activity;
2 |
3 | import android.content.res.Configuration;
4 | import android.content.res.Resources;
5 | import android.os.Bundle;
6 | import android.support.v7.app.AppCompatActivity;
7 |
8 | /**
9 | * 自定义 Activity 所有 Activity 继承此类 方便管理
10 | * Created by Yancy on 2016/1/27.
11 | */
12 | public class BaseActivity extends AppCompatActivity {
13 |
14 | private final static String TAG = "BaseActivity";
15 |
16 | @Override
17 | protected void onCreate(Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | }
20 |
21 | @Override
22 | protected void onStart() {
23 | super.onStart();
24 | }
25 |
26 | @Override
27 | protected void onResume() {
28 | super.onResume();
29 | }
30 |
31 | @Override
32 | protected void onPause() {
33 | super.onPause();
34 | }
35 |
36 | @Override
37 | protected void onRestart() {
38 | super.onRestart();
39 | }
40 |
41 | @Override
42 | protected void onStop() {
43 | super.onStop();
44 | }
45 |
46 | @Override
47 | protected void onDestroy() {
48 | super.onDestroy();
49 | }
50 |
51 | /**
52 | * 防止字体随手机系统的字体变大而变大
53 | */
54 | @Override
55 | public Resources getResources() {
56 | Resources res = super.getResources();
57 | Configuration config = new Configuration();
58 | config.setToDefaults();
59 | res.updateConfiguration(config, res.getDisplayMetrics());
60 | return res;
61 | }
62 |
63 | }
64 | /*
65 | * ┏┓ ┏┓
66 | * ┏┛┻━━━┛┻┓
67 | * ┃ ┃
68 | * ┃ ━ ┃
69 | * ┃ ┳┛ ┗┳ ┃
70 | * ┃ ┃
71 | * ┃ ┻ ┃
72 | * ┃ ┃
73 | * ┗━┓ ┏━┛
74 | * ┃ ┃
75 | * ┃ ┃
76 | * ┃ ┗━━━┓
77 | * ┃ ┣┓
78 | * ┃ ┏┛
79 | * ┗┓┓┏━┳┓┏┛
80 | * ┃┫┫ ┃┫┫
81 | * ┗┻┛ ┗┻┛
82 | * 神兽保佑
83 | * 代码无BUG!
84 | */
--------------------------------------------------------------------------------
/gallerypick/src/main/java/com/yancy/gallerypick/activity/GalleryPickActivity.java:
--------------------------------------------------------------------------------
1 | package com.yancy.gallerypick.activity;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.database.Cursor;
7 | import android.net.Uri;
8 | import android.os.Bundle;
9 | import android.provider.MediaStore;
10 | import android.support.v4.app.LoaderManager;
11 | import android.support.v4.content.CursorLoader;
12 | import android.support.v4.content.Loader;
13 | import android.support.v7.widget.GridLayoutManager;
14 | import android.support.v7.widget.RecyclerView;
15 | import android.util.Log;
16 | import android.view.KeyEvent;
17 | import android.view.View;
18 | import android.widget.LinearLayout;
19 | import android.widget.TextView;
20 | import android.widget.Toast;
21 |
22 | import com.yalantis.ucrop.UCrop;
23 | import com.yancy.gallerypick.R;
24 | import com.yancy.gallerypick.adapter.FolderAdapter;
25 | import com.yancy.gallerypick.adapter.PhotoAdapter;
26 | import com.yancy.gallerypick.bean.FolderInfo;
27 | import com.yancy.gallerypick.bean.PhotoInfo;
28 | import com.yancy.gallerypick.config.GalleryConfig;
29 | import com.yancy.gallerypick.config.GalleryPick;
30 | import com.yancy.gallerypick.inter.IHandlerCallBack;
31 | import com.yancy.gallerypick.utils.FileUtils;
32 | import com.yancy.gallerypick.utils.UCropUtils;
33 | import com.yancy.gallerypick.utils.UIUtils;
34 | import com.yancy.gallerypick.widget.FolderListPopupWindow;
35 |
36 | import java.io.File;
37 | import java.util.ArrayList;
38 | import java.util.List;
39 |
40 | /**
41 | * 图片选择页面
42 | * Created by Yancy on 2016/1/26.
43 | */
44 | public class GalleryPickActivity extends BaseActivity {
45 |
46 | private Context mContext = null;
47 | private Activity mActivity = null;
48 | private final static String TAG = "GalleryPickActivity";
49 |
50 | private ArrayList resultPhoto;
51 |
52 | private TextView tvFinish; // 完成按钮
53 | private TextView tvGalleryFolder; // 文件夹按钮
54 | private LinearLayout btnGalleryPickBack; // 返回按钮
55 | private RecyclerView rvGalleryImage; // 图片列表
56 |
57 | private PhotoAdapter photoAdapter; // 图片适配器
58 | private FolderAdapter folderAdapter; // 文件夹适配器
59 |
60 |
61 | private List folderInfoList = new ArrayList<>(); // 本地文件夹信息List
62 | private List photoInfoList = new ArrayList<>(); // 本地图片信息List
63 |
64 | private static final int LOADER_ALL = 0; // 获取所有图片
65 | private static final int LOADER_CATEGORY = 1; // 获取某个文件夹中的所有图片
66 |
67 | private boolean hasFolderScan = false; // 是否扫描过
68 |
69 | private GalleryConfig galleryConfig; // GalleryPick 配置器
70 |
71 | private static final int REQUEST_CAMERA = 100; // 设置拍摄照片的 REQUEST_CODE
72 |
73 | private IHandlerCallBack mHandlerCallBack; // GalleryPick 生命周期接口
74 |
75 | private FolderListPopupWindow folderListPopupWindow; // 文件夹选择弹出框
76 |
77 | private LoaderManager.LoaderCallbacks mLoaderCallback;
78 |
79 |
80 | @Override
81 | protected void onCreate(Bundle savedInstanceState) {
82 | super.onCreate(savedInstanceState);
83 | setContentView(R.layout.gallery_main);
84 |
85 | mContext = this;
86 | mActivity = this;
87 |
88 | UIUtils.hideTitleBar(mActivity, R.id.ll_gallery_pick_main);
89 |
90 |
91 | galleryConfig = GalleryPick.getInstance().getGalleryConfig();
92 | Intent intent = getIntent();
93 | boolean isOpenCamera = intent.getBooleanExtra("isOpenCamera", false);
94 | if (isOpenCamera || galleryConfig.isOpenCamera()) {
95 | galleryConfig.getBuilder().isOpenCamera(true).build();
96 | showCameraAction();
97 | }
98 |
99 | initView();
100 | init();
101 | initPhoto();
102 |
103 |
104 | }
105 |
106 | /**
107 | * 初始化视图
108 | */
109 | private void initView() {
110 | tvFinish = (TextView) super.findViewById(R.id.tvFinish);
111 | tvGalleryFolder = (TextView) super.findViewById(R.id.tvGalleryFolder);
112 | btnGalleryPickBack = (LinearLayout) super.findViewById(R.id.btnGalleryPickBack);
113 | rvGalleryImage = (RecyclerView) super.findViewById(R.id.rvGalleryImage);
114 | }
115 |
116 | /**
117 | * 初始化
118 | */
119 | private void init() {
120 | mHandlerCallBack = galleryConfig.getIHandlerCallBack();
121 | mHandlerCallBack.onStart();
122 |
123 | resultPhoto = galleryConfig.getPathList();
124 |
125 | tvFinish.setText(getString(R.string.gallery_finish, resultPhoto.size(), galleryConfig.getMaxSize()));
126 |
127 | btnGalleryPickBack.setOnClickListener(new View.OnClickListener() {
128 | @Override
129 | public void onClick(View v) {
130 | mHandlerCallBack.onCancel();
131 | exit();
132 | }
133 | });
134 |
135 | final GridLayoutManager gridLayoutManager = new GridLayoutManager(mContext, 3);
136 | rvGalleryImage.setLayoutManager(gridLayoutManager);
137 | photoAdapter = new PhotoAdapter(mActivity, mContext, photoInfoList);
138 | photoAdapter.setOnCallBack(new PhotoAdapter.OnCallBack() {
139 | @Override
140 | public void OnClickCamera(List selectPhotoList) {
141 | resultPhoto.clear();
142 | resultPhoto.addAll(selectPhotoList);
143 | showCameraAction();
144 | }
145 |
146 | @Override
147 | public void OnClickPhoto(List selectPhotoList) {
148 | tvFinish.setText(getString(R.string.gallery_finish, selectPhotoList.size(), galleryConfig.getMaxSize()));
149 |
150 | resultPhoto.clear();
151 | resultPhoto.addAll(selectPhotoList);
152 |
153 | if (!galleryConfig.isMultiSelect() && resultPhoto != null && resultPhoto.size() > 0) {
154 | if (galleryConfig.isCrop()) {
155 | cameraTempFile = new File(resultPhoto.get(0));
156 | cropTempFile = FileUtils.getCorpFile(galleryConfig.getFilePath());
157 | UCropUtils.start(mActivity, cameraTempFile, cropTempFile, galleryConfig.getAspectRatioX(), galleryConfig.getAspectRatioY(), galleryConfig.getMaxWidth(), galleryConfig.getMaxHeight());
158 | return;
159 | }
160 | mHandlerCallBack.onSuccess(resultPhoto);
161 | exit();
162 | }
163 |
164 | }
165 |
166 | });
167 | photoAdapter.setSelectPhoto(resultPhoto);
168 | rvGalleryImage.setAdapter(photoAdapter);
169 |
170 |
171 | if (!galleryConfig.isMultiSelect()) {
172 | tvFinish.setVisibility(View.GONE);
173 | }
174 |
175 |
176 | tvFinish.setOnClickListener(new View.OnClickListener() {
177 | @Override
178 | public void onClick(View v) {
179 | if (resultPhoto != null && resultPhoto.size() > 0) {
180 | mHandlerCallBack.onSuccess(resultPhoto);
181 | exit();
182 | }
183 |
184 | }
185 | });
186 |
187 | tvGalleryFolder.setOnClickListener(new View.OnClickListener() {
188 | @Override
189 | public void onClick(View v) {
190 | if (folderListPopupWindow != null && folderListPopupWindow.isShowing()) {
191 | folderListPopupWindow.dismiss();
192 | return;
193 | }
194 | folderListPopupWindow = new FolderListPopupWindow(mActivity, mContext, folderAdapter);
195 | folderListPopupWindow.showAsDropDown(tvGalleryFolder);
196 | }
197 | });
198 |
199 | folderAdapter = new FolderAdapter(mActivity, mContext, folderInfoList);
200 | folderAdapter.setOnClickListener(new FolderAdapter.OnClickListener() {
201 | @Override
202 | public void onClick(FolderInfo folderInfo) {
203 | if (folderInfo == null) {
204 | getSupportLoaderManager().restartLoader(LOADER_ALL, null, mLoaderCallback);
205 | tvGalleryFolder.setText(R.string.gallery_all_folder);
206 | } else {
207 | photoInfoList.clear();
208 | photoInfoList.addAll(folderInfo.photoInfoList);
209 | photoAdapter.notifyDataSetChanged();
210 | tvGalleryFolder.setText(folderInfo.name);
211 | }
212 | folderListPopupWindow.dismiss();
213 | gridLayoutManager.scrollToPosition(0);
214 | }
215 | });
216 |
217 |
218 | }
219 |
220 |
221 | /**
222 | * 初始化配置
223 | */
224 | private void initPhoto() {
225 |
226 | mLoaderCallback = new LoaderManager.LoaderCallbacks() {
227 |
228 | private final String[] IMAGE_PROJECTION = {
229 | MediaStore.Images.Media.DATA,
230 | MediaStore.Images.Media.DISPLAY_NAME,
231 | MediaStore.Images.Media.DATE_ADDED,
232 | MediaStore.Images.Media._ID,
233 | MediaStore.Images.Media.SIZE
234 | };
235 |
236 | @Override
237 | public Loader onCreateLoader(int id, Bundle args) {
238 | if (id == LOADER_ALL) {
239 | return new CursorLoader(mActivity, MediaStore.Images.Media.EXTERNAL_CONTENT_URI, IMAGE_PROJECTION, null, null, IMAGE_PROJECTION[2] + " DESC");
240 | } else if (id == LOADER_CATEGORY) {
241 | return new CursorLoader(mActivity, MediaStore.Images.Media.EXTERNAL_CONTENT_URI, IMAGE_PROJECTION, IMAGE_PROJECTION[0] + " like '%" + args.getString("path") + "%'", null, IMAGE_PROJECTION[2] + " DESC");
242 | }
243 |
244 | return null;
245 | }
246 |
247 | @Override
248 | public void onLoadFinished(Loader loader, Cursor data) {
249 | if (data != null) {
250 | int count = data.getCount();
251 | if (count > 0) {
252 | List tempPhotoList = new ArrayList<>();
253 | data.moveToFirst();
254 | do {
255 | String path = data.getString(data.getColumnIndexOrThrow(IMAGE_PROJECTION[0]));
256 | String name = data.getString(data.getColumnIndexOrThrow(IMAGE_PROJECTION[1]));
257 | long dateTime = data.getLong(data.getColumnIndexOrThrow(IMAGE_PROJECTION[2]));
258 | int size = data.getInt(data.getColumnIndexOrThrow(IMAGE_PROJECTION[4]));
259 | boolean showFlag = size > 1024 * 5; //是否大于5K
260 | PhotoInfo photoInfo = new PhotoInfo(path, name, dateTime);
261 | if (showFlag) {
262 | tempPhotoList.add(photoInfo);
263 | }
264 | if (!hasFolderScan && showFlag) {
265 | File photoFile = new File(path); // 获取图片文件
266 | File folderFile = photoFile.getParentFile(); // 获取图片上一级文件夹
267 |
268 | FolderInfo folderInfo = new FolderInfo();
269 | folderInfo.name = folderFile.getName();
270 | folderInfo.path = folderFile.getAbsolutePath();
271 | folderInfo.photoInfo = photoInfo;
272 | if (!folderInfoList.contains(folderInfo)) { // 判断是否是已经扫描到的图片文件夹
273 | List photoInfoList = new ArrayList<>();
274 | photoInfoList.add(photoInfo);
275 | folderInfo.photoInfoList = photoInfoList;
276 | folderInfoList.add(folderInfo);
277 | } else {
278 | FolderInfo f = folderInfoList.get(folderInfoList.indexOf(folderInfo));
279 | f.photoInfoList.add(photoInfo);
280 | }
281 | }
282 |
283 | } while (data.moveToNext());
284 |
285 | photoInfoList.clear();
286 | photoInfoList.addAll(tempPhotoList);
287 |
288 | List tempPhotoPathList = new ArrayList<>();
289 | for (PhotoInfo photoInfo : photoInfoList) {
290 | tempPhotoPathList.add(photoInfo.path);
291 | }
292 | for (String mPhotoPath : galleryConfig.getPathList()) {
293 | if (!tempPhotoPathList.contains(mPhotoPath)) {
294 | PhotoInfo photoInfo = new PhotoInfo(mPhotoPath, null, 0L);
295 | photoInfoList.add(0, photoInfo);
296 | }
297 | }
298 |
299 |
300 | photoAdapter.notifyDataSetChanged();
301 |
302 | hasFolderScan = true;
303 | }
304 | }
305 | }
306 |
307 | @Override
308 | public void onLoaderReset(Loader loader) {
309 |
310 | }
311 | };
312 | getSupportLoaderManager().restartLoader(LOADER_ALL, null, mLoaderCallback); // 扫描手机中的图片
313 | }
314 |
315 |
316 | private File cameraTempFile;
317 | private File cropTempFile;
318 |
319 | /**
320 | * 选择相机
321 | */
322 | private void showCameraAction() {
323 | // 跳转到系统照相机
324 | Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
325 | if (cameraIntent.resolveActivity(mActivity.getPackageManager()) != null) {
326 | // 设置系统相机拍照后的输出路径
327 | // 创建临时文件
328 | cameraTempFile = FileUtils.createTmpFile(mActivity, galleryConfig.getFilePath());
329 | cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(cameraTempFile));
330 | startActivityForResult(cameraIntent, REQUEST_CAMERA);
331 | } else {
332 | Toast.makeText(mContext, R.string.gallery_msg_no_camera, Toast.LENGTH_SHORT).show();
333 | galleryConfig.getIHandlerCallBack().onError();
334 | }
335 | }
336 |
337 | @Override
338 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
339 | if (requestCode == REQUEST_CAMERA) {
340 | Log.i(TAG, "onActivityResult: " + resultCode);
341 | if (resultCode == RESULT_OK) {
342 | if (cameraTempFile != null) {
343 | if (!galleryConfig.isMultiSelect()) {
344 | resultPhoto.clear();
345 | if (galleryConfig.isCrop()) {
346 | cropTempFile = FileUtils.getCorpFile(galleryConfig.getFilePath());
347 | UCropUtils.start(mActivity, cameraTempFile, cropTempFile, galleryConfig.getAspectRatioX(), galleryConfig.getAspectRatioY(), galleryConfig.getMaxWidth(), galleryConfig.getMaxHeight());
348 | return;
349 | }
350 | }
351 | resultPhoto.add(cameraTempFile.getAbsolutePath());
352 | mHandlerCallBack.onSuccess(resultPhoto);
353 | exit();
354 | }
355 | } else {
356 | if (cameraTempFile != null && cameraTempFile.exists()) {
357 | cameraTempFile.delete();
358 | }
359 | if (galleryConfig.isOpenCamera()) {
360 | exit();
361 | }
362 | }
363 | } else if (resultCode == RESULT_OK && requestCode == UCrop.REQUEST_CROP) {
364 | // final Uri resultUri = UCrop.getOutput(data);
365 | // if (cameraTempFile != null && cameraTempFile.exists()) {
366 | // cameraTempFile.delete();
367 | // }
368 | resultPhoto.clear();
369 | resultPhoto.add(cropTempFile.getAbsolutePath());
370 | mHandlerCallBack.onSuccess(resultPhoto);
371 | exit();
372 | } else if (resultCode == UCrop.RESULT_ERROR) {
373 | galleryConfig.getIHandlerCallBack().onError();
374 | // final Throwable cropError = UCrop.getError(data);
375 | }
376 |
377 | super.onActivityResult(requestCode, resultCode, data);
378 | }
379 |
380 | /**
381 | * 退出
382 | */
383 | private void exit() {
384 | mHandlerCallBack.onFinish();
385 | finish();
386 | }
387 |
388 | /**
389 | * 回退键监听
390 | */
391 | public boolean onKeyDown(int keyCode, KeyEvent event) {
392 | if (keyCode == KeyEvent.KEYCODE_BACK) {
393 | if (folderListPopupWindow != null && folderListPopupWindow.isShowing()) {
394 | folderListPopupWindow.dismiss();
395 | return true;
396 | }
397 | mHandlerCallBack.onCancel();
398 | exit();
399 | }
400 | return true;
401 | }
402 |
403 |
404 | }
405 | /*
406 | * ┏┓ ┏┓
407 | * ┏┛┻━━━┛┻┓
408 | * ┃ ┃
409 | * ┃ ━ ┃
410 | * ┃ ┳┛ ┗┳ ┃
411 | * ┃ ┃
412 | * ┃ ┻ ┃
413 | * ┃ ┃
414 | * ┗━┓ ┏━┛
415 | * ┃ ┃
416 | * ┃ ┃
417 | * ┃ ┗━━━┓
418 | * ┃ ┣┓
419 | * ┃ ┏┛
420 | * ┗┓┓┏━┳┓┏┛
421 | * ┃┫┫ ┃┫┫
422 | * ┗┻┛ ┗┻┛
423 | * 神兽保佑
424 | * 代码无BUG!
425 | */
--------------------------------------------------------------------------------
/gallerypick/src/main/java/com/yancy/gallerypick/adapter/FolderAdapter.java:
--------------------------------------------------------------------------------
1 | package com.yancy.gallerypick.adapter;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.ImageView;
10 | import android.widget.TextView;
11 |
12 | import com.yancy.gallerypick.R;
13 | import com.yancy.gallerypick.bean.FolderInfo;
14 | import com.yancy.gallerypick.config.GalleryConfig;
15 | import com.yancy.gallerypick.config.GalleryPick;
16 | import com.yancy.gallerypick.utils.ScreenUtils;
17 | import com.yancy.gallerypick.widget.GalleryImageView;
18 |
19 | import java.util.List;
20 |
21 | /**
22 | * 文件夹列表适配器
23 | * Created by Yancy on 2016/11/1.
24 | */
25 | public class FolderAdapter extends RecyclerView.Adapter {
26 |
27 | private Context mContext;
28 | private Activity mActivity;
29 | private LayoutInflater mLayoutInflater;
30 | private List result;
31 | private final static String TAG = "FolderAdapter";
32 |
33 | private GalleryConfig galleryConfig = GalleryPick.getInstance().getGalleryConfig();
34 | private int mSelector = 0;
35 | private OnClickListener onClickListener;
36 |
37 | public FolderAdapter(Activity mActivity, Context mContext, List result) {
38 | mLayoutInflater = LayoutInflater.from(mContext);
39 | this.mContext = mContext;
40 | this.mActivity = mActivity;
41 | this.result = result;
42 | }
43 |
44 | @Override
45 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
46 | return new ViewHolder(mLayoutInflater.inflate(R.layout.gallery_item_folder, parent, false));
47 | }
48 |
49 | @Override
50 | public void onBindViewHolder(final ViewHolder holder, int position) {
51 | if (position == 0) {
52 | holder.tvGalleryFolderName.setText(mContext.getString(R.string.gallery_all_folder));
53 | holder.tvGalleryPhotoNum.setText(mContext.getString(R.string.gallery_photo_num, getTotalImageSize()));
54 | if (result.size() > 0) {
55 | galleryConfig.getImageLoader().displayImage(mActivity, mContext, result.get(0).photoInfo.path, holder.ivGalleryFolderImage, ScreenUtils.getScreenWidth(mContext) / 3, ScreenUtils.getScreenWidth(mContext) / 3);
56 | }
57 | holder.itemView.setOnClickListener(new View.OnClickListener() {
58 | @Override
59 | public void onClick(View v) {
60 | mSelector = 0;
61 | onClickListener.onClick(null);
62 | }
63 | });
64 |
65 | if (mSelector == 0) {
66 | holder.ivGalleryIndicator.setVisibility(View.VISIBLE);
67 | } else {
68 | holder.ivGalleryIndicator.setVisibility(View.GONE);
69 | }
70 | return;
71 | }
72 | final FolderInfo folderInfo = result.get(position - 1);
73 | holder.tvGalleryFolderName.setText(folderInfo.name);
74 | holder.tvGalleryPhotoNum.setText(mContext.getString(R.string.gallery_photo_num, folderInfo.photoInfoList.size()));
75 | galleryConfig.getImageLoader().displayImage(mActivity, mContext, folderInfo.photoInfo.path, holder.ivGalleryFolderImage, ScreenUtils.getScreenWidth(mContext) / 3, ScreenUtils.getScreenWidth(mContext) / 3);
76 | holder.itemView.setOnClickListener(new View.OnClickListener() {
77 | @Override
78 | public void onClick(View v) {
79 | mSelector = holder.getAdapterPosition() + 1;
80 | onClickListener.onClick(folderInfo);
81 | }
82 | });
83 |
84 | if (mSelector == holder.getAdapterPosition() + 1) {
85 | holder.ivGalleryIndicator.setVisibility(View.VISIBLE);
86 | } else {
87 | holder.ivGalleryIndicator.setVisibility(View.GONE);
88 | }
89 | }
90 |
91 | @Override
92 | public int getItemCount() {
93 | return result.size() + 1;
94 | }
95 |
96 | public class ViewHolder extends RecyclerView.ViewHolder {
97 | private GalleryImageView ivGalleryFolderImage;
98 | private TextView tvGalleryFolderName;
99 | private TextView tvGalleryPhotoNum;
100 | private ImageView ivGalleryIndicator;
101 |
102 | public ViewHolder(View itemView) {
103 | super(itemView);
104 | ivGalleryFolderImage = (GalleryImageView) itemView.findViewById(R.id.ivGalleryFolderImage);
105 | tvGalleryFolderName = (TextView) itemView.findViewById(R.id.tvGalleryFolderName);
106 | tvGalleryPhotoNum = (TextView) itemView.findViewById(R.id.tvGalleryPhotoNum);
107 | ivGalleryIndicator = (ImageView) itemView.findViewById(R.id.ivGalleryIndicator);
108 | }
109 |
110 | }
111 |
112 |
113 | public interface OnClickListener {
114 | void onClick(FolderInfo folderInfo);
115 | }
116 |
117 | /**
118 | * @return 所有图片数量
119 | */
120 | private int getTotalImageSize() {
121 | int result = 0;
122 | if (this.result != null && this.result.size() > 0) {
123 | for (FolderInfo folderInfo : this.result) {
124 | result += folderInfo.photoInfoList.size();
125 | }
126 | }
127 | return result;
128 | }
129 |
130 | public void setOnClickListener(OnClickListener onClickListener) {
131 | this.onClickListener = onClickListener;
132 | }
133 | }
134 | /*
135 | * ┏┓ ┏┓
136 | * ┏┛┻━━━┛┻┓
137 | * ┃ ┃
138 | * ┃ ━ ┃
139 | * ┃ ┳┛ ┗┳ ┃
140 | * ┃ ┃
141 | * ┃ ┻ ┃
142 | * ┃ ┃
143 | * ┗━┓ ┏━┛
144 | * ┃ ┃
145 | * ┃ ┃
146 | * ┃ ┗━━━┓
147 | * ┃ ┣┓
148 | * ┃ ┏┛
149 | * ┗┓┓┏━┳┓┏┛
150 | * ┃┫┫ ┃┫┫
151 | * ┗┻┛ ┗┻┛
152 | * 神兽保佑
153 | * 代码无BUG!
154 | */
--------------------------------------------------------------------------------
/gallerypick/src/main/java/com/yancy/gallerypick/adapter/MiniPhotoAdapter.java:
--------------------------------------------------------------------------------
1 | package com.yancy.gallerypick.adapter;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.CheckBox;
10 |
11 | import com.yancy.gallerypick.R;
12 | import com.yancy.gallerypick.bean.PhotoInfo;
13 | import com.yancy.gallerypick.config.GalleryConfig;
14 | import com.yancy.gallerypick.config.GalleryPick;
15 | import com.yancy.gallerypick.utils.ScreenUtils;
16 | import com.yancy.gallerypick.widget.GalleryImageView;
17 |
18 | import java.util.List;
19 |
20 | /**
21 | * Mini选择器 适配器
22 | * Created by Yancy on 2016/2/3.
23 | */
24 | public class MiniPhotoAdapter extends RecyclerView.Adapter {
25 |
26 | private Context mContext;
27 | private Activity mActivity;
28 | private LayoutInflater mLayoutInflater;
29 | private List photoInfoList;
30 | private final static String TAG = "MiniPhotoAdapter";
31 |
32 | private GalleryConfig galleryConfig = GalleryPick.getInstance().getGalleryConfig();
33 |
34 | public MiniPhotoAdapter(Context context, List photoInfoList) {
35 | mLayoutInflater = LayoutInflater.from(context);
36 | this.mContext = context;
37 | this.photoInfoList = photoInfoList;
38 | }
39 |
40 | @Override
41 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
42 | return new ViewHolder(mLayoutInflater.inflate(R.layout.gallery_mini_item, parent, false));
43 | }
44 |
45 | @Override
46 | public void onBindViewHolder(ViewHolder holder, int position) {
47 | galleryConfig.getImageLoader().displayImage(mActivity, mContext, photoInfoList.get(position).path, holder.ivPhotoImage, ScreenUtils.getScreenWidth(mContext), ScreenUtils.getScreenWidth(mContext));
48 | }
49 |
50 | @Override
51 | public int getItemCount() {
52 | return photoInfoList.size();
53 | }
54 |
55 | public class ViewHolder extends RecyclerView.ViewHolder {
56 |
57 | private GalleryImageView ivPhotoImage;
58 | private CheckBox chkPhotoSelector;
59 |
60 | public ViewHolder(View itemView) {
61 | super(itemView);
62 | ivPhotoImage = (GalleryImageView) itemView.findViewById(R.id.ivGalleryPhotoImage);
63 | chkPhotoSelector = (CheckBox) itemView.findViewById(R.id.chkGalleryPhotoSelector);
64 | }
65 |
66 | }
67 |
68 | public void setmActivity(Activity mActivity) {
69 | this.mActivity = mActivity;
70 | }
71 | }
72 | /*
73 | * ┏┓ ┏┓
74 | * ┏┛┻━━━┛┻┓
75 | * ┃ ┃
76 | * ┃ ━ ┃
77 | * ┃ ┳┛ ┗┳ ┃
78 | * ┃ ┃
79 | * ┃ ┻ ┃
80 | * ┃ ┃
81 | * ┗━┓ ┏━┛
82 | * ┃ ┃
83 | * ┃ ┃
84 | * ┃ ┗━━━┓
85 | * ┃ ┣┓
86 | * ┃ ┏┛
87 | * ┗┓┓┏━┳┓┏┛
88 | * ┃┫┫ ┃┫┫
89 | * ┗┻┛ ┗┻┛
90 | * 神兽保佑
91 | * 代码无BUG!
92 | */
--------------------------------------------------------------------------------
/gallerypick/src/main/java/com/yancy/gallerypick/adapter/PhotoAdapter.java:
--------------------------------------------------------------------------------
1 | package com.yancy.gallerypick.adapter;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.CheckBox;
10 |
11 | import com.yancy.gallerypick.R;
12 | import com.yancy.gallerypick.bean.PhotoInfo;
13 | import com.yancy.gallerypick.config.GalleryConfig;
14 | import com.yancy.gallerypick.config.GalleryPick;
15 | import com.yancy.gallerypick.utils.ScreenUtils;
16 | import com.yancy.gallerypick.widget.GalleryImageView;
17 |
18 | import java.util.ArrayList;
19 | import java.util.List;
20 |
21 | /**
22 | * 列表中图片的适配器
23 | * Created by Yancy on 2016/1/27.
24 | */
25 | public class PhotoAdapter extends RecyclerView.Adapter {
26 |
27 | private Context mContext;
28 | private Activity mActivity;
29 | private LayoutInflater mLayoutInflater;
30 | private List photoInfoList; // 本地照片数据
31 | private List selectPhoto = new ArrayList<>(); // 选择的图片数据
32 | private OnCallBack onCallBack;
33 | private final static String TAG = "PhotoAdapter";
34 |
35 | private GalleryConfig galleryConfig = GalleryPick.getInstance().getGalleryConfig();
36 |
37 | private final static int HEAD = 0; // 开启相机时需要显示的布局
38 | private final static int ITEM = 1; // 照片布局
39 |
40 | public PhotoAdapter(Activity mActivity, Context mContext, List photoInfoList) {
41 | mLayoutInflater = LayoutInflater.from(mContext);
42 | this.mContext = mContext;
43 | this.photoInfoList = photoInfoList;
44 | this.mActivity = mActivity;
45 | }
46 |
47 | @Override
48 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
49 | if (viewType == HEAD) {
50 | return new HeadHolder(mLayoutInflater.inflate(R.layout.gallery_item_camera, parent, false));
51 | }
52 | return new ViewHolder(mLayoutInflater.inflate(R.layout.gallery_item_photo, parent, false));
53 | }
54 |
55 | @Override
56 | public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
57 |
58 | // 设置 每个imageView 的大小
59 | ViewGroup.LayoutParams params = holder.itemView.getLayoutParams();
60 | params.height = ScreenUtils.getScreenWidth(mContext) / 3;
61 | params.width = ScreenUtils.getScreenWidth(mContext) / 3;
62 | holder.itemView.setLayoutParams(params);
63 |
64 | if (getItemViewType(position) == HEAD) {
65 | holder.itemView.setOnClickListener(new View.OnClickListener() {
66 | @Override
67 | public void onClick(View v) {
68 | if (galleryConfig.getMaxSize() <= selectPhoto.size()) { // 当选择图片达到上限时, 禁止继续添加
69 | return;
70 | }
71 | onCallBack.OnClickCamera(selectPhoto);
72 | }
73 | });
74 | return;
75 | }
76 |
77 | final PhotoInfo photoInfo;
78 | if (galleryConfig.isShowCamera()) {
79 | photoInfo = photoInfoList.get(position - 1);
80 | } else {
81 | photoInfo = photoInfoList.get(position);
82 | }
83 | final ViewHolder viewHolder = (ViewHolder) holder;
84 | galleryConfig.getImageLoader().displayImage(mActivity, mContext, photoInfo.path, viewHolder.ivPhotoImage, ScreenUtils.getScreenWidth(mContext) / 3, ScreenUtils.getScreenWidth(mContext) / 3);
85 |
86 |
87 | if (selectPhoto.contains(photoInfo.path)) {
88 | viewHolder.chkPhotoSelector.setChecked(true);
89 | viewHolder.chkPhotoSelector.setButtonDrawable(R.mipmap.gallery_pick_select_checked);
90 | viewHolder.vPhotoMask.setVisibility(View.VISIBLE);
91 | } else {
92 | viewHolder.chkPhotoSelector.setChecked(false);
93 | viewHolder.chkPhotoSelector.setButtonDrawable(R.mipmap.gallery_pick_select_unchecked);
94 | viewHolder.vPhotoMask.setVisibility(View.GONE);
95 | }
96 |
97 | if (!galleryConfig.isMultiSelect()) {
98 | viewHolder.chkPhotoSelector.setVisibility(View.GONE);
99 | viewHolder.vPhotoMask.setVisibility(View.GONE);
100 | }
101 |
102 |
103 | viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
104 | @Override
105 | public void onClick(View v) {
106 | if (!galleryConfig.isMultiSelect()) {
107 | selectPhoto.clear();
108 | selectPhoto.add(photoInfo.path);
109 | onCallBack.OnClickPhoto(selectPhoto);
110 | return;
111 | }
112 |
113 | if (selectPhoto.contains(photoInfo.path)) {
114 | selectPhoto.remove(photoInfo.path);
115 | viewHolder.chkPhotoSelector.setChecked(false);
116 | viewHolder.chkPhotoSelector.setButtonDrawable(R.mipmap.gallery_pick_select_unchecked);
117 | viewHolder.vPhotoMask.setVisibility(View.GONE);
118 | } else {
119 | if (galleryConfig.getMaxSize() <= selectPhoto.size()) { // 当选择图片达到上限时, 禁止继续添加
120 | return;
121 | }
122 | selectPhoto.add(photoInfo.path);
123 | viewHolder.chkPhotoSelector.setChecked(true);
124 | viewHolder.chkPhotoSelector.setButtonDrawable(R.mipmap.gallery_pick_select_checked);
125 | viewHolder.vPhotoMask.setVisibility(View.VISIBLE);
126 | }
127 | onCallBack.OnClickPhoto(selectPhoto);
128 | }
129 | });
130 |
131 |
132 | }
133 |
134 |
135 | /**
136 | * 照片的 Holder
137 | */
138 | private class ViewHolder extends RecyclerView.ViewHolder {
139 | private GalleryImageView ivPhotoImage;
140 | private View vPhotoMask;
141 | private CheckBox chkPhotoSelector;
142 |
143 | private ViewHolder(View itemView) {
144 | super(itemView);
145 | ivPhotoImage = (GalleryImageView) itemView.findViewById(R.id.ivGalleryPhotoImage);
146 | vPhotoMask = itemView.findViewById(R.id.vGalleryPhotoMask);
147 | chkPhotoSelector = (CheckBox) itemView.findViewById(R.id.chkGalleryPhotoSelector);
148 | }
149 | }
150 |
151 | /**
152 | * 相机按钮的 Holder
153 | */
154 | private class HeadHolder extends RecyclerView.ViewHolder {
155 | private HeadHolder(View itemView) {
156 | super(itemView);
157 | }
158 | }
159 |
160 |
161 | @Override
162 | public int getItemViewType(int position) {
163 | if (galleryConfig.isShowCamera() && position == 0) {
164 | return HEAD;
165 | }
166 | return ITEM;
167 | }
168 |
169 | @Override
170 | public int getItemCount() {
171 | if (galleryConfig.isShowCamera())
172 | return photoInfoList.size() + 1;
173 | else
174 | return photoInfoList.size();
175 | }
176 |
177 | public interface OnCallBack {
178 | void OnClickPhoto(List selectPhoto);
179 |
180 | void OnClickCamera(List selectPhoto);
181 | }
182 |
183 | public void setOnCallBack(OnCallBack onCallBack) {
184 | this.onCallBack = onCallBack;
185 | }
186 |
187 | /**
188 | * 传入已选的图片
189 | *
190 | * @param selectPhoto 已选的图片路径
191 | */
192 | public void setSelectPhoto(List selectPhoto) {
193 | this.selectPhoto.addAll(selectPhoto);
194 |
195 | // for (String filePath : selectPhoto) {
196 | // PhotoInfo photoInfo = getPhotoByPath(filePath);
197 | // if (photoInfo != null) {
198 | // this.selectPhoto.add(photoInfo);
199 | // }
200 | // }
201 | // if (selectPhoto.size() > 0) {
202 | // notifyDataSetChanged();
203 | // }
204 | }
205 |
206 | // /**
207 | // * 根据图片路径,获取图片 PhotoInfo 对象
208 | // *
209 | // * @param filePath 图片路径
210 | // * @return PhotoInfo 对象
211 | // */
212 | // private PhotoInfo getPhotoByPath(String filePath) {
213 | // if (photoInfoList != null && photoInfoList.size() > 0) {
214 | // for (PhotoInfo photoInfo : photoInfoList) {
215 | // if (photoInfo.path.equalsIgnoreCase(filePath)) {
216 | // return photoInfo;
217 | // }
218 | // }
219 | // }
220 | // return null;
221 | // }
222 |
223 |
224 | }
225 | /*
226 | * ┏┓ ┏┓
227 | * ┏┛┻━━━┛┻┓
228 | * ┃ ┃
229 | * ┃ ━ ┃
230 | * ┃ ┳┛ ┗┳ ┃
231 | * ┃ ┃
232 | * ┃ ┻ ┃
233 | * ┃ ┃
234 | * ┗━┓ ┏━┛
235 | * ┃ ┃
236 | * ┃ ┃
237 | * ┃ ┗━━━┓
238 | * ┃ ┣┓
239 | * ┃ ┏┛
240 | * ┗┓┓┏━┳┓┏┛
241 | * ┃┫┫ ┃┫┫
242 | * ┗┻┛ ┗┻┛
243 | * 神兽保佑
244 | * 代码无BUG!
245 | */
--------------------------------------------------------------------------------
/gallerypick/src/main/java/com/yancy/gallerypick/bean/FolderInfo.java:
--------------------------------------------------------------------------------
1 | package com.yancy.gallerypick.bean;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * 文件夹信息
7 | * Created by Yancy on 2016/1/27.
8 | */
9 | public class FolderInfo {
10 |
11 | public String name; // 文件夹名称
12 | public String path; // 文件夹路径
13 | public PhotoInfo photoInfo; // 文件夹中第一张图片的信息
14 | public List photoInfoList; // 文件夹中的图片集合
15 |
16 | @Override
17 | public boolean equals(Object object) {
18 | try {
19 | FolderInfo other = (FolderInfo) object;
20 | return this.path.equalsIgnoreCase(other.path);
21 | } catch (ClassCastException e) {
22 | e.printStackTrace();
23 | }
24 | return super.equals(object);
25 | }
26 |
27 | @Override
28 | public String toString() {
29 | return "FolderInfo{" +
30 | "name='" + name + '\'' +
31 | ", path='" + path + '\'' +
32 | ", photoInfo=" + photoInfo +
33 | ", photoInfoList=" + photoInfoList +
34 | '}';
35 | }
36 | }
37 | /*
38 | * ┏┓ ┏┓
39 | * ┏┛┻━━━┛┻┓
40 | * ┃ ┃
41 | * ┃ ━ ┃
42 | * ┃ ┳┛ ┗┳ ┃
43 | * ┃ ┃
44 | * ┃ ┻ ┃
45 | * ┃ ┃
46 | * ┗━┓ ┏━┛
47 | * ┃ ┃
48 | * ┃ ┃
49 | * ┃ ┗━━━┓
50 | * ┃ ┣┓
51 | * ┃ ┏┛
52 | * ┗┓┓┏━┳┓┏┛
53 | * ┃┫┫ ┃┫┫
54 | * ┗┻┛ ┗┻┛
55 | * 神兽保佑
56 | * 代码无BUG!
57 | */
--------------------------------------------------------------------------------
/gallerypick/src/main/java/com/yancy/gallerypick/bean/PhotoInfo.java:
--------------------------------------------------------------------------------
1 | package com.yancy.gallerypick.bean;
2 |
3 | /**
4 | * 图片信息
5 | * Created by Yancy on 2016/1/27.
6 | */
7 | public class PhotoInfo {
8 |
9 | public String name; // 图片名
10 | public String path; // 图片路径
11 | public long time; // 图片添加时间
12 |
13 | public PhotoInfo(String path, String name, long time) {
14 | this.path = path;
15 | this.name = name;
16 | this.time = time;
17 | }
18 |
19 | @Override
20 | public String toString() {
21 | return "PhotoInfo{" +
22 | "name='" + name + '\'' +
23 | ", path='" + path + '\'' +
24 | ", time=" + time +
25 | '}';
26 | }
27 |
28 | @Override
29 | public boolean equals(Object object) {
30 | try {
31 | PhotoInfo other = (PhotoInfo) object;
32 | return this.path.equalsIgnoreCase(other.path);
33 | } catch (ClassCastException e) {
34 | e.printStackTrace();
35 | }
36 | return super.equals(object);
37 | }
38 |
39 |
40 | }
41 | /*
42 | * ┏┓ ┏┓
43 | * ┏┛┻━━━┛┻┓
44 | * ┃ ┃
45 | * ┃ ━ ┃
46 | * ┃ ┳┛ ┗┳ ┃
47 | * ┃ ┃
48 | * ┃ ┻ ┃
49 | * ┃ ┃
50 | * ┗━┓ ┏━┛
51 | * ┃ ┃
52 | * ┃ ┃
53 | * ┃ ┗━━━┓
54 | * ┃ ┣┓
55 | * ┃ ┏┛
56 | * ┗┓┓┏━┳┓┏┛
57 | * ┃┫┫ ┃┫┫
58 | * ┗┻┛ ┗┻┛
59 | * 神兽保佑
60 | * 代码无BUG!
61 | */
--------------------------------------------------------------------------------
/gallerypick/src/main/java/com/yancy/gallerypick/config/GalleryConfig.java:
--------------------------------------------------------------------------------
1 | package com.yancy.gallerypick.config;
2 |
3 | import com.yancy.gallerypick.inter.IHandlerCallBack;
4 | import com.yancy.gallerypick.inter.ImageLoader;
5 |
6 | import java.io.Serializable;
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | /**
11 | * GalleryPick 配置器
12 | * Created by Yancy on 2016/1/27.
13 | */
14 | public class GalleryConfig {
15 |
16 | private ImageLoader imageLoader; // 图片加载器
17 | private IHandlerCallBack iHandlerCallBack; // GalleryPick 生命周期接口
18 |
19 | private boolean multiSelect; // 是否开启多选 默认 : false
20 | private int maxSize; // 配置开启多选时 最大可选择的图片数量。 默认:9
21 | private boolean isShowCamera; // 是否开启相机 默认:true
22 | private String filePath; // 拍照以及截图后 存放的位置。 默认:/Gallery/Pictures
23 | private ArrayList pathList; // 已选择照片的路径
24 | private boolean isOpenCamera; // 是否直接开启相机 默认:false
25 |
26 | private boolean isCrop; // 是否开启裁剪 默认关闭
27 | private float aspectRatioX; // 裁剪比 默认 1:1
28 | private float aspectRatioY; // 裁剪比 默认 1:1
29 | private int maxWidth; // 最大的裁剪值 默认 500
30 | private int maxHeight; // 最大的裁剪值 默认 500
31 |
32 | private Builder builder;
33 |
34 |
35 | private GalleryConfig(Builder builder) {
36 | setBuilder(builder);
37 | }
38 |
39 |
40 | private void setBuilder(Builder builder) {
41 | this.imageLoader = builder.imageLoader;
42 | this.iHandlerCallBack = builder.iHandlerCallBack;
43 | this.multiSelect = builder.multiSelect;
44 | this.maxSize = builder.maxSize;
45 | this.isShowCamera = builder.isShowCamera;
46 | this.pathList = builder.pathList;
47 | this.filePath = builder.filePath;
48 | this.isOpenCamera = builder.isOpenCamera;
49 | this.isCrop = builder.isCrop;
50 | this.aspectRatioX = builder.aspectRatioX;
51 | this.aspectRatioY = builder.aspectRatioY;
52 | this.maxWidth = builder.maxWidth;
53 | this.maxHeight = builder.maxHeight;
54 | this.builder = builder;
55 | }
56 |
57 | public static class Builder implements Serializable {
58 |
59 | private static GalleryConfig galleryConfig;
60 |
61 | private ImageLoader imageLoader;
62 | private IHandlerCallBack iHandlerCallBack;
63 |
64 | private boolean multiSelect = false;
65 | private int maxSize = 9;
66 | private boolean isShowCamera = true;
67 | private String filePath = "/Gallery/Pictures";
68 |
69 | private boolean isCrop = false;
70 | private float aspectRatioX = 1;
71 | private float aspectRatioY = 1;
72 | private int maxWidth = 500;
73 | private int maxHeight = 500;
74 |
75 | private ArrayList pathList = new ArrayList<>();
76 |
77 | private boolean isOpenCamera = false;
78 |
79 | public Builder crop(boolean isCrop) {
80 | this.isCrop = isCrop;
81 | return this;
82 | }
83 |
84 | public Builder crop(boolean isCrop, float aspectRatioX, float aspectRatioY, int maxWidth, int maxHeight) {
85 | this.isCrop = isCrop;
86 | this.aspectRatioX = aspectRatioX;
87 | this.aspectRatioY = aspectRatioY;
88 | this.maxWidth = maxWidth;
89 | this.maxHeight = maxHeight;
90 | return this;
91 | }
92 |
93 |
94 | public Builder imageLoader(ImageLoader imageLoader) {
95 | this.imageLoader = imageLoader;
96 | return this;
97 | }
98 |
99 | public Builder iHandlerCallBack(IHandlerCallBack iHandlerCallBack) {
100 | this.iHandlerCallBack = iHandlerCallBack;
101 | return this;
102 | }
103 |
104 |
105 | public Builder multiSelect(boolean multiSelect) {
106 | this.multiSelect = multiSelect;
107 | return this;
108 | }
109 |
110 | public Builder multiSelect(boolean multiSelect, int maxSize) {
111 | this.multiSelect = multiSelect;
112 | this.maxSize = maxSize;
113 | return this;
114 | }
115 |
116 | public Builder maxSize(int maxSize) {
117 | this.maxSize = maxSize;
118 | return this;
119 | }
120 |
121 | public Builder isShowCamera(boolean isShowCamera) {
122 | this.isShowCamera = isShowCamera;
123 | return this;
124 | }
125 |
126 | public Builder filePath(String filePath) {
127 | this.filePath = filePath;
128 | return this;
129 | }
130 |
131 | public Builder isOpenCamera(boolean isOpenCamera) {
132 | this.isOpenCamera = isOpenCamera;
133 | return this;
134 | }
135 |
136 |
137 | public Builder pathList(List pathList) {
138 | this.pathList.clear();
139 | this.pathList.addAll(pathList);
140 | return this;
141 | }
142 |
143 | public GalleryConfig build() {
144 | if (galleryConfig == null) {
145 | galleryConfig = new GalleryConfig(this);
146 | } else {
147 | galleryConfig.setBuilder(this);
148 | }
149 | return galleryConfig;
150 | }
151 |
152 | }
153 |
154 | public ImageLoader getImageLoader() {
155 | return imageLoader;
156 | }
157 |
158 | public boolean isMultiSelect() {
159 | return multiSelect;
160 | }
161 |
162 | public int getMaxSize() {
163 | return maxSize;
164 | }
165 |
166 | public boolean isShowCamera() {
167 | return isShowCamera;
168 | }
169 |
170 | public ArrayList getPathList() {
171 | return pathList;
172 | }
173 |
174 | public String getFilePath() {
175 | return filePath;
176 | }
177 |
178 | public IHandlerCallBack getIHandlerCallBack() {
179 | return iHandlerCallBack;
180 | }
181 |
182 | public Builder getBuilder() {
183 | return builder;
184 | }
185 |
186 | public boolean isOpenCamera() {
187 | return isOpenCamera;
188 | }
189 |
190 | public int getMaxHeight() {
191 | return maxHeight;
192 | }
193 |
194 | public boolean isCrop() {
195 | return isCrop;
196 | }
197 |
198 | public float getAspectRatioX() {
199 | return aspectRatioX;
200 | }
201 |
202 | public float getAspectRatioY() {
203 | return aspectRatioY;
204 | }
205 |
206 | public int getMaxWidth() {
207 | return maxWidth;
208 | }
209 | }
210 | /*
211 | * ┏┓ ┏┓
212 | * ┏┛┻━━━┛┻┓
213 | * ┃ ┃
214 | * ┃ ━ ┃
215 | * ┃ ┳┛ ┗┳ ┃
216 | * ┃ ┃
217 | * ┃ ┻ ┃
218 | * ┃ ┃
219 | * ┗━┓ ┏━┛
220 | * ┃ ┃
221 | * ┃ ┃
222 | * ┃ ┗━━━┓
223 | * ┃ ┣┓
224 | * ┃ ┏┛
225 | * ┗┓┓┏━┳┓┏┛
226 | * ┃┫┫ ┃┫┫
227 | * ┗┻┛ ┗┻┛
228 | * 神兽保佑
229 | * 代码无BUG!
230 | */
--------------------------------------------------------------------------------
/gallerypick/src/main/java/com/yancy/gallerypick/config/GalleryPick.java:
--------------------------------------------------------------------------------
1 | package com.yancy.gallerypick.config;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.util.Log;
6 |
7 | import com.yancy.gallerypick.activity.GalleryPickActivity;
8 | import com.yancy.gallerypick.utils.FileUtils;
9 |
10 | /**
11 | * GalleryPick 启动类 (单例)
12 | * Created by Yancy on 2016/1/27.
13 | */
14 | public class GalleryPick {
15 |
16 | private final static String TAG = "GalleryPick";
17 |
18 | private static GalleryPick galleryPick;
19 |
20 | private GalleryConfig galleryConfig;
21 |
22 | public static GalleryPick getInstance() {
23 | if (galleryPick == null) {
24 | galleryPick = new GalleryPick();
25 | }
26 | return galleryPick;
27 | }
28 |
29 |
30 | public void open(Activity mActivity) {
31 | if (galleryPick.galleryConfig == null) {
32 | Log.e(TAG, "请配置 GalleryConfig");
33 | return;
34 | }
35 | if (galleryPick.galleryConfig.getImageLoader() == null) {
36 | Log.e(TAG, "请配置 ImageLoader");
37 | return;
38 | }
39 | if (galleryPick.galleryConfig.getIHandlerCallBack() == null) {
40 | Log.e(TAG, "请配置 IHandlerCallBack");
41 | return;
42 | }
43 |
44 | FileUtils.createFile(galleryPick.galleryConfig.getFilePath());
45 |
46 | Intent intent = new Intent(mActivity, GalleryPickActivity.class);
47 | mActivity.startActivity(intent);
48 | }
49 |
50 | public void openCamera(Activity mActivity) {
51 | if (galleryPick.galleryConfig == null) {
52 | Log.e(TAG, "请配置 GalleryConfig");
53 | return;
54 | }
55 | if (galleryPick.galleryConfig.getIHandlerCallBack() == null) {
56 | Log.e(TAG, "请配置 IHandlerCallBack");
57 | return;
58 | }
59 |
60 | FileUtils.createFile(galleryPick.galleryConfig.getFilePath());
61 |
62 | Intent intent = new Intent(mActivity, GalleryPickActivity.class);
63 | intent.putExtra("isOpenCamera", true);
64 | mActivity.startActivity(intent);
65 | }
66 |
67 |
68 | public GalleryPick setGalleryConfig(GalleryConfig galleryConfig) {
69 | this.galleryConfig = galleryConfig;
70 | return this;
71 | }
72 |
73 | public GalleryConfig getGalleryConfig() {
74 | return galleryConfig;
75 | }
76 |
77 | }
78 | /*
79 | * ┏┓ ┏┓
80 | * ┏┛┻━━━┛┻┓
81 | * ┃ ┃
82 | * ┃ ━ ┃
83 | * ┃ ┳┛ ┗┳ ┃
84 | * ┃ ┃
85 | * ┃ ┻ ┃
86 | * ┃ ┃
87 | * ┗━┓ ┏━┛
88 | * ┃ ┃
89 | * ┃ ┃
90 | * ┃ ┗━━━┓
91 | * ┃ ┣┓
92 | * ┃ ┏┛
93 | * ┗┓┓┏━┳┓┏┛
94 | * ┃┫┫ ┃┫┫
95 | * ┗┻┛ ┗┻┛
96 | * 神兽保佑
97 | * 代码无BUG!
98 | */
--------------------------------------------------------------------------------
/gallerypick/src/main/java/com/yancy/gallerypick/inter/IHandlerCallBack.java:
--------------------------------------------------------------------------------
1 | package com.yancy.gallerypick.inter;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * IHandlerCallBack
7 | * Created by Yancy on 2016/10/26.
8 | */
9 |
10 | public interface IHandlerCallBack {
11 |
12 | void onStart();
13 |
14 | void onSuccess(List photoList);
15 |
16 | void onCancel();
17 |
18 | void onFinish();
19 |
20 | void onError();
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/gallerypick/src/main/java/com/yancy/gallerypick/inter/ImageLoader.java:
--------------------------------------------------------------------------------
1 | package com.yancy.gallerypick.inter;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 |
6 | import com.yancy.gallerypick.widget.GalleryImageView;
7 |
8 | import java.io.Serializable;
9 |
10 | /**
11 | * 自定义图片加载框架
12 | * Created by Yancy on 2016/1/27.
13 | */
14 | public interface ImageLoader extends Serializable {
15 | void displayImage(Activity activity, Context context, String path, GalleryImageView galleryImageView, int width, int height);
16 |
17 | void clearMemoryCache();
18 | }
19 | /*
20 | * ┏┓ ┏┓
21 | * ┏┛┻━━━┛┻┓
22 | * ┃ ┃
23 | * ┃ ━ ┃
24 | * ┃ ┳┛ ┗┳ ┃
25 | * ┃ ┃
26 | * ┃ ┻ ┃
27 | * ┃ ┃
28 | * ┗━┓ ┏━┛
29 | * ┃ ┃
30 | * ┃ ┃
31 | * ┃ ┗━━━┓
32 | * ┃ ┣┓
33 | * ┃ ┏┛
34 | * ┗┓┓┏━┳┓┏┛
35 | * ┃┫┫ ┃┫┫
36 | * ┗┻┛ ┗┻┛
37 | * 神兽保佑
38 | * 代码无BUG!
39 | */
--------------------------------------------------------------------------------
/gallerypick/src/main/java/com/yancy/gallerypick/utils/AppUtils.java:
--------------------------------------------------------------------------------
1 | package com.yancy.gallerypick.utils;
2 |
3 | import android.content.Context;
4 | import android.content.pm.PackageInfo;
5 | import android.content.pm.PackageManager;
6 |
7 | /**
8 | * App相关辅助类
9 | * Created by Yancy on 2015/9/24.
10 | */
11 | public class AppUtils {
12 |
13 | private AppUtils() {
14 | throw new UnsupportedOperationException("cannot be instantiated");
15 | }
16 |
17 | /**
18 | * 获取应用程序名称
19 | */
20 | public static String getAppName(Context context) {
21 | try {
22 | PackageManager packageManager = context.getPackageManager();
23 | PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
24 | int labelRes = packageInfo.applicationInfo.labelRes;
25 | return context.getResources().getString(labelRes);
26 | } catch (PackageManager.NameNotFoundException e) {
27 | e.printStackTrace();
28 | }
29 | return null;
30 | }
31 |
32 | /**
33 | * 获取当前应用的版本名称
34 | */
35 | public static String getVersionName(Context context) {
36 | try {
37 | PackageManager packageManager = context.getPackageManager();
38 | PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
39 | return packageInfo.versionName;
40 | } catch (PackageManager.NameNotFoundException e) {
41 | e.printStackTrace();
42 | }
43 | return null;
44 | }
45 |
46 | /**
47 | * 获取 android API 版本号 : API 21
48 | */
49 | public static int getAPIVersion() {
50 | return android.os.Build.VERSION.SDK_INT;
51 | }
52 |
53 | /**
54 | * 获取 android 版本号 : Android 5.0
55 | */
56 | public static String getAndroidVersion() {
57 | return "Android " + android.os.Build.VERSION.RELEASE;
58 | }
59 |
60 |
61 | }
62 | /*
63 | * ┏┓ ┏┓
64 | * ┏┛┻━━━┛┻┓
65 | * ┃ ┃
66 | * ┃ ━ ┃
67 | * ┃ ┳┛ ┗┳ ┃
68 | * ┃ ┃
69 | * ┃ ┻ ┃
70 | * ┃ ┃
71 | * ┗━┓ ┏━┛
72 | * ┃ ┃
73 | * ┃ ┃
74 | * ┃ ┗━━━┓
75 | * ┃ ┣┓
76 | * ┃ ┏┛
77 | * ┗┓┓┏━┳┓┏┛
78 | * ┃┫┫ ┃┫┫
79 | * ┗┻┛ ┗┻┛
80 | * 神兽保佑
81 | * 代码无BUG!
82 | */
--------------------------------------------------------------------------------
/gallerypick/src/main/java/com/yancy/gallerypick/utils/FileUtils.java:
--------------------------------------------------------------------------------
1 | package com.yancy.gallerypick.utils;
2 |
3 | import android.content.Context;
4 | import android.os.Environment;
5 |
6 | import java.io.File;
7 | import java.io.IOException;
8 | import java.text.SimpleDateFormat;
9 | import java.util.Date;
10 | import java.util.Locale;
11 |
12 | /**
13 | * FileUtils
14 | * Created by Yancy on 2015/12/2.
15 | */
16 | public class FileUtils {
17 |
18 |
19 | private final static String PATTERN = "yyyyMMddHHmmss"; // 时间戳命名
20 |
21 |
22 | /**
23 | * 创建文件
24 | *
25 | * @param context context
26 | * @param filePath 文件路径
27 | * @return file
28 | */
29 | public static File createTmpFile(Context context, String filePath) {
30 |
31 | String timeStamp = new SimpleDateFormat(PATTERN, Locale.CHINA).format(new Date());
32 |
33 | String externalStorageState = Environment.getExternalStorageState();
34 |
35 | File dir = new File(Environment.getExternalStorageDirectory() + filePath);
36 |
37 | if (externalStorageState.equals(Environment.MEDIA_MOUNTED)) {
38 | if (!dir.exists()) {
39 | dir.mkdirs();
40 | }
41 | return new File(dir, timeStamp + ".jpg");
42 | } else {
43 | File cacheDir = context.getCacheDir();
44 | return new File(cacheDir, timeStamp + ".jpg");
45 | }
46 |
47 | }
48 |
49 |
50 | /**
51 | * 创建初始文件夹。保存拍摄图片和裁剪后的图片
52 | *
53 | * @param filePath 文件夹路径
54 | */
55 | public static void createFile(String filePath) {
56 | String externalStorageState = Environment.getExternalStorageState();
57 |
58 | File dir = new File(Environment.getExternalStorageDirectory() + filePath);
59 | File cropFile = new File(Environment.getExternalStorageDirectory() + filePath + "/crop");
60 |
61 | if (externalStorageState.equals(Environment.MEDIA_MOUNTED)) {
62 | if (!cropFile.exists()) {
63 | cropFile.mkdirs();
64 | }
65 |
66 | File file = new File(dir, ".nomedia"); // 创建忽视文件。 有该文件,系统将检索不到此文件夹下的图片。
67 | if (!file.exists()) {
68 | try {
69 | file.createNewFile();
70 | } catch (IOException e) {
71 | e.printStackTrace();
72 | }
73 | }
74 |
75 | }
76 | }
77 |
78 | /**
79 | * @param filePath 文件夹路径
80 | * @return 截图完成的 file
81 | */
82 | public static File getCorpFile(String filePath) {
83 | String timeStamp = new SimpleDateFormat(PATTERN, Locale.CHINA).format(new Date());
84 | return new File(Environment.getExternalStorageDirectory() + filePath + "/crop/" + timeStamp + ".jpg");
85 | }
86 |
87 |
88 | }
--------------------------------------------------------------------------------
/gallerypick/src/main/java/com/yancy/gallerypick/utils/ScreenUtils.java:
--------------------------------------------------------------------------------
1 | package com.yancy.gallerypick.utils;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.graphics.Bitmap;
6 | import android.graphics.Rect;
7 | import android.util.DisplayMetrics;
8 | import android.view.View;
9 | import android.view.WindowManager;
10 |
11 | /**
12 | * 屏幕相关辅助类
13 | * Created by Yancy on 2015/9/24.
14 | */
15 | public class ScreenUtils {
16 |
17 | private ScreenUtils() {
18 | throw new UnsupportedOperationException("cannot be instantiated");
19 | }
20 |
21 | /**
22 | * 获得屏幕高度
23 | *
24 | * @param context context
25 | * @return 屏幕高度
26 | */
27 | public static int getScreenWidth(Context context) {
28 | WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
29 | DisplayMetrics outMetrics = new DisplayMetrics();
30 | wm.getDefaultDisplay().getMetrics(outMetrics);
31 | return outMetrics.widthPixels;
32 | }
33 |
34 | /**
35 | * 获得屏幕宽度
36 | *
37 | * @param context context
38 | * @return 屏幕宽度
39 | */
40 | public static int getScreenHeight(Context context) {
41 | WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
42 | DisplayMetrics outMetrics = new DisplayMetrics();
43 | wm.getDefaultDisplay().getMetrics(outMetrics);
44 | return outMetrics.heightPixels;
45 | }
46 |
47 | /**
48 | * 获得状态栏的高度
49 | *
50 | * @param context context
51 | * @return 状态栏的高度
52 | */
53 | public static int getStatusHeight(Context context) {
54 |
55 | int statusHeight = -1;
56 | try {
57 | Class> clazz = Class.forName("com.android.internal.R$dimen");
58 | Object object = clazz.newInstance();
59 | int height = Integer.parseInt(clazz.getField("status_bar_height").get(object).toString());
60 | statusHeight = context.getResources().getDimensionPixelSize(height);
61 | } catch (Exception e) {
62 | e.printStackTrace();
63 | }
64 | return statusHeight;
65 | }
66 |
67 | /**
68 | * 获取当前屏幕截图,包含状态栏
69 | *
70 | * @param activity activity
71 | * @return Bitmap 获取当前屏幕截图,包含状态栏
72 | */
73 | public static Bitmap snapShotWithStatusBar(Activity activity) {
74 | View view = activity.getWindow().getDecorView();
75 | view.setDrawingCacheEnabled(true);
76 | view.buildDrawingCache();
77 | Bitmap bmp = view.getDrawingCache();
78 | int width = getScreenWidth(activity);
79 | int height = getScreenHeight(activity);
80 | Bitmap bp = null;
81 | bp = Bitmap.createBitmap(bmp, 0, 0, width, height);
82 | view.destroyDrawingCache();
83 | return bp;
84 | }
85 |
86 | /**
87 | * 获取当前屏幕截图,不包含状态栏
88 | *
89 | * @param activity activity
90 | * @return Bitmap 获取当前屏幕截图,不包含状态栏
91 | */
92 | public static Bitmap snapShotWithoutStatusBar(Activity activity) {
93 | View view = activity.getWindow().getDecorView();
94 | view.setDrawingCacheEnabled(true);
95 | view.buildDrawingCache();
96 | Bitmap bmp = view.getDrawingCache();
97 | Rect frame = new Rect();
98 | activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
99 | int statusBarHeight = frame.top;
100 |
101 | int width = getScreenWidth(activity);
102 | int height = getScreenHeight(activity);
103 | Bitmap bp = null;
104 | bp = Bitmap.createBitmap(bmp, 0, statusBarHeight, width, height - statusBarHeight);
105 | view.destroyDrawingCache();
106 | return bp;
107 |
108 | }
109 |
110 | }
111 | /*
112 | * ┏┓ ┏┓
113 | * ┏┛┻━━━┛┻┓
114 | * ┃ ┃
115 | * ┃ ━ ┃
116 | * ┃ ┳┛ ┗┳ ┃
117 | * ┃ ┃
118 | * ┃ ┻ ┃
119 | * ┃ ┃
120 | * ┗━┓ ┏━┛
121 | * ┃ ┃
122 | * ┃ ┃
123 | * ┃ ┗━━━┓
124 | * ┃ ┣┓
125 | * ┃ ┏┛
126 | * ┗┓┓┏━┳┓┏┛
127 | * ┃┫┫ ┃┫┫
128 | * ┗┻┛ ┗┻┛
129 | * 神兽保佑
130 | * 代码无BUG!
131 | */
--------------------------------------------------------------------------------
/gallerypick/src/main/java/com/yancy/gallerypick/utils/UCropUtils.java:
--------------------------------------------------------------------------------
1 | package com.yancy.gallerypick.utils;
2 |
3 | import android.app.Activity;
4 | import android.net.Uri;
5 |
6 | import com.yalantis.ucrop.UCrop;
7 | import com.yancy.gallerypick.R;
8 |
9 | import java.io.File;
10 |
11 | /**
12 | * UCropUtils
13 | * Created by Yancy on 2016/11/2.
14 | */
15 | public class UCropUtils {
16 |
17 | public static void start(Activity mActivity, File sourceFile, File destinationFile, float aspectRatioX, float aspectRatioY, int maxWidth, int maxHeight) {
18 | UCrop uCrop = UCrop.of(Uri.fromFile(sourceFile), Uri.fromFile(destinationFile))
19 | .withAspectRatio(aspectRatioX, aspectRatioY)
20 | .withMaxResultSize(maxWidth, maxHeight);
21 |
22 | UCrop.Options options = new UCrop.Options();
23 | options.setToolbarColor(mActivity.getResources().getColor(R.color.gallery_blue));
24 | options.setStatusBarColor(mActivity.getResources().getColor(R.color.gallery_blue));
25 | uCrop.withOptions(options);
26 |
27 |
28 | uCrop.start(mActivity);
29 | }
30 |
31 |
32 | }
33 | /*
34 | * ┏┓ ┏┓
35 | * ┏┛┻━━━┛┻┓
36 | * ┃ ┃
37 | * ┃ ━ ┃
38 | * ┃ ┳┛ ┗┳ ┃
39 | * ┃ ┃
40 | * ┃ ┻ ┃
41 | * ┃ ┃
42 | * ┗━┓ ┏━┛
43 | * ┃ ┃
44 | * ┃ ┃
45 | * ┃ ┗━━━┓
46 | * ┃ ┣┓
47 | * ┃ ┏┛
48 | * ┗┓┓┏━┳┓┏┛
49 | * ┃┫┫ ┃┫┫
50 | * ┗┻┛ ┗┻┛
51 | * 神兽保佑
52 | * 代码无BUG!
53 | */
--------------------------------------------------------------------------------
/gallerypick/src/main/java/com/yancy/gallerypick/utils/UIUtils.java:
--------------------------------------------------------------------------------
1 | package com.yancy.gallerypick.utils;
2 |
3 | import android.app.Activity;
4 | import android.os.Build;
5 | import android.view.ViewGroup;
6 | import android.view.Window;
7 | import android.view.WindowManager;
8 |
9 | import java.lang.reflect.Field;
10 |
11 | /**
12 | * UI工具类
13 | * Created by Yancy on 2015/9/19.
14 | */
15 | public class UIUtils {
16 |
17 | /**
18 | * @return : 获取状态栏的高度
19 | */
20 | private static int getStatusBarHeight() {
21 | Class> c;
22 | Object obj;
23 | Field field;
24 | int x = 0;
25 | try {
26 | c = Class.forName("com.android.internal.R$dimen");
27 | obj = c.newInstance();
28 | field = c.getField("status_bar_height");
29 | x = Integer.parseInt(field.get(obj).toString());
30 | } catch (Exception e1) {
31 | e1.printStackTrace();
32 | }
33 | return x;
34 | }
35 |
36 | /**
37 | * 如果系统为4.4以上 ,则隐藏状态栏
38 | *
39 | * @param activity activity
40 | * @param resource 资源文件最外层 layout Id
41 | */
42 | public static void hideTitleBar(Activity activity, int resource) {
43 | if (Build.VERSION.SDK_INT > 18) { // 如果系统为4.4以上 ,则隐藏状态栏
44 | Window window = activity.getWindow();
45 | window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
46 | ViewGroup whole_layout = (ViewGroup) activity.findViewById(resource); // 页面整体布局
47 | whole_layout.setPadding(0, activity.getResources().getDimensionPixelSize(getStatusBarHeight()), 0, 0);
48 | }
49 | }
50 |
51 | }
52 | /*
53 | * ┏┓ ┏┓
54 | * ┏┛┻━━━┛┻┓
55 | * ┃ ┃
56 | * ┃ ━ ┃
57 | * ┃ ┳┛ ┗┳ ┃
58 | * ┃ ┃
59 | * ┃ ┻ ┃
60 | * ┃ ┃
61 | * ┗━┓ ┏━┛
62 | * ┃ ┃
63 | * ┃ ┃
64 | * ┃ ┗━━━┓
65 | * ┃ ┣┓
66 | * ┃ ┏┛
67 | * ┗┓┓┏━┳┓┏┛
68 | * ┃┫┫ ┃┫┫
69 | * ┗┻┛ ┗┻┛
70 | * 神兽保佑
71 | * 代码无BUG!
72 | */
--------------------------------------------------------------------------------
/gallerypick/src/main/java/com/yancy/gallerypick/widget/FolderListPopupWindow.java:
--------------------------------------------------------------------------------
1 | package com.yancy.gallerypick.widget;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.graphics.drawable.ColorDrawable;
6 | import android.support.v7.widget.LinearLayoutManager;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.PopupWindow;
12 |
13 | import com.yancy.gallerypick.R;
14 | import com.yancy.gallerypick.adapter.FolderAdapter;
15 |
16 | /**
17 | * 文件夹列表选择
18 | * Created by Yancy on 2016/11/1.
19 | */
20 | public class FolderListPopupWindow extends PopupWindow {
21 |
22 | private final static String TAG = "FolderListPopupWindow";
23 |
24 | private RecyclerView rvFolderList;
25 |
26 | private Context mContext;
27 | private Activity mActivity;
28 | private View popupWindow;
29 |
30 | private FolderAdapter folderAdapter; // 文件夹适配器
31 |
32 |
33 | public FolderListPopupWindow(Activity mActivity, Context mContext, FolderAdapter folderAdapter) {
34 | super(mContext);
35 | this.mContext = mContext;
36 | this.mActivity = mActivity;
37 | this.folderAdapter = folderAdapter;
38 |
39 | LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
40 | popupWindow = inflater.inflate(R.layout.gallery_popup_folder, null);
41 |
42 | initView();
43 | init();
44 |
45 | }
46 |
47 | private void initView() {
48 | rvFolderList = (RecyclerView) popupWindow.findViewById(R.id.rvFolderList);
49 | }
50 |
51 | private void init() {
52 | LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
53 | linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
54 | rvFolderList.setLayoutManager(linearLayoutManager);
55 | rvFolderList.setAdapter(folderAdapter);
56 |
57 | //设置PopupWindow的View
58 | this.setContentView(popupWindow);
59 | //设置PopupWindow弹出窗体的宽
60 | this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
61 | //设置PopupWindow弹出窗体的高
62 | this.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
63 | //设置PopupWindow弹出窗体可点击
64 | this.setFocusable(false);
65 | //设置PopupWindow弹出窗体动画效果
66 | this.setAnimationStyle(R.style.popupAnimation);
67 | //实例化一个ColorDrawable颜色为半透明
68 | ColorDrawable dw = new ColorDrawable(mContext.getResources().getColor(R.color.gallery_folder_bg));
69 | //设置PopupWindow弹出窗体的背景
70 | this.setBackgroundDrawable(dw);
71 |
72 | }
73 |
74 |
75 | }
76 | /*
77 | * ┏┓ ┏┓
78 | * ┏┛┻━━━┛┻┓
79 | * ┃ ┃
80 | * ┃ ━ ┃
81 | * ┃ ┳┛ ┗┳ ┃
82 | * ┃ ┃
83 | * ┃ ┻ ┃
84 | * ┃ ┃
85 | * ┗━┓ ┏━┛
86 | * ┃ ┃
87 | * ┃ ┃
88 | * ┃ ┗━━━┓
89 | * ┃ ┣┓
90 | * ┃ ┏┛
91 | * ┗┓┓┏━┳┓┏┛
92 | * ┃┫┫ ┃┫┫
93 | * ┗┻┛ ┗┻┛
94 | * 神兽保佑
95 | * 代码无BUG!
96 | */
--------------------------------------------------------------------------------
/gallerypick/src/main/java/com/yancy/gallerypick/widget/GalleryImageView.java:
--------------------------------------------------------------------------------
1 | package com.yancy.gallerypick.widget;
2 |
3 | import android.annotation.TargetApi;
4 | import android.content.Context;
5 | import android.graphics.Canvas;
6 | import android.graphics.drawable.Drawable;
7 | import android.util.AttributeSet;
8 | import android.widget.ImageView;
9 |
10 | /**
11 | * 自定义 Image 用来兼容 fresco
12 | * Created by Yancy on 2016/10/28.
13 | */
14 | public class GalleryImageView extends ImageView {
15 |
16 |
17 | private OnImageViewListener onImageViewListener;
18 |
19 | public GalleryImageView(Context context) {
20 | super(context);
21 | }
22 |
23 | public GalleryImageView(Context context, AttributeSet attrs) {
24 | super(context, attrs);
25 | }
26 |
27 | public GalleryImageView(Context context, AttributeSet attrs, int defStyleAttr) {
28 | super(context, attrs, defStyleAttr);
29 | }
30 |
31 | @TargetApi(21)
32 | public GalleryImageView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
33 | super(context, attrs, defStyleAttr, defStyleRes);
34 | }
35 |
36 | public interface OnImageViewListener {
37 | void onDraw(Canvas canvas);
38 |
39 | boolean verifyDrawable(Drawable dr);
40 |
41 | void onDetach();
42 |
43 | void onAttach();
44 | }
45 |
46 | @Override
47 | protected boolean verifyDrawable(Drawable dr) {
48 | onImageViewListener.verifyDrawable(dr);
49 | return super.verifyDrawable(dr);
50 | }
51 |
52 | public void setOnImageViewListener(OnImageViewListener onImageViewListener) {
53 | this.onImageViewListener = onImageViewListener;
54 | }
55 |
56 | @Override
57 | protected void onDraw(Canvas canvas) {
58 | super.onDraw(canvas);
59 | if (onImageViewListener != null) {
60 | onImageViewListener.onDraw(canvas);
61 | }
62 | }
63 |
64 | @Override
65 | protected void onDetachedFromWindow() {
66 | super.onDetachedFromWindow();
67 | if (onImageViewListener != null) {
68 | onImageViewListener.onDetach();
69 | }
70 | }
71 |
72 | @Override
73 | public void onStartTemporaryDetach() {
74 | super.onStartTemporaryDetach();
75 | if (onImageViewListener != null) {
76 | onImageViewListener.onDetach();
77 | }
78 | }
79 |
80 | @Override
81 | public void onAttachedToWindow() {
82 | super.onAttachedToWindow();
83 | if (onImageViewListener != null) {
84 | onImageViewListener.onAttach();
85 | }
86 | }
87 |
88 | @Override
89 | public void onFinishTemporaryDetach() {
90 | super.onFinishTemporaryDetach();
91 | if (onImageViewListener != null) {
92 | onImageViewListener.onAttach();
93 | }
94 | }
95 |
96 |
97 | }
98 | /*
99 | * ┏┓ ┏┓
100 | * ┏┛┻━━━┛┻┓
101 | * ┃ ┃
102 | * ┃ ━ ┃
103 | * ┃ ┳┛ ┗┳ ┃
104 | * ┃ ┃
105 | * ┃ ┻ ┃
106 | * ┃ ┃
107 | * ┗━┓ ┏━┛
108 | * ┃ ┃
109 | * ┃ ┃
110 | * ┃ ┗━━━┓
111 | * ┃ ┣┓
112 | * ┃ ┏┛
113 | * ┗┓┓┏━┳┓┏┛
114 | * ┃┫┫ ┃┫┫
115 | * ┗┻┛ ┗┻┛
116 | * 神兽保佑
117 | * 代码无BUG!
118 | */
--------------------------------------------------------------------------------
/gallerypick/src/main/java/com/yancy/gallerypick/widget/GalleryPickView.java:
--------------------------------------------------------------------------------
1 | package com.yancy.gallerypick.widget;
2 |
3 | import android.annotation.TargetApi;
4 | import android.app.Activity;
5 | import android.content.Context;
6 | import android.database.Cursor;
7 | import android.os.Bundle;
8 | import android.provider.MediaStore;
9 | import android.support.v4.app.FragmentActivity;
10 | import android.support.v4.app.LoaderManager;
11 | import android.support.v4.content.CursorLoader;
12 | import android.support.v4.content.Loader;
13 | import android.support.v7.widget.LinearLayoutManager;
14 | import android.support.v7.widget.RecyclerView;
15 | import android.util.AttributeSet;
16 | import android.view.LayoutInflater;
17 | import android.view.View;
18 | import android.widget.Button;
19 | import android.widget.RelativeLayout;
20 |
21 | import com.yancy.gallerypick.R;
22 | import com.yancy.gallerypick.adapter.MiniPhotoAdapter;
23 | import com.yancy.gallerypick.bean.PhotoInfo;
24 | import com.yancy.gallerypick.config.GalleryPick;
25 |
26 | import java.util.ArrayList;
27 | import java.util.List;
28 |
29 | /**
30 | * 迷你图片选择器
31 | * Created by Yancy on 2016/2/3.
32 | */
33 | public class GalleryPickView extends RelativeLayout {
34 |
35 | private Context context;
36 | private Activity activity;
37 | private final static String TAG = "GalleryPickView";
38 |
39 | private List photoInfoList = new ArrayList<>();
40 | private MiniPhotoAdapter miniPhotoAdapter;
41 |
42 | private Button btnGallery; // 相册按钮
43 |
44 | public GalleryPickView(Context context) {
45 | super(context);
46 | this.context = context;
47 | init();
48 | }
49 |
50 |
51 | public GalleryPickView(Context context, AttributeSet attrs) {
52 | super(context, attrs);
53 | this.context = context;
54 | init();
55 | }
56 |
57 | public GalleryPickView(Context context, AttributeSet attrs, int defStyleAttr) {
58 | super(context, attrs, defStyleAttr);
59 | this.context = context;
60 | init();
61 | }
62 |
63 | @TargetApi(21)
64 | public GalleryPickView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
65 | super(context, attrs, defStyleAttr, defStyleRes);
66 | this.context = context;
67 | init();
68 | }
69 |
70 | private void init() {
71 | View galleryPickView = LayoutInflater.from(context).inflate(R.layout.gallery_mini, this, true);
72 |
73 | btnGallery = (Button) galleryPickView.findViewById(R.id.btnGallery);
74 | btnGallery.setOnClickListener(new OnClickListener() {
75 | @Override
76 | public void onClick(View v) {
77 | GalleryPick.getInstance().open(activity);
78 | }
79 | });
80 | RecyclerView rvMiniImage = (RecyclerView) galleryPickView.findViewById(R.id.rvGalleryMiniImage);
81 | LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
82 | linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
83 | rvMiniImage.setLayoutManager(linearLayoutManager);
84 |
85 | miniPhotoAdapter = new MiniPhotoAdapter(context, photoInfoList);
86 | rvMiniImage.setAdapter(miniPhotoAdapter);
87 | }
88 |
89 | public void init(FragmentActivity fragmentActivity) {
90 | activity = fragmentActivity;
91 | miniPhotoAdapter.setmActivity(fragmentActivity);
92 |
93 |
94 | LoaderManager.LoaderCallbacks mLoaderCallback = new LoaderManager.LoaderCallbacks() {
95 |
96 | private final String[] IMAGE_PROJECTION = {
97 | MediaStore.Images.Media.DATA,
98 | MediaStore.Images.Media.DISPLAY_NAME,
99 | MediaStore.Images.Media.DATE_ADDED,
100 | MediaStore.Images.Media._ID,
101 | MediaStore.Images.Media.SIZE
102 | };
103 |
104 | @Override
105 | public Loader onCreateLoader(int id, Bundle args) {
106 | if (id == 1) {
107 | return new CursorLoader(context, MediaStore.Images.Media.EXTERNAL_CONTENT_URI, IMAGE_PROJECTION, null, null, IMAGE_PROJECTION[2] + " DESC");
108 | }
109 | return null;
110 | }
111 |
112 | @Override
113 | public void onLoadFinished(Loader loader, Cursor data) {
114 | if (data != null) {
115 | int count = data.getCount();
116 | if (count > 0) {
117 | List tempPhotoList = new ArrayList<>();
118 | data.moveToFirst();
119 | do {
120 | String path = data.getString(data.getColumnIndexOrThrow(IMAGE_PROJECTION[0]));
121 | String name = data.getString(data.getColumnIndexOrThrow(IMAGE_PROJECTION[1]));
122 | long dateTime = data.getLong(data.getColumnIndexOrThrow(IMAGE_PROJECTION[2]));
123 | int size = data.getInt(data.getColumnIndexOrThrow(IMAGE_PROJECTION[4]));
124 | boolean showFlag = size > 1024 * 5; //是否大于5K
125 | PhotoInfo photoInfo = new PhotoInfo(path, name, dateTime);
126 | if (showFlag) {
127 | tempPhotoList.add(photoInfo);
128 | }
129 | } while (data.moveToNext());
130 |
131 | photoInfoList.clear();
132 | photoInfoList.addAll(tempPhotoList);
133 | miniPhotoAdapter.notifyDataSetChanged();
134 |
135 | }
136 | }
137 | }
138 |
139 | @Override
140 | public void onLoaderReset(Loader loader) {
141 |
142 | }
143 | };
144 |
145 |
146 | fragmentActivity.getSupportLoaderManager().restartLoader(1, null, mLoaderCallback); // 扫描手机中的图片
147 | }
148 |
149 | }
150 | /*
151 | * ┏┓ ┏┓
152 | * ┏┛┻━━━┛┻┓
153 | * ┃ ┃
154 | * ┃ ━ ┃
155 | * ┃ ┳┛ ┗┳ ┃
156 | * ┃ ┃
157 | * ┃ ┻ ┃
158 | * ┃ ┃
159 | * ┗━┓ ┏━┛
160 | * ┃ ┃
161 | * ┃ ┃
162 | * ┃ ┗━━━┓
163 | * ┃ ┣┓
164 | * ┃ ┏┛
165 | * ┗┓┓┏━┳┓┏┛
166 | * ┃┫┫ ┃┫┫
167 | * ┗┻┛ ┗┻┛
168 | * 神兽保佑
169 | * 代码无BUG!
170 | */
--------------------------------------------------------------------------------
/gallerypick/src/main/res/anim/in_fade.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
--------------------------------------------------------------------------------
/gallerypick/src/main/res/anim/out_fade.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
--------------------------------------------------------------------------------
/gallerypick/src/main/res/layout/gallery_item_camera.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
20 |
--------------------------------------------------------------------------------
/gallerypick/src/main/res/layout/gallery_item_folder.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
15 |
25 |
26 |
37 |
38 |
48 |
49 |
50 |
55 |
56 |
--------------------------------------------------------------------------------
/gallerypick/src/main/res/layout/gallery_item_photo.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
14 |
15 |
23 |
24 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/gallerypick/src/main/res/layout/gallery_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
14 |
15 |
16 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/gallerypick/src/main/res/layout/gallery_mini.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
20 |
21 |
29 |
30 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/gallerypick/src/main/res/layout/gallery_mini_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
16 |
17 |
24 |
--------------------------------------------------------------------------------
/gallerypick/src/main/res/layout/gallery_popup_folder.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
--------------------------------------------------------------------------------
/gallerypick/src/main/res/layout/gallery_title.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
18 |
19 |
20 |
21 |
32 |
33 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-hdpi/gallery_pick_back_black.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-hdpi/gallery_pick_back_black.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-hdpi/gallery_pick_back_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-hdpi/gallery_pick_back_white.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-hdpi/gallery_pick_camera.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-hdpi/gallery_pick_camera.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-hdpi/gallery_pick_dropdown_black.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-hdpi/gallery_pick_dropdown_black.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-hdpi/gallery_pick_dropdown_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-hdpi/gallery_pick_dropdown_white.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-hdpi/gallery_pick_photo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-hdpi/gallery_pick_photo.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-hdpi/gallery_pick_select_checked.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-hdpi/gallery_pick_select_checked.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-hdpi/gallery_pick_select_unchecked.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-hdpi/gallery_pick_select_unchecked.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-hdpi/gallery_pick_selected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-hdpi/gallery_pick_selected.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-mdpi/gallery_pick_back_black.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-mdpi/gallery_pick_back_black.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-mdpi/gallery_pick_back_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-mdpi/gallery_pick_back_white.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-mdpi/gallery_pick_camera.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-mdpi/gallery_pick_camera.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-mdpi/gallery_pick_dropdown_black.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-mdpi/gallery_pick_dropdown_black.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-mdpi/gallery_pick_dropdown_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-mdpi/gallery_pick_dropdown_white.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-mdpi/gallery_pick_photo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-mdpi/gallery_pick_photo.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-mdpi/gallery_pick_select_checked.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-mdpi/gallery_pick_select_checked.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-mdpi/gallery_pick_select_unchecked.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-mdpi/gallery_pick_select_unchecked.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-mdpi/gallery_pick_selected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-mdpi/gallery_pick_selected.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-xhdpi/gallery_pick_back_black.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-xhdpi/gallery_pick_back_black.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-xhdpi/gallery_pick_back_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-xhdpi/gallery_pick_back_white.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-xhdpi/gallery_pick_camera.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-xhdpi/gallery_pick_camera.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-xhdpi/gallery_pick_dropdown_black.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-xhdpi/gallery_pick_dropdown_black.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-xhdpi/gallery_pick_dropdown_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-xhdpi/gallery_pick_dropdown_white.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-xhdpi/gallery_pick_photo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-xhdpi/gallery_pick_photo.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-xhdpi/gallery_pick_select_checked.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-xhdpi/gallery_pick_select_checked.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-xhdpi/gallery_pick_select_unchecked.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-xhdpi/gallery_pick_select_unchecked.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-xhdpi/gallery_pick_selected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-xhdpi/gallery_pick_selected.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-xxhdpi/gallery_pick_back_black.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-xxhdpi/gallery_pick_back_black.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-xxhdpi/gallery_pick_back_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-xxhdpi/gallery_pick_back_white.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-xxhdpi/gallery_pick_camera.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-xxhdpi/gallery_pick_camera.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-xxhdpi/gallery_pick_dropdown_black.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-xxhdpi/gallery_pick_dropdown_black.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-xxhdpi/gallery_pick_dropdown_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-xxhdpi/gallery_pick_dropdown_white.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-xxhdpi/gallery_pick_photo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-xxhdpi/gallery_pick_photo.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-xxhdpi/gallery_pick_select_checked.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-xxhdpi/gallery_pick_select_checked.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-xxhdpi/gallery_pick_select_unchecked.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-xxhdpi/gallery_pick_select_unchecked.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-xxhdpi/gallery_pick_selected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-xxhdpi/gallery_pick_selected.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-xxxhdpi/gallery_pick_back_black.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-xxxhdpi/gallery_pick_back_black.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-xxxhdpi/gallery_pick_back_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-xxxhdpi/gallery_pick_back_white.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-xxxhdpi/gallery_pick_camera.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-xxxhdpi/gallery_pick_camera.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-xxxhdpi/gallery_pick_dropdown_black.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-xxxhdpi/gallery_pick_dropdown_black.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-xxxhdpi/gallery_pick_dropdown_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-xxxhdpi/gallery_pick_dropdown_white.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-xxxhdpi/gallery_pick_photo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-xxxhdpi/gallery_pick_photo.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-xxxhdpi/gallery_pick_select_checked.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-xxxhdpi/gallery_pick_select_checked.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-xxxhdpi/gallery_pick_select_unchecked.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-xxxhdpi/gallery_pick_select_unchecked.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/mipmap-xxxhdpi/gallery_pick_selected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gallerypick/src/main/res/mipmap-xxxhdpi/gallery_pick_selected.png
--------------------------------------------------------------------------------
/gallerypick/src/main/res/values-v19/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/gallerypick/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/gallerypick/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | #88000000
5 |
6 | #FF343535
7 |
8 |
9 | #f7eee3
10 |
11 | #FFDCDCDC
12 |
13 | #FF999999
14 |
15 | #FF333333
16 | #88FFFFFF
17 |
18 |
19 | #FFFFFFFF
20 | #000000
21 | #00FF00
22 | #0000FF
23 | #FFFF00
24 | #FF0000
25 | #FF6600
26 |
27 |
--------------------------------------------------------------------------------
/gallerypick/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | 所有图片
3 | 拍摄照片
4 | ( %1$d / %2$d )完成
5 | 相册
6 | 发送
7 | 没有系统相机
8 | 文件夹名
9 | %d 张
10 |
11 |
12 |
--------------------------------------------------------------------------------
/gallerypick/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
13 |
14 |
15 |
16 |
20 |
21 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whaoming/WebViewCacheModule/dfa15c396118ff22402221b4f1208e6ebe856f4d/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':gallerypick'
2 |
--------------------------------------------------------------------------------