Example usage for android.widget ImageView getViewTreeObserver

List of usage examples for android.widget ImageView getViewTreeObserver

Introduction

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

Prototype

public ViewTreeObserver getViewTreeObserver() 

Source Link

Document

Returns the ViewTreeObserver for this view's hierarchy.

Usage

From source file:ru.tlrs.vincent.LightBox.java

@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.d(TAG, "onCreateView: ");
    inflateView(inflater, container);/*from w w w.  j a va2 s  .  c om*/
    final ImageView fullImage = (ImageView) view.findViewById(R.id.fullImage);
    fullImage.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            fullImage.getViewTreeObserver().removeOnPreDrawListener(this);
            int height = fullImage.getMeasuredHeight();
            int width = fullImage.getMeasuredWidth();
            Log.d(TAG, "onPreDraw: " + String.format("height: %s, width: %s", height, width));
            //Rect view = new Rect(0,0,width, height);
            Drawable drawable = ((ImageView) getActivity().findViewById(parentId)).getDrawable();
            /*drawable = drawable.mutate();
            //Rect draw = drawable.getBounds();
            int h = drawable.getIntrinsicHeight();
            int w = drawable.getIntrinsicWidth();
            //drawable.setBounds(0,0,w,h);
            drawable.setBounds(new Rect(0,0,width,height));
            //ScaleDrawable sd = new ScaleDrawable(drawable, 0, 1.0f ,1.0f );*/
            //fullImage.setImageDrawable(drawable);
            //fullImage.setImageURI(null);
            Log.d(TAG, "onPreDraw: mSrc = " + mSrc);
            fullImage.setImageURI(Uri.parse("android.resource://com.example.vincent/" + mSrc)); //give "More than two path segments", instead of NullPointer
            return false;
        }
    });

    //((ImageView) view.findViewById(R.id.fullImage)).setImageDrawable(((ImageView) getActivity().findViewById(parentId)).getDrawable());
    ((TextView) view.findViewById(R.id.description)).setText(mDesc);
    return view;
}

From source file:codingpractice.renard314.com.products.ui.ProductDetailFragment.java

private void startLoadingImage(final ImageView imageView, final String name, final boolean extractColor) {

    imageView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        @SuppressLint("NewApi")
        @SuppressWarnings("deprecation")
        @Override// www .ja  v  a2 s  .com
        public void onGlobalLayout() {
            final int width = imageView.getWidth();
            final int height = imageView.getHeight();

            loadImage(width, height, imageView, name, extractColor);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                imageView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            } else {
                imageView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            }
        }
    });

}

From source file:com.example.linhdq.test.MonitoredActivity.java

/**
 * position the app icon at the bottom of the action bar and start animation
 *//* ww w.  jav  a 2  s.  c o  m*/
private void initAppIcon(final int dialogId, ImageView appIcon) {
    setDialogId(dialogId);
    mAppIcon = appIcon;
    final ViewTreeObserver viewTreeObserver = appIcon.getViewTreeObserver();
    if (viewTreeObserver.isAlive()) {
        viewTreeObserver.addOnGlobalLayoutListener(this);

    }
}

From source file:it.mb.whatshare.PairOutboundActivity.java

private void showPairingLayout() {
    View view = getLayoutInflater().inflate(R.layout.activity_qrcode, null);
    setContentView(view);//from   w  w w  .  ja va2s.c o  m
    String paired = getOutboundPaired();
    if (paired != null) {
        ((TextView) findViewById(R.id.qr_instructions))
                .setText(getString(R.string.new_outbound_instructions, paired));
    }
    inputCode = (EditText) findViewById(R.id.inputCode);

    inputCode.setFilters(new InputFilter[] { new InputFilter() {
        /*
         * (non- Javadoc )
         * 
         * @see android .text. InputFilter # filter( java .lang.
         * CharSequence , int, int, android .text. Spanned , int, int)
         */
        @Override
        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
                int dend) {
            if (source instanceof SpannableStringBuilder) {
                SpannableStringBuilder sourceAsSpannableBuilder = (SpannableStringBuilder) source;
                for (int i = end - 1; i >= start; i--) {
                    char currentChar = source.charAt(i);
                    if (!Character.isLetterOrDigit(currentChar)) {
                        sourceAsSpannableBuilder.delete(i, i + 1);
                    }
                }
                return source;
            } else {
                StringBuilder filteredStringBuilder = new StringBuilder();
                for (int i = 0; i < end; i++) {
                    char currentChar = source.charAt(i);
                    if (Character.isLetterOrDigit(currentChar)) {
                        filteredStringBuilder.append(currentChar);
                    }
                }
                return filteredStringBuilder.toString();
            }
        }
    }, new InputFilter.LengthFilter(MAX_SHORTENED_URL_LENGTH) });

    inputCode.setOnEditorActionListener(new OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                onSubmitPressed(null);
                return keepKeyboardVisible;
            }
            return false;
        }
    });

    final ImageView qrWrapper = (ImageView) findViewById(R.id.qr_code);
    qrWrapper.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        private boolean createdQRCode = false;

        @Override
        public void onGlobalLayout() {
            if (!createdQRCode) {
                try {
                    Bitmap qrCode = generateQRCode(generateRandomSeed(),
                            getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT
                                    ? qrWrapper.getHeight()
                                    : qrWrapper.getWidth());
                    if (qrCode != null) {
                        qrWrapper.setImageBitmap(qrCode);
                    }
                    createdQRCode = true;
                } catch (WriterException e) {
                    e.printStackTrace();
                }
            }
        }
    });
}

From source file:ca.rmen.android.scrumchatter.meeting.detail.MeetingCursorAdapter.java

/**
 * Show the imageView and start its animation drawable.
 *///from   w  ww .j  a  va2s  . co m
private void startAnimation(final ImageView imageView) {
    if (imageView.getVisibility() != View.VISIBLE) {
        Log.v(TAG, "startAnimation");
        imageView.setVisibility(View.VISIBLE);
        final AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getDrawable();
        // On some devices, directly calling start() on the animation does not work.
        // We have to wait until the ImageView is visible before starting the animation.
        imageView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
            @SuppressWarnings("deprecation")
            @Override
            public void onGlobalLayout() {
                if (!animationDrawable.isRunning()) {
                    imageView.post(() -> {
                        animationDrawable.setVisible(true, false);
                        animationDrawable.start();
                    });
                }
                imageView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            }
        });
    }
}

From source file:it.configure.imageloader.zoom.PhotoViewAttacher.java

public PhotoViewAttacher(ImageView imageView) {
    mImageView = new WeakReference<ImageView>(imageView);

    imageView.setOnTouchListener(this);

    mViewTreeObserver = imageView.getViewTreeObserver();
    mViewTreeObserver.addOnGlobalLayoutListener(this);

    // Make sure we using MATRIX Scale Type
    setImageViewScaleTypeMatrix(imageView);

    if (!imageView.isInEditMode()) {
        // Create Gesture Detectors...
        mScaleDragDetector = VersionedGestureDetector.newInstance(imageView.getContext(), this);

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

                    // forward long click listener
                    @Override/*from   w  ww .j  av  a  2  s  . c  o m*/
                    public void onLongPress(MotionEvent e) {
                        if (null != mLongClickListener) {
                            mLongClickListener.onLongClick(mImageView.get());
                        }
                    }
                });

        mGestureDetector.setOnDoubleTapListener(this);

        // Finally, update the UI so that we're zoomable
        setZoomable(true);
    }
}

From source file:com.ycl.framework.photoview.PhotoViewAttacher.java

public PhotoViewAttacher(final ImageView imageView) {
    mImageView = new WeakReference<ImageView>(imageView);

    imageView.setDrawingCacheEnabled(true);
    imageView.setOnTouchListener(this);

    ViewTreeObserver observer = imageView.getViewTreeObserver();
    if (null != observer)
        observer.addOnGlobalLayoutListener(this);

    // Make sure we using MATRIX Scale Type
    setImageViewScaleTypeMatrix(imageView);

    if (imageView.isInEditMode()) {
        return;/*from w ww  . j  ava 2 s .  c o m*/
    }
    // Create Gesture Detectors...
    mScaleDragDetector = com.ycl.framework.photoview.gestures.VersionedGestureDetector
            .newInstance(imageView.getContext(), this);

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

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

    mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this));

    // Finally, update the UI so that we're zoomable
    setZoomable(true);
}

From source file:suntai.ditudome.utils.photoview.PhotoViewAttacher.java

public void cleanup() {
    if (null == mImageView) {
        return; // cleanup already done
    }/*ww w  .  j  a  v  a  2s. co m*/

    final ImageView imageView = mImageView.get();

    if (null != imageView) {
        // Remove this as a global layout listener
        ViewTreeObserver observer = imageView.getViewTreeObserver();
        if (null != observer && observer.isAlive()) {
            observer.removeGlobalOnLayoutListener(this);
        }

        // Remove the ImageView's reference to this
        imageView.setOnTouchListener(null);

        // make sure a pending fling runnable won't be run
        cancelFling();
    }

    if (null != mGestureDetector) {
        mGestureDetector.setOnDoubleTapListener(null);
    }

    // Clear listeners too
    mMatrixChangeListener = null;
    mPhotoTapListener = null;
    mViewTapListener = null;

    // Finally, clear ImageView
    mImageView = null;
}

From source file:com.cylan.jiafeigou.support.photoview.PhotoViewAttacher.java

/**
 * Clean-up the resources attached to this object. This needs to be called when the ImageView is
 * no longer used. A good example is from {@link View#onDetachedFromWindow()} or
 * from {@link android.app.Activity#onDestroy()}. This is automatically called if you are using
 * {@link PhotoView}./*from ww w  .  j av a  2s .co  m*/
 */
@SuppressWarnings("deprecation")
public void cleanup() {
    if (null == mImageView) {
        return; // cleanup already done
    }

    final ImageView imageView = mImageView.get();

    if (null != imageView) {
        // Remove this as a global layout listener
        ViewTreeObserver observer = imageView.getViewTreeObserver();
        if (null != observer && observer.isAlive()) {
            observer.removeGlobalOnLayoutListener(this);
        }

        // Remove the ImageView'account reference to this
        imageView.setOnTouchListener(null);

        // make sure a pending fling runnable won't be run
        cancelFling();
    }

    if (null != mGestureDetector) {
        mGestureDetector.setOnDoubleTapListener(null);
    }

    // Clear listeners too
    mMatrixChangeListener = null;
    mPhotoTapListener = null;
    mViewTapListener = null;

    // Finally, clearLocal ImageView
    mImageView = null;
}

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

@SuppressWarnings("deprecation")
public void cleanup() {
    if (null == mImageView) {
        return; // cleanup already done
    }/*from   w  ww. j a v a 2s  . c  om*/

    final ImageView imageView = mImageView.get();

    if (null != imageView) {
        // Remove this as a global layout listener
        ViewTreeObserver observer = imageView.getViewTreeObserver();
        if (null != observer && observer.isAlive()) {
            observer.removeGlobalOnLayoutListener(this);
        }

        // Remove the ImageView's reference to this
        imageView.setOnTouchListener(null);

        // make sure a pending fling runnable won't be run
        cancelFling();
    }

    if (null != mGestureDetector) {
        mGestureDetector.setOnDoubleTapListener(null);
    }

    // Clear listeners too
    mMatrixChangeListener = null;
    mPhotoTapListener = null;
    mViewTapListener = null;

    // Finally, clear ImageView
    mImageView = null;
}