Java Code Examples for android.view.View.resolveSizeAndState()

The following are Jave code examples for showing how to use resolveSizeAndState() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: hella-renderscript   File: FixedAspectSurfaceView.java   Source Code and License Vote up 5 votes
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    int width = MeasureSpec.getSize(widthMeasureSpec);
    int height = MeasureSpec.getSize(heightMeasureSpec);

    // General goal: Adjust dimensions to maintain the requested aspect ratio as much
    // as possible. Depending on the measure specs handed down, this may not be possible

    // Only set one of these to true
    boolean scaleWidth = false;
    boolean scaleHeight = false;

    // Sort out which dimension to scale, if either can be. There are 9 combinations of
    // possible measure specs; a few cases below handle multiple combinations
    if (widthMode == MeasureSpec.EXACTLY && heightMode == MeasureSpec.EXACTLY) {
        // Can't adjust sizes at all, do nothing
    } else if (widthMode == MeasureSpec.EXACTLY) {
        // Width is fixed, heightMode either AT_MOST or UNSPECIFIED, so adjust height
        scaleHeight = true;
    } else if (heightMode == MeasureSpec.EXACTLY) {
        // Height is fixed, widthMode either AT_MOST or UNSPECIFIED, so adjust width
        scaleWidth = true;
    } else if (widthMode == MeasureSpec.AT_MOST && heightMode == MeasureSpec.AT_MOST) {
        // Need to fit into box <= [width, height] in size.
        // Maximize the View's area while maintaining aspect ratio
        // This means keeping one dimension as large as possible and shrinking the other
        float boxAspectRatio = width / (float) height;
        if (boxAspectRatio > mAspectRatio) {
            // Box is wider than requested aspect; pillarbox
            scaleWidth = true;
        } else {
            // Box is narrower than requested aspect; letterbox
            scaleHeight = true;
        }
    } else if (widthMode == MeasureSpec.AT_MOST) {
        // Maximize width, heightSpec is UNSPECIFIED
        scaleHeight = true;
    } else if (heightMode == MeasureSpec.AT_MOST) {
        // Maximize height, widthSpec is UNSPECIFIED
        scaleWidth = true;
    } else {
        // Both MeasureSpecs are UNSPECIFIED. This is probably a pathological layout,
        // with width == height == 0
        // but arbitrarily scale height anyway
        scaleHeight = true;
    }

    // Do the scaling
    if (scaleWidth) {
        width = (int) (height * mAspectRatio);
    } else if (scaleHeight) {
        height = (int) (width / mAspectRatio);
    }

    // Override width/height if needed for EXACTLY and AT_MOST specs
    width = View.resolveSizeAndState(width, widthMeasureSpec, 0);
    height = View.resolveSizeAndState(height, heightMeasureSpec, 0);

    // Finally set the calculated dimensions
    setMeasuredDimension(width, height);
}
 
Example 2
Project: CSipSimple   File: Utility11.java   Source Code and License Vote up 4 votes
@Override
public int resolveSizeAndState(int size, int measureSpec, int state) {
    return View.resolveSizeAndState(size, measureSpec, state);
}
 
Example 3
Project: letv   File: ViewCompatHC.java   Source Code and License Vote up 4 votes
public static int resolveSizeAndState(int size, int measureSpec, int childMeasuredState) {
    return View.resolveSizeAndState(size, measureSpec, childMeasuredState);
}
 
Example 4
Project: boohee_v5.6   File: ViewCompatHC.java   Source Code and License Vote up 4 votes
public static int resolveSizeAndState(int size, int measureSpec, int childMeasuredState) {
    return View.resolveSizeAndState(size, measureSpec, childMeasuredState);
}