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:com.github.programmerr47.vkgroups.imageloading.ImageWorker.java

private void handleParams(ImageView imageView, LoadBitmapParams params) {
    if (params.imageHeight == 0) {
        params.imageHeight = imageView.getHeight();
    }//  ww  w.  j a v a 2  s  .  c  om

    if (params.imageWidth == 0) {
        params.imageWidth = imageView.getWidth();
    }
}

From source file:de.janrenz.app.mediathek.LiveFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    // TODO Auto-generated method stub
    if (cursor != null && cursor.getCount() > 0) {

        Cursor myCursor = cursor;
        myCursor.moveToFirst();/*from   w  w  w. j a  v a2 s.  c om*/
        TextView tView = (TextView) mView.findViewById(R.id.description);
        tView.setText(myCursor.getString(myCursor.getColumnIndexOrThrow("description")));
        Boolean showLongDesc = false;
        try {
            SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity());
            showLongDesc = sharedPref.getBoolean(SettingsActivity.SHOW_LONG_DESC, true);

        } catch (Exception e) {
            // use the default if we cant fetch it
        }
        if (showLongDesc == false) {
            tView.setMaxLines(5);

            tView.setHorizontalFadingEdgeEnabled(true);

            tView.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    TextView tv = (TextView) v;
                    tv.setMaxLines(200);
                    tv.setHorizontalFadingEdgeEnabled(false);
                }
            });

        } else {

        }
        TextView dView = (TextView) mView.findViewById(R.id.durationText);
        dView.setText(myCursor.getString(myCursor.getColumnIndexOrThrow("timeinfo")));
        /**
         * Set the image
         */
        DisplayImageOptions loadingOptions = new DisplayImageOptions.Builder().showStubImage(R.drawable.ic_stub)
                // .showImageForEmptyUri(R.drawable.ic_empty)
                .showImageOnFail(R.drawable.ic_error).cacheInMemory()
                // .cacheOnDisc()
                .build();
        ImageView image_view = (ImageView) mView.findViewById(R.id.thumbnail);

        if (image_view != null) {
            ImageLoader.getInstance().displayImage(
                    myCursor.getString(myCursor.getColumnIndexOrThrow("image")) + "/" + image_view.getWidth(),
                    image_view, loadingOptions);
        }
        TextView h1 = (TextView) mView.findViewById(R.id.headline1);
        h1.setText(myCursor.getString(myCursor.getColumnIndexOrThrow("title")));

        // The Cursor is now set to the right position
        Movie mMovie = new Movie();
        mMovie.setTitle(myCursor.getString(myCursor.getColumnIndexOrThrow("title")));
        mMovie.setSubtitle(myCursor.getString(myCursor.getColumnIndexOrThrow("subtitle")));
        mMovie.setExtId(myCursor.getString(myCursor.getColumnIndexOrThrow("extId")));
        mMovie.setStarttime(myCursor.getString(myCursor.getColumnIndexOrThrow("startTime")));
        mMovie.setStarttimestamp(myCursor.getInt(myCursor.getColumnIndexOrThrow("startTimeAsTimestamp")));
        mMovie.setIsLive(myCursor.getString(myCursor.getColumnIndexOrThrow("isLive")));
        mView.findViewById(R.id.showAfterLoadItems).setVisibility(View.VISIBLE);
        mView.findViewById(R.id.hideAfterLoadItems).setVisibility(View.GONE);
    }

}

From source file:com.landenlabs.all_UiDemo.frag.ImageScalesFrag.java

private Bitmap fillUpperLeft(final Drawable drawable, ImageView imageView, Bitmap prevBm) {

    // Compute  matrix to fill viewer with drawable starting with upper left
    // Stretching till 2nd edge is crossed (filling screen) with correct aspect ratio.
    Matrix m = new Matrix();
    m.reset();/*from   w  w  w  .  java 2s. co  m*/
    int imgWidth = drawable.getIntrinsicWidth();
    int imgHeight = drawable.getIntrinsicHeight();
    int viewWidth = imageView.getWidth();
    int viewHeight = imageView.getHeight();
    float xScale = (float) viewWidth / imgWidth;
    float yScale = (float) viewHeight / imgHeight;
    float maxScale = Math.max(xScale, yScale);

    m.postScale(maxScale, maxScale);

    imageView.setScaleType(ImageView.ScaleType.MATRIX);
    imageView.setImageMatrix(m);
    imageView.setImageDrawable(drawable);
    return prevBm;
}

From source file:com.landenlabs.all_UiDemo.frag.ImageScalesFrag.java

private Bitmap fillLowerLeft(final Drawable drawable, ImageView imageView, Bitmap prevBm) {

    // Compute  matrix to fill viewer with drawable starting with upper left
    // Stretching till 2nd edge is crossed (filling screen) with correct aspect ratio.
    Matrix m = new Matrix();
    m.reset();//w w  w .j  av  a  2  s .  co  m
    int imgWidth = drawable.getIntrinsicWidth();
    int imgHeight = drawable.getIntrinsicHeight();
    int viewWidth = imageView.getWidth();
    int viewHeight = imageView.getHeight();
    float xScale = (float) viewWidth / imgWidth;
    float yScale = (float) viewHeight / imgHeight;
    float maxScale = Math.max(xScale, yScale);

    float dy = (imgHeight * maxScale - viewHeight) / maxScale;
    // dy = imgHeight / 2;
    m.preTranslate(0, -dy);
    m.postScale(maxScale, maxScale);

    imageView.setScaleType(ImageView.ScaleType.MATRIX);
    imageView.setImageMatrix(m);
    imageView.setImageDrawable(drawable);
    return prevBm;
}

From source file:com.fa.mastodon.activity.MainActivity.java

private void onFetchUserInfoSuccess(Account me, String domain) {
    // Add the header image and avatar from the account, into the navigation drawer header.
    headerResult.clear();/* w w  w  . j a v  a 2  s  .c om*/

    ImageView background = headerResult.getHeaderBackgroundView();
    int backgroundWidth = background.getWidth();
    int backgroundHeight = background.getHeight();
    if (backgroundWidth == 0 || backgroundHeight == 0) {
        /* The header ImageView may not be layed out when the verify credentials call returns so
         * measure the dimensions and use those. */
        background.measure(View.MeasureSpec.EXACTLY, View.MeasureSpec.EXACTLY);
        backgroundWidth = background.getMeasuredWidth();
        backgroundHeight = background.getMeasuredHeight();
    }

    background.setBackgroundColor(ContextCompat.getColor(this, R.color.window_background_dark));

    if (backgroundWidth == 0 || backgroundHeight == 0) {
    } else {
        Picasso.with(MainActivity.this).load(me.header).placeholder(R.drawable.account_header_default)
                .resize(backgroundWidth, backgroundHeight).centerCrop().into(background);
    }

    headerResult.addProfiles(new ProfileDrawerItem().withName(me.getDisplayName())
            .withEmail(String.format("%s@%s", me.username, domain)).withIcon(me.avatar));

    // Show follow requests in the menu, if this is a locked account.
    if (me.locked) {
        PrimaryDrawerItem followRequestsItem = new PrimaryDrawerItem().withIdentifier(6)
                .withName(R.string.action_view_follow_requests).withSelectable(false)
                .withIcon(GoogleMaterial.Icon.gmd_person_add);
        drawer.addItemAtPosition(followRequestsItem, 3);
    }

    // Update the current login information.
    loggedInAccountId = me.id;
    loggedInAccountUsername = me.username;
    getPrivatePreferences().edit().putString("loggedInAccountId", loggedInAccountId)
            .putString("loggedInAccountUsername", loggedInAccountUsername)
            .putBoolean("loggedInAccountLocked", me.locked).apply();
}

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

private int getImageViewWidth(ImageView imageView) {
    return imageView.getWidth() - imageView.getPaddingLeft() - imageView.getPaddingRight();
}

From source file:com.evandroid.musica.fragment.LocalLyricsFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    if (this.isHidden())
        return;//from  w w w .  j  a va  2  s  .  c o m

    megaListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {

        @Override
        public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
            final ImageView indicator = (ImageView) v.findViewById(R.id.group_indicator);
            RotateAnimation anim;
            if (megaListView.isGroupExpanded(groupPosition)) {
                megaListView.collapseGroupWithAnimation(groupPosition);
                if (indicator != null) {
                    anim = new RotateAnimation(180f, 360f, indicator.getWidth() / 2, indicator.getHeight() / 2);
                    anim.setInterpolator(new DecelerateInterpolator(3));
                    anim.setDuration(500);
                    anim.setFillAfter(true);
                    indicator.startAnimation(anim);
                }
            } else {
                megaListView.expandGroupWithAnimation(groupPosition);
                if (indicator != null) {
                    anim = new RotateAnimation(0f, 180f, indicator.getWidth() / 2, indicator.getHeight() / 2);
                    anim.setInterpolator(new DecelerateInterpolator(2));
                    anim.setDuration(500);
                    anim.setFillAfter(true);
                    indicator.startAnimation(anim);
                }
            }
            return true;
        }
    });

    megaListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
        @Override
        public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition,
                long id) {
            if (mSwiping) {
                mSwiping = false;
                return false;
            }
            final MainLyricActivity mainLyricActivity = (MainLyricActivity) getActivity();
            megaListView.setOnChildClickListener(null); // prevents bug on double tap
            mainLyricActivity.updateLyricsFragment(R.animator.slide_out_start, R.animator.slide_in_start, true,
                    lyricsArray.get(groupPosition).get(childPosition));
            return true;
        }
    });

    this.isActiveFragment = true;
    new DBContentLister(this).execute();
}

From source file:uk.org.ngo.squeezer.util.ImageWorker.java

/**
 * Load an image specified by the data parameter into an ImageView (override {@link
 * ImageWorker#processBitmap(BitmapWorkerTaskParams)} to define the processing logic). A memory and disk cache
 * will be used if an {@link ImageCache} has been set using {@link
 * ImageWorker#setImageCache(ImageCache)}. If the image is found in the memory cache, it is set
 * immediately, otherwise an {@link AsyncTask} will be created to asynchronously load the
 * bitmap./*from   w w w . j ava 2 s . co  m*/
 *
 * @param data The URL of the image to download
 * @param imageView The ImageView to bind the downloaded image to
 */
public void loadImage(final Object data, final ImageView imageView) {
    if (data == null) {
        return;
    }

    int width = imageView.getWidth();
    int height = imageView.getHeight();

    // If the dimensions aren't known yet then the view hasn't been measured. Get a
    // ViewTreeObserver and listen for the PreDraw message. Using a GlobalLayoutListener
    // does not work for views that are in the list but drawn off-screen, possibly due
    // to the convertview. See http://stackoverflow.com/a/14325365 for some discussion.
    // The solution there, of posting a runnable, does not appear to reliably work on
    // devices running (at least) API 7. An OnPreDrawListener appears to work, and will
    // be called after measurement is complete.
    if (width == 0 || height == 0) {
        // Store the URL in the imageView's tag, in case the URL assigned to is changed.
        imageView.setTag(data);

        imageView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
            @Override
            public boolean onPreDraw() {
                imageView.getViewTreeObserver().removeOnPreDrawListener(this);
                // If the imageView is still assigned to the URL then we can load in to it.
                if (data.equals(imageView.getTag())) {
                    loadImage(data, imageView);
                }
                return true;
            }
        });
        return;
    }

    loadImage(data, imageView, width, height);
}

From source file:com.geecko.QuickLyric.fragment.LocalLyricsFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    final MainActivity mainActivity = ((MainActivity) this.getActivity());
    super.onViewCreated(view, savedInstanceState);
    if (this.isHidden())
        return;// ww w. j a  v a2s .c  o m

    DrawerAdapter drawerAdapter = ((DrawerAdapter) ((ListView) mainActivity.findViewById(R.id.drawer_list))
            .getAdapter());
    if (drawerAdapter.getSelectedItem() != 1) {
        drawerAdapter.setSelectedItem(1);
        drawerAdapter.notifyDataSetChanged();
    }

    if (!megaListView.hasOnGroupClickListener())
        megaListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {

            @Override
            public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
                final ImageView indicator = (ImageView) v.findViewById(R.id.group_indicator);
                RotateAnimation anim;
                if (megaListView.isGroupExpanded(groupPosition)) {
                    megaListView.collapseGroupWithAnimation(groupPosition);
                    if (indicator != null) {
                        anim = new RotateAnimation(180f, 360f, indicator.getWidth() / 2,
                                indicator.getHeight() / 2);
                        anim.setInterpolator(new DecelerateInterpolator(3));
                        anim.setDuration(500);
                        anim.setFillAfter(true);
                        indicator.startAnimation(anim);
                    }
                } else {
                    megaListView.expandGroupWithAnimation(groupPosition);
                    if (indicator != null) {
                        anim = new RotateAnimation(0f, 180f, indicator.getWidth() / 2,
                                indicator.getHeight() / 2);
                        anim.setInterpolator(new DecelerateInterpolator(2));
                        anim.setDuration(500);
                        anim.setFillAfter(true);
                        indicator.startAnimation(anim);
                    }
                }
                return true;
            }
        });

    if (!megaListView.hasOnChildClickListener())
        megaListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
            @Override
            public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition,
                    long id) {
                if (mSwiping) {
                    mSwiping = false;
                    return false;
                }
                final MainActivity mainActivity = (MainActivity) getActivity();
                megaListView.setOnChildClickListener(null); // prevents bug on double tap
                mainActivity.updateLyricsFragment(R.animator.slide_out_start, R.animator.slide_in_start, true,
                        ((LocalAdapter) megaListView.getExpandableListAdapter()).getChild(groupPosition,
                                childPosition));
                return true;
            }
        });

    this.isActiveFragment = true;
    new DBContentLister(this).execute();
}

From source file:io.intue.kamu.BestNearbyFragment.java

@Override
public void bindCollectionItemView(Context context, View view, int groupId, int indexInGroup, int dataIndex,
        Object tag) {//ww  w  .java  2s  .c  o m
    //        if (mCursor == null || !mCursor.moveToPosition(dataIndex)) {
    //            LOGW(TAG, "Can't bind collection view item, dataIndex=" + dataIndex +
    //                    (mCursor == null ? ": cursor is null" : ": bad data index."));
    //            return;
    //        }

    if (mresult == null) {
        return;
    }
    Venue result = mresult.get(dataIndex);

    final String sessionId = result.getId();
    if (sessionId == null) {
        return;
    }

    // first, read session info from cursor and put it in convenience variables
    final String sessionTitle = result.getName();
    //final String speakerNames = "SessionsQuery.SPEAKER_NAMES";
    //final String sessionAbstract = "SessionsQuery.ABSTRACT";
    //final long sessionStart = 44454544;
    //final long sessionEnd = 334343433;
    //final String roomName = "SessionsQuery.ROOM_NAME";
    int sessionColor = 0;
    sessionColor = sessionColor == 0 ? getResources().getColor(R.color.transparent) : sessionColor;
    //final String snippet = "SessionsQuery.SNIPPET";
    final Spannable styledSnippet = null;
    final boolean starred = false;
    //final String[] tags = "A,B,C".split(",");

    // now let's compute a few pieces of information from the data, which we will use
    // later to decide what to render where
    final boolean hasLivestream = false;
    final long now = UIUtils.getCurrentTime(context);
    final boolean happeningNow = false;

    // text that says "LIVE" if session is live, or empty if session is not live
    //final String liveNowText =  "";

    // get reference to all the views in the layout we will need
    final TextView titleView = (TextView) view.findViewById(R.id.session_title);
    final TextView subtitleView = (TextView) view.findViewById(R.id.session_subtitle);
    final TextView shortSubtitleView = (TextView) view.findViewById(R.id.session_subtitle_short);
    final TextView snippetView = (TextView) view.findViewById(R.id.session_snippet);
    //final TextView abstractView = (TextView) view.findViewById(R.id.session_abstract);
    //final TextView categoryView = (TextView) view.findViewById(R.id.session_category);
    final View boxView = view.findViewById(R.id.info_box);
    final View sessionTargetView = view.findViewById(R.id.session_target);

    if (sessionColor == 0) {
        // use default
        sessionColor = getResources().getColor(R.color.transparent);
    }
    sessionColor = UIUtils.scaleSessionColorToDefaultBG(sessionColor);

    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
        photoView.setColorFilter(UIUtils.setColorAlpha(sessionColor, UIUtils.SESSION_PHOTO_SCRIM_ALPHA));
    } else {
        photoView = (ImageView) view.findViewById(R.id.session_photo);
    }
    ((BaseActivity) getActivity()).getLPreviewUtils().setViewName(photoView, "photo_" + sessionId);

    // 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(sessionColor);
    } else {
        photoView.setBackgroundColor(sessionColor);
    }

    String photo = result.getPhotoUrl();
    if (!TextUtils.isEmpty(photo)) {
        mImageLoader.loadImage(photo, photoView, true /*crop*/);
    } else {
        // cleaning the (potentially) recycled photoView, in case this session has no photo:
        photoView.setImageDrawable(null);
    }

    // render title
    titleView.setText(sessionTitle == null ? "?" : sessionTitle);

    // render subtitle into either the subtitle view, or the short subtitle view, as available
    if (subtitleView != null) {
        subtitleView.setText(result.getAddress());
    } else if (shortSubtitleView != null) {
        shortSubtitleView.setText(result.getAddress());
    }

    // render category
    //        if (categoryView != null) {
    //            TagMetadata.Tag groupTag = mTagMetadata.getSessionGroupTag(tags);
    //            if (groupTag != null && !Config.Tags.SESSIONS.equals(groupTag.getId())) {
    //                categoryView.setText(groupTag.getName());
    //                categoryView.setVisibility(View.VISIBLE);
    //            } else {
    //                categoryView.setVisibility(View.GONE);
    //            }
    //        }

    // if a snippet view is available, render the session snippet there.
    if (snippetView != null) {
        //if (mIsSearchCursor) {
        // render the search snippet into the snippet view
        snippetView.setText(styledSnippet);
        //            } else {
        //                // render speaker names and abstracts into the snippet view
        //                mBuffer.setLength(0);
        //                if (!TextUtils.isEmpty(speakerNames)) {
        //                    mBuffer.append(speakerNames).append(". ");
        //                }
        //                if (!TextUtils.isEmpty(sessionAbstract)) {
        //                    mBuffer.append(sessionAbstract);
        //                }
        //                snippetView.setText(mBuffer.toString());
        //            }
    }

    //        if (abstractView != null && !mIsSearchCursor) {
    //            // render speaker names and abstracts into the abstract view
    //            mBuffer.setLength(0);
    //            if (!TextUtils.isEmpty(speakerNames)) {
    //                mBuffer.append(speakerNames).append("\n\n");
    //            }
    //            if (!TextUtils.isEmpty(sessionAbstract)) {
    //                mBuffer.append(sessionAbstract);
    //            }
    //            abstractView.setText(mBuffer.toString());
    //        }

    // in expanded mode, the box background color follows the session color
    //if (useExpandedMode()) {
    boxView.setBackgroundColor(sessionColor);
    //}

    // show or hide the "in my schedule" indicator
    view.findViewById(R.id.indicator_in_schedule).setVisibility(starred ? View.VISIBLE : View.INVISIBLE);

    // if we are in condensed mode and this card is the hero card (big card at the top
    // of the screen), set up the message card if necessary.
    if (groupId == HERO_GROUP_ID) {
        // this is the hero view, so we might want to show a message card
        final boolean cardShown = setupMessageCard(view);

        // if this is the wide hero layout, show or hide the card or the session abstract
        // view, as appropriate (they are mutually exclusive).
        final View cardContainer = view.findViewById(R.id.message_card_container_wide);
        final View abstractContainer = view.findViewById(R.id.session_abstract);
        if (cardContainer != null && abstractContainer != null) {
            cardContainer.setVisibility(cardShown ? View.VISIBLE : View.GONE);
            abstractContainer.setVisibility(cardShown ? View.GONE : View.VISIBLE);
            abstractContainer.setBackgroundColor(sessionColor);
        }
    }

    // if this session is live right now, display the "LIVE NOW" icon on top of it
    View liveNowBadge = view.findViewById(R.id.live_now_badge);
    if (liveNowBadge != null) {
        liveNowBadge.setVisibility(happeningNow && hasLivestream ? View.VISIBLE : View.GONE);
    }

    // if this view is clicked, open the session details view
    final View finalPhotoView = photoView;
    sessionTargetView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mCallbacks.onSessionSelected(sessionId, finalPhotoView);
        }
    });

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