Search in sources :

Example 11 with PhotoView

use of com.github.chrisbanes.photoview.PhotoView in project 91Pop by DanteAndroid.

the class PictureAdapter method destroyItem.

@Override
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
    FrameLayout view = (FrameLayout) object;
    for (int i = 0; i < view.getChildCount(); i++) {
        View childView = view.getChildAt(i);
        if (childView instanceof TouchImageView) {
            childView.setOnClickListener(null);
            childView.setOnLongClickListener(null);
            GlideApp.with(container).clear(childView);
            view.removeViewAt(i);
            Logger.t(TAG).d("clean photoView");
        }
    }
    container.removeView(view);
    Logger.t(TAG).d("destroyItem");
}
Also used : FrameLayout(android.widget.FrameLayout) TouchImageView(com.dante.custom.TouchImageView) TouchImageView(com.dante.custom.TouchImageView) PhotoView(com.github.chrisbanes.photoview.PhotoView) View(android.view.View)

Example 12 with PhotoView

use of com.github.chrisbanes.photoview.PhotoView in project 91Pop by DanteAndroid.

the class PictureAdapter method instantiateItem.

@NonNull
@Override
public View instantiateItem(@NonNull ViewGroup container, final int position) {
    View contentView = LayoutInflater.from(container.getContext()).inflate(R.layout.item_picture_adapter, container, false);
    PhotoView photoView = contentView.findViewById(R.id.photoView);
    final ProgressBar progressBar = contentView.findViewById(R.id.progressBar);
    String url = imageList.get(position);
    if (url.contains("meizitu.net")) {
        GlideApp.with(container).load(buildGlideUrl(url)).transition(new DrawableTransitionOptions().crossFade(300)).listener(new RequestListener<Drawable>() {

            @Override
            public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
                progressBar.setVisibility(View.GONE);
                return false;
            }

            @Override
            public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
                progressBar.setVisibility(View.GONE);
                return false;
            }
        }).into(photoView);
    } else {
        GlideApp.with(container).load(Uri.parse(url)).transition(new DrawableTransitionOptions().crossFade(300)).listener(new RequestListener<Drawable>() {

            @Override
            public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
                progressBar.setVisibility(View.GONE);
                return false;
            }

            @Override
            public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
                progressBar.setVisibility(View.GONE);
                return false;
            }
        }).into(photoView);
    }
    // Now just add PhotoView to ViewPager and return it
    container.addView(contentView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    photoView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (onImageClickListener != null) {
                onImageClickListener.onImageClick(v, position);
            }
        }
    });
    photoView.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            if (onImageClickListener != null) {
                onImageClickListener.onImageLongClick(v, position);
            }
            return true;
        }
    });
    Logger.t(TAG).d("instantiateItem");
    return contentView;
}
Also used : RequestListener(com.bumptech.glide.request.RequestListener) Drawable(android.graphics.drawable.Drawable) TouchImageView(com.dante.custom.TouchImageView) PhotoView(com.github.chrisbanes.photoview.PhotoView) View(android.view.View) DataSource(com.bumptech.glide.load.DataSource) PhotoView(com.github.chrisbanes.photoview.PhotoView) DrawableTransitionOptions(com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions) Target(com.bumptech.glide.request.target.Target) ProgressBar(android.widget.ProgressBar) GlideException(com.bumptech.glide.load.engine.GlideException) Nullable(android.support.annotation.Nullable) NonNull(android.support.annotation.NonNull)

Example 13 with PhotoView

use of com.github.chrisbanes.photoview.PhotoView in project NightSkyGuide by MTBehnke.

the class DetailFragment method onCreateView.

// called when DetailFragment's view needs to be created
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    setHasOptionsMenu(true);
    // get Bundle of arguments then extract the dsObject
    Bundle arguments = getArguments();
    if (arguments != null)
        dsObject = arguments.getParcelable("dsObjectArrayListItem");
    // inflate DetailFragment's layout
    View view = inflater.inflate(R.layout.fragment_details, container, false);
    // get the EditTexts
    TextView objectIdTextView = view.findViewById(R.id.objectIdTextView);
    TextView typeTextView = view.findViewById(R.id.typeTextView);
    TextView magTextView = view.findViewById(R.id.magTextView);
    TextView sizeTextView = view.findViewById(R.id.sizeTextView);
    TextView distTextView = view.findViewById(R.id.distTextView);
    TextView raTextView = view.findViewById(R.id.raTextView);
    TextView decTextView = view.findViewById(R.id.decTextView);
    TextView constTextView = view.findViewById(R.id.constTextView);
    TextView nameTextView = view.findViewById(R.id.nameTextView);
    psaTextView = view.findViewById(R.id.psaTextView);
    oithTextView = view.findViewById(R.id.oithTextView);
    skyAtlasTextView = view.findViewById(R.id.skyAtlasTextView);
    psaTextViewLabel = view.findViewById(R.id.psaLabelTextView);
    oithTextViewLabel = view.findViewById(R.id.oithLabelTextView);
    skyAtlasTextViewLabel = view.findViewById(R.id.skyAtlasLabelTextView);
    TextView catTextView = view.findViewById(R.id.catTextView);
    TextView altTextView = view.findViewById(R.id.altTextView);
    TextView azTextView = view.findViewById(R.id.azTextView);
    TextView riseTextView = view.findViewById(R.id.riseTextView);
    TextView setTextViewLabel = view.findViewById(R.id.setLabelTextView);
    TextView setTextView = view.findViewById(R.id.setTextView);
    TextView transitTextViewLabel = view.findViewById(R.id.transitLabelTextView);
    TextView transitTextView = view.findViewById(R.id.tranitTextView);
    // set the TextViews
    NumberFormat numberFormat = NumberFormat.getInstance(Locale.US);
    DecimalFormat df = (DecimalFormat) numberFormat;
    df.applyPattern("0.0");
    setUserPreferences();
    objectIdTextView.setText(dsObject.getDsoObjectID());
    String typeAbbr = dsObject.getDsoType();
    typeTextView.setText(AstroCalc.getDSOType(typeAbbr));
    if (dsObject.getDsoMag() == null) {
        magTextView.setVisibility(View.GONE);
        view.findViewById(R.id.magLabelTextView).setVisibility(View.GONE);
    } else {
        String magnitude = df.format(dsObject.getDsoMag());
        magTextView.setText(magnitude);
    }
    sizeTextView.setText(dsObject.getDsoSize());
    distTextView.setText(dsObject.getDsoDist());
    raTextView.setText(AstroCalc.convertDDToHMS(dsObject.getDsoRA()));
    decTextView.setText(AstroCalc.convertDDToDMS(dsObject.getDsoDec()));
    String constAbbr = dsObject.getDsoConst();
    constTextView.setText(AstroCalc.getConstName(constAbbr));
    nameTextView.setText(dsObject.getDsoName());
    psaTextView.setText(dsObject.getDsoPSA());
    oithTextView.setText(dsObject.getDsoOITH());
    skyAtlasTextView.setText(dsObject.getDsoSkyAtlas());
    catTextView.setText(dsObject.getDsoCatalogue());
    String altitude = df.format(dsObject.getDsoAlt()) + "°";
    altTextView.setText(altitude);
    String azimuth = df.format(dsObject.getDsoAz()) + "°";
    azTextView.setText(azimuth);
    DateTimeFormatter dtf = DateTimeFormat.shortTime().withZone(DateTimeZone.getDefault()).withLocale(Locale.getDefault());
    String dsoRiseTimeStr;
    String dsoSetTimeStr;
    if (dsObject.getDsoRiseTime() == null) {
        dsoRiseTimeStr = "This DSO never rises";
        dsoSetTimeStr = "at this latitude";
        transitTextViewLabel.setVisibility(View.GONE);
        transitTextView.setVisibility(View.GONE);
    } else if (dsObject.getDsoSetTime() == null) {
        dsoRiseTimeStr = "Circumpolar: never";
        dsoSetTimeStr = "sets below horizon";
        transitTextViewLabel.setVisibility(View.VISIBLE);
        transitTextView.setVisibility(View.VISIBLE);
        transitTextView.setText(dsObject.getDsoTransitTime().toString(dtf));
    } else {
        // switch Transit Time and Set Time positions to display in order
        dsoRiseTimeStr = dsObject.getDsoRiseTime().toString(dtf);
        dsoSetTimeStr = dsObject.getDsoTransitTime().toString(dtf);
        transitTextViewLabel.setVisibility(View.VISIBLE);
        transitTextView.setVisibility(View.VISIBLE);
        transitTextView.setText(dsObject.getDsoSetTime().toString(dtf));
        setTextViewLabel.setText(getString(R.string.label_transit));
        transitTextViewLabel.setText(getString(R.string.label_set));
    }
    riseTextView.setText(dsoRiseTimeStr);
    setTextView.setText(dsoSetTimeStr);
    // display constellation image
    if (!constAbbr.equals("")) {
        String constName = "images/" + dsObject.getDsoConst() + ".gif";
        PhotoView constImageView = view.findViewById(R.id.constImageView);
        // display constellation .gif on detail screen
        Bitmap bm = loadConstImage(constName);
        constImageView.setImageBitmap(bm);
    /*
            // Change constellation image to night mode version
            int colorCode = Color.argb(255,255,0,0);  // transparency and red = 255, green and blue = 0
            constImageView.setColorFilter(colorCode, PorterDuff.Mode.MULTIPLY);  */
    }
    return view;
}
Also used : PhotoView(com.github.chrisbanes.photoview.PhotoView) Bitmap(android.graphics.Bitmap) Bundle(android.os.Bundle) DecimalFormat(java.text.DecimalFormat) TextView(android.widget.TextView) NavigationView(android.support.design.widget.NavigationView) View(android.view.View) PhotoView(com.github.chrisbanes.photoview.PhotoView) TextView(android.widget.TextView) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) NumberFormat(java.text.NumberFormat)

Example 14 with PhotoView

use of com.github.chrisbanes.photoview.PhotoView in project CloudReader by youlookwhat.

the class BigImagePagerActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_view_big_image);
    mViewPager = (ViewPager) findViewById(R.id.very_image_viewpager);
    // 延迟动画
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        postponeEnterTransition();
    }
    mEnterIndex = getIntent().getIntExtra(KEY_ENTER_INDEX, 0);
    mImageUrls = getIntent().getStringArrayListExtra(KEY_IMAGE_URLS);
    if (mImageUrls == null) {
        return;
    }
    mPhotoViewMap = new SparseArray<>();
    // imageView.setLayoutParams(new ViewGroup.LayoutParams(
    // ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    // View view = getLayoutInflater().inflate(R.layout.dialog_save_image, null);
    // 
    // AlertDialog alertDialog = new AlertDialog.Builder(BigImagePagerActivity.this)
    // .setView(view)
    // .create();
    // 
    // TextView textView = (TextView) view.findViewById(R.id.save_image_tv);
    // textView.setOnClickListener(v1 -> {
    // saveImage(pv.getDrawable(), imageUrl);
    // alertDialog.dismiss();
    // });
    // alertDialog.show();
    PagerAdapter mPagerAdapter = new PagerAdapter() {

        @Override
        public int getCount() {
            return mImageUrls.size();
        }

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

        @NonNull
        @Override
        public Object instantiateItem(@NonNull ViewGroup container, int position) {
            PhotoView photoView = new PhotoView(container.getContext());
            // imageView.setLayoutParams(new ViewGroup.LayoutParams(
            // ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
            String imageUrl = mImageUrls.get(position);
            Glide.with(BigImagePagerActivity.this).load(imageUrl).into(photoView);
            if (mPhotoViewMap.get(position) != null) {
                mPhotoViewMap.remove(position);
            }
            mPhotoViewMap.put(position, photoView);
            photoView.setOnViewTapListener((view, x, y) -> {
                onBackPressed();
            });
            photoView.setOnLongClickListener(v -> {
                PhotoView pv = (PhotoView) v;
                if (pv.getDrawable() == null) {
                    return false;
                }
                // alertDialog.show();
                return true;
            });
            if (position == mEnterIndex) {
                ViewCompat.setTransitionName(photoView, mImageUrls.get(position));
                setStartPostTransition(photoView);
            }
            container.addView(photoView);
            return photoView;
        }

        @Override
        public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
            if (mPhotoViewMap.get(position) != null) {
                mPhotoViewMap.remove(position);
            }
            container.removeView((View) object);
        }
    };
    mViewPager.setAdapter(mPagerAdapter);
    mViewPager.setCurrentItem(mEnterIndex);
    mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int i, float v, int i1) {
        }

        @Override
        public void onPageSelected(int i) {
            RxBus.getDefault().post(RxCodeConstants.JUMP_CURRENT_POSITION, i);
        }

        @Override
        public void onPageScrollStateChanged(int i) {
        }
    });
}
Also used : ViewGroup(android.view.ViewGroup) PhotoView(com.github.chrisbanes.photoview.PhotoView) View(android.view.View) ViewPager(androidx.viewpager.widget.ViewPager) PagerAdapter(androidx.viewpager.widget.PagerAdapter) PhotoView(com.github.chrisbanes.photoview.PhotoView) NonNull(androidx.annotation.NonNull)

Aggregations

PhotoView (com.github.chrisbanes.photoview.PhotoView)14 View (android.view.View)11 ImageView (android.widget.ImageView)6 Drawable (android.graphics.drawable.Drawable)5 Bundle (android.os.Bundle)4 NonNull (android.support.annotation.NonNull)3 Nullable (android.support.annotation.Nullable)3 ViewGroup (android.view.ViewGroup)3 PhotoViewAttacher (com.github.chrisbanes.photoview.PhotoViewAttacher)3 Bitmap (android.graphics.Bitmap)2 PagerAdapter (android.support.v4.view.PagerAdapter)2 MotionEvent (android.view.MotionEvent)2 ProgressBar (android.widget.ProgressBar)2 TextView (android.widget.TextView)2 BindView (butterknife.BindView)2 TouchImageView (com.dante.custom.TouchImageView)2 OnOutsidePhotoTapListener (com.github.chrisbanes.photoview.OnOutsidePhotoTapListener)2 OnPhotoTapListener (com.github.chrisbanes.photoview.OnPhotoTapListener)2 OnSingleFlingListener (com.github.chrisbanes.photoview.OnSingleFlingListener)2 Callback (com.squareup.picasso.Callback)2