Java Code Examples for android.widget.ImageView#getMaxHeight()

The following examples show how to use android.widget.ImageView#getMaxHeight() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: candybar   File: ImageViewAware.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 * <br />
 * 3) Get <b>maxHeight</b>
 */
@Override
public int getHeight() {
    int height = super.getHeight();
    if (height <= 0) {
        ImageView imageView = (ImageView) viewRef.get();
        if (imageView != null) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                height = imageView.getMaxHeight();
            } else {
                height = getImageViewFieldValue(imageView, "mMaxHeight"); // Check maxHeight parameter
            }
        }
    }
    return height;
}
 
Example 2
Source Project: android-testdpc   File: Util.java    License: Apache License 2.0 6 votes vote down vote up
public static void updateImageView(Context context, ImageView imageView, Uri uri) {
    try {
        InputStream inputStream = context.getContentResolver().openInputStream(uri);
        // Avoid decoding the entire image if the imageView holding this image is smaller.
        BitmapFactory.Options bounds = new BitmapFactory.Options();
        bounds.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(inputStream, null, bounds);
        int streamWidth = bounds.outWidth;
        int streamHeight = bounds.outHeight;
        int maxDesiredWidth = imageView.getMaxWidth();
        int maxDesiredHeight = imageView.getMaxHeight();
        int ratio = Math.max(streamWidth / maxDesiredWidth, streamHeight / maxDesiredHeight);
        if (ratio > 1) {
            bounds.inSampleSize = ratio;
        }
        bounds.inJustDecodeBounds = false;

        inputStream = context.getContentResolver().openInputStream(uri);
        imageView.setImageBitmap(BitmapFactory.decodeStream(inputStream, null, bounds));
    } catch (FileNotFoundException e) {
        Toast.makeText(context, R.string.error_opening_image_file, Toast.LENGTH_SHORT);
    }
}
 
Example 3
Source Project: DevUtils   File: ImageViewUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 获取 ImageView 最大高度
 * @param imageView ImageView
 * @return view 最大高度
 */
@RequiresApi(Build.VERSION_CODES.JELLY_BEAN)
public static int getMaxHeight(final ImageView imageView) {
    if (imageView != null) {
        return imageView.getMaxHeight();
    }
    return -1;
}
 
Example 4
Source Project: cosu   File: LockedActivity.java    License: Apache License 2.0 4 votes vote down vote up
private void setImageToView(){
    // Restore preferences
    SharedPreferences settings = getSharedPreferences(PREFS_FILE_NAME, 0);
    String savedPhotoPath = settings.getString(PHOTO_PATH, null);

    //Initialize the image view and display the picture if one exists
    imageView = (ImageView) findViewById(R.id.lock_imageView);
    Intent intent = getIntent();

    String passedPhotoPath = intent.getStringExtra(
            MainActivity.EXTRA_FILEPATH);
    if (passedPhotoPath != null) {
        mCurrentPhotoPath = passedPhotoPath;
    } else {
        mCurrentPhotoPath = savedPhotoPath;
    }

    if (mCurrentPhotoPath != null) {
        int targetH = imageView.getMaxHeight();
        int targetW = imageView.getMaxWidth();

        // Get the dimensions of the bitmap

        BitmapFactory.Options bmOptions = new BitmapFactory.Options();
        bmOptions.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
        int photoH = bmOptions.outHeight;
        int photoW = bmOptions.outWidth;

        // Determine how much to scale down 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;

        Bitmap imageBitmap = BitmapFactory.decodeFile(mCurrentPhotoPath,
                bmOptions);
        imageView.setImageBitmap(imageBitmap);
    }
}
 
Example 5
Source Project: cosu   File: LockedActivity.java    License: Apache License 2.0 4 votes vote down vote up
private void setImageToView(){

        // Restore preferences
        SharedPreferences settings = getSharedPreferences(PREFS_FILE_NAME, 0);
        String savedPhotoPath = settings.getString(PHOTO_PATH, null);

        //Initialize the image view and display the picture if one exists
        imageView = (ImageView) findViewById(R.id.lock_imageView);
        Intent intent = getIntent();

        String passedPhotoPath = intent.getStringExtra(
                MainActivity.EXTRA_FILEPATH);
        if (passedPhotoPath != null) {
            mCurrentPhotoPath = passedPhotoPath;
        } else {
            mCurrentPhotoPath = savedPhotoPath;
        }

        if (mCurrentPhotoPath != null) {
            int targetH = imageView.getMaxHeight();
            int targetW = imageView.getMaxWidth();

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

            // Determine how much to scale down 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;

            Bitmap imageBitmap = BitmapFactory.decodeFile(mCurrentPhotoPath,
                    bmOptions);
            imageView.setImageBitmap(imageBitmap);
        }
    }