在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ Android/ Provider Bindings
Just-in-time Bindings
Binding Annotations
Standard Injection
第一個例子 Hello World
Bindings 概述
Linked Bindings
如何綁定 generic 類型
@Provides Methods
RoboGuice 功能描述
概述
綜合示例 Astroboy
Inject Resources
Instance Bindings
Inject 自定義 View
Scopes
Provider Bindings
Untargetted Bindings
Inject Extra
第一個例子 Hello World
Inject Context
發(fā)送接收 Events
Inject View

Provider Bindings

如果 @Provides 方法很復(fù)雜的話,可以將這些代碼移動到單獨的類中。這個類需要實現(xiàn) Guice 的 Provider 接口,該接口定義如下:

public interface Provider<T> {
 T get();
}

為一個 generic 接口。

本例我們定義一個 PathProvider,用于返回一個 Path 對象:

public class PathProvider implements Provider<Path>{

 private String pathdata
 = "M 60 20 Q -40 70 60 120 Q 160 70 60 20 z";
 @Override
 public Path get() {
 return Path.fromString(pathdata);
 }

}

然后在 Module 中定義從 Path 類到 Provider 的綁定:

bind(Path.class).toProvider(PathProvider.class);

然后使用繪制這個 Path:

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);

 }

}

http://wiki.jikexueyuan.com/project/android-roboguice/images/12.png" alt="" />