|
@@ -0,0 +1,382 @@
|
|
|
|
|
+package com.xzjmyk.pm.activity.ui.erp.activity.form;
|
|
|
|
|
+
|
|
|
|
|
+import android.content.Context;
|
|
|
|
|
+import android.os.Bundle;
|
|
|
|
|
+import android.support.v4.app.Fragment;
|
|
|
|
|
+import android.support.v4.app.FragmentManager;
|
|
|
|
|
+import android.support.v4.app.FragmentPagerAdapter;
|
|
|
|
|
+import android.support.v4.view.ViewPager;
|
|
|
|
|
+import android.view.LayoutInflater;
|
|
|
|
|
+import android.view.Menu;
|
|
|
|
|
+import android.view.MenuItem;
|
|
|
|
|
+import android.view.View;
|
|
|
|
|
+import android.view.ViewGroup;
|
|
|
|
|
+import android.widget.AdapterView;
|
|
|
|
|
+import android.widget.BaseAdapter;
|
|
|
|
|
+import android.widget.LinearLayout;
|
|
|
|
|
+import android.widget.TextView;
|
|
|
|
|
+
|
|
|
|
|
+import com.lidroid.xutils.ViewUtils;
|
|
|
|
|
+import com.lidroid.xutils.view.annotation.ViewInject;
|
|
|
|
|
+import com.xzjmyk.pm.activity.R;
|
|
|
|
|
+import com.xzjmyk.pm.activity.ui.base.BaseActivity;
|
|
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.fragment.CalendarDateFragmet;
|
|
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.view.NScrollerGridView;
|
|
|
|
|
+import com.xzjmyk.pm.activity.util.DateFormatUtil;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.Calendar;
|
|
|
|
|
+import java.util.Date;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+import java.util.Set;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * @desc:公共选择日历日期类
|
|
|
|
|
+ * @author:Arison on 2017/1/18
|
|
|
|
|
+ */
|
|
|
|
|
+public class SelectCalendarActivity extends BaseActivity implements View.OnClickListener{
|
|
|
|
|
+
|
|
|
|
|
+ @ViewInject(R.id.viewPager)
|
|
|
|
|
+ private ViewPager viewPager;
|
|
|
|
|
+ @ViewInject(R.id.ll_date_start)
|
|
|
|
|
+ private LinearLayout ll_date_start;
|
|
|
|
|
+ @ViewInject(R.id.ll_date_end)
|
|
|
|
|
+ private LinearLayout ll_date_end;
|
|
|
|
|
+ @ViewInject(R.id.ll_time_start)
|
|
|
|
|
+ private LinearLayout ll_time_start;
|
|
|
|
|
+ @ViewInject(R.id.ll_time_end)
|
|
|
|
|
+ private LinearLayout ll_time_end;
|
|
|
|
|
+ @ViewInject(R.id.ll_bottom)
|
|
|
|
|
+ private LinearLayout ll_bottom;
|
|
|
|
|
+
|
|
|
|
|
+ @ViewInject(R.id.tv_date_start)
|
|
|
|
|
+ private TextView tv_date_start;
|
|
|
|
|
+ @ViewInject(R.id.tv_date_end)
|
|
|
|
|
+ private TextView tv_date_end;
|
|
|
|
|
+
|
|
|
|
|
+ @ViewInject(R.id.v_date_start)
|
|
|
|
|
+ private TextView v_date_start;
|
|
|
|
|
+ @ViewInject(R.id.v_date_end)
|
|
|
|
|
+ private TextView v_date_end;
|
|
|
|
|
+
|
|
|
|
|
+ @ViewInject(R.id.v_time_start)
|
|
|
|
|
+ private TextView v_time_start;
|
|
|
|
|
+ @ViewInject(R.id.v_time_end)
|
|
|
|
|
+ private TextView v_time_end;
|
|
|
|
|
+
|
|
|
|
|
+ @ViewInject(R.id.gv_date_list)
|
|
|
|
|
+ private NScrollerGridView gv_date_list;
|
|
|
|
|
+
|
|
|
|
|
+ private List<String> mTimeData=new ArrayList<>();
|
|
|
|
|
+ private GridDataAdapter gAdapter;
|
|
|
|
|
+ private PagerAdapter pagerAdapter;//当前Viewpager适配器
|
|
|
|
|
+
|
|
|
|
|
+ private int MAX_PAGER = 30;
|
|
|
|
|
+ private Date[] date = new Date[MAX_PAGER];
|
|
|
|
|
+
|
|
|
|
|
+ private String currentSelectDate;
|
|
|
|
|
+
|
|
|
|
|
+ private boolean startDate=true;
|
|
|
|
|
+ private boolean startTime=true;
|
|
|
|
|
+
|
|
|
|
|
+ private int status;//0:在录入(无值)1:在录入(有值)
|
|
|
|
|
+ private boolean swich=true;//true 按时间段 false按时间
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
|
+ getMenuInflater().inflate(R.menu.menu_signin_set, menu);
|
|
|
|
|
+ return super.onCreateOptionsMenu(menu);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
|
+ switch (item.getItemId()) {
|
|
|
|
|
+ case R.id.oa_leave:
|
|
|
|
|
+ if (swich){
|
|
|
|
|
+ //按时间请假
|
|
|
|
|
+ getSupportActionBar().setTitle("按时间请假");
|
|
|
|
|
+ getSupportActionBar().setSubtitle("只适合普通请假");
|
|
|
|
|
+ ll_bottom.setVisibility(View.GONE);
|
|
|
|
|
+ swich=false;
|
|
|
|
|
+
|
|
|
|
|
+ tv_date_start.setText("开始时间");
|
|
|
|
|
+ tv_date_end.setText("结束时间");
|
|
|
|
|
+ }else{
|
|
|
|
|
+ //按时间段请假
|
|
|
|
|
+ getSupportActionBar().setTitle("按时段请假");
|
|
|
|
|
+ getSupportActionBar().setSubtitle("只适合特殊请假");
|
|
|
|
|
+ ll_bottom.setVisibility(View.VISIBLE);
|
|
|
|
|
+ swich=true;
|
|
|
|
|
+
|
|
|
|
|
+ tv_date_start.setText("开始日期");
|
|
|
|
|
+ tv_date_end.setText("结束日期");
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ return super.onOptionsItemSelected(item);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
|
|
+ setContentView(R.layout.activity_select_calendar);
|
|
|
|
|
+ initView();
|
|
|
|
|
+ initData();
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private void initView() {
|
|
|
|
|
+ ViewUtils.inject(this);
|
|
|
|
|
+ initListener();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void initListener() {
|
|
|
|
|
+ ll_date_start.setOnClickListener(this);
|
|
|
|
|
+ ll_date_end.setOnClickListener(this);
|
|
|
|
|
+
|
|
|
|
|
+ ll_time_start.setOnClickListener(this);
|
|
|
|
|
+ ll_time_end.setOnClickListener(this);
|
|
|
|
|
+
|
|
|
|
|
+ ll_date_end.setEnabled(false);//不可点击
|
|
|
|
|
+ ll_time_end.setEnabled(false);//不可点击
|
|
|
|
|
+
|
|
|
|
|
+ gv_date_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
|
|
+ GridDataAdapter.ViewModle modle = (GridDataAdapter.ViewModle) view.getTag();
|
|
|
|
|
+ ToastMessage(modle.tv_text.getText().toString());
|
|
|
|
|
+ if (swich) {
|
|
|
|
|
+ //时间段请假:
|
|
|
|
|
+ if (startTime){
|
|
|
|
|
+ v_time_start.setText(currentSelectDate);
|
|
|
|
|
+ swichTimeButton(false);
|
|
|
|
|
+ startTime=false;
|
|
|
|
|
+ }else{
|
|
|
|
|
+ v_time_end.setText(currentSelectDate);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ //按时间请假:
|
|
|
|
|
+ if (startDate){//按钮状态
|
|
|
|
|
+ //开始时间
|
|
|
|
|
+ v_date_start.setText(currentSelectDate +" "+ modle.tv_text.getText().toString());
|
|
|
|
|
+ //切换到开始时间
|
|
|
|
|
+ swichDateButton(false);//要不要清楚日历状态?
|
|
|
|
|
+ startDate=false;
|
|
|
|
|
+ }else{
|
|
|
|
|
+ //结束时间
|
|
|
|
|
+ v_date_end.setText(currentSelectDate +" "+ modle.tv_text.getText().toString());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void initData() {
|
|
|
|
|
+ initGridData();
|
|
|
|
|
+ initCalender();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void initCalender() {
|
|
|
|
|
+ setDate();
|
|
|
|
|
+ listenerMap = new HashMap<>();
|
|
|
|
|
+ LinearLayout.LayoutParams linearParams = (LinearLayout.LayoutParams) viewPager.getLayoutParams(); // 取控件mGrid当前的布局参数 搜索
|
|
|
|
|
+ linearParams.height = (getResources().getDisplayMetrics().heightPixels * 1 / 3);// 当控件的高强制设成50象素
|
|
|
|
|
+ viewPager.setLayoutParams(linearParams); // 使设置好的布局参数应用到控件myGrid
|
|
|
|
|
+ pagerAdapter = new PagerAdapter(getSupportFragmentManager());
|
|
|
|
|
+ viewPager.setAdapter(pagerAdapter);
|
|
|
|
|
+ viewPager.setCurrentItem(MAX_PAGER / 2);
|
|
|
|
|
+
|
|
|
|
|
+ swichDateButton(true);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @desc:初始化表格数据
|
|
|
|
|
+ * @author:Arison on 2017/1/18
|
|
|
|
|
+ */
|
|
|
|
|
+ private void initGridData() {
|
|
|
|
|
+ mTimeData.add("08:30");
|
|
|
|
|
+ mTimeData.add("09:00");
|
|
|
|
|
+ mTimeData.add("09:30");
|
|
|
|
|
+ mTimeData.add("10:00");
|
|
|
|
|
+ mTimeData.add("10:30");
|
|
|
|
|
+ mTimeData.add("11:00");
|
|
|
|
|
+ mTimeData.add("11:30");
|
|
|
|
|
+ mTimeData.add("12:30");
|
|
|
|
|
+ mTimeData.add("13:00");
|
|
|
|
|
+ mTimeData.add("13:30");
|
|
|
|
|
+ mTimeData.add("14:00");
|
|
|
|
|
+ mTimeData.add("14:30");
|
|
|
|
|
+ mTimeData.add("15:00");
|
|
|
|
|
+ mTimeData.add("15:30");
|
|
|
|
|
+ mTimeData.add("16:00");
|
|
|
|
|
+ mTimeData.add("16:30");
|
|
|
|
|
+ mTimeData.add("17:00");
|
|
|
|
|
+ mTimeData.add("17:30");
|
|
|
|
|
+ mTimeData.add("18:00");
|
|
|
|
|
+ mTimeData.add("18:30");
|
|
|
|
|
+ gAdapter=new GridDataAdapter(mContext,mTimeData);
|
|
|
|
|
+ gv_date_list.setAdapter(gAdapter);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private void setDate() {
|
|
|
|
|
+ //当前天在 MAX_PAGER/2 位置
|
|
|
|
|
+ Calendar c = Calendar.getInstance();
|
|
|
|
|
+ Date date = new Date();
|
|
|
|
|
+ for (int i = 0; i < MAX_PAGER; i++) {
|
|
|
|
|
+ c.setTime(date);
|
|
|
|
|
+ c.add(Calendar.MONTH, i - (MAX_PAGER / 2));
|
|
|
|
|
+ c.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
|
|
+ this.date[i] = c.getTime();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClick(View v) {
|
|
|
|
|
+ switch (v.getId()){
|
|
|
|
|
+ case R.id.ll_date_start:
|
|
|
|
|
+ startDate=true;
|
|
|
|
|
+ swichDateButton(startDate);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case R.id.ll_date_end:
|
|
|
|
|
+ startDate=false;
|
|
|
|
|
+ swichDateButton(startDate);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case R.id.ll_time_start:
|
|
|
|
|
+ startTime=true;
|
|
|
|
|
+ swichTimeButton(startTime);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case R.id.ll_time_end:
|
|
|
|
|
+ startTime=false;
|
|
|
|
|
+ swichTimeButton(startTime);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void swichDateButton(boolean swich) {
|
|
|
|
|
+ ll_date_start.setSelected(swich);
|
|
|
|
|
+ ll_date_end.setSelected(!swich);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void swichTimeButton(boolean swich) {
|
|
|
|
|
+ ll_time_start.setSelected(swich);
|
|
|
|
|
+ ll_time_end.setSelected(!swich);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @desc:表格适配器
|
|
|
|
|
+ * @author:Arison on 2017/1/18
|
|
|
|
|
+ */
|
|
|
|
|
+ private class GridDataAdapter extends BaseAdapter{
|
|
|
|
|
+
|
|
|
|
|
+ private Context ct;
|
|
|
|
|
+ private List<String> mData=new ArrayList<>();
|
|
|
|
|
+ private LayoutInflater inflater;
|
|
|
|
|
+
|
|
|
|
|
+ GridDataAdapter(Context ct,List<String> data){
|
|
|
|
|
+ this.ct=ct;
|
|
|
|
|
+ this.mData=data;
|
|
|
|
|
+ this.inflater= LayoutInflater.from(ct);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public int getCount() {
|
|
|
|
|
+ return mData.size();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Object getItem(int position) {
|
|
|
|
|
+ return position;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public long getItemId(int position) {
|
|
|
|
|
+ return position;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public View getView(int position, View convertView, ViewGroup parent) {
|
|
|
|
|
+ ViewModle modle=null;
|
|
|
|
|
+
|
|
|
|
|
+ if (convertView==null){
|
|
|
|
|
+ convertView=inflater.inflate(R.layout.item_simple_text,parent,false);
|
|
|
|
|
+ modle= new ViewModle();
|
|
|
|
|
+ modle.tv_text= (TextView) convertView.findViewById(R.id.tv_text);
|
|
|
|
|
+ convertView.setTag(modle);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ modle= (ViewModle) convertView.getTag();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ modle.tv_text.setText(mData.get(position));
|
|
|
|
|
+ return convertView;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ class ViewModle {
|
|
|
|
|
+ TextView tv_text;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ class PagerAdapter extends FragmentPagerAdapter {
|
|
|
|
|
+
|
|
|
|
|
+ public PagerAdapter(FragmentManager fm) {
|
|
|
|
|
+ super(fm);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Fragment getItem(int position) {
|
|
|
|
|
+ return CalendarDateFragmet.getInstance(date[position]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public int getCount() {
|
|
|
|
|
+ return MAX_PAGER;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Map<String, OnTaskChangeListener> listenerMap;
|
|
|
|
|
+
|
|
|
|
|
+ public void setListener(String key, OnTaskChangeListener listener) {
|
|
|
|
|
+ listenerMap.put(key, listener);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public interface OnTaskChangeListener {
|
|
|
|
|
+ void onChange(Set<Integer> in);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /*当点击了指定日期(点击日期、滑动时候触发)*/
|
|
|
|
|
+ public void setClickDay(Date date) {
|
|
|
|
|
+ currentSelectDate=DateFormatUtil.getStrDate4Date(date,"yyyy-MM-dd");
|
|
|
|
|
+ if (swich){
|
|
|
|
|
+ //按时间段
|
|
|
|
|
+ if (startTime){
|
|
|
|
|
+ v_time_start.setText(currentSelectDate);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ v_time_end.setText(currentSelectDate);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }else{
|
|
|
|
|
+ //按时间
|
|
|
|
|
+ // v_date_start.setText(DateFormatUtil.getStrDate4Date(date,"yyyy-MM-dd"));
|
|
|
|
|
+ //按时间请假:
|
|
|
|
|
+ if (startDate){//按钮状态
|
|
|
|
|
+ //开始时间
|
|
|
|
|
+ v_date_start.setText(currentSelectDate);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ //结束时间
|
|
|
|
|
+ v_date_end.setText(currentSelectDate);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ ToastMessage(currentSelectDate);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|