Android Roboguice Use Guide (8) Provider bindings

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.