Example usage for android.view View addOnLayoutChangeListener

List of usage examples for android.view View addOnLayoutChangeListener

Introduction

In this page you can find the example usage for android.view View 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:com.huyn.demogroup.zoomageview.view.PhotoViewAttacher.java

public PhotoViewAttacher(ImageView imageView) {
    mImageView = imageView;//from   www .  java  2  s.  c  o  m
    View parent = (View) mImageView.getParent();
    parent.setOnTouchListener(this);
    parent.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 (mIsDragging) {
                return false;
            }
            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.simas.vc.editor.EditorFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
    View root = inflater.inflate(R.layout.fragment_editor, container, false);
    // Overlay a ProgressBar when preparing the PlayerFragment for the first time
    mProgressOverlay = root.findViewById(R.id.editor_progress_overlay);

    mPlayerFragment = (PlayerFragment) getChildFragmentManager().findFragmentById(R.id.player_fragment);

    // Queue container modifications until it's measured
    final View playerContainer = mPlayerFragment.getContainer();
    final Runnable playerResize = new Runnable() {
        @Override//from  w w  w . j ava2 s .c  o  m
        public void run() {
            ViewGroup.LayoutParams params = playerContainer.getLayoutParams();
            params.width = MainActivity.sPlayerContainerSize;
            params.height = MainActivity.sPlayerContainerSize;
            playerContainer.setLayoutParams(params);

            playerContainer.post(new Runnable() {
                @Override
                public void run() {
                    modifyProgressOverlayStates(true, ProgressStates.PLAYER_CONTAINER_DRAWN);
                }
            });
        }
    };
    if (MainActivity.sPlayerContainerSize != 0) {
        playerResize.run();
    } else {
        playerContainer.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
            @Override
            public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft,
                    int oldTop, int oldRight, int oldBottom) {
                int size = Math.max(playerContainer.getWidth(), playerContainer.getHeight());
                if (size <= 0)
                    return;
                MainActivity.sPlayerContainerSize = size;
                playerContainer.removeOnLayoutChangeListener(this);
                playerResize.run();
            }
        });
    }

    mDelayedHandler.resume();

    View actions = root.findViewById(R.id.editor_actions);
    mDataMap.put(Data.ACTIONS, actions);
    mDataMap.put(Data.FILENAME, actions.findViewById(R.id.filename_value));
    mDataMap.put(Data.SIZE, actions.findViewById(R.id.size_value));
    mDataMap.put(Data.DURATION, actions.findViewById(R.id.duration_value));
    mDataMap.put(Data.STREAM_TREE, actions.findViewById(R.id.tree_view));

    if (savedState != null) {
        NavItem previousItem = savedState.getParcelable(STATE_PREVIOUS_ITEM);
        if (previousItem != null) {
            setItem(previousItem);
        }
    }

    return root;
}

From source file:com.vuze.android.remote.fragment.TorrentListFragment.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void onCreateViewHC(View fragView) {
    if (sideListArea != null) {
        fragView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
            int lastWidth = -1;

            @Override/* w  ww .j  av a 2s .c om*/
            public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft,
                    int oldTop, int oldRight, int oldBottom) {
                int width = right - left;
                if (width != lastWidth) {
                    lastWidth = width;
                    expandSideListWidth(sidelistInFocus);
                }
            }
        });
    }
}

From source file:Main.java

private static void setupChangeAnimationOneTime(final View view) {
    ObjectAnimator objectAnimator = sMapAnimators.get(view);
    if (objectAnimator != null) {
        objectAnimator.cancel();//from  www. j  a  v  a2 s .  c om
        sMapAnimators.remove(objectAnimator);
    }
    OnLayoutChangeListener listener = sMapListeners.get(view);
    if (listener != null) {
        view.removeOnLayoutChangeListener(listener);
        sMapListeners.remove(view);
    }

    final OnLayoutChangeListener onLayoutChangeListener = new OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop,
                int oldRight, int oldBottom) {

            ObjectAnimator objectAnimator = sMapAnimators.get(view);
            if (objectAnimator != null) {
                objectAnimator.cancel();
                sMapAnimators.remove(objectAnimator);
            }

            final ObjectAnimator changeAnimator = getChangeAnimator(v, left, top, right, bottom, oldLeft,
                    oldTop, oldRight, oldBottom);

            sMapAnimators.put(view, changeAnimator);

            if (left != oldLeft || top != oldTop || right != oldRight || bottom != oldBottom) {
                Animator.AnimatorListener animatorListener = new Animator.AnimatorListener() {

                    @Override
                    public void onAnimationStart(Animator animation) {
                        if (sAnimatorListener != null) {
                            sAnimatorListener.onAnimationStart(animation);
                        }
                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {
                        if (sAnimatorListener != null) {
                            sAnimatorListener.onAnimationRepeat(animation);
                        }
                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        sMapAnimators.remove(view);
                        if (sAnimatorListener != null) {
                            sAnimatorListener.onAnimationEnd(animation);
                        }
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {
                        if (sAnimatorListener != null) {
                            sAnimatorListener.onAnimationCancel(animation);
                        }
                    }
                };
                changeAnimator.addListener(animatorListener);

                changeAnimator.start();
            } else {
                sMapAnimators.remove(view);
                if (sAnimatorListener != null) {
                    sAnimatorListener.onAnimationEnd(changeAnimator);
                }
            }
        }
    };
    view.addOnLayoutChangeListener(onLayoutChangeListener);
    sMapListeners.put(view, onLayoutChangeListener);
}

From source file:com.waz.zclient.newreg.fragments.EmailInvitationFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup viewGroup, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_invite__email, viewGroup, false);

    int buttonColor = getResources().getColor(R.color.text__primary_dark);

    TextView termsOfServicesTextView = ViewUtils.getView(view, R.id.tv__email_invite__terms_of_service);
    TextViewUtils.linkifyText(termsOfServicesTextView, buttonColor, false, new Runnable() {
        @Override/*from w w w .j  a va 2  s  . co m*/
        public void run() {
            if (getContainer() == null || getControllerFactory() == null
                    || getControllerFactory().isTornDown()) {
                return;
            }
            getContainer().onOpenUrlInApp(getString(R.string.url_terms_of_service), true);
            getControllerFactory().getTrackingController().tagEvent(new ViewTOS(ViewTOS.Source.FROM_JOIN_PAGE));
        }
    });

    signUpAlternativeButton = ViewUtils.getView(view, R.id.zb__email_invite__signup_alternative);
    signUpAlternativeButton.setIsFilled(false);
    signUpAlternativeButton.setAccentColor(getResources().getColor(R.color.text__secondary_dark__40));
    if (LayoutSpec.isPhone(getActivity())) {
        signUpAlternativeButton.setText(getString(R.string.invitation_email__normal_phone_signup_button));
    } else {
        signUpAlternativeButton.setText(getString(R.string.invitation_email__normal_email_signup_button));
    }

    headerTextView = ViewUtils.getView(view, R.id.ttv_email_invite__header);
    headerTextView.setText(getResources().getString(R.string.invitation_email__welcome_header, name));
    messageTextView = ViewUtils.getView(view, R.id.ttv_email_invite__message);

    registerButton = ViewUtils.getView(view, R.id.zb__email_invite__register);
    registerButton.setIsFilled(true);
    registerButton.setAccentColor(buttonColor);
    registerButton.setEnabled(false);

    passwordEditText = ViewUtils.getView(view, R.id.tet__email_invite__password);
    passwordEditText.setHint(getResources().getString(R.string.invitation_email__password_placeholder,
            getResources().getInteger(R.integer.password_validator__min_password_length)));

    emailTextView = ViewUtils.getView(view, R.id.tet__email_invite__email);
    emailTextView.setText(email);

    view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop,
                int oldRight, int oldBottom) {
            int[] buttonLocation = new int[2];
            signUpAlternativeButton.getLocationOnScreen(buttonLocation);
            int[] headerLocation = new int[2];
            headerTextView.getLocationOnScreen(headerLocation);
            if (buttonLocation[1] + signUpAlternativeButton.getHeight() > headerLocation[1]) {
                headerTextView.setVisibility(View.INVISIBLE);
                messageTextView.setVisibility(View.INVISIBLE);
            } else {
                headerTextView.setVisibility(View.VISIBLE);
                messageTextView.setVisibility(View.VISIBLE);
            }
        }
    });

    return view;
}