Example usage for android.util TypedValue TYPE_NULL

List of usage examples for android.util TypedValue TYPE_NULL

Introduction

In this page you can find the example usage for android.util TypedValue TYPE_NULL.

Prototype

int TYPE_NULL

To view the source code for android.util TypedValue TYPE_NULL.

Click Source Link

Document

The value contains no data.

Usage

From source file:nya.miku.wishmaster.ui.presentation.ThemeUtils.java

private static void resolveAttribute(Theme theme, int attrId, TypedValue outValue, boolean resolveRefs) {
    if (!theme.resolveAttribute(attrId, outValue, resolveRefs))
        outValue.type = TypedValue.TYPE_NULL;
}

From source file:com.nttec.everychan.ui.theme.ThemeUtils.java

private static void resolveAttribute(Theme theme, int attrId, TypedValue outValue, boolean resolveRefs) {
    if (CustomThemeHelper.resolveAttribute(attrId, outValue))
        return;//from w  w w  .j ava 2 s. c o m
    if (!theme.resolveAttribute(attrId, outValue, resolveRefs))
        outValue.type = TypedValue.TYPE_NULL;
}

From source file:com.actionbarsherlock.internal.widget.FakeDialogPhoneWindow.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    final DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
    final boolean isPortrait = metrics.widthPixels < metrics.heightPixels;

    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    int width = getMeasuredWidth();
    boolean measure = false;

    widthMeasureSpec = MeasureSpec.makeMeasureSpec(width, EXACTLY);

    final TypedValue tv = isPortrait ? mMinWidthMinor : mMinWidthMajor;

    if (tv.type != TypedValue.TYPE_NULL) {
        final int min;
        if (tv.type == TypedValue.TYPE_DIMENSION) {
            min = (int) tv.getDimension(metrics);
        } else if (tv.type == TypedValue.TYPE_FRACTION) {
            min = (int) tv.getFraction(metrics.widthPixels, metrics.widthPixels);
        } else {//from  w w  w.j  a v a2  s .c  o  m
            min = 0;
        }

        if (width < min) {
            widthMeasureSpec = MeasureSpec.makeMeasureSpec(min, EXACTLY);
            measure = true;
        }
    }

    // TODO: Support height?

    if (measure) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}

From source file:com.hippo.conductor.dialog.DialogContentView.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    final boolean isPortrait = getResources()
            .getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
    final TypedValue tv = isPortrait ? minWidthMinor : minWidthMajor;
    boolean measure = false;

    if (widthMode == MeasureSpec.AT_MOST && tv.type != TypedValue.TYPE_NULL) {
        final int min;
        final DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
        if (tv.type == TypedValue.TYPE_DIMENSION) {
            min = (int) tv.getDimension(metrics);
        } else if (tv.type == TypedValue.TYPE_FRACTION) {
            min = (int) tv.getFraction(metrics.widthPixels, metrics.widthPixels);
        } else {// w w w  .  j  a v a 2s  . co  m
            min = 0;
        }

        if (getMeasuredWidth() < min) {
            widthMeasureSpec = MeasureSpec.makeMeasureSpec(min, MeasureSpec.EXACTLY);
            measure = true;
        }
    }

    if (measure) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}

From source file:android.support.v7ox.widget.ContentFrameLayout.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    final DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
    final boolean isPortrait = metrics.widthPixels < metrics.heightPixels;

    final int widthMode = getMode(widthMeasureSpec);
    final int heightMode = getMode(heightMeasureSpec);

    boolean fixedWidth = false;
    if (widthMode == AT_MOST) {
        final TypedValue tvw = isPortrait ? mFixedWidthMinor : mFixedWidthMajor;
        if (tvw != null && tvw.type != TypedValue.TYPE_NULL) {
            int w = 0;
            if (tvw.type == TypedValue.TYPE_DIMENSION) {
                w = (int) tvw.getDimension(metrics);
            } else if (tvw.type == TypedValue.TYPE_FRACTION) {
                w = (int) tvw.getFraction(metrics.widthPixels, metrics.widthPixels);
            }//from w  w w  .ja  v  a  2 s.  c  o  m
            if (w > 0) {
                w -= (mDecorPadding.left + mDecorPadding.right);
                final int widthSize = MeasureSpec.getSize(widthMeasureSpec);
                widthMeasureSpec = MeasureSpec.makeMeasureSpec(Math.min(w, widthSize), EXACTLY);
                fixedWidth = true;
            }
        }
    }

    if (heightMode == AT_MOST) {
        final TypedValue tvh = isPortrait ? mFixedHeightMajor : mFixedHeightMinor;
        if (tvh != null && tvh.type != TypedValue.TYPE_NULL) {
            int h = 0;
            if (tvh.type == TypedValue.TYPE_DIMENSION) {
                h = (int) tvh.getDimension(metrics);
            } else if (tvh.type == TypedValue.TYPE_FRACTION) {
                h = (int) tvh.getFraction(metrics.heightPixels, metrics.heightPixels);
            }
            if (h > 0) {
                h -= (mDecorPadding.top + mDecorPadding.bottom);
                final int heightSize = MeasureSpec.getSize(heightMeasureSpec);
                heightMeasureSpec = MeasureSpec.makeMeasureSpec(Math.min(h, heightSize), EXACTLY);
            }
        }
    }

    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    int width = getMeasuredWidth();
    boolean measure = false;

    widthMeasureSpec = MeasureSpec.makeMeasureSpec(width, EXACTLY);

    if (!fixedWidth && widthMode == AT_MOST) {
        final TypedValue tv = isPortrait ? mMinWidthMinor : mMinWidthMajor;
        if (tv != null && tv.type != TypedValue.TYPE_NULL) {
            int min = 0;
            if (tv.type == TypedValue.TYPE_DIMENSION) {
                min = (int) tv.getDimension(metrics);
            } else if (tv.type == TypedValue.TYPE_FRACTION) {
                min = (int) tv.getFraction(metrics.widthPixels, metrics.widthPixels);
            }
            if (min > 0) {
                min -= (mDecorPadding.left + mDecorPadding.right);
            }
            if (width < min) {
                widthMeasureSpec = MeasureSpec.makeMeasureSpec(min, EXACTLY);
                measure = true;
            }
        }
    }

    if (measure) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}

From source file:com.tooltip.Tooltip.java

private View getContentView(Builder builder) {
    GradientDrawable drawable = new GradientDrawable();
    drawable.setColor(builder.mBackgroundColor);
    drawable.setCornerRadius(builder.mCornerRadius);

    int padding = (int) builder.mPadding;

    TextView textView = new TextView(builder.mContext);
    TextViewCompat.setTextAppearance(textView, builder.mTextAppearance);
    textView.setText(builder.mText);/*w  w w . j  a va2s  .  c  o  m*/
    textView.setPadding(padding, padding, padding, padding);
    textView.setLineSpacing(builder.mLineSpacingExtra, builder.mLineSpacingMultiplier);
    textView.setTypeface(builder.mTypeface, builder.mTextStyle);

    if (builder.mTextSize >= 0) {
        textView.setTextSize(TypedValue.TYPE_NULL, builder.mTextSize);
    }
    if (builder.mTextColor != null) {
        textView.setTextColor(builder.mTextColor);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        textView.setBackground(drawable);
    } else {
        //noinspection deprecation
        textView.setBackgroundDrawable(drawable);
    }

    LinearLayout.LayoutParams textViewParams = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0);
    textViewParams.gravity = Gravity.CENTER;
    textView.setLayoutParams(textViewParams);

    mArrowView = new ImageView(builder.mContext);
    mArrowView.setImageDrawable(builder.mArrowDrawable);

    LinearLayout.LayoutParams arrowLayoutParams;
    if (mGravity == Gravity.TOP || mGravity == Gravity.BOTTOM) {
        arrowLayoutParams = new LinearLayout.LayoutParams((int) builder.mArrowWidth, (int) builder.mArrowHeight,
                0);
    } else {
        arrowLayoutParams = new LinearLayout.LayoutParams((int) builder.mArrowHeight, (int) builder.mArrowWidth,
                0);
    }
    arrowLayoutParams.gravity = Gravity.CENTER;
    mArrowView.setLayoutParams(arrowLayoutParams);

    mContentView = new LinearLayout(builder.mContext);
    mContentView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    mContentView.setOrientation(mGravity == Gravity.START || mGravity == Gravity.END ? LinearLayout.HORIZONTAL
            : LinearLayout.VERTICAL);

    padding = (int) Util.dpToPx(5);

    switch (mGravity) {
    case Gravity.START:
        mContentView.setPadding(0, 0, padding, 0);
        break;
    case Gravity.TOP:
    case Gravity.BOTTOM:
        mContentView.setPadding(padding, 0, padding, 0);
        break;
    case Gravity.END:
        mContentView.setPadding(padding, 0, 0, 0);
        break;
    }

    if (mGravity == Gravity.TOP || mGravity == Gravity.START) {
        mContentView.addView(textView);
        mContentView.addView(mArrowView);
    } else {
        mContentView.addView(mArrowView);
        mContentView.addView(textView);
    }

    mContentView.setOnClickListener(mClickListener);
    mContentView.setOnLongClickListener(mLongClickListener);

    if (builder.isCancelable || builder.isDismissOnClick) {
        mContentView.setOnTouchListener(mTouchListener);
    }
    return mContentView;
}

From source file:android.support.v7.app.AppCompatDelegateImplV7.java

private void applyFixedSizeWindow() {
    TypedArray a = mContext.obtainStyledAttributes(R.styleable.Theme);

    TypedValue mFixedWidthMajor = null;/*from   w ww .j  ava  2s . c  o m*/
    TypedValue mFixedWidthMinor = null;
    TypedValue mFixedHeightMajor = null;
    TypedValue mFixedHeightMinor = null;

    if (a.hasValue(R.styleable.Theme_windowFixedWidthMajor)) {
        if (mFixedWidthMajor == null)
            mFixedWidthMajor = new TypedValue();
        a.getValue(R.styleable.Theme_windowFixedWidthMajor, mFixedWidthMajor);
    }
    if (a.hasValue(R.styleable.Theme_windowFixedWidthMinor)) {
        if (mFixedWidthMinor == null)
            mFixedWidthMinor = new TypedValue();
        a.getValue(R.styleable.Theme_windowFixedWidthMinor, mFixedWidthMinor);
    }
    if (a.hasValue(R.styleable.Theme_windowFixedHeightMajor)) {
        if (mFixedHeightMajor == null)
            mFixedHeightMajor = new TypedValue();
        a.getValue(R.styleable.Theme_windowFixedHeightMajor, mFixedHeightMajor);
    }
    if (a.hasValue(R.styleable.Theme_windowFixedHeightMinor)) {
        if (mFixedHeightMinor == null)
            mFixedHeightMinor = new TypedValue();
        a.getValue(R.styleable.Theme_windowFixedHeightMinor, mFixedHeightMinor);
    }

    final DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
    final boolean isPortrait = metrics.widthPixels < metrics.heightPixels;
    int w = ViewGroup.LayoutParams.MATCH_PARENT;
    int h = ViewGroup.LayoutParams.MATCH_PARENT;

    final TypedValue tvw = isPortrait ? mFixedWidthMinor : mFixedWidthMajor;
    if (tvw != null && tvw.type != TypedValue.TYPE_NULL) {
        if (tvw.type == TypedValue.TYPE_DIMENSION) {
            w = (int) tvw.getDimension(metrics);
        } else if (tvw.type == TypedValue.TYPE_FRACTION) {
            w = (int) tvw.getFraction(metrics.widthPixels, metrics.widthPixels);
        }
    }

    final TypedValue tvh = isPortrait ? mFixedHeightMajor : mFixedHeightMinor;
    if (tvh != null && tvh.type != TypedValue.TYPE_NULL) {
        if (tvh.type == TypedValue.TYPE_DIMENSION) {
            h = (int) tvh.getDimension(metrics);
        } else if (tvh.type == TypedValue.TYPE_FRACTION) {
            h = (int) tvh.getFraction(metrics.heightPixels, metrics.heightPixels);
        }
    }

    if (w != ViewGroup.LayoutParams.MATCH_PARENT || h != ViewGroup.LayoutParams.MATCH_PARENT) {
        mWindow.setLayout(w, h);
    }

    a.recycle();
}