From 4f367da84516723e5633bca95057133f280bc0cb Mon Sep 17 00:00:00 2001 From: renyu Date: Tue, 2 Jan 2018 10:42:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=B6=E9=97=B4=E9=80=89=E6=8B=A9=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E6=89=A9=E5=B1=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../actionsheet/ActionSheetFragment.java | 108 +++++++++++------- .../src/main/res/layout/view_actionsheet.xml | 28 +++++ .../activity/ActionSheetActivity.java | 65 ++++++----- 3 files changed, 126 insertions(+), 75 deletions(-) diff --git a/CommonLibrary/src/main/java/com/renyu/commonlibrary/views/actionsheet/ActionSheetFragment.java b/CommonLibrary/src/main/java/com/renyu/commonlibrary/views/actionsheet/ActionSheetFragment.java index 6d6edbb..2599ea2 100644 --- a/CommonLibrary/src/main/java/com/renyu/commonlibrary/views/actionsheet/ActionSheetFragment.java +++ b/CommonLibrary/src/main/java/com/renyu/commonlibrary/views/actionsheet/ActionSheetFragment.java @@ -650,14 +650,16 @@ else if (getArguments().getInt("type")==6) { days.add(""+i); } - LinearLayout pop_wheel_yearlayout= (LinearLayout) view.findViewById(R.id.pop_wheel_yearlayout); - pop_wheel_yearlayout.setVisibility(View.VISIBLE); + LinearLayout pop_wheel_datarangelayout= (LinearLayout) view.findViewById(R.id.pop_wheel_datarangelayout); + pop_wheel_datarangelayout.setVisibility(View.VISIBLE); - LoopView pop_wheel_yearlayout_year= (LoopView) view.findViewById(R.id.pop_wheel_yearlayout_year); - LoopView pop_wheel_yearlayout_month= (LoopView) view.findViewById(R.id.pop_wheel_yearlayout_month); - LoopView pop_wheel_yearlayout_day= (LoopView) view.findViewById(R.id.pop_wheel_yearlayout_day); + LoopView pop_wheel_datarangelayout_year= (LoopView) view.findViewById(R.id.pop_wheel_datarangelayout_year); + LoopView pop_wheel_datarangelayout_month= (LoopView) view.findViewById(R.id.pop_wheel_datarangelayout_month); + LoopView pop_wheel_datarangelayout_day= (LoopView) view.findViewById(R.id.pop_wheel_datarangelayout_day); + LoopView pop_wheel_datarangelayout_hour= (LoopView) view.findViewById(R.id.pop_wheel_datarangelayout_hour); + LoopView pop_wheel_datarangelayout_minute= (LoopView) view.findViewById(R.id.pop_wheel_datarangelayout_minute); - pop_wheel_yearlayout_year.setListener(index -> { + pop_wheel_datarangelayout_year.setListener(index -> { months.clear(); days.clear(); Calendar calendar=Calendar.getInstance(); @@ -665,13 +667,13 @@ else if (getArguments().getInt("type")==6) { for (int i=1;i<=12;i++) { months.add(""+i); } - pop_wheel_yearlayout_month.setItems(months); + pop_wheel_datarangelayout_month.setItems(months); //当前月份最大天数 Calendar cl=Calendar.getInstance(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); try { - cl.setTime(format.parse(years.get(index)+"-"+months.get(pop_wheel_yearlayout_month.getSelectedItem())+"-01")); + cl.setTime(format.parse(years.get(index)+"-"+months.get(pop_wheel_datarangelayout_month.getSelectedItem())+"-01")); } catch (ParseException e) { e.printStackTrace(); } @@ -680,35 +682,35 @@ else if (getArguments().getInt("type")==6) { days.add(""+i); } - if (pop_wheel_yearlayout_day.getSelectedItem()+1>dayCount) { - pop_wheel_yearlayout_day.setInitPosition(0); - pop_wheel_yearlayout_day.setTotalScrollYPosition(dayCount-1); + if (pop_wheel_datarangelayout_day.getSelectedItem()+1>dayCount) { + pop_wheel_datarangelayout_day.setInitPosition(0); + pop_wheel_datarangelayout_day.setTotalScrollYPosition(dayCount-1); } else { - pop_wheel_yearlayout_day.setInitPosition(0); - pop_wheel_yearlayout_day.setTotalScrollYPosition(pop_wheel_yearlayout_day.getSelectedItem()); + pop_wheel_datarangelayout_day.setInitPosition(0); + pop_wheel_datarangelayout_day.setTotalScrollYPosition(pop_wheel_datarangelayout_day.getSelectedItem()); } - pop_wheel_yearlayout_day.setItems(days); + pop_wheel_datarangelayout_day.setItems(days); }); - pop_wheel_yearlayout_year.setNotLoop(); - pop_wheel_yearlayout_year.setViewPadding(SizeUtils.dp2px(20), SizeUtils.dp2px(15), SizeUtils.dp2px(20), SizeUtils.dp2px(15)); - pop_wheel_yearlayout_year.setItems(years); - pop_wheel_yearlayout_year.setTextSize(18); + pop_wheel_datarangelayout_year.setNotLoop(); + pop_wheel_datarangelayout_year.setViewPadding(SizeUtils.dp2px(15), SizeUtils.dp2px(15), SizeUtils.dp2px(15), SizeUtils.dp2px(15)); + pop_wheel_datarangelayout_year.setItems(years); + pop_wheel_datarangelayout_year.setTextSize(18); for (int i = 0; i < years.size(); i++) { if (calendar_today.get(Calendar.YEAR) == Integer.parseInt(years.get(i))) { - pop_wheel_yearlayout_year.setInitPosition(i); + pop_wheel_datarangelayout_year.setInitPosition(i); break; } } - pop_wheel_yearlayout_month.setNotLoop(); - pop_wheel_yearlayout_month.setListener(index -> { + pop_wheel_datarangelayout_month.setNotLoop(); + pop_wheel_datarangelayout_month.setListener(index -> { days.clear(); //当前月份最大天数 Calendar cl=Calendar.getInstance(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); try { - cl.setTime(format.parse(years.get(pop_wheel_yearlayout_year.getSelectedItem())+"-"+months.get(index)+"-01")); + cl.setTime(format.parse(years.get(pop_wheel_datarangelayout_year.getSelectedItem())+"-"+months.get(index)+"-01")); } catch (ParseException e) { e.printStackTrace(); } @@ -717,51 +719,71 @@ else if (getArguments().getInt("type")==6) { days.add(""+i); } - if (pop_wheel_yearlayout_day.getSelectedItem()+1>dayCount) { - pop_wheel_yearlayout_day.setInitPosition(0); - pop_wheel_yearlayout_day.setTotalScrollYPosition(dayCount-1); + if (pop_wheel_datarangelayout_day.getSelectedItem()+1>dayCount) { + pop_wheel_datarangelayout_day.setInitPosition(0); + pop_wheel_datarangelayout_day.setTotalScrollYPosition(dayCount-1); } else { - pop_wheel_yearlayout_day.setInitPosition(0); - pop_wheel_yearlayout_day.setTotalScrollYPosition(pop_wheel_yearlayout_day.getSelectedItem()); + pop_wheel_datarangelayout_day.setInitPosition(0); + pop_wheel_datarangelayout_day.setTotalScrollYPosition(pop_wheel_datarangelayout_day.getSelectedItem()); } - pop_wheel_yearlayout_day.setItems(days); + pop_wheel_datarangelayout_day.setItems(days); }); - pop_wheel_yearlayout_month.setViewPadding(SizeUtils.dp2px(30), SizeUtils.dp2px(15), SizeUtils.dp2px(30), SizeUtils.dp2px(15)); - pop_wheel_yearlayout_month.setItems(months); - pop_wheel_yearlayout_month.setTextSize(18); + pop_wheel_datarangelayout_month.setViewPadding(SizeUtils.dp2px(15), SizeUtils.dp2px(15), SizeUtils.dp2px(15), SizeUtils.dp2px(15)); + pop_wheel_datarangelayout_month.setItems(months); + pop_wheel_datarangelayout_month.setTextSize(18); for (int i = 0; i < months.size(); i++) { if (calendar_today.get(Calendar.MONTH)+1 == Integer.parseInt(months.get(i))) { - pop_wheel_yearlayout_month.setInitPosition(i); + pop_wheel_datarangelayout_month.setInitPosition(i); break; } } - pop_wheel_yearlayout_day.setNotLoop(); - pop_wheel_yearlayout_day.setViewPadding(SizeUtils.dp2px(30), SizeUtils.dp2px(15), SizeUtils.dp2px(30), SizeUtils.dp2px(15)); - pop_wheel_yearlayout_day.setItems(days); - pop_wheel_yearlayout_day.setTextSize(18); + pop_wheel_datarangelayout_day.setNotLoop(); + pop_wheel_datarangelayout_day.setViewPadding(SizeUtils.dp2px(15), SizeUtils.dp2px(15), SizeUtils.dp2px(15), SizeUtils.dp2px(15)); + pop_wheel_datarangelayout_day.setItems(days); + pop_wheel_datarangelayout_day.setTextSize(18); if (getArguments().getInt("type")==3) { - pop_wheel_yearlayout_day.setInitPosition(days.size()-1); + pop_wheel_datarangelayout_day.setInitPosition(days.size()-1); } else if (getArguments().getInt("type")==6) { for (int i = 0; i < days.size(); i++) { if (calendar_today.get(Calendar.DAY_OF_MONTH) == Integer.parseInt(days.get(i))) { - pop_wheel_yearlayout_day.setInitPosition(i); + pop_wheel_datarangelayout_day.setInitPosition(i); break; } } } + ArrayList hours=new ArrayList<>(); + for (int i=0;i<24;i++) { + hours.add(""+i); + } + ArrayList minutes=new ArrayList<>(); + for (int i=0;i<60;i++) { + minutes.add(i<10?"0"+i:""+i); + } + + pop_wheel_datarangelayout_hour.setNotLoop(); + pop_wheel_datarangelayout_hour.setViewPadding(SizeUtils.dp2px(15), SizeUtils.dp2px(15), SizeUtils.dp2px(15), SizeUtils.dp2px(15)); + pop_wheel_datarangelayout_hour.setItems(hours); + pop_wheel_datarangelayout_hour.setTextSize(18); + pop_wheel_datarangelayout_minute.setNotLoop(); + pop_wheel_datarangelayout_minute.setViewPadding(SizeUtils.dp2px(15), SizeUtils.dp2px(15), SizeUtils.dp2px(15), SizeUtils.dp2px(15)); + pop_wheel_datarangelayout_minute.setItems(minutes); + pop_wheel_datarangelayout_minute.setTextSize(18); + LinearLayout pop_morechoice= (LinearLayout) view.findViewById(R.id.pop_morechoice); pop_morechoice.setVisibility(View.VISIBLE); TextView pop_ok1= (TextView) view.findViewById(R.id.pop_ok1); pop_ok1.setText(getArguments().getString("okTitle")); pop_ok1.setOnClickListener(v -> { if (onOKListener!=null) { - onOKListener.onOKClick(years.get(pop_wheel_yearlayout_year.getSelectedItem())+"-" - +months.get(pop_wheel_yearlayout_month.getSelectedItem())+"-" - +days.get(pop_wheel_yearlayout_day.getSelectedItem())); + onOKListener.onOKClick(years.get(pop_wheel_datarangelayout_year.getSelectedItem())+"-" + +(Integer.parseInt(months.get(pop_wheel_datarangelayout_month.getSelectedItem()))<10?"0"+months.get(pop_wheel_datarangelayout_month.getSelectedItem()):months.get(pop_wheel_datarangelayout_month.getSelectedItem()))+"-" + +(Integer.parseInt(days.get(pop_wheel_datarangelayout_day.getSelectedItem()))<10?"0"+days.get(pop_wheel_datarangelayout_day.getSelectedItem()):days.get(pop_wheel_datarangelayout_day.getSelectedItem()))+" " + +(Integer.parseInt(hours.get(pop_wheel_datarangelayout_hour.getSelectedItem()))<10?"0"+hours.get(pop_wheel_datarangelayout_hour.getSelectedItem()):hours.get(pop_wheel_datarangelayout_hour.getSelectedItem()))+":" + +minutes.get(pop_wheel_datarangelayout_minute.getSelectedItem())); } dismiss(); }); @@ -803,7 +825,9 @@ else if (getArguments().getInt("type")==4) { pop_ok1.setText(getArguments().getString("okTitle")); pop_ok1.setOnClickListener(v -> { if (onOKListener!=null) { - onOKListener.onOKClick(hours.get(pop_wheel_timelayout_hour.getSelectedItem())+":"+minutes.get(pop_wheel_timelayout_minute.getSelectedItem())); + onOKListener.onOKClick( + Integer.parseInt(hours.get(pop_wheel_timelayout_hour.getSelectedItem()))<10?"0"+hours.get(pop_wheel_timelayout_hour.getSelectedItem()):hours.get(pop_wheel_timelayout_hour.getSelectedItem())+":"+ + minutes.get(pop_wheel_timelayout_minute.getSelectedItem())); } dismiss(); }); diff --git a/CommonLibrary/src/main/res/layout/view_actionsheet.xml b/CommonLibrary/src/main/res/layout/view_actionsheet.xml index f614c97..b44eda9 100644 --- a/CommonLibrary/src/main/res/layout/view_actionsheet.xml +++ b/CommonLibrary/src/main/res/layout/view_actionsheet.xml @@ -124,6 +124,34 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" /> + + + + + + + { -// -// }) -// .setCustomerView(view_threeloopertitle_floor) -// .show(); + View view_threeloopertitle_floor = addAction(); + ActionSheetFragment.build() + .setChoice(ActionSheetFragment.CHOICE.CUSTOMER) + .setCanDismiss(false) + .setOnOKListener(value -> { + + }) + .setCustomerView(view_threeloopertitle_floor) + .show(this); -// ActionSheetFragment.build(getSupportFragmentManager()).setChoice(ActionSheetFragment.CHOICE.GRID).setGridItems(new String[]{"微信好友", "朋友圈", "QQ好友", "微博"}, +// ActionSheetFragment.build().setChoice(ActionSheetFragment.CHOICE.GRID).setGridItems(new String[]{"微信好友", "朋友圈", "QQ好友", "微博"}, // new int[]{R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher}, // position -> { // -// }).show(); +// }).show(this); - ActionSheetUtils.showDateRange(this, "", "", "", 946656000000L, 1924876800000L, new ActionSheetFragment.OnOKListener() { - @Override - public void onOKClick(Object value) { - - } - }, new ActionSheetFragment.OnCancelListener() { - @Override - public void onCancelClick() { - - } - }); +// ActionSheetUtils.showDateRange(this, "", "取消", "确定", 946656000000L, 1924876800000L, new ActionSheetFragment.OnOKListener() { +// @Override +// public void onOKClick(Object value) { +// Toast.makeText(ActionSheetActivity.this, value.toString(), Toast.LENGTH_SHORT).show(); +// } +// }, new ActionSheetFragment.OnCancelListener() { +// @Override +// public void onCancelClick() { +// +// } +// }); break; } } @@ -97,16 +96,16 @@ private void initLooper(LoopView loopview, ArrayList strings) { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); -// if (savedInstanceState!=null) { -// if (getSupportFragmentManager().getFragments().size()>0) { -// for (Fragment fragment : getSupportFragmentManager().getFragments()) { -// if (fragment instanceof ActionSheetFragment) { -// View view_threeloopertitle_floor = addAction(); -// ((ActionSheetFragment) fragment).restoreCustomerView(view_threeloopertitle_floor); -// } -// } -// } -// } + if (savedInstanceState!=null) { + if (getSupportFragmentManager().getFragments().size()>0) { + for (Fragment fragment : getSupportFragmentManager().getFragments()) { + if (fragment instanceof ActionSheetFragment) { + View view_threeloopertitle_floor = addAction(); + ((ActionSheetFragment) fragment).restoreCustomerView(view_threeloopertitle_floor); + } + } + } + } } @NonNull