Browse Source

no message

master
lh 7 years ago
parent
commit
0a923effb5
5 changed files with 266 additions and 1 deletions
  1. +127
    -0
      app/src/main/java/com/qhclh/ytzh/ui/Chose2timePopuWindow.java
  2. +33
    -0
      app/src/main/java/com/qhclh/ytzh/work/Hatchery/ChoseTimeEvent.java
  3. +28
    -1
      app/src/main/java/com/qhclh/ytzh/work/Hatchery/HatcheryReportActivity.java
  4. +1
    -0
      app/src/main/res/layout/act_hatchery_report.xml
  5. +77
    -0
      app/src/main/res/layout/pop_chosetime.xml

+ 127
- 0
app/src/main/java/com/qhclh/ytzh/ui/Chose2timePopuWindow.java View File

@ -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();
}
}
}

+ 33
- 0
app/src/main/java/com/qhclh/ytzh/work/Hatchery/ChoseTimeEvent.java View File

@ -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;
}
}

+ 28
- 1
app/src/main/java/com/qhclh/ytzh/work/Hatchery/HatcheryReportActivity.java View File

@ -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());
}
}

+ 1
- 0
app/src/main/res/layout/act_hatchery_report.xml View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="@+id/ll_main"
android:layout_height="match_parent"
android:orientation="vertical">


+ 77
- 0
app/src/main/res/layout/pop_chosetime.xml View File

@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00000000"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical">
<LinearLayout
android:id="@+id/ll_pop_start"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="@dimen/dp_10"
android:paddingTop="@dimen/dp_10">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="起始:"
android:textSize="@dimen/text_size_16" />
<TextView
android:id="@+id/tv_start"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请选择起始时间"
android:textSize="@dimen/text_size_16" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_pop_end"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="@dimen/dp_10"
android:paddingTop="@dimen/dp_10">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="终止:"
android:textSize="@dimen/text_size_16" />
<TextView
android:id="@+id/tv_end"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请选择终止时间"
android:textSize="@dimen/text_size_16" />
</LinearLayout>
<Button
android:id="@+id/pop_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/tijiao_bgshap"
android:text="确定"
android:textColor="@color/white"
android:textSize="@dimen/text_size_16" />
</LinearLayout>
</LinearLayout>

Loading…
Cancel
Save