Search in sources :

Example 26 with StateListDrawable

use of android.graphics.drawable.StateListDrawable in project Android-Iconics by mikepenz.

the class PlaygroundActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_playground);
    //Show how to style the text of an existing TextView
    TextView tv1 = (TextView) findViewById(R.id.test1);
    new Iconics.IconicsBuilder().ctx(this).style(new ForegroundColorSpan(Color.WHITE), new BackgroundColorSpan(Color.BLACK), new RelativeSizeSpan(2f)).styleFor("faw-adjust", new BackgroundColorSpan(Color.RED), new ForegroundColorSpan(Color.parseColor("#33000000")), new RelativeSizeSpan(2f)).on(tv1).build();
    //You can also do some advanced stuff like setting an image within a text
    TextView tv2 = (TextView) findViewById(R.id.test5);
    SpannableString sb = new SpannableString(tv2.getText());
    IconicsDrawable d = new IconicsDrawable(this, FontAwesome.Icon.faw_android).sizeDp(48).paddingDp(4);
    sb.setSpan(new ImageSpan(d, DynamicDrawableSpan.ALIGN_BOTTOM), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    tv2.setText(sb);
    //Set the icon of an ImageView (or something else) as drawable
    ImageView iv2 = (ImageView) findViewById(R.id.test2);
    iv2.setImageDrawable(new IconicsDrawable(this, FontAwesome.Icon.faw_thumbs_o_up).sizeDp(48).color(Color.parseColor("#aaFF0000")).contourWidthDp(1));
    //Set the icon of an ImageView (or something else) as bitmap
    ImageView iv3 = (ImageView) findViewById(R.id.test3);
    iv3.setImageBitmap(new IconicsDrawable(this, FontAwesome.Icon.faw_android).sizeDpX(48).sizeDpY(32).paddingDp(4).roundedCornersDp(8).color(Color.parseColor("#deFF0000")).toBitmap());
    //Show how to style the text of an existing button
    Button b4 = (Button) findViewById(R.id.test4);
    new Iconics.IconicsBuilder().ctx(this).style(new BackgroundColorSpan(Color.BLACK)).style(new RelativeSizeSpan(2f)).style(new ForegroundColorSpan(Color.WHITE)).on(b4).build();
    //Show how to style the text of an existing button
    ImageButton b6 = (ImageButton) findViewById(R.id.test6);
    StateListDrawable iconStateListDrawable = new StateListDrawable();
    iconStateListDrawable.addState(new int[] { android.R.attr.state_pressed }, new IconicsDrawable(this, FontAwesome.Icon.faw_thumbs_o_up).sizeDp(48).color(Color.parseColor("#aaFF0000")).contourWidthDp(1));
    iconStateListDrawable.addState(new int[] {}, new IconicsDrawable(this, FontAwesome.Icon.faw_thumbs_o_up).sizeDp(48).color(Color.parseColor("#aa00FF00")).contourWidthDp(2));
    b6.setImageDrawable(iconStateListDrawable);
    ListView listView = (ListView) findViewById(R.id.list);
    IconicsDrawable iconicsDrawableBase = new IconicsDrawable(this).actionBar().color(Color.GREEN).backgroundColor(Color.RED);
    IconicsDrawable[] array = new IconicsArrayBuilder(iconicsDrawableBase).add(FontAwesome.Icon.faw_android).add(Octicons.Icon.oct_octoface).add("Hallo").add('A').add(";)").build();
    listView.setAdapter(new IconsAdapter(this, array));
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) Iconics(com.mikepenz.iconics.Iconics) RelativeSizeSpan(android.text.style.RelativeSizeSpan) StateListDrawable(android.graphics.drawable.StateListDrawable) SpannableString(android.text.SpannableString) ImageButton(android.widget.ImageButton) ListView(android.widget.ListView) ImageButton(android.widget.ImageButton) Button(android.widget.Button) IconicsArrayBuilder(com.mikepenz.iconics.IconicsArrayBuilder) TextView(android.widget.TextView) ImageView(android.widget.ImageView) IconicsDrawable(com.mikepenz.iconics.IconicsDrawable) BackgroundColorSpan(android.text.style.BackgroundColorSpan) ImageSpan(android.text.style.ImageSpan)

Example 27 with StateListDrawable

use of android.graphics.drawable.StateListDrawable in project GalleryFinal by pengjianbo.

the class FloatingActionButton method createFillDrawable.

private StateListDrawable createFillDrawable(RectF circleRect) {
    StateListDrawable drawable = new StateListDrawable();
    drawable.addState(new int[] { android.R.attr.state_pressed }, createCircleDrawable(circleRect, mColorPressed));
    drawable.addState(new int[] {}, createCircleDrawable(circleRect, mColorNormal));
    return drawable;
}
Also used : StateListDrawable(android.graphics.drawable.StateListDrawable)

Example 28 with StateListDrawable

use of android.graphics.drawable.StateListDrawable in project material-calendarview by prolificinteractive.

the class DayView method generateBackground.

private static Drawable generateBackground(int color, int fadeTime, Rect bounds) {
    StateListDrawable drawable = new StateListDrawable();
    drawable.setExitFadeDuration(fadeTime);
    drawable.addState(new int[] { android.R.attr.state_checked }, generateCircleDrawable(color));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        drawable.addState(new int[] { android.R.attr.state_pressed }, generateRippleDrawable(color, bounds));
    } else {
        drawable.addState(new int[] { android.R.attr.state_pressed }, generateCircleDrawable(color));
    }
    drawable.addState(new int[] {}, generateCircleDrawable(Color.TRANSPARENT));
    return drawable;
}
Also used : StateListDrawable(android.graphics.drawable.StateListDrawable)

Example 29 with StateListDrawable

use of android.graphics.drawable.StateListDrawable in project robolectric by robolectric.

the class ShadowStateListDrawableTest method testAddDrawableWithWildCardState.

@Test
public void testAddDrawableWithWildCardState() {
    Drawable drawable = ShadowDrawable.createFromPath("/foo");
    StateListDrawable stateListDrawable = new StateListDrawable();
    stateListDrawable.addState(StateSet.WILD_CARD, drawable);
    ShadowStateListDrawable shadow = shadowOf(stateListDrawable);
    Drawable drawableForState = shadow.getDrawableForState(StateSet.WILD_CARD);
    assertNotNull(drawableForState);
    assertThat(((ShadowBitmapDrawable) shadowOf(drawableForState)).getPath()).isEqualTo("/foo");
}
Also used : StateListDrawable(android.graphics.drawable.StateListDrawable) Drawable(android.graphics.drawable.Drawable) StateListDrawable(android.graphics.drawable.StateListDrawable) Test(org.junit.Test)

Example 30 with StateListDrawable

use of android.graphics.drawable.StateListDrawable in project platform_frameworks_base by android.

the class IconUtilities method createIconDrawable.

public Drawable createIconDrawable(Drawable src) {
    Bitmap scaled = createIconBitmap(src);
    StateListDrawable result = new StateListDrawable();
    result.addState(new int[] { android.R.attr.state_focused }, new BitmapDrawable(createSelectedBitmap(scaled, false)));
    result.addState(new int[] { android.R.attr.state_pressed }, new BitmapDrawable(createSelectedBitmap(scaled, true)));
    result.addState(new int[0], new BitmapDrawable(scaled));
    result.setBounds(0, 0, mIconTextureWidth, mIconTextureHeight);
    return result;
}
Also used : Bitmap(android.graphics.Bitmap) BitmapDrawable(android.graphics.drawable.BitmapDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable)

Aggregations

StateListDrawable (android.graphics.drawable.StateListDrawable)163 Drawable (android.graphics.drawable.Drawable)43 LayerDrawable (android.graphics.drawable.LayerDrawable)24 BitmapDrawable (android.graphics.drawable.BitmapDrawable)21 GradientDrawable (android.graphics.drawable.GradientDrawable)21 ColorDrawable (android.graphics.drawable.ColorDrawable)15 Bitmap (android.graphics.Bitmap)13 TextView (android.widget.TextView)12 ShapeDrawable (android.graphics.drawable.ShapeDrawable)11 View (android.view.View)11 AnimationDrawable (android.graphics.drawable.AnimationDrawable)9 ClipDrawable (android.graphics.drawable.ClipDrawable)9 SuppressLint (android.annotation.SuppressLint)8 Paint (android.graphics.Paint)8 ColorStateList (android.content.res.ColorStateList)7 RippleDrawable (android.graphics.drawable.RippleDrawable)7 TargetApi (android.annotation.TargetApi)6 TypedArray (android.content.res.TypedArray)6 TextPaint (android.text.TextPaint)5 Button (android.widget.Button)5