Context obtainStyledAttributes - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Context obtainStyledAttributes method.

This code example shows how to use the following methods:obtainStyledAttributes
    assertThat(dataDir.exists()).isTrue();
  } 
 
  @Test 
  public void shouldStubThemeStuff() throws Exception { 
    assertThat(context.obtainStyledAttributes(null)).isNotNull();
    assertThat(context.obtainStyledAttributes(0, null)).isNotNull();
    assertThat(context.obtainStyledAttributes(null, null)).isNotNull();
    assertThat(context.obtainStyledAttributes(null, null, 0, 0)).isNotNull();
  } 
 
  @Test 
  public void getCacheDir_shouldCreateDirectory() throws Exception { 
    assertTrue(context.getCacheDir().exists());
  } 
 
  @Test 
  public void getExternalCacheDir_shouldCreateDirectory() throws Exception { 
    assertTrue(context.getExternalCacheDir().exists());
  } 
8
CodeRank
This code example shows how to use the following methods:obtainStyledAttributes
This code example shows how to use the following methods:obtainStyledAttributes
 
    public TitleBarView(Context context, AttributeSet attrs) {
        super(context, attrs, 0);
        mContext=context;
        mVisibilityController = new VisibilityController(this);
        TypedArray a = context.obtainStyledAttributes(attrs, new int[] {
        		android.R.attr.windowTitleStyle,
                android.R.attr.defaultValue });
        mIsLegacy = a.getBoolean(a.getIndex(1 /* defaultValue */), false);
        if (mIsLegacy) {
            mTitleResource = a.getResourceId(a.getIndex(0 /* windowTitleStyle */), 0);
        } else { 
            a.recycle();
            a = context.obtainStyledAttributes(null,
                    new int[] { android.R.attr.titleTextStyle,
                            android.R.attr.subtitleTextStyle },
                    android.R.attr.actionBarStyle,
                    0); 
            mTitleResource = a.getResourceId(a.getIndex(0 /* titleTextStyle */), 0);
            mSubtitleResource = a.getResourceId(a.getIndex(1 /* subtitleTextStyle */), 0);
7
CodeRank
This code example shows how to use the following methods:obtainStyledAttributes
This code example shows how to use the following methods:obtainStyledAttributes
 
    public TitleBarView(Context context, AttributeSet attrs) {
        super(context, attrs, 0);
        mContext=context;
        mVisibilityController = new VisibilityController(this);
        TypedArray a = context.obtainStyledAttributes(attrs, new int[] {
        		android.R.attr.windowTitleStyle,
                android.R.attr.defaultValue });
        mIsLegacy = a.getBoolean(a.getIndex(1 /* defaultValue */), false);
        if (mIsLegacy) {
            mTitleResource = a.getResourceId(a.getIndex(0 /* windowTitleStyle */), 0);
        } else { 
            a.recycle();
            a = context.obtainStyledAttributes(null,
                    new int[] { android.R.attr.titleTextStyle,
                            android.R.attr.subtitleTextStyle },
                    android.R.attr.actionBarStyle,
                    0); 
            mTitleResource = a.getResourceId(a.getIndex(0 /* titleTextStyle */), 0);
            mSubtitleResource = a.getResourceId(a.getIndex(1 /* subtitleTextStyle */), 0);
7
CodeRank
This code example shows how to use the following methods:obtainStyledAttributes
    resources = Robolectric.application.getResources();
  } 
 
  @Test 
  public void getResources() throws Exception { 
    assertNotNull(context.obtainStyledAttributes(new int[]{}).getResources());
  } 
 
  @Test 
  public void getInt_shouldReturnDefaultValue() throws Exception { 
    assertThat(context.obtainStyledAttributes(new int[]{android.R.attr.alpha}).getInt(0, -1)).isEqualTo(-1);
  } 
 
  @Test 
  public void getInteger_shouldReturnDefaultValue() throws Exception { 
    assertThat(context.obtainStyledAttributes(new int[]{android.R.attr.alpha}).getInteger(0, -1)).isEqualTo(-1);
  } 
 
  @Test 
  public void getInt_withFlags_shouldReturnValue() throws Exception { 
7
CodeRank
This code example shows how to use the following methods:obtainStyledAttributes
        context = new Activity();
    } 
 
    @Test 
    public void getResources() throws Exception { 
        assertNotNull(context.obtainStyledAttributes(null).getResources());
    } 
 
    @Test 
    public void getInt_shouldReturnDefaultValue() throws Exception { 
        assertThat(context.obtainStyledAttributes(new int[]{android.R.attr.alpha}).getInt(0, -1)).isEqualTo(-1);
    } 
 
    @Test 
    public void getInteger_shouldReturnDefaultValue() throws Exception { 
        assertThat(context.obtainStyledAttributes(new int[]{android.R.attr.alpha}).getInteger(0, -1)).isEqualTo(-1);
    } 
 
    @Test 
    public void getResourceId_shouldReturnDefaultValue() throws Exception { 
6
CodeRank
This code example shows how to use the following methods:obtainStyledAttributes
    private boolean mAllCaps;
 
    public CapitalizingButton(Context context, AttributeSet attrs) {
        super(context, attrs);
 
        TypedArray a = context.obtainStyledAttributes(attrs, R_styleable_Button);
        mAllCaps = a.getBoolean(R_styleable_Button_textAllCaps, true);
        a.recycle();
    } 
 
    public void setTextCompat(CharSequence text) {
        if (SANS_ICE_CREAM && mAllCaps && text != null) {
            if (IS_GINGERBREAD) {
                try { 
                    setText(text.toString().toUpperCase(Locale.ROOT));
                } catch (NoSuchFieldError e) {
                    //Some manufacturer broke Locale.ROOT. See #572. 
                    setText(text.toString().toUpperCase());
                } 
            } else { 
6
CodeRank
This code example shows how to use the following methods:obtainStyledAttributes
		this(context, attrs, 0);
	} 
 
	public ActionBarTitleView(final Context context, final AttributeSet attrs, final int defStyle) {
		super(context, attrs, defStyle);
		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.Widget_Holo_ActionBar);
		a.recycle();
		setTextAppearance(context, textAppearance);
	} 
 
} 
6
CodeRank
This code example shows how to use the following methods:obtainStyledAttributes
		this(context, attrs, 0);
	} 
 
	public ActionBarHomeAsUpIndicator(final Context context, final AttributeSet attrs, final int defStyle) {
		super(context, attrs, defStyle);
		final TypedArray a = context.obtainStyledAttributes(new int[] { android.R.attr.homeAsUpIndicator });
		final Drawable d = a.getDrawable(0);
		a.recycle();
		setImageDrawable(d);
		setScaleType(ScaleType.CENTER);
	} 
 
} 
6
CodeRank

Related Context obtainStyledAttributes Questions & Answers:

obtainStyledAttributes Method Overview
Retrieve styled attribute information in this Context's theme.
See Code Examples for other Android Context Methods: