/**
* 月份popwindow需要变量
*/
private static int days = 0; // 月的天数
private static int year = 2017;
private static int month = 0;
private static String[] dates;
private Map<String, String> dateMap;
private List<String> dateList;
private PopupWindow popupWindow;
private ListView dateListView;
private String tradeStartDate;
private String tradeEndDate;
private String startRecord = "0";
private String tradeTotal;
private void inidData() {
int thisYear = CalendarUtil.getYear(0);
year = thisYear;
dates = new String[12];
int j = 0;
for (int i = 0; i > -12; i--) {
int thisMonth = CalendarUtil.getMonth(0);
month = CalendarUtil.getMonth(i);
if (12 != thisMonth && 12 == month) {
year = CalendarUtil.getYear(-1);
}
String startDate = "";
if (10 > month) {
startDate = year + "-" + "0" + month;
} else {
startDate = year + "-" + month;
}
String endDate = year + "-" + month;
dates[j] = startDate;
j = j + 1;
int days = CalendarUtil.getPreviousMonthEndDay(i);
endDate = startDate + "-" + days;
dateMap.put(startDate, endDate);
dateList.add(startDate);
}
}
/**
* 初始化popWindow
*/
private void initPopWindow() {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View popView = inflater.inflate(R.layout.account_information_pop, null);
popupWindow = new PopupWindow(popView, ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
popupWindow.setFocusable(false);
popupWindow.setOutsideTouchable(false);
popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.alpha = 1f;
getWindow().setAttributes(lp);
}
});
// popupWindow.setAnimationStyle(R.style.PopupAnimation);
dateListView = (ListView) popView.findViewById(R.id.date_list_id);
ArrayAdapter<String> list = new ArrayAdapter<String>(this,
R.layout.list_item_spinner, dateList);
dateListView.setAdapter(list);
dateListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int position, long arg3) {
// TODO Auto-generated method stub
Log.e(TAG, "dateListView: onItemClick. position == " + position);
tradeTotal = "0.00";
dismissPop();
String date = (String) dateListView.getItemAtPosition(position);
Log.e(TAG, "dateListView: onItemClick. date 1 == " + date);
date = dateList.get(position);
// String dateString = arg0.getSelectedItem().toString();
// Log.e(TAG,
// "dateListView: onItemClick dateString :"+dateString);
mMonthDaysText.setText(date);
queryUserBonusPutForwardHandler(date);
tradeStartDate = date + "-01";
tradeEndDate = (String) dateMap.get(date).toString();
startRecord = "0";
}
});
}
/**
* 显示popWindow
*/
private void showPop() {
if (isFinishing()) {
return;
}
if (popupWindow == null) {
initPopWindow();
}
if (!popupWindow.isShowing()) {
popupWindow.showAsDropDown(mLlSelectDate,
DensityUtil.dip2px(this, 20), 0);
// 设置背景颜色变暗
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.alpha = 0.4f;
getWindow().setAttributes(lp);
}
popupWindow.update();
}
private boolean dismissPop() {
if (popupWindow != null && popupWindow.isShowing()) {
popupWindow.dismiss();
return true;
}
return false;
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (dismissPop()) {
return true;
}
return super.dispatchTouchEvent(ev);
}
* 月份popwindow需要变量
*/
private static int days = 0; // 月的天数
private static int year = 2017;
private static int month = 0;
private static String[] dates;
private Map<String, String> dateMap;
private List<String> dateList;
private PopupWindow popupWindow;
private ListView dateListView;
private String tradeStartDate;
private String tradeEndDate;
private String startRecord = "0";
private String tradeTotal;
private void inidData() {
int thisYear = CalendarUtil.getYear(0);
year = thisYear;
dates = new String[12];
int j = 0;
for (int i = 0; i > -12; i--) {
int thisMonth = CalendarUtil.getMonth(0);
month = CalendarUtil.getMonth(i);
if (12 != thisMonth && 12 == month) {
year = CalendarUtil.getYear(-1);
}
String startDate = "";
if (10 > month) {
startDate = year + "-" + "0" + month;
} else {
startDate = year + "-" + month;
}
String endDate = year + "-" + month;
dates[j] = startDate;
j = j + 1;
int days = CalendarUtil.getPreviousMonthEndDay(i);
endDate = startDate + "-" + days;
dateMap.put(startDate, endDate);
dateList.add(startDate);
}
}
/**
* 初始化popWindow
*/
private void initPopWindow() {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View popView = inflater.inflate(R.layout.account_information_pop, null);
popupWindow = new PopupWindow(popView, ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
popupWindow.setFocusable(false);
popupWindow.setOutsideTouchable(false);
popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.alpha = 1f;
getWindow().setAttributes(lp);
}
});
// popupWindow.setAnimationStyle(R.style.PopupAnimation);
dateListView = (ListView) popView.findViewById(R.id.date_list_id);
ArrayAdapter<String> list = new ArrayAdapter<String>(this,
R.layout.list_item_spinner, dateList);
dateListView.setAdapter(list);
dateListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int position, long arg3) {
// TODO Auto-generated method stub
Log.e(TAG, "dateListView: onItemClick. position == " + position);
tradeTotal = "0.00";
dismissPop();
String date = (String) dateListView.getItemAtPosition(position);
Log.e(TAG, "dateListView: onItemClick. date 1 == " + date);
date = dateList.get(position);
// String dateString = arg0.getSelectedItem().toString();
// Log.e(TAG,
// "dateListView: onItemClick dateString :"+dateString);
mMonthDaysText.setText(date);
queryUserBonusPutForwardHandler(date);
tradeStartDate = date + "-01";
tradeEndDate = (String) dateMap.get(date).toString();
startRecord = "0";
}
});
}
/**
* 显示popWindow
*/
private void showPop() {
if (isFinishing()) {
return;
}
if (popupWindow == null) {
initPopWindow();
}
if (!popupWindow.isShowing()) {
popupWindow.showAsDropDown(mLlSelectDate,
DensityUtil.dip2px(this, 20), 0);
// 设置背景颜色变暗
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.alpha = 0.4f;
getWindow().setAttributes(lp);
}
popupWindow.update();
}
private boolean dismissPop() {
if (popupWindow != null && popupWindow.isShowing()) {
popupWindow.dismiss();
return true;
}
return false;
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (dismissPop()) {
return true;
}
return super.dispatchTouchEvent(ev);
}