Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android, Drawable.createFromStream(is, srcname): what's the 2nd parameter meaning?

Which is the meaning of the second parameter of Drawable.createFromStream() method?

From Android APIs I only get:

public static Drawable createFromStream (InputStream is, String srcName) Create a drawable from an inputstream 

In all examples I have read I see they use the string "src": is it the name of the directory where the drawable is cached, relative to my application's root dir?

One parallel question: where am I supposed to find Android core sources (for example of Drawable.createFromStream() method...), to avoid such silly questions, in future?

like image 288
MarcoS Avatar asked May 25 '11 09:05

MarcoS


People also ask

What are Drawables in Android?

A drawable resource is a general concept for a graphic that can be drawn to the screen and which you can retrieve with APIs such as getDrawable(int) or apply to another XML resource with attributes such as android:drawable and android:icon . There are several different types of drawables: Bitmap File.

What is SetColorFilter?

SetColorFilter(ColorFilter) Specify an optional color filter for the drawable. SetColorFilter(Color, PorterDuff+Mode) Obsolete. Specify a color and Porter-Duff mode to be the color filter for this drawable.

What is Drawable class in Android?

A Drawable is a general abstraction for "something that can be drawn." Most often you will deal with Drawable as the type of resource retrieved for drawing things to the screen; the Drawable class provides a generic API for dealing with an underlying visual resource that may take a variety of forms.


1 Answers

It's basically useless:

Based on Froyo source, it is used when creating nine-patch images from the resource, but not when creating a regular Bitmap:

852 private static Drawable drawableFromBitmap(Resources res, Bitmap bm, byte[] np, 853         Rect pad, String srcName) { 854 855     if (np != null) { 856        return new NinePatchDrawable(res, bm, np, pad, srcName); 857     } 858 859     return new BitmapDrawable(res, bm); 860  } 

You get there by following the Drawable code:

createFromStream returns:

return createFromResourceStream(null, null, is, srcName, null); 

which in turn uses:

return drawableFromBitmap(res, bm, np, pad, srcName); 

(np comes from Bitmap#getNinePatchChunk();) and this calls:

return new NinePatchDrawable(res, bm, np, pad, srcName); 

Finally, you get to the NinePatch declaration:

public class NinePatch 

Create a drawable projection from a bitmap to nine patches.

Parameters:

bitmap The bitmap describing the patches.

chunk The 9-patch data chunk describing how the underlying bitmap is split apart and drawn.

srcName The name of the source for the bitmap. Might be null.

like image 157
Aleadam Avatar answered Oct 09 '22 09:10

Aleadam