package com.geo.smallcredit.popwindow;
import com.geo.smallcredit.R;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.PopupWindow;
import android.widget.TextView;
public class SelectPicPopupWindow extends PopupWindow {
private TextView kefu, workTime;
private Button btn_pick_tel, btn_cancel;
private View mMenuView;
public SelectPicPopupWindow(Activity context, OnClickListener itemsOnClick) {
super(context);
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mMenuView = inflater.inflate(R.layout.alert_dialog, null);
kefu = (TextView) mMenuView
.findViewById(R.id.alert_dialog_btn_take_kefu);
workTime = (TextView) mMenuView
.findViewById(R.id.alert_dialog_worktime);
btn_pick_tel = (Button) mMenuView
.findViewById(R.id.alert_dialog_btn_pick_tel);
btn_cancel = (Button) mMenuView
.findViewById(R.id.alert_dialog_btn_cancel);
// ȡ����ť
btn_cancel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// ���ٵ�����
dismiss();
}
});
// ���ð�ť����
btn_pick_tel.setOnClickListener(itemsOnClick);
// ����SelectPicPopupWindow��View
this.setContentView(mMenuView);
// ����SelectPicPopupWindow��������Ŀ�
this.setWidth(LayoutParams.FILL_PARENT);
// ����SelectPicPopupWindow��������ĸ�
this.setHeight(LayoutParams.WRAP_CONTENT);
// ����SelectPicPopupWindow��������ɵ��
this.setFocusable(true);
// ����SelectPicPopupWindow�������嶯��Ч��
this.setAnimationStyle(R.style.AnimBottom);
// ʵ����һ��ColorDrawable��ɫΪ����
ColorDrawable dw = new ColorDrawable(0xb0000000);
// ����SelectPicPopupWindow��������ı���
this.setBackgroundDrawable(dw);
// mMenuView���OnTouchListener�����жϻ�ȡ����λ�������ѡ������������ٵ�����
mMenuView.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
int height = mMenuView.findViewById(
R.id.alert_dialog_pop_layout).getTop();
int y = (int) event.getY();
if (event.getAction() == MotionEvent.ACTION_UP) {
if (y < height) {
dismiss();
}
}
return true;
}
});
}
}