修改数据收集接口,去掉点击加载更多,新闻和下载数据实时上传
This commit is contained in:
@ -2,21 +2,28 @@ package com.gh.gamecenter;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.v4.view.PagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v4.view.ViewPager.OnPageChangeListener;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ImageView.ScaleType;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.view.Gh_ImageView;
|
||||
import com.gh.common.view.Gh_ImageView.OnSingleTapListener;
|
||||
import com.gh.common.view.Gh_ImageLayout;
|
||||
import com.gh.common.view.Gh_ImageLayout.OnSingleTapListener;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
@ -39,9 +46,42 @@ public class ViewImageActivity extends BaseActivity implements
|
||||
private int width;
|
||||
private String scaleType;
|
||||
|
||||
private Handler handler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
notifyItemChanged(msg.arg1);
|
||||
}
|
||||
};
|
||||
|
||||
private void notifyItemChanged(int position) {
|
||||
Object object = viewimage_vp_show.findViewWithTag(position);
|
||||
if (object != null) {
|
||||
RelativeLayout view = (RelativeLayout) object;
|
||||
ImageView imageView = (ImageView) view.findViewById(R.id.viewimage_iv_show);
|
||||
final ProgressBarCircularIndeterminate progressBar = (ProgressBarCircularIndeterminate) view.findViewById(R.id.viewimage_pb_loading);
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
if (scaleType != null) {
|
||||
ImageUtils.getInstance(getApplicationContext()).display(
|
||||
urls.get(position), imageView, ScaleType.FIT_CENTER, new ImageUtils.OnLoadingCompleteListener() {
|
||||
@Override
|
||||
public void onLoadingComplete() {
|
||||
progressBar.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
ImageUtils.getInstance(getApplicationContext()).display(
|
||||
urls.get(position), imageView, new ImageUtils.OnLoadingCompleteListener() {
|
||||
@Override
|
||||
public void onLoadingComplete() {
|
||||
progressBar.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Intent intent = getIntent();
|
||||
@ -49,6 +89,10 @@ public class ViewImageActivity extends BaseActivity implements
|
||||
current = intent.getIntExtra("current", 0);
|
||||
scaleType = intent.getStringExtra("ScaleType");
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
current = savedInstanceState.getInt("currentItem", 0);
|
||||
}
|
||||
|
||||
setContentView(R.layout.activity_viewimage);
|
||||
|
||||
DisplayMetrics outMetrics = new DisplayMetrics();
|
||||
@ -70,20 +114,26 @@ public class ViewImageActivity extends BaseActivity implements
|
||||
viewimage_vp_show.addOnPageChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putInt("currentItem", viewimage_vp_show.getCurrentItem());
|
||||
}
|
||||
|
||||
private class ViewImageAdapter extends PagerAdapter implements
|
||||
OnSingleTapListener {
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
|
||||
return urls.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object instantiateItem(ViewGroup container, int position) {
|
||||
|
||||
Gh_ImageView imageView = new Gh_ImageView(ViewImageActivity.this);
|
||||
imageView.setOnSingleTapListener(this);
|
||||
Gh_ImageLayout view = (Gh_ImageLayout) View.inflate(container.getContext(),
|
||||
R.layout.viewimage_item, null);
|
||||
view.setOnSingleTapListener(this);
|
||||
ImageView imageView = (ImageView) view.findViewById(R.id.viewimage_iv_show);
|
||||
if (scaleType != null) {
|
||||
ImageUtils.getInstance(getApplicationContext()).display(
|
||||
urls.get(position), imageView, ScaleType.FIT_CENTER);
|
||||
@ -91,40 +141,40 @@ public class ViewImageActivity extends BaseActivity implements
|
||||
ImageUtils.getInstance(getApplicationContext()).display(
|
||||
urls.get(position), imageView);
|
||||
}
|
||||
container.addView(imageView);
|
||||
return imageView;
|
||||
if (!urls.get(position).startsWith("http://image.ghzhushou.com/pic/hq/")) {
|
||||
checkUrl(urls.get(position));
|
||||
}
|
||||
view.setTag(position);
|
||||
container.addView(view);
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isViewFromObject(View view, Object object) {
|
||||
|
||||
return view == object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyItem(ViewGroup container, int position, Object object) {
|
||||
|
||||
container.removeView((View) object);
|
||||
object = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSingleTap() {
|
||||
|
||||
finish();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int newState) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset,
|
||||
int positionOffsetPixels) {
|
||||
|
||||
if (positionOffset != 0) {
|
||||
rparams.leftMargin = (int) (width * (positionOffset + position));
|
||||
viewimage_slide_line.setLayoutParams(rparams);
|
||||
@ -133,13 +183,45 @@ public class ViewImageActivity extends BaseActivity implements
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void checkUrl(final String url) {
|
||||
if (!url.startsWith("http://image.ghzhushou.com/pic/")){
|
||||
return;
|
||||
}
|
||||
new Thread(){
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
String newUrl = "http://image.ghzhushou.com/pic/hq" + url.substring(url.lastIndexOf("/"));
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(newUrl).openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setConnectTimeout(5 * 1000);
|
||||
connection.setReadTimeout(5 * 1000);
|
||||
connection.connect();
|
||||
int code = connection.getResponseCode();
|
||||
if (code == 200) {
|
||||
//图片存在
|
||||
for (int i = 0, size = urls.size(); i < size; i++) {
|
||||
if (urls.get(i).equals(url)){
|
||||
urls.set(i, newUrl);
|
||||
Message msg = new Message();
|
||||
msg.arg1 = i;
|
||||
handler.sendMessage(msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
|
||||
super.onDestroy();
|
||||
viewimage_vp_show = null;
|
||||
adapter = null;
|
||||
|
||||
Reference in New Issue
Block a user