Skip to content

Commit

Permalink
时间选择功能扩展
Browse files Browse the repository at this point in the history
  • Loading branch information
r17171709 committed Jan 2, 2018
1 parent 33c8183 commit 4f367da
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -650,28 +650,30 @@ 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();
calendar.setTime(new Date());
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();
}
Expand All @@ -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();
}
Expand All @@ -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<String> hours=new ArrayList<>();
for (int i=0;i<24;i++) {
hours.add(""+i);
}
ArrayList<String> 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();
});
Expand Down Expand Up @@ -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();
});
Expand Down
28 changes: 28 additions & 0 deletions CommonLibrary/src/main/res/layout/view_actionsheet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,34 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="@+id/pop_wheel_datarangelayout"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="230dip"
android:gravity="center"
android:orientation="horizontal">
<com.renyu.commonlibrary.views.wheelview.LoopView
android:id="@+id/pop_wheel_datarangelayout_year"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<com.renyu.commonlibrary.views.wheelview.LoopView
android:id="@+id/pop_wheel_datarangelayout_month"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<com.renyu.commonlibrary.views.wheelview.LoopView
android:id="@+id/pop_wheel_datarangelayout_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<com.renyu.commonlibrary.views.wheelview.LoopView
android:id="@+id/pop_wheel_datarangelayout_hour"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<com.renyu.commonlibrary.views.wheelview.LoopView
android:id="@+id/pop_wheel_datarangelayout_minute"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="@+id/pop_customer_layout"
android:layout_width="match_parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.renyu.androidcommonlibrary.R;
import com.renyu.commonlibrary.baseact.BaseActivity;
import com.renyu.commonlibrary.views.actionsheet.ActionSheetFragment;
import com.renyu.commonlibrary.views.actionsheet.ActionSheetUtils;
import com.renyu.commonlibrary.views.wheelview.LoopView;
import com.renyu.commonlibrary.views.wheelview.OnItemSelectedListener;

Expand Down Expand Up @@ -55,33 +54,33 @@ public int setStatusBarTranslucent() {
public void onClick(View view) {
switch (view.getId()) {
case R.id.btn_click:
// View view_threeloopertitle_floor = addAction();
// ActionSheetFragment.build(getSupportFragmentManager())
// .setChoice(ActionSheetFragment.CHOICE.CUSTOMER)
// .setCanDismiss(false)
// .setOnOKListener(value -> {
//
// })
// .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;
}
}
Expand All @@ -97,16 +96,16 @@ private void initLooper(LoopView loopview, ArrayList<String> 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
Expand Down

0 comments on commit 4f367da

Please sign in to comment.