package com.mzeat.ui; import java.util.ArrayList; import uk.co.senab.photoview.PhotoView; import com.mzeat.R; import com.mzeat.image.BitmapManager; import com.mzeat.image.BmpManager; import com.mzeat.ui.widget.HackyViewPager; import com.mzeat.ui.widget.MulitPointTouchListener; import android.content.Intent; import android.graphics.BitmapFactory; import android.os.Bundle; 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.util.Log; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.RelativeLayout; import android.widget.TextView; public class SharePhoto extends BaseActivity { //private ImageView imgView; private TextView total_num; private TextView current_num; private BmpManager bmpManager; private HackyViewPager mPager; private ArrayList<View> pageViews = new ArrayList<View>(); private ArrayList<String> url_imgs = new ArrayList<String>(); DisplayMetrics dm; //ProgressBar pb; int fromwhere; int position = 0; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_photodetail); dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm);// 获取分辨率 this.bmpManager = new BmpManager(dm,BitmapFactory.decodeResource(this.getResources(), R.drawable.empty_image)); total_num = (TextView) findViewById(R.id.total_num); current_num = (TextView) findViewById(R.id.current_num); Intent intent = getIntent(); fromwhere = intent.getIntExtra("fromShareList", 0); position = intent.getIntExtra("position", 0); if (fromwhere == 1) { url_imgs.add(intent.getStringExtra("img_url")); }else { url_imgs = intent.getStringArrayListExtra("img_url"); Log.e("url_imgs", String.valueOf(url_imgs.size())); } total_num.setText(String.valueOf(url_imgs.size())); mPager = (HackyViewPager) findViewById(R.id.photo_page); /** for (int i = 0; i <url_imgs.size() ; i++) { RelativeLayout ll = (RelativeLayout) LayoutInflater.from( SharePhoto.this).inflate(R.layout.activity_photo, null); ProgressBar pb = (ProgressBar) ll.findViewById(R.id.imagezoomdialog_progress) ; PhotoView imgView = (PhotoView) ll.findViewById(R.id.sharephoto); //imgView.setOnTouchListener(new MulitPointTouchListener());// 设置触屏监听 bmpManager.loadBitmap(url_imgs.get(i), imgView,pb); pageViews.add(ll); } **/ mPager.setAdapter(new myPagerView()); mPager.setCurrentItem(position); current_num.setText(String.valueOf(position+1)); mPager.setOnPageChangeListener(new OnPageChangeListener() { @Override public void onPageSelected(int arg0) { // TODO Auto-generated method stub current_num.setText(String.valueOf(arg0+1)); } @Override public void onPageScrolled(int arg0, float arg1, int arg2) { // TODO Auto-generated method stub } @Override public void onPageScrollStateChanged(int arg0) { // TODO Auto-generated method stub } }); } /*** * viewpager 的数据源 * * @author zhangjia * */ class myPagerView extends PagerAdapter { // 显示数目 @Override public int getCount() { return url_imgs.size(); } @Override public boolean isViewFromObject(View container, Object object) { return container == object; } @Override public int getItemPosition(Object object) { // TODO Auto-generated method stub return super.getItemPosition(object); } @Override public void destroyItem(View container, int position, Object object) { // TODO Auto-generated method stub //((ViewPager) container).removeView(pageViews.get(position)); ((ViewPager) container).removeView((View) object); } /*** * 获取每一个item, 类于listview中的getview */ @Override public Object instantiateItem(View container, int position) { //((ViewPager) container).addView(pageViews.get(position)); RelativeLayout ll = (RelativeLayout) LayoutInflater.from( SharePhoto.this).inflate(R.layout.activity_photo, null); ProgressBar pb = (ProgressBar) ll.findViewById(R.id.imagezoomdialog_progress) ; PhotoView imgView = (PhotoView) ll.findViewById(R.id.sharephoto); //imgView.setOnTouchListener(new MulitPointTouchListener());// 设置触屏监听 bmpManager.loadBitmap(url_imgs.get(position), imgView,pb); ((ViewPager) container).addView(ll); return ll; } } public boolean onKeyDown(int keyCode, KeyEvent event) {// 捕捉返回键 if (keyCode == KeyEvent.KEYCODE_BACK) { finish(); return true; } return super.onKeyDown(keyCode, event); } }