Search in sources :

Example 1 with PhotoView

use of com.bm.library.PhotoView in project PhotoView by bm-x.

the class ViewPagerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_view_pager);
    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setPageMargin((int) (getResources().getDisplayMetrics().density * 15));
    mPager.setAdapter(new PagerAdapter() {

        @Override
        public int getCount() {
            return imgsId.length;
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            PhotoView view = new PhotoView(ViewPagerActivity.this);
            view.enable();
            view.setScaleType(ImageView.ScaleType.FIT_CENTER);
            view.setImageResource(imgsId[position]);
            container.addView(view);
            return view;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }
    });
}
Also used : PhotoView(com.bm.library.PhotoView) ViewGroup(android.view.ViewGroup) ImageView(android.widget.ImageView) View(android.view.View) PhotoView(com.bm.library.PhotoView) PagerAdapter(android.support.v4.view.PagerAdapter)

Example 2 with PhotoView

use of com.bm.library.PhotoView in project PhotoView by bm-x.

the class PhotoBrowse method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_photo_browse);
    in.setDuration(300);
    out.setDuration(300);
    out.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            mBg.setVisibility(View.INVISIBLE);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }
    });
    mParent = findViewById(R.id.parent);
    mBg = findViewById(R.id.bg);
    mPhotoView = (PhotoView) findViewById(R.id.img);
    mPhotoView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    gv = (GridView) findViewById(R.id.gv);
    gv.setAdapter(new BaseAdapter() {

        @Override
        public int getCount() {
            return imgs.length;
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            PhotoView p = new PhotoView(PhotoBrowse.this);
            p.setLayoutParams(new AbsListView.LayoutParams((int) (getResources().getDisplayMetrics().density * 100), (int) (getResources().getDisplayMetrics().density * 100)));
            p.setScaleType(ImageView.ScaleType.CENTER_CROP);
            p.setImageResource(imgs[position]);
            // 把PhotoView当普通的控件把触摸功能关掉
            p.disenable();
            return p;
        }
    });
    gv.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            PhotoView p = (PhotoView) view;
            mInfo = p.getInfo();
            mPhotoView.setImageResource(imgs[position]);
            mBg.startAnimation(in);
            mBg.setVisibility(View.VISIBLE);
            mParent.setVisibility(View.VISIBLE);
            ;
            mPhotoView.animaFrom(mInfo);
        }
    });
    mPhotoView.enable();
    mPhotoView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mBg.startAnimation(out);
            mPhotoView.animaTo(mInfo, new Runnable() {

                @Override
                public void run() {
                    mParent.setVisibility(View.GONE);
                }
            });
        }
    });
}
Also used : ViewGroup(android.view.ViewGroup) GridView(android.widget.GridView) ImageView(android.widget.ImageView) AbsListView(android.widget.AbsListView) View(android.view.View) AdapterView(android.widget.AdapterView) PhotoView(com.bm.library.PhotoView) PhotoView(com.bm.library.PhotoView) AlphaAnimation(android.view.animation.AlphaAnimation) Animation(android.view.animation.Animation) AdapterView(android.widget.AdapterView) BaseAdapter(android.widget.BaseAdapter)

Aggregations

View (android.view.View)2 ViewGroup (android.view.ViewGroup)2 ImageView (android.widget.ImageView)2 PhotoView (com.bm.library.PhotoView)2 PagerAdapter (android.support.v4.view.PagerAdapter)1 AlphaAnimation (android.view.animation.AlphaAnimation)1 Animation (android.view.animation.Animation)1 AbsListView (android.widget.AbsListView)1 AdapterView (android.widget.AdapterView)1 BaseAdapter (android.widget.BaseAdapter)1 GridView (android.widget.GridView)1