Example usage for android.graphics.drawable NinePatchDrawable getIntrinsicWidth

List of usage examples for android.graphics.drawable NinePatchDrawable getIntrinsicWidth

Introduction

In this page you can find the example usage for android.graphics.drawable NinePatchDrawable getIntrinsicWidth.

Prototype

@Override
    public int getIntrinsicWidth() 

Source Link

Usage

From source file:com.google.blockly.android.ui.vertical.PatchManager.java

/**
 * Compute layout measures such as offsets and paddings from the various block patches.
 *//* www .  j av a 2  s  . c  o  m*/
private void computePatchLayoutMeasures(boolean rtl, boolean useHat) {
    final Configuration config = mResources.getConfiguration();

    if (!getPatchDrawable(R.drawable.top_start_default).getPadding(mTempRect)) {
        throw new IllegalStateException("9-patch 'top_start_default' does not have padding.");
    }
    mBlockStartPadding = rtl ? mTempRect.right : mTempRect.left;

    mBlockEndPadding = getPatchDrawable(R.drawable.dummy_input).getIntrinsicWidth();
    mValueInputWidth = getPatchDrawable(R.drawable.value_input_external).getIntrinsicWidth() - mBlockEndPadding;

    final NinePatchDrawable bottomPatchDefault = getPatchDrawable(R.drawable.bottom_start_default);
    if (!bottomPatchDefault.getPadding(mTempRect)) {
        throw new IllegalStateException("9-patch 'bottom_start_default' does not have padding.");
    }
    mBlockBottomPadding = mTempRect.bottom;

    final NinePatchDrawable bottomPatchNext = getPatchDrawable(R.drawable.bottom_start_next);
    if (!bottomPatchNext.getPadding(mTempRect)) {
        throw new IllegalStateException("9-patch 'bottom_start_next' does not have padding.");
    }
    mNextConnectorHeight = mTempRect.bottom - mBlockBottomPadding;

    final NinePatchDrawable topLeftDefaultPatch = getPatchDrawable(
            useHat ? R.drawable.top_start_hat : R.drawable.top_start_default);
    if (!topLeftDefaultPatch.getPadding(mTempRect)) {
        throw new IllegalStateException("9-patch 'top_start_default' does not have padding.");
    }
    ;
    mBlockTopDefaultPadding = mTempRect.top;

    final NinePatchDrawable topLeftPreviousPatch = getPatchDrawable(R.drawable.top_start_previous);
    if (!topLeftPreviousPatch.getPadding(mTempRect)) {
        throw new IllegalStateException("9-patch 'top_start_previous' does not have padding.");
    }
    ;
    mBlockTopPreviousPadding = mTempRect.top;

    final NinePatchDrawable topLeftOutputPatch = getPatchDrawable(R.drawable.top_start_output);
    if (!topLeftOutputPatch.getPadding(mTempRect)) {
        throw new IllegalStateException("9-patch 'top_start_output' does not have padding.");
    }
    ;
    mBlockTopOutputPadding = mTempRect.top;
    mOutputConnectorWidth = (rtl ? mTempRect.right : mTempRect.left) - mBlockStartPadding;
    mOutputConnectorHeight = topLeftOutputPatch.getIntrinsicHeight();

    mBlockTopMinPadding = Math.min(mBlockTopDefaultPadding,
            Math.min(mBlockTopOutputPadding, mBlockTopPreviousPadding));

    // Block height must be sufficient to at least accommodate vertical padding and an Output
    // connector.
    mMinBlockHeight = mBlockTopMinPadding + mOutputConnectorHeight + mBlockBottomPadding;

    final NinePatchDrawable statementTopPatch = getPatchDrawable(R.drawable.statementinput_top);
    if (!statementTopPatch.getPadding(mTempRect)) {
        throw new IllegalStateException("9-patch 'statementinput_top' does not have padding.");
    }
    ;
    mStatementTopThickness = mTempRect.top;
    mStatementInputIndent = statementTopPatch.getIntrinsicWidth();
    mStatementInputPadding = rtl ? mTempRect.right : mTempRect.left;

    final NinePatchDrawable statementBottomPatch = getPatchDrawable(R.drawable.statementinput_bottom);
    if (!statementBottomPatch.getPadding(mTempRect)) {
        throw new IllegalStateException("9-patch 'statementinput_bottom' does not have padding.");
    }
    mStatementBottomThickness = mTempRect.bottom;

    mStatementMinHeight = statementTopPatch.getIntrinsicHeight() + statementBottomPatch.getIntrinsicHeight();

    final NinePatchDrawable inlineInputPatch = getPatchDrawable(R.drawable.value_input_inline);
    mInlineInputMinimumWidth = inlineInputPatch.getIntrinsicWidth();
    mInlineInputMinimumHeight = inlineInputPatch.getIntrinsicHeight();

    inlineInputPatch.getPadding(mTempRect);
    mInlineInputStartPadding = rtl ? mTempRect.right : mTempRect.left;
    mInlineInputTopPadding = mTempRect.top;
    mInlineInputTotalPaddingX = mTempRect.left + mTempRect.right;
    mInlineInputTotalPaddingY = mTempRect.top + mTempRect.bottom;

    // Convenience fields.
    mBlockTotalPaddingX = mBlockStartPadding + mBlockEndPadding;
}