Example usage for android.content.res TypedArray getIndexCount

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

Introduction

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

Prototype

public int getIndexCount() 

Source Link

Document

Returns the number of indices in the array that actually have data.

Usage

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 {// w  ww. j  ava  2 s  .c o m
        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.albedinsky.android.support.ui.widget.BaseProgressBar.java

/**
 * Creates a new instance of BaseProgressBar within the given <var>context</var>.
 *
 * @param context      Context in which will be this view presented.
 * @param attrs        Set of Xml attributes used to configure the new instance of this view.
 * @param defStyleAttr An attribute which contains a reference to a default style resource for
 *                     this view within a theme of the given context.
 *//*ww  w.  j a v a  2s  .c o  m*/
public BaseProgressBar(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    this.mResources = context.getResources();
    this.mUiThreadId = Thread.currentThread().getId();

    onAttachDrawable();
    if (mDrawable == null) {
        throw new IllegalArgumentException("No progress drawable has been attached.");
    }

    /**
     * Process attributes.
     */
    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Ui_Widget_ProgressBar,
            defStyleAttr, 0);
    if (typedArray != null) {
        this.processTintValues(context, typedArray);

        final int n = typedArray.getIndexCount();
        for (int i = 0; i < n; i++) {
            final int index = typedArray.getIndex(i);
            if (index == R.styleable.Ui_Widget_ProgressBar_uiColorProgress) {
                mDrawable.setColor(typedArray.getColor(index, mDrawable.getColor()));
            } else if (index == R.styleable.Ui_Widget_ProgressBar_uiColorsProgress) {
                final int colorsResId = typedArray.getResourceId(index, -1);
                if (colorsResId > 0) {
                    mDrawable.setColors(mResources.getIntArray(colorsResId));
                }
            } else if (index == R.styleable.Ui_Widget_ProgressBar_uiMultiColored) {
                mDrawable.setMultiColored(typedArray.getBoolean(index, mDrawable.isMultiColored()));
            } else if (index == R.styleable.Ui_Widget_ProgressBar_uiColorProgressBackground) {
                mDrawable.setBackgroundColor(typedArray.getInt(index, Color.TRANSPARENT));
            } else if (index == R.styleable.Ui_Widget_ProgressBar_android_thickness) {
                mDrawable.setThickness(typedArray.getDimensionPixelSize(index, 0));
            } else if (index == R.styleable.Ui_Widget_ProgressBar_uiRounded) {
                mDrawable.setRounded(typedArray.getBoolean(index, false));
            } else if (index == R.styleable.Ui_Widget_ProgressBar_uiIndeterminateSpeed) {
                mDrawable.setIndeterminateSpeed(typedArray.getFloat(index, 1));
            }
        }
    }

    this.applyProgressTint();
    this.applyIndeterminateTint();
    this.applyProgressBackgroundTint();
}

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);/*from  w  ww.ja  va 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 void resetKeyboardTheme(@NonNull KeyboardTheme theme) {
    final int keyboardThemeStyleResId = getKeyboardStyleResId(theme);

    final int[] remoteKeyboardThemeStyleable = theme.getResourceMapping()
            .getRemoteStyleableArrayFromLocal(R.styleable.AnyKeyboardViewTheme);
    final int[] remoteKeyboardIconsThemeStyleable = theme.getResourceMapping()
            .getRemoteStyleableArrayFromLocal(R.styleable.AnyKeyboardViewIconsTheme);

    final int[] padding = new int[] { 0, 0, 0, 0 };

    int keyTypeFunctionAttrId = R.attr.key_type_function;
    int keyActionAttrId = R.attr.key_type_action;
    int keyActionTypeDoneAttrId = R.attr.action_done;
    int keyActionTypeSearchAttrId = R.attr.action_search;
    int keyActionTypeGoAttrId = R.attr.action_go;

    HashSet<Integer> doneLocalAttributeIds = new HashSet<>();
    TypedArray a = theme.getPackageContext().obtainStyledAttributes(keyboardThemeStyleResId,
            remoteKeyboardThemeStyleable);
    final int n = a.getIndexCount();
    for (int i = 0; i < n; i++) {
        final int remoteIndex = a.getIndex(i);
        final int localAttrId = R.styleable.AnyKeyboardViewTheme[remoteIndex];
        if (setValueFromTheme(a, padding, localAttrId, remoteIndex)) {
            doneLocalAttributeIds.add(localAttrId);
            if (localAttrId == R.attr.keyBackground) {
                //keyTypeFunctionAttrId and keyActionAttrId are remote
                final int[] keyStateAttributes = theme.getResourceMapping()
                        .getRemoteStyleableArrayFromLocal(KEY_TYPES);
                keyTypeFunctionAttrId = keyStateAttributes[0];
                keyActionAttrId = keyStateAttributes[1];
            }// ww  w.j a  v  a  2 s . com
        }
    }
    a.recycle();
    // taking icons
    int iconSetStyleRes = getKeyboardIconsStyleResId(theme);
    if (iconSetStyleRes != 0) {
        a = theme.getPackageContext().obtainStyledAttributes(iconSetStyleRes,
                remoteKeyboardIconsThemeStyleable);
        final int iconsCount = a.getIndexCount();
        for (int i = 0; i < iconsCount; i++) {
            final int remoteIndex = a.getIndex(i);
            final int localAttrId = R.styleable.AnyKeyboardViewIconsTheme[remoteIndex];
            if (setKeyIconValueFromTheme(theme, a, localAttrId, remoteIndex)) {
                doneLocalAttributeIds.add(localAttrId);
                if (localAttrId == R.attr.iconKeyAction) {
                    //keyActionTypeDoneAttrId and keyActionTypeSearchAttrId and keyActionTypeGoAttrId are remote
                    final int[] keyStateAttributes = theme.getResourceMapping()
                            .getRemoteStyleableArrayFromLocal(ACTION_KEY_TYPES);
                    keyActionTypeDoneAttrId = keyStateAttributes[0];
                    keyActionTypeSearchAttrId = keyStateAttributes[1];
                    keyActionTypeGoAttrId = keyStateAttributes[2];
                }
            }
        }
        a.recycle();
    }
    // filling what's missing
    KeyboardTheme fallbackTheme = KeyboardThemeFactory.getFallbackTheme(getContext().getApplicationContext());
    final int keyboardFallbackThemeStyleResId = getKeyboardStyleResId(fallbackTheme);
    a = fallbackTheme.getPackageContext().obtainStyledAttributes(keyboardFallbackThemeStyleResId,
            R.styleable.AnyKeyboardViewTheme);

    final int fallbackCount = a.getIndexCount();
    for (int i = 0; i < fallbackCount; i++) {
        final int index = a.getIndex(i);
        final int attrId = R.styleable.AnyKeyboardViewTheme[index];
        if (doneLocalAttributeIds.contains(attrId))
            continue;
        setValueFromTheme(a, padding, attrId, index);
    }
    a.recycle();
    // taking missing icons
    int fallbackIconSetStyleId = fallbackTheme.getIconsThemeResId();
    a = fallbackTheme.getPackageContext().obtainStyledAttributes(fallbackIconSetStyleId,
            R.styleable.AnyKeyboardViewIconsTheme);

    final int fallbackIconsCount = a.getIndexCount();
    for (int i = 0; i < fallbackIconsCount; i++) {
        final int index = a.getIndex(i);
        final int attrId = R.styleable.AnyKeyboardViewIconsTheme[index];
        if (doneLocalAttributeIds.contains(attrId))
            continue;
        setKeyIconValueFromTheme(fallbackTheme, a, attrId, index);
    }
    a.recycle();
    //creating the key-drawable state provider, as we suppose to have the entire data now
    mDrawableStatesProvider = new KeyDrawableStateProvider(keyTypeFunctionAttrId, keyActionAttrId,
            keyActionTypeDoneAttrId, keyActionTypeSearchAttrId, keyActionTypeGoAttrId);

    // settings.
    // don't forget that there are THREE padding,
    // the theme's and the
    // background image's padding and the
    // View
    Drawable keyboardBackground = super.getBackground();
    if (keyboardBackground != null) {
        Rect backgroundPadding = new Rect();
        keyboardBackground.getPadding(backgroundPadding);
        padding[0] += backgroundPadding.left;
        padding[1] += backgroundPadding.top;
        padding[2] += backgroundPadding.right;
        padding[3] += backgroundPadding.bottom;
    }
    setPadding(padding[0], padding[1], padding[2], padding[3]);

    final Resources res = getResources();
    final int viewWidth = (getWidth() > 0) ? getWidth() : res.getDisplayMetrics().widthPixels;
    mKeyboardDimens.setKeyboardMaxWidth(viewWidth - padding[0] - padding[2]);

    mPaint.setTextSize(mKeyTextSize);

    mKeyBackground.getPadding(mKeyBackgroundPadding);
}

From source file:com.ruesga.timelinechart.TimelineChartView.java

private void init(Context ctx, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    mUiHandler = new Handler(Looper.getMainLooper(), mMessenger);
    if (!isInEditMode()) {
        mAudioManager = (AudioManager) ctx.getSystemService(Context.AUDIO_SERVICE);
    }/*from   w w w  .  jav  a 2  s. c  o m*/

    final Resources res = getResources();
    final Resources.Theme theme = ctx.getTheme();

    mTickFormats = getResources().getStringArray(R.array.tlcDefTickLabelFormats);
    mTickLabels = getResources().getStringArray(R.array.tlcDefTickLabelValues);

    final DisplayMetrics dp = getResources().getDisplayMetrics();
    mSize8 = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 8, dp);
    mSize12 = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 12, dp);
    mSize20 = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 20, dp);

    final ViewConfiguration vc = ViewConfiguration.get(ctx);
    mLongPressTimeout = ViewConfiguration.getLongPressTimeout();
    mTouchSlop = vc.getScaledTouchSlop() / 2;
    mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
    mScroller = new OverScroller(ctx);

    int graphBgColor = ContextCompat.getColor(ctx, R.color.tlcDefGraphBackgroundColor);
    int footerBgColor = ContextCompat.getColor(ctx, R.color.tlcDefFooterBackgroundColor);

    mDefFooterBarHeight = mFooterBarHeight = res.getDimension(R.dimen.tlcDefFooterBarHeight);
    mShowFooter = res.getBoolean(R.bool.tlcDefShowFooter);
    mGraphMode = res.getInteger(R.integer.tlcDefGraphMode);
    mPlaySelectionSoundEffect = res.getBoolean(R.bool.tlcDefPlaySelectionSoundEffect);
    mSelectionSoundEffectSource = res.getInteger(R.integer.tlcDefSelectionSoundEffectSource);
    mAnimateCursorTransition = res.getBoolean(R.bool.tlcDefAnimateCursorTransition);
    mFollowCursorPosition = res.getBoolean(R.bool.tlcDefFollowCursorPosition);
    mAlwaysEnsureSelection = res.getBoolean(R.bool.tlcDefAlwaysEnsureSelection);

    mGraphAreaBgPaint = new Paint();
    mGraphAreaBgPaint.setColor(graphBgColor);
    mFooterAreaBgPaint = new Paint();
    mFooterAreaBgPaint.setColor(footerBgColor);
    mTickLabelFgPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.LINEAR_TEXT_FLAG);
    mTickLabelFgPaint.setFakeBoldText(true);
    mTickLabelFgPaint.setColor(MaterialPaletteHelper.isDarkColor(footerBgColor) ? Color.LTGRAY : Color.DKGRAY);

    mBarItemWidth = res.getDimension(R.dimen.tlcDefBarItemWidth);
    mBarItemSpace = res.getDimension(R.dimen.tlcDefBarItemSpace);

    TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.tlcTimelineChartView, defStyleAttr,
            defStyleRes);
    try {
        int n = a.getIndexCount();
        for (int i = 0; i < n; i++) {
            int attr = a.getIndex(i);
            if (attr == R.styleable.tlcTimelineChartView_tlcGraphBackground) {
                graphBgColor = a.getColor(attr, graphBgColor);
                mGraphAreaBgPaint.setColor(graphBgColor);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcShowFooter) {
                mShowFooter = a.getBoolean(attr, mShowFooter);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcFooterBackground) {
                footerBgColor = a.getColor(attr, footerBgColor);
                mFooterAreaBgPaint.setColor(footerBgColor);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcFooterBarHeight) {
                mFooterBarHeight = a.getDimension(attr, mFooterBarHeight);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcGraphMode) {
                mGraphMode = a.getInt(attr, mGraphMode);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcAnimateCursorTransition) {
                mAnimateCursorTransition = a.getBoolean(attr, mAnimateCursorTransition);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcFollowCursorPosition) {
                mFollowCursorPosition = a.getBoolean(attr, mFollowCursorPosition);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcAlwaysEnsureSelection) {
                mAlwaysEnsureSelection = a.getBoolean(attr, mAlwaysEnsureSelection);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcBarItemWidth) {
                mBarItemWidth = a.getDimension(attr, mBarItemWidth);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcBarItemSpace) {
                mBarItemSpace = a.getDimension(attr, mBarItemSpace);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcPlaySelectionSoundEffect) {
                mPlaySelectionSoundEffect = a.getBoolean(attr, mPlaySelectionSoundEffect);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcSelectionSoundEffectSource) {
                mSelectionSoundEffectSource = a.getInt(attr, mSelectionSoundEffectSource);
            }
        }
    } finally {
        a.recycle();
    }

    // SurfaceView requires a background
    if (getBackground() == null) {
        setBackgroundColor(ContextCompat.getColor(ctx, android.R.color.transparent));
    }

    // Minimize the impact of create dynamic layouts by assume that in most case
    // we will have a day formatter
    mTickHasDayFormat = true;

    // Initialize stuff
    setupBackgroundHandler();
    setupTickLabels();
    if (ViewCompat.getOverScrollMode(this) != ViewCompat.OVER_SCROLL_NEVER) {
        setupEdgeEffects();
    }
    setupAnimators();
    setupSoundEffects();

    // Initialize the drawing refs (this will be update when we have
    // the real size of the canvas)
    computeBoundAreas();

    // Create a fake data for the edit mode
    if (isInEditMode()) {
        setupViewInEditMode();
    }
}

From source file:com.github.shareme.gwsmaterialuikit.library.material.app.Dialog.java

public Dialog applyStyle(int resId) {
    Context context = getContext();
    TypedArray a = context.obtainStyledAttributes(resId, R.styleable.Dialog);

    int layout_width = mLayoutWidth;
    int layout_height = mLayoutHeight;
    boolean layoutParamsDefined = false;
    int titleTextAppearance = 0;
    int titleTextColor = 0;
    boolean titleTextColorDefined = false;
    int actionBackground = 0;
    int actionRipple = 0;
    int actionTextAppearance = 0;
    ColorStateList actionTextColors = null;
    int positiveActionBackground = 0;
    int positiveActionRipple = 0;
    int positiveActionTextAppearance = 0;
    ColorStateList positiveActionTextColors = null;
    int negativeActionBackground = 0;
    int negativeActionRipple = 0;
    int negativeActionTextAppearance = 0;
    ColorStateList negativeActionTextColors = null;
    int neutralActionBackground = 0;
    int neutralActionRipple = 0;
    int neutralActionTextAppearance = 0;
    ColorStateList neutralActionTextColors = null;

    for (int i = 0, count = a.getIndexCount(); i < count; i++) {
        int attr = a.getIndex(i);

        if (attr == R.styleable.Dialog_android_layout_width) {
            layout_width = a.getLayoutDimension(attr, ViewGroup.LayoutParams.WRAP_CONTENT);
            layoutParamsDefined = true;// www.  j av a 2  s.  co  m
        } else if (attr == R.styleable.Dialog_android_layout_height) {
            layout_height = a.getLayoutDimension(attr, ViewGroup.LayoutParams.WRAP_CONTENT);
            layoutParamsDefined = true;
        } else if (attr == R.styleable.Dialog_di_maxWidth)
            maxWidth(a.getDimensionPixelOffset(attr, 0));
        else if (attr == R.styleable.Dialog_di_maxHeight)
            maxHeight(a.getDimensionPixelOffset(attr, 0));
        else if (attr == R.styleable.Dialog_di_dimAmount)
            dimAmount(a.getFloat(attr, 0));
        else if (attr == R.styleable.Dialog_di_backgroundColor)
            backgroundColor(a.getColor(attr, 0));
        else if (attr == R.styleable.Dialog_di_maxElevation)
            maxElevation(a.getDimensionPixelOffset(attr, 0));
        else if (attr == R.styleable.Dialog_di_elevation)
            elevation(a.getDimensionPixelOffset(attr, 0));
        else if (attr == R.styleable.Dialog_di_cornerRadius)
            cornerRadius(a.getDimensionPixelOffset(attr, 0));
        else if (attr == R.styleable.Dialog_di_layoutDirection)
            layoutDirection(a.getInteger(attr, 0));
        else if (attr == R.styleable.Dialog_di_titleTextAppearance)
            titleTextAppearance = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_titleTextColor) {
            titleTextColor = a.getColor(attr, 0);
            titleTextColorDefined = true;
        } else if (attr == R.styleable.Dialog_di_actionBackground)
            actionBackground = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_actionRipple)
            actionRipple = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_actionTextAppearance)
            actionTextAppearance = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_actionTextColor)
            actionTextColors = a.getColorStateList(attr);
        else if (attr == R.styleable.Dialog_di_positiveActionBackground)
            positiveActionBackground = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_positiveActionRipple)
            positiveActionRipple = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_positiveActionTextAppearance)
            positiveActionTextAppearance = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_positiveActionTextColor)
            positiveActionTextColors = a.getColorStateList(attr);
        else if (attr == R.styleable.Dialog_di_negativeActionBackground)
            negativeActionBackground = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_negativeActionRipple)
            negativeActionRipple = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_negativeActionTextAppearance)
            negativeActionTextAppearance = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_negativeActionTextColor)
            negativeActionTextColors = a.getColorStateList(attr);
        else if (attr == R.styleable.Dialog_di_neutralActionBackground)
            neutralActionBackground = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_neutralActionRipple)
            neutralActionRipple = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_neutralActionTextAppearance)
            neutralActionTextAppearance = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_neutralActionTextColor)
            neutralActionTextColors = a.getColorStateList(attr);
        else if (attr == R.styleable.Dialog_di_inAnimation)
            inAnimation(a.getResourceId(attr, 0));
        else if (attr == R.styleable.Dialog_di_outAnimation)
            outAnimation(a.getResourceId(attr, 0));
        else if (attr == R.styleable.Dialog_di_dividerColor)
            dividerColor(a.getColor(attr, 0));
        else if (attr == R.styleable.Dialog_di_dividerHeight)
            dividerHeight(a.getDimensionPixelOffset(attr, 0));
        else if (attr == R.styleable.Dialog_di_cancelable)
            cancelable(a.getBoolean(attr, true));
        else if (attr == R.styleable.Dialog_di_canceledOnTouchOutside)
            canceledOnTouchOutside(a.getBoolean(attr, true));
    }

    a.recycle();

    if (layoutParamsDefined)
        layoutParams(layout_width, layout_height);

    if (titleTextAppearance != 0)
        titleTextAppearance(titleTextAppearance);

    if (titleTextColorDefined)
        titleColor(titleTextColor);

    if (actionBackground != 0)
        actionBackground(actionBackground);

    if (actionRipple != 0)
        actionRipple(actionRipple);

    if (actionTextAppearance != 0)
        actionTextAppearance(actionTextAppearance);

    if (actionTextColors != null)
        actionTextColor(actionTextColors);

    if (positiveActionBackground != 0)
        positiveActionBackground(positiveActionBackground);

    if (positiveActionRipple != 0)
        positiveActionRipple(positiveActionRipple);

    if (positiveActionTextAppearance != 0)
        positiveActionTextAppearance(positiveActionTextAppearance);

    if (positiveActionTextColors != null)
        positiveActionTextColor(positiveActionTextColors);

    if (negativeActionBackground != 0)
        negativeActionBackground(negativeActionBackground);

    if (negativeActionRipple != 0)
        negativeActionRipple(negativeActionRipple);

    if (negativeActionTextAppearance != 0)
        negativeActionTextAppearance(negativeActionTextAppearance);

    if (negativeActionTextColors != null)
        negativeActionTextColor(negativeActionTextColors);

    if (neutralActionBackground != 0)
        neutralActionBackground(neutralActionBackground);

    if (neutralActionRipple != 0)
        neutralActionRipple(neutralActionRipple);

    if (neutralActionTextAppearance != 0)
        neutralActionTextAppearance(neutralActionTextAppearance);

    if (neutralActionTextColors != null)
        neutralActionTextColor(neutralActionTextColors);

    return this;
}

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

public AnyKeyboardBaseView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    //creating the KeyDrawableStateProvider, as it suppose to be backward compatible
    int keyTypeFunctionAttrId = R.attr.key_type_function;
    int keyActionAttrId = R.attr.key_type_action;
    int keyActionTypeDoneAttrId = R.attr.action_done;
    int keyActionTypeSearchAttrId = R.attr.action_search;
    int keyActionTypeGoAttrId = R.attr.action_go;

    LayoutInflater inflate = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    // int previewLayout = 0;
    mPreviewKeyTextSize = -1;//from  w w  w .  ja va 2s  .  c o m
    mPreviewLabelTextSize = -1;
    mPreviewKeyBackground = null;
    mPreviewKeyTextColor = 0xFFF;
    final int[] padding = new int[] { 0, 0, 0, 0 };

    KeyboardTheme theme = KeyboardThemeFactory.getCurrentKeyboardTheme(context.getApplicationContext());
    final int keyboardThemeStyleResId = getKeyboardStyleResId(theme);
    Log.d(TAG, "Will use keyboard theme " + theme.getName() + " id " + theme.getId() + " res "
            + keyboardThemeStyleResId);

    //creating a mapping from the remote Attribute IDs to my local attribute ID.
    //this is required in order to backward support any build-system (which may cause the attribute IDs to change)
    final SparseIntArray attributeIdMap = new SparseIntArray(R.styleable.AnyKeyboardViewTheme.length
            + R.styleable.AnyKeyboardViewIconsTheme.length + ACTION_KEY_TYPES.length + KEY_TYPES.length);

    final int[] remoteKeyboardThemeStyleable = KeyboardSupport.createBackwardCompatibleStyleable(
            R.styleable.AnyKeyboardViewTheme, context, theme.getPackageContext(), attributeIdMap);
    final int[] remoteKeyboardIconsThemeStyleable = KeyboardSupport.createBackwardCompatibleStyleable(
            R.styleable.AnyKeyboardViewIconsTheme, context, theme.getPackageContext(), attributeIdMap);

    HashSet<Integer> doneLocalAttributeIds = new HashSet<Integer>();
    TypedArray a = theme.getPackageContext().obtainStyledAttributes(keyboardThemeStyleResId,
            remoteKeyboardThemeStyleable);
    final int n = a.getIndexCount();
    for (int i = 0; i < n; i++) {
        final int remoteIndex = a.getIndex(i);
        final int localAttrId = attributeIdMap.get(remoteKeyboardThemeStyleable[remoteIndex]);
        if (setValueFromTheme(a, padding, localAttrId, remoteIndex)) {
            doneLocalAttributeIds.add(localAttrId);
            if (localAttrId == R.attr.keyBackground) {
                //keyTypeFunctionAttrId and keyActionAttrId are remote
                final int[] keyStateAttributes = KeyboardSupport.createBackwardCompatibleStyleable(KEY_TYPES,
                        context, theme.getPackageContext(), attributeIdMap);
                keyTypeFunctionAttrId = keyStateAttributes[0];
                keyActionAttrId = keyStateAttributes[1];
            }
        }
    }
    a.recycle();
    // taking icons
    int iconSetStyleRes = theme.getIconsThemeResId();
    Log.d(TAG, "Will use keyboard icons theme " + theme.getName() + " id " + theme.getId() + " res "
            + iconSetStyleRes);
    if (iconSetStyleRes != 0) {
        a = theme.getPackageContext().obtainStyledAttributes(iconSetStyleRes,
                remoteKeyboardIconsThemeStyleable);
        final int iconsCount = a.getIndexCount();
        for (int i = 0; i < iconsCount; i++) {
            final int remoteIndex = a.getIndex(i);
            final int localAttrId = attributeIdMap.get(remoteKeyboardIconsThemeStyleable[remoteIndex]);
            if (setKeyIconValueFromTheme(theme, a, localAttrId, remoteIndex)) {
                doneLocalAttributeIds.add(localAttrId);
                if (localAttrId == R.attr.iconKeyAction) {
                    //keyActionTypeDoneAttrId and keyActionTypeSearchAttrId and keyActionTypeGoAttrId are remote
                    final int[] keyStateAttributes = KeyboardSupport.createBackwardCompatibleStyleable(
                            ACTION_KEY_TYPES, context, theme.getPackageContext(), attributeIdMap);
                    keyActionTypeDoneAttrId = keyStateAttributes[0];
                    keyActionTypeSearchAttrId = keyStateAttributes[1];
                    keyActionTypeGoAttrId = keyStateAttributes[2];
                }
            }
        }
        a.recycle();
    }
    // filling what's missing
    KeyboardTheme fallbackTheme = KeyboardThemeFactory.getFallbackTheme(context.getApplicationContext());
    final int keyboardFallbackThemeStyleResId = getKeyboardStyleResId(fallbackTheme);
    Log.d(TAG, "Will use keyboard fallback theme " + fallbackTheme.getName() + " id " + fallbackTheme.getId()
            + " res " + keyboardFallbackThemeStyleResId);
    a = fallbackTheme.getPackageContext().obtainStyledAttributes(keyboardFallbackThemeStyleResId,
            R.styleable.AnyKeyboardViewTheme);

    final int fallbackCount = a.getIndexCount();
    for (int i = 0; i < fallbackCount; i++) {
        final int index = a.getIndex(i);
        final int attrId = R.styleable.AnyKeyboardViewTheme[index];
        if (doneLocalAttributeIds.contains(attrId))
            continue;
        Log.d(TAG, "Falling back theme res ID " + index);
        setValueFromTheme(a, padding, attrId, index);
    }
    a.recycle();
    // taking missing icons
    int fallbackIconSetStyleId = fallbackTheme.getIconsThemeResId();
    Log.d(TAG, "Will use keyboard fallback icons theme " + fallbackTheme.getName() + " id "
            + fallbackTheme.getId() + " res " + fallbackIconSetStyleId);
    a = fallbackTheme.getPackageContext().obtainStyledAttributes(fallbackIconSetStyleId,
            R.styleable.AnyKeyboardViewIconsTheme);

    final int fallbackIconsCount = a.getIndexCount();
    for (int i = 0; i < fallbackIconsCount; i++) {
        final int index = a.getIndex(i);
        final int attrId = R.styleable.AnyKeyboardViewIconsTheme[index];
        if (doneLocalAttributeIds.contains(attrId))
            continue;
        Log.d(TAG, "Falling back icon res ID " + index);
        setKeyIconValueFromTheme(fallbackTheme, a, attrId, index);
    }
    a.recycle();
    //creating the key-drawable state provider, as we suppose to have the entire data now
    mDrawableStatesProvider = new KeyDrawableStateProvider(keyTypeFunctionAttrId, keyActionAttrId,
            keyActionTypeDoneAttrId, keyActionTypeSearchAttrId, keyActionTypeGoAttrId);

    // settings.
    // don't forget that there are TWO paddings, the theme's and the
    // background image's padding!
    Drawable keyboardBabground = super.getBackground();
    if (keyboardBabground != null) {
        Rect backgroundPadding = new Rect();
        keyboardBabground.getPadding(backgroundPadding);
        padding[0] += backgroundPadding.left;
        padding[1] += backgroundPadding.top;
        padding[2] += backgroundPadding.right;
        padding[3] += backgroundPadding.bottom;
    }
    super.setPadding(padding[0], padding[1], padding[2], padding[3]);

    final Resources res = getResources();
    mKeyboardDimens.setKeyboardMaxWidth(res.getDisplayMetrics().widthPixels - padding[0] - padding[2]);
    mPreviewPopup = new PopupWindow(context);
    if (mPreviewKeyTextSize > 0) {
        if (mPreviewLabelTextSize <= 0)
            mPreviewLabelTextSize = mPreviewKeyTextSize;
        mPreviewLayut = inflatePreviewWindowLayout(inflate);
        mPreviewText = (TextView) mPreviewLayut.findViewById(R.id.key_preview_text);
        mPreviewText.setTextColor(mPreviewKeyTextColor);
        mPreviewText.setTypeface(mKeyTextStyle);
        mPreviewIcon = (ImageView) mPreviewLayut.findViewById(R.id.key_preview_icon);
        mPreviewPopup.setBackgroundDrawable(mPreviewKeyBackground);
        mPreviewPopup.setContentView(mPreviewLayut);
        mShowPreview = mPreviewLayut != null;
    } else {
        mPreviewLayut = null;
        mPreviewText = null;
        mShowPreview = false;
    }
    mPreviewPopup.setTouchable(false);
    mPreviewPopup
            .setAnimationStyle((mAnimationLevel == AnimationsLevel.None) ? 0 : R.style.KeyPreviewAnimation);
    mDelayBeforePreview = 0;
    mDelayAfterPreview = 10;

    mMiniKeyboardParent = this;
    mMiniKeyboardPopup = new PopupWindow(context.getApplicationContext());
    mMiniKeyboardPopup.setBackgroundDrawable(null);

    mMiniKeyboardPopup
            .setAnimationStyle((mAnimationLevel == AnimationsLevel.None) ? 0 : R.style.MiniKeyboardAnimation);

    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setTextSize(mKeyTextSize);
    mPaint.setTextAlign(Align.CENTER);
    mPaint.setAlpha(255);

    mKeyBackgroundPadding = new Rect(0, 0, 0, 0);
    mKeyBackground.getPadding(mKeyBackgroundPadding);

    reloadSwipeThresholdsSettings(res);

    mMiniKeyboardSlideAllowance = res.getDimension(R.dimen.mini_keyboard_slide_allowance);

    AskOnGestureListener listener = new AskGestureEventsListener(this);

    mGestureDetector = AnyApplication.getDeviceSpecific().createGestureDetector(getContext(), listener);
    mGestureDetector.setIsLongpressEnabled(false);

    MultiTouchSupportLevel multiTouchSupportLevel = AnyApplication.getDeviceSpecific()
            .getMultiTouchSupportLevel(getContext());

    mHasDistinctMultitouch = multiTouchSupportLevel == MultiTouchSupportLevel.Distinct;

    mKeyRepeatInterval = 50;

    AnyApplication.getConfig().addChangedListener(this);
}

From source file:com.albedinsky.android.ui.widget.SeekBarWidget.java

/**
 * Called from one of constructors of this view to perform its initialization.
 * <p>//from   w  w w . j  a  v a  2s. c  o m
 * Initialization is done via parsing of the specified <var>attrs</var> set and obtaining for
 * this view specific data from it that can be used to configure this new view instance. The
 * specified <var>defStyleAttr</var> and <var>defStyleRes</var> are used to obtain default data
 * from the current theme provided by the specified <var>context</var>.
 */
@SuppressWarnings("ConstantConditions")
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    this.ensureRect();
    this.ensureDecorator();
    mDecorator.processAttributes(context, attrs, defStyleAttr, defStyleRes);
    this.mAnimations = Animations.get(this);

    /**
     * Process attributes.
     */
    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Ui_SeekBar, defStyleAttr,
            defStyleRes);
    if (typedArray != null) {
        final Rect indicatorTextPadding = new Rect();
        final int n = typedArray.getIndexCount();
        for (int i = 0; i < n; i++) {
            final int index = typedArray.getIndex(i);
            if (index == R.styleable.Ui_SeekBar_android_enabled) {
                setEnabled(typedArray.getBoolean(index, true));
            } else if (index == R.styleable.Ui_SeekBar_uiDiscrete) {
                setDiscrete(typedArray.getBoolean(index, false));
            } else if (index == R.styleable.Ui_SeekBar_uiDiscretePreviewEnabled) {
                setDiscretePreviewEnabled(typedArray.getBoolean(index, true));
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIntervalRatio) {
                setDiscreteIntervalRatio(typedArray.getFloat(index, mDiscreteIntervalRatio));
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIndicator) {
                setDiscreteIndicator(typedArray.getResourceId(index, 0));
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIndicatorTextAppearance) {
                setDiscreteIndicatorTextAppearance(typedArray.getResourceId(index, 0));
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIndicatorTextGravity) {
                setDiscreteIndicatorTextGravity(
                        typedArray.getInteger(index, DISCRETE_INDICATOR_TEXT_INFO.gravity));
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIndicatorTextPaddingStart) {
                indicatorTextPadding.left = typedArray.getDimensionPixelSize(index, 0);
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIndicatorTextPaddingTop) {
                indicatorTextPadding.top = typedArray.getDimensionPixelSize(index, 0);
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIndicatorTextPaddingEnd) {
                indicatorTextPadding.right = typedArray.getDimensionPixelSize(index, 0);
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIndicatorTextPaddingBottom) {
                indicatorTextPadding.bottom = typedArray.getDimensionPixelSize(index, 0);
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIntervalTickMarkColor) {
                setDiscreteIntervalTickMarkColor(typedArray.getColorStateList(index));
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIntervalTickMarkRadius) {
                setDiscreteIntervalTickMarkRadius(typedArray.getDimensionPixelSize(index, 0));
            }
        }
        setDiscreteIndicatorTextPadding(indicatorTextPadding.left, indicatorTextPadding.top,
                indicatorTextPadding.right, indicatorTextPadding.bottom);
        typedArray.recycle();
    }
    this.applyProgressTints();
    this.applyThumbTint();
}

From source file:com.ruesga.rview.widget.TagEditTextView.java

private void init(Context ctx, AttributeSet attrs, int defStyleAttr) {
    mHandler = new Handler(mTagMessenger);
    mTriggerTagCreationThreshold = CREATE_CHIP_DEFAULT_DELAYED_TIMEOUT;

    Resources.Theme theme = ctx.getTheme();
    TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.TagEditTextView, defStyleAttr, 0);

    mReadOnly = a.getBoolean(R.styleable.TagEditTextView_readonly, false);
    mDefaultTagMode = TAG_MODE.HASH;/*w w  w.  j a  va 2  s .  c  om*/

    // Create the internal EditText that holds the tag logic
    mTagEdit = mReadOnly ? new TagEditText(ctx, attrs, defStyleAttr) : new TagEditText(ctx, attrs);
    mTagEdit.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 0));
    mTagEdit.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    mTagEdit.addTextChangedListener(mEditListener);
    mTagEdit.setTextIsSelectable(false);
    mTagEdit.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
    mTagEdit.setOnFocusChangeListener((v, hasFocus) -> {
        // Remove any pending message
        mHandler.removeMessages(MESSAGE_CREATE_CHIP);
    });
    mTagEdit.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            return false;
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {

        }
    });
    addView(mTagEdit);

    // Configure the window mode for landscape orientation, to disallow hide the
    // EditText control, and show characters instead of chips
    int orientation = ctx.getResources().getConfiguration().orientation;
    if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
        if (ctx instanceof Activity) {
            Window window = ((Activity) ctx).getWindow();
            if (window != null) {
                window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
                mTagEdit.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
            }
        }
    }

    // Save the keyListener for later restore
    mEditModeKeyListener = mTagEdit.getKeyListener();

    // Initialize resources for chips
    mChipBgPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

    mChipFgPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mChipFgPaint.setTextSize(mTagEdit.getTextSize() * (mReadOnly ? 1 : 0.8f));
    if (CHIP_TYPEFACE != null) {
        mChipFgPaint.setTypeface(CHIP_TYPEFACE);
    }
    mChipFgPaint.setTextAlign(Paint.Align.LEFT);

    // Calculate the width area used to remove the tag in the chip
    mChipRemoveAreaWidth = (int) (mChipFgPaint.measureText(CHIP_REMOVE_TEXT) + 0.5f);

    if (ONE_PIXEL <= 0) {
        Resources res = getResources();
        ONE_PIXEL = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, res.getDisplayMetrics());
    }

    int n = a.getIndexCount();
    for (int i = 0; i < n; i++) {
        int attr = a.getIndex(i);
        switch (attr) {
        case R.styleable.TagEditTextView_supportUserTags:
            setSupportsUserTags(a.getBoolean(attr, false));
            break;

        case R.styleable.TagEditTextView_chipBackgroundColor:
            mChipBackgroundColor = a.getColor(attr, mChipBackgroundColor);
            break;

        case R.styleable.TagEditTextView_chipTextColor:
            mChipFgPaint.setColor(a.getColor(attr, Color.WHITE));
            break;
        }
    }
    a.recycle();
}

From source file:com.github.shareme.gwsmaterialuikit.library.material.widget.EditText.java

@Override
protected void applyStyle(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super.applyStyle(context, attrs, defStyleAttr, defStyleRes);

    CharSequence text = mInputView == null ? null : mInputView.getText();
    removeAllViews();//from   ww w . ja  v a 2  s.  co  m

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.EditText, defStyleAttr, defStyleRes);

    int labelPadding = -1;
    int labelTextSize = -1;
    ColorStateList labelTextColor = null;
    int supportPadding = -1;
    int supportTextSize = -1;
    ColorStateList supportColors = null;
    ColorStateList supportErrorColors = null;
    String supportHelper = null;
    String supportError = null;
    ColorStateList dividerColors = null;
    ColorStateList dividerErrorColors = null;
    int dividerHeight = -1;
    int dividerPadding = -1;
    int dividerAnimDuration = -1;

    mAutoCompleteMode = a.getInteger(R.styleable.EditText_et_autoCompleteMode, mAutoCompleteMode);
    if (needCreateInputView(mAutoCompleteMode)) {
        switch (mAutoCompleteMode) {
        case AUTOCOMPLETE_MODE_SINGLE:
            mInputView = new InternalAutoCompleteTextView(context, attrs, defStyleAttr);
            break;
        case AUTOCOMPLETE_MODE_MULTI:
            mInputView = new InternalMultiAutoCompleteTextView(context, attrs, defStyleAttr);
            break;
        default:
            mInputView = new InternalEditText(context, attrs, defStyleAttr);
            break;
        }
        ViewUtil.applyFont(mInputView, attrs, defStyleAttr, defStyleRes);
        if (text != null)
            mInputView.setText(text);

        mInputView.addTextChangedListener(new InputTextWatcher());

        if (mDivider != null) {
            mDivider.setAnimEnable(false);
            ViewUtil.setBackground(mInputView, mDivider);
            mDivider.setAnimEnable(true);
        }
    } else
        ViewUtil.applyStyle(mInputView, attrs, defStyleAttr, defStyleRes);
    mInputView.setVisibility(View.VISIBLE);
    mInputView.setFocusableInTouchMode(true);

    for (int i = 0, count = a.getIndexCount(); i < count; i++) {
        int attr = a.getIndex(i);

        if (attr == R.styleable.EditText_et_labelEnable)
            mLabelEnable = a.getBoolean(attr, false);
        else if (attr == R.styleable.EditText_et_labelPadding)
            labelPadding = a.getDimensionPixelSize(attr, 0);
        else if (attr == R.styleable.EditText_et_labelTextSize)
            labelTextSize = a.getDimensionPixelSize(attr, 0);
        else if (attr == R.styleable.EditText_et_labelTextColor)
            labelTextColor = a.getColorStateList(attr);
        else if (attr == R.styleable.EditText_et_labelTextAppearance)
            getLabelView().setTextAppearance(context, a.getResourceId(attr, 0));
        else if (attr == R.styleable.EditText_et_labelEllipsize) {
            int labelEllipsize = a.getInteger(attr, 0);
            switch (labelEllipsize) {
            case 1:
                getLabelView().setEllipsize(TruncateAt.START);
                break;
            case 2:
                getLabelView().setEllipsize(TruncateAt.MIDDLE);
                break;
            case 3:
                getLabelView().setEllipsize(TruncateAt.END);
                break;
            case 4:
                getLabelView().setEllipsize(TruncateAt.MARQUEE);
                break;
            default:
                getLabelView().setEllipsize(TruncateAt.END);
                break;
            }
        } else if (attr == R.styleable.EditText_et_labelInAnim)
            mLabelInAnimId = a.getResourceId(attr, 0);
        else if (attr == R.styleable.EditText_et_labelOutAnim)
            mLabelOutAnimId = a.getResourceId(attr, 0);
        else if (attr == R.styleable.EditText_et_supportMode)
            mSupportMode = a.getInteger(attr, 0);
        else if (attr == R.styleable.EditText_et_supportPadding)
            supportPadding = a.getDimensionPixelSize(attr, 0);
        else if (attr == R.styleable.EditText_et_supportTextSize)
            supportTextSize = a.getDimensionPixelSize(attr, 0);
        else if (attr == R.styleable.EditText_et_supportTextColor)
            supportColors = a.getColorStateList(attr);
        else if (attr == R.styleable.EditText_et_supportTextErrorColor)
            supportErrorColors = a.getColorStateList(attr);
        else if (attr == R.styleable.EditText_et_supportTextAppearance)
            getSupportView().setTextAppearance(context, a.getResourceId(attr, 0));
        else if (attr == R.styleable.EditText_et_supportEllipsize) {
            int supportEllipsize = a.getInteger(attr, 0);
            switch (supportEllipsize) {
            case 1:
                getSupportView().setEllipsize(TruncateAt.START);
                break;
            case 2:
                getSupportView().setEllipsize(TruncateAt.MIDDLE);
                break;
            case 3:
                getSupportView().setEllipsize(TruncateAt.END);
                break;
            case 4:
                getSupportView().setEllipsize(TruncateAt.MARQUEE);
                break;
            default:
                getSupportView().setEllipsize(TruncateAt.END);
                break;
            }
        } else if (attr == R.styleable.EditText_et_supportMaxLines)
            getSupportView().setMaxLines(a.getInteger(attr, 0));
        else if (attr == R.styleable.EditText_et_supportLines)
            getSupportView().setLines(a.getInteger(attr, 0));
        else if (attr == R.styleable.EditText_et_supportSingleLine)
            getSupportView().setSingleLine(a.getBoolean(attr, false));
        else if (attr == R.styleable.EditText_et_supportMaxChars)
            mSupportMaxChars = a.getInteger(attr, 0);
        else if (attr == R.styleable.EditText_et_helper)
            supportHelper = a.getString(attr);
        else if (attr == R.styleable.EditText_et_error)
            supportError = a.getString(attr);
        else if (attr == R.styleable.EditText_et_inputId)
            mInputView.setId(a.getResourceId(attr, 0));
        else if (attr == R.styleable.EditText_et_dividerColor)
            dividerColors = a.getColorStateList(attr);
        else if (attr == R.styleable.EditText_et_dividerErrorColor)
            dividerErrorColors = a.getColorStateList(attr);
        else if (attr == R.styleable.EditText_et_dividerHeight)
            dividerHeight = a.getDimensionPixelSize(attr, 0);
        else if (attr == R.styleable.EditText_et_dividerPadding)
            dividerPadding = a.getDimensionPixelSize(attr, 0);
        else if (attr == R.styleable.EditText_et_dividerAnimDuration)
            dividerAnimDuration = a.getInteger(attr, 0);
        else if (attr == R.styleable.EditText_et_dividerCompoundPadding)
            mDividerCompoundPadding = a.getBoolean(attr, true);
    }

    a.recycle();

    if (mInputView.getId() == 0)
        mInputView.setId(ViewUtil.generateViewId());

    if (mDivider == null) {
        mDividerColors = dividerColors;
        mDividerErrorColors = dividerErrorColors;

        if (mDividerColors == null) {
            int[][] states = new int[][] { new int[] { -android.R.attr.state_focused },
                    new int[] { android.R.attr.state_focused, android.R.attr.state_enabled }, };
            int[] colors = new int[] { ThemeUtil.colorControlNormal(context, 0xFF000000),
                    ThemeUtil.colorControlActivated(context, 0xFF000000), };

            mDividerColors = new ColorStateList(states, colors);
        }

        if (mDividerErrorColors == null)
            mDividerErrorColors = ColorStateList.valueOf(ThemeUtil.colorAccent(context, 0xFFFF0000));

        if (dividerHeight < 0)
            dividerHeight = 0;

        if (dividerPadding < 0)
            dividerPadding = 0;

        if (dividerAnimDuration < 0)
            dividerAnimDuration = context.getResources().getInteger(android.R.integer.config_shortAnimTime);

        mDividerPadding = dividerPadding;
        mInputView.setPadding(0, 0, 0, mDividerPadding + dividerHeight);

        mDivider = new DividerDrawable(dividerHeight,
                mDividerCompoundPadding ? mInputView.getTotalPaddingLeft() : 0,
                mDividerCompoundPadding ? mInputView.getTotalPaddingRight() : 0, mDividerColors,
                dividerAnimDuration);
        mDivider.setInEditMode(isInEditMode());
        mDivider.setAnimEnable(false);
        ViewUtil.setBackground(mInputView, mDivider);
        mDivider.setAnimEnable(true);
    } else {
        if (dividerHeight >= 0 || dividerPadding >= 0) {
            if (dividerHeight < 0)
                dividerHeight = mDivider.getDividerHeight();

            if (dividerPadding >= 0)
                mDividerPadding = dividerPadding;

            mInputView.setPadding(0, 0, 0, mDividerPadding + dividerHeight);
            mDivider.setDividerHeight(dividerHeight);
            mDivider.setPadding(mDividerCompoundPadding ? mInputView.getTotalPaddingLeft() : 0,
                    mDividerCompoundPadding ? mInputView.getTotalPaddingRight() : 0);
        }

        if (dividerColors != null)
            mDividerColors = dividerColors;

        if (dividerErrorColors != null)
            mDividerErrorColors = dividerErrorColors;

        mDivider.setColor(getError() == null ? mDividerColors : mDividerErrorColors);

        if (dividerAnimDuration >= 0)
            mDivider.setAnimationDuration(dividerAnimDuration);
    }

    if (labelPadding >= 0)
        getLabelView().setPadding(mDivider.getPaddingLeft(), 0, mDivider.getPaddingRight(), labelPadding);

    if (labelTextSize >= 0)
        getLabelView().setTextSize(TypedValue.COMPLEX_UNIT_PX, labelTextSize);

    if (labelTextColor != null)
        getLabelView().setTextColor(labelTextColor);

    if (mLabelEnable) {
        mLabelVisible = true;
        getLabelView().setText(mInputView.getHint());
        addView(getLabelView(), 0, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        setLabelVisible(!TextUtils.isEmpty(mInputView.getText().toString()), false);
    }

    if (supportTextSize >= 0)
        getSupportView().setTextSize(TypedValue.COMPLEX_UNIT_PX, supportTextSize);

    if (supportColors != null)
        mSupportColors = supportColors;
    else if (mSupportColors == null)
        mSupportColors = context.getResources().getColorStateList(R.color.abc_secondary_text_material_light);

    if (supportErrorColors != null)
        mSupportErrorColors = supportErrorColors;
    else if (mSupportErrorColors == null)
        mSupportErrorColors = ColorStateList.valueOf(ThemeUtil.colorAccent(context, 0xFFFF0000));

    if (supportPadding >= 0)
        getSupportView().setPadding(mDivider.getPaddingLeft(), supportPadding, mDivider.getPaddingRight(), 0);

    if (supportHelper == null && supportError == null)
        getSupportView().setTextColor(getError() == null ? mSupportColors : mSupportErrorColors);
    else if (supportHelper != null)
        setHelper(supportHelper);
    else
        setError(supportError);

    if (mSupportMode != SUPPORT_MODE_NONE) {
        switch (mSupportMode) {
        case SUPPORT_MODE_CHAR_COUNTER:
            getSupportView().setGravity(Gravity.END);
            updateCharCounter(mInputView.getText().length());
            break;
        case SUPPORT_MODE_HELPER:
        case SUPPORT_MODE_HELPER_WITH_ERROR:
            getSupportView().setGravity(GravityCompat.START);
            break;
        }
        addView(getSupportView(), new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
    }

    addView(mInputView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    requestLayout();
}