1:效果图
2:代码复用部分,以及用来耦合的抽象接口
抽象接口:
publicinterface IFillView //接口,暴露的抽象规则;
{
View getView();
void setBroadCast(IBroadcast iBroadcast);
}
public interface IBroadcast// 回调接口,用于类之间的异步交互{
void setTag(Object type);
void close();
}
复用代码
public abstractclass PoupFillView extendsPopupWindow implements IBroadcast
{
private Activityact;
private int width,height;
private IFillViewiFillView;
public PoupFillView(Activityact,IFillView iFillView)
{
super(act);
this.act=act;
this.iFillView=iFillView;
height=act.getWindowManager().getDefaultDisplay().getHeight();
width=act.getWindowManager().getDefaultDisplay().getWidth();
}
public void initPoupView()
{
setContentView(iFillView.getView());
iFillView.setBroadCast(this);
setFocusable(true);
setTouchable(true);
setHeight(height);
setWidth(width);
setAnimationStyle(R.style.PopumAnimation);
}
@Override
public void close()
{
dismiss();
}
}
3:扩展部分(只需实现IFillView接口即可)
{
private Context context ;
public PoupWebView(Context context)
{
this . context =context;
initView();
initInfo();
initBinder();
}
private View contentView ;
private TextView tvOk ;
private TextView tvNo ;
private WebView webView ;
private void initView()
{
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 );
}
private String url ;
private void initInfo()
{
url = "http://mt.sohu.com/20150923/n421957484.shtml" ;
}
private void initBinder()
{
webView .loadUrl( url );
tvOk .setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View v) {
iBroadcast .setTag( false );
iBroadcast .close();
}
});
tvNo .setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View v) {
iBroadcast .setTag( true );
iBroadcast .close();
}
});
}
@Override
public View getView() {
return contentView ;
}
private IBroadcast iBroadcast ;
@Override
public void setBroadCast(IBroadcast iBroadcast)
{
this . iBroadcast =iBroadcast;
}
4 ,调用使用
final PoupFillView poupFillView= new PoupFillView(getActivity(), new PoupWebView(getActivity())) {
@Override
public void setTag(Object type) {
Boolean logic= (Boolean) type;
if (!logic)
{
getActivity().finish();
}
}
};
poupFillView .showAtLocation( convertView , Gravity. CENTER , 0 , 0 );
}