diff --git a/app/src/main/java/com/qhclh/ytzh/ui/Chose2timePopuWindow.java b/app/src/main/java/com/qhclh/ytzh/ui/Chose2timePopuWindow.java new file mode 100644 index 0000000..3990a38 --- /dev/null +++ b/app/src/main/java/com/qhclh/ytzh/ui/Chose2timePopuWindow.java @@ -0,0 +1,127 @@ +package com.qhclh.ytzh.ui; + +import android.app.Activity; +import android.content.Context; +import android.graphics.drawable.ColorDrawable; +import android.view.Gravity; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.Button; +import android.widget.LinearLayout; +import android.widget.PopupWindow; +import android.widget.TextView; + +import com.qhclh.ytzh.R; +import com.qhclh.ytzh.utils.DateUtils; +import com.qhclh.ytzh.utils.widget.DateTimePickDialog; +import com.qhclh.ytzh.work.Hatchery.ChoseTimeEvent; + +import org.greenrobot.eventbus.EventBus; + +import java.util.Date; + +import static com.qhclh.ytzh.utils.DateUtils.PATTERN_TRANSVERSE; + +/** + * Created by 青花瓷 on 2018/4/3. + */ + +public class Chose2timePopuWindow extends PopupWindow { + private View conentView; + private Activity context; + public Chose2timePopuWindow(final Activity context){ + super(context); + this.context = context; + this.initPopupWindow(); + } + + private Date startDate = null; + private Date endDate = null; + private void initPopupWindow() { + //使用view来引入布局 + LayoutInflater inflater = (LayoutInflater) context + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + conentView = inflater.inflate(R.layout.pop_chosetime, null); + //获取popupwindow的高度与宽度 + int h = context.getWindowManager().getDefaultDisplay().getHeight(); + int w = context.getWindowManager().getDefaultDisplay().getWidth(); + // 设置SelectPicPopupWindow的View + this.setContentView(conentView); + // 设置SelectPicPopupWindow弹出窗体的宽 + this.setWidth(w / 2 + 50); + // 设置SelectPicPopupWindow弹出窗体的高 + this.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT); + // 设置SelectPicPopupWindow弹出窗体可点击 + this.setFocusable(true); + this.setOutsideTouchable(true); + // 刷新状态 + this.update(); + // 实例化一个ColorDrawable颜色为半透明 + ColorDrawable dw = new ColorDrawable(0000000000); + // 点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener ,设置其他控件变化等操作 + this.setBackgroundDrawable(dw); + + LinearLayout ll_pop_start = conentView.findViewById(R.id.ll_pop_start); + LinearLayout ll_pop_end = conentView.findViewById(R.id.ll_pop_end); + Button pop_btn = conentView.findViewById(R.id.pop_btn); + + final TextView tv_start = conentView.findViewById(R.id.tv_start); + final TextView tv_end = conentView.findViewById(R.id.tv_end); + + ll_pop_start.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + DateTimePickDialog mDateTimePickDialog = new DateTimePickDialog(context, new DateTimePickDialog.DateChangedCallBack() { + @Override + public void onDateChanged(Date date) { + String start = DateUtils.format(date, PATTERN_TRANSVERSE); + tv_start.setText(start); + startDate = date; + } + }); + mDateTimePickDialog.show(); + } + }); + + ll_pop_end.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + DateTimePickDialog mDateTimePickDialog = new DateTimePickDialog(context, new DateTimePickDialog.DateChangedCallBack() { + @Override + public void onDateChanged(Date date) { + String end = DateUtils.format(date, PATTERN_TRANSVERSE); + tv_end.setText(end); + endDate = date; + } + }); + mDateTimePickDialog.show(); + } + }); + + pop_btn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + EventBus.getDefault().post(new ChoseTimeEvent(startDate,endDate)); + dismissPopupWindow(); + } + }); + + } + + + + public void showPopupWindow(View parent) { + if (!this.isShowing()) { + this.showAtLocation(context.getWindow().getDecorView(), Gravity.CENTER, 0, 0); + } else { + this.dismiss(); + } + } + + private void dismissPopupWindow(){ + if (isShowing()){ + this.dismiss(); + } + } + +} diff --git a/app/src/main/java/com/qhclh/ytzh/work/Hatchery/ChoseTimeEvent.java b/app/src/main/java/com/qhclh/ytzh/work/Hatchery/ChoseTimeEvent.java new file mode 100644 index 0000000..5cce2f3 --- /dev/null +++ b/app/src/main/java/com/qhclh/ytzh/work/Hatchery/ChoseTimeEvent.java @@ -0,0 +1,33 @@ +package com.qhclh.ytzh.work.Hatchery; + +import java.util.Date; + +/** + * Created by 青花瓷 on 2018/4/3. + */ + +public class ChoseTimeEvent { + private Date startDate; + private Date endDate; + + public ChoseTimeEvent(Date startDate, Date endDate) { + this.startDate = startDate; + this.endDate = endDate; + } + + public Date getStartDate() { + return startDate; + } + + public void setStartDate(Date startDate) { + this.startDate = startDate; + } + + public Date getEndDate() { + return endDate; + } + + public void setEndDate(Date endDate) { + this.endDate = endDate; + } +} diff --git a/app/src/main/java/com/qhclh/ytzh/work/Hatchery/HatcheryReportActivity.java b/app/src/main/java/com/qhclh/ytzh/work/Hatchery/HatcheryReportActivity.java index f905ffc..54eb62e 100644 --- a/app/src/main/java/com/qhclh/ytzh/work/Hatchery/HatcheryReportActivity.java +++ b/app/src/main/java/com/qhclh/ytzh/work/Hatchery/HatcheryReportActivity.java @@ -6,13 +6,19 @@ import android.view.MenuItem; import android.view.View; import android.widget.AbsListView; import android.widget.HorizontalScrollView; +import android.widget.LinearLayout; import android.widget.ListView; import com.qhclh.ytzh.R; import com.qhclh.ytzh.base.BaseActivity; +import com.qhclh.ytzh.ui.Chose2timePopuWindow; import com.qhclh.ytzh.ui.LinkedHorizontalScrollView; import com.qhclh.ytzh.ui.NoScrollHorizontalScrollView; +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + import java.util.ArrayList; import java.util.List; @@ -33,6 +39,8 @@ public class HatcheryReportActivity extends BaseActivity { ListView lv_buildhousename;//底部左侧的ListView @BindView(R.id.lv_report_info_right) ListView lv_report_info;//底部右侧的ListView + @BindView(R.id.ll_main) + LinearLayout ll_main; private boolean isLeftListEnabled = false; private boolean isRightListEnabled = false; @@ -49,6 +57,9 @@ public class HatcheryReportActivity extends BaseActivity { @Override protected void initView() { + if (!EventBus.getDefault().isRegistered(this)) { + EventBus.getDefault().register(this); + } initToolbar(mToolbar, "报表指数", new View.OnClickListener() { @Override public void onClick(View view) { @@ -87,11 +98,13 @@ public class HatcheryReportActivity extends BaseActivity { getMenuInflater().inflate(R.menu.chosetime, menu); return true; } + @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.chose_time: - + Chose2timePopuWindow popuWindow = new Chose2timePopuWindow(HatcheryReportActivity.this); + popuWindow.showPopupWindow(ll_main); break; } @@ -161,4 +174,18 @@ public class HatcheryReportActivity extends BaseActivity { } }); } + + @Override + protected void onDestroy() { + super.onDestroy(); + if (EventBus.getDefault().isRegistered(this)) { + EventBus.getDefault().unregister(this); + } + } + + @Subscribe(threadMode = ThreadMode.MAIN, sticky = false) + public void onEvent(ChoseTimeEvent event) { + System.out.println("aaa+++starttiem+++"+event.getStartDate()); + System.out.println("aaa+++endtime+++"+event.getEndDate()); + } } diff --git a/app/src/main/res/layout/act_hatchery_report.xml b/app/src/main/res/layout/act_hatchery_report.xml index 23ba919..f7d66d0 100644 --- a/app/src/main/res/layout/act_hatchery_report.xml +++ b/app/src/main/res/layout/act_hatchery_report.xml @@ -1,6 +1,7 @@ diff --git a/app/src/main/res/layout/pop_chosetime.xml b/app/src/main/res/layout/pop_chosetime.xml new file mode 100644 index 0000000..1f260e1 --- /dev/null +++ b/app/src/main/res/layout/pop_chosetime.xml @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + +