Example usage for android.widget ImageView getWidth

List of usage examples for android.widget ImageView getWidth

Introduction

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

Prototype

@ViewDebug.ExportedProperty(category = "layout")
public final int getWidth() 

Source Link

Document

Return the width of your view.

Usage

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

/**
 * Calculate Matrix for FIT_CENTER// ww w .j  ava 2  s  . co  m
 * 
 * @param d - Drawable being displayed
 */
private void updateBaseMatrix(Drawable d) {
    ImageView imageView = getImageView();
    if (null == imageView || null == d) {
        return;
    }

    final float viewWidth = imageView.getWidth();
    final float viewHeight = imageView.getHeight();
    final int drawableWidth = d.getIntrinsicWidth();
    final int drawableHeight = d.getIntrinsicHeight();

    mBaseMatrix.reset();

    final float widthScale = viewWidth / drawableWidth;
    final float heightScale = viewHeight / drawableHeight;

    if (mScaleType == ScaleType.CENTER) {
        mBaseMatrix.postTranslate((viewWidth - drawableWidth) / 2F, (viewHeight - drawableHeight) / 2F);

    } else if (mScaleType == ScaleType.CENTER_CROP) {
        float scale = Math.max(widthScale, heightScale);
        mBaseMatrix.postScale(scale, scale);
        mBaseMatrix.postTranslate((viewWidth - drawableWidth * scale) / 2F,
                (viewHeight - drawableHeight * scale) / 2F);

    } else if (mScaleType == ScaleType.CENTER_INSIDE) {
        float scale = Math.min(1.0f, Math.min(widthScale, heightScale));
        mBaseMatrix.postScale(scale, scale);
        mBaseMatrix.postTranslate((viewWidth - drawableWidth * scale) / 2F,
                (viewHeight - drawableHeight * scale) / 2F);

    } else {
        RectF mTempSrc = new RectF(0, 0, drawableWidth, drawableHeight);
        RectF mTempDst = new RectF(0, 0, viewWidth, viewHeight);

        switch (mScaleType) {
        case FIT_CENTER:
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.CENTER);
            break;

        case FIT_START:
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.START);
            break;

        case FIT_END:
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.END);
            break;

        case FIT_XY:
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.FILL);
            break;

        default:
            break;
        }
    }

    resetMatrix();
}

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

@Override
public final void onFling(float startX, float startY, float velocityX, float velocityY) {
    if (DEBUG) {//from   ww w. java2 s. c o  m
        Log.d(LOG_TAG, "onFling. sX: " + startX + " sY: " + startY + " Vx: " + velocityX + " Vy: " + velocityY);
    }

    ImageView imageView = getImageView();
    if (hasDrawable(imageView)) {
        mCurrentFlingRunnable = new FlingRunnable(imageView.getContext());
        mCurrentFlingRunnable.fling(imageView.getWidth(), imageView.getHeight(), (int) velocityX,
                (int) velocityY);
        imageView.post(mCurrentFlingRunnable);
    }
}

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

private void showPairingLayout() {
    View view = getLayoutInflater().inflate(R.layout.activity_qrcode, null);
    setContentView(view);//  ww w . java2 s.  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:com.imaginamos.taxisya.taxista.activities.RegisterDriverActivity.java

private void setThumbnailImage(ImageView mImageView, String imagePath) {
    // Get the dimensions of the View
    int targetW = mImageView.getWidth();
    int targetH = mImageView.getHeight();

    // Get the dimensions of the bitmap
    BitmapFactory.Options bmOptions = new BitmapFactory.Options();
    bmOptions.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(imagePath, bmOptions);
    int photoW = bmOptions.outWidth;
    int photoH = bmOptions.outHeight;

    // Determine how much to scale down the image
    int scaleFactor = Math.min(photoW / targetW, photoH / targetH);

    // Decode the image file into a Bitmap sized to fill the View
    bmOptions.inJustDecodeBounds = false;
    bmOptions.inSampleSize = scaleFactor;
    bmOptions.inPurgeable = true;//from   w  w w .j a v a  2s  .  co  m

    Bitmap bitmap = BitmapFactory.decodeFile(imagePath, bmOptions);
    mImageView.setImageBitmap(bitmap);
}

From source file:com.imaginamos.taxisya.taxista.activities.RegisterDriverActivity.java

private void setThumbnailImageStorage(ImageView mImageView, String imageString) {
    // Get the dimensions of the View
    int targetW = mImageView.getWidth();
    int targetH = mImageView.getHeight();

    // Get the dimensions of the bitmap
    BitmapFactory.Options bmOptions = new BitmapFactory.Options();
    bmOptions.inJustDecodeBounds = true;
    //BitmapFactory.decodeFile(imagePat, bmOptions);
    int photoW = bmOptions.outWidth;
    int photoH = bmOptions.outHeight;

    // Determine how much to scale down the image
    int scaleFactor = Math.min(photoW / targetW, photoH / targetH);

    // Decode the image file into a Bitmap sized to fill the View
    bmOptions.inJustDecodeBounds = false;
    bmOptions.inSampleSize = scaleFactor;
    bmOptions.inPurgeable = true;/*w  w  w. jav a 2  s. c o m*/

    // Bitmap bitmap = decodeBase64(imageString));

    byte[] b = Base64.decode(imageString, Base64.DEFAULT);
    InputStream is = new ByteArrayInputStream(b);
    //Bitmap bitmap = BitmapFactory.decodeStream(is, bmOptions);
    Bitmap bitmap = BitmapFactory.decodeFile(imageString, bmOptions);
    mImageView.setImageBitmap(bitmap);

}

From source file:koma.movieapp.ui.MoviesFragment.java

@Override
public void bindCollectionItemView(Context context, View view, int groupId, int indexInGroup, int dataIndex,
        Object tag) {//from  ww  w.  java  2 s.  com

    if (mMovieList.isEmpty() || mMovieList.get(dataIndex) == null) {
        return;
    }

    Movie movie = mMovieList.get(dataIndex);

    final String movieId = movie.id.toString();

    if (movieId == null)
        return;

    final String movieTitle = movie.title;
    final String movieRating = movie.vote_average.toString();
    final String movieBackdrop = movie.backdrop_path;

    System.out.println("Movie title in BindCollectionItemView: " + movieTitle);

    int movieColor = getResources().getColor(R.color.default_movie_color);
    int darkMovieColor = 0;

    final TextView titleView = (TextView) view.findViewById(R.id.movie_title);

    final View movieTargetView = view.findViewById(R.id.movie_target);

    if (movieColor == 0) {
        movieColor = mDefaultMovieColor;
    }

    darkMovieColor = UIUtils.scaleMovieColorToDefaultBG(movieColor);

    ImageView photoView = (ImageView) view.findViewById(R.id.session_photo_colored);

    if (photoView != null) {
        if (!mPreloader.isDimensSet()) {
            final ImageView finalPhotoView = photoView;
            photoView.post(new Runnable() {
                @Override
                public void run() {
                    mPreloader.setDimens(finalPhotoView.getWidth(), finalPhotoView.getHeight());
                }
            });
        }
        //            // colored filter on the images
        //            photoView.setColorFilter(mNoTrackBranding
        //                    ? new PorterDuffColorFilter(
        //                    getResources().getColor(R.color.no_track_branding_session_tile_overlay),
        //                    PorterDuff.Mode.SRC_ATOP)
        //                    : UIUtils.makeSessionImageScrimColorFilter(darkMovieColor));
    } else {
        photoView = (ImageView) view.findViewById(R.id.session_photo_colored);
    }
    ViewCompat.setTransitionName(photoView, "photo_" + movieId);

    // when we load a photo, it will fade in from transparent so the
    // background of the container must be the session color to avoid a white flash
    ViewParent parent = photoView.getParent();
    if (parent != null && parent instanceof View) {
        ((View) parent).setBackgroundColor(darkMovieColor);
    } else {
        photoView.setBackgroundColor(darkMovieColor);
    }

    // render title

    //titleView.setTextColor(getResources().getColor(R.color.body_text_1_inverse));
    //titleView.setTextColor(getResources().getColor(R.color.body_text_1_inverse));
    //titleView.setBackgroundColor(getResources().getColor(R.color.material_blue_grey_800));
    //titleView.setBackgroundColor(getResources().getColor(R.color.theme_primary));

    titleView.setText(movieTitle == null ? "?" : movieTitle);

    //photoView.setColorFilter(new PorterDuffColorFilter(getResources().getColor(R.color.data_item_background_with_alpha),PorterDuff.Mode.SCREEN));

    // set the images
    if (movieBackdrop != null) {
        mImageLoader.loadImage(Config.TMDB_IMAGE_BASE_URL + "w780" + movieBackdrop, photoView);
    }

    final View finalPhotoView = photoView;
    movieTargetView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mCallbacks.onMovieSelected(movieId, finalPhotoView);
        }
    });

    // animate this card
    if (dataIndex > mMaxDataIndexAnimated) {
        mMaxDataIndexAnimated = dataIndex;
    }

}

From source file:com.sociablue.nanodegree_p1.MovieListFragment.java

private void initializeFab(View rootView) {
    final RelativeLayout buttonContainer = (RelativeLayout) rootView.findViewById(R.id.menu_button_container);
    final FloatingActionButton Fab = (FloatingActionButton) rootView.findViewById(R.id.fab);
    final ImageView bottomBar = (ImageView) rootView.findViewById(R.id.menu_bottom_bar);
    final ImageView topBar = (ImageView) rootView.findViewById(R.id.menu_top_bar);
    Fab.setOnClickListener(new View.OnClickListener() {
        @TargetApi(Build.VERSION_CODES.LOLLIPOP)
        @Override//from   ww  w  .j a v  a  2s.c  o m
        public void onClick(View v) {

            //Menu Button Icon Animation
            //Setting up necessary variables
            long animationDuration = 500;
            float containerHeight = buttonContainer.getHeight();
            float containerCenterY = containerHeight / 2;
            float containerCenterX = buttonContainer.getWidth() / 2;
            float topBarCenter = topBar.getTop() + topBar.getHeight() / 2;
            float widthOfBar = topBar.getWidth();
            float heightOfBar = topBar.getHeight();
            final float distanceBetweenBars = (containerCenterY - topBarCenter);

            /**
             *TODO: Refactor block of code to use Value Property Animator. Should be more efficient to animate multiple properties
             *and objects at the same time. Also, will try to break intialization into smaller functions.
             */

            //Setting up animations of hamburger bars and rotation

            /**
             * Animation For Top Menu Button Icon Bar. Sliding from the top to rest on top of the middle bar.
             * Y Translation is 1/2 the height of the hamburger bar minus the distance.
             * Subtracting the distance from the height because the distance between bars is
             * calculated of the exact center of the button.
             * With out the subtraction the bar would translate slightly below the middle bar.
             */
            float yTranslation = heightOfBar / 2 - distanceBetweenBars;
            float xTranslation = widthOfBar / 2 + heightOfBar / 2;
            TranslateAnimation topBarTranslationAnim = new TranslateAnimation(Animation.ABSOLUTE, 0f,
                    Animation.ABSOLUTE, 0F, Animation.ABSOLUTE, 0f, Animation.ABSOLUTE, distanceBetweenBars);
            topBarTranslationAnim.setDuration((long) (animationDuration * 0.8));
            topBarTranslationAnim.setFillAfter(true);

            //Animation for bottom hamburger bar. Translates and Rotates to create 'X'
            AnimationSet bottomBarAnimation = new AnimationSet(true);
            bottomBarAnimation.setFillAfter(true);

            //Rotate to create cross. (The cross becomes the X after the button rotation completes"
            RotateAnimation bottomBarRotationAnimation = new RotateAnimation(0f, 90f,
                    Animation.RELATIVE_TO_SELF, 1f, Animation.RELATIVE_TO_SELF, 1f);
            bottomBarRotationAnimation.setDuration(animationDuration);
            bottomBarAnimation.addAnimation(bottomBarRotationAnimation);

            //Translate to correct X alignment
            TranslateAnimation bottomBarTranslationAnimation = new TranslateAnimation(Animation.ABSOLUTE, 0f,
                    Animation.ABSOLUTE, -xTranslation, Animation.ABSOLUTE, 0f, Animation.ABSOLUTE,
                    -yTranslation);
            bottomBarTranslationAnimation.setDuration(animationDuration);
            bottomBarAnimation.addAnimation(bottomBarTranslationAnimation);

            //Button Specific Animations
            //Rotate Button Container
            RotateAnimation containerRotationAnimation = new RotateAnimation(0, 135f,
                    Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
            containerRotationAnimation.setDuration(animationDuration);
            containerRotationAnimation.setFillAfter(true);

            //Animate change of button color between Active and Disabled colors that have been
            //defined in color.xml
            int activeColor = getResources().getColor(R.color.active_button);
            int disabledColor = getResources().getColor(R.color.disabled_button);

            //Need to use ValueAnimator because property animator does not support BackgroundTint
            ValueAnimator buttonColorAnimation = ValueAnimator.ofArgb(activeColor, disabledColor);
            buttonColorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    Fab.setBackgroundTintList(ColorStateList.valueOf((int) animation.getAnimatedValue()));
                }
            });
            buttonColorAnimation.setDuration(animationDuration);

            //Start all the animations
            topBar.startAnimation(topBarTranslationAnim);
            bottomBar.startAnimation(bottomBarAnimation);
            buttonContainer.startAnimation(containerRotationAnimation);
            buttonColorAnimation.start();

            //Toogle mMenu open and closed
            if (mMenu.isOpen()) {
                //If mMenu is open, do the reverse of the animation
                containerRotationAnimation
                        .setInterpolator(new ReverseInterpolator(new AccelerateInterpolator()));
                topBarTranslationAnim.setInterpolator(new ReverseInterpolator(new AccelerateInterpolator()));
                bottomBarAnimation.setInterpolator(new ReverseInterpolator(new AccelerateInterpolator()));
                buttonColorAnimation.setInterpolator(new ReverseInterpolator(new LinearInterpolator()));
                mMenu.close();
            } else {
                bottomBarAnimation.setInterpolator(new AccelerateInterpolator());
                mMenu.open();
            }
        }
    });
}

From source file:ru.gkpromtech.exhibition.events.EventsFragment.java

private View createHeader(LayoutInflater inflater, int index) {

    final View v = inflater.inflate(R.layout.layout_events_baner, null);
    final ImageView image = (ImageView) v.findViewById(R.id.imageView);
    final TextView textDay = (TextView) v.findViewById(R.id.textDateDay);
    final TextView textMonth = (TextView) v.findViewById(R.id.textDateMonth);

    final SimpleDateFormat dateFormatDay = new SimpleDateFormat("dd", Locale.getDefault());
    final SimpleDateFormat dateFormatMonth = new SimpleDateFormat("MMMM", Locale.getDefault());
    Date day = EventReader.getInstance(getActivity()).getDay(index);
    textDay.setText(dateFormatDay.format(day));
    textMonth.setText(dateFormatMonth.format(day));

    final int resourceIds[] = { R.drawable.dayimage1, R.drawable.dayimage2, R.drawable.dayimage3,
            R.drawable.dayimage4 };/*from  w w w .  ja  va  2 s. c  o m*/
    final int num = index % (resourceIds.length);
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            if (getActivity() != null) {
                Bitmap b = decodeSampledBitmapFromResource(getResources(), resourceIds[num], image.getWidth(),
                        image.getHeight());
                image.setImageBitmap(b);
            }
        }
    }, 50);

    return v;
}

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

private int getImageViewWidth(ImageView imageView) {
    if (null == imageView) {
        return 0;
    }//from w ww  .j  a v  a  2s.c o  m
    return imageView.getWidth() - imageView.getPaddingLeft() - imageView.getPaddingRight();
}

From source file:uk.co.senab.photoview.PhotoViewAttacher.java

private void calculateCurrentImageMatrix() {
    ImageView iv = getImageView();
    if (iv != null) {
        currentImageMatrix.reset();/*  w  w  w  .j  a v  a2 s  .  co  m*/
        currentImageMatrix.setScale((float) iv.getWidth() / originalBitmapSize.x,
                (float) iv.getHeight() / originalBitmapSize.y);
    }
}