增加 正文字号设置,加载Gif,Httpdns防止网络劫持,游戏截图横屏修改
This commit is contained in:
35
app/src/main/java/com/gh/common/util/HttpdnsUtils.java
Normal file
35
app/src/main/java/com/gh/common/util/HttpdnsUtils.java
Normal file
@ -0,0 +1,35 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.alibaba.sdk.android.httpdns.HttpDns;
|
||||
import com.alibaba.sdk.android.httpdns.HttpDnsService;
|
||||
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/7/11.
|
||||
*/
|
||||
public class HttpdnsUtils {
|
||||
private static HttpDnsService httpdns;
|
||||
private static String accountID = "180813";
|
||||
|
||||
public static String getUrls(Context context,String url){
|
||||
httpdns = HttpDns.getService(context,accountID);
|
||||
try {
|
||||
URL oldUrl = new URL(url);
|
||||
HttpURLConnection connection = (HttpURLConnection) oldUrl.openConnection();
|
||||
String ip = httpdns.getIpByHost(oldUrl.getHost());
|
||||
if (ip!= null){
|
||||
String newUrl = url.replaceFirst(oldUrl.getHost(), ip);
|
||||
return newUrl;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@ -2,6 +2,9 @@ package com.gh.common.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Matrix;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.animation.AlphaAnimation;
|
||||
import android.widget.ImageView;
|
||||
@ -13,15 +16,18 @@ import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
|
||||
import com.nostra13.universalimageloader.core.assist.FailReason;
|
||||
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
|
||||
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public class ImageUtils {
|
||||
private static ImageUtils singleton;
|
||||
private static ImageLoader imageLoader;
|
||||
private static DisplayImageOptions options;
|
||||
private static ImageUtils singleton;
|
||||
private static ImageLoader imageLoader;
|
||||
private static DisplayImageOptions options;
|
||||
private ArrayMap<String, WeakReference<Bitmap>> imageCache = new ArrayMap<String, WeakReference<Bitmap>>();
|
||||
|
||||
ExecutorService fixedThreadPool = Executors.newFixedThreadPool(5);
|
||||
|
||||
@ -39,18 +45,21 @@ public class ImageUtils {
|
||||
return singleton;
|
||||
}
|
||||
|
||||
private ImageUtils(Context context, int size) {
|
||||
private ImageUtils(Context context, int size) {
|
||||
|
||||
options = new DisplayImageOptions.Builder().cacheInMemory(true)
|
||||
.cacheOnDisk(true).considerExifParams(true)
|
||||
.bitmapConfig(Bitmap.Config.RGB_565)
|
||||
.imageScaleType(ImageScaleType.IN_SAMPLE_INT)
|
||||
// .showImageOnLoading(R.drawable.ocupy)
|
||||
// .showImageForEmptyUri(R.drawable.ocupy)
|
||||
// .showImageOnFail(R.drawable.ocupy)
|
||||
.build();
|
||||
|
||||
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
|
||||
context).writeDebugLogs().build();
|
||||
context).writeDebugLogs()
|
||||
.memoryCacheExtraOptions(480, 800)
|
||||
.build();
|
||||
|
||||
ImageLoader.getInstance().init(config);
|
||||
imageLoader = ImageLoader.getInstance();
|
||||
@ -130,17 +139,81 @@ public class ImageUtils {
|
||||
});
|
||||
}
|
||||
|
||||
public void display(String url, ImageView imageView, ScaleType scaleType) {
|
||||
display(url, imageView, R.drawable.ocupy, scaleType, null);
|
||||
}
|
||||
public void display(final String url, final ImageView imageView,
|
||||
final int drawable, final ScaleType scaleType,
|
||||
final OnLoadingCompleteListener listener, final int i) {
|
||||
imageLoader.displayImage(url, imageView, options,
|
||||
new ImageLoadingListener() {
|
||||
@Override
|
||||
public void onLoadingComplete(String imageUri, View view,
|
||||
Bitmap loadedImage) {
|
||||
WeakReference<Bitmap> bitmapWeakReference = imageCache.get(imageUri);
|
||||
try {
|
||||
if (bitmapWeakReference!=null){
|
||||
Bitmap bitmap = bitmapWeakReference.get();
|
||||
imageView.setImageBitmap(bitmap);
|
||||
}else {
|
||||
Matrix m = new Matrix();
|
||||
m.setRotate(i, (float) loadedImage.getWidth() / 2, (float) loadedImage.getHeight() / 2);
|
||||
Bitmap bm1 = Bitmap.createBitmap(loadedImage, 0, 0, loadedImage.getWidth(), loadedImage.getHeight(), m, true);
|
||||
imageView.setImageBitmap(bm1);
|
||||
WeakReference<Bitmap> weakBM = new WeakReference<Bitmap>(bm1);
|
||||
imageCache.put(imageUri, weakBM);
|
||||
}
|
||||
|
||||
public void display(String url, ImageView imageView) {
|
||||
display(url, imageView, R.drawable.ocupy, ScaleType.FIT_XY, null);
|
||||
}
|
||||
} catch (OutOfMemoryError ex) {
|
||||
Utils.log("Bitmap:::内存溢出");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (imageView instanceof CircleImageView) {
|
||||
imageView.setScaleType(ScaleType.CENTER_CROP);
|
||||
} else {
|
||||
imageView.setScaleType(scaleType);
|
||||
}
|
||||
if (listener != null) {
|
||||
listener.onLoadingComplete();
|
||||
}
|
||||
}
|
||||
|
||||
public void display(String url, ImageView imageView, ScaleType scaleType, OnLoadingCompleteListener listener) {
|
||||
display(url, imageView, R.drawable.ocupy, scaleType, listener);
|
||||
}
|
||||
@Override
|
||||
public void onLoadingStarted(String imageUri, View view) {
|
||||
imageView.setScaleType(ScaleType.CENTER);
|
||||
if (drawable != -1) {
|
||||
imageView.setImageResource(drawable);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingCancelled(String imageUri, View view) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingFailed(String imageUri, View view,
|
||||
FailReason reason) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void display(String url, ImageView imageView, ScaleType scaleType) {
|
||||
display(url, imageView, R.drawable.ocupy, scaleType, null);
|
||||
}
|
||||
|
||||
public void display(String url, ImageView imageView) {
|
||||
display(url, imageView, R.drawable.ocupy, ScaleType.FIT_XY, null);
|
||||
}
|
||||
|
||||
//旋转图片 i表示角度
|
||||
public void display(String url, ImageView imageView, int i, boolean isHorizontal) {
|
||||
display(url, imageView, R.drawable.ocupy, ScaleType.FIT_XY, null, i);
|
||||
}
|
||||
|
||||
public void display(String url, ImageView imageView, ScaleType scaleType, OnLoadingCompleteListener listener) {
|
||||
display(url, imageView, R.drawable.ocupy, scaleType, listener);
|
||||
}
|
||||
|
||||
public void display(String url, ImageView imageView, OnLoadingCompleteListener listener) {
|
||||
display(url, imageView, R.drawable.ocupy, ScaleType.FIT_XY, listener);
|
||||
|
||||
@ -4,6 +4,7 @@ import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.gh.common.util.HttpdnsUtils;
|
||||
import com.gh.common.util.Trace;
|
||||
import com.gh.common.util.Utils;
|
||||
|
||||
@ -52,14 +53,28 @@ public class DownloadThread extends Thread {
|
||||
fileOutputStream = new FileOutputStream(entry.getPath());
|
||||
}
|
||||
|
||||
//Httpdns替换地址
|
||||
String newUrl = HttpdnsUtils.getUrls(context, entry.getUrl());
|
||||
if (newUrl == null){
|
||||
newUrl = entry.getUrl();
|
||||
Utils.log("HttpDnsService::获取新地址失败,用原地址进行下载,原地址为::"+newUrl);
|
||||
}else {
|
||||
Utils.log("HttpDnsService::获取新地址成功,目标地址为::"+newUrl);
|
||||
}
|
||||
|
||||
URL url = new URL(entry.getUrl());
|
||||
HttpURLConnection connection = (HttpURLConnection) url
|
||||
.openConnection();
|
||||
// HttpURLConnection connection = (HttpURLConnection) url
|
||||
// .openConnection();
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(newUrl).openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setConnectTimeout(CONNECT_TIME);
|
||||
connection.setReadTimeout(READ_TIME);
|
||||
connection.setRequestProperty("RANGE",
|
||||
"bytes=" + targetFile.length() + "-");
|
||||
|
||||
// 设置HTTP请求头Host域
|
||||
connection.setRequestProperty("Host",url.getHost());
|
||||
|
||||
//设置自动重定向
|
||||
connection.setInstanceFollowRedirects(true);
|
||||
Trace.getInstance().debug(DownloadThread.class.getSimpleName(),
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
@ -32,6 +34,7 @@ import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.volley.NoConnectionError;
|
||||
import com.android.volley.Response;
|
||||
@ -135,8 +138,10 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
|
||||
private double R11;
|
||||
private int mActivePointerId;
|
||||
private WebSettings webSettings;
|
||||
private int defaultTextZoom = 100;
|
||||
private int defaultTextZoom = 85;
|
||||
private int scrollSize = 300;//滑动距离超过300触发事件(放大缩小字体)
|
||||
private SharedPreferences sp;
|
||||
private int fontsize;
|
||||
|
||||
private DataWatcher dataWatcher = new DataWatcher() {
|
||||
@Override
|
||||
@ -241,6 +246,31 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
|
||||
}
|
||||
});
|
||||
}
|
||||
sp = getSharedPreferences(Config.PREFERENCE, Activity.MODE_PRIVATE);
|
||||
fontsize = sp.getInt("fontsize",1);
|
||||
if (fontsize == 0){
|
||||
fontsize = 1;
|
||||
}
|
||||
}
|
||||
|
||||
private void saveFontSize(int size){
|
||||
SharedPreferences.Editor edit = sp.edit();
|
||||
edit.putInt("fontsize",size);
|
||||
edit.apply();
|
||||
}
|
||||
private String getFontSize(int i){
|
||||
switch (i){
|
||||
case 1:
|
||||
return "小字号";
|
||||
case 2:
|
||||
return "中字号";
|
||||
case 3:
|
||||
return "大字号";
|
||||
case 4:
|
||||
return "特大字号";
|
||||
default:
|
||||
return "未知字号";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -270,13 +300,19 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
|
||||
float R2 = (X2 * X2) + (Y2 * Y2);
|
||||
double R12 = Math.sqrt(R2);
|
||||
if (isSecondDown && webSettings != null) {
|
||||
if ((R11 - R12) > scrollSize) {
|
||||
defaultTextZoom -= 10;
|
||||
webSettings.setTextZoom(defaultTextZoom);
|
||||
if ((R11 - R12) > scrollSize&&fontsize>1) {
|
||||
fontsize --;
|
||||
webSettings.setTextZoom(defaultTextZoom+15*fontsize);
|
||||
saveFontSize(fontsize);
|
||||
String fontSizeText = getFontSize(fontsize);
|
||||
Toast.makeText(this,fontSizeText,Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
if ((R11 - R12) < -scrollSize) {
|
||||
defaultTextZoom += 10;
|
||||
webSettings.setTextZoom(defaultTextZoom);
|
||||
if ((R11 - R12) < -scrollSize&&fontsize<4) {
|
||||
fontsize ++;
|
||||
webSettings.setTextZoom(defaultTextZoom+15*fontsize);
|
||||
saveFontSize(fontsize);
|
||||
String fontSizeText = getFontSize(fontsize);
|
||||
Toast.makeText(this,fontSizeText,Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -1032,6 +1068,7 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
|
||||
webSettings = holder.essaydetails_wv_content.getSettings();
|
||||
webSettings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
|
||||
webSettings.setJavaScriptEnabled(true);
|
||||
webSettings.setTextZoom(defaultTextZoom+fontsize*15);
|
||||
holder.essaydetails_wv_content.loadDataWithBaseURL(null, entity.getContent(), "text/html", "utf-8", null);
|
||||
holder.essaydetails_wv_content.setWebViewClient(new WebViewClient() {
|
||||
@Override
|
||||
|
||||
@ -15,9 +15,9 @@ import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.Window;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.VolleyError;
|
||||
@ -59,7 +59,7 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
private SwitchButton setting_sb_autoinstall, setting_sb_autodelete,
|
||||
setting_sb_deletedata, setting_sb_autoupdate;
|
||||
private TextView setting_tv_version, app_tv_speed, app_tv_percent,
|
||||
app_btn_cancel, setting_tv_cache;
|
||||
app_btn_cancel, setting_tv_cache,setting_tv_size;
|
||||
private ProgressBar app_pb_progress;
|
||||
|
||||
private SharedPreferences sp;
|
||||
@ -73,6 +73,8 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
|
||||
private Handler handler = new Handler();
|
||||
|
||||
private int checkSizeIndex;
|
||||
|
||||
private DataWatcher dataWatcher = new DataWatcher() {
|
||||
|
||||
@Override
|
||||
@ -147,12 +149,17 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
setting_sb_autodelete.setChecked(sp.getBoolean("autodelete", true));
|
||||
setting_sb_deletedata.setChecked(sp.getBoolean("deletedata", true));
|
||||
setting_sb_autoupdate.setChecked(sp.getBoolean("autoupdate", true));
|
||||
checkSizeIndex = sp.getInt("fontsize",1);
|
||||
|
||||
if (sp.getBoolean("isShowDisclaimer", false)) {
|
||||
TextView setting_tv_disclaimer = (TextView) findViewById(R.id.setting_tv_disclaimer);
|
||||
setting_tv_disclaimer.setVisibility(View.VISIBLE);
|
||||
setting_tv_disclaimer.setOnClickListener(this);
|
||||
}
|
||||
if (checkSizeIndex == 0){
|
||||
checkSizeIndex = 1;
|
||||
}
|
||||
fontTextSize(checkSizeIndex);
|
||||
}
|
||||
|
||||
// 获取缓存大小
|
||||
@ -196,6 +203,7 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
mEditor.putBoolean("autodelete", setting_sb_autodelete.isChecked());
|
||||
mEditor.putBoolean("deletedata", setting_sb_deletedata.isChecked());
|
||||
mEditor.putBoolean("autoupdate", setting_sb_autoupdate.isChecked());
|
||||
mEditor.putInt("fontsize",checkSizeIndex);
|
||||
mEditor.apply();
|
||||
}
|
||||
|
||||
@ -239,38 +247,62 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
}
|
||||
break;
|
||||
case R.id.setting_rl_font_size:
|
||||
final Dialog dialog = new Dialog(this);
|
||||
View inflate = LayoutInflater.from(this).inflate(R.layout.dialog_font_size, null);
|
||||
TextView tv_negative = (TextView) inflate.findViewById(R.id.font_size_negative);
|
||||
TextView tv_positive = (TextView) inflate.findViewById(R.id.font_size_positive);
|
||||
final RadioGroup radioGroup = (RadioGroup) inflate.findViewById(R.id.font_size_radiogroup);
|
||||
tv_negative.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
tv_positive.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int checkedRadioButtonId = radioGroup.getCheckedRadioButtonId();
|
||||
int index = checkedRadioButtonId % 4;
|
||||
if (index == 0) {
|
||||
index = 4;
|
||||
}
|
||||
Toast.makeText(getApplicationContext(), "" +index, Toast.LENGTH_SHORT).show();
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(inflate);
|
||||
dialog.show();
|
||||
fontSize();
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
private void fontTextSize(int i){
|
||||
switch (i){
|
||||
case 1:
|
||||
setting_tv_size.setText("小字号");
|
||||
break;
|
||||
case 2:
|
||||
setting_tv_size.setText("中字号");
|
||||
break;
|
||||
case 3:
|
||||
setting_tv_size.setText("大字号");
|
||||
break;
|
||||
case 4:
|
||||
setting_tv_size.setText("特大字号");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//设置正文字号
|
||||
private void fontSize() {
|
||||
final Dialog dialog = new Dialog(this);
|
||||
View inflate = LayoutInflater.from(this).inflate(R.layout.dialog_font_size, null);
|
||||
TextView tv_negative = (TextView) inflate.findViewById(R.id.font_size_negative);
|
||||
TextView tv_positive = (TextView) inflate.findViewById(R.id.font_size_positive);
|
||||
final RadioGroup radioGroup = (RadioGroup) inflate.findViewById(R.id.font_size_radiogroup);
|
||||
((RadioButton)(radioGroup.getChildAt(checkSizeIndex-1))).setChecked(true);
|
||||
|
||||
tv_negative.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
tv_positive.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
checkSizeIndex = radioGroup.getCheckedRadioButtonId() % 4;
|
||||
|
||||
if (checkSizeIndex == 0){
|
||||
checkSizeIndex = 4;
|
||||
}
|
||||
dialog.cancel();
|
||||
saveCurrentSetting();
|
||||
fontTextSize(checkSizeIndex);
|
||||
}
|
||||
});
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(inflate);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
// 清除缓存
|
||||
private void claerCache() {
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
@ -22,16 +23,17 @@ import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.view.Gh_ImageLayout;
|
||||
import com.gh.common.view.Gh_ImageLayout.OnSingleTapListener;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
|
||||
//import com.facebook.drawee.backends.pipeline.Fresco;
|
||||
//import com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilder;
|
||||
//import com.facebook.drawee.view.SimpleDraweeView;
|
||||
//import com.facebook.imagepipeline.request.ImageRequest;
|
||||
//import com.facebook.imagepipeline.request.ImageRequestBuilder;
|
||||
import pl.droidsonroids.gif.GifDrawable;
|
||||
import pl.droidsonroids.gif.GifImageView;
|
||||
|
||||
|
||||
/**
|
||||
* 查看游戏截图页面
|
||||
@ -49,7 +51,9 @@ public class ViewImageActivity extends BaseActivity implements
|
||||
private int current;
|
||||
private int width;
|
||||
private String scaleType;
|
||||
|
||||
private ImageView imageView;
|
||||
private boolean isOrientation;
|
||||
private boolean isLoading = false;
|
||||
private Handler handler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
@ -95,6 +99,7 @@ public class ViewImageActivity extends BaseActivity implements
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
current = savedInstanceState.getInt("currentItem", 0);
|
||||
isOrientation = savedInstanceState.getBoolean("isOrientation");
|
||||
}
|
||||
|
||||
setContentView(R.layout.activity_viewimage);
|
||||
@ -116,12 +121,25 @@ public class ViewImageActivity extends BaseActivity implements
|
||||
viewimage_vp_show.setAdapter(adapter);
|
||||
viewimage_vp_show.setCurrentItem(current);
|
||||
viewimage_vp_show.addOnPageChangeListener(this);
|
||||
|
||||
if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
|
||||
|
||||
{
|
||||
isOrientation = true; // 横屏
|
||||
|
||||
} else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)
|
||||
|
||||
{
|
||||
isOrientation = false;// 竖屏
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putInt("currentItem", viewimage_vp_show.getCurrentItem());
|
||||
outState.putBoolean("isOrientation", isOrientation);
|
||||
}
|
||||
|
||||
private class ViewImageAdapter extends PagerAdapter implements
|
||||
@ -129,6 +147,9 @@ public class ViewImageActivity extends BaseActivity implements
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
if (urls == null) {
|
||||
return 0;
|
||||
}
|
||||
return urls.size();
|
||||
}
|
||||
|
||||
@ -138,30 +159,29 @@ public class ViewImageActivity extends BaseActivity implements
|
||||
Gh_ImageLayout view = (Gh_ImageLayout) View.inflate(container.getContext(),
|
||||
R.layout.viewimage_item, null);
|
||||
view.setOnSingleTapListener(this);
|
||||
// if (url.contains(".gif")) {
|
||||
// SimpleDraweeView simpleDraweeView = (SimpleDraweeView) view.findViewById(R.id.test_gif);
|
||||
// ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url))
|
||||
// .build();
|
||||
// PipelineDraweeControllerBuilder controllerBuilder = Fresco.newDraweeControllerBuilder()
|
||||
// .setAutoPlayAnimations(true)
|
||||
// .setTapToRetryEnabled(true)
|
||||
// .setImageRequest(imageRequest);
|
||||
// simpleDraweeView.setController(controllerBuilder.build());
|
||||
// ViewParent parent = simpleDraweeView.getParent();
|
||||
//
|
||||
// if (parent != null) {
|
||||
// ViewGroup parent1 = (ViewGroup) parent;
|
||||
// parent1.removeView(simpleDraweeView);
|
||||
// }
|
||||
// container.addView(simpleDraweeView);
|
||||
// return simpleDraweeView;
|
||||
//
|
||||
// } else {
|
||||
ImageView imageView = (ImageView) view.findViewById(R.id.viewimage_iv_show);
|
||||
if (url.contains(".gif")) {
|
||||
GifImageView gifImageView = (GifImageView) view.findViewById(R.id.gifView);
|
||||
ViewParent parent = gifImageView.getParent();
|
||||
if (!isLoading) {
|
||||
LoadGifData(gifImageView, urls.get(position));
|
||||
}
|
||||
|
||||
if (parent != null) {
|
||||
ViewGroup parent1 = (ViewGroup) parent;
|
||||
parent1.removeView(gifImageView);
|
||||
}
|
||||
container.addView(gifImageView);
|
||||
return gifImageView;
|
||||
|
||||
} else {
|
||||
imageView = (ImageView) view.findViewById(R.id.viewimage_iv_show);
|
||||
if (scaleType != null) {
|
||||
ImageUtils.getInstance(getApplicationContext()).display(
|
||||
urls.get(position), imageView, ScaleType.FIT_CENTER);
|
||||
} else {
|
||||
} else if (isOrientation && imageView.getDrawable() == null) {
|
||||
ImageUtils.getInstance(getApplicationContext()).display(
|
||||
urls.get(position), imageView, 270, isOrientation);
|
||||
} else if (imageView.getDrawable() == null) {
|
||||
ImageUtils.getInstance(getApplicationContext()).display(
|
||||
urls.get(position), imageView);
|
||||
}
|
||||
@ -177,10 +197,52 @@ public class ViewImageActivity extends BaseActivity implements
|
||||
view.setTag(position);
|
||||
container.addView(imageView);
|
||||
return imageView;
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void LoadGifData(final GifImageView gifImageView, final String gifUrl) {
|
||||
isLoading = true;
|
||||
gifImageView.setImageResource(R.drawable.ocupy);
|
||||
gifImageView.setScaleType(ScaleType.CENTER);
|
||||
final GifDrawable[] gifDrawable = {null};
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
URL url = new URL(gifUrl);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("GET");
|
||||
conn.setConnectTimeout(5 * 1000);
|
||||
conn.setReadTimeout(5 * 1000);
|
||||
conn.connect();
|
||||
if (conn.getResponseCode() == 200) {
|
||||
InputStream inputStream = conn.getInputStream();
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
byte[] data = new byte[1024 * 5];
|
||||
int count = -1;
|
||||
while ((count = inputStream.read(data, 0, 1024 * 5)) != -1) {
|
||||
output.write(data, 0, count);
|
||||
}
|
||||
byte[] bytes = output.toByteArray();
|
||||
gifDrawable[0] = new GifDrawable(bytes);
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
gifImageView.setImageDrawable(gifDrawable[0]);
|
||||
gifImageView.setScaleType(ScaleType.FIT_CENTER);
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isViewFromObject(View view, Object object) {
|
||||
return view == object;
|
||||
@ -235,6 +297,10 @@ public class ViewImageActivity extends BaseActivity implements
|
||||
int code = connection.getResponseCode();
|
||||
if (code == 200) {
|
||||
//图片存在
|
||||
if (urls == null) {
|
||||
return;
|
||||
}
|
||||
//urls出现空指针
|
||||
for (int i = 0, size = urls.size(); i < size; i++) {
|
||||
if (urls.get(i).equals(url)) {
|
||||
urls.set(i, newUrl);
|
||||
@ -260,5 +326,7 @@ public class ViewImageActivity extends BaseActivity implements
|
||||
viewimage_slide_line = null;
|
||||
rparams = null;
|
||||
urls = null;
|
||||
imageView = null;
|
||||
System.gc();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user