正在查看: 自健身 v3.3.4 应用的 GallyActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: 自健身 v3.3.4 应用的 GallyActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.mu.gymtrain.Widget.PicChosePackage;
import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import butterknife.BindView;
import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.FutureTarget;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.Target;
import com.mu.gymtrain.Base.BaseActivity;
import com.mu.gymtrain.R;
import com.mu.gymtrain.Utils.AppOperator;
import com.mu.gymtrain.Utils.PicturesCompressor;
import com.mu.gymtrain.Widget.PicChosePackage.TweetPicturesPreviewer.ImagePreviewView;
import com.mu.gymtrain.Widget.PicChosePackage.TweetPicturesPreviewer.PreviewerViewPager;
import java.io.File;
public class GallyActivity extends BaseActivity implements ViewPager.OnPageChangeListener {
public static final String KEY_COOKIE = "cookie";
public static final String KEY_IMAGE = "images";
public static final String KEY_NEED_SAVE = "save";
public static final String KEY_POSITION = "position";
private int mCurPosition;
private Point mDisplayDimens;
private String[] mImageSources;
private boolean mNeedCookie;
@BindView(R.id.tv_index)
TextView tvIndex;
@BindView(R.id.vp_image)
PreviewerViewPager vpImage;
interface DoOverrideSizeCallback {
void onDone(int overrideW, int overrideH, boolean isTrue);
}
public int getContentLayout() {
return R.layout.activity_gally;
}
public void onClick(View view) {
}
public void onPageScrollStateChanged(int state) {
}
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
public void onPageSelected(int position) {
}
public static void show(Context context, String images) {
show(context, images, true);
}
public static void show(Context context, String images, boolean needSaveLocal) {
if (images == null) {
return;
}
show(context, new String[]{images}, 0, needSaveLocal);
}
public static void show(Context context, String images, boolean needSaveLocal, boolean needCookie) {
if (images == null) {
return;
}
show(context, new String[]{images}, 0, needSaveLocal, needCookie);
}
public static void show(Context context, String[] images, int position) {
show(context, images, position, true);
}
public static void show(Context context, String[] images, int position, boolean needSaveLocal) {
show(context, images, position, needSaveLocal, false);
}
public static void show(Context context, String[] images, int position, boolean needSaveLocal, boolean needCookie) {
if (images == null || images.length == 0) {
return;
}
Intent intent = new Intent(context, (Class<?>) GallyActivity.class);
intent.putExtra("images", images);
intent.putExtra("position", position);
intent.putExtra(KEY_NEED_SAVE, needSaveLocal);
intent.putExtra(KEY_COOKIE, needCookie);
context.startActivity(intent);
}
public void initData() {
int length = this.mImageSources.length;
int i = this.mCurPosition;
if (i < 0 || i >= length) {
this.mCurPosition = 0;
}
if (length == 1) {
this.tvIndex.setVisibility(8);
}
this.vpImage.setAdapter(new ViewPagerAdapter());
this.vpImage.setCurrentItem(this.mCurPosition);
onPageSelected(this.mCurPosition);
}
public void initView() {
if (getIntent().getExtras() != null) {
Bundle extras = getIntent().getExtras();
this.mImageSources = extras.getStringArray("images");
this.mCurPosition = extras.getInt("position", 0);
this.mNeedCookie = extras.getBoolean(KEY_COOKIE, false);
}
this.vpImage.addOnPageChangeListener(this);
}
private class ViewPagerAdapter extends PagerAdapter implements ImagePreviewView.OnReachBorderListener {
private View.OnClickListener mFinishClickListener;
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
private ViewPagerAdapter() {
}
public int getCount() {
return GallyActivity.this.mImageSources.length;
}
public Object instantiateItem(ViewGroup container, int position) {
View inflate = LayoutInflater.from(container.getContext()).inflate(R.layout.item_gallery_page_contener, container, false);
ImagePreviewView imagePreviewView = (ImagePreviewView) inflate.findViewById(R.id.iv_preview);
imagePreviewView.setOnReachBorderListener(this);
ImageView imageView = (ImageView) inflate.findViewById(R.id.iv_default);
if (GallyActivity.this.mNeedCookie) {
loadImage(GallyActivity.this.mImageSources[position], imagePreviewView, imageView);
} else {
loadImage(GallyActivity.this.mImageSources[position], imagePreviewView, imageView);
}
imagePreviewView.setOnClickListener(getListener());
container.addView(inflate);
return inflate;
}
private View.OnClickListener getListener() {
if (this.mFinishClickListener == null) {
this.mFinishClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
GallyActivity.this.finish();
}
};
}
return this.mFinishClickListener;
}
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
@Override
public void onReachBorder(boolean isReached) {
GallyActivity.this.vpImage.isInterceptable(isReached);
}
private <T> void loadImage(final T urlOrPath, final ImageView previewView, final ImageView defaultView) {
loadImageDoDownAndGetOverrideSize(urlOrPath, new DoOverrideSizeCallback() {
@Override
public void onDone(int overrideW, int overrideH, boolean isTrue) {
RequestBuilder listener = GallyActivity.this.getGlide().load(urlOrPath).listener(new RequestListener<Drawable>() {
public boolean onResourceReady(Drawable drawable, Object o, Target<Drawable> target, DataSource dataSource, boolean b) {
return false;
}
public boolean onResourceReady(Object drawable, Object o, Target target, DataSource dataSource, boolean b) {
return onResourceReady((Drawable) drawable, o, (Target<Drawable>) target, dataSource, b);
}
public boolean onLoadFailed(GlideException e, Object o, Target<Drawable> target, boolean b) {
if (e != null) {
e.printStackTrace();
}
defaultView.setVisibility(0);
return false;
}
});
if (isTrue && overrideW > 0 && overrideH > 0) {
listener = listener.apply(new RequestOptions().override(overrideW, overrideH));
}
listener.into(previewView);
}
});
}
private <T> void loadImageDoDownAndGetOverrideSize(final T urlOrPath, final DoOverrideSizeCallback callback) {
final FutureTarget downloadOnly = GallyActivity.this.getGlide().load(urlOrPath).downloadOnly(Integer.MIN_VALUE, Integer.MIN_VALUE);
AppOperator.runOnThread(new Runnable() {
@Override
public void run() {
final int min;
final int min2;
try {
File file = (File) downloadOnly.get();
BitmapFactory.Options createOptions = PicturesCompressor.createOptions();
createOptions.inJustDecodeBounds = true;
BitmapFactory.decodeFile(file.getAbsolutePath(), createOptions);
int i = createOptions.outWidth;
int i2 = createOptions.outHeight;
PicturesCompressor.resetOptions(createOptions);
if (i > 0 && i2 > 0) {
Point displayDimens = GallyActivity.this.getDisplayDimens();
int min3 = Math.min(Math.min(displayDimens.y, displayDimens.x) * 5, 4098);
if (i / i2 > displayDimens.x / displayDimens.y) {
min2 = Math.min(i2, displayDimens.y);
min = Math.min(i, min3);
} else {
min = Math.min(i, displayDimens.x);
min2 = Math.min(i2, min3);
}
GallyActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
callback.onDone(min, min2, true);
}
});
return;
}
GallyActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
callback.onDone(0, 0, false);
}
});
} catch (Exception e) {
e.printStackTrace();
GallyActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
callback.onDone(0, 0, false);
}
});
}
}
});
}
}
public synchronized Point getDisplayDimens() {
Point point;
Point point2 = this.mDisplayDimens;
if (point2 != null) {
return point2;
}
Display defaultDisplay = ((WindowManager) getSystemService("window")).getDefaultDisplay();
if (Build.VERSION.SDK_INT >= 13) {
point = new Point();
defaultDisplay.getSize(point);
} else {
point = new Point(defaultDisplay.getWidth(), defaultDisplay.getHeight());
}
this.mDisplayDimens = point;
return point;
}
}