Commit 14ee710a by 郭倩芳

1.1 相册选择 可以根据Uri加载

parent 6d225728
...@@ -3,6 +3,12 @@ ...@@ -3,6 +3,12 @@
package="com.sobot.moduletest"> package="com.sobot.moduletest">
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<!-- To handle the reselection within the app on Android 14 (API level 34) -->
<uses-permission android:name="android.permission.READ_MEDIA_VISUAL_USER_SELECTED" />
<application <application
android:name=".MyApp" android:name=".MyApp"
......
...@@ -14,22 +14,7 @@ android { ...@@ -14,22 +14,7 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8
} }
buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
consumerProguardFiles 'proguard-rules.pro'
}
qa_test {
}
qa_api {
}
}
} }
dependencies { dependencies {
......
...@@ -10,8 +10,12 @@ public class SobotMediaLoader implements AlbumLoader { ...@@ -10,8 +10,12 @@ public class SobotMediaLoader implements AlbumLoader {
@Override @Override
public void load(ImageView imageView, AlbumFile albumFile) { public void load(ImageView imageView, AlbumFile albumFile) {
if (albumFile != null && SobotStringUtils.isNoEmpty(albumFile.getPath())) { if (albumFile != null) {
load(imageView, albumFile.getPath()); if (albumFile.getUri() != null) {
load(imageView, albumFile.getUri());
} else {
load(imageView, albumFile.getPath());
}
} }
} }
...@@ -23,9 +27,9 @@ public class SobotMediaLoader implements AlbumLoader { ...@@ -23,9 +27,9 @@ public class SobotMediaLoader implements AlbumLoader {
} }
public void load(ImageView imageView, Uri uri) { public void load(ImageView imageView, Uri uri) {
// if (uri != null && imageView != null) { if (uri != null && imageView != null) {
// imageView.setImageURI(uri); SobotBitmapUtil.display(imageView.getContext(), uri, imageView);
// } }
} }
} }
\ No newline at end of file
...@@ -32,7 +32,7 @@ dependencies { ...@@ -32,7 +32,7 @@ dependencies {
compileOnly 'com.github.bumptech.glide:glide:3.8.0' compileOnly 'com.github.bumptech.glide:glide:3.8.0'
compileOnly 'com.squareup.picasso:picasso:2.8' compileOnly 'com.squareup.picasso:picasso:2.8'
compileOnly 'com.facebook.fresco:fresco:2.6.0' compileOnly 'com.facebook.fresco:fresco:2.6.0'
api 'com.sobot.chat:sobotsupport-glidev4:1.0' api 'com.sobot.chat:sobotsupport-glidev4:3.0'
} }
//添加发布到mavenCentral脚本 //添加发布到mavenCentral脚本
......
...@@ -3,6 +3,7 @@ package com.sobot.pictureframe; ...@@ -3,6 +3,7 @@ package com.sobot.pictureframe;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.ImageView; import android.widget.ImageView;
...@@ -73,6 +74,11 @@ public class SobotBitmapUtil { ...@@ -73,6 +74,11 @@ public class SobotBitmapUtil {
getImageLoader().displayImage(context, imageView, resourceId, 0, 0, imageView.getWidth(), imageView.getHeight(), null); getImageLoader().displayImage(context, imageView, resourceId, 0, 0, imageView.getWidth(), imageView.getHeight(), null);
} }
} }
public static void display(Context context, Uri uri, ImageView imageView) {
if (context != null && imageView != null) {
getImageLoader().displayImage(context, imageView, uri, 0, 0, imageView.getWidth(), imageView.getHeight(), null);
}
}
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public static Bitmap compress(String filePath, Context context, boolean isCamera) { public static Bitmap compress(String filePath, Context context, boolean isCamera) {
......
...@@ -83,6 +83,55 @@ public class SobotFrescoImageLoader extends SobotImageLoader { ...@@ -83,6 +83,55 @@ public class SobotFrescoImageLoader extends SobotImageLoader {
dataSource.subscribe(subscriber, UiThreadImmediateExecutorService.getInstance()); dataSource.subscribe(subscriber, UiThreadImmediateExecutorService.getInstance());
} }
@Override
public void displayImage(Context context, final ImageView imageView, final Uri imgUri, @DrawableRes int loadingResId, @DrawableRes int failResId, int width, int height, final SobotDisplayImageListener listener) {
if (null == imgUri) {
return;
}
if (imageView == null) {
return;
}
ImageRequestBuilder builder = ImageRequestBuilder.newBuilderWithSource(imgUri);
if (width > 0 && height > 0) {
builder.setResizeOptions(new ResizeOptions(width, height));
}
ImageRequest imageRequest = builder.build();
ImagePipeline imagePipeline = Fresco.getImagePipeline();
DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, context);
BaseBitmapDataSubscriber subscriber = new BaseBitmapDataSubscriber() {
@Override
public void onNewResultImpl(@Nullable Bitmap bitmap) {
new AsyncTask<Bitmap, Void, Bitmap>() {
@Override
protected Bitmap doInBackground(Bitmap... params) {
Bitmap bitmap = params[0];
Bitmap result = null;
if (bitmap != null && !bitmap.isRecycled()) {
result = bitmap.copy(Bitmap.Config.RGB_565, false);
}
return result;
}
@Override
protected void onPostExecute(Bitmap bitmap) {
if (bitmap != null) {
imageView.setImageBitmap(bitmap);
} else {
}
}
}.execute(bitmap);
}
@Override
public void onFailureImpl(DataSource dataSource) {
}
};
dataSource.subscribe(subscriber, UiThreadImmediateExecutorService.getInstance());
}
@Override @Override
public void displayImage(Context context, final ImageView imageView, @DrawableRes int targetResId, @DrawableRes int loadingResId, @DrawableRes int failResId, int width, int height, final SobotDisplayImageListener listener) { public void displayImage(Context context, final ImageView imageView, @DrawableRes int targetResId, @DrawableRes int loadingResId, @DrawableRes int failResId, int width, int height, final SobotDisplayImageListener listener) {
......
...@@ -3,6 +3,8 @@ package com.sobot.pictureframe; ...@@ -3,6 +3,8 @@ package com.sobot.pictureframe;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import androidx.annotation.DrawableRes; import androidx.annotation.DrawableRes;
import android.net.Uri;
import android.text.TextUtils; import android.text.TextUtils;
import android.widget.ImageView; import android.widget.ImageView;
...@@ -44,6 +46,34 @@ public class SobotGlideImageLoader extends SobotImageLoader { ...@@ -44,6 +46,34 @@ public class SobotGlideImageLoader extends SobotImageLoader {
} }
}).into(imageView); }).into(imageView);
} }
@Override
public void displayImage(Context context, final ImageView imageView, final Uri imgUri, @DrawableRes int loadingResId, @DrawableRes int failResId, int width, int height, final SobotDisplayImageListener listener) {
if (null == imgUri) {
return;
}
if (imageView == null) {
return;
}
BitmapRequestBuilder<Uri, Bitmap> builder = Glide.with(context).load(imgUri).asBitmap().placeholder(loadingResId).error(failResId);
if (width != 0 || height != 0) {
builder.override(width, height);
}
builder.listener(new RequestListener<Object, Bitmap>() {
@Override
public boolean onException(Exception e, Object model, Target<Bitmap> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, boolean isFromMemoryCache, boolean isFirstResource) {
if (listener != null) {
listener.onSuccess(imageView, imgUri.getPath());
}
return false;
}
}).into(imageView);
}
@Override @Override
public void displayImage(Context context, final ImageView imageView, @DrawableRes int targetResId, @DrawableRes int loadingResId, @DrawableRes int failResId, int width, int height, final SobotDisplayImageListener listener) { public void displayImage(Context context, final ImageView imageView, @DrawableRes int targetResId, @DrawableRes int loadingResId, @DrawableRes int failResId, int width, int height, final SobotDisplayImageListener listener) {
......
...@@ -2,6 +2,7 @@ package com.sobot.pictureframe; ...@@ -2,6 +2,7 @@ package com.sobot.pictureframe;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.net.Uri;
import android.text.TextUtils; import android.text.TextUtils;
import android.widget.ImageView; import android.widget.ImageView;
...@@ -55,6 +56,33 @@ public class SobotPicassoImageLoader extends SobotImageLoader { ...@@ -55,6 +56,33 @@ public class SobotPicassoImageLoader extends SobotImageLoader {
} }
}); });
} }
@Override
public void displayImage(Context context, final ImageView imageView, final Uri imgUri, int loadingResId, int failResId, int width, int height, final SobotDisplayImageListener listener) {
if (null == imgUri) {
return;
}
RequestCreator creator = Picasso.get().load(imgUri);
if (loadingResId != 0) {
creator.placeholder(loadingResId);
}
if (failResId != 0) {
creator.error(failResId);
}
creator.config(Bitmap.Config.RGB_565);
if (width != 0 || height != 0) {
creator.resize(width, height);
} else {
creator.fit();
}
creator.into(imageView, new Callback.EmptyCallback() {
@Override
public void onSuccess() {
if (listener != null) {
listener.onSuccess(imageView, imgUri.getPath());
}
}
});
}
@Override @Override
public void displayImage(Context context, final ImageView imageView, int targetResId, int loadingResId, int failResId, int width, int height, final SobotDisplayImageListener listener) { public void displayImage(Context context, final ImageView imageView, int targetResId, int loadingResId, int failResId, int width, int height, final SobotDisplayImageListener listener) {
......
...@@ -3,6 +3,8 @@ package com.sobot.pictureframe; ...@@ -3,6 +3,8 @@ package com.sobot.pictureframe;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import androidx.annotation.DrawableRes; import androidx.annotation.DrawableRes;
import android.net.Uri;
import android.view.View; import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
...@@ -50,6 +52,29 @@ public class SobotUILImageLoader extends SobotImageLoader { ...@@ -50,6 +52,29 @@ public class SobotUILImageLoader extends SobotImageLoader {
} }
}, null); }, null);
} }
@Override
public void displayImage(Context context, ImageView imageView, Uri imgUri, @DrawableRes int loadingResId, @DrawableRes int failResId, int width, int height, final SobotDisplayImageListener listener) {
initImageLoader(context);
DisplayImageOptions options = new DisplayImageOptions.Builder()
.showImageOnLoading(loadingResId)
.showImageOnFail(failResId)
.showImageForEmptyUri(failResId)
.cacheInMemory(true)
.cacheOnDisk(true)
.bitmapConfig(Bitmap.Config.RGB_565)
.build();
ImageSize imageSize = width != 0 || height != 0 ? new ImageSize(width, height) : null;
ImageLoader.getInstance().displayImage(imgUri, new ImageViewAware(imageView), options, imageSize, new SimpleImageLoadingListener() {
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
if (listener != null) {
listener.onSuccess(view, imageUri);
}
}
}, null);
}
@Override @Override
public void displayImage(Context context, ImageView imageView, @DrawableRes int targetResId, @DrawableRes int loadingResId, @DrawableRes int failResId, int width, int height, final SobotDisplayImageListener listener) { public void displayImage(Context context, ImageView imageView, @DrawableRes int targetResId, @DrawableRes int loadingResId, @DrawableRes int failResId, int width, int height, final SobotDisplayImageListener listener) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment