Example usage for android.content.res TypedArray getColor

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

Introduction

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

Prototype

@ColorInt
public int getColor(@StyleableRes int index, @ColorInt int defValue) 

Source Link

Document

Retrieve the color value for the attribute at index.

Usage

From source file:com.appeaser.sublimepickerlibrary.timepicker.RadialTimePickerView.java

private void init(AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    Context context = getContext();

    // Pull disabled alpha from theme.
    final TypedValue outValue = new TypedValue();
    context.getTheme().resolveAttribute(android.R.attr.disabledAlpha, outValue, true);
    mDisabledAlpha = outValue.getFloat();

    // process style attributes
    final Resources res = getResources();
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RadialTimePickerView, defStyleAttr,
            defStyleRes);/*from w  ww  .  java2 s  . com*/

    mTypeface = Typeface.create("sans-serif", Typeface.NORMAL);

    // Initialize all alpha values to opaque.
    for (int i = 0; i < mAlpha.length; i++) {
        mAlpha[i] = new IntHolder(ALPHA_OPAQUE);
    }

    mTextColor[HOURS] = a.getColorStateList(R.styleable.RadialTimePickerView_spNumbersTextColor);
    mTextColor[HOURS_INNER] = a.getColorStateList(R.styleable.RadialTimePickerView_spNumbersInnerTextColor);
    mTextColor[MINUTES] = mTextColor[HOURS];

    mPaint[HOURS] = new Paint();
    mPaint[HOURS].setAntiAlias(true);
    mPaint[HOURS].setTextAlign(Paint.Align.CENTER);

    mPaint[MINUTES] = new Paint();
    mPaint[MINUTES].setAntiAlias(true);
    mPaint[MINUTES].setTextAlign(Paint.Align.CENTER);

    final ColorStateList selectorColors = a
            .getColorStateList(R.styleable.RadialTimePickerView_spNumbersSelectorColor);

    int selectorActivatedColor = Color.BLACK;
    if (selectorColors != null) {
        selectorActivatedColor = selectorColors
                .getColorForState(SUtils.resolveStateSet(SUtils.STATE_ENABLED | SUtils.STATE_ACTIVATED), 0);
    }

    mPaintCenter.setColor(selectorActivatedColor);
    mPaintCenter.setAntiAlias(true);

    final int[] activatedStateSet = SUtils.resolveStateSet(SUtils.STATE_ENABLED | SUtils.STATE_ACTIVATED);

    mSelectorColor = selectorActivatedColor;
    mSelectorDotColor = mTextColor[HOURS].getColorForState(activatedStateSet, 0);

    mPaintSelector[HOURS][SELECTOR_CIRCLE] = new Paint();
    mPaintSelector[HOURS][SELECTOR_CIRCLE].setAntiAlias(true);

    mPaintSelector[HOURS][SELECTOR_DOT] = new Paint();
    mPaintSelector[HOURS][SELECTOR_DOT].setAntiAlias(true);

    mPaintSelector[HOURS][SELECTOR_LINE] = new Paint();
    mPaintSelector[HOURS][SELECTOR_LINE].setAntiAlias(true);
    mPaintSelector[HOURS][SELECTOR_LINE].setStrokeWidth(2);

    mPaintSelector[MINUTES][SELECTOR_CIRCLE] = new Paint();
    mPaintSelector[MINUTES][SELECTOR_CIRCLE].setAntiAlias(true);

    mPaintSelector[MINUTES][SELECTOR_DOT] = new Paint();
    mPaintSelector[MINUTES][SELECTOR_DOT].setAntiAlias(true);

    mPaintSelector[MINUTES][SELECTOR_LINE] = new Paint();
    mPaintSelector[MINUTES][SELECTOR_LINE].setAntiAlias(true);
    mPaintSelector[MINUTES][SELECTOR_LINE].setStrokeWidth(2);

    mPaintBackground.setColor(a.getColor(R.styleable.RadialTimePickerView_spNumbersBackgroundColor,
            ContextCompat.getColor(context, R.color.timepicker_default_numbers_background_color_material)));
    mPaintBackground.setAntiAlias(true);

    mSelectorRadius = res.getDimensionPixelSize(R.dimen.sp_timepicker_selector_radius);
    mSelectorStroke = res.getDimensionPixelSize(R.dimen.sp_timepicker_selector_stroke);
    mSelectorDotRadius = res.getDimensionPixelSize(R.dimen.sp_timepicker_selector_dot_radius);
    mCenterDotRadius = res.getDimensionPixelSize(R.dimen.sp_timepicker_center_dot_radius);

    mTextSize[HOURS] = res.getDimensionPixelSize(R.dimen.sp_timepicker_text_size_normal);
    mTextSize[MINUTES] = res.getDimensionPixelSize(R.dimen.sp_timepicker_text_size_normal);
    mTextSize[HOURS_INNER] = res.getDimensionPixelSize(R.dimen.sp_timepicker_text_size_inner);

    mTextInset[HOURS] = res.getDimensionPixelSize(R.dimen.sp_timepicker_text_inset_normal);
    mTextInset[MINUTES] = res.getDimensionPixelSize(R.dimen.sp_timepicker_text_inset_normal);
    mTextInset[HOURS_INNER] = res.getDimensionPixelSize(R.dimen.sp_timepicker_text_inset_inner);

    mShowHours = true;
    mIs24HourMode = false;
    mAmOrPm = AM;

    // Set up accessibility components.
    mTouchHelper = new RadialPickerTouchHelper();
    ViewCompat.setAccessibilityDelegate(this, mTouchHelper);

    if (ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
        ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    }

    initHoursAndMinutesText();
    initData();

    a.recycle();

    // Initial values
    final Calendar calendar = Calendar.getInstance(Locale.getDefault());
    final int currentHour = calendar.get(Calendar.HOUR_OF_DAY);
    final int currentMinute = calendar.get(Calendar.MINUTE);

    setCurrentHourInternal(currentHour, false, false);
    setCurrentMinuteInternal(currentMinute, false);

    setHapticFeedbackEnabled(true);
}

From source file:com.android.contacts.list.ContactListItemView.java

public ContactListItemView(Context context, AttributeSet attrs) {
    super(context, attrs);

    TypedArray a;

    if (R.styleable.ContactListItemView != null) {
        // Read all style values
        a = getContext().obtainStyledAttributes(attrs, R.styleable.ContactListItemView);
        mPreferredHeight = a.getDimensionPixelSize(R.styleable.ContactListItemView_list_item_height,
                mPreferredHeight);/*from  ww w .jav  a 2  s .c o m*/
        mActivatedBackgroundDrawable = a.getDrawable(R.styleable.ContactListItemView_activated_background);

        mGapBetweenImageAndText = a.getDimensionPixelOffset(
                R.styleable.ContactListItemView_list_item_gap_between_image_and_text, mGapBetweenImageAndText);
        mGapBetweenIndexerAndImage = a.getDimensionPixelOffset(
                R.styleable.ContactListItemView_list_item_gap_between_indexer_and_image,
                mGapBetweenIndexerAndImage);
        mGapBetweenLabelAndData = a.getDimensionPixelOffset(
                R.styleable.ContactListItemView_list_item_gap_between_label_and_data, mGapBetweenLabelAndData);
        mPresenceIconMargin = a.getDimensionPixelOffset(
                R.styleable.ContactListItemView_list_item_presence_icon_margin, mPresenceIconMargin);
        mPresenceIconSize = a.getDimensionPixelOffset(
                R.styleable.ContactListItemView_list_item_presence_icon_size, mPresenceIconSize);
        mDefaultPhotoViewSize = a.getDimensionPixelOffset(R.styleable.ContactListItemView_list_item_photo_size,
                mDefaultPhotoViewSize);
        mTextIndent = a.getDimensionPixelOffset(R.styleable.ContactListItemView_list_item_text_indent,
                mTextIndent);
        mTextOffsetTop = a.getDimensionPixelOffset(R.styleable.ContactListItemView_list_item_text_offset_top,
                mTextOffsetTop);
        mAvatarOffsetTop = a.getDimensionPixelOffset(
                R.styleable.ContactListItemView_list_item_avatar_offset_top, mAvatarOffsetTop);
        mDataViewWidthWeight = a.getInteger(R.styleable.ContactListItemView_list_item_data_width_weight,
                mDataViewWidthWeight);
        mLabelViewWidthWeight = a.getInteger(R.styleable.ContactListItemView_list_item_label_width_weight,
                mLabelViewWidthWeight);
        mNameTextViewTextColor = a.getColor(R.styleable.ContactListItemView_list_item_name_text_color,
                mNameTextViewTextColor);
        mNameTextViewTextSize = (int) a.getDimension(R.styleable.ContactListItemView_list_item_name_text_size,
                (int) getResources().getDimension(R.dimen.contact_browser_list_item_text_size));
        mVideoCallIconSize = a.getDimensionPixelOffset(
                R.styleable.ContactListItemView_list_item_video_call_icon_size, mVideoCallIconSize);
        mVideoCallIconMargin = a.getDimensionPixelOffset(
                R.styleable.ContactListItemView_list_item_video_call_icon_margin, mVideoCallIconMargin);

        setPaddingRelative(a.getDimensionPixelOffset(R.styleable.ContactListItemView_list_item_padding_left, 0),
                a.getDimensionPixelOffset(R.styleable.ContactListItemView_list_item_padding_top, 0),
                a.getDimensionPixelOffset(R.styleable.ContactListItemView_list_item_padding_right, 0),
                a.getDimensionPixelOffset(R.styleable.ContactListItemView_list_item_padding_bottom, 0));

        a.recycle();
    }

    mTextHighlighter = new TextHighlighter(Typeface.BOLD);

    if (R.styleable.Theme != null) {
        a = getContext().obtainStyledAttributes(R.styleable.Theme);
        mSecondaryTextColor = a.getColorStateList(R.styleable.Theme_android_textColorSecondary);
        a.recycle();
    }

    mHeaderWidth = getResources().getDimensionPixelSize(R.dimen.contact_list_section_header_width);

    if (mActivatedBackgroundDrawable != null) {
        mActivatedBackgroundDrawable.setCallback(this);
    }

    mNameHighlightSequence = new ArrayList<HighlightSequence>();
    mNumberHighlightSequence = new ArrayList<HighlightSequence>();

    setLayoutDirection(View.LAYOUT_DIRECTION_LOCALE);
}

From source file:android.support.graphics.drawable.AnimatorInflaterCompat.java

private static PropertyValuesHolder getPVH(TypedArray styledAttributes, int valueType, int valueFromId,
        int valueToId, String propertyName) {

    TypedValue tvFrom = styledAttributes.peekValue(valueFromId);
    boolean hasFrom = (tvFrom != null);
    int fromType = hasFrom ? tvFrom.type : 0;
    TypedValue tvTo = styledAttributes.peekValue(valueToId);
    boolean hasTo = (tvTo != null);
    int toType = hasTo ? tvTo.type : 0;

    if (valueType == VALUE_TYPE_UNDEFINED) {
        // Check whether it's color type. If not, fall back to default type (i.e. float type)
        if ((hasFrom && isColorType(fromType)) || (hasTo && isColorType(toType))) {
            valueType = VALUE_TYPE_COLOR;
        } else {/*from w w  w. ja  va  2s  . co m*/
            valueType = VALUE_TYPE_FLOAT;
        }
    }

    boolean getFloats = (valueType == VALUE_TYPE_FLOAT);

    PropertyValuesHolder returnValue = null;

    if (valueType == VALUE_TYPE_PATH) {
        String fromString = styledAttributes.getString(valueFromId);
        String toString = styledAttributes.getString(valueToId);

        PathParser.PathDataNode[] nodesFrom = PathParser.createNodesFromPathData(fromString);
        PathParser.PathDataNode[] nodesTo = PathParser.createNodesFromPathData(toString);
        if (nodesFrom != null || nodesTo != null) {
            if (nodesFrom != null) {
                TypeEvaluator evaluator = new PathDataEvaluator();
                if (nodesTo != null) {
                    if (!PathParser.canMorph(nodesFrom, nodesTo)) {
                        throw new InflateException(" Can't morph from " + fromString + " to " + toString);
                    }
                    returnValue = PropertyValuesHolder.ofObject(propertyName, evaluator, nodesFrom, nodesTo);
                } else {
                    returnValue = PropertyValuesHolder.ofObject(propertyName, evaluator, (Object) nodesFrom);
                }
            } else if (nodesTo != null) {
                TypeEvaluator evaluator = new PathDataEvaluator();
                returnValue = PropertyValuesHolder.ofObject(propertyName, evaluator, (Object) nodesTo);
            }
        }
    } else {
        TypeEvaluator evaluator = null;
        // Integer and float value types are handled here.
        if (valueType == VALUE_TYPE_COLOR) {
            // special case for colors: ignore valueType and get ints
            evaluator = ArgbEvaluator.getInstance();
        }
        if (getFloats) {
            float valueFrom;
            float valueTo;
            if (hasFrom) {
                if (fromType == TypedValue.TYPE_DIMENSION) {
                    valueFrom = styledAttributes.getDimension(valueFromId, 0f);
                } else {
                    valueFrom = styledAttributes.getFloat(valueFromId, 0f);
                }
                if (hasTo) {
                    if (toType == TypedValue.TYPE_DIMENSION) {
                        valueTo = styledAttributes.getDimension(valueToId, 0f);
                    } else {
                        valueTo = styledAttributes.getFloat(valueToId, 0f);
                    }
                    returnValue = PropertyValuesHolder.ofFloat(propertyName, valueFrom, valueTo);
                } else {
                    returnValue = PropertyValuesHolder.ofFloat(propertyName, valueFrom);
                }
            } else {
                if (toType == TypedValue.TYPE_DIMENSION) {
                    valueTo = styledAttributes.getDimension(valueToId, 0f);
                } else {
                    valueTo = styledAttributes.getFloat(valueToId, 0f);
                }
                returnValue = PropertyValuesHolder.ofFloat(propertyName, valueTo);
            }
        } else {
            int valueFrom;
            int valueTo;
            if (hasFrom) {
                if (fromType == TypedValue.TYPE_DIMENSION) {
                    valueFrom = (int) styledAttributes.getDimension(valueFromId, 0f);
                } else if (isColorType(fromType)) {
                    valueFrom = styledAttributes.getColor(valueFromId, 0);
                } else {
                    valueFrom = styledAttributes.getInt(valueFromId, 0);
                }
                if (hasTo) {
                    if (toType == TypedValue.TYPE_DIMENSION) {
                        valueTo = (int) styledAttributes.getDimension(valueToId, 0f);
                    } else if (isColorType(toType)) {
                        valueTo = styledAttributes.getColor(valueToId, 0);
                    } else {
                        valueTo = styledAttributes.getInt(valueToId, 0);
                    }
                    returnValue = PropertyValuesHolder.ofInt(propertyName, valueFrom, valueTo);
                } else {
                    returnValue = PropertyValuesHolder.ofInt(propertyName, valueFrom);
                }
            } else {
                if (hasTo) {
                    if (toType == TypedValue.TYPE_DIMENSION) {
                        valueTo = (int) styledAttributes.getDimension(valueToId, 0f);
                    } else if (isColorType(toType)) {
                        valueTo = styledAttributes.getColor(valueToId, 0);
                    } else {
                        valueTo = styledAttributes.getInt(valueToId, 0);
                    }
                    returnValue = PropertyValuesHolder.ofInt(propertyName, valueTo);
                }
            }
        }
        if (returnValue != null && evaluator != null) {
            returnValue.setEvaluator(evaluator);
        }
    }

    return returnValue;
}

From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardBaseView.java

public boolean setValueFromTheme(TypedArray remoteTypedArray, final int[] padding, final int localAttrId,
        final int remoteTypedArrayIndex) {
    try {//from w ww  .j  a  v a 2s. c  om

        if (localAttrId == android.R.attr.background) {
            Drawable keyboardBackground = remoteTypedArray.getDrawable(remoteTypedArrayIndex);
            Log.d(TAG, "AnySoftKeyboardTheme_android_background " + (keyboardBackground != null));
            super.setBackgroundDrawable(keyboardBackground);
        } else if (localAttrId == android.R.attr.paddingLeft) {
            padding[0] = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, 0);
            Log.d(TAG, "AnySoftKeyboardTheme_android_paddingLeft " + padding[0]);
        } else if (localAttrId == android.R.attr.paddingTop) {
            padding[1] = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, 0);
            Log.d(TAG, "AnySoftKeyboardTheme_android_paddingTop " + padding[1]);
        } else if (localAttrId == android.R.attr.paddingRight) {
            padding[2] = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, 0);
            Log.d(TAG, "AnySoftKeyboardTheme_android_paddingRight " + padding[2]);
        } else if (localAttrId == android.R.attr.paddingBottom) {
            padding[3] = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, 0);
            Log.d(TAG, "AnySoftKeyboardTheme_android_paddingBottom " + padding[3]);
        } else if (localAttrId == R.attr.keyBackground) {
            mKeyBackground = remoteTypedArray.getDrawable(remoteTypedArrayIndex);
            Log.d(TAG, "AnySoftKeyboardTheme_keyBackground " + (mKeyBackground != null));
        } else if (localAttrId == R.attr.keyHysteresisDistance) {
            mKeyHysteresisDistance = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0);
            Log.d(TAG, "AnySoftKeyboardTheme_keyHysteresisDistance " + mKeyHysteresisDistance);
        } else if (localAttrId == R.attr.verticalCorrection) {
            mVerticalCorrection = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0);
            Log.d(TAG, "AnySoftKeyboardTheme_verticalCorrection " + mVerticalCorrection);
        } else if (localAttrId == R.attr.keyPreviewBackground) {
            mPreviewKeyBackground = remoteTypedArray.getDrawable(remoteTypedArrayIndex);
            Log.d(TAG, "AnySoftKeyboardTheme_keyPreviewBackground " + (mPreviewKeyBackground != null));
        } else if (localAttrId == R.attr.keyPreviewTextColor) {
            mPreviewKeyTextColor = remoteTypedArray.getColor(remoteTypedArrayIndex, 0xFFF);
            Log.d(TAG, "AnySoftKeyboardTheme_keyPreviewTextColor " + mPreviewKeyTextColor);
        } else if (localAttrId == R.attr.keyPreviewTextSize) {
            mPreviewKeyTextSize = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, 0);
            Log.d(TAG, "AnySoftKeyboardTheme_keyPreviewTextSize " + mPreviewKeyTextSize);
        } else if (localAttrId == R.attr.keyPreviewLabelTextSize) {
            mPreviewLabelTextSize = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, 0);
            Log.d(TAG, "AnySoftKeyboardTheme_keyPreviewLabelTextSize " + mPreviewLabelTextSize);
        } else if (localAttrId == R.attr.keyPreviewOffset) {
            mPreviewOffset = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0);
            Log.d(TAG, "AnySoftKeyboardTheme_keyPreviewOffset " + mPreviewOffset);
        } else if (localAttrId == R.attr.keyTextSize) {
            mKeyTextSize = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, 18);
            // you might ask yourself "why did Menny sqrt root the factor?"
            // I'll tell you; the factor is mostly for the height, not the
            // font size,
            // but I also factorize the font size because I want the text to
            // be a little like
            // the key size.
            // the whole factor maybe too much, so I ease that a bit.
            if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
                mKeyTextSize = mKeyTextSize
                        * FloatMath.sqrt(AnyApplication.getConfig().getKeysHeightFactorInLandscape());
            else
                mKeyTextSize = mKeyTextSize
                        * FloatMath.sqrt(AnyApplication.getConfig().getKeysHeightFactorInPortrait());
            Log.d(TAG, "AnySoftKeyboardTheme_keyTextSize " + mKeyTextSize);
        } else if (localAttrId == R.attr.keyTextColor) {
            mKeyTextColor = remoteTypedArray.getColorStateList(remoteTypedArrayIndex);
            if (mKeyTextColor == null) {
                Log.d(TAG, "Creating an empty ColorStateList for mKeyTextColor");
                mKeyTextColor = new ColorStateList(new int[][] { { 0 } },
                        new int[] { remoteTypedArray.getColor(remoteTypedArrayIndex, 0xFF000000) });
            }
            Log.d(TAG, "AnySoftKeyboardTheme_keyTextColor " + mKeyTextColor);
        } else if (localAttrId == R.attr.labelTextSize) {
            mLabelTextSize = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, 14);
            if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
                mLabelTextSize = mLabelTextSize * AnyApplication.getConfig().getKeysHeightFactorInLandscape();
            else
                mLabelTextSize = mLabelTextSize * AnyApplication.getConfig().getKeysHeightFactorInPortrait();
            Log.d(TAG, "AnySoftKeyboardTheme_labelTextSize " + mLabelTextSize);
        } else if (localAttrId == R.attr.keyboardNameTextSize) {
            mKeyboardNameTextSize = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, 10);
            if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
                mKeyboardNameTextSize = mKeyboardNameTextSize
                        * AnyApplication.getConfig().getKeysHeightFactorInLandscape();
            else
                mKeyboardNameTextSize = mKeyboardNameTextSize
                        * AnyApplication.getConfig().getKeysHeightFactorInPortrait();
            Log.d(TAG, "AnySoftKeyboardTheme_keyboardNameTextSize " + mKeyboardNameTextSize);
        } else if (localAttrId == R.attr.keyboardNameTextColor) {
            mKeyboardNameTextColor = remoteTypedArray.getColorStateList(remoteTypedArrayIndex);
            if (mKeyboardNameTextColor == null) {
                Log.d(TAG, "Creating an empty ColorStateList for mKeyboardNameTextColor");
                mKeyboardNameTextColor = new ColorStateList(new int[][] { { 0 } },
                        new int[] { remoteTypedArray.getColor(remoteTypedArrayIndex, 0xFFAAAAAA) });
            }
            Log.d(TAG, "AnySoftKeyboardTheme_keyboardNameTextColor " + mKeyboardNameTextColor);
        } else if (localAttrId == R.attr.shadowColor) {
            mShadowColor = remoteTypedArray.getColor(remoteTypedArrayIndex, 0);
            Log.d(TAG, "AnySoftKeyboardTheme_shadowColor " + mShadowColor);
        } else if (localAttrId == R.attr.shadowRadius) {
            mShadowRadius = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0);
            Log.d(TAG, "AnySoftKeyboardTheme_shadowRadius " + mShadowRadius);
        } else if (localAttrId == R.attr.shadowOffsetX) {
            mShadowOffsetX = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0);
            Log.d(TAG, "AnySoftKeyboardTheme_shadowOffsetX " + mShadowOffsetX);
        } else if (localAttrId == R.attr.shadowOffsetY) {
            mShadowOffsetY = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0);
            Log.d(TAG, "AnySoftKeyboardTheme_shadowOffsetY " + mShadowOffsetY);
        } else if (localAttrId == R.attr.backgroundDimAmount) {
            mBackgroundDimAmount = remoteTypedArray.getFloat(remoteTypedArrayIndex, 0.5f);
            Log.d(TAG, "AnySoftKeyboardTheme_backgroundDimAmount " + mBackgroundDimAmount);
        } else if (localAttrId == R.attr.keyTextStyle) {
            int textStyle = remoteTypedArray.getInt(remoteTypedArrayIndex, 0);
            switch (textStyle) {
            case 0:
                mKeyTextStyle = Typeface.DEFAULT;
                break;
            case 1:
                mKeyTextStyle = Typeface.DEFAULT_BOLD;
                break;
            case 2:
                mKeyTextStyle = Typeface.defaultFromStyle(Typeface.ITALIC);
                break;
            default:
                mKeyTextStyle = Typeface.defaultFromStyle(textStyle);
                break;
            }
            Log.d(TAG, "AnySoftKeyboardTheme_keyTextStyle " + mKeyTextStyle);
        } else if (localAttrId == R.attr.symbolColorScheme) {
            mSymbolColorScheme = remoteTypedArray.getInt(remoteTypedArrayIndex, 0);
            Log.d(TAG, "AnySoftKeyboardTheme_symbolColorScheme " + mSymbolColorScheme);
        } else if (localAttrId == R.attr.keyHorizontalGap) {
            float themeHorizotalKeyGap = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0);
            mKeyboardDimens.setHorizontalKeyGap(themeHorizotalKeyGap);
            Log.d(TAG, "AnySoftKeyboardTheme_keyHorizontalGap " + themeHorizotalKeyGap);
        } else if (localAttrId == R.attr.keyVerticalGap) {
            float themeVerticalRowGap = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0);
            mKeyboardDimens.setVerticalRowGap(themeVerticalRowGap);
            Log.d(TAG, "AnySoftKeyboardTheme_keyVerticalGap " + themeVerticalRowGap);
        } else if (localAttrId == R.attr.keyNormalHeight) {
            float themeNormalKeyHeight = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0);
            mKeyboardDimens.setNormalKeyHeight(themeNormalKeyHeight);
            Log.d(TAG, "AnySoftKeyboardTheme_keyNormalHeight " + themeNormalKeyHeight);
        } else if (localAttrId == R.attr.keyLargeHeight) {
            float themeLargeKeyHeight = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0);
            mKeyboardDimens.setLargeKeyHeight(themeLargeKeyHeight);
            Log.d(TAG, "AnySoftKeyboardTheme_keyLargeHeight " + themeLargeKeyHeight);
        } else if (localAttrId == R.attr.keySmallHeight) {
            float themeSmallKeyHeight = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0);
            mKeyboardDimens.setSmallKeyHeight(themeSmallKeyHeight);
            Log.d(TAG, "AnySoftKeyboardTheme_keySmallHeight " + themeSmallKeyHeight);
        } else if (localAttrId == R.attr.hintTextSize) {
            mHintTextSize = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, 0);
            Log.d(TAG, "AnySoftKeyboardTheme_hintTextSize " + mHintTextSize);
            if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
                mHintTextSize = mHintTextSize * AnyApplication.getConfig().getKeysHeightFactorInLandscape();
            else
                mHintTextSize = mHintTextSize * AnyApplication.getConfig().getKeysHeightFactorInPortrait();
            Log.d(TAG, "AnySoftKeyboardTheme_hintTextSize with factor " + mHintTextSize);
        } else if (localAttrId == R.attr.hintTextColor) {
            mHintTextColor = remoteTypedArray.getColorStateList(remoteTypedArrayIndex);
            if (mHintTextColor == null) {
                Log.d(TAG, "Creating an empty ColorStateList for mHintTextColor");
                mHintTextColor = new ColorStateList(new int[][] { { 0 } },
                        new int[] { remoteTypedArray.getColor(remoteTypedArrayIndex, 0xFF000000) });
            }
            Log.d(TAG, "AnySoftKeyboardTheme_hintTextColor " + mHintTextColor);
        } else if (localAttrId == R.attr.hintLabelVAlign) {
            mHintLabelVAlign = remoteTypedArray.getInt(remoteTypedArrayIndex, Gravity.BOTTOM);
            Log.d(TAG, "AnySoftKeyboardTheme_hintLabelVAlign " + mHintLabelVAlign);
        } else if (localAttrId == R.attr.hintLabelAlign) {
            mHintLabelAlign = remoteTypedArray.getInt(remoteTypedArrayIndex, Gravity.RIGHT);
            Log.d(TAG, "AnySoftKeyboardTheme_hintLabelAlign " + mHintLabelAlign);
        } else if (localAttrId == R.attr.hintOverflowLabel) {
            mHintOverflowLabel = remoteTypedArray.getString(remoteTypedArrayIndex);
            Log.d(TAG, "AnySoftKeyboardTheme_hintOverflowLabel " + mHintOverflowLabel);
        }

        return true;
    } catch (Exception e) {
        // on API changes, so the incompatible themes wont crash me..
        e.printStackTrace();
        return false;
    }
}

From source file:com.facebook.litho.InternalNode.java

void applyAttributes(TypedArray a) {
    for (int i = 0, size = a.getIndexCount(); i < size; i++) {
        final int attr = a.getIndex(i);

        if (attr == R.styleable.ComponentLayout_android_layout_width) {
            int width = a.getLayoutDimension(attr, -1);
            // We don't support WRAP_CONTENT or MATCH_PARENT so no-op for them
            if (width >= 0) {
                widthPx(width);/* w  ww  . j a v  a  2 s  .c om*/
            }
        } else if (attr == R.styleable.ComponentLayout_android_layout_height) {
            int height = a.getLayoutDimension(attr, -1);
            // We don't support WRAP_CONTENT or MATCH_PARENT so no-op for them
            if (height >= 0) {
                heightPx(height);
            }
        } else if (attr == R.styleable.ComponentLayout_android_paddingLeft) {
            paddingPx(LEFT, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_paddingTop) {
            paddingPx(TOP, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_paddingRight) {
            paddingPx(RIGHT, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_paddingBottom) {
            paddingPx(BOTTOM, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_paddingStart && SUPPORTS_RTL) {
            paddingPx(START, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_paddingEnd && SUPPORTS_RTL) {
            paddingPx(END, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_padding) {
            paddingPx(ALL, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_layout_marginLeft) {
            marginPx(LEFT, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_layout_marginTop) {
            marginPx(TOP, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_layout_marginRight) {
            marginPx(RIGHT, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_layout_marginBottom) {
            marginPx(BOTTOM, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_layout_marginStart && SUPPORTS_RTL) {
            marginPx(START, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_layout_marginEnd && SUPPORTS_RTL) {
            marginPx(END, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_layout_margin) {
            marginPx(ALL, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_importantForAccessibility
                && SDK_INT >= JELLY_BEAN) {
            importantForAccessibility(a.getInt(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_duplicateParentState) {
            duplicateParentState(a.getBoolean(attr, false));
        } else if (attr == R.styleable.ComponentLayout_android_background) {
            if (TypedArrayUtils.isColorAttribute(a, R.styleable.ComponentLayout_android_background)) {
                backgroundColor(a.getColor(attr, 0));
            } else {
                backgroundRes(a.getResourceId(attr, -1));
            }
        } else if (attr == R.styleable.ComponentLayout_android_foreground) {
            if (TypedArrayUtils.isColorAttribute(a, R.styleable.ComponentLayout_android_foreground)) {
                foregroundColor(a.getColor(attr, 0));
            } else {
                foregroundRes(a.getResourceId(attr, -1));
            }
        } else if (attr == R.styleable.ComponentLayout_android_contentDescription) {
            contentDescription(a.getString(attr));
        } else if (attr == R.styleable.ComponentLayout_flex_direction) {
            flexDirection(YogaFlexDirection.fromInt(a.getInteger(attr, 0)));
        } else if (attr == R.styleable.ComponentLayout_flex_wrap) {
            wrap(YogaWrap.fromInt(a.getInteger(attr, 0)));
        } else if (attr == R.styleable.ComponentLayout_flex_justifyContent) {
            justifyContent(YogaJustify.fromInt(a.getInteger(attr, 0)));
        } else if (attr == R.styleable.ComponentLayout_flex_alignItems) {
            alignItems(YogaAlign.fromInt(a.getInteger(attr, 0)));
        } else if (attr == R.styleable.ComponentLayout_flex_alignSelf) {
            alignSelf(YogaAlign.fromInt(a.getInteger(attr, 0)));
        } else if (attr == R.styleable.ComponentLayout_flex_positionType) {
            positionType(YogaPositionType.fromInt(a.getInteger(attr, 0)));
        } else if (attr == R.styleable.ComponentLayout_flex) {
            final float flex = a.getFloat(attr, -1);
            if (flex >= 0f) {
                flex(flex);
            }
        } else if (attr == R.styleable.ComponentLayout_flex_left) {
            positionPx(LEFT, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_flex_top) {
            positionPx(TOP, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_flex_right) {
            positionPx(RIGHT, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_flex_bottom) {
            positionPx(BOTTOM, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_flex_layoutDirection) {
            final int layoutDirection = a.getInteger(attr, -1);
            layoutDirection(YogaDirection.fromInt(layoutDirection));
        }
    }
}

From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardViewBase.java

protected boolean setValueFromTheme(TypedArray remoteTypedArray, final int[] padding, final int localAttrId,
        final int remoteTypedArrayIndex) {
    try {/* w  ww  .  ja  v  a2s .c  o  m*/
        switch (localAttrId) {
        case android.R.attr.background:
            Drawable keyboardBackground = remoteTypedArray.getDrawable(remoteTypedArrayIndex);
            if (keyboardBackground == null)
                return false;
            CompatUtils.setViewBackgroundDrawable(this, keyboardBackground);
            break;
        case android.R.attr.paddingLeft:
            padding[0] = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, -1);
            if (padding[0] == -1)
                return false;
            break;
        case android.R.attr.paddingTop:
            padding[1] = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, -1);
            if (padding[1] == -1)
                return false;
            break;
        case android.R.attr.paddingRight:
            padding[2] = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, -1);
            if (padding[2] == -1)
                return false;
            break;
        case android.R.attr.paddingBottom:
            padding[3] = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, -1);
            if (padding[3] == -1)
                return false;
            break;
        case R.attr.keyBackground:
            mKeyBackground = remoteTypedArray.getDrawable(remoteTypedArrayIndex);
            if (mKeyBackground == null)
                return false;
            break;
        case R.attr.keyHysteresisDistance:
            mKeyHysteresisDistance = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, -1);
            if (mKeyHysteresisDistance == -1)
                return false;
            break;
        case R.attr.verticalCorrection:
            mOriginalVerticalCorrection = mVerticalCorrection = remoteTypedArray
                    .getDimensionPixelOffset(remoteTypedArrayIndex, -1);
            if (mOriginalVerticalCorrection == -1)
                return false;
            break;
        case R.attr.keyTextSize:
            mKeyTextSize = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, -1);
            if (mKeyTextSize == -1)
                return false;
            // you might ask yourself "why did Menny sqrt root the factor?"
            // I'll tell you; the factor is mostly for the height, not the
            // font size,
            // but I also factorize the font size because I want the text to
            // be a little like
            // the key size.
            // the whole factor maybe too much, so I ease that a bit.
            if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
                mKeyTextSize = (float) (mKeyTextSize
                        * Math.sqrt(AnyApplication.getConfig().getKeysHeightFactorInLandscape()));
            else
                mKeyTextSize = (float) (mKeyTextSize
                        * Math.sqrt(AnyApplication.getConfig().getKeysHeightFactorInPortrait()));
            Logger.d(TAG, "AnySoftKeyboardTheme_keyTextSize " + mKeyTextSize);
            break;
        case R.attr.keyTextColor:
            mKeyTextColor = remoteTypedArray.getColorStateList(remoteTypedArrayIndex);
            if (mKeyTextColor == null) {
                mKeyTextColor = new ColorStateList(new int[][] { { 0 } },
                        new int[] { remoteTypedArray.getColor(remoteTypedArrayIndex, 0xFF000000) });
            }
            break;
        case R.attr.labelTextSize:
            mLabelTextSize = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, -1);
            if (mLabelTextSize == -1)
                return false;
            if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
                mLabelTextSize = mLabelTextSize * AnyApplication.getConfig().getKeysHeightFactorInLandscape();
            else
                mLabelTextSize = mLabelTextSize * AnyApplication.getConfig().getKeysHeightFactorInPortrait();
            break;
        case R.attr.keyboardNameTextSize:
            mKeyboardNameTextSize = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, -1);
            if (mKeyboardNameTextSize == -1)
                return false;
            if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
                mKeyboardNameTextSize = mKeyboardNameTextSize
                        * AnyApplication.getConfig().getKeysHeightFactorInLandscape();
            else
                mKeyboardNameTextSize = mKeyboardNameTextSize
                        * AnyApplication.getConfig().getKeysHeightFactorInPortrait();
            break;
        case R.attr.keyboardNameTextColor:
            mKeyboardNameTextColor = remoteTypedArray.getColor(remoteTypedArrayIndex, Color.WHITE);
            break;
        case R.attr.shadowColor:
            mShadowColor = remoteTypedArray.getColor(remoteTypedArrayIndex, 0);
            break;
        case R.attr.shadowRadius:
            mShadowRadius = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0);
            break;
        case R.attr.shadowOffsetX:
            mShadowOffsetX = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0);
            break;
        case R.attr.shadowOffsetY:
            mShadowOffsetY = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0);
            break;
        case R.attr.backgroundDimAmount:
            mBackgroundDimAmount = remoteTypedArray.getFloat(remoteTypedArrayIndex, -1f);
            if (mBackgroundDimAmount == -1f)
                return false;
            break;
        case R.attr.keyPreviewBackground:
            Drawable keyPreviewBackground = remoteTypedArray.getDrawable(remoteTypedArrayIndex);
            if (keyPreviewBackground == null)
                return false;
            mPreviewPopupTheme.setPreviewKeyBackground(keyPreviewBackground);
            break;
        case R.attr.keyPreviewTextColor:
            mPreviewPopupTheme.setPreviewKeyTextColor(remoteTypedArray.getColor(remoteTypedArrayIndex, 0xFFF));
            break;
        case R.attr.keyPreviewTextSize:
            mPreviewPopupTheme
                    .setPreviewKeyTextSize(remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, 0));
            break;
        case R.attr.keyPreviewLabelTextSize:
            mPreviewPopupTheme
                    .setPreviewLabelTextSize(remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, 0));
            break;
        case R.attr.keyPreviewOffset:
            mPreviewPopupTheme
                    .setVerticalOffset(remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0));
            break;
        case R.attr.previewAnimationType:
            int previewAnimationType = remoteTypedArray.getInteger(remoteTypedArrayIndex, -1);
            if (previewAnimationType == -1)
                return false;
            mPreviewPopupTheme.setPreviewAnimationType(previewAnimationType);
            break;
        case R.attr.keyTextStyle:
            int textStyle = remoteTypedArray.getInt(remoteTypedArrayIndex, 0);
            switch (textStyle) {
            case 0:
                mKeyTextStyle = Typeface.DEFAULT;
                break;
            case 1:
                mKeyTextStyle = Typeface.DEFAULT_BOLD;
                break;
            case 2:
                mKeyTextStyle = Typeface.defaultFromStyle(Typeface.ITALIC);
                break;
            default:
                mKeyTextStyle = Typeface.defaultFromStyle(textStyle);
                break;
            }
            mPreviewPopupTheme.setKeyStyle(mKeyTextStyle);
            break;
        case R.attr.keyHorizontalGap:
            float themeHorizontalKeyGap = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, -1);
            if (themeHorizontalKeyGap == -1)
                return false;
            mKeyboardDimens.setHorizontalKeyGap(themeHorizontalKeyGap);
            break;
        case R.attr.keyVerticalGap:
            float themeVerticalRowGap = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, -1);
            if (themeVerticalRowGap == -1)
                return false;
            mKeyboardDimens.setVerticalRowGap(themeVerticalRowGap);
            break;
        case R.attr.keyNormalHeight:
            int themeNormalKeyHeight = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, -1);
            if (themeNormalKeyHeight == -1)
                return false;
            mKeyboardDimens.setNormalKeyHeight(themeNormalKeyHeight);
            break;
        case R.attr.keyLargeHeight:
            int themeLargeKeyHeight = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, -1);
            if (themeLargeKeyHeight == -1)
                return false;
            mKeyboardDimens.setLargeKeyHeight(themeLargeKeyHeight);
            break;
        case R.attr.keySmallHeight:
            int themeSmallKeyHeight = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, -1);
            if (themeSmallKeyHeight == -1)
                return false;
            mKeyboardDimens.setSmallKeyHeight(themeSmallKeyHeight);
            break;
        case R.attr.hintTextSize:
            mHintTextSize = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, -1);
            if (mHintTextSize == -1)
                return false;
            if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
                mHintTextSize = mHintTextSize * AnyApplication.getConfig().getKeysHeightFactorInLandscape();
            else
                mHintTextSize = mHintTextSize * AnyApplication.getConfig().getKeysHeightFactorInPortrait();
            break;
        case R.attr.hintTextColor:
            mHintTextColor = remoteTypedArray.getColorStateList(remoteTypedArrayIndex);
            if (mHintTextColor == null) {
                mHintTextColor = new ColorStateList(new int[][] { { 0 } },
                        new int[] { remoteTypedArray.getColor(remoteTypedArrayIndex, 0xFF000000) });
            }
            break;
        case R.attr.hintLabelVAlign:
            mHintLabelVAlign = remoteTypedArray.getInt(remoteTypedArrayIndex, Gravity.BOTTOM);
            break;
        case R.attr.hintLabelAlign:
            mHintLabelAlign = remoteTypedArray.getInt(remoteTypedArrayIndex, Gravity.RIGHT);
            break;
        case R.attr.hintOverflowLabel:
            mHintOverflowLabel = remoteTypedArray.getString(remoteTypedArrayIndex);
            break;
        }
        return true;
    } catch (Exception e) {
        // on API changes, so the incompatible themes wont crash me..
        e.printStackTrace();
        return false;
    }
}

From source file:com.arlib.floatingsearchview.FloatingSearchView.java

private void applyXmlAttributes(AttributeSet attrs) {

    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.FloatingSearchView);

    try {//from  w  ww  .  j a va2s. c  o  m

        int searchBarWidth = a.getDimensionPixelSize(
                R.styleable.FloatingSearchView_floatingSearch_searchBarWidth,
                ViewGroup.LayoutParams.MATCH_PARENT);
        mQuerySection.getLayoutParams().width = searchBarWidth;
        mDivider.getLayoutParams().width = searchBarWidth;
        mSuggestionListContainer.getLayoutParams().width = searchBarWidth;
        int searchBarLeftMargin = a.getDimensionPixelSize(
                R.styleable.FloatingSearchView_floatingSearch_searchBarMarginLeft,
                ATTRS_SEARCH_BAR_MARGIN_DEFAULT);
        int searchBarTopMargin = a.getDimensionPixelSize(
                R.styleable.FloatingSearchView_floatingSearch_searchBarMarginTop,
                ATTRS_SEARCH_BAR_MARGIN_DEFAULT);
        int searchBarRightMargin = a.getDimensionPixelSize(
                R.styleable.FloatingSearchView_floatingSearch_searchBarMarginRight,
                ATTRS_SEARCH_BAR_MARGIN_DEFAULT);
        LayoutParams querySectionLP = (LayoutParams) mQuerySection.getLayoutParams();
        LayoutParams dividerLP = (LayoutParams) mDivider.getLayoutParams();
        LinearLayout.LayoutParams suggestListSectionLP = (LinearLayout.LayoutParams) mSuggestionsSection
                .getLayoutParams();
        int cardPadding = Util.dpToPx(CARD_VIEW_TOP_BOTTOM_SHADOW_HEIGHT);
        querySectionLP.setMargins(searchBarLeftMargin, searchBarTopMargin, searchBarRightMargin, 0);
        dividerLP.setMargins(searchBarLeftMargin + cardPadding, 0, searchBarRightMargin + cardPadding,
                ((MarginLayoutParams) mDivider.getLayoutParams()).bottomMargin);
        suggestListSectionLP.setMargins(searchBarLeftMargin, 0, searchBarRightMargin, 0);
        mQuerySection.setLayoutParams(querySectionLP);
        mDivider.setLayoutParams(dividerLP);
        mSuggestionsSection.setLayoutParams(suggestListSectionLP);

        setQueryTextSize(
                a.getDimensionPixelSize(R.styleable.FloatingSearchView_floatingSearch_searchInputTextSize,
                        ATTRS_QUERY_TEXT_SIZE_SP_DEFAULT));
        setSearchHint(a.getString(R.styleable.FloatingSearchView_floatingSearch_searchHint));
        setShowSearchKey(a.getBoolean(R.styleable.FloatingSearchView_floatingSearch_showSearchKey,
                ATTRS_SEARCH_BAR_SHOW_SEARCH_KEY_DEFAULT));
        setCloseSearchOnKeyboardDismiss(
                a.getBoolean(R.styleable.FloatingSearchView_floatingSearch_close_search_on_keyboard_dismiss,
                        ATTRS_DISMISS_ON_KEYBOARD_DISMISS_DEFAULT));
        setDismissOnOutsideClick(
                a.getBoolean(R.styleable.FloatingSearchView_floatingSearch_dismissOnOutsideTouch,
                        ATTRS_DISMISS_ON_OUTSIDE_TOUCH_DEFAULT));
        setSuggestionItemTextSize(
                a.getDimensionPixelSize(R.styleable.FloatingSearchView_floatingSearch_searchSuggestionTextSize,
                        Util.spToPx(ATTRS_SUGGESTION_TEXT_SIZE_SP_DEFAULT)));
        //noinspection ResourceType
        mLeftActionMode = a.getInt(R.styleable.FloatingSearchView_floatingSearch_leftActionMode,
                ATTRS_SEARCH_BAR_LEFT_ACTION_MODE_DEFAULT);
        if (a.hasValue(R.styleable.FloatingSearchView_floatingSearch_menu)) {
            mMenuId = a.getResourceId(R.styleable.FloatingSearchView_floatingSearch_menu, -1);
        }
        setDimBackground(a.getBoolean(R.styleable.FloatingSearchView_floatingSearch_dimBackground,
                ATTRS_SHOW_DIM_BACKGROUND_DEFAULT));
        setShowMoveUpSuggestion(a.getBoolean(R.styleable.FloatingSearchView_floatingSearch_showMoveSuggestionUp,
                ATTRS_SHOW_MOVE_UP_SUGGESTION_DEFAULT));
        this.mSuggestionSectionAnimDuration = a.getInt(
                R.styleable.FloatingSearchView_floatingSearch_suggestionsListAnimDuration,
                ATTRS_SUGGESTION_ANIM_DURATION_DEFAULT);
        setBackgroundColor(a.getColor(R.styleable.FloatingSearchView_floatingSearch_backgroundColor,
                Util.getColor(getContext(), R.color.background)));
        setLeftActionIconColor(a.getColor(R.styleable.FloatingSearchView_floatingSearch_leftActionColor,
                Util.getColor(getContext(), R.color.left_action_icon)));
        setActionMenuOverflowColor(
                a.getColor(R.styleable.FloatingSearchView_floatingSearch_actionMenuOverflowColor,
                        Util.getColor(getContext(), R.color.overflow_icon_color)));
        setMenuItemIconColor(a.getColor(R.styleable.FloatingSearchView_floatingSearch_menuItemIconColor,
                Util.getColor(getContext(), R.color.menu_icon_color)));
        setDividerColor(a.getColor(R.styleable.FloatingSearchView_floatingSearch_dividerColor,
                Util.getColor(getContext(), R.color.divider)));
        setClearBtnColor(a.getColor(R.styleable.FloatingSearchView_floatingSearch_clearBtnColor,
                Util.getColor(getContext(), R.color.clear_btn_color)));
        int viewTextColor = a.getColor(R.styleable.FloatingSearchView_floatingSearch_viewTextColor,
                Util.getColor(getContext(), R.color.dark_gray));
        setViewTextColor(viewTextColor);
        setQueryTextColor(a.getColor(R.styleable.FloatingSearchView_floatingSearch_viewSearchInputTextColor,
                viewTextColor));
        setSuggestionsTextColor(a.getColor(
                R.styleable.FloatingSearchView_floatingSearch_viewSuggestionItemTextColor, viewTextColor));
        setHintTextColor(a.getColor(R.styleable.FloatingSearchView_floatingSearch_hintTextColor,
                Util.getColor(getContext(), R.color.hint_color)));
        setSuggestionRightIconColor(
                a.getColor(R.styleable.FloatingSearchView_floatingSearch_suggestionRightIconColor,
                        Util.getColor(getContext(), R.color.gray_active_icon)));
    } finally {
        a.recycle();
    }
}

From source file:com.appunite.list.AbsHorizontalListView.java

public AbsHorizontalListView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    initAbsListView();/*from   w  w  w.j  av a  2s  .  c o  m*/

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AbsListView, defStyle, 0);

    Drawable d = a.getDrawable(R.styleable.AbsListView_listSelector);
    if (d != null) {
        setSelector(d);
    }

    mDrawSelectorOnTop = a.getBoolean(R.styleable.AbsListView_drawSelectorOnTop, false);

    boolean stackFromRight = a.getBoolean(R.styleable.AbsListView_stackFromBottom, false);
    setStackFromRight(stackFromRight);

    boolean scrollingCacheEnabled = a.getBoolean(R.styleable.AbsListView_scrollingCache, true);
    setScrollingCacheEnabled(scrollingCacheEnabled);

    boolean useTextFilter = a.getBoolean(R.styleable.AbsListView_textFilterEnabled, false);
    setTextFilterEnabled(useTextFilter);

    int transcriptMode = a.getInt(R.styleable.AbsListView_transcriptMode, TRANSCRIPT_MODE_DISABLED);
    setTranscriptMode(transcriptMode);

    int color = a.getColor(R.styleable.AbsListView_cacheColorHint, 0);
    setCacheColorHint(color);

    boolean smoothScrollbar = a.getBoolean(R.styleable.AbsListView_smoothScrollbar, true);
    setSmoothScrollbarEnabled(smoothScrollbar);

    setChoiceMode(a.getInt(R.styleable.AbsListView_choiceMode, CHOICE_MODE_NONE));

    a.recycle();
}

From source file:com.appunite.list.AbsListView.java

public AbsListView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    initAbsListView();//from   w ww.  j a v  a 2 s . c o  m

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AbsListView, defStyle, 0);

    Drawable d = a.getDrawable(R.styleable.AbsListView_listSelector);
    if (d != null) {
        setSelector(d);
    }

    mDrawSelectorOnTop = a.getBoolean(R.styleable.AbsListView_drawSelectorOnTop, false);

    boolean stackFromBottom = a.getBoolean(R.styleable.AbsListView_stackFromBottom, false);
    setStackFromBottom(stackFromBottom);

    boolean scrollingCacheEnabled = a.getBoolean(R.styleable.AbsListView_scrollingCache, true);
    setScrollingCacheEnabled(scrollingCacheEnabled);

    boolean useTextFilter = a.getBoolean(R.styleable.AbsListView_textFilterEnabled, false);
    setTextFilterEnabled(useTextFilter);

    int transcriptMode = a.getInt(R.styleable.AbsListView_transcriptMode, TRANSCRIPT_MODE_DISABLED);
    setTranscriptMode(transcriptMode);

    int color = a.getColor(R.styleable.AbsListView_cacheColorHint, 0);
    setCacheColorHint(color);

    boolean enableFastScroll = a.getBoolean(R.styleable.AbsListView_fastScrollEnabled, false);
    setFastScrollEnabled(enableFastScroll);

    boolean smoothScrollbar = a.getBoolean(R.styleable.AbsListView_smoothScrollbar, true);
    setSmoothScrollbarEnabled(smoothScrollbar);

    setChoiceMode(a.getInt(R.styleable.AbsListView_choiceMode, CHOICE_MODE_NONE));
    setFastScrollAlwaysVisible(a.getBoolean(R.styleable.AbsListView_fastScrollAlwaysVisible, false));

    a.recycle();
}