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.umeng.common.ui.adapters.ImagePagerAdapter.java

/**
 * ?imagewrap_content,match_parent250</br>
 * //from   w  w w  .j  av  a  2  s. c  o  m
 * @param imageView
 * @return
 */
private Point getSize(ImageView imageView) {
    Point size = new Point();
    if (imageView.getWidth() > 0) {
        size.x = imageView.getWidth();
        size.y = imageView.getHeight();
    } else {
        size.x = size.y = 500;
    }
    return size;
}

From source file:nz.ac.otago.psyanlab.common.util.BitmapCache.java

/**
 * Prepares parameters for loading a bitmap into the cache. The parameters
 * are themselves cached so many ImageViews can be run through generating
 * only one set of parameters to fit all ImageViews using the same image.
 * //from w  ww.  j a v a2s  . c  o  m
 * @param path
 *            Path to bitmap.
 * @param imageView
 *            ImageView to use the bitmap.
 * @return
 */
public BitmapParams prepareBitmapParams(String path, ImageView imageView) {
    BitmapParams param = map.get(path);
    if (param == null) {
        param = new BitmapParams(path, imageView.getWidth(), imageView.getHeight());
        map.put(path, param);
    } else {
        if (param.height < imageView.getHeight()) {
            param.height = imageView.getHeight();
        }
        if (param.width < imageView.getWidth()) {
            param.width = imageView.getWidth();
        }
    }

    return param;
}

From source file:camera.AnotherCamera.java

/**
 * Scale the photo down and fit it to our image views.
 *
 * "Drastically increases performance" to set images using this technique.
 * Read more:http://developer.android.com/training/camera/photobasics.html
 *///w w  w . ja  v a  2 s . com
private void setFullImageFromFilePath(String imagePath, ImageView imageView) {
    // Get the dimensions of the View
    int targetW = imageView.getWidth();
    int targetH = imageView.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;

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

From source file:eu.liveGov.libraries.livegovtoolkit.activities_fragments.DetailFragment.java

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

    _progressBar = (ProgressBar) view.findViewById(R.id.detailsProgressBar);

    if (_proposalObject != null) {
        ImageView thumb = (ImageView) view.findViewById(R.id.detailsThumbnail);
        int width = thumb.getWidth();
        int height = thumb.getWidth();

        thumb.setImageBitmap(_proposalObject.get_image(width, height));

        ((TextView) view.findViewById(R.id.detailsTvDescription)).setText(_proposalObject.get_description());
        ((TextView) view.findViewById(R.id.detailstvTitle)).setText(_proposalObject.get_title());
    }//from w ww .java2 s . com

    changeFragment(_currentFragment);

    return view;
}

From source file:nz.ac.otago.psyanlab.common.util.BitmapCache.java

public void loadBitmap(String path, ImageView imageView) {
    final BitmapPack pack = getBitmapFromMemCache(path);
    if (pack != null) {
        if (pack.sampleSize > 1 && (pack.bitmap.getWidth() < imageView.getWidth()
                || pack.bitmap.getHeight() < imageView.getHeight())) {
            // The image was sampled before for a smaller ImageView and now
            // needs to be re-sampled for the new ImageView.
            new BitmapWorkerTask(imageView).execute(prepareBitmapParams(path, imageView));
        } else {/*from  w w  w  .  j  av a2s . c o  m*/
            imageView.setImageBitmap(pack.bitmap);
        }
    } else {
        new BitmapWorkerTask(imageView).execute(prepareBitmapParams(path, imageView));
    }
}

From source file:org.que.activities.fragments.MapImageFragment.java

/**
 * Scales the bitmap to save memory and to show the hole image in the image view.
 * //w  w  w.  ja v a 2  s  . c o  m
 * @param imageView the image view which shows the bitmap
 * @param o the bitmap options which contains the bitmap informations
 * @param btm the bitmap which should be scaled
 * @return the scaled bitmap
 */
private Bitmap scaleImage(ImageView imageView, BitmapFactory.Options o, Bitmap btm) {

    int viewWidth = imageView.getWidth();
    int viewHeight = imageView.getHeight();
    int imgWidth = o.outWidth;//bitm.getWidth();
    int imgHeight = o.outHeight;//bitm.getHeight();

    float scaleX = viewWidth / (float) imgWidth;
    float scaleY = viewHeight / (float) imgHeight;

    if (btm == null) {
        btm = BitmapFactory.decodeResource(getResources(), imgRes);
    }

    Bitmap b2 = Bitmap.createScaledBitmap(btm, (int) (scaleX * imgWidth), (int) (scaleY * imgHeight), false);
    if (btm != b2) {
        btm.recycle();
    }
    return b2;

}

From source file:com.keylesspalace.tusky.activity.MainActivity.java

private void fetchUserInfo() {
    SharedPreferences preferences = getSharedPreferences(getString(R.string.preferences_file_key),
            Context.MODE_PRIVATE);
    final String domain = preferences.getString("domain", null);
    String id = preferences.getString("loggedInAccountId", null);
    String username = preferences.getString("loggedInAccountUsername", null);

    if (id != null && username != null) {
        loggedInAccountId = id;/*from ww  w. j  av a  2  s .  co  m*/
        loggedInAccountUsername = username;
    }

    mastodonAPI.accountVerifyCredentials().enqueue(new Callback<Account>() {
        @Override
        public void onResponse(Call<Account> call, Response<Account> response) {
            if (!response.isSuccessful()) {
                onFetchUserInfoFailure(new Exception(response.message()));
                return;
            }

            Account me = response.body();
            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();
            }

            Picasso.with(MainActivity.this).load(me.header).placeholder(R.drawable.account_header_missing)
                    .resize(backgroundWidth, backgroundHeight).centerCrop().into(background);

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

            onFetchUserInfoSuccess(me.id, me.username);
        }

        @Override
        public void onFailure(Call<Account> call, Throwable t) {
            onFetchUserInfoFailure((Exception) t);
        }
    });
}

From source file:eu.liveGov.libraries.livegovtoolkit.activities_fragments.MapFragment.java

private void SetPopup(OverlayItem item) {
    if (item == null) {
        if (_popupView != null) {
            mOsmv.removeView(_popupView);
            mOsmv.setOnClickListener(null);
            mOsmv.setClickable(false);//  ww w  .  j a  va  2  s . c  o  m
        }
    } else {
        mOsmv.setOnClickListener(outsideClick);
        if (_popupView == null) {
            _popupView = getLayoutInflater(new Bundle()).inflate(R.layout.map_itempopup, mOsmv, false);

            ImageButton imbClose = (ImageButton) _popupView.findViewById(R.id.imbInfoClose);
            imbClose.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    mOsmv.removeView(_popupView);
                }
            });

            _popupView.setOnClickListener(this);
        }
        mOsmv.removeView(_popupView);
        _popupView.setTag(item.getUid());
        TextView tv = (TextView) _popupView.findViewById(R.id.map_popup_title);

        tv.setText(item.getTitle());
        tv.setTag(item.getUid());
        TextView dv = (TextView) _popupView.findViewById(R.id.map_popup_description);
        dv.setText(item.getSnippet());
        dv.setTag(item.getUid());

        ImageView iv = (ImageView) _popupView.findViewById(R.id.map_popup_Thumbnail);

        ProposalObject proposalObject = ProposalHelper.getProposalById(Integer.parseInt(item.getUid()));

        iv.setImageBitmap(proposalObject.get_image(iv.getWidth() / 2, iv.getHeight() / 2));

        MapView.LayoutParams mapParams = new MapView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, item.getPoint(), MapView.LayoutParams.BOTTOM_CENTER, 0, 0);

        mOsmv.addView(_popupView, mapParams);
    }

}

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//from   w  w w  . j  a va  2 s .  c  o m
        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:net.maa123.tatuky.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();/*from w w w.j a  v  a2  s  .  co m*/

    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));

    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();
}