Commit f59ad090 by 郭倩芳

修改 相册预览图显示不全

parent e52c69cf
...@@ -22,7 +22,7 @@ dependencies { ...@@ -22,7 +22,7 @@ dependencies {
compileOnly 'androidx.recyclerview:recyclerview:1.0.0' compileOnly 'androidx.recyclerview:recyclerview:1.0.0'
compileOnly 'com.google.android.material:material:1.4.0' compileOnly 'com.google.android.material:material:1.4.0'
api 'com.sobot.library:widget_x:1.2.7' api 'com.sobot.library:widget_x:1.2.7'
api 'com.sobot.library:picture_x:1.2.0' api 'com.sobot.library:sobotcommon_x:1.7.7.3'
} }
......
...@@ -12,7 +12,7 @@ task androidSourcesJar(type: Jar) { ...@@ -12,7 +12,7 @@ task androidSourcesJar(type: Jar) {
ext { ext {
PUBLISH_GROUP_ID = "com.sobot.library" //项目包名 PUBLISH_GROUP_ID = "com.sobot.library" //项目包名
PUBLISH_ARTIFACT_ID = 'album' //项目名 PUBLISH_ARTIFACT_ID = 'album' //项目名
PUBLISH_VERSION = '1.0.4.2' //版本号 PUBLISH_VERSION = '1.0.4.4' //版本号
} }
......
package com.sobot.album.app.fragment; package com.sobot.album.app.fragment;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle; import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.SoundEffectConstants;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.RelativeLayout;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
...@@ -16,6 +21,18 @@ import com.sobot.album.R; ...@@ -16,6 +21,18 @@ import com.sobot.album.R;
import com.sobot.album.SobotAlbum; import com.sobot.album.SobotAlbum;
import com.sobot.album.widget.photoview.AttacherImageView; import com.sobot.album.widget.photoview.AttacherImageView;
import com.sobot.album.widget.photoview.PhotoViewAttacher; import com.sobot.album.widget.photoview.PhotoViewAttacher;
import com.sobot.common.utils.SobotImageUtils;
import com.sobot.common.utils.SobotPathManager;
import com.sobot.network.http.HttpBaseUtils;
import com.sobot.pictureframe.SobotBitmapUtil;
import com.sobot.utils.SobotDensityUtil;
import com.sobot.utils.SobotLogUtils;
import com.sobot.utils.SobotMD5Util;
import com.sobot.utils.SobotStringUtils;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
public class ImageFragment extends Fragment implements PhotoViewAttacher.OnViewTapListener, View.OnLongClickListener { public class ImageFragment extends Fragment implements PhotoViewAttacher.OnViewTapListener, View.OnLongClickListener {
private View mRootView; private View mRootView;
...@@ -23,6 +40,8 @@ public class ImageFragment extends Fragment implements PhotoViewAttacher.OnViewT ...@@ -23,6 +40,8 @@ public class ImageFragment extends Fragment implements PhotoViewAttacher.OnViewT
public AlbumFile mAlbum; public AlbumFile mAlbum;
private View.OnClickListener mItemClickListener; private View.OnClickListener mItemClickListener;
private View.OnClickListener mItemLongClickListener; private View.OnClickListener mItemLongClickListener;
private String imageUrL;
private Bitmap bitmap;
@Nullable @Nullable
@Override @Override
...@@ -56,10 +75,93 @@ public class ImageFragment extends Fragment implements PhotoViewAttacher.OnViewT ...@@ -56,10 +75,93 @@ public class ImageFragment extends Fragment implements PhotoViewAttacher.OnViewT
private void initDate() { private void initDate() {
if (mAlbum != null) { if (mAlbum != null) {
SobotAlbum.getAlbumConfig().getAlbumLoader().load(imageView, mAlbum); //设置地址
if (SobotStringUtils.isNoEmpty( mAlbum.getPath())) {
imageUrL = mAlbum.getPath();
} else if(mAlbum.getUri()!=null){
imageUrL = mAlbum.getUri().getPath();
}else{
imageUrL="";
}
if (imageUrL.startsWith("http")) {
String dirPath = SobotPathManager.getInstance().getPicDir();
String encode = SobotMD5Util.encode(imageUrL) + getFileName(imageUrL);
File savePath = new File(SobotStringUtils.checkStringIsNull(dirPath), encode);
if (!savePath.exists()) {
if (imageUrL.contains("?")) {
imageUrL = imageUrL.substring(0, imageUrL.indexOf("?"));
}
displayImage(imageUrL, savePath);
} else {
showView(savePath.getAbsolutePath());
}
} else {
File gifSavePath = new File(imageUrL);
if (gifSavePath.exists()) {
showView(imageUrL);
}
}
}
}
public String getFileName(String filePath) {
try {
if (filePath.indexOf("/") != -1) {
return filePath.substring(filePath.lastIndexOf("/") + 1);
}
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
void showView(String savePath) {
if (!TextUtils.isEmpty(imageUrL)) {
bitmap = SobotBitmapUtil.compress(savePath, getContext(), true);
//判断图片是否有旋转,有的话旋转后再显示
try {
int degree = SobotImageUtils.readPictureDegree(savePath);
if (degree > 0) {
bitmap = SobotImageUtils.rotateBitmap(bitmap, degree);
}
} catch (Exception e) {
e.printStackTrace();
}
if (bitmap != null) {
imageView.setImageBitmap(bitmap);
}
imageView.setVisibility(View.VISIBLE);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
imageView.playSoundEffect(SoundEffectConstants.CLICK);
}
});
} }
} }
public void displayImage(String url, File saveFile) {
// 下载图片
HttpBaseUtils.getInstance().download(url, saveFile, new HttpBaseUtils.FileCallBack() {
@Override
public void onResponse(File file) {
SobotLogUtils.i("down load onSuccess gif"
+ file.getAbsolutePath());
// 把图片文件打开为文件流,然后解码为bitmap
showView(file.getAbsolutePath());
}
@Override
public void onError(Exception e, String msg, int responseCode) {
SobotLogUtils.w("图片下载失败:" + msg, e);
}
@Override
public void inProgress(int progress) {
//SobotLogUtils.i("图片下载进度:" + progress);
}
});
}
@Override @Override
public void onViewTap(View v, float x, float y) { public void onViewTap(View v, float x, float y) {
if (mItemClickListener != null) { if (mItemClickListener != null) {
......
...@@ -18,16 +18,10 @@ package com.sobot.album.app.preview; ...@@ -18,16 +18,10 @@ package com.sobot.album.app.preview;
import android.app.Activity; import android.app.Activity;
import android.net.Uri; import android.net.Uri;
import android.os.Handler; import android.os.Handler;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.CheckBox;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
...@@ -37,7 +31,6 @@ import androidx.viewpager.widget.ViewPager; ...@@ -37,7 +31,6 @@ import androidx.viewpager.widget.ViewPager;
import com.sobot.album.AlbumFile; import com.sobot.album.AlbumFile;
import com.sobot.album.R; import com.sobot.album.R;
import com.sobot.album.SobotAlbum;
import com.sobot.album.api.widget.Widget; import com.sobot.album.api.widget.Widget;
import com.sobot.album.app.Contract; import com.sobot.album.app.Contract;
import com.sobot.album.app.fragment.ImageFragment; import com.sobot.album.app.fragment.ImageFragment;
......
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