Search in sources :

Example 1 with ImagePageAdapter

use of com.lzy.imagepicker.adapter.ImagePageAdapter in project ImagePicker by jeasonlzy.

the class ImagePreviewBaseActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_image_preview);
    mCurrentPosition = getIntent().getIntExtra(ImagePicker.EXTRA_SELECTED_IMAGE_POSITION, 0);
    // 据说这样会导致大量图片崩溃
    mImageItems = (ArrayList<ImageItem>) getIntent().getSerializableExtra(ImagePicker.EXTRA_IMAGE_ITEMS);
    // 下面采用弱引用会导致预览崩溃
    //        mImageItems =  (ArrayList<ImageItem>) DataHolder.getInstance().retrieve(DataHolder.DH_CURRENT_IMAGE_FOLDER_ITEMS);
    imagePicker = ImagePicker.getInstance();
    selectedImages = imagePicker.getSelectedImages();
    //初始化控件
    content = findViewById(R.id.content);
    //因为状态栏透明后,布局整体会上移,所以给头部加上状态栏的margin值,保证头部不会被覆盖
    topBar = findViewById(R.id.top_bar);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) topBar.getLayoutParams();
        params.topMargin = Utils.getStatusHeight(this);
        topBar.setLayoutParams(params);
    }
    topBar.findViewById(R.id.btn_ok).setVisibility(View.GONE);
    topBar.findViewById(R.id.btn_back).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    mTitleCount = (TextView) findViewById(R.id.tv_des);
    mViewPager = (ViewPagerFixed) findViewById(R.id.viewpager);
    mAdapter = new ImagePageAdapter(this, mImageItems);
    mAdapter.setPhotoViewClickListener(new ImagePageAdapter.PhotoViewClickListener() {

        @Override
        public void OnPhotoTapListener(View view, float v, float v1) {
            onImageSingleTap();
        }
    });
    mViewPager.setAdapter(mAdapter);
    mViewPager.setCurrentItem(mCurrentPosition, false);
    //初始化当前页面的状态
    mTitleCount.setText(getString(R.string.preview_image_count, mCurrentPosition + 1, mImageItems.size()));
}
Also used : RelativeLayout(android.widget.RelativeLayout) ImagePageAdapter(com.lzy.imagepicker.adapter.ImagePageAdapter) ImageItem(com.lzy.imagepicker.bean.ImageItem) TextView(android.widget.TextView) View(android.view.View)

Aggregations

View (android.view.View)1 RelativeLayout (android.widget.RelativeLayout)1 TextView (android.widget.TextView)1 ImagePageAdapter (com.lzy.imagepicker.adapter.ImagePageAdapter)1 ImageItem (com.lzy.imagepicker.bean.ImageItem)1