483 lines
20 KiB
Java
483 lines
20 KiB
Java
//package com.gh.gamecenter;
|
|
//
|
|
//import android.annotation.SuppressLint;
|
|
//import android.app.Activity;
|
|
//import android.app.Dialog;
|
|
//import android.content.Context;
|
|
//import android.content.Intent;
|
|
//import android.content.res.Configuration;
|
|
//import android.graphics.BitmapFactory;
|
|
//import android.graphics.Color;
|
|
//import android.net.Uri;
|
|
//import android.os.Bundle;
|
|
//import android.os.Environment;
|
|
//import android.text.TextUtils;
|
|
//import android.util.Base64;
|
|
//import android.util.DisplayMetrics;
|
|
//import android.view.View;
|
|
//import android.view.ViewGroup;
|
|
//import android.view.Window;
|
|
//import android.widget.LinearLayout;
|
|
//import android.widget.RelativeLayout;
|
|
//import android.widget.TextView;
|
|
//
|
|
//import androidx.annotation.NonNull;
|
|
//import androidx.annotation.Nullable;
|
|
//import androidx.core.content.ContextCompat;
|
|
//import androidx.viewpager.widget.PagerAdapter;
|
|
//import androidx.viewpager.widget.ViewPager.OnPageChangeListener;
|
|
//
|
|
//import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
|
|
//import com.facebook.drawee.backends.pipeline.Fresco;
|
|
//import com.facebook.imagepipeline.core.ImagePipeline;
|
|
//import com.facebook.imagepipeline.request.ImageRequest;
|
|
//import com.gh.base.BaseActivity;
|
|
//import com.gh.common.AppExecutor;
|
|
//import com.gh.common.Base64ImageHolder;
|
|
//import com.gh.common.util.DisplayUtils;
|
|
//import com.gh.common.util.EntranceUtils;
|
|
//import com.gh.common.util.ImageUtils;
|
|
//import com.gh.common.util.MD5Utils;
|
|
//import com.gh.common.util.MessageShareUtils;
|
|
//import com.gh.common.util.NetworkUtils;
|
|
//import com.gh.common.util.PermissionHelper;
|
|
//import com.gh.common.util.SimpleImageLoader;
|
|
//import com.gh.common.view.Gh_RelativeLayout;
|
|
//import com.gh.common.view.Gh_ViewPager;
|
|
//import com.gh.gamecenter.entity.ImageInfoEntity;
|
|
//import com.gh.gamecenter.retrofit.Response;
|
|
//import com.gh.gamecenter.retrofit.RetrofitManager;
|
|
//import com.github.piasy.biv.view.BigImageView;
|
|
//import com.github.piasy.biv.view.FrescoImageViewFactory;
|
|
//import com.lightgame.utils.Utils;
|
|
//
|
|
//import java.io.BufferedOutputStream;
|
|
//import java.io.File;
|
|
//import java.io.FileInputStream;
|
|
//import java.io.FileOutputStream;
|
|
//import java.io.InputStream;
|
|
//import java.io.OutputStream;
|
|
//import java.util.ArrayList;
|
|
//import java.util.HashMap;
|
|
//import java.util.HashSet;
|
|
//import java.util.Locale;
|
|
//import java.util.Map;
|
|
//
|
|
//import butterknife.BindView;
|
|
//import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
//import io.reactivex.schedulers.Schedulers;
|
|
//
|
|
///**
|
|
// * 查看游戏截图页面
|
|
// *
|
|
// * @author 黄壮华
|
|
// *
|
|
// * todo BigImageView静态webp/动态webp(ImageInfoExtractor.getImageType(image))判断有问题,导致部分静态webp无法使用缩放功能
|
|
// */
|
|
//public class ViewImageActivity extends BaseActivity implements OnPageChangeListener {
|
|
//
|
|
// public static final int REQUEST_FOR_VIEWED_IMAGE = 921;
|
|
// public static final String VIEWED_IMAGE = "viewed_image";
|
|
//
|
|
// @BindView(R.id.image_detail_page)
|
|
// Gh_ViewPager mViewPager;
|
|
// @BindView(R.id.image_detail_progress)
|
|
// TextView mProgressHint;
|
|
// @BindView(R.id.image_mask)
|
|
// View mIndicatorMask;
|
|
// @BindView(R.id.image_indicator_tv)
|
|
// TextView mIndicatorTv;
|
|
//
|
|
// private ViewImageAdapter adapter;
|
|
//
|
|
// private ImagePipeline mImagePipeline;
|
|
//
|
|
// private boolean mShowBase64Image = false;
|
|
//
|
|
// private static final String KEY_BASE64 = "base64";
|
|
//
|
|
// private static final String KEY_URLS = "urls";
|
|
// private static final String KEY_CURRENT = "current";
|
|
//
|
|
// private ArrayList<String> urls;
|
|
// private HashSet<Integer> mViewedSet; // 让调用者知道该图片是否被看过了
|
|
// private Map<String, ImageInfoEntity> mImageInfoMap;
|
|
//
|
|
// private int mLimitWidth;
|
|
//
|
|
// private boolean isOrientation;
|
|
//
|
|
// public static Intent getBase64ViewImageIntent(Context context, boolean showSingleBase64Image) {
|
|
// Intent checkIntent = new Intent(context, ViewImageActivity.class);
|
|
// checkIntent.putExtra(KEY_BASE64, showSingleBase64Image);
|
|
// return checkIntent;
|
|
// }
|
|
//
|
|
// public static Intent getViewImageIntent(Context context, ArrayList<String> list, int position, String entrance) {
|
|
// Intent checkIntent = new Intent(context, ViewImageActivity.class);
|
|
// checkIntent.putExtra(KEY_URLS, list);
|
|
// checkIntent.putExtra(KEY_CURRENT, position);
|
|
// checkIntent.putExtra(EntranceUtils.KEY_ENTRANCE, entrance);
|
|
// return checkIntent;
|
|
// }
|
|
//
|
|
// @Override
|
|
// protected int getLayoutId() {
|
|
// return R.layout.activity_viewimage;
|
|
// }
|
|
//
|
|
// @Override
|
|
// protected void onCreate(Bundle savedInstanceState) {
|
|
// super.onCreate(savedInstanceState);
|
|
// mViewedSet = new HashSet<>();
|
|
// mImageInfoMap = new HashMap<>();
|
|
// // init data
|
|
// int current = 0;
|
|
// Bundle extras = getIntent().getExtras();
|
|
// if (extras != null) {
|
|
// if (extras.getBoolean(KEY_BASE64)) {
|
|
// mShowBase64Image = true;
|
|
// urls = new ArrayList<>();
|
|
// urls.add(Base64ImageHolder.INSTANCE.getImage());
|
|
// } else {
|
|
// urls = extras.getStringArrayList(KEY_URLS);
|
|
// current = extras.getInt(KEY_CURRENT, 0);
|
|
// }
|
|
// }
|
|
//
|
|
// if (savedInstanceState != null) {
|
|
// current = savedInstanceState.getInt(EntranceUtils.KEY_CURRENTITEM, 0);
|
|
// isOrientation = savedInstanceState.getBoolean("isOrientation");
|
|
// }
|
|
//
|
|
// if (urls.size() > 1) mIndicatorMask.setVisibility(View.VISIBLE);
|
|
// mIndicatorTv.setText(String.format("%d/%d", current + 1, urls.size()));
|
|
//
|
|
// mImagePipeline = Fresco.getImagePipeline();
|
|
//
|
|
// // init slide
|
|
// DisplayMetrics outMetrics = new DisplayMetrics();
|
|
// getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
|
|
// int widthPixels = outMetrics.widthPixels;
|
|
// if (NetworkUtils.isWifiOr4GConnected(this)) {
|
|
// mLimitWidth = widthPixels * 2;
|
|
// } else {
|
|
// mLimitWidth = widthPixels;
|
|
// }
|
|
// // init viewPage
|
|
// adapter = new ViewImageAdapter();
|
|
// mViewPager.setAdapter(adapter);
|
|
// mViewPager.setCurrentItem(current);
|
|
// mViewPager.addOnPageChangeListener(this);
|
|
//
|
|
// if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
|
// isOrientation = true; // 横屏
|
|
// } else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
|
|
// isOrientation = false;// 竖屏
|
|
// }
|
|
//
|
|
// mProgressHint.setOnClickListener(v -> {
|
|
// int position = mViewPager.getCurrentItem();
|
|
// Object object = mViewPager.findViewWithTag(position);
|
|
// if (object != null) {
|
|
// mProgressHint.setWidth(mProgressHint.getWidth());
|
|
// RelativeLayout view = (RelativeLayout) object;
|
|
// final BigImageView imageView = view.findViewById(R.id.viewimage_iv_show);
|
|
// String url = urls.get(position);
|
|
// imageView.showImage(Uri.parse(url));
|
|
// imageView.setImageLoaderCallback(new SimpleImageLoader() {
|
|
// @Override
|
|
// public void onProgress(int progress) {
|
|
// if (position == mViewPager.getCurrentItem()) { // 防止下载过程中切换图片
|
|
// if (progress < 100) {
|
|
// mProgressHint.setText((progress + "%"));
|
|
// } else {
|
|
// mProgressHint.setText("已完成");
|
|
// mBaseHandler.postDelayed(() -> {
|
|
// if (position == mViewPager.getCurrentItem()) { // 防止等待过程中切换图片
|
|
// mProgressHint.setVisibility(View.GONE);
|
|
// }
|
|
// }, 500);
|
|
// }
|
|
// }
|
|
// }
|
|
// });
|
|
// }
|
|
// });
|
|
//
|
|
// DisplayUtils.transparentStatusAndNavigation(this);
|
|
// }
|
|
//
|
|
// @Override
|
|
// protected void onSaveInstanceState(Bundle outState) {
|
|
// super.onSaveInstanceState(outState);
|
|
// outState.putInt(EntranceUtils.KEY_CURRENTITEM, mViewPager.getCurrentItem());
|
|
// outState.putBoolean("isOrientation", isOrientation);
|
|
// }
|
|
//
|
|
// @Override
|
|
// protected void onDestroy() {
|
|
// super.onDestroy();
|
|
// if (mShowBase64Image) {
|
|
// urls.clear();
|
|
// Base64ImageHolder.INSTANCE.setImage("");
|
|
// }
|
|
// mViewPager.onDestroy(); // 注销EventBus
|
|
// }
|
|
//
|
|
// @Override
|
|
// public void onPageScrolled(int position, float positionOffset,
|
|
// int positionOffsetPixels) {
|
|
// if (positionOffset != 0) {
|
|
// mProgressHint.setVisibility(View.GONE);
|
|
// } else {
|
|
// String url = urls.get(position);
|
|
// ImageInfoEntity imageInfoEntity = mImageInfoMap.get(url);
|
|
// if (imageInfoEntity != null && imageInfoEntity.getFileSize() != null &&
|
|
// !mImagePipeline.isInBitmapMemoryCache(ImageRequest.fromUri(url)) &&
|
|
// !mImagePipeline.isInDiskCacheSync(ImageRequest.fromUri(url))) {
|
|
// String size = String.format(Locale.CHINA, "%.1fM",
|
|
// Integer.valueOf(imageInfoEntity.getFileSize().getValue()) / 1024F / 1024F);
|
|
// mProgressHint.setVisibility(View.VISIBLE);
|
|
// mProgressHint.setText(("查看原图(" + size + ")"));
|
|
// ViewGroup.LayoutParams layoutParams = mProgressHint.getLayoutParams();
|
|
// layoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
|
|
// mProgressHint.setLayoutParams(layoutParams);
|
|
// }
|
|
// }
|
|
//
|
|
// mViewedSet.add(position);
|
|
// setResult(Activity.RESULT_OK, new Intent().putExtra(VIEWED_IMAGE, mViewedSet));
|
|
// }
|
|
//
|
|
// @Override
|
|
// public void onPageSelected(int position) {
|
|
// Gh_RelativeLayout ghRelativeLayout;
|
|
// for (int i = 0; i < mViewPager.getChildCount(); i++) {
|
|
// if (mViewPager.getChildAt(i).getTag() != null) {
|
|
// ghRelativeLayout = (Gh_RelativeLayout) mViewPager.getChildAt(i);
|
|
// if (ghRelativeLayout == null) {
|
|
// return;
|
|
// }
|
|
//
|
|
// BigImageView imageView = ghRelativeLayout.findViewById(R.id.viewimage_iv_show);
|
|
// SubsamplingScaleImageView ssiv = imageView.getSSIV();
|
|
// if (ssiv != null) ssiv.resetScaleAndCenter();
|
|
//
|
|
// }
|
|
// }
|
|
// mIndicatorTv.setText(String.format("%d/%d", position + 1, urls.size()));
|
|
// }
|
|
//
|
|
// @Override
|
|
// public void onPageScrollStateChanged(int newState) {
|
|
//
|
|
// }
|
|
//
|
|
// private void loadImageInfo(int position, int width) {
|
|
// String url = urls.get(position);
|
|
// RetrofitManager.getInstance(this)
|
|
// .getApi().getImageInfo(url + "?x-oss-process=image/info")
|
|
// .subscribeOn(Schedulers.io())
|
|
// .observeOn(AndroidSchedulers.mainThread())
|
|
// .subscribe(new Response<ImageInfoEntity>() {
|
|
// @Override
|
|
// public void onResponse(@Nullable ImageInfoEntity response) {
|
|
// if (response != null && response.getImageWidth() != null &&
|
|
// Integer.valueOf(response.getImageWidth().getValue()) > width) {
|
|
// mImageInfoMap.put(url, response);
|
|
// if (position == mViewPager.getCurrentItem()) {
|
|
// onPageScrolled(position, 0, 0); // 刷新下载原图提示按钮
|
|
// }
|
|
// }
|
|
// }
|
|
// });
|
|
// }
|
|
//
|
|
// private void loadImage(String url, final BigImageView imageView) {
|
|
// if (TextUtils.isEmpty(url)) return;
|
|
//
|
|
// if (url.startsWith("data:image/png;base64")) {
|
|
// AppExecutor.getIoExecutor().execute(() -> {
|
|
// String base64String = url.replace("data:image/png;base64", "");
|
|
// try {
|
|
// File imageFile = new File(getCacheDir().getAbsolutePath() + File.separator + System.currentTimeMillis() + ".png");
|
|
//
|
|
// byte[] decodedString = Base64.decode(base64String, Base64.DEFAULT);
|
|
//
|
|
// BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(imageFile));
|
|
// bos.write(decodedString);
|
|
// bos.flush();
|
|
// bos.close();
|
|
//
|
|
// AppExecutor.getUiExecutor().execute(() -> {
|
|
// imageView.setImageViewFactory(new FrescoImageViewFactory());
|
|
// imageView.showImage(Uri.fromFile(imageFile));
|
|
// });
|
|
// } catch (Exception e) {
|
|
// e.printStackTrace();
|
|
// }
|
|
// });
|
|
// } else {
|
|
// // 添加GIF支持
|
|
// imageView.setImageViewFactory(new FrescoImageViewFactory());
|
|
// imageView.showImage(Uri.parse(url));
|
|
// }
|
|
// }
|
|
//
|
|
// private class ViewImageAdapter extends PagerAdapter {
|
|
//
|
|
// @Override
|
|
// public int getCount() {
|
|
// if (urls == null) {
|
|
// return 0;
|
|
// }
|
|
// return urls.size();
|
|
// }
|
|
//
|
|
// @SuppressLint("MissingPermission")
|
|
// @NonNull
|
|
// @Override
|
|
// public Object instantiateItem(@NonNull ViewGroup container, int position) {
|
|
// String url = urls.get(position);
|
|
// ImageRequest imageRequest = ImageRequest.fromUri(url);
|
|
// boolean isInMemoryCache = mImagePipeline.isInBitmapMemoryCache(imageRequest);
|
|
// boolean isInDiskCache = imageRequest != null && mImagePipeline.isInDiskCacheSync(imageRequest);
|
|
//
|
|
// Gh_RelativeLayout view = (Gh_RelativeLayout) View.inflate(container.getContext(), R.layout.viewimage_normal_item, null);
|
|
// BigImageView imageView = view.findViewById(R.id.viewimage_iv_show);
|
|
//
|
|
// if (!isInMemoryCache
|
|
// && !isInDiskCache
|
|
// && !NetworkUtils.isWifiOr4GConnected(ViewImageActivity.this)
|
|
// && !url.contains(".gif")) {
|
|
// url = ImageUtils.getTransformLimitUrl(url, mLimitWidth, getApplicationContext());
|
|
// }
|
|
//
|
|
// String finalUrl = url;
|
|
// imageView.setImageLoaderCallback(new SimpleImageLoader() {
|
|
// @Override
|
|
// public void onSuccess(File image) {
|
|
// if (!finalUrl.equals(urls.get(position))) {
|
|
// BitmapFactory.Options options = new BitmapFactory.Options();
|
|
// options.inJustDecodeBounds = true;
|
|
// BitmapFactory.decodeFile(new File(image.getPath()).getAbsolutePath(), options);
|
|
// loadImageInfo(position, options.outWidth); // 加载图片参数,目的是用户显示原文按钮
|
|
// }
|
|
// SubsamplingScaleImageView ssiv = imageView.getSSIV();
|
|
// if (ssiv != null) {
|
|
// ssiv.setMaxScale(10f); // 这个缩放倍数最好很具宽高自动调节
|
|
// ssiv.setOnImageEventListener(new SubsamplingScaleImageView.DefaultOnImageEventListener() {
|
|
// @Override
|
|
// public void onReady() {
|
|
// ssiv.resetScaleAndCenter();
|
|
// }
|
|
// });
|
|
// ssiv.setOnClickListener(v -> finish());
|
|
//
|
|
// }
|
|
// }
|
|
// });
|
|
// loadImage(url, imageView);
|
|
//
|
|
// //长按
|
|
// imageView.setOnLongClickListener(v -> {
|
|
// final Dialog dialog = new Dialog(ViewImageActivity.this);
|
|
//
|
|
// LinearLayout container1 = new LinearLayout(ViewImageActivity.this);
|
|
// container1.setOrientation(LinearLayout.VERTICAL);
|
|
// container1.setBackgroundColor(Color.WHITE);
|
|
//
|
|
// final TextView reportTv = new TextView(ViewImageActivity.this);
|
|
// reportTv.setPadding(
|
|
// DisplayUtils.dip2px(ViewImageActivity.this, 20),
|
|
// DisplayUtils.dip2px(ViewImageActivity.this, 12),
|
|
// 0,
|
|
// DisplayUtils.dip2px(ViewImageActivity.this, 12));
|
|
// reportTv.setText(R.string.save_pic);
|
|
// reportTv.setTextSize(17);
|
|
// reportTv.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.title));
|
|
// reportTv.setBackgroundResource(R.drawable.textview_white_style);
|
|
// int widthPixels = getResources().getDisplayMetrics().widthPixels;
|
|
// reportTv.setLayoutParams(new LinearLayout.LayoutParams((widthPixels * 9) / 10,
|
|
// LinearLayout.LayoutParams.WRAP_CONTENT));
|
|
// container1.addView(reportTv);
|
|
//
|
|
// dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
|
// dialog.setContentView(container1);
|
|
//
|
|
// if (!isFinishing()) {
|
|
// dialog.show();
|
|
// }
|
|
//
|
|
// reportTv.setOnClickListener(v1 -> {
|
|
// PermissionHelper.checkStoragePermissionBeforeAction(ViewImageActivity.this, () -> {
|
|
// saveImageToFile(imageView.getCurrentImageFile(), finalUrl);
|
|
// dialog.cancel();
|
|
// });
|
|
// dialog.cancel();
|
|
// });
|
|
//
|
|
// return false;
|
|
// });
|
|
//
|
|
// view.setTag(position);
|
|
// container.addView(view);
|
|
// return view;
|
|
// }
|
|
//
|
|
// private void saveImageToFile(File src, String curUrl) {
|
|
// InputStream in = null;
|
|
// OutputStream out = null;
|
|
// try {
|
|
// String fileName;
|
|
// if (mShowBase64Image) {
|
|
// fileName = MD5Utils.getUrlMD5(curUrl.substring(0, 50)) + ".png";
|
|
// } else {
|
|
// fileName = curUrl.substring(curUrl.lastIndexOf("/"));
|
|
// }
|
|
// String savePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pictures/ghzhushou/";
|
|
// File file = new File(savePath);
|
|
// if (!file.exists()) {
|
|
// file.mkdirs();
|
|
// }
|
|
//
|
|
// File dst = new File(savePath, fileName);
|
|
// if (dst.exists()) {
|
|
// dst.delete();
|
|
// }
|
|
//
|
|
// in = new FileInputStream(src);
|
|
// out = new FileOutputStream(dst);
|
|
// byte[] buf = new byte[1024];
|
|
// int len;
|
|
// while ((len = in.read(buf)) > 0) {
|
|
// out.write(buf, 0, len);
|
|
// }
|
|
//
|
|
// Utils.toast(ViewImageActivity.this, "图片已保存到/Pictures/ghzhushou/");
|
|
// MessageShareUtils.refreshImage(ViewImageActivity.this, dst);
|
|
// } catch (Exception e) {
|
|
// Utils.log("图片保存失败:" + e.toString());
|
|
// } finally {
|
|
// try {
|
|
// if (out != null) out.close();
|
|
// if (in != null) in.close();
|
|
// } catch (Exception ignore) {
|
|
// }
|
|
// }
|
|
// }
|
|
//
|
|
//
|
|
// @Override
|
|
// public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
|
|
// container.removeView((View) object);
|
|
// }
|
|
//
|
|
// @Override
|
|
// public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
|
|
// return view == object;
|
|
// }
|
|
// }
|
|
//}
|