package com.baway.test;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.zip.Inflater;
import com.baidu.f1.F1;
import com.baidu.f1.Fra;
import com.baidu.vo1.Mycode;
import com.baidu.vo1.Mygallery;
import com.bwie.net.Network;
import com.google.gson.Gson;
import android.os.AsyncTask;
import android.os.Bundle;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
public class Show extends FragmentActivity {
private ViewPager vp;
private ImageView ii;
private String img;
private String id;
private List<Mygallery> gallery;
int num = 0;
private LinearLayout ll;
private List<View> list;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show);
vp = (ViewPager) findViewById(R.id.viewpager);
ll = (LinearLayout) findViewById(R.id.linear);
new Asy().execute();
Intent in = getIntent();
id = in.getStringExtra("id");
}
class Asy extends AsyncTask<String, Integer, String> {
protected String doInBackground(String... params) {
String ss = Network
.getjson("http://mobile.hmeili.com/yunifang/mobile/goods/detail?id="
+ id);
return ss;
}
protected void onPostExecute(String result) {
Gson g = new Gson();
Mycode my = g.fromJson(result, Mycode.class);
gallery = my.getData().getGoods().getGallery();
getdot();
FragmentManager fm = getSupportFragmentManager();
vp.setAdapter(new Fra(fm, getdata()));
// 设置
list.get(0).setBackgroundResource(R.drawable.check);
Timer timer = new Timer();
timer.schedule(new TimerTask() {
public void run() {
runOnUiThread(new Runnable() {
public void run() {
num++;
if (num == gallery.size()) {
num = 0;
}
vp.setCurrentItem(num);
count=num;
list.get(oldcount).setBackgroundResource(R.drawable.moren);
list.get(count).setBackgroundResource(R.drawable.check);
oldcount=count;
}
});
}
}, 1000, 1000);
}
}
int count=0;
int oldcount=0;
// 创建获得远点的方法
public void getdot() {
list = new ArrayList<View>();
for (int i = 0; i < gallery.size(); i++) {
View v = LayoutInflater.from(this).inflate(R.layout.view, null);
View dot = v.findViewById(R.id.view1);
list.add(dot);
ll.addView(v);
}
}
private List<Fragment> getdata() {
List<Fragment> li = new ArrayList<Fragment>();
for (int i = 0; i < gallery.size(); i++) {
li.add(new F1(gallery.get(i).getNormal_url()));
}
return li;
}
}