Example usage for android.content Context obtainStyledAttributes

List of usage examples for android.content Context obtainStyledAttributes

Introduction

In this page you can find the example usage for android.content Context obtainStyledAttributes.

Prototype

public final TypedArray obtainStyledAttributes(AttributeSet set, @StyleableRes int[] attrs,
        @AttrRes int defStyleAttr, @StyleRes int defStyleRes) 

Source Link

Document

Retrieve styled attribute information in this Context's theme.

Usage

From source file:com.android.util.widget.FragmentTabHost.java

private void initFragmentTabHost(Context context, AttributeSet attrs) {
    TypedArray a = context.obtainStyledAttributes(attrs, new int[] { android.R.attr.inflatedId }, 0, 0);
    mContainerId = a.getResourceId(0, 0);
    a.recycle();//  ww  w. java  2 s  .c  o m

    super.setOnTabChangedListener(this);

    // If owner hasn't made its own view hierarchy, then as a convenience
    // we will construct a standard one here.
    /**
    if (findViewById(android.R.id.tabs) == null) {
    LinearLayout ll = new LinearLayout(context);
    ll.setOrientation(LinearLayout.VERTICAL);
    addView(ll, new FrameLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
            
    TabWidget tw = new TabWidget(context);
    tw.setId(android.R.id.tabs);
    tw.setOrientation(TabWidget.HORIZONTAL);
    ll.addView(tw, new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT, 0));
            
    FrameLayout fl = new FrameLayout(context);
    fl.setId(android.R.id.tabcontent);
    ll.addView(fl, new LinearLayout.LayoutParams(0, 0, 0));
            
    mRealTabContent = fl = new FrameLayout(context);
    mRealTabContent.setId(mContainerId);
    ll.addView(fl, new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, 0, 1));
    }*/
}

From source file:com.acious.android.paginationseekbar.internal.Marker.java

public Marker(Context context, AttributeSet attrs, int defStyleAttr, String maxValue) {
    super(context, attrs, defStyleAttr);
    DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PaginationSeekBar,
            R.attr.paginationSeekBarStyle, R.style.DefaultSeekBar);

    int padding = (int) (PADDING_DP * displayMetrics.density) * 2;
    int textAppearanceId = a.getResourceId(R.styleable.PaginationSeekBar_psb_indicatorTextAppearance,
            R.style.DefaultIndicatorTextAppearance);
    mNumber = new TextView(context);
    //Add some padding to this textView so the bubble has some space to breath
    mNumber.setPadding(padding, 0, padding, 0);
    mNumber.setTextAppearance(context, textAppearanceId);
    mNumber.setGravity(Gravity.CENTER);//from   w  w  w.j  a v  a  2s  .  c om
    mNumber.setText(maxValue);
    mNumber.setMaxLines(1);
    mNumber.setSingleLine(true);
    SeekBarCompat.setTextDirection(mNumber, TEXT_DIRECTION_LOCALE);
    mNumber.setVisibility(View.INVISIBLE);

    //add some padding for the elevation shadow not to be clipped
    //I'm sure there are better ways of doing this...
    setPadding(padding, padding, padding, padding);

    resetSizes(maxValue);

    mSeparation = (int) (SEPARATION_DP * displayMetrics.density);
    int thumbSize = (int) (ThumbDrawable.DEFAULT_SIZE_DP * displayMetrics.density);
    ColorStateList color = a.getColorStateList(R.styleable.PaginationSeekBar_psb_indicatorColor);
    mMarkerDrawable = new MarkerDrawable(color, thumbSize);
    mMarkerDrawable.setCallback(this);
    mMarkerDrawable.setMarkerListener(this);
    mMarkerDrawable.setExternalOffset(padding);

    //Elevation for anroid 5+
    float elevation = a.getDimension(R.styleable.PaginationSeekBar_psb_indicatorElevation,
            ELEVATION_DP * displayMetrics.density);
    ViewCompat.setElevation(this, elevation);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        SeekBarCompat.setOutlineProvider(this, mMarkerDrawable);
    }
    a.recycle();
}

From source file:android.support.v7.preference.MultiSelectListPreferenceCompat.java

public MultiSelectListPreferenceCompat(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MultiSelectListPreference,
            defStyleAttr, defStyleRes);//from w  ww.ja v  a  2  s .c o m

    mEntries = TypedArrayUtils.getTextArray(a, R.styleable.MultiSelectListPreference_entries,
            R.styleable.MultiSelectListPreference_android_entries);

    mEntryValues = TypedArrayUtils.getTextArray(a, R.styleable.MultiSelectListPreference_entryValues,
            R.styleable.MultiSelectListPreference_android_entryValues);

    a.recycle();
}

From source file:android.support.v7.preference.ListPreference.java

public ListPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

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

    mEntries = TypedArrayUtils.getTextArray(a, R.styleable.ListPreference_entries,
            R.styleable.ListPreference_android_entries);

    mEntryValues = TypedArrayUtils.getTextArray(a, R.styleable.ListPreference_entryValues,
            R.styleable.ListPreference_android_entryValues);

    a.recycle();/*  w  w  w  .j  a v a2 s. c  o  m*/

    /* Retrieve the Preference summary attribute since it's private
     * in the Preference class.
     */
    a = context.obtainStyledAttributes(attrs, R.styleable.Preference, defStyleAttr, defStyleRes);

    mSummary = TypedArrayUtils.getString(a, R.styleable.Preference_summary,
            R.styleable.Preference_android_summary);

    a.recycle();
}

From source file:android.support.v14.preference.MultiSelectListPreference.java

public MultiSelectListPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    final TypedArray a = context.obtainStyledAttributes(attrs,
            android.support.v7.preference.R.styleable.MultiSelectListPreference, defStyleAttr, defStyleRes);

    mEntries = TypedArrayUtils.getTextArray(a,
            android.support.v7.preference.R.styleable.MultiSelectListPreference_entries,
            android.support.v7.preference.R.styleable.MultiSelectListPreference_android_entries);

    mEntryValues = TypedArrayUtils.getTextArray(a,
            android.support.v7.preference.R.styleable.MultiSelectListPreference_entryValues,
            android.support.v7.preference.R.styleable.MultiSelectListPreference_android_entryValues);

    a.recycle();//from  w  w w . j a va2 s.  com
}

From source file:ar.rulosoft.custompref.SeekBarCustomPreference.java

private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CustomDialogPref, defStyleAttr,
            defStyleRes);//www  .j a va  2  s  .com
    setMax(a.getInt(R.styleable.CustomDialogPref_val_max, mPreferredMax));
    setMin(a.getInt(R.styleable.CustomDialogPref_val_min, mPreferredMin));
    a.recycle();
    setLayoutResource(R.layout.preference_seekbar_widget_layout);
}

From source file:com.astir_trotter.atcustom.ui.iconics.core.view.IconicsImageView.java

public IconicsImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (!isInEditMode()) {
        // Attribute initialization
        final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.IconicsImageView, defStyle, 0);
        String icon = a.getString(R.styleable.IconicsImageView_iiv_icon);

        //set the color even if we had no image yet
        mColor = a.getColor(R.styleable.IconicsImageView_iiv_color, 0);
        mSize = a.getDimensionPixelSize(R.styleable.IconicsImageView_iiv_size, -1);
        mPadding = a.getDimensionPixelSize(R.styleable.IconicsImageView_iiv_padding, -1);
        mContourColor = a.getColor(R.styleable.IconicsImageView_iiv_contour_color, 0);
        mContourWidth = a.getDimensionPixelSize(R.styleable.IconicsImageView_iiv_contour_width, -1);
        mBackgroundColor = a.getColor(R.styleable.IconicsImageView_iiv_background_color, 0);
        mCornerRadius = a.getDimensionPixelSize(R.styleable.IconicsImageView_iiv_corner_radius, -1);

        //recycle the typedArray
        a.recycle();/*from   ww w .j av  a2s . c o  m*/

        //set the scale type for this view
        setScaleType(ScaleType.CENTER_INSIDE);

        //if we have no icon return now
        if (icon == null) {
            return;
        }

        //get the drawable
        mIcon = new IconicsDrawable(context, icon);

        //set attributes
        setAttributes();

        //set our values for this view
        setImageDrawable(mIcon);
    }
}

From source file:com.android.demos.module.animation.materialloadingprogressbar.CircleProgressBar.java

private void init(Context context, AttributeSet attrs, int defStyleAttr) {
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircleProgressBar, defStyleAttr, 0);
    //        <attr name="mlpb_inner_radius" format="dimension"/>
    //        <attr name="mlpb_background_color" format="color"/>
    //        <attr name="mlpb_progress_color" format="color"/>
    //        <attr name="mlpb_progress_stoke_width" format="dimension"/>
    //        <attr name="mlpb_arrow_width" format="dimension"/>
    //        <attr name="mlpb_arrow_height" format="dimension"/>
    ///* ww w  .ja  v a  2  s.c o  m*/
    //        <attr name="mlpb_progress" format="integer"/>
    //        <attr name="mlpb_max" format="integer"/>
    //
    //
    //        <attr name="mlpb_progress_text_size" format="dimension"/>
    //        <attr name="mlpb_progress_text_color" format="color"/>
    //
    //        <attr name="mlpb_progress_text_offset" format="dimension"/>
    //
    //        <attr name="mlpb_progress_text_visibility" format="enum">
    //        <enum name="visible" value="0"/>
    //        <enum name="invisible" value="1"/>
    //        </attr>
    final float density = getContext().getResources().getDisplayMetrics().density;

    mBackGroundColor = a.getColor(R.styleable.CircleProgressBar_mlpb_background_color, DEFAULT_CIRCLE_BG_LIGHT);

    mProgressColor = a.getColor(R.styleable.CircleProgressBar_mlpb_progress_color, DEFAULT_CIRCLE_BG_LIGHT);//ToDO 

    mInnerRadius = a.getDimensionPixelOffset(R.styleable.CircleProgressBar_mlpb_inner_radius, -1);

    mProgressStokeWidth = a.getDimensionPixelOffset(R.styleable.CircleProgressBar_mlpb_progress_stoke_width,
            (int) (STROKE_WIDTH_LARGE * density));
    mArrowWidth = a.getDimensionPixelOffset(R.styleable.CircleProgressBar_mlpb_arrow_width, -1);
    mArrowHeight = a.getDimensionPixelOffset(R.styleable.CircleProgressBar_mlpb_arrow_height, -1);
    mTextSize = a.getDimensionPixelOffset(R.styleable.CircleProgressBar_mlpb_progress_text_size,
            (int) (DEFAULT_TEXT_SIZE * density));
    mTextColor = a.getColor(R.styleable.CircleProgressBar_mlpb_progress_text_color, Color.BLACK);

    mShowArrow = a.getBoolean(R.styleable.CircleProgressBar_mlpb_show_arrow, false);
    mCircleBackgroundEnabled = a.getBoolean(R.styleable.CircleProgressBar_mlpb_enable_circle_background, true);

    mProgress = a.getInt(R.styleable.CircleProgressBar_mlpb_progress, 0);
    mMax = a.getInt(R.styleable.CircleProgressBar_mlpb_max, 100);
    int textVisible = a.getInt(R.styleable.CircleProgressBar_mlpb_progress_text_visibility, 1);
    if (textVisible != 1) {
        mIfDrawText = true;
    }

    mTextPaint = new Paint();
    mTextPaint.setStyle(Paint.Style.FILL);
    mTextPaint.setColor(mTextColor);
    mTextPaint.setTextSize(mTextSize);
    mTextPaint.setAntiAlias(true);
    a.recycle();
    mProgressDrawable = new MaterialProgressDrawable(getContext(), this);
    super.setImageDrawable(mProgressDrawable);
}

From source file:android.preference.MultiSelectDragListPreference.java

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

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MultiSelectDragListPreference, 0, 0);
    mEntries = a.getTextArray(R.styleable.MultiSelectDragListPreference_entries);
    mEntryValues = a.getTextArray(R.styleable.MultiSelectDragListPreference_entryValues);
    a.recycle();// w ww  .  j  av  a 2 s  .  co m
}

From source file:am.widget.MaterialProgressImageView.java

private void initView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    final float density = getResources().getDisplayMetrics().density;
    ArrayList<Integer> colors = new ArrayList<>();
    TypedArray custom = context.obtainStyledAttributes(attrs, R.styleable.MaterialProgressImageView,
            defStyleAttr, defStyleRes);//w  w w. ja v a  2 s .  com
    boolean autoStart = custom.getBoolean(R.styleable.MaterialProgressImageView_mpiAutoStart, true);
    int color = custom.getColor(R.styleable.MaterialProgressImageView_mpiShadowsCircleColor, DEFAULT_COLOR);
    float elevation = custom.getDimension(R.styleable.MaterialProgressImageView_mpiElevation,
            density * SHADOW_ELEVATION);
    if (custom.hasValue(R.styleable.MaterialProgressImageView_mpiSchemeColor1)) {
        colors.add(custom.getColor(R.styleable.MaterialProgressImageView_mpiSchemeColor1, Color.BLACK));
    }
    if (custom.hasValue(R.styleable.MaterialProgressImageView_mpiSchemeColor2)) {
        colors.add(custom.getColor(R.styleable.MaterialProgressImageView_mpiSchemeColor2, Color.BLACK));
    }
    if (custom.hasValue(R.styleable.MaterialProgressImageView_mpiSchemeColor3)) {
        colors.add(custom.getColor(R.styleable.MaterialProgressImageView_mpiSchemeColor3, Color.BLACK));
    }
    if (custom.hasValue(R.styleable.MaterialProgressImageView_mpiSchemeColor4)) {
        colors.add(custom.getColor(R.styleable.MaterialProgressImageView_mpiSchemeColor4, Color.BLACK));
    }
    if (custom.hasValue(R.styleable.MaterialProgressImageView_mpiSchemeColor5)) {
        colors.add(custom.getColor(R.styleable.MaterialProgressImageView_mpiSchemeColor5, Color.BLACK));
    }
    custom.recycle();
    setElevationCompat(elevation);
    Drawable background = getBackground();
    if (background == null)
        setShadowsCircleBackground(color);
    drawable = new MaterialProgressDrawable(density);
    drawable.setBackgroundColor(0x00000000);
    drawable.setAlpha(255);
    drawable.setCallback(this);
    final int size = colors.size();
    if (size > 0) {
        int[] colorArray = new int[size];
        for (int i = 0; i < size; i++) {
            colorArray[i] = colors.get(i);
        }
        drawable.setColorSchemeColors(colorArray);
    }
    setImageDrawable(drawable);
    if (autoStart)
        start();
}