Example usage for android.content.res TypedArray getFloat

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

Introduction

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

Prototype

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

Source Link

Document

Retrieve the float value for the attribute at index.

Usage

From source file:devlight.io.library.ntb.NavigationTabBar.java

@SuppressWarnings({ "ResourceAsColor", "ResourceType" })
public NavigationTabBar(final Context context, final AttributeSet attrs, final int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    //Init NTB/*ww w  .  ja v  a2s .  c o m*/

    // Always draw
    setWillNotDraw(false);
    // Speed and fix for pre 17 API
    ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, null);
    setLayerType(LAYER_TYPE_SOFTWARE, null);

    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NavigationTabBar);
    try {
        setIsTitled(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_titled, false));
        setIsBadged(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badged, false));
        setIsScaled(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_scaled, true));
        setIsTinted(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_tinted, true));
        setIsSwiped(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_swiped, true));
        setTitleSize(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_title_size, AUTO_SIZE));
        setIsBadgeUseTypeface(
                typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badge_use_typeface, false));

        setTitleMode(typedArray.getInt(R.styleable.NavigationTabBar_ntb_title_mode, TitleMode.ALL_INDEX));
        setBadgeSize(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_badge_size, AUTO_SIZE));
        setBadgePosition(
                typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_position, BadgePosition.RIGHT_INDEX));
        setBadgeGravity(
                typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_gravity, BadgeGravity.TOP_INDEX));
        setBadgeBgColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_badge_bg_color, AUTO_COLOR));
        setBadgeTitleColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_badge_title_color, AUTO_COLOR));

        setTypeface(typedArray.getString(R.styleable.NavigationTabBar_ntb_typeface));
        setInactiveColor(
                typedArray.getColor(R.styleable.NavigationTabBar_ntb_inactive_color, DEFAULT_INACTIVE_COLOR));
        setActiveColor(
                typedArray.getColor(R.styleable.NavigationTabBar_ntb_active_color, DEFAULT_ACTIVE_COLOR));
        setBgColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_bg_color, DEFAULT_BG_COLOR));
        setAnimationDuration(typedArray.getInteger(R.styleable.NavigationTabBar_ntb_animation_duration,
                DEFAULT_ANIMATION_DURATION));
        setCornersRadius(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_corners_radius, 0.0F));
        setIconSizeFraction(
                typedArray.getFloat(R.styleable.NavigationTabBar_ntb_icon_size_fraction, AUTO_SCALE));

        // Init animator
        mAnimator.setFloatValues(MIN_FRACTION, MAX_FRACTION);
        mAnimator.setInterpolator(new LinearInterpolator());
        mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(final ValueAnimator animation) {
                updateIndicatorPosition((Float) animation.getAnimatedValue());
            }
        });

        // Set preview models
        if (isInEditMode()) {
            // Get preview colors
            String[] previewColors = null;
            try {
                final int previewColorsId = typedArray
                        .getResourceId(R.styleable.NavigationTabBar_ntb_preview_colors, 0);
                previewColors = previewColorsId == 0 ? null
                        : typedArray.getResources().getStringArray(previewColorsId);
            } catch (Exception exception) {
                previewColors = null;
                exception.printStackTrace();
            } finally {
                if (previewColors == null)
                    previewColors = typedArray.getResources().getStringArray(R.array.default_preview);

                for (String previewColor : previewColors)
                    mModels.add(new Model.Builder(null, Color.parseColor(previewColor)).build());
                requestLayout();
            }
        }
    } finally {
        typedArray.recycle();
    }
}

From source file:co.ceryle.radiorealbutton.library.RadioRealButtonGroup.java

private void getAttributes(AttributeSet attrs) {
    TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.RadioRealButtonGroup);

    bottomLineColor = ta.getColor(R.styleable.RadioRealButtonGroup_rrbg_bottomLineColor, Color.GRAY);
    bottomLineSize = ta.getDimensionPixelSize(R.styleable.RadioRealButtonGroup_rrbg_bottomLineSize, 0);
    bottomLineBringToFront = ta.getBoolean(R.styleable.RadioRealButtonGroup_rrbg_bottomLineBringToFront, false);
    bottomLineRadius = ta.getDimensionPixelSize(R.styleable.RadioRealButtonGroup_rrbg_bottomLineRadius, 0);

    selectorColor = ta.getColor(R.styleable.RadioRealButtonGroup_rrbg_selectorColor, Color.GRAY);
    selectorBringToFront = ta.getBoolean(R.styleable.RadioRealButtonGroup_rrbg_selectorBringToFront, false);
    selectorAboveOfBottomLine = ta.getBoolean(R.styleable.RadioRealButtonGroup_rrbg_selectorAboveOfBottomLine,
            false);/*from w ww.  j a  v  a 2 s  .  co  m*/
    selectorSize = ta.getDimensionPixelSize(R.styleable.RadioRealButtonGroup_rrbg_selectorSize, 12);
    selectorRadius = ta.getDimensionPixelSize(R.styleable.RadioRealButtonGroup_rrbg_selectorRadius, 0);

    animateSelector = ta.getInt(R.styleable.RadioRealButtonGroup_rrbg_animateSelector, 0);
    animateSelectorDuration = ta.getInt(R.styleable.RadioRealButtonGroup_rrbg_animateSelector_duration, 500);
    animateSelectorDelay = ta.getInt(R.styleable.RadioRealButtonGroup_rrbg_animateSelector_delay, 0);

    dividerSize = ta.getDimensionPixelSize(R.styleable.RadioRealButtonGroup_rrbg_dividerSize, 0);
    boolean hasDividerSize = ta.hasValue(R.styleable.RadioRealButtonGroup_rrbg_dividerSize);
    dividerRadius = ta.getDimensionPixelSize(R.styleable.RadioRealButtonGroup_rrbg_dividerRadius, 0);
    dividerPadding = ta.getDimensionPixelSize(R.styleable.RadioRealButtonGroup_rrbg_dividerPadding, 30);
    dividerColor = ta.getColor(R.styleable.RadioRealButtonGroup_rrbg_dividerColor, Color.TRANSPARENT);
    dividerBackgroundColor = ta.getColor(R.styleable.RadioRealButtonGroup_rrbg_dividerBackgroundColor,
            Color.WHITE);
    hasDividerBackgroundColor = ta.hasValue(R.styleable.RadioRealButtonGroup_rrbg_dividerBackgroundColor);

    selectorDividerSize = ta.getDimensionPixelSize(R.styleable.RadioRealButtonGroup_rrbg_selectorDividerSize,
            dividerSize);
    if (!hasDividerSize) {
        dividerSize = selectorDividerSize;
    }
    selectorDividerRadius = ta
            .getDimensionPixelSize(R.styleable.RadioRealButtonGroup_rrbg_selectorDividerRadius, 0);
    selectorDividerPadding = ta
            .getDimensionPixelSize(R.styleable.RadioRealButtonGroup_rrbg_selectorDividerPadding, 0);
    selectorDividerColor = ta.getColor(R.styleable.RadioRealButtonGroup_rrbg_selectorDividerColor,
            Color.TRANSPARENT);

    radius = ta.getDimension(R.styleable.RadioRealButtonGroup_rrbg_radius, 0);

    animateImages = ta.getInt(R.styleable.RadioRealButtonGroup_rrbg_animateDrawables_enter, 0);
    hasAnimateImages = ta.hasValue(R.styleable.RadioRealButtonGroup_rrbg_animateDrawables_enter);
    animateImagesExit = ta.getInt(R.styleable.RadioRealButtonGroup_rrbg_animateDrawables_exit, 0);
    animateImagesDuration = ta.getInt(R.styleable.RadioRealButtonGroup_rrbg_animateDrawables_enterDuration,
            500);
    animateImagesExitDuration = ta.getInt(R.styleable.RadioRealButtonGroup_rrbg_animateDrawables_exitDuration,
            100);
    animateImagesScale = ta.getFloat(R.styleable.RadioRealButtonGroup_rrbg_animateDrawables_scale, 1.2f);

    animateTexts = ta.getInt(R.styleable.RadioRealButtonGroup_rrbg_animateTexts_enter, 0);
    hasAnimateTexts = ta.hasValue(R.styleable.RadioRealButtonGroup_rrbg_animateTexts_enter);
    animateTextsExit = ta.getInt(R.styleable.RadioRealButtonGroup_rrbg_animateTexts_exit, 0);
    animateTextsDuration = ta.getInt(R.styleable.RadioRealButtonGroup_rrbg_animateTexts_enterDuration, 500);
    animateTextsExitDuration = ta.getInt(R.styleable.RadioRealButtonGroup_rrbg_animateTexts_exitDuration, 100);
    animateTextsScale = ta.getFloat(R.styleable.RadioRealButtonGroup_rrbg_animateTexts_scale, 1.2f);

    lastPosition = initialPosition = ta.getInt(R.styleable.RadioRealButtonGroup_rrbg_checkedPosition, -1);
    checkedButtonId = ta.getResourceId(R.styleable.RadioRealButtonGroup_rrbg_checkedButton, NO_ID);

    buttonPadding = ta.getDimensionPixelSize(R.styleable.RadioRealButtonGroup_rrbg_buttonsPadding, 0);
    buttonPaddingLeft = ta.getDimensionPixelSize(R.styleable.RadioRealButtonGroup_rrbg_buttonsPaddingLeft, 0);
    buttonPaddingRight = ta.getDimensionPixelSize(R.styleable.RadioRealButtonGroup_rrbg_buttonsPaddingRight, 0);
    buttonPaddingTop = ta.getDimensionPixelSize(R.styleable.RadioRealButtonGroup_rrbg_buttonsPaddingTop, 0);
    buttonPaddingBottom = ta.getDimensionPixelSize(R.styleable.RadioRealButtonGroup_rrbg_buttonsPaddingBottom,
            0);

    hasPadding = ta.hasValue(R.styleable.RadioRealButtonGroup_rrbg_buttonsPadding);
    hasPaddingLeft = ta.hasValue(R.styleable.RadioRealButtonGroup_rrbg_buttonsPaddingLeft);
    hasPaddingRight = ta.hasValue(R.styleable.RadioRealButtonGroup_rrbg_buttonsPaddingRight);
    hasPaddingTop = ta.hasValue(R.styleable.RadioRealButtonGroup_rrbg_buttonsPaddingTop);
    hasPaddingBottom = ta.hasValue(R.styleable.RadioRealButtonGroup_rrbg_buttonsPaddingBottom);

    groupBackgroundColor = ta.getColor(R.styleable.RadioRealButtonGroup_rrbg_backgroundColor, Color.WHITE);

    selectorTop = ta.getBoolean(R.styleable.RadioRealButtonGroup_rrbg_selectorTop, false);
    selectorBottom = ta.getBoolean(R.styleable.RadioRealButtonGroup_rrbg_selectorBottom, true);

    borderSize = ta.getDimensionPixelSize(R.styleable.RadioRealButtonGroup_rrbg_borderSize,
            ConversionHelper.dpToPx(getContext(), 1));
    borderColor = ta.getColor(R.styleable.RadioRealButtonGroup_rrbg_borderColor, Color.BLACK);

    boolean hasBorderSize = ta.hasValue(R.styleable.RadioRealButtonGroup_rrbg_borderSize);
    boolean hasBorderColor = ta.hasValue(R.styleable.RadioRealButtonGroup_rrbg_borderColor);
    hasBorder = hasBorderColor || hasBorderSize;

    clickable = ta.getBoolean(R.styleable.RadioRealButtonGroup_android_clickable, true);
    hasClickable = ta.hasValue(R.styleable.RadioRealButtonGroup_android_clickable);
    enabled = ta.getBoolean(R.styleable.RadioRealButtonGroup_android_enabled, true);
    hasEnabled = ta.hasValue(R.styleable.RadioRealButtonGroup_android_enabled);

    animationType = ta.getInt(R.styleable.RadioRealButtonGroup_rrbg_selectorAnimationType, 0);
    enableDeselection = ta.getBoolean(R.styleable.RadioRealButtonGroup_rrbg_enableDeselection, false);

    hasAnimation = ta.getBoolean(R.styleable.RadioRealButtonGroup_rrbg_animate, true);

    selectorFullSize = ta.getBoolean(R.styleable.RadioRealButtonGroup_rrbg_selectorFullSize, false);

    ta.recycle();
}

From source file:com.waz.zclient.views.images.CircularSeekBar.java

/**
 * Initialize the CircularSeekBar with the attributes from the XML style.
 * Uses the defaults defined at the top of this file when an attribute is not specified by the user.
 *
 * @param attrArray TypedArray containing the attributes.
 *///w ww.ja v a2 s  .  co m
protected void initAttributes(TypedArray attrArray) {
    circleXRadius = attrArray.getDimension(R.styleable.CircularSeekBar_circle_x_radius,
            DEFAULT_CIRCLE_X_RADIUS * dpToPxScale);
    circleYRadius = attrArray.getDimension(R.styleable.CircularSeekBar_circle_y_radius,
            DEFAULT_CIRCLE_Y_RADIUS * dpToPxScale);
    pointerRadius = attrArray.getDimension(R.styleable.CircularSeekBar_pointer_radius,
            DEFAULT_POINTER_RADIUS * dpToPxScale);
    pointerHaloWidth = attrArray.getDimension(R.styleable.CircularSeekBar_pointer_halo_width,
            DEFAULT_POINTER_HALO_WIDTH * dpToPxScale);
    pointerHaloBorderWidth = attrArray.getDimension(R.styleable.CircularSeekBar_pointer_halo_border_width,
            DEFAULT_POINTER_HALO_BORDER_WIDTH * dpToPxScale);
    circleStrokeWidth = attrArray.getDimension(R.styleable.CircularSeekBar_circle_stroke_width,
            DEFAULT_CIRCLE_STROKE_WIDTH * dpToPxScale);

    String tempColor = attrArray.getString(R.styleable.CircularSeekBar_pointer_color);
    if (tempColor != null) {
        try {
            pointerColor = Color.parseColor(tempColor);
        } catch (IllegalArgumentException e) {
            pointerColor = DEFAULT_POINTER_COLOR;
        }
    }

    tempColor = attrArray.getString(R.styleable.CircularSeekBar_pointer_halo_color);
    if (tempColor != null) {
        try {
            pointerHaloColor = Color.parseColor(tempColor);
        } catch (IllegalArgumentException e) {
            pointerHaloColor = DEFAULT_POINTER_HALO_COLOR;
        }
    }

    tempColor = attrArray.getString(R.styleable.CircularSeekBar_pointer_halo_color_ontouch);
    if (tempColor != null) {
        try {
            pointerHaloColorOnTouch = Color.parseColor(tempColor);
        } catch (IllegalArgumentException e) {
            pointerHaloColorOnTouch = DEFAULT_POINTER_HALO_COLOR_ONTOUCH;
        }
    }

    tempColor = attrArray.getString(R.styleable.CircularSeekBar_circle_color);
    if (tempColor != null) {
        try {
            circleColor = Color.parseColor(tempColor);
        } catch (IllegalArgumentException e) {
            circleColor = DEFAULT_CIRCLE_COLOR;
        }
    }

    tempColor = attrArray.getString(R.styleable.CircularSeekBar_circle_progress_color);
    if (tempColor != null) {
        try {
            circleProgressColor = Color.parseColor(tempColor);
        } catch (IllegalArgumentException e) {
            circleProgressColor = DEFAULT_CIRCLE_PROGRESS_COLOR;
        }
    }

    tempColor = attrArray.getString(R.styleable.CircularSeekBar_circle_fill);
    if (tempColor != null) {
        try {
            circleFillColor = Color.parseColor(tempColor);
        } catch (IllegalArgumentException e) {
            circleFillColor = DEFAULT_CIRCLE_FILL_COLOR;
        }
    }

    pointerAlpha = Color.alpha(pointerHaloColor);

    pointerAlphaOnTouch = attrArray.getInt(R.styleable.CircularSeekBar_pointer_alpha_ontouch,
            DEFAULT_POINTER_ALPHA_ONTOUCH);
    if (pointerAlphaOnTouch > 255 || pointerAlphaOnTouch < 0) {
        pointerAlphaOnTouch = DEFAULT_POINTER_ALPHA_ONTOUCH;
    }

    max = attrArray.getInt(R.styleable.CircularSeekBar_max, DEFAULT_MAX);
    progress = attrArray.getInt(R.styleable.CircularSeekBar_progress, DEFAULT_PROGRESS);
    customRadii = attrArray.getBoolean(R.styleable.CircularSeekBar_use_custom_radii, DEFAULT_USE_CUSTOM_RADII);
    maintainEqualCircle = attrArray.getBoolean(R.styleable.CircularSeekBar_maintain_equal_circle,
            DEFAULT_MAINTAIN_EQUAL_CIRCLE);
    moveOutsideCircle = attrArray.getBoolean(R.styleable.CircularSeekBar_move_outside_circle,
            DEFAULT_MOVE_OUTSIDE_CIRCLE);

    // Modulo 360 right now to avoid constant conversion
    startAngle = ((360f
            + (attrArray.getFloat((R.styleable.CircularSeekBar_start_angle), DEFAULT_START_ANGLE) % 360f))
            % 360f);
    endAngle = ((360f + (attrArray.getFloat((R.styleable.CircularSeekBar_end_angle), DEFAULT_END_ANGLE) % 360f))
            % 360f);

    if (MathUtils.floatEqual(startAngle, endAngle)) {
        //startAngle = startAngle + 1f;
        endAngle = endAngle - .1f;
    }
    final GestureDetector.SimpleOnGestureListener gestureListener = new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            if (onArtClickListener != null) {
                onArtClickListener.onSingleClick();
                return true;
            }
            return false;
        }

        @Override
        public boolean onDoubleTap(MotionEvent e) {
            if (onArtClickListener != null) {
                onArtClickListener.onDoubleClick();
            }
            return super.onDoubleTap(e);
        }

        @Override
        public void onLongPress(MotionEvent e) {
            performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
            if (onArtLongClickListener != null) {
                onArtLongClickListener.onLongClick(CircularSeekBar.this);
            }
        }
    };
    gestureDetector = new GestureDetectorCompat(getContext(), gestureListener);
    gestureDetector.setOnDoubleTapListener(gestureListener);
}

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 o  m*/
            }
        } 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 {//from w  ww.  j  av  a  2s  .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:org.kde.necessitas.ministro.ExtractStyle.java

public JSONObject extractTextAppearanceInformations(String styleName, String qtClass, AttributeSet attribSet,
        int textAppearance) {
    JSONObject json = new JSONObject();
    try {/*from w  ww .  j a v a2 s  .c  om*/
        int textColorHighlight = 0; //
        ColorStateList textColor = null; //
        ColorStateList textColorHint = null; //
        ColorStateList textColorLink = null; //
        int textSize = 15; //
        int typefaceIndex = -1; //
        int styleIndex = -1;
        boolean allCaps = false;

        Class<?> attrClass = Class.forName("android.R$attr");
        int styleId = attrClass.getDeclaredField(styleName).getInt(null);

        extractViewInformations(styleName, styleId, json, qtClass, attribSet);

        int[] textViewAttrs = (int[]) styleableClass.getDeclaredField("TextView").get(null);
        TypedArray a = m_theme.obtainStyledAttributes(null, textViewAttrs, styleId, 0);

        TypedArray appearance = null;
        if (-1 == textAppearance)
            textAppearance = a
                    .getResourceId(styleableClass.getDeclaredField("TextView_textAppearance").getInt(null), -1);

        if (textAppearance != -1)
            appearance = m_theme.obtainStyledAttributes(textAppearance,
                    (int[]) styleableClass.getDeclaredField("TextAppearance").get(null));

        if (appearance != null) {
            int n = appearance.getIndexCount();
            for (int i = 0; i < n; i++) {
                int attr = appearance.getIndex(i);
                if (attr == TextAppearance_textColorHighlight)
                    textColorHighlight = appearance.getColor(attr, textColorHighlight);
                else if (attr == TextAppearance_textColor)
                    textColor = appearance.getColorStateList(attr);
                else if (attr == TextAppearance_textColorHint)
                    textColorHint = appearance.getColorStateList(attr);
                else if (attr == TextAppearance_textColorLink)
                    textColorLink = appearance.getColorStateList(attr);
                else if (attr == TextAppearance_textSize)
                    textSize = appearance.getDimensionPixelSize(attr, textSize);
                else if (attr == TextAppearance_typeface)
                    typefaceIndex = appearance.getInt(attr, -1);
                else if (attr == TextAppearance_textStyle)
                    styleIndex = appearance.getInt(attr, -1);
                else if (attr == TextAppearance_textAllCaps)
                    allCaps = appearance.getBoolean(attr, false);
            }
            appearance.recycle();
        }

        int n = a.getIndexCount();

        for (int i = 0; i < n; i++) {
            int attr = a.getIndex(i);

            if (attr == TextView_editable)
                json.put("TextView_editable", a.getBoolean(attr, false));
            else if (attr == TextView_inputMethod)
                json.put("TextView_inputMethod", a.getText(attr));
            else if (attr == TextView_numeric)
                json.put("TextView_numeric", a.getInt(attr, 0));
            else if (attr == TextView_digits)
                json.put("TextView_digits", a.getText(attr));
            else if (attr == TextView_phoneNumber)
                json.put("TextView_phoneNumber", a.getBoolean(attr, false));
            else if (attr == TextView_autoText)
                json.put("TextView_autoText", a.getBoolean(attr, false));
            else if (attr == TextView_capitalize)
                json.put("TextView_capitalize", a.getInt(attr, -1));
            else if (attr == TextView_bufferType)
                json.put("TextView_bufferType", a.getInt(attr, 0));
            else if (attr == TextView_selectAllOnFocus)
                json.put("TextView_selectAllOnFocus", a.getBoolean(attr, false));
            else if (attr == TextView_autoLink)
                json.put("TextView_autoLink", a.getInt(attr, 0));
            else if (attr == TextView_linksClickable)
                json.put("TextView_linksClickable", a.getBoolean(attr, true));
            else if (attr == TextView_linksClickable)
                json.put("TextView_linksClickable", a.getBoolean(attr, true));
            else if (attr == TextView_drawableLeft)
                json.put("TextView_drawableLeft",
                        getDrawable(a.getDrawable(attr), styleName + "_TextView_drawableLeft"));
            else if (attr == TextView_drawableTop)
                json.put("TextView_drawableTop",
                        getDrawable(a.getDrawable(attr), styleName + "_TextView_drawableTop"));
            else if (attr == TextView_drawableRight)
                json.put("TextView_drawableRight",
                        getDrawable(a.getDrawable(attr), styleName + "_TextView_drawableRight"));
            else if (attr == TextView_drawableBottom)
                json.put("TextView_drawableBottom",
                        getDrawable(a.getDrawable(attr), styleName + "_TextView_drawableBottom"));
            else if (attr == TextView_drawableStart)
                json.put("TextView_drawableStart",
                        getDrawable(a.getDrawable(attr), styleName + "_TextView_drawableStart"));
            else if (attr == TextView_drawableEnd)
                json.put("TextView_drawableEnd",
                        getDrawable(a.getDrawable(attr), styleName + "_TextView_drawableEnd"));
            else if (attr == TextView_drawablePadding)
                json.put("TextView_drawablePadding", a.getDimensionPixelSize(attr, 0));
            else if (attr == TextView_textCursorDrawable)
                json.put("TextView_textCursorDrawable",
                        getDrawable(m_context.getResources().getDrawable(a.getResourceId(attr, 0)),
                                styleName + "_TextView_textCursorDrawable"));
            else if (attr == TextView_maxLines)
                json.put("TextView_maxLines", a.getInt(attr, -1));
            else if (attr == TextView_maxHeight)
                json.put("TextView_maxHeight", a.getDimensionPixelSize(attr, -1));
            else if (attr == TextView_lines)
                json.put("TextView_lines", a.getInt(attr, -1));
            else if (attr == TextView_height)
                json.put("TextView_height", a.getDimensionPixelSize(attr, -1));
            else if (attr == TextView_minLines)
                json.put("TextView_minLines", a.getInt(attr, -1));
            else if (attr == TextView_minHeight)
                json.put("TextView_minHeight", a.getDimensionPixelSize(attr, -1));
            else if (attr == TextView_maxEms)
                json.put("TextView_maxEms", a.getInt(attr, -1));
            else if (attr == TextView_maxWidth)
                json.put("TextView_maxWidth", a.getDimensionPixelSize(attr, -1));
            else if (attr == TextView_ems)
                json.put("TextView_ems", a.getInt(attr, -1));
            else if (attr == TextView_width)
                json.put("TextView_width", a.getDimensionPixelSize(attr, -1));
            else if (attr == TextView_minEms)
                json.put("TextView_minEms", a.getInt(attr, -1));
            else if (attr == TextView_minWidth)
                json.put("TextView_minWidth", a.getDimensionPixelSize(attr, -1));
            else if (attr == TextView_gravity)
                json.put("TextView_gravity", a.getInt(attr, -1));
            else if (attr == TextView_hint)
                json.put("TextView_hint", a.getText(attr));
            else if (attr == TextView_text)
                json.put("TextView_text", a.getText(attr));
            else if (attr == TextView_scrollHorizontally)
                json.put("TextView_scrollHorizontally", a.getBoolean(attr, false));
            else if (attr == TextView_singleLine)
                json.put("TextView_singleLine", a.getBoolean(attr, false));
            else if (attr == TextView_ellipsize)
                json.put("TextView_ellipsize", a.getInt(attr, -1));
            else if (attr == TextView_marqueeRepeatLimit)
                json.put("TextView_marqueeRepeatLimit", a.getInt(attr, 3));
            else if (attr == TextView_includeFontPadding)
                json.put("TextView_includeFontPadding", a.getBoolean(attr, true));
            else if (attr == TextView_cursorVisible)
                json.put("TextView_cursorVisible", a.getBoolean(attr, true));
            else if (attr == TextView_maxLength)
                json.put("TextView_maxLength", a.getInt(attr, -1));
            else if (attr == TextView_textScaleX)
                json.put("TextView_textScaleX", a.getFloat(attr, 1.0f));
            else if (attr == TextView_freezesText)
                json.put("TextView_freezesText", a.getBoolean(attr, false));
            else if (attr == TextView_shadowColor)
                json.put("TextView_shadowColor", a.getInt(attr, 0));
            else if (attr == TextView_shadowDx)
                json.put("TextView_shadowDx", a.getFloat(attr, 0));
            else if (attr == TextView_shadowDy)
                json.put("TextView_shadowDy", a.getFloat(attr, 0));
            else if (attr == TextView_shadowRadius)
                json.put("TextView_shadowRadius", a.getFloat(attr, 0));
            else if (attr == TextView_enabled)
                json.put("TextView_enabled", a.getBoolean(attr, true));
            else if (attr == TextView_textColorHighlight)
                textColorHighlight = a.getColor(attr, textColorHighlight);
            else if (attr == TextView_textColor)
                textColor = a.getColorStateList(attr);
            else if (attr == TextView_textColorHint)
                textColorHint = a.getColorStateList(attr);
            else if (attr == TextView_textColorLink)
                textColorLink = a.getColorStateList(attr);
            else if (attr == TextView_textSize)
                textSize = a.getDimensionPixelSize(attr, textSize);
            else if (attr == TextView_typeface)
                typefaceIndex = a.getInt(attr, typefaceIndex);
            else if (attr == TextView_textStyle)
                styleIndex = a.getInt(attr, styleIndex);
            else if (attr == TextView_password)
                json.put("TextView_password", a.getBoolean(attr, false));
            else if (attr == TextView_lineSpacingExtra)
                json.put("TextView_lineSpacingExtra", a.getDimensionPixelSize(attr, 0));
            else if (attr == TextView_lineSpacingMultiplier)
                json.put("TextView_lineSpacingMultiplier", a.getFloat(attr, 1.0f));
            else if (attr == TextView_inputType)
                json.put("TextView_inputType", a.getInt(attr, EditorInfo.TYPE_NULL));
            else if (attr == TextView_imeOptions)
                json.put("TextView_imeOptions", a.getInt(attr, EditorInfo.IME_NULL));
            else if (attr == TextView_imeActionLabel)
                json.put("TextView_imeActionLabel", a.getText(attr));
            else if (attr == TextView_imeActionId)
                json.put("TextView_imeActionId", a.getInt(attr, 0));
            else if (attr == TextView_privateImeOptions)
                json.put("TextView_privateImeOptions", a.getString(attr));
            else if (attr == TextView_textSelectHandleLeft && styleName.equals("textViewStyle"))
                json.put("TextView_textSelectHandleLeft",
                        getDrawable(m_context.getResources().getDrawable(a.getResourceId(attr, 0)),
                                styleName + "_TextView_textSelectHandleLeft"));
            else if (attr == TextView_textSelectHandleRight && styleName.equals("textViewStyle"))
                json.put("TextView_textSelectHandleRight",
                        getDrawable(m_context.getResources().getDrawable(a.getResourceId(attr, 0)),
                                styleName + "_TextView_textSelectHandleRight"));
            else if (attr == TextView_textSelectHandle && styleName.equals("textViewStyle"))
                json.put("TextView_textSelectHandle",
                        getDrawable(m_context.getResources().getDrawable(a.getResourceId(attr, 0)),
                                styleName + "_TextView_textSelectHandle"));
            else if (attr == TextView_textIsSelectable)
                json.put("TextView_textIsSelectable", a.getBoolean(attr, false));
            else if (attr == TextView_textAllCaps)
                allCaps = a.getBoolean(attr, false);
        }
        a.recycle();

        json.put("TextAppearance_textColorHighlight", textColorHighlight);
        json.put("TextAppearance_textColor", getColorStateList(textColor));
        json.put("TextAppearance_textColorHint", getColorStateList(textColorHint));
        json.put("TextAppearance_textColorLink", getColorStateList(textColorLink));
        json.put("TextAppearance_textSize", textSize);
        json.put("TextAppearance_typeface", typefaceIndex);
        json.put("TextAppearance_textStyle", styleIndex);
        json.put("TextAppearance_textAllCaps", allCaps);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return json;
}

From source file:com.github.yggie.pulltorefresh.PullListFragment.java

/**
 * Applies the xml attributes sent through the Bundle object
 *
 * @param a The TypedArray object containing the xml attributes
 *//*  w w w  .  j a v a  2  s.c o m*/

private void parseXmlAttributes(final TypedArray a) {
    if (a != null) {
        /** apply the background color */
        final int backgroundColor = a.getColor(R.styleable.PullListFragment_list_backgroundColor, 0);
        if (backgroundColor != 0) {
            setListViewBackgroundColor(backgroundColor);
        }

        /**
         * Applies the padding, more specific padding has higher priority
         */

        int paddingTop = listView.getPaddingTop();
        int paddingBottom = listView.getPaddingBottom();
        int paddingLeft = listView.getPaddingLeft();
        int paddingRight = listView.getPaddingRight();

        final int padding = a.getDimensionPixelSize(R.styleable.PullListFragment_list_padding, -1);
        if (padding != -1) {
            paddingTop = padding;
            paddingBottom = padding;
            paddingLeft = padding;
            paddingRight = padding;
        }

        paddingTop = a.getDimensionPixelSize(R.styleable.PullListFragment_list_paddingTop, paddingTop);
        paddingBottom = a.getDimensionPixelSize(R.styleable.PullListFragment_list_paddingBottom, paddingBottom);
        paddingLeft = a.getDimensionPixelSize(R.styleable.PullListFragment_list_paddingLeft, paddingLeft);
        paddingRight = a.getDimensionPixelSize(R.styleable.PullListFragment_list_paddingRight, paddingRight);

        listView.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);

        /**
         * apply pull modes
         */

        final int topMode = a.getInt(R.styleable.PullListFragment_top_mode, MODE_PULL);
        if (topMode != MODE_PULL) {
            enableTopPull(false);
        }

        final int bottomMode = a.getInt(R.styleable.PullListFragment_bottom_mode, MODE_PULL);
        if (bottomMode != MODE_PULL) {
            enableBottomPull(false);
        }

        /**
         * apply custom pulled views
         */

        final int topViewResId = a.getResourceId(R.styleable.PullListFragment_top_view, -1);
        if (topViewResId != -1) {
            setTopPulledView(topViewResId);
        }

        final int bottomViewResId = a.getResourceId(R.styleable.PullListFragment_bottom_view, -1);
        if (bottomViewResId != -1) {
            setBottomPulledView(bottomViewResId);
        }

        /**
         * apply custom text to default views
         */

        if (topManager != null) {
            final String pullStartedText = a.getString(R.styleable.PullListFragment_top_pullStartedText);
            if (pullStartedText != null) {
                topManager.setPullStartedText(pullStartedText);
            }

            final String pullThresholdText = a.getString(R.styleable.PullListFragment_top_pullThresholdText);
            if (pullThresholdText != null) {
                topManager.setPullThresholdText(pullThresholdText);
            }

            final String refreshingText = a.getString(R.styleable.PullListFragment_top_refreshingText);
            if (refreshingText != null) {
                topManager.setRefreshingText(refreshingText);
            }

            final String refreshSuccessText = a.getString(R.styleable.PullListFragment_top_refreshSuccessText);
            if (refreshSuccessText != null) {
                topManager.setRefreshSuccessText(refreshSuccessText);
            }

            final String refreshFailedText = a.getString(R.styleable.PullListFragment_top_refreshFailedText);
            if (refreshFailedText != null) {
                topManager.setRefreshFailedText(refreshFailedText);
            }

            final int bgColor = a.getInt(R.styleable.PullListFragment_top_backgroundColor, -1);
            if (bgColor != -1) {
                topManager.setBackgroundColor(bgColor);
            }

            final int innerBgColor = a.getInt(R.styleable.PullListFragment_top_innerBackgroundColor, -1);
            if (innerBgColor != -1) {
                topManager.setInnerBackgroundColor(innerBgColor);
            }

            final int textSize = a.getDimensionPixelSize(R.styleable.PullListFragment_top_textSize,
                    (int) topManager.getTextSize());
            topManager.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);

            final int textColor = a.getInt(R.styleable.PullListFragment_top_textColor,
                    topManager.getTextColor());
            topManager.setTextColor(textColor);
        }

        if (bottomManager != null) {
            final String pullStartedText = a.getString(R.styleable.PullListFragment_bottom_pullStartedText);
            if (pullStartedText != null) {
                bottomManager.setPullStartedText(pullStartedText);
            }

            final String pullThresholdText = a.getString(R.styleable.PullListFragment_bottom_pullThresholdText);
            if (pullThresholdText != null) {
                bottomManager.setPullThresholdText(pullThresholdText);
            }

            final String refreshingText = a.getString(R.styleable.PullListFragment_bottom_refreshingText);
            if (refreshingText != null) {
                bottomManager.setRefreshingText(refreshingText);
            }

            final String refreshSuccessText = a
                    .getString(R.styleable.PullListFragment_bottom_refreshSuccessText);
            if (refreshSuccessText != null) {
                bottomManager.setRefreshSuccessText(refreshSuccessText);
            }

            final String refreshFailedText = a.getString(R.styleable.PullListFragment_bottom_refreshFailedText);
            if (refreshFailedText != null) {
                bottomManager.setRefreshFailedText(refreshFailedText);
            }

            final int bgColor = a.getInt(R.styleable.PullListFragment_bottom_backgroundColor, -1);
            if (bgColor != -1) {
                bottomManager.setBackgroundColor(bgColor);
            }

            final int innerBgColor = a.getInt(R.styleable.PullListFragment_bottom_innerBackgroundColor, -1);
            if (innerBgColor != -1) {
                bottomManager.setInnerBackgroundColor(innerBgColor);
            }

            final float textSize = a.getDimensionPixelSize(R.styleable.PullListFragment_bottom_textSize,
                    (int) bottomManager.getTextSize());
            bottomManager.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);

            final int textColor = a.getInt(R.styleable.PullListFragment_bottom_textSize,
                    bottomManager.getTextColor());
            bottomManager.setTextColor(textColor);
        }

        /**
         * Apply custom empty view configurations
         */

        final int emptyViewId = a.getResourceId(R.styleable.PullListFragment_empty_view, -1);
        if (emptyViewId != -1) {
            setEmptyView(emptyViewId);
        } else {
            final String emptyText = a.getString(R.styleable.PullListFragment_empty_text);
            if (emptyText != null) {
                setEmptyText(emptyText);
            }
        }

        /**
         * Apply custom behaviour to scroller
         */

        final int delay = a.getInt(R.styleable.PullListFragment_pull_delay,
                scroller.getOnRequestCompleteDelay());
        scroller.setOnRequestCompleteDelay(delay);

        final float damping = a.getFloat(R.styleable.PullListFragment_pull_damping, scroller.getDamping());
        scroller.setDamping(damping);

        final float easing = a.getFloat(R.styleable.PullListFragment_release_easing, scroller.getEasing());
        scroller.setEasing(easing);

        a.recycle();
    }
}

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  w w  .  j  av  a  2  s .  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;
    }
}