public class GuangdongZhuangche_view extends Activity {
Context context = null;
@SuppressWarnings("deprecation")
LocalActivityManager manager = null;
ViewPager pager = null;
TabHost tabHost = null;
private static final String[] m={"请选择","山东","广东"};  
private Spinner huochangspinner; 
TextView t1,t2,t3;
private static ArrayList<Waifuchechi> checihao = null;
ArrayList<View> list=null;
private int offset = 0;// 动画图片偏移量
private int currIndex = 0;// 当前页卡编号
private int bmpW;// 动画图片宽度
private ImageView cursor;// 动画图片
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_guangdong_zhuangche_view);
context = GuangdongZhuangche_view.this;
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,   
                WindowManager.LayoutParams.FLAG_FULLSCREEN); 

manager = new LocalActivityManager(this , true);
manager.dispatchCreate(savedInstanceState);

pager = (ViewPager) findViewById(R.id.viewpage);
list = new ArrayList<View>();
 ArrayAdapter<String> adapter1;  
 huochangspinner = (Spinner) findViewById(R.id.huochangspinner);  
        //将可选内容与ArrayAdapter连接起来  
adapter1 = new ArrayAdapter<String>(this,R.layout.spinnerview,m); 
          
      
          
        //将adapter 添加到spinner中  
huochangspinner.setAdapter(adapter1);  
huochangspinner.setOnItemSelectedListener(new OnItemSelectedListener(){
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {

if(!huochangspinner.getSelectedItem().toString().trim().equals("请选择"))
{
InitImageView();
initTextView();
checihao = CallLoginService.GetListshandongcarnumbers(huochangspinner.getSelectedItem().toString());
initPagerViewer();
}
}
public void onNothingSelected(AdapterView<?> arg0) {
}
});





}
private void initTextView() {
t1 = (TextView) findViewById(R.id.text1);
t2 = (TextView) findViewById(R.id.text2);
t1.setOnClickListener(new MyOnClickListener(0));
t2.setOnClickListener(new MyOnClickListener(1));


}
public void destroyItem(View collection) {
       
        ((ViewPager) collection).removeAllViews();
      
    }
/**
 * 初始化PageViewer
 */
private void initPagerViewer() { destroyItem(pager);
list.clear();
Intent intent = new Intent(context, GuangdongZhuangche_weixiugai.class);
list.add(getView("A", intent));
Intent intent2 = new Intent(context, GuangdongZhuangche_yixiugai.class);
list.add(getView("B", intent2));



pager.setAdapter(new MyPagerAdapter(list));
pager.setCurrentItem(0);
pager.setOnPageChangeListener(new MyOnPageChangeListener());

}
/**
 * 初始化动画
 */
private void InitImageView() {
cursor = (ImageView) findViewById(R.id.cursor);
bmpW = BitmapFactory.decodeResource(getResources(), R.drawable.roller)
.getWidth();// 获取图片宽度
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int screenW = dm.widthPixels;// 获取分辨率宽度
offset = (screenW / 2 - bmpW) / 2;// 计算偏移量
Matrix matrix = new Matrix();
matrix.postTranslate(offset, 0);
cursor.setImageMatrix(matrix);// 设置动画初始位置
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.shangdong_zhuangche_view, menu);
return true;
}
/**
 * 通过activity获取视图
 * @param id
 * @param intent
 * @return
 */
private View getView(String id, Intent intent) {
if(id.equals("A"))
{
intent.putExtra("city", huochangspinner.getSelectedItem().toString());
}
if(id.equals("B"))
{
intent.putExtra("checihao", (Serializable)checihao);
intent.putExtra("city", huochangspinner.getSelectedItem().toString());
}
return manager.startActivity(id, intent).getDecorView();
} /**
 * Pager适配器
 */
public class MyPagerAdapter extends PagerAdapter{
List<View> list =  new ArrayList<View>();
public MyPagerAdapter(ArrayList<View> list) {
this.list = list;
} @Override
public void destroyItem(ViewGroup container, int position,
Object object) {
ViewPager pViewPager = ((ViewPager) container);
pViewPager.removeView(list.get(position));
} @Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == arg1;
} @Override
public int getCount() {
return list.size();
}
@Override
public Object instantiateItem(View arg0, int arg1) {
ViewPager pViewPager = ((ViewPager) arg0);
pViewPager.addView(list.get(arg1));
return list.get(arg1);
} @Override
public void restoreState(Parcelable arg0, ClassLoader arg1) { } @Override
public Parcelable saveState() {
return null;
} @Override
public void startUpdate(View arg0) {
}
}
/**
 * 页卡切换监听
 */
public class MyOnPageChangeListener implements OnPageChangeListener { int one = offset * 2 + bmpW;// 页卡1 -> 页卡2 偏移量
int two = one * 2;// 页卡1 -> 页卡3 偏移量 public void onPageSelected(int arg0) {
Animation animation = null;
switch (arg0) {
case 0:
if (currIndex == 1) {
animation = new TranslateAnimation(one, 0, 0, 0);
} else if (currIndex == 2) {
animation = new TranslateAnimation(two, 0, 0, 0);
}
break;
case 1:
if (currIndex == 0) {
animation = new TranslateAnimation(offset, one, 0, 0);
} else if (currIndex == 2) {
animation = new TranslateAnimation(two, one, 0, 0);
}
break;
case 2:
if (currIndex == 0) {
animation = new TranslateAnimation(offset, two, 0, 0);
} else if (currIndex == 1) {
animation = new TranslateAnimation(one, two, 0, 0);
}
break;
}
currIndex = arg0;
animation.setFillAfter(true);// True:图片停在动画结束位置
animation.setDuration(300);
cursor.startAnimation(animation);
} public void onPageScrollStateChanged(int arg0) {

} public void onPageScrolled(int arg0, float arg1, int arg2) {

}
}
public boolean onKeyDown(int keyCode, KeyEvent event)
{
//按下键盘上返回按钮
        if(keyCode == KeyEvent.KEYCODE_BACK){   
         GuangdongZhuangche_view.this.finish();
            return true; 
        }else{        
            return super.onKeyDown(keyCode, event); 
        } 
}
/**
 * 头标点击监听
 */
public class MyOnClickListener implements View.OnClickListener {
private int index = 0; public MyOnClickListener(int i) {
index = i;
} public void onClick(View v) {
pager.setCurrentItem(index);
}
};
}