Skip to content

Commit c8ae690

Browse files
author
sherlock
committed
Merge branch 'dev'
2 parents c645606 + dc15770 commit c8ae690

21 files changed

+489
-119
lines changed

app/build.gradle

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
apply plugin: 'com.android.application'
22
android {
3-
compileSdkVersion 26
4-
buildToolsVersion "26.0.1"
3+
compileSdkVersion 28
54
defaultConfig {
65
applicationId "xyz.zpayh.original"
76
minSdkVersion 16
8-
targetSdkVersion 26
7+
targetSdkVersion 28
98
versionCode 1
109
versionName "1.0"
1110
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@@ -28,15 +27,16 @@ dependencies {
2827
exclude group: 'com.android.support', module: 'support-annotations'
2928
})
3029
compile project(':library')
31-
compile 'com.android.support:appcompat-v7:26.0.+'
32-
compile 'com.android.support.constraint:constraint-layout:1.0.2'
33-
compile 'com.android.support:design:26.0.+'
30+
compile 'com.android.support:appcompat-v7:28.0.0'
31+
compile 'com.android.support.constraint:constraint-layout:1.1.3'
32+
compile 'com.android.support:design:28.0.0'
3433
compile 'xyz.zpayh:sherlockadapter:1.0.9'
3534
testCompile 'junit:junit:4.12'
36-
compile 'com.android.support:cardview-v7:26.0.+'
35+
compile 'com.android.support:cardview-v7:28.0.0'
3736
compile 'com.facebook.fresco:imagepipeline:1.4.0'
38-
compile project(':support-fresco')
37+
//compile project(':support-fresco')
3938
//compile project(':support-glide')
40-
compile 'xyz.zpayh:hdimageview-glide:2.0.0'
41-
compile 'com.github.bumptech.glide:glide:4.0.0'
39+
//compile 'xyz.zpayh:hdimageview-glide:2.0.0'
40+
compile 'com.github.bumptech.glide:glide:4.8.0'
41+
compile 'com.android.support:exifinterface:28.0.0'
4242
}
Lines changed: 155 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,48 @@
11
package xyz.zpayh.original;
22

33
import android.app.Application;
4+
import android.content.Context;
5+
import android.graphics.BitmapRegionDecoder;
6+
import android.net.Uri;
7+
import android.support.annotation.NonNull;
8+
import android.support.media.ExifInterface;
9+
import android.util.Log;
410

11+
import com.bumptech.glide.Glide;
12+
import com.bumptech.glide.RequestManager;
13+
import com.bumptech.glide.request.FutureTarget;
14+
import com.facebook.binaryresource.BinaryResource;
15+
import com.facebook.binaryresource.FileBinaryResource;
16+
import com.facebook.cache.common.CacheKey;
17+
import com.facebook.common.internal.Closeables;
18+
import com.facebook.common.memory.PooledByteBuffer;
19+
import com.facebook.common.memory.PooledByteBufferInputStream;
20+
import com.facebook.common.references.CloseableReference;
21+
import com.facebook.datasource.DataSource;
22+
import com.facebook.datasource.DataSources;
23+
import com.facebook.imagepipeline.cache.DefaultCacheKeyFactory;
24+
import com.facebook.imagepipeline.core.ImagePipeline;
525
import com.facebook.imagepipeline.core.ImagePipelineFactory;
26+
import com.facebook.imagepipeline.request.ImageRequest;
27+
28+
import java.io.File;
29+
import java.io.FileInputStream;
30+
import java.io.IOException;
31+
import java.io.InputStream;
32+
33+
import xyz.zpayh.hdimage.core.HDImageViewConfig;
34+
import xyz.zpayh.hdimage.core.HDImageViewFactory;
35+
import xyz.zpayh.hdimage.datasource.Interceptor;
36+
import xyz.zpayh.hdimage.datasource.OrientationInterceptor;
37+
import xyz.zpayh.hdimage.datasource.interceptor.Interceptors;
38+
import xyz.zpayh.hdimage.state.Orientation;
39+
import xyz.zpayh.hdimage.util.Preconditions;
40+
import xyz.zpayh.hdimage.util.UriUtil;
41+
42+
import static xyz.zpayh.hdimage.state.Orientation.ORIENTATION_0;
43+
import static xyz.zpayh.hdimage.state.Orientation.ORIENTATION_180;
44+
import static xyz.zpayh.hdimage.state.Orientation.ORIENTATION_270;
45+
import static xyz.zpayh.hdimage.state.Orientation.ORIENTATION_90;
646

747
/**
848
* 文 件 名: MainApplication
@@ -22,14 +62,114 @@ public void onCreate() {
2262
ImagePipelineFactory.initialize(this);
2363

2464
// 与Fresco加载库结合,共享缓存
25-
//HDImageViewConfig config = HDImageViewConfig.newBuilder(this)
26-
//.addInterceptor(new FrescoInterceptor())
27-
// .addInterceptor(new GlideInterceptor(this))
28-
// .build();
29-
//HDImageViewFactory.initialize(config);
65+
HDImageViewConfig config = HDImageViewConfig.newBuilder(this)
66+
.addInterceptor(new FrescoInterceptor())
67+
//.addInterceptor(new GlideInterceptor(this))
68+
//.addOrientationInterceptor(new GlideOrientationInterceptor(this))
69+
.build();
70+
HDImageViewFactory.initialize(config);
71+
}
72+
73+
public class FrescoInterceptor implements Interceptor {
74+
@Override
75+
public BitmapRegionDecoder intercept(Chain chain) throws IOException {
76+
final Uri uri = chain.uri();
77+
BitmapRegionDecoder decoder = chain.chain(uri);
78+
if (decoder != null){
79+
return decoder;
80+
}
81+
82+
if (com.facebook.common.util.UriUtil.isNetworkUri(uri)){
83+
ImagePipeline imagePipeline = ImagePipelineFactory.getInstance().getImagePipeline();
84+
85+
ImageRequest request = ImageRequest.fromUri(uri);
86+
DataSource<CloseableReference<PooledByteBuffer>> dataSource = imagePipeline.fetchEncodedImage(request,null);
87+
try {
88+
CloseableReference<PooledByteBuffer> ref = DataSources.waitForFinalResult(dataSource);
89+
if (ref == null){
90+
return null;
91+
}
92+
PooledByteBuffer result = ref.get();
93+
if (BuildConfig.DEBUG) {
94+
Log.d("FrescoInterceptor", "从我这加载");
95+
}
96+
try {
97+
InputStream inputStream = new PooledByteBufferInputStream(result);
98+
Closeables.closeQuietly(inputStream);
99+
return BitmapRegionDecoder.newInstance(inputStream,false);
100+
} catch (IOException e) {
101+
e.printStackTrace();
102+
ImageRequest imageRequest=ImageRequest.fromUri(uri);
103+
CacheKey cacheKey= DefaultCacheKeyFactory.getInstance().getEncodedCacheKey(imageRequest,null);
104+
BinaryResource resource = ImagePipelineFactory.getInstance().getMainFileCache().getResource(cacheKey);
105+
File file=((FileBinaryResource)resource).getFile();
106+
if (BuildConfig.DEBUG) {
107+
Log.d("FrescoInterceptor", file.getName());
108+
}
109+
return Interceptors.fixJPEGDecoder(file,e);
110+
}
111+
} catch (Throwable throwable) {
112+
if (BuildConfig.DEBUG) {
113+
Log.d("FrescoInterceptor", "intercept: 加载失败了");
114+
}
115+
throwable.printStackTrace();
116+
return null;
117+
}
118+
}
119+
120+
return null;
121+
}
122+
}
123+
124+
public class GlideOrientationInterceptor implements OrientationInterceptor {
125+
126+
private final RequestManager mRequestManager;
127+
128+
public GlideOrientationInterceptor(Context context) {
129+
Preconditions.checkNotNull(context);
130+
131+
mRequestManager = Glide.with(context);
132+
}
133+
134+
@Override
135+
public int getExifOrientation(@NonNull Context context, String sourceUri) {
136+
int orientation = Orientation.ORIENTATION_EXIF;
137+
Log.d("Sherlock", "从这儿加载: ");
138+
if (UriUtil.isNetworkUri(Uri.parse(sourceUri))) {
139+
FutureTarget<File> target = mRequestManager.downloadOnly().load(Uri.parse(sourceUri)).submit();
140+
try {
141+
File file = target.get();
142+
try {
143+
ExifInterface exifInterface = new ExifInterface(new FileInputStream(file));
144+
int orientationAttr = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,
145+
ExifInterface.ORIENTATION_NORMAL);
146+
if (orientationAttr == ExifInterface.ORIENTATION_NORMAL ||
147+
orientationAttr == ExifInterface.ORIENTATION_UNDEFINED) {
148+
orientation = ORIENTATION_0;
149+
} else if (orientationAttr == ExifInterface.ORIENTATION_ROTATE_90) {
150+
orientation = ORIENTATION_90;
151+
} else if (orientationAttr == ExifInterface.ORIENTATION_ROTATE_180) {
152+
orientation = ORIENTATION_180;
153+
} else if (orientationAttr == ExifInterface.ORIENTATION_ROTATE_270) {
154+
orientation = ORIENTATION_270;
155+
} else {
156+
Log.w("Sherlock", "Unsupported EXIF orientation: " + orientationAttr);
157+
}
158+
} catch (IOException e) {
159+
e.printStackTrace();
160+
Log.w("Sherlock", "Could not get EXIF orientation of image");
161+
}
162+
} catch (Exception e) {
163+
e.printStackTrace();
164+
}
165+
mRequestManager.clear(target);
166+
}
167+
Log.d("Sherlock", "返回了:"+orientation);
168+
return orientation;
169+
}
30170
}
31171

32-
/*public class GlideInterceptor implements Interceptor {
172+
public class GlideInterceptor implements Interceptor {
33173

34174
private final RequestManager mRequestManager;
35175

@@ -51,36 +191,20 @@ public BitmapRegionDecoder intercept(Chain chain) throws IOException {
51191
FutureTarget<File> target = mRequestManager.downloadOnly().load(uri).submit();
52192
try {
53193
File file = target.get();
54-
Log.d("GlideInterceptor", "用GlideInterceptor加载回来"+file.getAbsolutePath());
55-
FileInputStream inputStream = new FileInputStream(file);
56-
test(inputStream);
57-
decoder = BitmapRegionDecoder.newInstance(new FileInputStream(file),false);
58-
} catch (InterruptedException e) {
59-
e.printStackTrace();
60-
} catch (ExecutionException e) {
194+
try {
195+
Log.d("GlideInterceptor", "用GlideInterceptor加载回来"+file.getAbsolutePath());
196+
decoder = BitmapRegionDecoder.newInstance(new FileInputStream(file),false);
197+
} catch (IOException e) {
198+
e.printStackTrace();
199+
return Interceptors.fixJPEGDecoder(file, e);
200+
}
201+
202+
} catch (Exception e) {
61203
e.printStackTrace();
62204
}
63205
mRequestManager.clear(target);
64206
}
65207
return decoder;
66208
}
67209
}
68-
69-
private void test(FileInputStream inputStream) throws IOException{
70-
ExifInterface exifInterface = new ExifInterface(inputStream);
71-
Log.d("Application",""+exifInterface.getAttribute(ExifInterface.TAG_COLOR_SPACE));
72-
Log.d("Application",""+exifInterface.getAttribute(ExifInterface.TAG_APERTURE_VALUE));
73-
Log.d("Application",""+exifInterface.getAttribute(ExifInterface.TAG_ARTIST));
74-
Log.d("Application",""+exifInterface.getAttribute(ExifInterface.TAG_BITS_PER_SAMPLE));
75-
Log.d("Application",""+exifInterface.getAttribute(ExifInterface.TAG_BRIGHTNESS_VALUE));
76-
Log.d("Application",""+exifInterface.getAttribute(ExifInterface.TAG_CFA_PATTERN));
77-
Log.d("Application",""+exifInterface.getAttribute(ExifInterface.TAG_COMPONENTS_CONFIGURATION));
78-
Log.d("Application",""+exifInterface.getAttribute(ExifInterface.TAG_COMPRESSED_BITS_PER_PIXEL));
79-
Log.d("Application",""+exifInterface.getAttribute(ExifInterface.TAG_COMPRESSION));
80-
Log.d("Application",""+exifInterface.getAttribute(ExifInterface.TAG_CONTRAST));
81-
Log.d("Application",""+exifInterface.getAttribute(ExifInterface.TAG_COPYRIGHT));
82-
Log.d("Application",""+exifInterface.getAttribute(ExifInterface.TAG_CUSTOM_RENDERED));
83-
Log.d("Application",""+exifInterface.getAttribute(ExifInterface.TAG_CUSTOM_RENDERED));
84-
Log.d("Application",""+exifInterface.getAttribute(ExifInterface.TAG_DATETIME));
85-
}*/
86210
}

build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
buildscript {
44
repositories {
55
jcenter()
6+
google()
67
}
78
dependencies {
8-
classpath 'com.android.tools.build:gradle:2.3.3'
9-
classpath 'com.novoda:bintray-release:0.4.0'
9+
classpath 'com.android.tools.build:gradle:3.1.4'
10+
classpath 'com.novoda:bintray-release:0.8.0'
1011
// NOTE: Do not place your application dependencies here; they belong
1112
// in the individual module build.gradle files
1213
}
@@ -15,6 +16,7 @@ buildscript {
1516
allprojects {
1617
repositories {
1718
jcenter()
19+
google()
1820
}
1921
tasks.withType(Javadoc) {
2022
options.addStringOption('encoding', 'UTF-8')
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Sat Apr 01 14:38:30 CST 2017
1+
#Tue Dec 04 17:07:21 CST 2018
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

library/build.gradle

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
apply plugin: 'com.android.library'
2-
//apply plugin: 'com.novoda.bintray-release'
2+
apply plugin: 'com.novoda.bintray-release'
33
android {
4-
compileSdkVersion 25
5-
buildToolsVersion "25.0.3"
4+
compileSdkVersion 28
65

76
defaultConfig {
8-
minSdkVersion 10
9-
targetSdkVersion 25
10-
versionCode 6
11-
versionName "1.0.6"
7+
minSdkVersion 14
8+
targetSdkVersion 28
9+
versionCode 7
10+
versionName "1.0.7"
1211

1312
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1413

@@ -25,21 +24,22 @@ android {
2524
}
2625

2726
dependencies {
28-
compile fileTree(include: ['*.jar'], dir: 'libs')
29-
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
27+
implementation fileTree(include: ['*.jar'], dir: 'libs')
28+
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
3029
exclude group: 'com.android.support', module: 'support-annotations'
3130
})
32-
testCompile 'junit:junit:4.12'
33-
compile 'com.android.support:support-annotations:25.3.1'
31+
testImplementation 'junit:junit:4.12'
32+
implementation 'com.android.support:support-annotations:28.0.0'
33+
implementation 'com.android.support:exifinterface:28.0.0'
3434
}
3535

3636
// jcenter configuration for novoda's bintray-release
3737
// $ ./gradlew clean build bintrayUpload -PbintrayUser=BINTRAY_USERNAME -PbintrayKey=BINTRAY_KEY -PdryRun=false
38-
/*publish {
38+
publish {
3939
userOrg = 'sherlock' //bintray注册的用户名
4040
groupId = 'xyz.zpayh' //compile引用时的第1部分groupId
4141
artifactId = 'hdimageview' //compile引用时的第2部分项目名
42-
publishVersion = '2.0.0' //compile引用时的第3部分版本号
42+
publishVersion = '2.1.0' //compile引用时的第3部分版本号
4343
desc = 'This is a high-definition picture control that supports zooming'
4444
website = 'https://github.com/EvilBT/HDImageView'
45-
}*/
45+
}

library/src/main/java/xyz/zpayh/hdimage/HDImageView.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@
8686
import static xyz.zpayh.hdimage.state.Zoom.ZOOM_FOCUS_CENTER_IMMEDIATE;
8787
import static xyz.zpayh.hdimage.state.Zoom.ZOOM_FOCUS_FIXED;
8888
import static xyz.zpayh.hdimage.util.Utils.fileRect;
89-
import static xyz.zpayh.hdimage.util.Utils.getExifOrientation;
9089

9190
/**
9291
* 文 件 名: OriginalImageView
@@ -1935,7 +1934,7 @@ public void run() {
19351934
mDecoder.init(mContext, mUri, dimensions, new BitmapDataSource.OnInitListener() {
19361935
@Override
19371936
public void success() {
1938-
int exifOrientation = getExifOrientation(mContext,mUri.toString());
1937+
int exifOrientation = mBitmapDataSource.getExifOrientation(mContext,mUri.toString());
19391938
Bundle bundle = new Bundle();
19401939
bundle.putInt(SOURCE_ORIENTATION,exifOrientation);
19411940
Message msg = Message.obtain();

0 commit comments

Comments
 (0)