Example usage for android.content.res TypedArray getInt

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

Introduction

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

Prototype

public int getInt(@StyleableRes int index, int defValue) 

Source Link

Document

Retrieve the integer value for the attribute at index.

Usage

From source file:com.facebook.widget.LikeView.java

private void parseAttributes(AttributeSet attrs) {
    if (attrs == null || getContext() == null) {
        return;//from  ww w . j  a v  a2s.co m
    }

    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.com_facebook_like_view);
    if (a == null) {
        return;
    }

    objectId = Utility.coerceValueIfNullOrEmpty(a.getString(R.styleable.com_facebook_like_view_object_id),
            null);
    likeViewStyle = Style.fromInt(a.getInt(R.styleable.com_facebook_like_view_style, Style.DEFAULT.getValue()));
    if (likeViewStyle == null) {
        throw new IllegalArgumentException("Unsupported value for LikeView 'style'");
    }

    auxiliaryViewPosition = AuxiliaryViewPosition
            .fromInt(a.getInt(R.styleable.com_facebook_like_view_auxiliary_view_position,
                    AuxiliaryViewPosition.DEFAULT.getValue()));
    if (auxiliaryViewPosition == null) {
        throw new IllegalArgumentException("Unsupported value for LikeView 'auxiliary_view_position'");
    }

    horizontalAlignment = HorizontalAlignment.fromInt(a.getInt(
            R.styleable.com_facebook_like_view_horizontal_alignment, HorizontalAlignment.DEFAULT.getValue()));
    if (horizontalAlignment == null) {
        throw new IllegalArgumentException("Unsupported value for LikeView 'horizontal_alignment'");
    }

    foregroundColor = a.getColor(R.styleable.com_facebook_like_view_foreground_color, NO_FOREGROUND_COLOR);

    a.recycle();
}

From source file:com.kaplandroid.colorbook.SlidingLayer.java

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

    // Style/*w ww . j  a  v  a2 s . com*/
    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SlidingLayer);

    // Set the side of the screen
    setStickTo(ta.getInt(R.styleable.SlidingLayer_stickTo, STICK_TO_AUTO));

    // Sets the shadow drawable
    int shadowRes = ta.getResourceId(R.styleable.SlidingLayer_shadowDrawable, -1);
    if (shadowRes != -1) {
        setShadowDrawable(shadowRes);
    }

    // Sets the shadow width
    setShadowWidth((int) ta.getDimension(R.styleable.SlidingLayer_shadowWidth, 0));

    // Sets the ability to close the layer by tapping in any empty space
    closeOnTapEnabled = ta.getBoolean(R.styleable.SlidingLayer_closeOnTapEnabled, true);

    ta.recycle();

    init();
}

From source file:com.gm.grecyclerview.GmRecyclerView.java

private void initAttrs(Context context, AttributeSet attrs, int defStyle) {
    TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.grv_GRecyclerView,
            defStyle, 0);//from  ww w . j  a v a 2s. c o m
    layoutMode = typedArray.getInt(R.styleable.grv_GRecyclerView_grv_layoutMode, 0);
    gridSpanCount = typedArray.getInt(R.styleable.grv_GRecyclerView_grv_gridSpanCount, 0);
    gridSpanSequence = typedArray.getString(R.styleable.grv_GRecyclerView_grv_gridSpanSequence);
    spacing = typedArray.getDimensionPixelSize(R.styleable.grv_GRecyclerView_grv_spacing, 0);
    verticalSpacing = typedArray.getDimensionPixelSize(R.styleable.grv_GRecyclerView_grv_verticalSpacing, 0);
    horizontalSpacing = typedArray.getDimensionPixelSize(R.styleable.grv_GRecyclerView_grv_horizontalSpacing,
            0);
    isSpacingIncludeEdge = typedArray.getBoolean(R.styleable.grv_GRecyclerView_grv_isSpacingIncludeEdge, false);
    showDivider = typedArray.getBoolean(R.styleable.grv_GRecyclerView_grv_showDivider, false);
    showLastDivider = typedArray.getBoolean(R.styleable.grv_GRecyclerView_grv_showLastDivider, false);
    dividerColor = typedArray.getColor(R.styleable.grv_GRecyclerView_grv_dividerColor, 0);
    dividerOrientation = typedArray.getInt(R.styleable.grv_GRecyclerView_grv_dividerOrientation, 2);
    dividerPaddingLeft = typedArray.getDimensionPixelSize(R.styleable.grv_GRecyclerView_grv_dividerPaddingLeft,
            0);
    dividerPaddingRight = typedArray
            .getDimensionPixelSize(R.styleable.grv_GRecyclerView_grv_dividerPaddingRight, 0);
    dividerPaddingTop = typedArray.getDimensionPixelSize(R.styleable.grv_GRecyclerView_grv_dividerPaddingTop,
            0);
    dividerPaddingBottom = typedArray
            .getDimensionPixelSize(R.styleable.grv_GRecyclerView_grv_dividerPaddingBottom, 0);
    isSnappyEnabled = typedArray.getBoolean(R.styleable.grv_GRecyclerView_grv_snappy, false);
    snapAlignment = typedArray.getInt(R.styleable.grv_GRecyclerView_grv_snap_alignment, 0);
    showEmptyStateView = typedArray.getBoolean(R.styleable.grv_GRecyclerView_grv_showEmptyStateView, false);
    emptyStateViewRes = typedArray.getResourceId(R.styleable.grv_GRecyclerView_grv_emptyStateView, 0);
    loadMoreViewRes = typedArray.getResourceId(R.styleable.grv_GRecyclerView_grv_loadMoreView, 0);
    typedArray.recycle();
}

From source file:android.support.v7.widget.AppCompatTextViewAutoSizeHelper.java

void loadFromAttributes(AttributeSet attrs, int defStyleAttr) {
    float autoSizeMinTextSizeInPx = UNSET_AUTO_SIZE_UNIFORM_CONFIGURATION_VALUE;
    float autoSizeMaxTextSizeInPx = UNSET_AUTO_SIZE_UNIFORM_CONFIGURATION_VALUE;
    float autoSizeStepGranularityInPx = UNSET_AUTO_SIZE_UNIFORM_CONFIGURATION_VALUE;

    TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.AppCompatTextView, defStyleAttr, 0);
    if (a.hasValue(R.styleable.AppCompatTextView_autoSizeTextType)) {
        mAutoSizeTextType = a.getInt(R.styleable.AppCompatTextView_autoSizeTextType,
                TextViewCompat.AUTO_SIZE_TEXT_TYPE_NONE);
    }//from   ww  w  .  j ava 2s.  c o  m
    if (a.hasValue(R.styleable.AppCompatTextView_autoSizeStepGranularity)) {
        autoSizeStepGranularityInPx = a.getDimension(R.styleable.AppCompatTextView_autoSizeStepGranularity,
                UNSET_AUTO_SIZE_UNIFORM_CONFIGURATION_VALUE);
    }
    if (a.hasValue(R.styleable.AppCompatTextView_autoSizeMinTextSize)) {
        autoSizeMinTextSizeInPx = a.getDimension(R.styleable.AppCompatTextView_autoSizeMinTextSize,
                UNSET_AUTO_SIZE_UNIFORM_CONFIGURATION_VALUE);
    }
    if (a.hasValue(R.styleable.AppCompatTextView_autoSizeMaxTextSize)) {
        autoSizeMaxTextSizeInPx = a.getDimension(R.styleable.AppCompatTextView_autoSizeMaxTextSize,
                UNSET_AUTO_SIZE_UNIFORM_CONFIGURATION_VALUE);
    }
    if (a.hasValue(R.styleable.AppCompatTextView_autoSizePresetSizes)) {
        final int autoSizeStepSizeArrayResId = a
                .getResourceId(R.styleable.AppCompatTextView_autoSizePresetSizes, 0);
        if (autoSizeStepSizeArrayResId > 0) {
            final TypedArray autoSizePreDefTextSizes = a.getResources()
                    .obtainTypedArray(autoSizeStepSizeArrayResId);
            setupAutoSizeUniformPresetSizes(autoSizePreDefTextSizes);
            autoSizePreDefTextSizes.recycle();
        }
    }
    a.recycle();

    if (supportsAutoSizeText()) {
        if (mAutoSizeTextType == TextViewCompat.AUTO_SIZE_TEXT_TYPE_UNIFORM) {
            // If uniform auto-size has been specified but preset values have not been set then
            // replace the auto-size configuration values that have not been specified with the
            // defaults.
            if (!mHasPresetAutoSizeValues) {
                final DisplayMetrics displayMetrics = mContext.getResources().getDisplayMetrics();

                if (autoSizeMinTextSizeInPx == UNSET_AUTO_SIZE_UNIFORM_CONFIGURATION_VALUE) {
                    autoSizeMinTextSizeInPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,
                            DEFAULT_AUTO_SIZE_MIN_TEXT_SIZE_IN_SP, displayMetrics);
                }

                if (autoSizeMaxTextSizeInPx == UNSET_AUTO_SIZE_UNIFORM_CONFIGURATION_VALUE) {
                    autoSizeMaxTextSizeInPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,
                            DEFAULT_AUTO_SIZE_MAX_TEXT_SIZE_IN_SP, displayMetrics);
                }

                if (autoSizeStepGranularityInPx == UNSET_AUTO_SIZE_UNIFORM_CONFIGURATION_VALUE) {
                    autoSizeStepGranularityInPx = DEFAULT_AUTO_SIZE_GRANULARITY_IN_PX;
                }

                validateAndSetAutoSizeTextTypeUniformConfiguration(autoSizeMinTextSizeInPx,
                        autoSizeMaxTextSizeInPx, autoSizeStepGranularityInPx);
            }

            setupAutoSizeText();
        }
    } else {
        mAutoSizeTextType = TextViewCompat.AUTO_SIZE_TEXT_TYPE_NONE;
    }
}

From source file:com.lovejjfg.blogdemo.ui.indicator.RectPageIndicator.java

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

    if (isInEditMode())
        return;//from  w ww .j av  a 2 s.  c o  m

    //Load defaults from resources
    final Resources res = getResources();
    final int defaultPageColor = res.getColor(R.color.colorPrimary);
    final int defaultFillColor = res.getColor(R.color.colorPrimaryDark);
    final int defaultOrientation = 0;
    final int defaultStrokeColor = res.getColor(R.color.whitesmoke);
    final float defaultStrokeWidth = res.getDimension(R.dimen.dp1);
    final float defaultRectWidth = res.getDimension(R.dimen.dp4) * 2.0f;
    final boolean defaultCentered = true;
    final boolean defaultSnap = true;

    //Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RectPageIndicator, defStyle, 0);
    mRectWidth = a.getDimension(R.styleable.RectPageIndicator_rectWidth, defaultRectWidth);
    a.recycle();

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

    mCentered = a.getBoolean(R.styleable.CirclePageIndicator_centered, defaultCentered);
    mOrientation = a.getInt(R.styleable.CirclePageIndicator_orientation, defaultOrientation);
    mPaintPageFill.setStyle(Paint.Style.FILL);
    mPaintPageFill.setColor(a.getColor(R.styleable.CirclePageIndicator_pageColor, defaultPageColor));
    mPaintStroke.setStyle(Paint.Style.STROKE);
    mPaintStroke.setColor(a.getColor(R.styleable.CirclePageIndicator_strokeColor, defaultStrokeColor));
    mPaintStroke
            .setStrokeWidth(a.getDimension(R.styleable.CirclePageIndicator_strokeWidth, defaultStrokeWidth));
    mPaintFill.setStyle(Paint.Style.FILL);
    mPaintFill.setColor(a.getColor(R.styleable.CirclePageIndicator_fillColor, defaultFillColor));
    mSnap = a.getBoolean(R.styleable.CirclePageIndicator_snap, defaultSnap);

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

    a.recycle();

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}

From source file:com.actionbarsherlock.widget.ActivityChooserView.java

/**
 * Create a new instance./*from  w w  w .  j a  v  a 2  s.c  o  m*/
 *
 * @param context The application environment.
 * @param attrs A collection of attributes.
 * @param defStyle The default style to apply to this view.
 */
public ActivityChooserView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    mContext = context;

    TypedArray attributesArray = context.obtainStyledAttributes(attrs, R.styleable.SherlockActivityChooserView,
            defStyle, 0);

    mInitialActivityCount = attributesArray.getInt(R.styleable.SherlockActivityChooserView_initialActivityCount,
            ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_DEFAULT);

    Drawable expandActivityOverflowButtonDrawable = attributesArray
            .getDrawable(R.styleable.SherlockActivityChooserView_expandActivityOverflowButtonDrawable);

    attributesArray.recycle();

    LayoutInflater inflater = LayoutInflater.from(mContext);
    inflater.inflate(R.layout.abs__activity_chooser_view, this, true);

    mCallbacks = new Callbacks();

    mActivityChooserContent = (IcsLinearLayout) findViewById(R.id.abs__activity_chooser_view_content);
    mActivityChooserContentBackground = mActivityChooserContent.getBackground();

    mDefaultActivityButton = (FrameLayout) findViewById(R.id.abs__default_activity_button);
    mDefaultActivityButton.setOnClickListener(mCallbacks);
    mDefaultActivityButton.setOnLongClickListener(mCallbacks);
    mDefaultActivityButtonImage = (ImageView) mDefaultActivityButton.findViewById(R.id.abs__image);

    mExpandActivityOverflowButton = (FrameLayout) findViewById(R.id.abs__expand_activities_button);
    mExpandActivityOverflowButton.setOnClickListener(mCallbacks);
    mExpandActivityOverflowButtonImage = (ImageView) mExpandActivityOverflowButton
            .findViewById(R.id.abs__image);
    mExpandActivityOverflowButtonImage.setImageDrawable(expandActivityOverflowButtonDrawable);

    mAdapter = new ActivityChooserViewAdapter();
    mAdapter.registerDataSetObserver(new DataSetObserver() {
        @Override
        public void onChanged() {
            super.onChanged();
            updateAppearance();
        }
    });

    Resources resources = context.getResources();
    mListPopupMaxWidth = Math.max(resources.getDisplayMetrics().widthPixels / 2,
            resources.getDimensionPixelSize(R.dimen.abs__config_prefDialogWidth));
}

From source file:android.support.v7.internal.widget.ActivityChooserView.java

/**
 * Create a new instance.// www.j a va 2 s  .  c  o  m
 *
 * @param context The application environment.
 * @param attrs A collection of attributes.
 * @param defStyle The default style to apply to this view.
 */
public ActivityChooserView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    TypedArray attributesArray = context.obtainStyledAttributes(attrs, R.styleable.ActivityChooserView,
            defStyle, 0);

    mInitialActivityCount = attributesArray.getInt(R.styleable.ActivityChooserView_initialActivityCount,
            ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_DEFAULT);

    Drawable expandActivityOverflowButtonDrawable = attributesArray
            .getDrawable(R.styleable.ActivityChooserView_expandActivityOverflowButtonDrawable);

    attributesArray.recycle();

    LayoutInflater inflater = LayoutInflater.from(getContext());
    inflater.inflate(R.layout.abc_activity_chooser_view, this, true);

    mCallbacks = new Callbacks();

    mActivityChooserContent = (LinearLayoutCompat) findViewById(R.id.activity_chooser_view_content);
    mActivityChooserContentBackground = mActivityChooserContent.getBackground();

    mDefaultActivityButton = (FrameLayout) findViewById(R.id.default_activity_button);
    mDefaultActivityButton.setOnClickListener(mCallbacks);
    mDefaultActivityButton.setOnLongClickListener(mCallbacks);
    mDefaultActivityButtonImage = (ImageView) mDefaultActivityButton.findViewById(R.id.image);

    final FrameLayout expandButton = (FrameLayout) findViewById(R.id.expand_activities_button);
    expandButton.setOnClickListener(mCallbacks);
    expandButton.setOnTouchListener(new ListPopupWindow.ForwardingListener(expandButton) {
        @Override
        public ListPopupWindow getPopup() {
            return getListPopupWindow();
        }

        @Override
        protected boolean onForwardingStarted() {
            showPopup();
            return true;
        }

        @Override
        protected boolean onForwardingStopped() {
            dismissPopup();
            return true;
        }
    });
    mExpandActivityOverflowButton = expandButton;
    mExpandActivityOverflowButtonImage = (ImageView) expandButton.findViewById(R.id.image);
    mExpandActivityOverflowButtonImage.setImageDrawable(expandActivityOverflowButtonDrawable);

    mAdapter = new ActivityChooserViewAdapter();
    mAdapter.registerDataSetObserver(new DataSetObserver() {
        @Override
        public void onChanged() {
            super.onChanged();
            updateAppearance();
        }
    });

    Resources resources = context.getResources();
    mListPopupMaxWidth = Math.max(resources.getDisplayMetrics().widthPixels / 2,
            resources.getDimensionPixelSize(R.dimen.abc_config_prefDialogWidth));
}

From source file:com.albedinsky.android.setting.SettingSelectionDialogPreference.java

/**
 *///from  w w w.  j a  va2 s.  c  o m
@Override
@SuppressWarnings("ResourceType")
protected void onConfigureDialogOptions(@NonNull SelectionDialog.SelectionOptions options,
        @NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr,
        @StyleRes int defStyleRes) {
    super.onConfigureDialogOptions(options, context, attrs, defStyleAttr, defStyleRes);
    final TypedArray typedArray = context.obtainStyledAttributes(attrs,
            R.styleable.Ui_Settings_SelectionDialogPreference, defStyleAttr, defStyleRes);
    for (int i = 0; i < typedArray.getIndexCount(); i++) {
        final int index = typedArray.getIndex(i);
        if (index == R.styleable.Ui_Settings_SelectionDialogPreference_dialogSelectionMode) {
            options.selectionMode(typedArray.getInt(index, options.selectionMode()));
        } else if (index == R.styleable.Ui_Settings_SelectionDialogPreference_dialogEmptySelectionAllowed) {
            options.emptySelectionAllowed(typedArray.getBoolean(index, options.shouldAllowEmptySelection()));
        }
    }
    typedArray.recycle();
}

From source file:com.iangclifton.android.floatlabel.FloatLabel.java

private void init(Context context, AttributeSet attrs, int defStyle) {
    // Load custom attributes
    final int layout;
    final CharSequence text;
    final CharSequence hint;
    final ColorStateList hintColor;
    final int floatLabelColor;
    final int inputType;

    if (attrs == null) {
        layout = R.layout.float_label;
        text = null;/*from   w  w  w  .  j  a v  a 2s  .  c o m*/
        hint = null;
        hintColor = null;
        floatLabelColor = 0;
        inputType = 0;
    } else {
        final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FloatLabel, defStyle, 0);

        layout = a.getResourceId(R.styleable.FloatLabel_android_layout, R.layout.float_label);
        text = a.getText(R.styleable.FloatLabel_android_text);
        hint = a.getText(R.styleable.FloatLabel_android_hint);
        hintColor = a.getColorStateList(R.styleable.FloatLabel_android_textColorHint);
        floatLabelColor = a.getColor(R.styleable.FloatLabel_floatLabelColor, 0);
        inputType = a.getInt(R.styleable.FloatLabel_android_inputType, InputType.TYPE_CLASS_TEXT);
        a.recycle();
    }

    inflate(context, layout, this);
    mEditText = (EditText) findViewById(R.id.edit_text);
    if (mEditText == null) {
        throw new RuntimeException("Your layout must have an EditText whose ID is @id/edit_text");
    }
    mEditText.setHint(hint);
    mEditText.setText(text);
    if (hintColor != null) {
        mEditText.setHintTextColor(hintColor);
    }
    if (inputType != 0) {
        mEditText.setInputType(inputType);
    }

    mLabel = (TextView) findViewById(R.id.float_label);
    if (mLabel == null) {
        throw new RuntimeException("Your layout must have a TextView whose ID is @id/float_label");
    }
    mLabel.setText(mEditText.getHint());
    if (floatLabelColor != 0)
        mLabel.setTextColor(floatLabelColor);

    // Listen to EditText to know when it is empty or nonempty
    mEditText.addTextChangedListener(new EditTextWatcher());

    // Check current state of EditText
    if (mEditText.getText().length() == 0) {
        ViewHelper.setAlpha(mLabel, 0);
        mLabelShowing = false;
    } else {
        mLabel.setVisibility(View.VISIBLE);
        mLabelShowing = true;
    }

    // Mark init as complete to prevent accidentally breaking the view by
    // adding children
    mInitComplete = true;
}

From source file:android.support.v7.widget.AppCompatCompoundButtonHelper.java

void loadFromAttributes(AttributeSet attrs, int defStyleAttr) {
    TypedArray a = mView.getContext().obtainStyledAttributes(attrs, R.styleable.CompoundButton, defStyleAttr,
            0);/* w  ww.ja  v  a  2 s . c  o m*/
    try {
        if (a.hasValue(R.styleable.CompoundButton_android_button)) {
            final int resourceId = a.getResourceId(R.styleable.CompoundButton_android_button, 0);
            if (resourceId != 0) {
                mView.setButtonDrawable(mDrawableManager.getDrawable(mView.getContext(), resourceId));
            }
        }
        if (a.hasValue(R.styleable.CompoundButton_buttonTint)) {
            CompoundButtonCompat.setButtonTintList(mView,
                    a.getColorStateList(R.styleable.CompoundButton_buttonTint));
        }
        if (a.hasValue(R.styleable.CompoundButton_buttonTintMode)) {
            CompoundButtonCompat.setButtonTintMode(mView,
                    DrawableUtils.parseTintMode(a.getInt(R.styleable.CompoundButton_buttonTintMode, -1), null));
        }
    } finally {
        a.recycle();
    }
}