
package com.lianxin.pubqq.setup;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
//import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
//import android.widget.LinearLayout;
import android.widget.TextView;

import com.lianxin.pubqq.R;
import com.lianxin.panqq.common.bean.InformMessage;
import com.lianxin.panqq.common.bean.UserInfo;
import com.lianxin.panqq.utils.ImagesUtils;
import com.lianxin.panqq.utils.TimeUtil;

public class SigninDialog extends AlertDialog implements OnClickListener {
	private ImageView img_photo;  //用户头像
	private TextView txt_name;  //发布人名称	
	private TextView txt_time; //发布时间
	private TextView txt_title; //通知标题
	private TextView txt_content; //通知内容
	private TextView txt_file; //附件
	
    private OnSetListener mCallBack;	
    private InformMessage uinfo; 
//	private UserInfo sinfo;

    public interface OnSetListener {

        //void onSelect( int minage);
        void onSelect( UserInfo uinfo);        
    }
 
    public SigninDialog(Context context, InformMessage ainfo, int type,OnSetListener callBack) {
       // this(context, VoteNoticeDialog.THEME_HOLO_LIGHT);
        this(context, type);       
        uinfo = ainfo; 
       
        mCallBack = callBack;   
		initData();
            
    }     
    
    public SigninDialog(Context context, int type) {
       // super(context, theme);
        super(context, SigninDialog.THEME_HOLO_LIGHT);        
        Context themeContext = getContext();

        setButton(BUTTON_POSITIVE, "到  岗", this);
        setButton(BUTTON_NEGATIVE, "有  事", this);
 
    /*    super.setNeutralButton("查看详情", new DialogInterface.OnClickListener() { 
            
            @Override 
            public void onClick(DialogInterface dialog, int which) { 
                // TODO Auto-generated method stub  
            } 
        })   */ 
        setTitle("通知你签到");       
        setIcon(0);        
        LayoutInflater inflater = (LayoutInflater) themeContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.alert_signin, null);        
        setView(view);   
   	
		initControl(view);
	        
    }
 
	protected void initControl(View view) {		
		img_photo = (ImageView)view.findViewById(R.id.iv_image);
		txt_name = (TextView)view.findViewById(R.id.tv_name);
		txt_time = (TextView)view.findViewById(R.id.tv_time);
		txt_title = (TextView)view.findViewById(R.id.tv_title);
		txt_content = (TextView)view.findViewById(R.id.tv_content);
		txt_file = (TextView)view.findViewById(R.id.tv_file);		
	}   
 
	protected void initData() {
		String strname = uinfo.getFrom();	
		txt_name.setText(strname);
		txt_time.setText(TimeUtil.getMsgTime(uinfo.getTime()));		
		txt_title.setText("通知："+uinfo.getTitle());	
		txt_content.setText(uinfo.getContent());
        int image = uinfo.imageid;
	//	txt_userid.setText("10010");  
        if(image<0) image = -image;		
        if(image>80) image = image%80;
        img_photo.setImageResource(ImagesUtils.images[image]); 
      
	}	

    public void onClick(DialogInterface dialog, int which) {

        // 如果是“取 消”按钮，则返回，如果是“确 定”按钮，则往下执行
        if (which == BUTTON_POSITIVE)
            tryNotifyDateSet(); 
    }

    private void tryNotifyDateSet() {
        if (mCallBack != null) {
    //    	myPicker.clearFocus();
     //   	uinfo.type = tempPower; 
    //		String nickname = txt_nickname.getText().toString().trim();	       	
     //   	uinfo.nickname = nickname;   
     //       int index = Integer.parseInt(txt_index.getText().toString().trim());
    //       	uinfo.index = index;             
           // mCallBack.onSelect(1);
           	UserInfo sinfo = new UserInfo();;       	
            mCallBack.onSelect(sinfo);         	           
        }
    } 

}