Example usage for android.content.res TypedArray getDimension

List of usage examples for android.content.res TypedArray getDimension

Introduction

In this page you can find the example usage for android.content.res TypedArray getDimension.

Prototype

public float getDimension(@StyleableRes int index, float defValue) 

Source Link

Document

Retrieve a dimensional unit attribute at index.

Usage

From source file:com.github.omadahealth.slidepager.lib.views.ProgressView.java

/**
 * Loads the styles and attributes defined in the xml tag of this class
 *
 * @param attributes The attributes to read from, do not pass {@link AttributeSet} as inflation needs the context of the {@link android.support.v4.view.PagerAdapter}
 *///from www . j  a  v  a2 s.  c  o m
public ProgressView loadStyledAttributes(TypedArray attributes, ProgressAttr progress) {
    mAttributes = attributes;
    mProgressAttr = progress;

    mIsSpecial = progress != null && progress.isSpecial();
    mIsFuture = progress != null && progress.isFuture();
    mCompletedDrawable = progress == null ? null : progress.getCompletedDrawable();

    Resources res = getContext().getResources();
    if (attributes != null) {
        mShowStreaks = attributes.getBoolean(R.styleable.SlidePager_slide_show_streaks, true);
        mShowProgressText = attributes.getBoolean(R.styleable.SlidePager_slide_show_progress_text, true);
        mShowProgressPlusMark = attributes.getBoolean(R.styleable.SlidePager_slide_show_progress_plusmark,
                true);
        mHasToReanimate = mAttributes.getBoolean(R.styleable.SlidePager_slide_pager_reanimate_slide_view, true);

        mCompletedColor = progress != null && progress.getCompletedColor() != null
                ? progress.getCompletedColor()
                : attributes.getColor(R.styleable.SlidePager_slide_progress_completed_reach_color,
                        res.getColor(R.color.default_progress_completed_reach_color));

        mCompletedFillColor = progress != null && progress.getCompletedFillColor() != null
                ? progress.getCompletedFillColor()
                : attributes.getColor(R.styleable.SlidePager_slide_progress_completed_fill_color,
                        res.getColor(R.color.default_progress_completed_fill_color));

        mNotCompletedReachColor = progress != null && progress.getReachedColor() != null
                ? progress.getReachedColor()
                : attributes.getColor(R.styleable.SlidePager_slide_progress_not_completed_reach_color,
                        res.getColor(R.color.default_progress_not_completed_reach_color));

        mNotCompletedOutlineColor = attributes.getColor(
                R.styleable.SlidePager_slide_progress_not_completed_outline_color,
                res.getColor(R.color.default_progress_not_completed_outline_color));
        mNotCompletedOutlineSize = attributes.getDimension(
                R.styleable.SlidePager_slide_progress_not_completed_outline_size,
                res.getDimension(R.dimen.circular_bar_default_outline_width));
        mNotCompletedFutureOutlineSize = attributes.getDimension(
                R.styleable.SlidePager_slide_progress_not_completed_future_outline_size,
                res.getDimension(R.dimen.circular_bar_default_future_outline_width));
        mNotCompletedFillColor = attributes.getColor(
                R.styleable.SlidePager_slide_progress_not_completed_fill_color,
                res.getColor(R.color.default_progress_not_completed_fill_color));

        mSpecialReachColor = attributes.getColor(R.styleable.SlidePager_slide_progress_special_reach_color,
                res.getColor(R.color.default_progress_special_reach_color));
        mSpecialOutlineColor = attributes.getColor(R.styleable.SlidePager_slide_progress_special_outline_color,
                res.getColor(R.color.default_progress_special_outline_color));
        mSpecialFillColor = attributes.getColor(R.styleable.SlidePager_slide_progress_special_fill_color,
                res.getColor(R.color.default_progress_special_fill_color));

        mProgressTextColor = attributes.getColor(R.styleable.SlidePager_slide_progress_text_color,
                res.getColor(R.color.default_progress_text_color));

        mReachedWidth = attributes.getDimension(R.styleable.SlidePager_slide_progress_reached_width,
                res.getDimension(R.dimen.default_progress_reached_width));
        //Do not recycle attributes, we need them for the future views
    } else {
        mShowStreaks = true;
        mShowProgressText = true;
        mShowProgressPlusMark = true;
        mHasToReanimate = true;

        mCompletedColor = progress != null && progress.getCompletedColor() != null
                ? progress.getCompletedColor()
                : res.getColor(R.color.default_progress_completed_reach_color);
        mCompletedFillColor = res.getColor(R.color.default_progress_completed_fill_color);

        mNotCompletedReachColor = res.getColor(R.color.default_progress_not_completed_reach_color);
        mNotCompletedOutlineColor = res.getColor(R.color.default_progress_not_completed_outline_color);
        mNotCompletedOutlineSize = res.getDimension(R.dimen.circular_bar_default_outline_width);
        mNotCompletedFutureOutlineSize = res.getDimension(R.dimen.circular_bar_default_future_outline_width);
        mNotCompletedFillColor = res.getColor(R.color.default_progress_not_completed_fill_color);

        mSpecialReachColor = res.getColor(R.color.default_progress_special_reach_color);
        mSpecialOutlineColor = res.getColor(R.color.default_progress_special_outline_color);
        mSpecialFillColor = res.getColor(R.color.default_progress_special_fill_color);

        mProgressTextColor = res.getColor(R.color.default_progress_text_color);

        mReachedWidth = res.getDimension(R.dimen.default_progress_reached_width);
    }
    loadProgressTextLabels(res);

    setCircleColorsAndSize();

    initAnimations();

    return this;
}

From source file:com.bettervectordrawable.lib.graphics.drawable.VectorDrawable.java

private void updateStateFromTypedArray(TypedArray a) throws XmlPullParserException {
    final VectorDrawableState state = mVectorState;
    final VPathRenderer pathRenderer = state.mVPathRenderer;
    // Account for any configuration changes.
    state.mChangingConfigurations |= TypedArrayExtension.getChangingConfigurations(a);
    // Extract the theme attributes, if any.
    state.mThemeAttrs = extractThemeAttrs(a);
    final int tintMode = a.getInt(R.styleable.VectorDrawable_tintMode, -1);
    if (tintMode != -1) {
        state.mTintMode = parseTintMode(tintMode, Mode.SRC_IN);
    }//from w ww  .ja v  a  2  s . c o m
    final ColorStateList tint = a.getColorStateList(R.styleable.VectorDrawable_tint);
    if (tint != null) {
        state.mTint = tint;
    }
    state.mAutoMirrored = a.getBoolean(R.styleable.VectorDrawable_autoMirrored, state.mAutoMirrored);
    pathRenderer.mViewportWidth = a.getFloat(R.styleable.VectorDrawable_viewportWidth,
            pathRenderer.mViewportWidth);
    pathRenderer.mViewportHeight = a.getFloat(R.styleable.VectorDrawable_viewportHeight,
            pathRenderer.mViewportHeight);
    if (pathRenderer.mViewportWidth <= 0) {
        throw new XmlPullParserException(
                a.getPositionDescription() + "<vector> tag requires viewportWidth > 0");
    } else if (pathRenderer.mViewportHeight <= 0) {
        throw new XmlPullParserException(
                a.getPositionDescription() + "<vector> tag requires viewportHeight > 0");
    }
    pathRenderer.mBaseWidth = a.getDimension(R.styleable.VectorDrawable_android_width, pathRenderer.mBaseWidth);
    pathRenderer.mBaseHeight = a.getDimension(R.styleable.VectorDrawable_android_height,
            pathRenderer.mBaseHeight);
    if (pathRenderer.mBaseWidth <= 0) {
        throw new XmlPullParserException(a.getPositionDescription() + "<vector> tag requires width > 0");
    } else if (pathRenderer.mBaseHeight <= 0) {
        throw new XmlPullParserException(a.getPositionDescription() + "<vector> tag requires height > 0");
    }
    final int insetLeft = a.getDimensionPixelSize(R.styleable.VectorDrawable_opticalInsetLeft,
            pathRenderer.mOpticalInsets.left);
    final int insetTop = a.getDimensionPixelSize(R.styleable.VectorDrawable_opticalInsetTop,
            pathRenderer.mOpticalInsets.top);
    final int insetRight = a.getDimensionPixelSize(R.styleable.VectorDrawable_opticalInsetRight,
            pathRenderer.mOpticalInsets.right);
    final int insetBottom = a.getDimensionPixelSize(R.styleable.VectorDrawable_opticalInsetBottom,
            pathRenderer.mOpticalInsets.bottom);
    pathRenderer.mOpticalInsets = Insets.of(insetLeft, insetTop, insetRight, insetBottom);
    final float alphaInFloat = a.getFloat(R.styleable.VectorDrawable_android_alpha, pathRenderer.getAlpha());
    pathRenderer.setAlpha(alphaInFloat);
    final String name = a.getString(R.styleable.VectorDrawable_android_name);
    if (name != null) {
        pathRenderer.mRootName = name;
        pathRenderer.mVGTargetsMap.put(name, pathRenderer);
    }
}

From source file:com.john.main.VectorDrawable.java

private void updateStateFromTypedArray(TypedArray a) throws XmlPullParserException {
    final VectorDrawableState state = mVectorState;
    final VPathRenderer pathRenderer = state.mVPathRenderer;

    // Account for any configuration changes.
    state.mChangingConfigurations |= Utils.getChangingConfigurations(a);

    // Extract the theme attributes, if any.
    state.mThemeAttrs = null; // TODO THEME TINT Not supported yet a.extractThemeAttrs();

    final int tintMode = a.getInt(R.styleable.VectorDrawable_tintMode, -1);
    if (tintMode != -1) {
        state.mTintMode = Utils.parseTintMode(tintMode, DEFAULT_TINT_MODE);
    }/*from w  w  w  .j a va2 s  .  c  om*/

    final ColorStateList tint = a.getColorStateList(R.styleable.VectorDrawable_tint);
    if (tint != null) {
        state.mTint = tint;
    }

    state.mAutoMirrored = a.getBoolean(R.styleable.VectorDrawable_autoMirrored, state.mAutoMirrored);

    pathRenderer.mViewportWidth = a.getFloat(R.styleable.VectorDrawable_viewportWidth,
            pathRenderer.mViewportWidth);
    pathRenderer.mViewportHeight = a.getFloat(R.styleable.VectorDrawable_viewportHeight,
            pathRenderer.mViewportHeight);

    if (pathRenderer.mViewportWidth <= 0) {
        throw new XmlPullParserException(
                a.getPositionDescription() + "<vector> tag requires viewportWidth > 0");
    } else if (pathRenderer.mViewportHeight <= 0) {
        throw new XmlPullParserException(
                a.getPositionDescription() + "<vector> tag requires viewportHeight > 0");
    }

    pathRenderer.mBaseWidth = a.getDimension(R.styleable.VectorDrawable_width, pathRenderer.mBaseWidth);
    pathRenderer.mBaseHeight = a.getDimension(R.styleable.VectorDrawable_height, pathRenderer.mBaseHeight);

    if (pathRenderer.mBaseWidth <= 0) {
        throw new XmlPullParserException(a.getPositionDescription() + "<vector> tag requires width > 0");
    } else if (pathRenderer.mBaseHeight <= 0) {
        throw new XmlPullParserException(a.getPositionDescription() + "<vector> tag requires height > 0");
    }

    final float alphaInFloat = a.getFloat(R.styleable.VectorDrawable_alpha, pathRenderer.getAlpha());
    pathRenderer.setAlpha(alphaInFloat);

    final String name = a.getString(R.styleable.VectorDrawable_name);
    if (name != null) {
        pathRenderer.mRootName = name;
        pathRenderer.mVGTargetsMap.put(name, pathRenderer);
    }
}

From source file:com.grottworkshop.gwsvectorsandboxlib.VectorDrawable.java

private void updateStateFromTypedArray(TypedArray a) throws XmlPullParserException {
    final VectorDrawableState state = mVectorState;
    final VPathRenderer pathRenderer = state.mVPathRenderer;

    // Account for any configuration changes.
    state.mChangingConfigurations |= Utils.getChangingConfigurations(a);

    // Extract the theme attributes, if any.
    state.mThemeAttrs = null; // TODO THEME TINT Not supported yet a.extractThemeAttrs();

    final int tintMode = a.getInt(R.styleable.VectorDrawable_mv_tintMode, -1);
    if (tintMode != -1) {
        state.mTintMode = Utils.parseTintMode(tintMode, DEFAULT_TINT_MODE);
    }/* w  w  w. ja  va  2  s  .  c  o m*/

    final ColorStateList tint = a.getColorStateList(R.styleable.VectorDrawable_mv_tint);
    if (tint != null) {
        state.mTint = tint;
    }

    state.mAutoMirrored = a.getBoolean(R.styleable.VectorDrawable_mv_autoMirrored, state.mAutoMirrored);

    pathRenderer.mViewportWidth = a.getFloat(R.styleable.VectorDrawable_mv_viewportWidth,
            pathRenderer.mViewportWidth);
    pathRenderer.mViewportHeight = a.getFloat(R.styleable.VectorDrawable_mv_viewportHeight,
            pathRenderer.mViewportHeight);

    if (pathRenderer.mViewportWidth <= 0) {
        throw new XmlPullParserException(
                a.getPositionDescription() + "<vector> tag requires viewportWidth > 0");
    } else if (pathRenderer.mViewportHeight <= 0) {
        throw new XmlPullParserException(
                a.getPositionDescription() + "<vector> tag requires viewportHeight > 0");
    }

    pathRenderer.mBaseWidth = a.getDimension(R.styleable.VectorDrawable_mv_width, pathRenderer.mBaseWidth);
    pathRenderer.mBaseHeight = a.getDimension(R.styleable.VectorDrawable_mv_height, pathRenderer.mBaseHeight);

    if (pathRenderer.mBaseWidth <= 0) {
        throw new XmlPullParserException(a.getPositionDescription() + "<vector> tag requires width > 0");
    } else if (pathRenderer.mBaseHeight <= 0) {
        throw new XmlPullParserException(a.getPositionDescription() + "<vector> tag requires height > 0");
    }

    final float alphaInFloat = a.getFloat(R.styleable.VectorDrawable_mv_alpha, pathRenderer.getAlpha());
    pathRenderer.setAlpha(alphaInFloat);

    final String name = a.getString(R.styleable.VectorDrawable_mv_name);
    if (name != null) {
        pathRenderer.mRootName = name;
        pathRenderer.mVGTargetsMap.put(name, pathRenderer);
    }
}

From source file:com.yek.keyboard.anysoftkeyboard.AnySoftKeyboard.java

@Override
public void setCandidatesView(@NonNull View view) {
    super.setCandidatesView(view);
    mCandidatesParent = view.getParent() instanceof View ? (View) view.getParent() : null;

    mCandidateView = (CandidateView) view.findViewById(R.id.candidates);
    mCandidateView.setService(this);
    setCandidatesViewShown(false);/*from   www .j  a v a  2  s . c  o  m*/

    final KeyboardTheme theme = KeyboardThemeFactory.getCurrentKeyboardTheme(getApplicationContext());
    final TypedArray a = theme.getPackageContext().obtainStyledAttributes(null,
            R.styleable.AnyKeyboardViewTheme, 0, theme.getThemeResId());
    int closeTextColor = ContextCompat.getColor(this, R.color.candidate_other);
    float fontSizePixel = getResources().getDimensionPixelSize(R.dimen.candidate_font_height);
    Drawable suggestionCloseDrawable = null;
    try {
        closeTextColor = a.getColor(R.styleable.AnyKeyboardViewTheme_suggestionOthersTextColor, closeTextColor);
        fontSizePixel = a.getDimension(R.styleable.AnyKeyboardViewTheme_suggestionTextSize, fontSizePixel);
        suggestionCloseDrawable = a.getDrawable(R.styleable.AnyKeyboardViewTheme_suggestionCloseImage);
    } catch (Exception e) {
        e.printStackTrace();
    }
    a.recycle();

    // mCandidateCloseText = (TextView) view.findViewById(R.id.close_suggestions_strip_text);
    ImageView closeIcon = (ImageView) view.findViewById(R.id.close_suggestions_strip_icon);
    if (suggestionCloseDrawable != null)
        closeIcon.setImageDrawable(suggestionCloseDrawable);

    closeIcon.setOnClickListener(new OnClickListener() {
        // two seconds is enough.
        private final static long DOUBLE_TAP_TIMEOUT = 2 * 1000 - 50;

        public void onClick(View v) {
            //mKeyboardHandler.removeMessages(KeyboardUIStateHandler.MSG_REMOVE_CLOSE_SUGGESTIONS_HINT);
            // mCandidateCloseText.setVisibility(View.VISIBLE);
            // mCandidateCloseText.startAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.close_candidates_hint_in));
            //mKeyboardHandler.sendMessageDelayed(mKeyboardHandler.obtainMessage(KeyboardUIStateHandler.MSG_REMOVE_CLOSE_SUGGESTIONS_HINT), DOUBLE_TAP_TIMEOUT);
            onFunctionKey(KeyCodes.VOICE_INPUT, null, 0, null, true);

        }
    });
    /*
    mCandidateCloseText.setTextColor(closeTextColor);
    mCandidateCloseText.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSizePixel);
    mCandidateCloseText.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
        mKeyboardHandler.removeMessages(KeyboardUIStateHandler.MSG_REMOVE_CLOSE_SUGGESTIONS_HINT);
        mCandidateCloseText.setVisibility(View.GONE);
        abortCorrectionAndResetPredictionState(true);
    }
    });*/
}

From source file:com.anysoftkeyboard.AnySoftKeyboard.java

@Override
public void setCandidatesView(@NonNull View view) {
    super.setCandidatesView(view);
    mCandidatesParent = view.getParent() instanceof View ? (View) view.getParent() : null;

    mCandidateView = (CandidateView) view.findViewById(R.id.candidates);
    mCandidateView.setService(this);
    setCandidatesViewShown(false);/*from   w w  w. j  a  va2 s .  c  o m*/

    final KeyboardTheme theme = KeyboardThemeFactory.getCurrentKeyboardTheme(getApplicationContext());
    final TypedArray a = theme.getPackageContext().obtainStyledAttributes(null,
            R.styleable.AnyKeyboardViewTheme, 0, theme.getThemeResId());
    int closeTextColor = ContextCompat.getColor(this, R.color.candidate_other);
    float fontSizePixel = getResources().getDimensionPixelSize(R.dimen.candidate_font_height);
    Drawable suggestionCloseDrawable = null;
    try {
        closeTextColor = a.getColor(R.styleable.AnyKeyboardViewTheme_suggestionOthersTextColor, closeTextColor);
        fontSizePixel = a.getDimension(R.styleable.AnyKeyboardViewTheme_suggestionTextSize, fontSizePixel);
        suggestionCloseDrawable = a.getDrawable(R.styleable.AnyKeyboardViewTheme_suggestionCloseImage);
    } catch (Exception e) {
        e.printStackTrace();
    }
    a.recycle();

    mCandidateCloseText = (TextView) view.findViewById(R.id.close_suggestions_strip_text);
    ImageView closeIcon = (ImageView) view.findViewById(R.id.close_suggestions_strip_icon);
    if (suggestionCloseDrawable != null)
        closeIcon.setImageDrawable(suggestionCloseDrawable);

    closeIcon.setOnClickListener(new OnClickListener() {
        // two seconds is enough.
        private static final long DOUBLE_TAP_TIMEOUT = 2 * 1000 - 50;

        public void onClick(View v) {
            mKeyboardHandler.removeMessages(KeyboardUIStateHandler.MSG_REMOVE_CLOSE_SUGGESTIONS_HINT);
            mCandidateCloseText.setVisibility(View.VISIBLE);
            mCandidateCloseText.startAnimation(
                    AnimationUtils.loadAnimation(getApplicationContext(), R.anim.close_candidates_hint_in));
            mKeyboardHandler.sendMessageDelayed(
                    mKeyboardHandler.obtainMessage(KeyboardUIStateHandler.MSG_REMOVE_CLOSE_SUGGESTIONS_HINT),
                    DOUBLE_TAP_TIMEOUT);
        }
    });

    mCandidateCloseText.setTextColor(closeTextColor);
    mCandidateCloseText.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSizePixel);
    mCandidateCloseText.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mKeyboardHandler.removeMessages(KeyboardUIStateHandler.MSG_REMOVE_CLOSE_SUGGESTIONS_HINT);
            mCandidateCloseText.setVisibility(View.GONE);
            abortCorrectionAndResetPredictionState(true);
        }
    });
}

From source file:com.hippo.vector.VectorDrawable.java

private void updateStateFromTypedArray(TypedArray a) throws XmlPullParserException {
    final VectorDrawableState state = mVectorState;
    final VPathRenderer pathRenderer = state.mVPathRenderer;

    // Account for any configuration changes.
    state.mChangingConfigurations |= Utils.getChangingConfigurations(a);

    final int tintMode = a.getInt(R.styleable.VectorDrawable_tintMode, -1);
    if (tintMode != -1) {
        state.mTintMode = Utils.parseTintMode(tintMode, Mode.SRC_IN);
    }/*  w  w w .  j  a v  a  2 s  . c o  m*/

    final ColorStateList tint = a.getColorStateList(R.styleable.VectorDrawable_tint);
    if (tint != null) {
        state.mTint = tint;
    }

    state.mAutoMirrored = a.getBoolean(R.styleable.VectorDrawable_autoMirrored, state.mAutoMirrored);

    setAllowCaching(a.getBoolean(R.styleable.VectorDrawable_allowCaching, true));

    pathRenderer.mViewportWidth = a.getFloat(R.styleable.VectorDrawable_viewportWidth,
            pathRenderer.mViewportWidth);
    pathRenderer.mViewportHeight = a.getFloat(R.styleable.VectorDrawable_viewportHeight,
            pathRenderer.mViewportHeight);

    if (pathRenderer.mViewportWidth <= 0) {
        throw new XmlPullParserException(
                a.getPositionDescription() + "<vector> tag requires viewportWidth > 0");
    } else if (pathRenderer.mViewportHeight <= 0) {
        throw new XmlPullParserException(
                a.getPositionDescription() + "<vector> tag requires viewportHeight > 0");
    }

    pathRenderer.mBaseWidth = a.getDimension(R.styleable.VectorDrawable_width, pathRenderer.mBaseWidth);
    pathRenderer.mBaseHeight = a.getDimension(R.styleable.VectorDrawable_height, pathRenderer.mBaseHeight);

    if (pathRenderer.mBaseWidth <= 0) {
        throw new XmlPullParserException(a.getPositionDescription() + "<vector> tag requires width > 0");
    } else if (pathRenderer.mBaseHeight <= 0) {
        throw new XmlPullParserException(a.getPositionDescription() + "<vector> tag requires height > 0");
    }

    final int insetLeft = a.getDimensionPixelSize(R.styleable.VectorDrawable_opticalInsetLeft,
            pathRenderer.mOpticalInsets.left);
    final int insetTop = a.getDimensionPixelSize(R.styleable.VectorDrawable_opticalInsetTop,
            pathRenderer.mOpticalInsets.top);
    final int insetRight = a.getDimensionPixelSize(R.styleable.VectorDrawable_opticalInsetRight,
            pathRenderer.mOpticalInsets.right);
    final int insetBottom = a.getDimensionPixelSize(R.styleable.VectorDrawable_opticalInsetBottom,
            pathRenderer.mOpticalInsets.bottom);
    pathRenderer.mOpticalInsets = Insets.of(insetLeft, insetTop, insetRight, insetBottom);

    final float alphaInFloat = a.getFloat(R.styleable.VectorDrawable_alpha, pathRenderer.getAlpha());
    pathRenderer.setAlpha(alphaInFloat);

    final String name = a.getString(R.styleable.VectorDrawable_name);
    if (name != null) {
        pathRenderer.mRootName = name;
        pathRenderer.mVGTargetsMap.put(name, pathRenderer);
    }
}

From source file:com.homechart.app.commont.matertab.MaterialTabs.java

public MaterialTabs(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setFillViewport(true);/*from w w  w. ja  v a 2  s.  c  o m*/
    setWillNotDraw(false);
    tabsContainer = new LinearLayout(context);
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    addView(tabsContainer);

    DisplayMetrics dm = getResources().getDisplayMetrics();
    indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
    underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm);
    tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);

    // Get system attrs (android:textSize and android:textColor).
    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);
    tabTextSize = a.getDimensionPixelSize(TEXT_COLOR_INDEX, tabTextSize);
    int textPrimaryColor = a.getColor(TEXT_COLOR_PRIMARY, 0);
    tabTextColorUnselected = a.getColor(TEXT_COLOR_INDEX, textPrimaryColor);

    underlineColor = textPrimaryColor;
    indicatorColor = textPrimaryColor;
    int padding = a.getDimensionPixelSize(PADDING_INDEX, 0);
    paddingLeft = padding > 0 ? padding : a.getDimensionPixelSize(PADDING_LEFT_INDEX, 0);
    paddingRight = padding > 0 ? padding : a.getDimensionPixelSize(PADDING_RIGHT_INDEX, 0);
    a.recycle();

    a = context.obtainStyledAttributes(attrs, R.styleable.MaterialTabs);

    // Get custom attrs of MaterialTabs.
    indicatorColor = a.getColor(R.styleable.MaterialTabs_mtIndicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.MaterialTabs_mtUnderlineColor, underlineColor);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.MaterialTabs_mtIndicatorHeight, indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.MaterialTabs_mtUnderlineHeight, underlineHeight);
    tabPadding = a.getDimensionPixelSize(R.styleable.MaterialTabs_mtTabPaddingLeftRight, tabPadding);
    sameWeightTabs = a.getBoolean(R.styleable.MaterialTabs_mtSameWeightTabs, sameWeightTabs);
    textAllCaps = a.getBoolean(R.styleable.MaterialTabs_mtTextAllCaps, textAllCaps);
    isPaddingMiddle = a.getBoolean(R.styleable.MaterialTabs_mtPaddingMiddle, isPaddingMiddle);
    tabTypefaceUnselectedStyle = a.getInt(R.styleable.MaterialTabs_mtTextUnselectedStyle, Typeface.BOLD);
    tabTypefaceSelectedStyle = a.getInt(R.styleable.MaterialTabs_mtTextSelectedStyle, Typeface.BOLD);
    tabTextColorSelected = a.getColor(R.styleable.MaterialTabs_mtTextColorSelected, textPrimaryColor);

    // Get custom attrs of MaterialRippleLayout.
    rippleColor = a.getColor(R.styleable.MaterialTabs_mtMrlRippleColor, MaterialRippleLayout.DEFAULT_COLOR);
    // Making default ripple highlight color the same as rippleColor but with 1/4 the alpha.
    rippleHighlightColor = Color.argb((int) (Color.alpha(rippleColor) * 0.25), Color.red(rippleColor),
            Color.green(rippleColor), Color.blue(rippleColor));
    rippleHighlightColor = a.getColor(R.styleable.MaterialTabs_mtMrlRippleHighlightColor, rippleHighlightColor);
    rippleDiameterDp = a.getDimension(R.styleable.MaterialTabs_mtMrlRippleDiameter,
            MaterialRippleLayout.DEFAULT_DIAMETER_DP);
    rippleOverlay = a.getBoolean(R.styleable.MaterialTabs_mtMrlRippleOverlay,
            MaterialRippleLayout.DEFAULT_RIPPLE_OVERLAY);
    rippleDuration = a.getInt(R.styleable.MaterialTabs_mtMrlRippleDuration,
            MaterialRippleLayout.DEFAULT_DURATION);
    rippleAlphaFloat = a.getFloat(R.styleable.MaterialTabs_mtMrlRippleAlpha,
            MaterialRippleLayout.DEFAULT_ALPHA);
    rippleDelayClick = a.getBoolean(R.styleable.MaterialTabs_mtMrlRippleDelayClick,
            MaterialRippleLayout.DEFAULT_DELAY_CLICK);
    rippleFadeDuration = a.getInteger(R.styleable.MaterialTabs_mtMrlRippleFadeDuration,
            MaterialRippleLayout.DEFAULT_FADE_DURATION);
    ripplePersistent = a.getBoolean(R.styleable.MaterialTabs_mtMrlRipplePersistent,
            MaterialRippleLayout.DEFAULT_PERSISTENT);
    rippleInAdapter = a.getBoolean(R.styleable.MaterialTabs_mtMrlRippleInAdapter,
            MaterialRippleLayout.DEFAULT_SEARCH_ADAPTER);
    rippleRoundedCornersDp = a.getDimension(R.styleable.MaterialTabs_mtMrlRippleRoundedCorners,
            MaterialRippleLayout.DEFAULT_ROUNDED_CORNERS_DP);

    a.recycle();

    setMarginBottomTabContainer();

    rectPaint = new Paint();
    rectPaint.setAntiAlias(true);
    rectPaint.setStyle(Style.FILL);

    defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.MATCH_PARENT);
    expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);

    if (locale == null) {
        locale = getResources().getConfiguration().locale;
    }
}

From source file:io.karim.MaterialTabs.java

public MaterialTabs(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setFillViewport(true);/*from w w  w  .j  av  a2s .co m*/
    setWillNotDraw(false);
    tabsContainer = new LinearLayout(context);
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    addView(tabsContainer);

    DisplayMetrics dm = getResources().getDisplayMetrics();
    indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
    underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm);
    tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);

    // Get system attrs (android:textSize and android:textColor).
    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);
    tabTextSize = a.getDimensionPixelSize(TEXT_SIZE_INDEX, tabTextSize);
    int textPrimaryColor = a.getColor(TEXT_COLOR_PRIMARY, android.R.color.white);
    tabTextColorUnselected = a.getColor(TEXT_COLOR_INDEX, textPrimaryColor);

    underlineColor = textPrimaryColor;
    indicatorColor = textPrimaryColor;
    int padding = a.getDimensionPixelSize(PADDING_INDEX, 0);
    paddingLeft = padding > 0 ? padding : a.getDimensionPixelSize(PADDING_LEFT_INDEX, 0);
    paddingRight = padding > 0 ? padding : a.getDimensionPixelSize(PADDING_RIGHT_INDEX, 0);
    a.recycle();

    a = context.obtainStyledAttributes(attrs, R.styleable.MaterialTabs);

    // Get custom attrs of MaterialTabs.
    indicatorColor = a.getColor(R.styleable.MaterialTabs_mtIndicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.MaterialTabs_mtUnderlineColor, underlineColor);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.MaterialTabs_mtIndicatorHeight, indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.MaterialTabs_mtUnderlineHeight, underlineHeight);
    tabPadding = a.getDimensionPixelSize(R.styleable.MaterialTabs_mtTabPaddingLeftRight, tabPadding);
    sameWeightTabs = a.getBoolean(R.styleable.MaterialTabs_mtSameWeightTabs, sameWeightTabs);
    textAllCaps = a.getBoolean(R.styleable.MaterialTabs_mtTextAllCaps, textAllCaps);
    isPaddingMiddle = a.getBoolean(R.styleable.MaterialTabs_mtPaddingMiddle, isPaddingMiddle);
    tabTypefaceUnselectedStyle = a.getInt(R.styleable.MaterialTabs_mtTextUnselectedStyle, Typeface.BOLD);
    tabTypefaceSelectedStyle = a.getInt(R.styleable.MaterialTabs_mtTextSelectedStyle, Typeface.BOLD);
    tabTextColorSelected = a.getColor(R.styleable.MaterialTabs_mtTextColorSelected, textPrimaryColor);

    // Get custom attrs of MaterialRippleLayout.
    rippleColor = a.getColor(R.styleable.MaterialTabs_mtMrlRippleColor, MaterialRippleLayout.DEFAULT_COLOR);
    // Making default ripple highlight color the same as rippleColor but with 1/4 the alpha.
    rippleHighlightColor = Color.argb((int) (Color.alpha(rippleColor) * 0.25), Color.red(rippleColor),
            Color.green(rippleColor), Color.blue(rippleColor));
    rippleHighlightColor = a.getColor(R.styleable.MaterialTabs_mtMrlRippleHighlightColor, rippleHighlightColor);
    rippleDiameterDp = a.getDimension(R.styleable.MaterialTabs_mtMrlRippleDiameter,
            MaterialRippleLayout.DEFAULT_DIAMETER_DP);
    rippleOverlay = a.getBoolean(R.styleable.MaterialTabs_mtMrlRippleOverlay,
            MaterialRippleLayout.DEFAULT_RIPPLE_OVERLAY);
    rippleDuration = a.getInt(R.styleable.MaterialTabs_mtMrlRippleDuration,
            MaterialRippleLayout.DEFAULT_DURATION);
    rippleAlphaFloat = a.getFloat(R.styleable.MaterialTabs_mtMrlRippleAlpha,
            MaterialRippleLayout.DEFAULT_ALPHA);
    rippleDelayClick = a.getBoolean(R.styleable.MaterialTabs_mtMrlRippleDelayClick,
            MaterialRippleLayout.DEFAULT_DELAY_CLICK);
    rippleFadeDuration = a.getInteger(R.styleable.MaterialTabs_mtMrlRippleFadeDuration,
            MaterialRippleLayout.DEFAULT_FADE_DURATION);
    ripplePersistent = a.getBoolean(R.styleable.MaterialTabs_mtMrlRipplePersistent,
            MaterialRippleLayout.DEFAULT_PERSISTENT);
    rippleInAdapter = a.getBoolean(R.styleable.MaterialTabs_mtMrlRippleInAdapter,
            MaterialRippleLayout.DEFAULT_SEARCH_ADAPTER);
    rippleRoundedCornersDp = a.getDimension(R.styleable.MaterialTabs_mtMrlRippleRoundedCorners,
            MaterialRippleLayout.DEFAULT_ROUNDED_CORNERS_DP);

    a.recycle();

    setMarginBottomTabContainer();

    rectPaint = new Paint();
    rectPaint.setAntiAlias(true);
    rectPaint.setStyle(Style.FILL);

    defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.MATCH_PARENT);
    expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);

    if (locale == null) {
        locale = getResources().getConfiguration().locale;
    }
}

From source file:com.manuelpeinado.numericpageindicator.NumericPageIndicator.java

@SuppressWarnings("deprecation")
public NumericPageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode()) {
        return;/*from   ww  w  .  ja v  a  2 s  .c o  m*/
    }

    // Load defaults from resources
    final Resources res = getResources();
    final int defaultTextColor = res.getColor(R.color.default_page_number_indicator_text_color);
    final int defaultPageNumberTextColor = res
            .getColor(R.color.default_page_number_indicator_page_number_text_color);
    final boolean defaultPageNumberTextBold = res
            .getBoolean(R.bool.default_page_number_indicator_page_number_text_bold);
    final int defaultButtonPressedColor = res
            .getColor(R.color.default_page_number_indicator_pressed_button_color);
    final float defaultTopPadding = res.getDimension(R.dimen.default_page_number_indicator_top_padding);
    final float defaultBottomPadding = res.getDimension(R.dimen.default_page_number_indicator_bottom_padding);
    final float defaultTextSize = res.getDimension(R.dimen.default_page_number_indicator_text_size);
    final boolean defaultShowChangePageButtons = res
            .getBoolean(R.bool.default_page_number_indicator_show_change_page_buttons);
    final boolean defaultShowStartEndButtons = res
            .getBoolean(R.bool.default_page_number_indicator_show_start_end_buttons);
    final boolean defaultShowImagesForPageControls = res
            .getBoolean(R.bool.default_page_number_indicator_show_images_for_page_controls);

    // Retrieve styles attributes
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NumericPageIndicator, defStyle, 0);

    mTextTemplate = a.getString(R.styleable.NumericPageIndicator_textTemplate);
    if (mTextTemplate == null) {
        mTextTemplate = res.getString(R.string.default_page_number_indicator_text_template);
        ;
    }
    parseTextTemplate();

    mTextStartButton = a.getString(R.styleable.NumericPageIndicator_startButtonText);
    if (mTextStartButton == null) {
        mTextStartButton = res.getString(R.string.default_page_number_indicator_start_button_text);
    }
    mTextEndButton = a.getString(R.styleable.NumericPageIndicator_endButtonText);
    if (mTextEndButton == null) {
        mTextEndButton = res.getString(R.string.default_page_number_indicator_end_button_text);
    }
    mTextPreviousButton = a.getString(R.styleable.NumericPageIndicator_previousButtonText);
    if (mTextPreviousButton == null) {
        mTextPreviousButton = res.getString(R.string.default_page_number_indicator_previous_button_text);
    }
    mTextNextButton = a.getString(R.styleable.NumericPageIndicator_nextButtonText);
    if (mTextNextButton == null) {
        mTextNextButton = res.getString(R.string.default_page_number_indicator_next_button_text);
    }

    // these will be null if they are unused
    mStartButtonImage = getBitmapFromDrawable(a.getDrawable(R.styleable.NumericPageIndicator_startButtonImage));
    mEndButtonImage = getBitmapFromDrawable(a.getDrawable(R.styleable.NumericPageIndicator_endButtonImage));
    mPreviousButtonImage = getBitmapFromDrawable(
            a.getDrawable(R.styleable.NumericPageIndicator_previousButtonImage));
    mNextButtonImage = getBitmapFromDrawable(a.getDrawable(R.styleable.NumericPageIndicator_nextButtonImage));

    mColorText = a.getColor(R.styleable.NumericPageIndicator_android_textColor, defaultTextColor);
    mColorPageNumberText = a.getColor(R.styleable.NumericPageIndicator_pageNumberTextColor,
            defaultPageNumberTextColor);
    mPageNumberTextBold = a.getBoolean(R.styleable.NumericPageIndicator_pageNumberTextBold,
            defaultPageNumberTextBold);
    mColorPressedButton = a.getColor(R.styleable.NumericPageIndicator_pressedButtonColor,
            defaultButtonPressedColor);
    mPaddingTop = a.getDimension(R.styleable.NumericPageIndicator_android_paddingTop, defaultTopPadding);
    mPaddingBottom = a.getDimension(R.styleable.NumericPageIndicator_android_paddingBottom,
            defaultBottomPadding);
    mPaintText.setColor(mColorText);
    mShowChangePageButtons = a.getBoolean(R.styleable.NumericPageIndicator_showChangePageButtons,
            defaultShowChangePageButtons);
    mShowStartEndButtons = a.getBoolean(R.styleable.NumericPageIndicator_showStartEndButtons,
            defaultShowStartEndButtons);
    mShowImagesForPageControls = a.getBoolean(R.styleable.NumericPageIndicator_showImagesForPageControls,
            defaultShowImagesForPageControls);

    mPaintButtonBackground.setColor(mColorPressedButton);
    final float textSize = a.getDimension(R.styleable.NumericPageIndicator_android_textSize, defaultTextSize);
    mPaintText.setTextSize(textSize);
    mPaintText.setAntiAlias(true);

    mPaintPageNumberText.setColor(mColorPageNumberText);
    mPaintPageNumberText.setTextSize(textSize);
    mPaintPageNumberText.setAntiAlias(true);
    if (mPageNumberTextBold) {
        mPaintPageNumberText.setTypeface(Typeface.DEFAULT_BOLD);
    }

    final Drawable background = a.getDrawable(R.styleable.NumericPageIndicator_android_background);
    if (background != null) {
        setBackgroundDrawable(background);
    }

    a.recycle();
}