Commit 2be20c329965a40939b825ce35a98dde82bf8c70
1 parent
496a2d8b
图片全屏预览长按功能动态隐藏显示
Showing
11 changed files
with
1255 additions
and
61 deletions
app/strike/src/main/java/com/cnlive/strike/imgutil/ImgActivity.java
| ... | ... | @@ -17,12 +17,10 @@ import com.bumptech.glide.load.DecodeFormat; |
| 17 | 17 | import com.bumptech.glide.load.engine.DiskCacheStrategy; |
| 18 | 18 | import com.bumptech.glide.request.RequestOptions; |
| 19 | 19 | import com.bumptech.glide.request.transition.ViewPropertyTransition; |
| 20 | -import com.cnlive.core.activity.PreviewImageActivity; | |
| 21 | 20 | import com.cnlive.core.imageload.callback.ImageDownLoadCallBack; |
| 22 | 21 | import com.cnlive.core.imageload.config.PriorityMode; |
| 23 | 22 | import com.cnlive.core.imageload.config.ScaleMode; |
| 24 | 23 | import com.cnlive.core.imageload.loader.ImageLoader; |
| 25 | -import com.cnlive.core.imageload.preview.PreviewImageViewActivity; | |
| 26 | 24 | import com.cnlive.core.imageload.preview.model.ImagePreviewShowInfo; |
| 27 | 25 | import com.cnlive.core.imageload.preview.model.PreviewData; |
| 28 | 26 | import com.cnlive.core.imageload.util.DownLoadImageService; |
| ... | ... | @@ -30,7 +28,6 @@ import com.cnlive.cloud.R; |
| 30 | 28 | import com.cnlive.cloud.user.auth.UserService; |
| 31 | 29 | |
| 32 | 30 | import java.util.ArrayList; |
| 33 | -import java.util.List; | |
| 34 | 31 | |
| 35 | 32 | public class ImgActivity extends AppCompatActivity { |
| 36 | 33 | |
| ... | ... | @@ -92,14 +89,14 @@ public class ImgActivity extends AppCompatActivity { |
| 92 | 89 | |
| 93 | 90 | findViewById(R.id.simpla_see).setOnClickListener(view -> startActivity(new Intent(this,SimplePrevActivity.class))); |
| 94 | 91 | findViewById(R.id.pre_btn).setOnClickListener(view -> { |
| 95 | - ArrayList<String> list = new ArrayList<>(); | |
| 96 | - list.add("https://b-ssl.duitang.com/uploads/item/201505/09/20150509221719_kyNrM.jpeg"); | |
| 97 | - list.add("https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1035013881,3985887911&fm=26&gp=0.gif"); | |
| 98 | - list.add("https://b-ssl.duitang.com/uploads/item/201505/11/20150511122951_MAwVZ.jpeg"); | |
| 99 | - list.add("https://b-ssl.duitang.com/uploads/item/201704/23/20170423205828_BhNSv.jpeg"); | |
| 100 | - ARouter.getInstance().build("/preview/PreviewImageActivity") | |
| 101 | - .withStringArrayList("paths", list) | |
| 102 | - .navigation(this); | |
| 92 | +// ArrayList<String> list = new ArrayList<>(); | |
| 93 | +// list.add("https://b-ssl.duitang.com/uploads/item/201505/09/20150509221719_kyNrM.jpeg"); | |
| 94 | +// list.add("https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1035013881,3985887911&fm=26&gp=0.gif"); | |
| 95 | +// list.add("https://b-ssl.duitang.com/uploads/item/201505/11/20150511122951_MAwVZ.jpeg"); | |
| 96 | +// list.add("https://b-ssl.duitang.com/uploads/item/201704/23/20170423205828_BhNSv.jpeg"); | |
| 97 | +// ARouter.getInstance().build("/preview/PreViewImageActivity") | |
| 98 | +// .withStringArrayList("paths", list) | |
| 99 | +// .navigation(this); | |
| 103 | 100 | }); |
| 104 | 101 | } |
| 105 | 102 | ... | ... |
core/imageload/src/main/AndroidManifest.xml
| ... | ... | @@ -3,7 +3,7 @@ |
| 3 | 3 | package="com.cnlive.core.imageload"> |
| 4 | 4 | |
| 5 | 5 | <application> |
| 6 | - <activity android:name="com.cnlive.core.activity.PreviewImageActivity" | |
| 6 | + <activity android:name="com.cnlive.core.ui.activity.PreViewImageActivity" | |
| 7 | 7 | android:configChanges="keyboardHidden|screenSize|smallestScreenSize|screenLayout|orientation" |
| 8 | 8 | android:launchMode="singleTop" |
| 9 | 9 | android:theme="@style/PreviewTheme"/> | ... | ... |
core/imageload/src/main/java/com/cnlive/core/imageload/preview/model/PreviewData.java
| ... | ... | @@ -8,15 +8,8 @@ import java.util.ArrayList; |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | 10 | public class PreviewData implements Serializable { |
| 11 | - public String getCollectionType() { | |
| 12 | - return collectionType; | |
| 13 | - } | |
| 14 | - | |
| 15 | - public void setCollectionType(String collectionType) { | |
| 16 | - this.collectionType = collectionType; | |
| 17 | - } | |
| 18 | 11 | |
| 19 | - // moment/sub | |
| 12 | + //moment/sub | |
| 20 | 13 | private String collectionType; |
| 21 | 14 | private String sid; |
| 22 | 15 | // 0:文本, 1:图片, 2:视频, 3:h5 |
| ... | ... | @@ -44,6 +37,20 @@ public class PreviewData implements Serializable { |
| 44 | 37 | //是否展示转发生活圈(默认展示) |
| 45 | 38 | private boolean isLife = false; |
| 46 | 39 | |
| 40 | + //是否展示扫描二维码 | |
| 41 | + private boolean isScan = true; | |
| 42 | + private boolean isHide; | |
| 43 | + | |
| 44 | + private ArrayList<ImagePreviewShowInfo> picList; | |
| 45 | + | |
| 46 | + public String getCollectionType() { | |
| 47 | + return collectionType; | |
| 48 | + } | |
| 49 | + | |
| 50 | + public void setCollectionType(String collectionType) { | |
| 51 | + this.collectionType = collectionType; | |
| 52 | + } | |
| 53 | + | |
| 47 | 54 | public boolean isScan() { |
| 48 | 55 | return isScan; |
| 49 | 56 | } |
| ... | ... | @@ -52,9 +59,6 @@ public class PreviewData implements Serializable { |
| 52 | 59 | isScan = scan; |
| 53 | 60 | } |
| 54 | 61 | |
| 55 | - //是否展示扫描二维码 | |
| 56 | - private boolean isScan = true; | |
| 57 | - | |
| 58 | 62 | public boolean isFriend() { |
| 59 | 63 | return isFriend; |
| 60 | 64 | } |
| ... | ... | @@ -112,7 +116,6 @@ public class PreviewData implements Serializable { |
| 112 | 116 | isHideDialog = hideDialog; |
| 113 | 117 | } |
| 114 | 118 | |
| 115 | - private ArrayList<ImagePreviewShowInfo> picList; | |
| 116 | 119 | |
| 117 | 120 | public boolean isHide() { |
| 118 | 121 | return isHide; |
| ... | ... | @@ -122,8 +125,6 @@ public class PreviewData implements Serializable { |
| 122 | 125 | isHide = hide; |
| 123 | 126 | } |
| 124 | 127 | |
| 125 | - private boolean isHide; | |
| 126 | - | |
| 127 | 128 | public boolean isCollection() { |
| 128 | 129 | return isCollection; |
| 129 | 130 | } | ... | ... |
core/imageload/src/main/java/com/cnlive/core/activity/PreviewImageActivity.java renamed to core/imageload/src/main/java/com/cnlive/core/ui/activity/PreViewImageActivity.java
| 1 | -package com.cnlive.core.activity; | |
| 1 | +package com.cnlive.core.ui.activity; | |
| 2 | 2 | |
| 3 | +import android.app.Activity; | |
| 4 | +import android.content.Intent; | |
| 5 | +import android.view.View; | |
| 3 | 6 | import android.widget.ImageView; |
| 4 | 7 | |
| 5 | 8 | import com.alibaba.android.arouter.facade.annotation.Route; |
| 6 | 9 | import com.cnlive.core.imageload.R; |
| 7 | -import com.cnlive.core.imagepreview.ImagePreView; | |
| 10 | +import com.cnlive.core.imageload.databinding.ActivityPreviewImageBinding; | |
| 11 | +import com.cnlive.core.imageload.preview.PreviewImageViewActivity; | |
| 8 | 12 | import com.cnlive.core.imagepreview.ViewerStatus; |
| 9 | 13 | import com.cnlive.core.imagepreview.listener.OnItemClickListener; |
| 10 | 14 | import com.cnlive.core.imagepreview.listener.OnItemLongPressListener; |
| 11 | 15 | import com.cnlive.core.libs.base.frame.activity.BaseActivity; |
| 16 | +import com.cnlive.core.ui.model.PreViewImgData; | |
| 17 | +import com.cnlive.core.ui.presenter.PreViewImagePresenter; | |
| 18 | +import com.cnlive.core.ui.view.PreViewImageView; | |
| 19 | + | |
| 12 | 20 | |
| 13 | 21 | import java.util.ArrayList; |
| 14 | 22 | import java.util.List; |
| 15 | 23 | |
| 16 | -@Route(path = "/preview/PreviewImageActivity") | |
| 17 | -public class PreviewImageActivity extends BaseActivity { | |
| 24 | +import androidx.databinding.ViewDataBinding; | |
| 25 | + | |
| 26 | +@Route(path = "/preview/PreViewImageActivity") | |
| 27 | +public class PreViewImageActivity extends BaseActivity<PreViewImageView, PreViewImagePresenter> { | |
| 18 | 28 | |
| 19 | - private ImagePreView preView; | |
| 20 | - private List<String> list = new ArrayList<>(); | |
| 29 | + public ActivityPreviewImageBinding binding; | |
| 30 | + public PreViewImgData data; | |
| 31 | + public int position = 0; | |
| 32 | + public String type; | |
| 33 | + public List<String> picList = new ArrayList<>(); | |
| 21 | 34 | |
| 35 | + public static void startPreViewActivity(Activity context, View transitionView, PreViewImgData data) { | |
| 36 | + Intent intent = new Intent(context, PreviewImageViewActivity.class); | |
| 37 | + intent.putExtra("data", data); | |
| 38 | + context.startActivity(intent); | |
| 39 | + } | |
| 22 | 40 | |
| 23 | 41 | @Override |
| 24 | 42 | protected int getViewLayoutId() { |
| ... | ... | @@ -26,17 +44,16 @@ public class PreviewImageActivity extends BaseActivity { |
| 26 | 44 | } |
| 27 | 45 | |
| 28 | 46 | @Override |
| 29 | - protected void initView() { | |
| 30 | - preView = findViewById(R.id.image_pre); | |
| 31 | - list = getIntent().getStringArrayListExtra("paths"); | |
| 47 | + protected void initBindingLayoutData(ViewDataBinding baseBinding) { | |
| 48 | + super.initBindingLayoutData(baseBinding); | |
| 49 | + binding = (ActivityPreviewImageBinding) baseBinding; | |
| 50 | + } | |
| 32 | 51 | |
| 33 | - preView.overlayStatusBar(false) | |
| 34 | - .imageData(list) | |
| 35 | - .playExitAnim(false); | |
| 36 | -// .imageLoader(new PhotoLoader()); | |
| 37 | - preView.watch(0); | |
| 38 | 52 | |
| 39 | - preView.setOnItemClickListener(new OnItemClickListener() { | |
| 53 | + @Override | |
| 54 | + protected void initView() { | |
| 55 | + getMvpView().getData(getIntent()); | |
| 56 | + binding.imagePre.setOnItemClickListener(new OnItemClickListener() { | |
| 40 | 57 | @Override |
| 41 | 58 | public boolean onItemClick(int position, ImageView imageView) { |
| 42 | 59 | finish(); |
| ... | ... | @@ -44,13 +61,6 @@ public class PreviewImageActivity extends BaseActivity { |
| 44 | 61 | return true; |
| 45 | 62 | } |
| 46 | 63 | }); |
| 47 | - | |
| 48 | - preView.setOnItemLongPressListener(new OnItemLongPressListener() { | |
| 49 | - @Override | |
| 50 | - public boolean onItemLongPress(int position, ImageView imageView) { | |
| 51 | - return false; | |
| 52 | - } | |
| 53 | - }); | |
| 54 | 64 | } |
| 55 | 65 | |
| 56 | 66 | @Override |
| ... | ... | @@ -64,8 +74,8 @@ public class PreviewImageActivity extends BaseActivity { |
| 64 | 74 | @Override |
| 65 | 75 | protected void onDestroy() { |
| 66 | 76 | super.onDestroy(); |
| 67 | - if(preView != null && preView.getViewStatus() == ViewerStatus.STATUS_WATCHING){ | |
| 68 | - preView.cancel(); | |
| 77 | + if(binding.imagePre != null && binding.imagePre.getViewStatus() == ViewerStatus.STATUS_WATCHING){ | |
| 78 | + binding.imagePre.cancel(); | |
| 69 | 79 | } |
| 70 | 80 | } |
| 71 | 81 | } | ... | ... |
core/imageload/src/main/java/com/cnlive/core/ui/model/PreViewImgData.java
0 → 100644
| 1 | +package com.cnlive.core.ui.model; | |
| 2 | + | |
| 3 | +import java.io.Serializable; | |
| 4 | +import java.util.List; | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * created by hanyayun | |
| 8 | + * on 2020/2/21 | |
| 9 | + */ | |
| 10 | +public class PreViewImgData implements Serializable { | |
| 11 | + | |
| 12 | + //1,图片 2,视频 | |
| 13 | + private String type; | |
| 14 | + //当前展示的预览图片信息 | |
| 15 | + private PreViewImgInfo currPrewInfo; | |
| 16 | + private List<PreViewImgInfo> picInfoList; | |
| 17 | + | |
| 18 | + //视频相关 | |
| 19 | + private String videoVid; | |
| 20 | + private String videoImg; | |
| 21 | + private String videoPath; | |
| 22 | + private int videoWidth; | |
| 23 | + private int videoHeight; | |
| 24 | + private int videoSize; | |
| 25 | + private boolean isLocalVideo; | |
| 26 | + private String videoLocalPath; | |
| 27 | + private int localVideoWidth; | |
| 28 | + private int localVideoHeight; | |
| 29 | + private int localVideoSize; | |
| 30 | + | |
| 31 | + | |
| 32 | + //长按弹框显示事件 转发朋友 生活圈 收藏 保存 二维码识别 | |
| 33 | + private boolean isShowDialog;//是否显示弹框 | |
| 34 | + private boolean isFriend = true; | |
| 35 | + private boolean isLife = true; | |
| 36 | + private boolean isCollection; | |
| 37 | + private boolean isSave; | |
| 38 | + private boolean isScan; | |
| 39 | + | |
| 40 | + //收藏 | |
| 41 | + private String collectionId; | |
| 42 | + private String userId; | |
| 43 | + private String collectionType; | |
| 44 | + private String shareUrl; | |
| 45 | + | |
| 46 | + public String getType() { | |
| 47 | + return type; | |
| 48 | + } | |
| 49 | + | |
| 50 | + public void setType(String type) { | |
| 51 | + this.type = type; | |
| 52 | + } | |
| 53 | + | |
| 54 | + public PreViewImgInfo getCurrPrewInfo() { | |
| 55 | + return currPrewInfo; | |
| 56 | + } | |
| 57 | + | |
| 58 | + public void setCurrPrewInfo(PreViewImgInfo currPrewInfo) { | |
| 59 | + this.currPrewInfo = currPrewInfo; | |
| 60 | + } | |
| 61 | + | |
| 62 | + public List<PreViewImgInfo> getPicInfoList() { | |
| 63 | + return picInfoList; | |
| 64 | + } | |
| 65 | + | |
| 66 | + public void setPicInfoList(List<PreViewImgInfo> picInfoList) { | |
| 67 | + this.picInfoList = picInfoList; | |
| 68 | + } | |
| 69 | + | |
| 70 | + public String getVideoVid() { | |
| 71 | + return videoVid; | |
| 72 | + } | |
| 73 | + | |
| 74 | + public void setVideoVid(String videoVid) { | |
| 75 | + this.videoVid = videoVid; | |
| 76 | + } | |
| 77 | + | |
| 78 | + public String getVideoImg() { | |
| 79 | + return videoImg; | |
| 80 | + } | |
| 81 | + | |
| 82 | + public void setVideoImg(String videoImg) { | |
| 83 | + this.videoImg = videoImg; | |
| 84 | + } | |
| 85 | + | |
| 86 | + public String getVideoPath() { | |
| 87 | + return videoPath; | |
| 88 | + } | |
| 89 | + | |
| 90 | + public void setVideoPath(String videoPath) { | |
| 91 | + this.videoPath = videoPath; | |
| 92 | + } | |
| 93 | + | |
| 94 | + public int getVideoWidth() { | |
| 95 | + return videoWidth; | |
| 96 | + } | |
| 97 | + | |
| 98 | + public void setVideoWidth(int videoWidth) { | |
| 99 | + this.videoWidth = videoWidth; | |
| 100 | + } | |
| 101 | + | |
| 102 | + public int getVideoHeight() { | |
| 103 | + return videoHeight; | |
| 104 | + } | |
| 105 | + | |
| 106 | + public void setVideoHeight(int videoHeight) { | |
| 107 | + this.videoHeight = videoHeight; | |
| 108 | + } | |
| 109 | + | |
| 110 | + public int getVideoSize() { | |
| 111 | + return videoSize; | |
| 112 | + } | |
| 113 | + | |
| 114 | + public void setVideoSize(int videoSize) { | |
| 115 | + this.videoSize = videoSize; | |
| 116 | + } | |
| 117 | + | |
| 118 | + public boolean isLocalVideo() { | |
| 119 | + return isLocalVideo; | |
| 120 | + } | |
| 121 | + | |
| 122 | + public void setLocalVideo(boolean localVideo) { | |
| 123 | + isLocalVideo = localVideo; | |
| 124 | + } | |
| 125 | + | |
| 126 | + public String getVideoLocalPath() { | |
| 127 | + return videoLocalPath; | |
| 128 | + } | |
| 129 | + | |
| 130 | + public void setVideoLocalPath(String videoLocalPath) { | |
| 131 | + this.videoLocalPath = videoLocalPath; | |
| 132 | + } | |
| 133 | + | |
| 134 | + public int getLocalVideoWidth() { | |
| 135 | + return localVideoWidth; | |
| 136 | + } | |
| 137 | + | |
| 138 | + public void setLocalVideoWidth(int localVideoWidth) { | |
| 139 | + this.localVideoWidth = localVideoWidth; | |
| 140 | + } | |
| 141 | + | |
| 142 | + public int getLocalVideoHeight() { | |
| 143 | + return localVideoHeight; | |
| 144 | + } | |
| 145 | + | |
| 146 | + public void setLocalVideoHeight(int localVideoHeight) { | |
| 147 | + this.localVideoHeight = localVideoHeight; | |
| 148 | + } | |
| 149 | + | |
| 150 | + public int getLocalVideoSize() { | |
| 151 | + return localVideoSize; | |
| 152 | + } | |
| 153 | + | |
| 154 | + public void setLocalVideoSize(int localVideoSize) { | |
| 155 | + this.localVideoSize = localVideoSize; | |
| 156 | + } | |
| 157 | + | |
| 158 | + public boolean isShowDialog() { | |
| 159 | + return isShowDialog; | |
| 160 | + } | |
| 161 | + | |
| 162 | + public void setShowDialog(boolean showDialog) { | |
| 163 | + isShowDialog = showDialog; | |
| 164 | + } | |
| 165 | + | |
| 166 | + public boolean isFriend() { | |
| 167 | + return isFriend; | |
| 168 | + } | |
| 169 | + | |
| 170 | + public void setFriend(boolean friend) { | |
| 171 | + isFriend = friend; | |
| 172 | + } | |
| 173 | + | |
| 174 | + public boolean isLife() { | |
| 175 | + return isLife; | |
| 176 | + } | |
| 177 | + | |
| 178 | + public void setLife(boolean life) { | |
| 179 | + isLife = life; | |
| 180 | + } | |
| 181 | + | |
| 182 | + public boolean isCollection() { | |
| 183 | + return isCollection; | |
| 184 | + } | |
| 185 | + | |
| 186 | + public void setCollection(boolean collection) { | |
| 187 | + isCollection = collection; | |
| 188 | + } | |
| 189 | + | |
| 190 | + public boolean isSave() { | |
| 191 | + return isSave; | |
| 192 | + } | |
| 193 | + | |
| 194 | + public void setSave(boolean save) { | |
| 195 | + isSave = save; | |
| 196 | + } | |
| 197 | + | |
| 198 | + public boolean isScan() { | |
| 199 | + return isScan; | |
| 200 | + } | |
| 201 | + | |
| 202 | + public void setScan(boolean scan) { | |
| 203 | + isScan = scan; | |
| 204 | + } | |
| 205 | + | |
| 206 | + public String getCollectionId() { | |
| 207 | + return collectionId; | |
| 208 | + } | |
| 209 | + | |
| 210 | + public void setCollectionId(String collectionId) { | |
| 211 | + this.collectionId = collectionId; | |
| 212 | + } | |
| 213 | + | |
| 214 | + public String getUserId() { | |
| 215 | + return userId; | |
| 216 | + } | |
| 217 | + | |
| 218 | + public void setUserId(String userId) { | |
| 219 | + this.userId = userId; | |
| 220 | + } | |
| 221 | + | |
| 222 | + public String getCollectionType() { | |
| 223 | + return collectionType; | |
| 224 | + } | |
| 225 | + | |
| 226 | + public void setCollectionType(String collectionType) { | |
| 227 | + this.collectionType = collectionType; | |
| 228 | + } | |
| 229 | + | |
| 230 | + public String getShareUrl() { | |
| 231 | + return shareUrl; | |
| 232 | + } | |
| 233 | + | |
| 234 | + public void setShareUrl(String shareUrl) { | |
| 235 | + this.shareUrl = shareUrl; | |
| 236 | + } | |
| 237 | +} | ... | ... |
core/imageload/src/main/java/com/cnlive/core/ui/model/PreViewImgInfo.java
0 → 100644
| 1 | +package com.cnlive.core.ui.model; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * created by hanyayun | |
| 5 | + * on 2020/2/21 | |
| 6 | + */ | |
| 7 | +public class PreViewImgInfo { | |
| 8 | + //原图 | |
| 9 | + private String imgUrl; | |
| 10 | + //预览图 | |
| 11 | + private String previewImgUrl; | |
| 12 | + | |
| 13 | + public String getImgUrl() { | |
| 14 | + return imgUrl; | |
| 15 | + } | |
| 16 | + | |
| 17 | + public void setImgUrl(String imgUrl) { | |
| 18 | + this.imgUrl = imgUrl; | |
| 19 | + } | |
| 20 | + | |
| 21 | + public String getPreviewImgUrl() { | |
| 22 | + return previewImgUrl; | |
| 23 | + } | |
| 24 | + | |
| 25 | + public void setPreviewImgUrl(String previewImgUrl) { | |
| 26 | + this.previewImgUrl = previewImgUrl; | |
| 27 | + } | |
| 28 | +} | ... | ... |
core/imageload/src/main/java/com/cnlive/core/ui/presenter/PreViewImagePresenter.java
0 → 100644
| 1 | +package com.cnlive.core.ui.presenter; | |
| 2 | + | |
| 3 | +import android.app.Activity; | |
| 4 | +import android.content.Context; | |
| 5 | +import android.content.Intent; | |
| 6 | +import android.net.Uri; | |
| 7 | +import android.os.Environment; | |
| 8 | +import android.text.TextUtils; | |
| 9 | +import android.util.Log; | |
| 10 | + | |
| 11 | +import com.bumptech.glide.Glide; | |
| 12 | +import com.cnlive.cloud.user.auth.UserService; | |
| 13 | +import com.cnlive.core.imageload.api.ApiServiceStock; | |
| 14 | +import com.cnlive.core.imageload.preview.DataProcessingActivity; | |
| 15 | +import com.cnlive.core.imageload.preview.model.PreviewData; | |
| 16 | +import com.cnlive.core.libs.base.application.AppConfig; | |
| 17 | +import com.cnlive.core.libs.base.frame.presenter.BasePresenter; | |
| 18 | +import com.cnlive.core.libs.base.util.FileTypeUtil; | |
| 19 | +import com.cnlive.core.libs.base.util.FileUtils; | |
| 20 | +import com.cnlive.core.libs.base.util.MD5Util; | |
| 21 | +import com.cnlive.core.network.HttpConn; | |
| 22 | +import com.cnlive.core.network.NetCallBack; | |
| 23 | +import com.cnlive.core.network.model.BaseResult; | |
| 24 | +import com.cnlive.core.network.request.BaseRequest; | |
| 25 | +import com.cnlive.core.network.upload.UploadLogic; | |
| 26 | +import com.cnlive.core.network.upload.model.FeedBackInfo; | |
| 27 | +import com.cnlive.core.ui.activity.PreViewImageActivity; | |
| 28 | +import com.cnlive.core.ui.model.PreViewImgData; | |
| 29 | +import com.cnlive.core.ui.view.PreViewImageView; | |
| 30 | + | |
| 31 | +import java.io.File; | |
| 32 | +import java.io.FileInputStream; | |
| 33 | +import java.io.FileOutputStream; | |
| 34 | +import java.io.InputStream; | |
| 35 | +import java.util.ArrayList; | |
| 36 | +import java.util.HashMap; | |
| 37 | +import java.util.List; | |
| 38 | +import java.util.Map; | |
| 39 | + | |
| 40 | +import cn.bertsir.zbar.utils.QRUtils; | |
| 41 | +import io.reactivex.Observable; | |
| 42 | +import io.reactivex.ObservableEmitter; | |
| 43 | +import io.reactivex.ObservableOnSubscribe; | |
| 44 | +import io.reactivex.Observer; | |
| 45 | +import io.reactivex.android.schedulers.AndroidSchedulers; | |
| 46 | +import io.reactivex.disposables.Disposable; | |
| 47 | +import io.reactivex.schedulers.Schedulers; | |
| 48 | + | |
| 49 | +/** | |
| 50 | + * created by hanyayun | |
| 51 | + * on 2020/2/21 | |
| 52 | + */ | |
| 53 | +public class PreViewImagePresenter extends BasePresenter<PreViewImageView> { | |
| 54 | + | |
| 55 | + | |
| 56 | + /** | |
| 57 | + * 分享好友、生活圈 | |
| 58 | + * | |
| 59 | + * @param mContext | |
| 60 | + * @param type | |
| 61 | + * @param imgUrl | |
| 62 | + */ | |
| 63 | + public void shareFriendLife(Context mContext, String type, String imgUrl) { | |
| 64 | + if (TextUtils.isEmpty(imgUrl)) return; | |
| 65 | + if (mContext == null) return; | |
| 66 | + ifViewAttached(view -> view.showLoading()); | |
| 67 | + Observable.create((ObservableOnSubscribe<String>) emitter -> { | |
| 68 | + if (FileUtils.isFileExists(imgUrl) && FileUtils.getFileByPath(imgUrl).length() > 0) { | |
| 69 | + emitter.onNext(imgUrl); | |
| 70 | + } else { | |
| 71 | + if (imgUrl.contains("http")) { | |
| 72 | + File file = Glide.with(mContext).asFile().load(imgUrl).submit().get(); | |
| 73 | + if (file != null && file.exists() && file.length() > 0) { | |
| 74 | + String path = file.getAbsolutePath(); | |
| 75 | + emitter.onNext(path); | |
| 76 | + } else { | |
| 77 | + emitter.onError(new Throwable("非法图片地址")); | |
| 78 | + } | |
| 79 | + } else { | |
| 80 | + emitter.onError(new Throwable("非法图片地址")); | |
| 81 | + } | |
| 82 | + } | |
| 83 | + }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<String>() { | |
| 84 | + @Override | |
| 85 | + public void onSubscribe(Disposable d) { | |
| 86 | + | |
| 87 | + } | |
| 88 | + | |
| 89 | + @Override | |
| 90 | + public void onNext(String content) { | |
| 91 | + ifViewAttached(view -> view.hideLoading()); | |
| 92 | + if (!TextUtils.isEmpty(content)) { | |
| 93 | + if (type.equals("friends")) { | |
| 94 | + ifViewAttached(view -> view.shareFriends(content)); | |
| 95 | + } else if (type.equals("life")) { | |
| 96 | + ifViewAttached(view -> view.shareLife(content)); | |
| 97 | + } else { | |
| 98 | + ifViewAttached(view -> view.showMessage("类型异常")); | |
| 99 | + } | |
| 100 | + } else { | |
| 101 | + ifViewAttached(view -> view.showMessage("非法图片地址")); | |
| 102 | + } | |
| 103 | + } | |
| 104 | + | |
| 105 | + @Override | |
| 106 | + public void onError(Throwable e) { | |
| 107 | + ifViewAttached(view -> { | |
| 108 | + view.hideLoading(); | |
| 109 | + view.showMessage(e.getMessage()); | |
| 110 | + }); | |
| 111 | + } | |
| 112 | + | |
| 113 | + @Override | |
| 114 | + public void onComplete() { | |
| 115 | + | |
| 116 | + } | |
| 117 | + }); | |
| 118 | + } | |
| 119 | + | |
| 120 | + | |
| 121 | + /** | |
| 122 | + * 收藏图片 | |
| 123 | + * | |
| 124 | + * @param context | |
| 125 | + * @param imagePath | |
| 126 | + */ | |
| 127 | + public void collectionPic(PreViewImageActivity context, String imagePath) { | |
| 128 | + if (context == null && TextUtils.isEmpty(imagePath)) return; | |
| 129 | + if (FileUtils.isFileExists(imagePath)) { | |
| 130 | + List<String> list = new ArrayList(); | |
| 131 | + list.add(imagePath); | |
| 132 | + UploadLogic.uploadonePic(context, true, list, new NetCallBack<List<FeedBackInfo>>() { | |
| 133 | + @Override | |
| 134 | + public void onRequestState(int state) { | |
| 135 | + | |
| 136 | + } | |
| 137 | + | |
| 138 | + @Override | |
| 139 | + public void onSuccess(List<com.cnlive.core.network.upload.model.FeedBackInfo> data) { | |
| 140 | + if (data.size() > 0) { | |
| 141 | + if (data.get(0).getImageUrl().contains("http")) { | |
| 142 | + collection(context, data.get(0).getImageUrl(), context.data); | |
| 143 | + } else { | |
| 144 | + ifViewAttached(view -> view.showMessage("数据异常")); | |
| 145 | + } | |
| 146 | + } | |
| 147 | + } | |
| 148 | + | |
| 149 | + @Override | |
| 150 | + public void onFailure(String errCode, String errMsg, Exception e) { | |
| 151 | + ifViewAttached(view -> view.showMessage(errMsg)); | |
| 152 | + } | |
| 153 | + }); | |
| 154 | + } else if (context.data != null) { | |
| 155 | + collection(context, imagePath, context.data); | |
| 156 | + } | |
| 157 | + } | |
| 158 | + | |
| 159 | + | |
| 160 | + private void collection(PreViewImageActivity context, String imagePath, PreViewImgData previewData) { | |
| 161 | + if (previewData == null) return; | |
| 162 | + String sid = UserService.getUid(context); | |
| 163 | + Map<String, String> requestMap = new HashMap<>(); | |
| 164 | + requestMap.put("appId", AppConfig.getAppId()); | |
| 165 | + requestMap.put("sid", sid); | |
| 166 | + requestMap.put("type", previewData.getType()); | |
| 167 | + requestMap.put("img", imagePath); | |
| 168 | + | |
| 169 | + if ("2".equals(previewData.getType())) { | |
| 170 | + requestMap.put("videoImg", TextUtils.isEmpty(previewData.getCurrPrewInfo().getImgUrl()) ? previewData.getCurrPrewInfo().getPreviewImgUrl() : previewData.getCurrPrewInfo().getImgUrl()); | |
| 171 | + requestMap.put("videoId", previewData.getVideoVid()); | |
| 172 | + } | |
| 173 | +// if ("3".equals(previewData.getType())) { | |
| 174 | +// //收藏网址暂未实现 | |
| 175 | +// requestMap.put("shareUrl", previewData.getShowImg()); | |
| 176 | +// } | |
| 177 | + if (TextUtils.isEmpty(previewData.getCollectionId())) { | |
| 178 | + int index = imagePath.lastIndexOf("/"); | |
| 179 | + if (index != -1) { | |
| 180 | + String collectionId = imagePath.substring(index + 1); | |
| 181 | + requestMap.put("collectionId", collectionId); | |
| 182 | + } else { | |
| 183 | + requestMap.put("collectionId", imagePath); | |
| 184 | + } | |
| 185 | + } else { | |
| 186 | + requestMap.put("collectionId", previewData.getCollectionId()); | |
| 187 | + } | |
| 188 | + | |
| 189 | + if (TextUtils.isEmpty(previewData.getCollectionType())) { | |
| 190 | + requestMap.put("collectionType", "moment"); | |
| 191 | + } else { | |
| 192 | + requestMap.put("collectionType", previewData.getCollectionType()); | |
| 193 | + } | |
| 194 | + | |
| 195 | + HttpConn.action(BaseRequest.init() | |
| 196 | + .service(ApiServiceStock.class) | |
| 197 | + .collection(requestMap), new NetCallBack<BaseResult>() { | |
| 198 | + @Override | |
| 199 | + public void onRequestState(int state) { | |
| 200 | + | |
| 201 | + } | |
| 202 | + | |
| 203 | + @Override | |
| 204 | + public void onSuccess(BaseResult data) { | |
| 205 | + ifViewAttached(view -> view.showSucessfulMessage("收藏成功")); | |
| 206 | + } | |
| 207 | + | |
| 208 | + @Override | |
| 209 | + public void onFailure(String errCode, String errMsg, Exception e) { | |
| 210 | + ifViewAttached(view -> view.showMessage(errMsg)); | |
| 211 | + } | |
| 212 | + }); | |
| 213 | + } | |
| 214 | + | |
| 215 | + | |
| 216 | + /** | |
| 217 | + * 保存图片 | |
| 218 | + * | |
| 219 | + * @param url | |
| 220 | + */ | |
| 221 | + public void savePicture(Activity context, String url) { | |
| 222 | + ifViewAttached(view -> view.hideLoading()); | |
| 223 | + if (TextUtils.isEmpty(url)) { | |
| 224 | + ifViewAttached(view -> view.showMessage("非法图片地址")); | |
| 225 | + return; | |
| 226 | + } | |
| 227 | + if (FileUtils.isFileExists(url)) { | |
| 228 | +// 本地图片 做copy操作 | |
| 229 | + ifViewAttached(view -> view.saveLocalImg(url)); | |
| 230 | + } else { | |
| 231 | + if (!url.contains("http")) { | |
| 232 | + ifViewAttached(view -> view.showMessage("非法图片地址")); | |
| 233 | + return; | |
| 234 | + } | |
| 235 | + Observable.create(new ObservableOnSubscribe<String>() { | |
| 236 | + @Override | |
| 237 | + public void subscribe(ObservableEmitter<String> emitter) throws Exception { | |
| 238 | + if (url.contains("http")) { | |
| 239 | + File file = Glide.with(context).asFile().load(url).submit().get(); | |
| 240 | + if (file != null && file.exists() && file.length() > 0) { | |
| 241 | + String path = file.getAbsolutePath(); | |
| 242 | + emitter.onNext(path); | |
| 243 | + } else { | |
| 244 | + emitter.onError(new Throwable("非法图片地址")); | |
| 245 | + } | |
| 246 | + } else { | |
| 247 | + emitter.onError(new Throwable("非法图片地址")); | |
| 248 | + } | |
| 249 | + } | |
| 250 | + }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<String>() { | |
| 251 | + @Override | |
| 252 | + public void onSubscribe(Disposable d) { | |
| 253 | + | |
| 254 | + } | |
| 255 | + | |
| 256 | + @Override | |
| 257 | + public void onNext(String s) { | |
| 258 | + if (!TextUtils.isEmpty(s)) { | |
| 259 | + ifViewAttached(view -> view.saveLocalImg(s)); | |
| 260 | + } else { | |
| 261 | + ifViewAttached(view -> view.showMessage("数据异常")); | |
| 262 | + } | |
| 263 | + } | |
| 264 | + | |
| 265 | + @Override | |
| 266 | + public void onError(Throwable e) { | |
| 267 | + ifViewAttached(view -> view.showMessage(e.getMessage())); | |
| 268 | + } | |
| 269 | + | |
| 270 | + @Override | |
| 271 | + public void onComplete() { | |
| 272 | + | |
| 273 | + } | |
| 274 | + }); | |
| 275 | + } | |
| 276 | + } | |
| 277 | + | |
| 278 | + /** | |
| 279 | + * 保存视频 | |
| 280 | + * | |
| 281 | + * @param activity | |
| 282 | + * @param imgUrl | |
| 283 | + */ | |
| 284 | + public void saveVideo(Activity activity, String imgUrl) { | |
| 285 | + if (TextUtils.isEmpty(imgUrl)) { | |
| 286 | + ifViewAttached(view -> view.showMessage("数据异常")); | |
| 287 | + return; | |
| 288 | + } | |
| 289 | + if (imgUrl.contains("http")) { | |
| 290 | + ifViewAttached(view -> view.saveNetVideo(imgUrl)); | |
| 291 | + } else { | |
| 292 | + File file = FileUtils.getFileByPath(imgUrl); | |
| 293 | + try { | |
| 294 | + String filePath = "Strike" + File.separator + "video"; | |
| 295 | + String md5 = MD5Util.getMD5(file); | |
| 296 | + InputStream inStream = new FileInputStream(file); //读入原文件 | |
| 297 | + File appDir = new File(Environment.getExternalStorageDirectory(), filePath); | |
| 298 | + if (!appDir.exists()) appDir.mkdir(); | |
| 299 | + | |
| 300 | + String type = FileTypeUtil.getFileType(file.getAbsolutePath()); | |
| 301 | + String extension;//初始文件扩展名 | |
| 302 | + if (TextUtils.isEmpty(type)) { | |
| 303 | + extension = ".mp4"; | |
| 304 | + } else { | |
| 305 | + extension = "." + type; | |
| 306 | + } | |
| 307 | + | |
| 308 | + File newFile = new File(appDir, md5 + extension); | |
| 309 | + FileOutputStream outputStream = new FileOutputStream(newFile); | |
| 310 | + | |
| 311 | + int byteread = 0; | |
| 312 | + byte[] buffer2 = new byte[1444]; | |
| 313 | + while ((byteread = inStream.read(buffer2)) != -1) | |
| 314 | + outputStream.write(buffer2, 0, byteread); | |
| 315 | + inStream.close(); | |
| 316 | + outputStream.close(); | |
| 317 | + activity.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + newFile.getAbsolutePath()))); | |
| 318 | + ifViewAttached(view -> view.showSucessfulMessage("保存成功")); | |
| 319 | + activity.finish(); | |
| 320 | + } catch (Exception e) { | |
| 321 | + Log.e("文件保存异常:", "Exception ", e); | |
| 322 | + } | |
| 323 | + } | |
| 324 | + } | |
| 325 | + | |
| 326 | + /** | |
| 327 | + * 扫描二维码 | |
| 328 | + * | |
| 329 | + * @param mActivity | |
| 330 | + * @param path | |
| 331 | + */ | |
| 332 | + public void doScan(Activity mActivity, String path) { | |
| 333 | + | |
| 334 | + if (TextUtils.isEmpty(path) && mActivity != null) return; | |
| 335 | + Observable.create(new ObservableOnSubscribe<String>() { | |
| 336 | + @Override | |
| 337 | + public void subscribe(ObservableEmitter<String> emitter) throws Exception { | |
| 338 | + File scanFile = null; | |
| 339 | + if (FileUtils.isFileExists(path) && FileUtils.getFileByPath(path).length() > 0) { | |
| 340 | + scanFile = FileUtils.getFileByPath(path); | |
| 341 | + } else { | |
| 342 | + if (path.contains("http")) { | |
| 343 | + File file = Glide.with(mActivity).asFile().load(path).submit().get(); | |
| 344 | + if (file != null && file.exists() && file.length() > 0) { | |
| 345 | + scanFile = file; | |
| 346 | + } else { | |
| 347 | + emitter.onError(new Throwable("非法图片地址")); | |
| 348 | + } | |
| 349 | + } else { | |
| 350 | + emitter.onError(new Throwable("非法图片地址")); | |
| 351 | + } | |
| 352 | + } | |
| 353 | + if (scanFile != null && FileUtils.isFileExists(scanFile) && scanFile.length() > 0) { | |
| 354 | + String content = null; | |
| 355 | + content = QRUtils.getInstance().decodeQRcode(scanFile.getAbsolutePath()); | |
| 356 | + if (TextUtils.isEmpty(scanFile.getAbsolutePath())) { | |
| 357 | + content = QRUtils.getInstance().decodeQRcodeByZxing(scanFile.getAbsolutePath()); | |
| 358 | + } | |
| 359 | + if (content != null && content.length() > 0) { | |
| 360 | + emitter.onNext(content); | |
| 361 | + } else { | |
| 362 | + emitter.onNext(""); | |
| 363 | + } | |
| 364 | + } else { | |
| 365 | + emitter.onError(new Throwable("非法图片地址")); | |
| 366 | + } | |
| 367 | + | |
| 368 | + } | |
| 369 | + }).subscribeOn(Schedulers.io()) //指定被观察者中的方法在io线程中进行处理 | |
| 370 | + .observeOn(AndroidSchedulers.mainThread()) | |
| 371 | + //指定观察者接收数据在主线程中 | |
| 372 | + .subscribe(new Observer<String>() { | |
| 373 | + @Override | |
| 374 | + public void onSubscribe(Disposable d) { | |
| 375 | + } | |
| 376 | + | |
| 377 | + @Override | |
| 378 | + public void onNext(String qrContent) { | |
| 379 | +// if (getView()!=null)getView().hideLoading(); | |
| 380 | + if (qrContent != null && qrContent.length() > 0) { | |
| 381 | + ifViewAttached(view -> view.processQrContent(qrContent)); | |
| 382 | + } else { | |
| 383 | + ifViewAttached(view -> view.showMessage("未识别二维码")); | |
| 384 | + } | |
| 385 | + } | |
| 386 | + | |
| 387 | + @Override | |
| 388 | + public void onError(Throwable e) { | |
| 389 | + ifViewAttached(view -> view.hideLoading()); | |
| 390 | + ifViewAttached(view -> view.showMessage(e.getMessage())); | |
| 391 | + } | |
| 392 | + | |
| 393 | + @Override | |
| 394 | + public void onComplete() { | |
| 395 | + | |
| 396 | + } | |
| 397 | + }); | |
| 398 | + | |
| 399 | + } | |
| 400 | +} | ... | ... |
core/imageload/src/main/java/com/cnlive/core/ui/view/PreViewImageView.java
0 → 100644
| 1 | +package com.cnlive.core.ui.view; | |
| 2 | + | |
| 3 | +import android.annotation.SuppressLint; | |
| 4 | +import android.app.Dialog; | |
| 5 | +import android.content.ContentResolver; | |
| 6 | +import android.content.ContentValues; | |
| 7 | +import android.content.Intent; | |
| 8 | +import android.net.Uri; | |
| 9 | +import android.os.Environment; | |
| 10 | +import android.provider.MediaStore; | |
| 11 | +import android.text.TextUtils; | |
| 12 | +import android.util.Log; | |
| 13 | +import android.view.Gravity; | |
| 14 | +import android.view.View; | |
| 15 | +import android.view.ViewGroup; | |
| 16 | +import android.view.Window; | |
| 17 | +import android.widget.ImageView; | |
| 18 | + | |
| 19 | +import com.cnlive.cloud.moudle.qr.uitl.IdentifyTheQRCodeCallback; | |
| 20 | +import com.cnlive.cloud.moudle.qr.uitl.QrContentUtil; | |
| 21 | +import com.cnlive.core.imageload.R; | |
| 22 | +import com.cnlive.core.imageload.preview.router.PreviewRouters; | |
| 23 | +import com.cnlive.core.imageload.preview.widget.CustomTipDialog; | |
| 24 | +import com.cnlive.core.imageload.preview.widget.DownloadUtil; | |
| 25 | +import com.cnlive.core.imagepreview.listener.OnItemLongPressListener; | |
| 26 | +import com.cnlive.core.libs.base.frame.view.BaseView; | |
| 27 | +import com.cnlive.core.libs.base.util.AlertUtil; | |
| 28 | +import com.cnlive.core.libs.base.util.FileTypeUtil; | |
| 29 | +import com.cnlive.core.libs.base.util.FileUtils; | |
| 30 | +import com.cnlive.core.libs.base.util.MD5Util; | |
| 31 | +import com.cnlive.core.ui.activity.PreViewImageActivity; | |
| 32 | +import com.cnlive.core.ui.model.PreViewImgData; | |
| 33 | +import com.cnlive.core.ui.model.PreViewImgInfo; | |
| 34 | +import com.cnlive.media.picker.entity.Media; | |
| 35 | +import com.qmuiteam.qmui.widget.dialog.QMUITipDialog; | |
| 36 | + | |
| 37 | +import java.io.File; | |
| 38 | +import java.io.FileInputStream; | |
| 39 | +import java.io.FileOutputStream; | |
| 40 | +import java.io.InputStream; | |
| 41 | +import java.util.ArrayList; | |
| 42 | +import java.util.List; | |
| 43 | + | |
| 44 | +import io.reactivex.Observable; | |
| 45 | +import io.reactivex.ObservableEmitter; | |
| 46 | +import io.reactivex.ObservableOnSubscribe; | |
| 47 | +import io.reactivex.Observer; | |
| 48 | +import io.reactivex.android.schedulers.AndroidSchedulers; | |
| 49 | +import io.reactivex.disposables.Disposable; | |
| 50 | +import io.reactivex.schedulers.Schedulers; | |
| 51 | + | |
| 52 | +/** | |
| 53 | + * created by hanyayun | |
| 54 | + * on 2020/2/21 | |
| 55 | + */ | |
| 56 | +public class PreViewImageView extends BaseView { | |
| 57 | + | |
| 58 | + PreViewImageActivity activity; | |
| 59 | + private List<PreViewImgInfo> preViewImgList = new ArrayList<>(); | |
| 60 | + private Dialog dialog; | |
| 61 | + private CustomTipDialog loadingDiaog; | |
| 62 | + | |
| 63 | + public PreViewImageView(PreViewImageActivity activity) { | |
| 64 | + this.activity = activity; | |
| 65 | + } | |
| 66 | + | |
| 67 | + | |
| 68 | + public void getData(Intent intent) { | |
| 69 | + activity.data = (PreViewImgData) intent.getSerializableExtra("data"); | |
| 70 | + activity.type = activity.data.getType(); | |
| 71 | + if (TextUtils.isEmpty(activity.type)) { | |
| 72 | + showError(); | |
| 73 | + } | |
| 74 | + if (activity.type.equals("1")) { | |
| 75 | + preViewImgList = activity.data.getPicInfoList(); | |
| 76 | + if (preViewImgList.size() == 1) { | |
| 77 | + activity.position = 0; | |
| 78 | + } else { | |
| 79 | + PreViewImgInfo curPreInfo = activity.data.getCurrPrewInfo(); | |
| 80 | + for (int i = 0; i < preViewImgList.size(); i++) { | |
| 81 | + activity.picList.add(TextUtils.isEmpty(preViewImgList.get(i).getPreviewImgUrl()) ? preViewImgList.get(i).getImgUrl() : preViewImgList.get(i).getPreviewImgUrl()); | |
| 82 | + if (curPreInfo.getPreviewImgUrl().equals(preViewImgList.get(i).getPreviewImgUrl()) || curPreInfo.getImgUrl().equals(preViewImgList.get(i).getImgUrl())) { | |
| 83 | + activity.position = i; | |
| 84 | + } | |
| 85 | + } | |
| 86 | + setPreview(); | |
| 87 | + } | |
| 88 | + } else if (activity.data.getType().equals("2")) { | |
| 89 | + | |
| 90 | + } | |
| 91 | + } | |
| 92 | + | |
| 93 | + public void setPreview() { | |
| 94 | + activity.binding.imagePre.overlayStatusBar(false) | |
| 95 | + .imageData(activity.picList) | |
| 96 | + .playExitAnim(false); | |
| 97 | + activity.binding.imagePre.watch(activity.position); | |
| 98 | + | |
| 99 | + activity.binding.imagePre.setOnItemLongPressListener(new OnItemLongPressListener() { | |
| 100 | + @Override | |
| 101 | + public boolean onItemLongPress(int position, ImageView imageView) { | |
| 102 | + showDialog(position); | |
| 103 | + return false; | |
| 104 | + } | |
| 105 | + }); | |
| 106 | + } | |
| 107 | + | |
| 108 | + //长按弹框事件 | |
| 109 | + public void showDialog(int position) { | |
| 110 | + if (dialog == null) { | |
| 111 | + dialog = new Dialog(activity, R.style.CustomDialogStyle); | |
| 112 | + View view = View.inflate(activity, R.layout.dialog_show, null); | |
| 113 | + dialog.setContentView(view); | |
| 114 | + Window window = dialog.getWindow(); | |
| 115 | + window.setGravity(Gravity.BOTTOM); | |
| 116 | +// window.setWindowAnimations(R.style.main_menu_animStyle); | |
| 117 | + window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); | |
| 118 | + dialog.findViewById(R.id.share_friend).setVisibility(activity.data.isFriend() ? View.VISIBLE : View.GONE); | |
| 119 | + dialog.findViewById(R.id.share_cirfriend).setVisibility(activity.data.isLife() ? View.VISIBLE : View.GONE); | |
| 120 | + dialog.findViewById(R.id.cellection).setVisibility(activity.data.isCollection() ? View.VISIBLE : View.GONE); | |
| 121 | + dialog.findViewById(R.id.save_picture).setVisibility(activity.data.isSave() ? View.VISIBLE : View.GONE); | |
| 122 | + dialog.findViewById(R.id.can_scan).setVisibility(activity.data.isScan() ? View.VISIBLE : View.GONE); | |
| 123 | + dialog.findViewById(R.id.cancle).setOnClickListener(view1 -> dialog.dismiss()); | |
| 124 | + dialog.show(); | |
| 125 | + } else { | |
| 126 | + dialog.show(); | |
| 127 | + } | |
| 128 | + | |
| 129 | + dialog.findViewById(R.id.share_friend).setOnClickListener(view -> | |
| 130 | + activity.getPresenter().shareFriendLife(activity, "friends", TextUtils.isEmpty(preViewImgList.get(position).getImgUrl()) ? preViewImgList.get(position).getImgUrl() : preViewImgList.get(position).getImgUrl())); | |
| 131 | + dialog.findViewById(R.id.share_cirfriend).setOnClickListener(view -> | |
| 132 | + activity.getPresenter().shareFriendLife(activity, "life", TextUtils.isEmpty(preViewImgList.get(position).getImgUrl()) ? preViewImgList.get(position).getImgUrl() : preViewImgList.get(position).getImgUrl())); | |
| 133 | + dialog.findViewById(R.id.cellection).setOnClickListener(view -> | |
| 134 | + activity.getPresenter().collectionPic(activity, TextUtils.isEmpty(preViewImgList.get(position).getImgUrl()) ? preViewImgList.get(position).getImgUrl() : preViewImgList.get(position).getImgUrl())); | |
| 135 | + dialog.findViewById(R.id.save_picture).setOnClickListener(view -> { | |
| 136 | + if (activity.data.getType().equals("1")) { | |
| 137 | + activity.getPresenter().savePicture(activity, TextUtils.isEmpty(preViewImgList.get(position).getImgUrl()) ? preViewImgList.get(position).getImgUrl() : preViewImgList.get(position).getImgUrl()); | |
| 138 | + } else if (activity.data.getType().equals("1")) { | |
| 139 | + activity.getPresenter().saveVideo(activity, TextUtils.isEmpty(preViewImgList.get(position).getImgUrl()) ? preViewImgList.get(position).getImgUrl() : preViewImgList.get(position).getImgUrl()); | |
| 140 | + } | |
| 141 | + }); | |
| 142 | + dialog.findViewById(R.id.can_scan).setOnClickListener(view -> | |
| 143 | + activity.getPresenter().doScan(activity, TextUtils.isEmpty(preViewImgList.get(position).getImgUrl()) ? preViewImgList.get(position).getImgUrl() : preViewImgList.get(position).getImgUrl())); | |
| 144 | + } | |
| 145 | + | |
| 146 | + | |
| 147 | + @SuppressLint("WrongConstant") | |
| 148 | + public void showLoading() { | |
| 149 | + if (activity == null) return; | |
| 150 | + if (loadingDiaog == null) { | |
| 151 | + loadingDiaog = new CustomTipDialog.Builder(activity) | |
| 152 | + .setIconType(QMUITipDialog.Builder.ICON_TYPE_LOADING) | |
| 153 | + .setTipWord("请稍后") | |
| 154 | + .create(); | |
| 155 | + } | |
| 156 | + loadingDiaog.show(); | |
| 157 | + } | |
| 158 | + | |
| 159 | + /** | |
| 160 | + * 分享给朋友 | |
| 161 | + * | |
| 162 | + * @param content | |
| 163 | + */ | |
| 164 | + public void shareFriends(String content) { | |
| 165 | + if (activity == null) return; | |
| 166 | + PreviewRouters.startSelectFriend(activity, content, 0x2002, 0x1002); | |
| 167 | + if (activity == null) activity.finish(); | |
| 168 | + } | |
| 169 | + | |
| 170 | + /** | |
| 171 | + * 分享生活圈 | |
| 172 | + * | |
| 173 | + * @param content | |
| 174 | + */ | |
| 175 | + public void shareLife(String content) { | |
| 176 | + File file = new File(content); //pic 1 video 3 | |
| 177 | + if (!FileUtils.isFileExists(content)) return; | |
| 178 | + ArrayList<Media> medialist = new ArrayList<>(); | |
| 179 | + Media media = new Media(file.getPath(), file.getName(), 1, 1, file.length(), 0, ""); | |
| 180 | + medialist.add(media); | |
| 181 | + PreviewRouters.startReleaseManagementAcityity(activity, file.getPath(), file.getName(), 1, 1, file.length(), 0, ""); | |
| 182 | + if (activity == null) activity.finish(); | |
| 183 | + } | |
| 184 | + | |
| 185 | + /** | |
| 186 | + * 复制本地图片到指定文件夹下 | |
| 187 | + * | |
| 188 | + * @param imagePath | |
| 189 | + */ | |
| 190 | + public void saveLocalImg(String imagePath) { | |
| 191 | + File file = new File(imagePath); | |
| 192 | + try { | |
| 193 | + String md5 = MD5Util.getMD5(file); | |
| 194 | + InputStream inStream = new FileInputStream(file); //读入原文件 | |
| 195 | + File appDir = new File(Environment.getExternalStorageDirectory(), "strike"); | |
| 196 | + if (!appDir.exists()) appDir.mkdir(); | |
| 197 | + | |
| 198 | + String type = FileTypeUtil.getFileType(file.getAbsolutePath(), true); | |
| 199 | + String extension;//初始文件扩展名 | |
| 200 | + if (TextUtils.isEmpty(type)) { | |
| 201 | + extension = ".jpg"; | |
| 202 | + } else { | |
| 203 | + extension = "." + type; | |
| 204 | + } | |
| 205 | + | |
| 206 | + File newFile = new File(appDir, md5 + extension); | |
| 207 | + FileOutputStream outputStream = new FileOutputStream(newFile); | |
| 208 | + | |
| 209 | + int byteread = 0; | |
| 210 | + byte[] buffer2 = new byte[1444]; | |
| 211 | + while ((byteread = inStream.read(buffer2)) != -1) | |
| 212 | + outputStream.write(buffer2, 0, byteread); | |
| 213 | + inStream.close(); | |
| 214 | + outputStream.close(); | |
| 215 | + if (newFile != null) { | |
| 216 | + MediaStore.Images.Media.insertImage(activity.getContentResolver(), | |
| 217 | + file.getAbsolutePath(), newFile.getName(), null); | |
| 218 | + | |
| 219 | + } | |
| 220 | + activity.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + newFile.getAbsolutePath()))); | |
| 221 | + showSucessfulMessage("保存成功"); | |
| 222 | + } catch (Exception e) { | |
| 223 | + if (e != null && e.getMessage() != null) | |
| 224 | + Log.e("保存图片异常", e.getMessage()); | |
| 225 | + } | |
| 226 | + } | |
| 227 | + | |
| 228 | + /** | |
| 229 | + * 保存视频 | |
| 230 | + * | |
| 231 | + * @param imgUrl | |
| 232 | + */ | |
| 233 | + public void saveNetVideo(String imgUrl) { | |
| 234 | + showLoading(); | |
| 235 | + String saveDir = "Strike" + File.separator + "video"; | |
| 236 | + DownloadUtil.getInstance().download(imgUrl, saveDir, new DownloadUtil.OnDownloadListener() { | |
| 237 | + @Override | |
| 238 | + public void onDownloadSuccess(String path) { | |
| 239 | + jumpMain(path); | |
| 240 | + } | |
| 241 | + | |
| 242 | + @Override | |
| 243 | + public void onDownloading(int progress) { | |
| 244 | + | |
| 245 | + } | |
| 246 | + | |
| 247 | + @Override | |
| 248 | + public void onDownloadFailed(String message) { | |
| 249 | + showMessage(message); | |
| 250 | + hideLoading(); | |
| 251 | + } | |
| 252 | + }); | |
| 253 | + } | |
| 254 | + | |
| 255 | + public void jumpMain(String path) { | |
| 256 | + Observable.create(new ObservableOnSubscribe<String>() { | |
| 257 | + @Override | |
| 258 | + public void subscribe(ObservableEmitter<String> emitter) throws Exception { | |
| 259 | + if (!TextUtils.isEmpty(path)) { | |
| 260 | + emitter.onNext(path); | |
| 261 | + } else { | |
| 262 | + emitter.onError(new Throwable("文件地址为空")); | |
| 263 | + } | |
| 264 | + } | |
| 265 | + | |
| 266 | + }).subscribeOn(Schedulers.io()) //指定被观察者中的方法在io线程中进行处理 | |
| 267 | + .observeOn(AndroidSchedulers.mainThread()) //指定观察者接收数据在主线程中 | |
| 268 | + .subscribe(new Observer<String>() { | |
| 269 | + @Override | |
| 270 | + public void onSubscribe(Disposable d) { | |
| 271 | + } | |
| 272 | + | |
| 273 | + @Override | |
| 274 | + public void onNext(String s) { | |
| 275 | + hideLoading(); | |
| 276 | + showSucessfulMessage("下载完成"); | |
| 277 | + if (activity != null) { | |
| 278 | + try { | |
| 279 | + File file = FileUtils.getFileByPath(s); | |
| 280 | + if (file != null && file.exists()) { | |
| 281 | + ContentResolver localContentResolver = activity.getContentResolver(); | |
| 282 | + if (localContentResolver != null) { | |
| 283 | + ContentValues localContentValues = getVideoContentValues(file); | |
| 284 | + if (localContentValues != null) | |
| 285 | + localContentResolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, localContentValues); | |
| 286 | + } | |
| 287 | + activity.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + s))); | |
| 288 | + } | |
| 289 | + } catch (Exception e) { | |
| 290 | + e.printStackTrace(); | |
| 291 | + } | |
| 292 | + | |
| 293 | + } | |
| 294 | + } | |
| 295 | + | |
| 296 | + @Override | |
| 297 | + public void onError(Throwable e) { | |
| 298 | + showMessage(e.getMessage()); | |
| 299 | + } | |
| 300 | + | |
| 301 | + @Override | |
| 302 | + public void onComplete() { | |
| 303 | + | |
| 304 | + } | |
| 305 | + }); | |
| 306 | + } | |
| 307 | + | |
| 308 | + public ContentValues getVideoContentValues(File paramFile) { | |
| 309 | + long paramLong = System.currentTimeMillis(); | |
| 310 | + if (paramFile == null || !paramFile.exists()) return null; | |
| 311 | + ContentValues localContentValues = new ContentValues(); | |
| 312 | + localContentValues.put("title", paramFile.getName()); | |
| 313 | + localContentValues.put("_display_name", paramFile.getName()); | |
| 314 | + localContentValues.put("mime_type", "video/3gp"); | |
| 315 | + localContentValues.put("datetaken", Long.valueOf(paramLong)); | |
| 316 | + localContentValues.put("date_modified", Long.valueOf(paramLong)); | |
| 317 | + localContentValues.put("date_added", Long.valueOf(paramLong)); | |
| 318 | + localContentValues.put("_data", paramFile.getAbsolutePath()); | |
| 319 | + localContentValues.put("_size", Long.valueOf(paramFile.length())); | |
| 320 | + return localContentValues; | |
| 321 | + } | |
| 322 | + | |
| 323 | + | |
| 324 | + /** | |
| 325 | + * 二维码扫描处理 | |
| 326 | + * | |
| 327 | + * @param qrContent | |
| 328 | + */ | |
| 329 | + public void processQrContent(String qrContent) { | |
| 330 | + if (activity == null) return; | |
| 331 | + QrContentUtil.getInstance().getQrContent(activity, qrContent, new IdentifyTheQRCodeCallback() { | |
| 332 | + @Override | |
| 333 | + public void qRCodeCallback(boolean isIdentify, String message) { | |
| 334 | + hideLoading(); | |
| 335 | + if (!isIdentify) { | |
| 336 | + showMessage(message); | |
| 337 | + } | |
| 338 | + if (activity != null) activity.finish(); | |
| 339 | + } | |
| 340 | + }); | |
| 341 | + } | |
| 342 | + | |
| 343 | + public void showSucessfulMessage(String message) { | |
| 344 | + if (activity == null) return; | |
| 345 | + hideLoading(); | |
| 346 | + AlertUtil.showSuccessToast(activity, message); | |
| 347 | + } | |
| 348 | + | |
| 349 | + | |
| 350 | + public void showMessage(String message) { | |
| 351 | + if (activity == null) return; | |
| 352 | + AlertUtil.showDeftToast(activity, message); | |
| 353 | + hideLoading(); | |
| 354 | + } | |
| 355 | + | |
| 356 | + public void hideLoading() { | |
| 357 | + if (loadingDiaog != null) loadingDiaog.dismiss(); | |
| 358 | + if (activity != null) activity.finish(); | |
| 359 | + } | |
| 360 | + | |
| 361 | + public void showError() { | |
| 362 | + activity.binding.imagePre.setVisibility(View.GONE); | |
| 363 | + activity.binding.ivError.setVisibility(View.VISIBLE); | |
| 364 | + } | |
| 365 | +} | ... | ... |
core/imageload/src/main/res/layout/activity_preview_image.xml
| 1 | 1 | <?xml version="1.0" encoding="utf-8"?> |
| 2 | -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| 3 | - xmlns:app="http://schemas.android.com/apk/res-auto" | |
| 4 | - xmlns:tools="http://schemas.android.com/tools" | |
| 5 | - android:layout_width="match_parent" | |
| 6 | - android:layout_height="match_parent" | |
| 7 | - tools:context="com.cnlive.core.activity.PreviewImageActivity"> | |
| 8 | - | |
| 9 | - <com.cnlive.core.imagepreview.ImagePreView | |
| 10 | - android:id="@+id/image_pre" | |
| 2 | +<layout> | |
| 3 | + <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| 4 | + xmlns:app="http://schemas.android.com/apk/res-auto" | |
| 5 | + xmlns:tools="http://schemas.android.com/tools" | |
| 11 | 6 | android:layout_width="match_parent" |
| 12 | - android:layout_height="wrap_content"/> | |
| 7 | + android:layout_height="match_parent" | |
| 8 | + android:orientation="vertical" | |
| 9 | + tools:context="com.cnlive.core.ui.activity.PreViewImageActivity"> | |
| 10 | + | |
| 11 | + <com.cnlive.core.imagepreview.ImagePreView | |
| 12 | + android:id="@+id/image_pre" | |
| 13 | + android:layout_width="match_parent" | |
| 14 | + android:layout_height="wrap_content"/> | |
| 15 | + | |
| 16 | + <ImageView | |
| 17 | + android:id="@+id/iv_error" | |
| 18 | + android:layout_width="wrap_content" | |
| 19 | + android:layout_height="wrap_content" | |
| 20 | + android:layout_centerInParent="true" | |
| 21 | + android:scaleType="fitCenter" | |
| 22 | + android:background="@drawable/preview_zwtp" | |
| 23 | + android:visibility="gone"/> | |
| 24 | + </LinearLayout> | |
| 25 | +</layout> | |
| 13 | 26 | |
| 14 | -</LinearLayout> | ... | ... |
core/imageload/src/main/res/layout/dialog_show.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="utf-8"?> | |
| 2 | +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| 3 | + android:layout_width="match_parent" | |
| 4 | + android:layout_height="match_parent" | |
| 5 | + android:background="@color/white" | |
| 6 | + android:orientation="vertical"> | |
| 7 | + | |
| 8 | + <LinearLayout | |
| 9 | + android:id="@+id/share_friend" | |
| 10 | + android:layout_width="match_parent" | |
| 11 | + android:layout_height="wrap_content" | |
| 12 | + android:orientation="vertical" | |
| 13 | + android:visibility="gone"> | |
| 14 | + | |
| 15 | + <TextView | |
| 16 | + android:layout_width="match_parent" | |
| 17 | + android:layout_height="wrap_content" | |
| 18 | + android:gravity="center_horizontal" | |
| 19 | + android:padding="15dp" | |
| 20 | + android:text="@string/share_friend" | |
| 21 | + android:textColor="@color/color_333" | |
| 22 | + android:textSize="15sp" /> | |
| 23 | + | |
| 24 | + <View | |
| 25 | + android:layout_width="match_parent" | |
| 26 | + android:layout_height="1dp" | |
| 27 | + android:background="#f2f3f4" /> | |
| 28 | + </LinearLayout> | |
| 29 | + | |
| 30 | + <LinearLayout | |
| 31 | + android:id="@+id/share_cirfriend" | |
| 32 | + android:layout_width="match_parent" | |
| 33 | + android:layout_height="wrap_content" | |
| 34 | + android:orientation="vertical" | |
| 35 | + android:visibility="gone"> | |
| 36 | + | |
| 37 | + <TextView | |
| 38 | + android:layout_width="match_parent" | |
| 39 | + android:layout_height="wrap_content" | |
| 40 | + android:gravity="center_horizontal" | |
| 41 | + android:padding="15dp" | |
| 42 | + android:text="@string/share_circle_friend" | |
| 43 | + android:textColor="@color/color_333" | |
| 44 | + android:textSize="15sp" /> | |
| 45 | + | |
| 46 | + <View | |
| 47 | + android:layout_width="match_parent" | |
| 48 | + android:layout_height="1dp" | |
| 49 | + android:background="#f2f3f4" /> | |
| 50 | + </LinearLayout> | |
| 51 | + | |
| 52 | + <LinearLayout | |
| 53 | + android:id="@+id/cellection" | |
| 54 | + android:layout_width="match_parent" | |
| 55 | + android:layout_height="wrap_content" | |
| 56 | + android:orientation="vertical" | |
| 57 | + android:visibility="gone"> | |
| 58 | + | |
| 59 | + <TextView | |
| 60 | + android:layout_width="match_parent" | |
| 61 | + android:layout_height="wrap_content" | |
| 62 | + android:gravity="center_horizontal" | |
| 63 | + android:padding="15dp" | |
| 64 | + android:text="@string/collection" | |
| 65 | + android:textColor="@color/color_333" | |
| 66 | + android:textSize="15sp" /> | |
| 67 | + | |
| 68 | + <View | |
| 69 | + android:layout_width="match_parent" | |
| 70 | + android:layout_height="1dp" | |
| 71 | + android:background="#f2f3f4" /> | |
| 72 | + </LinearLayout> | |
| 73 | + | |
| 74 | + <LinearLayout | |
| 75 | + android:id="@+id/save_picture" | |
| 76 | + android:layout_width="match_parent" | |
| 77 | + android:layout_height="wrap_content" | |
| 78 | + android:orientation="vertical" | |
| 79 | + android:visibility="gone"> | |
| 80 | + | |
| 81 | + <TextView | |
| 82 | + android:layout_width="match_parent" | |
| 83 | + android:layout_height="wrap_content" | |
| 84 | + android:gravity="center_horizontal" | |
| 85 | + android:padding="15dp" | |
| 86 | + android:text="@string/save_pic" | |
| 87 | + android:textColor="@color/color_333" | |
| 88 | + android:textSize="15sp" /> | |
| 89 | + | |
| 90 | + <View | |
| 91 | + android:layout_width="match_parent" | |
| 92 | + android:layout_height="1dp" | |
| 93 | + android:background="#f2f3f4" /> | |
| 94 | + </LinearLayout> | |
| 95 | + | |
| 96 | + <LinearLayout | |
| 97 | + android:id="@+id/can_scan" | |
| 98 | + android:layout_width="match_parent" | |
| 99 | + android:layout_height="wrap_content" | |
| 100 | + android:orientation="vertical" | |
| 101 | + android:visibility="gone"> | |
| 102 | + | |
| 103 | + <TextView | |
| 104 | + android:layout_width="match_parent" | |
| 105 | + android:layout_height="wrap_content" | |
| 106 | + android:gravity="center_horizontal" | |
| 107 | + android:padding="15dp" | |
| 108 | + android:text="@string/scan" | |
| 109 | + android:textColor="@color/color_333" | |
| 110 | + android:textSize="15sp" /> | |
| 111 | + | |
| 112 | + <View | |
| 113 | + android:layout_width="match_parent" | |
| 114 | + android:layout_height="1dp" | |
| 115 | + android:background="#f2f3f4" /> | |
| 116 | + </LinearLayout> | |
| 117 | + | |
| 118 | + <LinearLayout | |
| 119 | + android:id="@+id/cancle" | |
| 120 | + android:layout_width="match_parent" | |
| 121 | + android:layout_height="wrap_content" | |
| 122 | + android:orientation="vertical"> | |
| 123 | + | |
| 124 | + <View | |
| 125 | + android:layout_width="match_parent" | |
| 126 | + android:layout_height="10dp" | |
| 127 | + android:background="#f2f3f4" /> | |
| 128 | + | |
| 129 | + <TextView | |
| 130 | + android:layout_width="match_parent" | |
| 131 | + android:layout_height="wrap_content" | |
| 132 | + android:gravity="center_horizontal" | |
| 133 | + android:padding="15dp" | |
| 134 | + android:text="@string/cancle" | |
| 135 | + android:textColor="@color/color_333" | |
| 136 | + android:textSize="15sp" /> | |
| 137 | + </LinearLayout> | |
| 138 | +</LinearLayout> | |
| 0 | 139 | \ No newline at end of file | ... | ... |
core/imageload/src/main/res/values/strings.xml
| 1 | 1 | <resources> |
| 2 | 2 | <string name="app_name">imageload</string> |
| 3 | + <string name="share_friend">转发好友</string> | |
| 4 | + <string name="share_circle_friend">转发生活圈</string> | |
| 5 | + <string name="collection">收藏</string> | |
| 6 | + <string name="save_pic">保存图片</string> | |
| 7 | + <string name="scan">识别二维码</string> | |
| 8 | + <string name="cancle">取消</string> | |
| 3 | 9 | </resources> | ... | ... |