Skip to content

Commit

Permalink
修复保存图片的逻辑,图片一定要加上后缀
Browse files Browse the repository at this point in the history
  • Loading branch information
郭文明 committed Sep 2, 2016
1 parent 0c04fd3 commit 2bbc3c6
Show file tree
Hide file tree
Showing 24 changed files with 184 additions and 96 deletions.
1 change: 1 addition & 0 deletions weiSwift/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
<uses-permission android:name="android.permission.VIBRATE"/>

<application
android:name=".MyApplication"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import com.wenming.weiswift.mvp.presenter.imp.GroupListPresenterImp;
import com.wenming.weiswift.mvp.view.GroupPopWindowView;
import com.wenming.weiswift.ui.common.NewFeature;
import com.wenming.weiswift.ui.login.fragment.home.imagedetaillist.ImageOptionPopupWindow;
import com.wenming.weiswift.ui.login.fragment.home.imagedetaillist.ImageDetailDialog;
import com.wenming.weiswift.utils.DensityUtil;
import com.wenming.weiswift.utils.ToastUtil;

Expand Down Expand Up @@ -49,7 +49,7 @@ public class GroupPopWindow extends PopupWindow implements GroupPopWindowView {

public static GroupPopWindow getInstance(Context context, int width, int height) {
if (mGroupPopWindow == null) {
synchronized (ImageOptionPopupWindow.class) {
synchronized (ImageDetailDialog.class) {
if (mGroupPopWindow == null) {
mGroupPopWindow = new GroupPopWindow(context.getApplicationContext(), width, height);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
package com.wenming.weiswift.ui.login.fragment.home.imagedetaillist;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.provider.MediaStore;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

Expand All @@ -18,20 +13,16 @@
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;
import com.nostra13.universalimageloader.utils.DiskCacheUtils;
import com.wenming.weiswift.R;
import com.wenming.weiswift.ui.common.BasePopupWindow;
import com.wenming.weiswift.utils.SaveImgUtil;
import com.wenming.weiswift.utils.ScreenUtil;
import com.wenming.weiswift.utils.ToastUtil;

import java.io.File;
import java.io.FileNotFoundException;

/**
* Created by xiangflight on 2016/4/22.
*/
public class ImageOptionPopupWindow extends BasePopupWindow {
public class ImageDetailDialog extends Dialog {

private View mView;
private TextView mCancalTextView;
private TextView mSavePicTextView;
private TextView mRetweetTextView;
Expand All @@ -41,7 +32,7 @@ public class ImageOptionPopupWindow extends BasePopupWindow {
/**
* 用于加载微博列表图片的配置,进行安全压缩,尽可能的展示图片细节
*/
private static DisplayImageOptions ImageOptions = new DisplayImageOptions.Builder()
private static DisplayImageOptions mImageOptions = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.message_image_default)
.showImageForEmptyUri(R.drawable.message_image_default)
.showImageOnFail(R.drawable.timeline_image_failure)
Expand All @@ -51,49 +42,29 @@ public class ImageOptionPopupWindow extends BasePopupWindow {
.cacheInMemory(true)
.cacheOnDisk(true)
.build();
;


public ImageOptionPopupWindow(String url, Context context) {
super(context, (Activity) context, 300);
public ImageDetailDialog(String url, Context context) {
super(context, R.style.ImageSaveDialog);
mContext = context;
mImgURL = url;
initPopWindow(mContext);
mView = LayoutInflater.from(mContext).inflate(R.layout.home_image_detail_list_pop_window, null);
this.setContentView(mView);
initOnClickListener(mContext);
}

private void initPopWindow(Context context) {
// 设置popupWindow的外部属性
// 设置宽高
this.setWidth(ScreenUtil.getScreenWidth(context));
this.setHeight(ScreenUtil.getScreenHeight(context) * 22 / 100);
// 设置弹出窗口可点击
this.setFocusable(true);
// 设置窗口外部可点击
this.setOutsideTouchable(true);
// 设置drawable,必须得设置
this.setBackgroundDrawable(new BitmapDrawable());
// 设置弹出window的动画效果,从底部弹出
this.setAnimationStyle(R.style.image_option_pop_window_anim_style);
// 设置点击外部隐藏window
this.setTouchInterceptor(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
dismiss();
return true;
}
return false;
}
});
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home_image_detail_list_pop_window);
mCancalTextView = (TextView) findViewById(R.id.pop_cancal);
mSavePicTextView = (TextView) findViewById(R.id.pop_savcpic);
mRetweetTextView = (TextView) findViewById(R.id.pop_retweet);
setCanceledOnTouchOutside(true);
setCancelable(true);
setUpListener(mContext);
}

private void initOnClickListener(final Context context) {
mCancalTextView = (TextView) mView.findViewById(R.id.pop_cancal);
mSavePicTextView = (TextView) mView.findViewById(R.id.pop_savcpic);
mRetweetTextView = (TextView) mView.findViewById(R.id.pop_retweet);

private void setUpListener(final Context context) {
mCancalTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand All @@ -109,10 +80,9 @@ public void onClick(View v) {
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
super.onLoadingComplete(imageUri, view, loadedImage);
File imgFile = DiskCacheUtils.findInCache(mImgURL, ImageLoader.getInstance().getDiskCache());
SaveImgUtil.create(mContext).saveImage(imgFile,loadedImage);
SaveImgUtil.create(mContext).saveImage(imgFile, loadedImage);
}
});

}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
import android.content.Context;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.Gravity;
import android.view.View;
import android.view.Window;

import com.wenming.weiswift.R;
import com.wenming.weiswift.ui.common.StatusBarUtils;
import com.wenming.weiswift.utils.SharedPreferencesUtil;

import java.util.ArrayList;

Expand Down Expand Up @@ -86,20 +84,14 @@ public void onPageScrollStateChanged(int state) {
mImageDetailTopBar.setOnMoreOptionsListener(new ImageDetailTopBar.OnMoreOptionsListener() {
@Override
public void onClick(View view) {
ImageOptionPopupWindow mPopupWindow = new ImageOptionPopupWindow(mDatas.get(mViewPager.getCurrentItem()), mContext);
if (mPopupWindow.isShowing()) {
mPopupWindow.dismiss();
} else {
mPopupWindow.showAtLocation(findViewById(R.id.frameLayout), Gravity.BOTTOM, 0, 0);
}
SaveImageDialog.showDialog(mDatas.get(mViewPager.getCurrentItem()), mContext);
}
});

StatusBarUtils.from(this)
.setTransparentStatusbar(true)
.setStatusBarColor(getResources().getColor(R.color.black))
.process(this);

}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.wenming.weiswift.ui.login.fragment.home.imagedetaillist;

import android.content.Context;
import android.os.Vibrator;
import android.view.Gravity;
import android.view.ViewGroup;

import com.wenming.weiswift.utils.DensityUtil;
import com.wenming.weiswift.utils.ScreenUtil;

/**
* Created by wenmingvs on 16/9/2.
*/
public class SaveImageDialog {

public static void showDialog(String url, Context context) {
ImageDetailDialog dialog = new ImageDetailDialog(url, context);
if (dialog.isShowing()) {
dialog.dismiss();
} else {
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(50);
dialog.show();
dialog.getWindow().setLayout((ViewGroup.LayoutParams.MATCH_PARENT), (ViewGroup.LayoutParams.WRAP_CONTENT));
dialog.getWindow().setGravity(Gravity.BOTTOM);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import android.graphics.PointF;
import android.support.v4.view.PagerAdapter;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import com.cesards.cropimageview.CropImageView;
import com.davemorrissey.labs.subscaleview.ImageSource;
import com.davemorrissey.labs.subscaleview.ImageViewState;
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
Expand All @@ -30,6 +30,7 @@
import pl.droidsonroids.gif.GifDrawable;
import pl.droidsonroids.gif.GifImageView;
import uk.co.senab.photoview.PhotoView;
import uk.co.senab.photoview.PhotoViewAttacher;


/**
Expand Down Expand Up @@ -81,17 +82,24 @@ public Object instantiateItem(ViewGroup container, final int position) {
final RelativeLayout bgLayout = (RelativeLayout) mView.findViewById(R.id.ImageViewItemLayout);
final DonutProgress donutProgress = (DonutProgress) mView.findViewById(R.id.donut_progress);

final PhotoView preImageView = (PhotoView) mView.findViewById(R.id.previewImg);
final SubsamplingScaleImageView longImg = (SubsamplingScaleImageView) mView.findViewById(R.id.longImg);
final GifImageView gifImageView = (GifImageView) mView.findViewById(R.id.gifView);
final uk.co.senab.photoview.PhotoView norImgView = (uk.co.senab.photoview.PhotoView) mView.findViewById(R.id.norImg);
setOnClickListener(bgLayout, longImg, gifImageView, norImgView);
setOnLongClickListener(bgLayout, longImg, gifImageView, norImgView, position);
final PhotoView norImgView = (uk.co.senab.photoview.PhotoView) mView.findViewById(R.id.norImg);


setOnClickListener(preImageView,bgLayout, longImg, gifImageView, norImgView);
setOnLongClickListener(preImageView,bgLayout, longImg, gifImageView, norImgView, position);

ImageLoader.getInstance().loadImage(mDatas.get(position), null, options, new SimpleImageLoadingListener() {
@Override
public void onLoadingStarted(String s, View view) {
if (DiskCacheUtils.findInCache(mDatas.get(position), ImageLoader.getInstance().getDiskCache()) == null) {

File bimiddleImg = DiskCacheUtils.findInCache(mDatas.get(position), ImageLoader.getInstance().getDiskCache());

if (bimiddleImg == null) {
donutProgress.setVisibility(View.VISIBLE);
ImageLoader.getInstance().displayImage(mDatas.get(position).replace("large", "bmiddle"), preImageView);
} else {
donutProgress.setVisibility(View.GONE);
}
Expand All @@ -100,29 +108,33 @@ public void onLoadingStarted(String s, View view) {
@Override
public void onLoadingFailed(String s, View view, FailReason failReason) {
donutProgress.setVisibility(View.GONE);
preImageView.setVisibility(View.VISIBLE);
}

@Override
public void onLoadingComplete(String s, final View view, Bitmap bitmap) {
File file = DiskCacheUtils.findInCache(mDatas.get(position), ImageLoader.getInstance().getDiskCache());
preImageView.setVisibility(View.GONE);
if (mDatas.get(position).endsWith(".gif")) {
gifImageView.setVisibility(View.VISIBLE);
longImg.setVisibility(View.INVISIBLE);
norImgView.setVisibility(View.INVISIBLE);
File file = DiskCacheUtils.findInCache(mDatas.get(position), ImageLoader.getInstance().getDiskCache());
displayGif(file, gifImageView);
} else if (bitmap.getHeight() > bitmap.getWidth() * 3) {
longImg.setVisibility(View.VISIBLE);
gifImageView.setVisibility(View.INVISIBLE);
norImgView.setVisibility(View.INVISIBLE);
File file = DiskCacheUtils.findInCache(mDatas.get(position), ImageLoader.getInstance().getDiskCache());
displayLongPic(file, bitmap, longImg);
} else {
norImgView.setVisibility(View.VISIBLE);
gifImageView.setVisibility(View.INVISIBLE);
longImg.setVisibility(View.INVISIBLE);
displayNormalImg(file, bitmap, norImgView);
displayNormalImg(bitmap, norImgView);
}
donutProgress.setProgress(100);
donutProgress.setVisibility(View.GONE);

}
}, new ImageLoadingProgressListener() {
@Override
Expand All @@ -134,7 +146,14 @@ public void onProgressUpdate(String s, View view, int current, int total) {
return mView;
}

private void setOnLongClickListener(final RelativeLayout bgLayout, SubsamplingScaleImageView longImg, GifImageView gifImageView, uk.co.senab.photoview.PhotoView photoView, final int position) {
private void setOnLongClickListener(PhotoView preImageView, final RelativeLayout bgLayout, SubsamplingScaleImageView longImg, GifImageView gifImageView, PhotoView photoView, final int position) {
preImageView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
showPopWindow(bgLayout, position);
return false;
}
});
longImg.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
Expand All @@ -158,13 +177,24 @@ public boolean onLongClick(View v) {
});
}

private void setOnClickListener(RelativeLayout relativeLayout, SubsamplingScaleImageView longImg, GifImageView gifImageView, uk.co.senab.photoview.PhotoView photoView) {
private void setOnClickListener(PhotoView preImageView, RelativeLayout relativeLayout, SubsamplingScaleImageView longImg, GifImageView gifImageView, PhotoView photoView) {
relativeLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onSingleTagListener.onTag();
}
});
preImageView.setOnPhotoTapListener(new PhotoViewAttacher.OnPhotoTapListener() {
@Override
public void onPhotoTap(View view, float v, float v1) {
onSingleTagListener.onTag();
}

@Override
public void onOutsidePhotoTap() {
onSingleTagListener.onTag();
}
});
longImg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand All @@ -177,7 +207,7 @@ public void onClick(View v) {
onSingleTagListener.onTag();
}
});
photoView.setOnPhotoTapListener(new uk.co.senab.photoview.PhotoViewAttacher.OnPhotoTapListener() {
photoView.setOnPhotoTapListener(new PhotoViewAttacher.OnPhotoTapListener() {
@Override
public void onPhotoTap(View view, float v, float v1) {
onSingleTagListener.onTag();
Expand Down Expand Up @@ -205,7 +235,7 @@ public void displayGif(File file, GifImageView gifImageView) {
}
}

private void displayNormalImg(File file, Bitmap bitmap, PhotoView photoView) {
private void displayNormalImg(Bitmap bitmap, PhotoView photoView) {
photoView.setImageBitmap(bitmap);
}

Expand All @@ -220,12 +250,7 @@ private void displayLongPic(File file, Bitmap bitmap, SubsamplingScaleImageView
}

private void showPopWindow(View parent, int position) {
ImageOptionPopupWindow mPopupWindow = new ImageOptionPopupWindow(mDatas.get(position), mContext);
if (mPopupWindow.isShowing()) {
mPopupWindow.dismiss();
} else {
mPopupWindow.showAtLocation(parent, Gravity.BOTTOM, 0, 0);
}
SaveImageDialog.showDialog(mDatas.get(position), mContext);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import com.wenming.weiswift.R;
import com.wenming.weiswift.ui.common.login.Constants;
import com.wenming.weiswift.ui.login.fragment.home.imagedetaillist.ImageOptionPopupWindow;
import com.wenming.weiswift.ui.login.fragment.home.imagedetaillist.ImageDetailDialog;
import com.wenming.weiswift.ui.login.fragment.message.IGroupItemClick;

/**
Expand All @@ -37,7 +37,7 @@ public class GroupPopWindow extends PopupWindow {

public static GroupPopWindow getInstance(Context context, int width, int height) {
if (mGroupPopWindow == null) {
synchronized (ImageOptionPopupWindow.class) {
synchronized (ImageDetailDialog.class) {
if (mGroupPopWindow == null) {
mGroupPopWindow = new GroupPopWindow(context.getApplicationContext(), width, height);
}
Expand Down
Loading

0 comments on commit 2bbc3c6

Please sign in to comment.