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.joaquimley.faboptions.FabOptions.java

private void inflateButtonsFromAttrs(Context context, TypedArray attributes) {
    if (attributes.hasValue(R.styleable.FabOptions_button_menu)) {
        setButtonsMenu(context, attributes.getResourceId(R.styleable.FabOptions_button_menu, 0));
    }//from  w  ww .ja  v a 2 s .co  m
}

From source file:cn.thinkjoy.startup.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();//w  w w  . j  av a  2s.  co  m
    super.setOnTabChangedListener(this);
}

From source file:com.example.fragmentdemo.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();/*  w  ww  .j a v a2  s.co m*/

    super.setOnTabChangedListener(this);

    // If owner hasn't made its own view hierarchy, then as a convenience
    // we will construct a standard one here.
    /*System.out.println("tabs= " + findViewById(android.R.id.tabs));
    if (findViewById(android.R.id.tabs) == null) {
    LinearLayout ll = new LinearLayout(context);
    ll.setOrientation(LinearLayout.VERTICAL);
    addView(ll, new FrameLayout.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));
            
    TabWidget tw = new TabWidget(context);
    tw.setId(android.R.id.tabs);
    tw.setOrientation(TabWidget.HORIZONTAL);
    ll.addView(tw, new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.FILL_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.FILL_PARENT, 0, 1));
    }*/
}

From source file:com.fast.access.kam.widget.colorpicker.dashclockpicker.ColorPreference.java

private void initAttrs(AttributeSet attrs, int defStyle) {
    TypedArray a = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.ColorPreference, defStyle,
            defStyle);//from www  .j av  a2s . c  om

    try {
        mItemLayoutId = a.getResourceId(R.styleable.ColorPreference_itemLayout, mItemLayoutId);
        mNumColumns = a.getInteger(R.styleable.ColorPreference_numColumns, mNumColumns);
        int choicesResId = a.getResourceId(R.styleable.ColorPreference_choices,
                R.array.default_color_choice_values);
        if (choicesResId > 0) {
            String[] choices = a.getResources().getStringArray(choicesResId);
            mColorChoices = new int[choices.length];
            for (int i = 0; i < choices.length; i++) {
                mColorChoices[i] = Color.parseColor(choices[i]);
            }
        }

    } finally {
        a.recycle();
    }

    setWidgetLayoutResource(mItemLayoutId);
}

From source file:com.facebook.FacebookButtonBase.java

private void parseCompoundDrawableAttributes(final Context context, final AttributeSet attrs,
        final int defStyleAttr, final int defStyleRes) {
    final int attrsResources[] = { android.R.attr.drawableLeft, android.R.attr.drawableTop,
            android.R.attr.drawableRight, android.R.attr.drawableBottom, android.R.attr.drawablePadding, };
    final TypedArray a = context.getTheme().obtainStyledAttributes(attrs, attrsResources, defStyleAttr,
            defStyleRes);//from   ww w.jav  a  2  s .c o  m
    try {
        setCompoundDrawablesWithIntrinsicBounds(a.getResourceId(0, 0), a.getResourceId(1, 0),
                a.getResourceId(2, 0), a.getResourceId(3, 0));
        setCompoundDrawablePadding(a.getDimensionPixelSize(4, 0));

    } finally {
        a.recycle();
    }
}

From source file:com.forrestguice.suntimeswidget.LightMapView.java

/**
 * @param context a context used to access resources
 *///from ww  w.j  av a  2  s .c om
@SuppressWarnings("ResourceType")
private void initColors(Context context) {
    int[] colorAttrs = { R.attr.graphColor_night, // 0
            R.attr.graphColor_astronomical, // 1
            R.attr.graphColor_nautical, // 2
            R.attr.graphColor_civil, // 3
            R.attr.graphColor_day, // 4
            R.attr.graphColor_pointFill, // 5
            R.attr.graphColor_pointStroke }; // 6
    TypedArray typedArray = context.obtainStyledAttributes(colorAttrs);
    int def = R.color.color_transparent;

    colorNight = ContextCompat.getColor(context, typedArray.getResourceId(0, def));
    colorAstro = ContextCompat.getColor(context, typedArray.getResourceId(1, def));
    colorNautical = ContextCompat.getColor(context, typedArray.getResourceId(2, def));
    colorCivil = ContextCompat.getColor(context, typedArray.getResourceId(3, def));
    colorDay = ContextCompat.getColor(context, typedArray.getResourceId(4, def));
    colorPointFill = ContextCompat.getColor(context, typedArray.getResourceId(5, def));
    colorPointStroke = ContextCompat.getColor(context, typedArray.getResourceId(6, def));

    typedArray.recycle();
}

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.  ja  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:com.gigamole.millspinners.lib.CirclesWaveSpinner.java

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

    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CirclesWaveSpinner);

    try {/*w  w  w.j a  v  a2s.  com*/
        this.speed = typedArray.getInteger(R.styleable.CirclesWaveSpinner_speed, 3000) / 2;
        this.halfSpeed = this.speed / 2;

        final int colorsId = typedArray.getResourceId(R.styleable.CirclesWaveSpinner_colors, 0);
        if (colorsId != 0) {
            this.colors = getResources().getIntArray(colorsId);
        } else {
            this.colors = getResources().getIntArray(R.array.wave_colors);
        }
    } finally {
        typedArray.recycle();
    }
}

From source file:com.jaspersoft.android.jaspermobile.dialog.CalendarDayDialogFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final TypedArray a = getActivity().obtainStyledAttributes(null,
            android.support.v7.appcompat.R.styleable.AlertDialog,
            android.support.v7.appcompat.R.attr.alertDialogStyle, 0);

    mMultiChoiceItemLayout = a
            .getResourceId(android.support.v7.appcompat.R.styleable.AlertDialog_multiChoiceItemLayout, 0);
    mListLayout = a.getResourceId(android.support.v7.appcompat.R.styleable.AlertDialog_listLayout, 0);

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

From source file:com.actionbarsherlock.internal.view.menu.ListMenuItemView.java

public ListMenuItemView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs);
    mContext = context;/*ww w.j  a  v  a 2  s.  co  m*/

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

    mBackground = a.getDrawable(R.styleable.SherlockMenuView_itemBackground);
    mTextAppearance = a.getResourceId(R.styleable.SherlockMenuView_itemTextAppearance, -1);
    mPreserveIconSpacing = a.getBoolean(R.styleable.SherlockMenuView_preserveIconSpacing, false);
    mTextAppearanceContext = context;

    a.recycle();
}