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.github.fountaingeyser.typefacecompat.FactoryTypefaceCompat.java

@Override
public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
    View result = null;/*from   w w w.  j  a  v  a  2s . co  m*/
    // Allow base factory to try and create a view first
    if (mBaseFactory != null) {
        result = mBaseFactory.onCreateView(parent, name, context, attrs);
    }
    if (result instanceof TextView) {
        TextView textView = (TextView) result;
        String fontFamily = null;
        int style = 0;
        Resources.Theme theme = context.getTheme();
        TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.TextViewAppearance, 0, 0);
        TypedArray appearance = null;
        int ap = a.getResourceId(R.styleable.TextViewAppearance_android_textAppearance, -1);
        a.recycle();
        if (ap != -1) {
            appearance = theme.obtainStyledAttributes(ap, R.styleable.TextAppearance);
        }
        if (appearance != null) {
            fontFamily = appearance.getString(R.styleable.TextAppearance_android_fontFamily);
            style = appearance.getInt(R.styleable.TextAppearance_android_textStyle, 0);
            appearance.recycle();
        }
        a = theme.obtainStyledAttributes(attrs, R.styleable.TextAppearance, 0, 0);
        if (a.hasValue(R.styleable.TextAppearance_android_fontFamily)) {
            fontFamily = a.getString(R.styleable.TextAppearance_android_fontFamily);
            style = a.getInt(R.styleable.TextAppearance_android_textStyle, 0);
        }
        a.recycle();
        if (fontFamily != null && TypefaceCompat.isSupported(fontFamily)) {
            Typeface tf = TypefaceCompat.create(textView.getContext(), fontFamily, style);
            if (tf != null) {
                textView.setTypeface(tf);
            }
        }
    }
    return result;
}

From source file:com.google.samples.apps.topeka.widget.AvatarView.java

public AvatarView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AvatarView, defStyle, 0);
    try {// w ww .j a  v a 2  s .com
        final int avatarDrawableId = a.getResourceId(R.styleable.AvatarView_avatar, NOT_FOUND);
        if (avatarDrawableId != NOT_FOUND) {
            setAvatar(avatarDrawableId);
        }
    } finally {
        a.recycle();
    }
}

From source file:com.flan.stock.view.TouTiaoPagerView.java

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

    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.SimplePagerView);
    int layout = typedArray.getResourceId(R.styleable.SimplePagerView_pager_layout,
            R.layout.layout_news_toutio);
    typedArray.recycle();//from  w w w .  j  av  a  2 s.co m

    inflate(context, layout, this);
    viewPager = (ViewPager) this.findViewById(R.id.vp_fragment);
    img_tab = (ImageView) this.findViewById(R.id.img_tab);

}

From source file:de.vanita5.twittnuker.util.ThemeUtils.java

public static int getTitleTextAppearance(final Context context) {
    final TypedArray a = context.obtainStyledAttributes(null, new int[] { android.R.attr.titleTextStyle },
            android.R.attr.actionBarStyle, android.R.style.Widget_Holo_ActionBar);
    final int textAppearance = a.getResourceId(0, android.R.style.TextAppearance_Holo);
    a.recycle();//from   w  w w. ja va 2s .c  om
    return textAppearance;
}

From source file:com.google.android.gcm.demo.ui.GroupsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
    mSenders = SenderCollection.getInstance(getActivity());
    mDeviceGroupsHelper = new DeviceGroupsHelper(getActivity());

    View view = inflater.inflate(R.layout.fragment_groups, container, false);
    setHtmlMode(view, R.id.groups_description);
    view.findViewById(R.id.groups_create_new).setOnClickListener(this);

    if (savedState != null) {
        mGroupToBeDeletedSenderId = savedState.getString(STATE_GROUP_TO_BE_DELETED_SENDER_ID);
        mGroupToBeDeletedName = savedState.getString(STATE_GROUP_TO_BE_DELETED_NAME);
    }/*from   w  w w.j  a v a  2  s  .c om*/

    int[] attrs = new int[] { R.attr.selectableItemBackground };
    TypedArray typedArray = getActivity().obtainStyledAttributes(attrs);
    selectableBackgroundResource = typedArray.getResourceId(0, 0);

    return view;
}

From source file:com.google.samples.apps.iosched.myschedule.MyScheduleSingleDayFragment.java

private void initViews() {
    mDayId = getArguments().getInt(MyScheduleActivity.ARG_CONFERENCE_DAY_INDEX, 0);

    // Set id to list view, so it can be referred to from tests
    TypedArray ids = getResources().obtainTypedArray(R.array.myschedule_listview_ids);
    int listViewId = ids.getResourceId(mDayId, 0);
    getListView().setId(listViewId);/*from   w w w .j a  v  a  2 s .  com*/

}

From source file:de.vanita5.twittnuker.util.ThemeUtils.java

public static Context getActionBarContext(final Context context) {
    final TypedArray a = context.obtainStyledAttributes(
            new int[] { android.R.attr.actionBarTheme, android.R.attr.actionBarWidgetTheme });
    final int resId;
    try {/*from   w  w w . j  a v a2 s .com*/
        resId = a.hasValue(0) ? a.getResourceId(0, 0) : a.getResourceId(1, 0);
    } finally {
        a.recycle();
    }
    if (resId == 0)
        return context;
    return new ContextThemeWrapper(context, resId);
}

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

@SuppressWarnings("ResourceType")
public void themeViews(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
    };/*from w  w  w.j  av a 2 s.c  o m*/
    TypedArray typedArray = context.obtainStyledAttributes(colorAttrs);
    int def = R.color.color_transparent;
    int colorNight = ContextCompat.getColor(context, typedArray.getResourceId(0, def));
    int colorAstro = ContextCompat.getColor(context, typedArray.getResourceId(1, def));
    int colorNautical = ContextCompat.getColor(context, typedArray.getResourceId(2, def));
    int colorCivil = ContextCompat.getColor(context, typedArray.getResourceId(3, def));
    int colorDay = ContextCompat.getColor(context, typedArray.getResourceId(4, def));
    typedArray.recycle();

    colorizeImageView(ic_night, colorNight);
    colorizeImageView(ic_astro, colorAstro);
    colorizeImageView(ic_nautical, colorNautical);
    colorizeImageView(ic_civil, colorCivil);
    colorizeImageView(ic_day, colorDay);
}

From source file:co.paulburke.android.textviewpager.TextViewPager.java

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

    mPagerAdapter = new TextViewPagerAdapter(context, mMeasureListener);

    if (attrs != null) {
        TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.TextViewPager);

        int layout = attributes.getResourceId(R.styleable.TextViewPager_textViewLayout, -1);
        CharSequence text = attributes.getText(R.styleable.TextViewPager_android_text);

        mPagerAdapter.setTextViewLayout(layout);
        mPagerAdapter.setText(text);//from   w w  w  .j ava2 s.  c  o m

        attributes.recycle();
    }

    setAdapter(mPagerAdapter);
}

From source file:cm.aptoidetv.pt.RecommendationBuilder.java

public Notification build() throws IOException {

    Log.d(TAG, "Building notification - " + this.toString());

    if (mNotificationManager == null) {
        mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    }//from  w  w w.j a  v a  2  s.c o  m

    Bundle extras = new Bundle();
    if (mBackgroundUri != null) {
        Log.d(TAG, "Background - " + mBackgroundUri);
        extras.putString(Notification.EXTRA_BACKGROUND_IMAGE_URI, mBackgroundUri);
    }

    Bitmap image = Picasso.with(mContext).load(mImageUri)
            .resize(Utils.convertDpToPixel(mContext, CARD_WIDTH), Utils.convertDpToPixel(mContext, CARD_HEIGHT))
            .get();

    TypedArray typedArray = mContext.getTheme().obtainStyledAttributes(ThemePicker.getThemePicker(),
            new int[] { R.attr.brandColor });
    int brandColorResourceId = typedArray.getResourceId(0, 0);
    typedArray.recycle();

    Notification notification = new NotificationCompat.BigPictureStyle(new NotificationCompat.Builder(mContext)
            .setContentTitle(mTitle).setContentText(mDescription).setPriority(mPriority).setLocalOnly(true)
            .setOngoing(true).setColor(mContext.getResources().getColor(brandColorResourceId))
            .setCategory(Notification.CATEGORY_RECOMMENDATION).setLargeIcon(image).setSmallIcon(mSmallIcon)
            .setContentIntent(mIntent).setExtras(extras)).build();

    mNotificationManager.notify(mId, notification);
    mNotificationManager = null;
    return notification;
}