android - Setting widget background to programmaticaly generated gradient -
i'm struggling making widget pretty, widget fights ;(
i have problem setting widget layout background generated linear gradient.
for now, have found how generate linear gradient custom "weigth" of colors gradient:
public static paintdrawable createlineargradient(final int left, final int top, final int right, final int bottom, final int[] colors, final float[] positions) { shapedrawable.shaderfactory shaderfactory = new shapedrawable.shaderfactory() { @override public shader resize(int width, int height) { lineargradient lg = new lineargradient(left, top, right, bottom, colors, positions, shader.tilemode.repeat); return lg; } }; paintdrawable gradient = new paintdrawable(); gradient.setshape(new rectshape()); gradient.setshaderfactory(shaderfactory); return gradient; } and here way set widget background drawable drawable folder:
int backgroundid = getdrawablebyname(context, "round_transparrent_background"); remoteviews.setint(r.id.mainlayout, "setbackgroundresource", backgroundid); i need way write command following:
drawable background = createlineargradient(params ... ); remoteviews.setint(r.id.mainlayout, "setbackgroundresource", background);
remoteviews inherently limited functions. makes sense when consider information pass remoteviews needs travel across processes, , not classes/data types supported.
there no way pass arbitrary drawable object remoteviews -- none of methods support it, , drawable in general not class data can marshalled across processes. reason works drawable resources resource id integer, , android knows how inflate them bitmaps (for pngs) or respective drawable implementations (for declared xml).
as see it, strategy might work draw gradient bitmap using canvas apis , use imageview in appwidget act background. call remoteviews.setimageviewbitmap() set content of imageview.
Comments
Post a Comment