Example usage for android.content.res TypedArray getResourceId

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

Introduction

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

Prototype

@AnyRes
public int getResourceId(@StyleableRes int index, int defValue) 

Source Link

Document

Retrieves the resource identifier for the attribute at index.

Usage

From source file:com.ahao.preferencelibrary.preference.DialogPreference.java

@Override
protected void init(final Context context, final AttributeSet attrs, final int defStyleAttr,
        final int defStyleRes) {
    super.init(context, attrs, defStyleAttr, defStyleRes);
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DialogPreference, defStyleAttr,
            defStyleRes);/*from   w w w .ja v  a  2  s. co  m*/
    mDialogTitle = a.getString(R.styleable.DialogPreference_dialogTitle);
    if (mDialogTitle == null) {
        // Fallback on the regular title of the preference
        // (the one that is seen in the list)
        mDialogTitle = getTitle();
    }

    mDialogMessage = a.getString(R.styleable.DialogPreference_dialogMessage);
    mDialogIcon = a.getDrawable(R.styleable.DialogPreference_dialogIcon);
    mPositiveButtonText = a.getString(R.styleable.DialogPreference_positiveButtonText);
    mNegativeButtonText = a.getString(R.styleable.DialogPreference_negativeButtonText);
    mDialogLayoutResId = a.getResourceId(R.styleable.DialogPreference_dialogLayout, mDialogLayoutResId);
    a.recycle();
}

From source file:com.cqyw.smart.widget.viewpaper.PagerSlidingTabStrip.java

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

    setFillViewport(true);//from w w w .j  a  v  a  2s  . co m
    setWillNotDraw(false);

    tabsContainer = new LinearLayout(context);
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    addView(tabsContainer);

    DisplayMetrics dm = getResources().getDisplayMetrics();

    scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
    indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, indicatorHeight, dm);
    underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, underlineHeight, dm);
    dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm);
    tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
    dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);

    // get system attrs (android:textSize and android:textColor)

    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);

    a.recycle();

    // get custom attrs

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

    indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor);

    checkedTextColor = a.getResourceId(R.styleable.TwoTextView_ttLeftTextColor, R.color.theme_color);
    unCheckedTextColor = a.getResourceId(R.styleable.TwoTextView_ttLeftTextColor, R.color.white);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight,
            indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight,
            underlineHeight);
    dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding,
            dividerPadding);
    tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding);
    scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset);
    textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps);

    a.recycle();

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

    dividerPaint = new Paint();
    dividerPaint.setAntiAlias(true);
    dividerPaint.setStrokeWidth(dividerWidth);

    tabViewLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);

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

From source file:com.todoroo.astrid.taskrabbit.TaskRabbitActivity.java

private void displayViewsForMode(int mode) {

    taskControls.removeAllViews();/*from   ww w  . j av  a  2s. c  om*/
    descriptionControls.removeAllViews();

    if (row == null) {
        row = new LinearLayout(this);
        row.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
        row.setOrientation(LinearLayout.HORIZONTAL);
    } else {
        row.removeAllViews();
    }

    if (menuTitle != null) {
        menuTitle.setText(getResources().getStringArray(R.array.tr_preset_types)[mode]);
    }
    int[] presetValues = getPresetValues(mode);
    TypedArray keys = getResources().obtainTypedArray(R.array.tr_default_set_key);
    JSONObject parameters = defaultValuesToJSON(keys, presetValues);
    for (int i = 0; i < controls.size(); i++) {
        if (presetValues[i] == -1)
            continue;
        TaskRabbitSetListener set = controls.get(i);
        int arrayID = keys.getResourceId(i, 0);
        if (arrayID == R.string.tr_set_key_cost_in_cents || arrayID == R.string.tr_set_key_named_price) {
            if (row.getParent() == null)
                taskControls.addView(row);
            else {
                //                    View separator = getLayoutInflater().inflate(R.layout.tea_separator, row);
                //                    separator.setLayoutParams(new LayoutParams(1, LayoutParams.FILL_PARENT));

            }
            LinearLayout displayRow = (LinearLayout) ((TaskEditControlSet) set).getDisplayView();
            LinearLayout.LayoutParams layoutParams = null;
            if (arrayID == R.string.tr_set_key_named_price) {
                layoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                        LayoutParams.FILL_PARENT, 1);
                displayRow.findViewById(R.id.display_row_body).setPadding(5, 0, 10, 0);
                displayRow.setMinimumWidth(130);
            } else {
                layoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                        LayoutParams.FILL_PARENT, 1);
                displayRow.findViewById(R.id.display_row_body).setPadding(10, 0, 5, 0);
            }
            row.addView(displayRow, layoutParams);
        } else if (arrayID == R.string.tr_set_key_description) {
            descriptionControls.addView(((TaskEditControlSet) set).getDisplayView());
        } else {
            taskControls.addView(((TaskEditControlSet) set).getDisplayView());
        }
        ((TaskRabbitSetListener) set).readFromModel(parameters, getString(arrayID), currentSelectedItem);
    }
}

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

protected void applyStyle(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TabPageIndicator, defStyleAttr,
            defStyleRes);//from  ww  w .ja  v a2 s. c o m

    int textAppearance = 0;
    int mode = -1;
    int rippleStyle = 0;

    for (int i = 0, count = a.getIndexCount(); i < count; i++) {
        int attr = a.getIndex(i);
        if (attr == R.styleable.TabPageIndicator_tpi_tabPadding)
            mTabPadding = a.getDimensionPixelSize(attr, 0);
        else if (attr == R.styleable.TabPageIndicator_tpi_tabRipple)
            rippleStyle = a.getResourceId(attr, 0);
        else if (attr == R.styleable.TabPageIndicator_tpi_indicatorColor)
            mPaint.setColor(a.getColor(attr, 0));
        else if (attr == R.styleable.TabPageIndicator_tpi_indicatorHeight)
            mIndicatorHeight = a.getDimensionPixelSize(attr, 0);
        else if (attr == R.styleable.TabPageIndicator_tpi_indicatorAtTop)
            mIndicatorAtTop = a.getBoolean(attr, true);
        else if (attr == R.styleable.TabPageIndicator_tpi_tabSingleLine)
            mTabSingleLine = a.getBoolean(attr, true);
        else if (attr == R.styleable.TabPageIndicator_android_textAppearance)
            textAppearance = a.getResourceId(attr, 0);
        else if (attr == R.styleable.TabPageIndicator_tpi_mode)
            mode = a.getInteger(attr, 0);
    }

    a.recycle();

    if (mTabPadding < 0)
        mTabPadding = ThemeUtil.dpToPx(context, 12);

    if (mIndicatorHeight < 0)
        mIndicatorHeight = ThemeUtil.dpToPx(context, 2);

    if (mode >= 0) {
        if (mMode != mode || getChildCount() == 0) {
            mMode = mode;
            removeAllViews();
            if (mMode == MODE_SCROLL) {
                addView(mTabContainer, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                        ViewGroup.LayoutParams.MATCH_PARENT));
                setFillViewport(false);
            } else if (mMode == MODE_FIXED) {
                addView(mTabContainer, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.MATCH_PARENT));
                setFillViewport(true);
            }
        }
    }

    if (textAppearance != 0 && mTextAppearance != textAppearance) {
        mTextAppearance = textAppearance;
        for (int i = 0, count = mTabContainer.getChildCount(); i < count; i++) {
            CheckedTextView tv = (CheckedTextView) mTabContainer.getChildAt(i);
            tv.setTextAppearance(context, mTextAppearance);
        }
    }

    if (rippleStyle != 0 && rippleStyle != mTabRippleStyle) {
        mTabRippleStyle = rippleStyle;
        for (int i = 0, count = mTabContainer.getChildCount(); i < count; i++)
            ViewUtil.setBackground(mTabContainer.getChildAt(i),
                    new RippleDrawable.Builder(getContext(), mTabRippleStyle).build());
    }

    if (mViewPager != null)
        notifyDataSetChanged();
    requestLayout();
}

From source file:com.albedinsky.android.ui.navigation.NavigationLayout.java

/**
 * Called from one of constructors of this view to perform its initialization.
 * <p>/* w w w.  j  ava2 s  .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("ResourceType")
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    mLayoutInflater = LayoutInflater.from(context);
    int initialLayout = 0;

    /**
     * Process attributes.
     */
    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Ui_NavigationLayout,
            defStyleAttr, defStyleRes);
    if (typedArray != null) {
        final int n = typedArray.getIndexCount();
        for (int i = 0; i < n; i++) {
            int index = typedArray.getIndex(i);
            if (index == R.styleable.Ui_NavigationLayout_android_initialLayout) {
                initialLayout = typedArray.getResourceId(index, initialLayout);
            } else if (index == R.styleable.Ui_NavigationLayout_uiNavigationDrawerShadow) {
                final int resId = typedArray.getResourceId(index, -1);
                if (resId != -1)
                    setDrawerShadow(resId, NAVIGATION_DRAWER_GRAVITY);
            } else if (index == R.styleable.Ui_NavigationLayout_uiColorScrim) {
                setScrimColor(typedArray.getColor(index, Color.TRANSPARENT));
            }
        }
        typedArray.recycle();
    }

    if (initialLayout != 0) {
        mLayoutInflater.inflate(initialLayout, this);
        this.handleInflationFinished();
    }
}

From source file:ca.uwaterloo.sh6choi.czshopper.ui.FloatLabelLayout.java

public FloatLabelLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
    setOrientation(VERTICAL);/*from  w  w  w.jav  a  2s  .c  om*/

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FloatLabelLayout);

    int leftPadding = a.getDimensionPixelSize(R.styleable.FloatLabelLayout_floatLabelPaddingLeft,
            dipsToPix(DEFAULT_LABEL_PADDING_LEFT));
    int topPadding = a.getDimensionPixelSize(R.styleable.FloatLabelLayout_floatLabelPaddingTop,
            dipsToPix(DEFAULT_LABEL_PADDING_TOP));
    int rightPadding = a.getDimensionPixelSize(R.styleable.FloatLabelLayout_floatLabelPaddingRight,
            dipsToPix(DEFAULT_LABEL_PADDING_RIGHT));
    int bottomPadding = a.getDimensionPixelSize(R.styleable.FloatLabelLayout_floatLabelPaddingBottom,
            dipsToPix(DEFAULT_LABEL_PADDING_BOTTOM));
    mHint = a.getText(R.styleable.FloatLabelLayout_floatLabelHint);

    mLabel = new TextView(context);
    mLabel.setPadding(leftPadding, topPadding, rightPadding, bottomPadding);
    mLabel.setVisibility(INVISIBLE);
    mLabel.setText(mHint);
    ViewCompat.setPivotX(mLabel, 0f);
    ViewCompat.setPivotY(mLabel, 0f);

    mLabel.setTextAppearance(context, a.getResourceId(R.styleable.FloatLabelLayout_floatLabelTextAppearance,
            android.R.style.TextAppearance_Small));
    a.recycle();

    addView(mLabel, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    mInterpolator = AnimationUtils.loadInterpolator(context,
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? android.R.interpolator.fast_out_slow_in
                    : android.R.anim.decelerate_interpolator);
}

From source file:com.advaitaworld.widgets.FloatLabelLayout.java

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

    setOrientation(VERTICAL);/*  w  w  w.  ja va  2  s.c o m*/

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FloatLabelLayout);

    int leftPadding = a.getDimensionPixelSize(R.styleable.FloatLabelLayout_floatLabelPaddingLeft,
            dipsToPix(DEFAULT_LABEL_PADDING_LEFT));
    int topPadding = a.getDimensionPixelSize(R.styleable.FloatLabelLayout_floatLabelPaddingTop,
            dipsToPix(DEFAULT_LABEL_PADDING_TOP));
    int rightPadding = a.getDimensionPixelSize(R.styleable.FloatLabelLayout_floatLabelPaddingRight,
            dipsToPix(DEFAULT_LABEL_PADDING_RIGHT));
    int bottomPadding = a.getDimensionPixelSize(R.styleable.FloatLabelLayout_floatLabelPaddingBottom,
            dipsToPix(DEFAULT_LABEL_PADDING_BOTTOM));
    mHint = a.getText(R.styleable.FloatLabelLayout_floatLabelHint);

    mLabel = new TextView(context);
    mLabel.setPadding(leftPadding, topPadding, rightPadding, bottomPadding);
    mLabel.setVisibility(INVISIBLE);
    mLabel.setText(mHint);
    ViewCompat.setPivotX(mLabel, 0f);
    ViewCompat.setPivotY(mLabel, 0f);

    mLabel.setTextAppearance(context, a.getResourceId(R.styleable.FloatLabelLayout_floatLabelTextAppearance,
            android.R.style.TextAppearance_Small));
    a.recycle();

    addView(mLabel, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    mInterpolator = AnimationUtils.loadInterpolator(context,
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? android.R.interpolator.fast_out_slow_in
                    : android.R.anim.decelerate_interpolator);
}

From source file:com.github.rubensousa.stackview.StackView.java

public StackView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    mViews = new ArrayList<>();
    mRandom = new Random();
    mHardwareAccelerationEnabled = true;
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.StackView, 0, 0);
    mSize = a.getInteger(R.styleable.StackView_stackview_size, 4);
    mHorizontalSpacing = a.getDimension(R.styleable.StackView_stackview_horizontalSpacing, 0f);
    mVerticalSpacing = a.getDimension(R.styleable.StackView_stackview_verticalSpacing, VERTICAL_SPACING);
    mElevationSpacing = a.getDimension(R.styleable.StackView_stackview_elevationSpacing, ELEVATION_SPACING);
    mItemMaxRotation = a.getInteger(R.styleable.StackView_stackview_rotationRandomMagnitude, 0);
    mScaleXFactor = a.getFloat(R.styleable.StackView_stackview_horizontalScalingFactor, SCALE_X_FACTOR);

    if (mScaleXFactor < 0 || mScaleXFactor > 1) {
        throw new IllegalArgumentException(
                "horizontalScalingFactor must be greater than 0" + "and less than 1");
    }/*from ww w.  jav a 2s  .co m*/

    mCyclicLooping = a.getBoolean(R.styleable.StackView_stackview_cyclicLooping, false);
    mLayout = a.getResourceId(R.styleable.StackView_stackview_adapterLayout, 0);
    mAnimator = new StackDefaultAnimator();
    mAnimator.setStackView(this);
    mAnimator.setStackAnimationListener(this);
    a.recycle();

    setClipToPadding(false);
    setClipChildren(false);

    if (isInEditMode()) {
        addViews();
    }

}

From source file:ch.heigvd.wordhunt.Interaction.FloatLabelLayout.java

public void init(Context context, AttributeSet attrs) {

    setOrientation(VERTICAL);// ww  w  .ja  v a  2s .  c  o  m

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FloatLabelLayout);

    int leftPadding = a.getDimensionPixelSize(R.styleable.FloatLabelLayout_floatLabelPaddingLeft,
            dipsToPix(DEFAULT_LABEL_PADDING_LEFT));
    int topPadding = a.getDimensionPixelSize(R.styleable.FloatLabelLayout_floatLabelPaddingTop,
            dipsToPix(DEFAULT_LABEL_PADDING_TOP));
    int rightPadding = a.getDimensionPixelSize(R.styleable.FloatLabelLayout_floatLabelPaddingRight,
            dipsToPix(DEFAULT_LABEL_PADDING_RIGHT));
    int bottomPadding = a.getDimensionPixelSize(R.styleable.FloatLabelLayout_floatLabelPaddingBottom,
            dipsToPix(DEFAULT_LABEL_PADDING_BOTTOM));
    mHint = a.getText(R.styleable.FloatLabelLayout_floatLabelHint);

    mLabel = new TextView(context);
    mLabel.setPadding(leftPadding, topPadding, rightPadding, bottomPadding);
    mLabel.setVisibility(INVISIBLE);
    mLabel.setText(mHint);
    ViewCompat.setPivotX(mLabel, 0f);
    ViewCompat.setPivotY(mLabel, 0f);

    mLabel.setTextAppearance(context, a.getResourceId(R.styleable.FloatLabelLayout_floatLabelTextAppearance,
            android.R.style.TextAppearance_Small));
    a.recycle();

    addView(mLabel, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    mInterpolator = AnimationUtils.loadInterpolator(context,
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? android.R.interpolator.fast_out_slow_in
                    : android.R.anim.decelerate_interpolator);
}

From source file:android.support.v17.leanback.app.BackgroundManager.java

private BackgroundManager(Activity activity, boolean isSupportFragmentActivity) {
    mContext = activity;/*from w  w  w  .  java2 s .  c  o m*/
    mService = BackgroundContinuityService.getInstance();
    mHeightPx = mContext.getResources().getDisplayMetrics().heightPixels;
    mWidthPx = mContext.getResources().getDisplayMetrics().widthPixels;
    mHandler = new Handler();

    Interpolator defaultInterpolator = new FastOutLinearInInterpolator();
    mAccelerateInterpolator = AnimationUtils.loadInterpolator(mContext, android.R.anim.accelerate_interpolator);
    mDecelerateInterpolator = AnimationUtils.loadInterpolator(mContext, android.R.anim.decelerate_interpolator);

    mAnimator = ValueAnimator.ofInt(0, FULL_ALPHA);
    mAnimator.addListener(mAnimationListener);
    mAnimator.addUpdateListener(mAnimationUpdateListener);
    mAnimator.setInterpolator(defaultInterpolator);

    mDimAnimator = new ValueAnimator();
    mDimAnimator.addUpdateListener(mDimUpdateListener);

    TypedArray ta = activity.getTheme().obtainStyledAttributes(new int[] { android.R.attr.windowBackground });
    mThemeDrawableResourceId = ta.getResourceId(0, -1);
    if (mThemeDrawableResourceId < 0) {
        if (DEBUG)
            Log.v(TAG, "BackgroundManager no window background resource!");
    }
    ta.recycle();

    if (isSupportFragmentActivity) {
        createSupportFragment((FragmentActivity) activity);
    } else {
        createFragment(activity);
    }
}