package com.wz.preadcloud.ui.activity;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.wz.preadcloud.R;
import com.wz.preadcloud.command.util.SceenMannage;
import com.wz.preadcloud.service.layout.ImageLoaderService;
import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
public class AdDialog extends AlertDialog implements android.view.View.OnClickListener{
private Context mContext;
//图片的地址
private String mUrl;
//抛出点击事件
private OnAdClickListener onAdClickListener;
public AdDialog(Context context, String mUrl, OnAdClickListener onAdClickListener) {
super(context);
this.mContext = context;
this.mUrl = mUrl;
this.onAdClickListener = onAdClickListener;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.ad_layout);
getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
initView();
}
private SceenMannage smg;
private DisplayImageOptions options;
private RelativeLayout rl_ad;
private ImageView imv_ad;
private void initView() {
// TODO Auto-generated method stub
smg=new SceenMannage(mContext);
options=ImageLoaderService.setCommonViewConfig(mContext);
rl_ad=(RelativeLayout) findViewById(R.id.rl_ad);
imv_ad=(ImageView) findViewById(R.id.imv_ad);
// ImageLoaderService.displayImage(options, imv_ad,mUrl);
imv_ad.setBackgroundResource(R.drawable.ad_pic);
rl_ad.setOnClickListener(this);
smg.RelativeLayoutParams(rl_ad, 805, 405, 70, 0, 0, 0);
smg.RelativeLayoutParams(imv_ad, 800, 400, 0, 0, 0, 0);
}
public interface OnAdClickListener{
void onAdClick();
}
public void setOnAdClickListener(OnAdClickListener onAdClickListener) {
this.onAdClickListener = onAdClickListener;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.rl_ad:
if(onAdClickListener!=null)onAdClickListener.onAdClick();
break;
}
}
public static class Builder{
private Context context;
private String url;
private OnAdClickListener onAdClickListener;
public Builder(Context context) {
this.context = context;
}
public Builder setUrl(String url) {
this.url = url;
return this;
}
public Builder setOnAdClickListener(OnAdClickListener onAdClickListener) {
this.onAdClickListener = onAdClickListener;
return this;
}
public AdDialog create() {
return new AdDialog(context,url,onAdClickListener);
}
}
}
layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<!-- android:layout_width="1920px" -->
<!-- android:layout_height="1200px" -->
<RelativeLayout
android:id="@+id/rl_ad"
android:layout_width="1279px"
android:layout_height="647px"
android:layout_centerHorizontal="true"
android:layout_marginTop="288px"
android:background="@drawable/ad_selector"
>
<ImageView
android:id="@+id/imv_ad"
android:layout_width="1274px"
android:layout_height="642px"
android:scaleType="centerCrop"
android:layout_centerInParent="true"
/>
</RelativeLayout>
</RelativeLayout>