Example usage for android.widget ImageView addOnLayoutChangeListener

List of usage examples for android.widget ImageView addOnLayoutChangeListener

Introduction

In this page you can find the example usage for android.widget ImageView addOnLayoutChangeListener.

Prototype

public void addOnLayoutChangeListener(OnLayoutChangeListener listener) 

Source Link

Document

Add a listener that will be called when the bounds of the view change due to layout processing.

Usage

From source file:org.schabi.newpipe.detail.VideoItemDetailFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceBundle) {
    super.onActivityCreated(savedInstanceBundle);
    Activity a = getActivity();/*  w w  w . ja v a  2  s .co  m*/

    infoItemBuilder = new InfoItemBuilder(a, a.findViewById(android.R.id.content));

    if (android.os.Build.VERSION.SDK_INT < 18) {
        playVideoButton = (FloatingActionButton) a.findViewById(R.id.play_video_button);
    }
    thumbnailWindowLayout = a.findViewById(R.id.detail_stream_thumbnail_window_layout);
    Button backgroundButton = (Button) a.findViewById(R.id.detail_stream_thumbnail_window_background_button);

    // Sometimes when this fragment is not visible it still gets initiated
    // then we must not try to access objects of this fragment.
    // Otherwise the applications would crash.
    if (backgroundButton != null) {
        streamingServiceId = getArguments().getInt(STREAMING_SERVICE);
        String videoUrl = getArguments().getString(VIDEO_URL);
        StreamInfoWorker siw = StreamInfoWorker.getInstance();
        siw.search(streamingServiceId, videoUrl, getActivity());

        autoPlayEnabled = getArguments().getBoolean(AUTO_PLAY);

        if (Build.VERSION.SDK_INT >= 18) {
            ImageView thumbnailView = (ImageView) activity.findViewById(R.id.detail_thumbnail_view);
            thumbnailView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
                // This is used to synchronize the thumbnailWindowButton and the playVideoButton
                // inside the ScrollView with the actual size of the thumbnail.
                //todo: onLayoutChage sometimes not triggered
                // background buttons area seem to overlap the thumbnail view
                // So although you just clicked slightly beneath the thumbnail the action still
                // gets triggered.
                @Override
                public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft,
                        int oldTop, int oldRight, int oldBottom) {
                    RelativeLayout.LayoutParams newWindowLayoutParams = (RelativeLayout.LayoutParams) thumbnailWindowLayout
                            .getLayoutParams();
                    newWindowLayoutParams.height = bottom - top;
                    thumbnailWindowLayout.setLayoutParams(newWindowLayoutParams);

                    //noinspection SuspiciousNameCombination
                    initialThumbnailPos.set(top, left);

                }
            });
        }
    }
}

From source file:com.huyn.demogroup.leaveblank.PhotoViewAttacher.java

public PhotoViewAttacher(ImageView imageView) {
    mImageView = imageView;// w  ww.  j  av  a  2s.c  o  m
    imageView.setOnTouchListener(this);
    imageView.addOnLayoutChangeListener(this);

    if (imageView.isInEditMode()) {
        return;
    }

    mBaseRotation = 0.0f;

    // Create Gesture Detectors...
    mScaleDragDetector = new CustomGestureDetector(imageView.getContext(), this);

    mGestureDetector = new GestureDetector(imageView.getContext(),
            new GestureDetector.SimpleOnGestureListener() {

                // forward long click listener
                @Override
                public void onLongPress(MotionEvent e) {
                    if (mLongClickListener != null) {
                        mLongClickListener.onLongClick(mImageView);
                    }
                }

                @Override
                public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                    if (mSingleFlingListener != null) {
                        if (getScale() > DEFAULT_MIN_SCALE) {
                            return false;
                        }

                        if (MotionEventCompat.getPointerCount(e1) > SINGLE_TOUCH
                                || MotionEventCompat.getPointerCount(e2) > SINGLE_TOUCH) {
                            return false;
                        }

                        return mSingleFlingListener.onFling(e1, e2, velocityX, velocityY);
                    }
                    return false;
                }
            });
}

From source file:com.tjw.selectimage.photoview.PhotoViewAttacher.java

public PhotoViewAttacher(ImageView imageView) {
    mImageView = imageView;//from w w w.  j  av  a  2  s .  c o m
    imageView.setOnTouchListener(this);
    imageView.addOnLayoutChangeListener(this);

    if (imageView.isInEditMode()) {
        return;
    }

    mBaseRotation = 0.0f;

    // Create Gesture Detectors...
    mScaleDragDetector = new CustomGestureDetector(imageView.getContext(), this);

    mGestureDetector = new GestureDetector(imageView.getContext(),
            new GestureDetector.SimpleOnGestureListener() {

                // forward long click listener
                @Override
                public void onLongPress(MotionEvent e) {
                    if (mLongClickListener != null) {
                        mLongClickListener.onLongClick(mImageView);
                    }
                }

                @Override
                public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                    if (mSingleFlingListener != null) {
                        if (getScale() > DEFAULT_MIN_SCALE) {
                            return false;
                        }

                        if (MotionEventCompat.getPointerCount(e1) > SINGLE_TOUCH
                                || MotionEventCompat.getPointerCount(e2) > SINGLE_TOUCH) {
                            return false;
                        }

                        return mSingleFlingListener.onFling(e1, e2, velocityX, velocityY);
                    }
                    return false;
                }
            });

    mGestureDetector.setOnDoubleTapListener(new GestureDetector.OnDoubleTapListener() {
        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            if (mOnClickListener != null) {
                mOnClickListener.onClick(mImageView);
            }
            final RectF displayRect = getDisplayRect();

            if (displayRect != null) {
                final float x = e.getX(), y = e.getY();

                // Check to see if the user tapped on the photo
                if (displayRect.contains(x, y)) {

                    float xResult = (x - displayRect.left) / displayRect.width();
                    float yResult = (y - displayRect.top) / displayRect.height();

                    if (mPhotoTapListener != null) {
                        mPhotoTapListener.onPhotoTap(mImageView, xResult, yResult);
                    }
                    return true;
                } else {
                    if (mOutsidePhotoTapListener != null) {
                        mOutsidePhotoTapListener.onOutsidePhotoTap(mImageView);
                    }
                }
            }
            return false;
        }

        @Override
        public boolean onDoubleTap(MotionEvent ev) {
            try {
                float scale = getScale();
                float x = ev.getX();
                float y = ev.getY();

                if (scale < getMediumScale()) {
                    setScale(getMediumScale(), x, y, true);
                } else if (scale >= getMediumScale() && scale < getMaximumScale()) {
                    setScale(getMaximumScale(), x, y, true);
                } else {
                    setScale(getMinimumScale(), x, y, true);
                }
            } catch (ArrayIndexOutOfBoundsException e) {
                // Can sometimes happen when getX() and getY() is called
            }

            return true;
        }

        @Override
        public boolean onDoubleTapEvent(MotionEvent e) {
            // Wait for the confirmed onDoubleTap() instead
            return false;
        }
    });
}

From source file:com.github.chrisbanes.photoview.PhotoViewAttacher.java

public PhotoViewAttacher(ImageView imageView) {
    mImageView = imageView;/*w w w  .j  a v a  2  s  .c  o m*/
    imageView.setOnTouchListener(this);
    imageView.addOnLayoutChangeListener(this);

    if (imageView.isInEditMode()) {
        return;
    }

    mBaseRotation = 0.0f;

    // Create Gesture Detectors...
    mScaleDragDetector = new CustomGestureDetector(imageView.getContext(), this);

    mGestureDetector = new GestureDetector(imageView.getContext(),
            new GestureDetector.SimpleOnGestureListener() {

                // forward long click listener
                @Override
                public void onLongPress(MotionEvent e) {
                    if (mLongClickListener != null) {
                        mLongClickListener.onLongClick(mImageView);
                    }
                }

                @Override
                public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                    if (mSingleFlingListener != null) {
                        if (getScale() > DEFAULT_MIN_SCALE) {
                            return false;
                        }

                        if (MotionEventCompat.getPointerCount(e1) > SINGLE_TOUCH
                                || MotionEventCompat.getPointerCount(e2) > SINGLE_TOUCH) {
                            return false;
                        }

                        return mSingleFlingListener.onFling(e1, e2, velocityX, velocityY);
                    }
                    return false;
                }
            });

    mGestureDetector.setOnDoubleTapListener(new GestureDetector.OnDoubleTapListener() {
        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            if (mOnClickListener != null) {
                mOnClickListener.onClick(mImageView);
            }
            final RectF displayRect = getDisplayRect();

            final float x = e.getX(), y = e.getY();

            if (mViewTapListener != null) {
                mViewTapListener.onViewTap(mImageView, x, y);
            }

            if (displayRect != null) {

                // Check to see if the user tapped on the photo
                if (displayRect.contains(x, y)) {

                    float xResult = (x - displayRect.left) / displayRect.width();
                    float yResult = (y - displayRect.top) / displayRect.height();

                    if (mPhotoTapListener != null) {
                        mPhotoTapListener.onPhotoTap(mImageView, xResult, yResult);
                    }
                    return true;
                } else {
                    if (mOutsidePhotoTapListener != null) {
                        mOutsidePhotoTapListener.onOutsidePhotoTap(mImageView);
                    }
                }
            }
            return false;
        }

        @Override
        public boolean onDoubleTap(MotionEvent ev) {
            try {
                float scale = getScale();
                float x = ev.getX();
                float y = ev.getY();

                if (scale < getMediumScale()) {
                    setScale(getMediumScale(), x, y, true);
                } else if (scale >= getMediumScale() && scale < getMaximumScale()) {
                    setScale(getMaximumScale(), x, y, true);
                } else {
                    setScale(getMinimumScale(), x, y, true);
                }
            } catch (ArrayIndexOutOfBoundsException e) {
                // Can sometimes happen when getX() and getY() is called
            }

            return true;
        }

        @Override
        public boolean onDoubleTapEvent(MotionEvent e) {
            // Wait for the confirmed onDoubleTap() instead
            return false;
        }
    });
}

From source file:com.frank.protean.photoview.PhotoViewAttacher.java

public PhotoViewAttacher(ImageView imageView) {
    mImageView = imageView;/*from   ww  w .  ja  v  a  2  s  .c o m*/
    imageView.setOnTouchListener(this);
    imageView.addOnLayoutChangeListener(this);

    if (imageView.isInEditMode()) {
        return;
    }

    mBaseRotation = 0.0f;

    // Create Gesture Detectors...
    mScaleDragDetector = new CustomGestureDetector(imageView.getContext(), onGestureListener);

    mGestureDetector = new GestureDetector(imageView.getContext(),
            new GestureDetector.SimpleOnGestureListener() {

                // forward long click listener
                @Override
                public void onLongPress(MotionEvent e) {
                    if (mLongClickListener != null) {
                        mLongClickListener.onLongClick(mImageView);
                    }
                }

                @Override
                public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                    if (mSingleFlingListener != null) {
                        if (getScale() > DEFAULT_MIN_SCALE) {
                            return false;
                        }

                        if (MotionEventCompat.getPointerCount(e1) > SINGLE_TOUCH
                                || MotionEventCompat.getPointerCount(e2) > SINGLE_TOUCH) {
                            return false;
                        }

                        return mSingleFlingListener.onFling(e1, e2, velocityX, velocityY);
                    }
                    return false;
                }
            });

    mGestureDetector.setOnDoubleTapListener(new GestureDetector.OnDoubleTapListener() {
        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            if (mOnClickListener != null) {
                mOnClickListener.onClick(mImageView);
            }
            final RectF displayRect = getDisplayRect();

            final float x = e.getX(), y = e.getY();

            if (mViewTapListener != null) {
                mViewTapListener.onViewTap(mImageView, x, y);
            }

            if (displayRect != null) {

                // Check to see if the user tapped on the photo
                if (displayRect.contains(x, y)) {

                    float xResult = (x - displayRect.left) / displayRect.width();
                    float yResult = (y - displayRect.top) / displayRect.height();

                    if (mPhotoTapListener != null) {
                        mPhotoTapListener.onPhotoTap(mImageView, xResult, yResult);
                    }
                    return true;
                } else {
                    if (mOutsidePhotoTapListener != null) {
                        mOutsidePhotoTapListener.onOutsidePhotoTap(mImageView);
                    }
                }
            }
            return false;
        }

        @Override
        public boolean onDoubleTap(MotionEvent ev) {
            try {
                float scale = getScale();
                float x = ev.getX();
                float y = ev.getY();

                if (scale < getMediumScale()) {
                    setScale(getMediumScale(), x, y, true);
                } else if (scale >= getMediumScale() && scale < getMaximumScale()) {
                    setScale(getMaximumScale(), x, y, true);
                } else {
                    setScale(getMinimumScale(), x, y, true);
                }
            } catch (ArrayIndexOutOfBoundsException e) {
                // Can sometimes happen when getX() and getY() is called
            }

            return true;
        }

        @Override
        public boolean onDoubleTapEvent(MotionEvent e) {
            // Wait for the confirmed onDoubleTap() instead
            return false;
        }
    });
}

From source file:org.schabi.newpipe.VideoItemDetailFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceBundle) {
    super.onActivityCreated(savedInstanceBundle);
    Activity a = getActivity();//  ww  w.ja v  a  2  s .c o m
    if (android.os.Build.VERSION.SDK_INT < 18) {
        playVideoButton = (FloatingActionButton) a.findViewById(R.id.playVideoButton);
    }
    thumbnailWindowLayout = a.findViewById(R.id.detailVideoThumbnailWindowLayout);
    Button backgroundButton = (Button) a.findViewById(R.id.detailVideoThumbnailWindowBackgroundButton);

    // Sometimes when this fragment is not visible it still gets initiated
    // then we must not try to access objects of this fragment.
    // Otherwise the applications would crash.
    if (backgroundButton != null) {
        try {
            streamingServiceId = getArguments().getInt(STREAMING_SERVICE);
            StreamingService streamingService = ServiceList.getService(streamingServiceId);
            Thread videoExtractorThread = new Thread(
                    new VideoExtractorRunnable(getArguments().getString(VIDEO_URL), streamingService));

            autoPlayEnabled = getArguments().getBoolean(AUTO_PLAY);
            videoExtractorThread.start();
        } catch (Exception e) {
            e.printStackTrace();
        }

        if (Build.VERSION.SDK_INT >= 18) {
            ImageView thumbnailView = (ImageView) activity.findViewById(R.id.detailThumbnailView);
            thumbnailView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
                // This is used to synchronize the thumbnailWindowButton and the playVideoButton
                // inside the ScrollView with the actual size of the thumbnail.
                //todo: onLayoutChage sometimes not triggered
                // background buttons area seem to overlap the thumbnail view
                // So although you just clicked slightly beneath the thumbnail the action still
                // gets triggered.
                @Override
                public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft,
                        int oldTop, int oldRight, int oldBottom) {
                    RelativeLayout.LayoutParams newWindowLayoutParams = (RelativeLayout.LayoutParams) thumbnailWindowLayout
                            .getLayoutParams();
                    newWindowLayoutParams.height = bottom - top;
                    thumbnailWindowLayout.setLayoutParams(newWindowLayoutParams);

                    //noinspection SuspiciousNameCombination
                    initialThumbnailPos.set(top, left);

                }
            });
        }
    }
}

From source file:com.lifehackinnovations.siteaudit.FloorPlanActivity.java

public void setonehourglass(final ImageView iv) {

    int resourceint = R.drawable.hourglassicon;
    Bitmap resourcebm = BitmapFactory.decodeResource(getResources(), resourceint);
    iv.setImageResource(resourceint);//from  www.  j a  v a 2 s  . c o  m
    iv.setClickable(false);
    iv.addOnLayoutChangeListener(hourglasslistener);

}