复用代码,接口扩展(自定义poupwindow)
来源:互联网 发布:js修改字体颜色 编辑:程序博客网 时间:2024/06/05 21:49
1:效果图
2:代码复用部分,以及用来耦合的抽象接口
抽象接口:
publicinterface IFillView //接口,暴露的抽象规则;
{
View getView();
void setBroadCast(IBroadcast iBroadcast);
}
public interface IBroadcast//回调接口,用于类之间的异步交互{
voidsetTag(Object type);
void close();
}
复用代码
public abstractclass PoupFillViewextendsPopupWindowimplementsIBroadcast
{
privateActivityact;
private intwidth,height;
privateIFillViewiFillView;
publicPoupFillView(Activityact,IFillView iFillView)
{
super(act);
this.act=act;
this.iFillView=iFillView;
height=act.getWindowManager().getDefaultDisplay().getHeight();
width=act.getWindowManager().getDefaultDisplay().getWidth();
}
public voidinitPoupView()
{
setContentView(iFillView.getView());
iFillView.setBroadCast(this);
setFocusable(true);
setTouchable(true);
setHeight(height);
setWidth(width);
setAnimationStyle(R.style.PopumAnimation);
}
@Override
public voidclose()
{
dismiss();
}
}
3:扩展部分(只需实现IFillView接口即可)
{
privateContext context;
public PoupWebView(Context context)
{
this.context=context;
initView();
initInfo();
initBinder();
}
privateView contentView;
privateTextView tvOk;
privateTextView tvNo;
privateWebView webView;
private voidinitView()
{
contentView= LayoutInflater.from(context).inflate(R.layout.poup_webview,null);
tvOk= (TextView)contentView.findViewById(R.id.poup_ok);
tvNo= (TextView)contentView.findViewById(R.id.poup_no);
webView= (WebView)contentView.findViewById(R.id.poup_web);
}
privateString url;
private voidinitInfo()
{
url="http://mt.sohu.com/20150923/n421957484.shtml";
}
private voidinitBinder()
{
webView.loadUrl(url);
tvOk.setOnClickListener(newView.OnClickListener() {
@Override
public voidonClick(View v) {
iBroadcast.setTag(false);
iBroadcast.close();
}
});
tvNo.setOnClickListener(newView.OnClickListener() {
@Override
public voidonClick(View v) {
iBroadcast.setTag(true);
iBroadcast.close();
}
});
}
@Override
public View getView() {
returncontentView;
}
privateIBroadcast iBroadcast;
@Override
public voidsetBroadCast(IBroadcast iBroadcast)
{
this.iBroadcast=iBroadcast;
}
4,调用使用
final PoupFillView poupFillView=newPoupFillView(getActivity(),newPoupWebView(getActivity())) {
@Override
public voidsetTag(Object type) {
Boolean logic= (Boolean) type;
if(!logic)
{
getActivity().finish();
}
}
};
poupFillView.showAtLocation(convertView, Gravity.CENTER,0,0);
}
- 复用代码,接口扩展(自定义poupwindow)
- MicrosoftReportingServicesinAction:用自定义代码扩展Microsoft2000ReportingServic…
- 用代码扩展和自定义应用程序模型
- 利用Tag接口自定义标签扩展
- 纯代码实现UITableViewCell的自定义扩展
- Java自定义注解代码实现与扩展
- mybatis-generator扩展-自定义代码注释
- 通过接口复用代码
- PoupWindow背景util
- 探索c++接口动态代理,实现二进制层次上的代码扩展(一)
- 扩展拦截器接口的自定义拦截器配置
- 扩展 Rxbinding,打造自定义监听多控件接口
- Microsoft Reporting Services in Action:用自定义代码扩展 Microsoft SQL Server 2000 Reporting Services
- Microsoft Reporting Services in Action:用自定义代码扩展 Microsoft SQL Server 2000 Reporting Services
- Microsoft Reporting Services in Action:用自定义代码扩展 Microsoft SQL Server 2000 Reporting Services
- 扩展接口
- 扩展接口
- 编写自定义任务,轻松扩展Ant (3) 代码
- 线程(1)
- Android CoolWeather 天气
- Spark Shuffle初探
- 【C++自学之旅】MFC计算器设计
- Leetcode第五周周赛
- 复用代码,接口扩展(自定义poupwindow)
- android中子线程访问UI组件
- 黑客教程:自建钓鱼网站入侵Gmail账户
- 第3周项目4-顺序表应用问题(2)
- 以此纪念我的第一个博客
- Android root-tools
- Is Subsequence
- 如何在shell脚本里传递一个变量给awk
- Android KeyboardListener键盘