If the @provides method is complex, you can move the code to a separate class. This class needs to implement the Guice provider interface, which defines the following
Public interface
provider<t> {
T get ();}
As a generic interface.
In this example we define a pathprovider for returning a Path object:
public class Pathprovider implements
provider<path>{
private String pathdata
= "M Q-40 70 60 120 Q 160 Z ";
@Override public
Path get () {return
path.fromstring (pathdata);
}
}
Then define the bindings from the path class to the provider in module:
Bind
(Path.class). Toprovider (Pathprovider.class);
Then use this Path to draw:
public class Providerbindingsdemo extends graphics2dactivity{@Inject path path;
protected void DrawImage () {AffineTransform mat1;
Colors Color Redcolor = new Color (0x96ff0000, true);
Color Greencolor = new color (0XFF00FF00);
Color Bluecolor = new Color (0x750000ff, true);
MAT1 = new AffineTransform ();
Mat1.translate (30, 40);
Mat1.rotate ( -30 * math.pi/180.0);
Clear the canvas with white color.
Graphics2d.clear (Color.White);
Graphics2d.setaffinetransform (New AffineTransform ());
SolidBrush brush = new SolidBrush (Greencolor);
Graphics2d.fill (brush, path);
Graphics2d.setaffinetransform (MAT1);
Brush = new SolidBrush (Bluecolor);
Com.mapdigit.drawing.Pen Pen = new Com.mapdigit.drawing.Pen (Redcolor, 5);
Graphics2d.setpenandbrush (pen, brush);
Graphics2d.draw (null, PATH);
Graphics2d.fill (null, PATH); }
}
This example downloads: Http://www.imobilebbs.com/download/android/roboguice/ProviderBindingsDe mo.zip
View a full set of articles: Http://www.bianceng.cn/OS/extra/201301/34950.htm