Skip to content

Commit

Permalink
General Changes
Browse files Browse the repository at this point in the history
- Fix issue with indexOutOfBounds on when scrolling by month DatePickerWheelView
- Set canLoop in WheelView to false as default value
- Removed unused attributes under datepicker and datepicker inverted XML layouts
  • Loading branch information
jonatansalas committed Feb 4, 2017
1 parent 2559633 commit e29d335
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 27 deletions.
19 changes: 15 additions & 4 deletions app/src/main/res/layout/content_main.xml
Expand Up @@ -17,16 +17,14 @@
android:id="@+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date Pick"
/>
android:text="Date Pick" />

<Button
android:id="@+id/province"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/date"
android:text="Province Pick"
/>
android:text="Province Pick" />

<io.blackbox_vision.wheelview.view.WheelView
android:id="@+id/loop_view"
Expand All @@ -41,4 +39,17 @@
app:wheelViewTextSize="25sp"
app:wheelViewOverflowTextColor="#ffafafaf"/>

<io.blackbox_vision.wheelview.view.DatePickerWheelView
android:layout_width="match_parent"
android:layout_height="180dp"
android:layout_below="@+id/loop_view"
app:datePickerWheelViewMinYear="1940"
app:datePickerWheelViewMaxYear="2100"
app:datePickerWheelViewInitialDate="2017-02-04"
app:datePickerWheelViewShowShortMonths="true"
app:datePickerWheelViewShowDayMonthYear="false"
app:datePickerWheelViewContentTextColor="@color/colorAccent"
app:datePickerWheelViewOverflowTextColor="@color/colorPrimary"
app:datePickerWheelViewLineColor="@color/colorAccent"/>

</RelativeLayout>
Expand Up @@ -140,12 +140,8 @@ private void drawDatePickerWheelView() {
monthSpinner.setOverflowTextColor(overflowTextColor);
daySpinner.setOverflowTextColor(overflowTextColor);

yearSpinner.setIsLoopEnabled(false);
monthSpinner.setIsLoopEnabled(false);
daySpinner.setIsLoopEnabled(false);

yearSpinner.setTextSize(textSize);
monthSpinner.setTextSize(textSize - 3.5F);
monthSpinner.setTextSize(textSize);
daySpinner.setTextSize(textSize);

yearSpinner.addOnLoopScrollListener(this::updateYearPosition);
Expand Down Expand Up @@ -182,9 +178,15 @@ private void updateDayPosition(@NonNull Object item, int position) {

private void onDateSelected(@NonNull Object item, int position) {
if (null != onDateSelectedListener) {
final int year = Integer.valueOf(years.get(yearPos));
final int month = showShortMonths ? months.indexOf(months.get(monthPos)) : Integer.valueOf(months.get(monthPos)) - 1;
final int dayOfMonth = Integer.valueOf(days.get(dayPos));
final Calendar calendar = Calendar.getInstance(locale);

calendar.set(Calendar.YEAR, Integer.valueOf(years.get(yearPos)));
calendar.set(Calendar.MONTH, monthPos);
calendar.set(Calendar.DAY_OF_MONTH, Integer.valueOf(days.get(dayPos)));

final int year = calendar.get(Calendar.YEAR);
final int month = calendar.get(Calendar.MONTH);
final int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);

onDateSelectedListener.onDateSelected(year, month, dayOfMonth);
}
Expand Down Expand Up @@ -240,13 +242,13 @@ private void drawMonthPickerView() {
private void drawDayPickerView() {
deleteAll(days);
final int year = Integer.valueOf(years.get(yearPos));
final int month = showShortMonths ? months.indexOf(months.get(monthPos)) + 1 : Integer.valueOf(months.get(monthPos));
//final int month = showShortMonths ? months.indexOf(months.get(monthPos)) + 1 : Integer.valueOf(months.get(monthPos));

calendar = Calendar.getInstance(locale);

for (int i = 0; i < calendar.getActualMaximum(Calendar.DAY_OF_MONTH); i++) {
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month - 1);
calendar.set(Calendar.MONTH, monthPos);
calendar.set(Calendar.DAY_OF_MONTH, i + 1);

days.add(i, formatDate(calendar, locale, DAY_FORMAT));
Expand Down
Expand Up @@ -132,7 +132,7 @@ private void initView(@NonNull AttributeSet attrs) {
overflowTextColor = array.getColor(R.styleable.WheelView_wheelViewOverflowTextColor, 0xffafafaf);
contentTextColor = array.getColor(R.styleable.WheelView_wheelViewContentTextColor, 0xff313131);
lineColor = array.getColor(R.styleable.WheelView_wheelViewLineColor, 0xffc5c5c5);
canLoop = array.getBoolean(R.styleable.WheelView_wheelViewIsLoopEnabled, true);
canLoop = array.getBoolean(R.styleable.WheelView_wheelViewIsLoopEnabled, false);
initialPosition = array.getInt(R.styleable.WheelView_wheelViewInitialPosition, -1);
textSize = array.getDimensionPixelSize(R.styleable.WheelView_wheelViewTextSize, sp2px(getContext(), 16));
drawItemsCount = array.getInt(R.styleable.WheelView_wheelViewDrawItemCount, 7);
Expand Down
9 changes: 3 additions & 6 deletions materialwheelview/src/main/res/layout/date_picker.xml
Expand Up @@ -11,8 +11,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
app:wheelViewTextSize="25sp"
app:wheelViewIsLoopEnabled="false"/>
app:wheelViewTextSize="25sp"/>

<io.blackbox_vision.wheelview.view.WheelView
android:id="@+id/picker_month"
Expand All @@ -21,8 +20,7 @@
android:layout_marginLeft="1dp"
android:layout_marginStart="1dp"
android:layout_weight="1"
app:wheelViewTextSize="25sp"
app:wheelViewIsLoopEnabled="false"/>
app:wheelViewTextSize="25sp"/>

<io.blackbox_vision.wheelview.view.WheelView
android:id="@+id/picker_day"
Expand All @@ -31,7 +29,6 @@
android:layout_marginLeft="1dp"
android:layout_marginStart="1dp"
android:layout_weight="1"
app:wheelViewTextSize="25sp"
app:wheelViewIsLoopEnabled="false"/>
app:wheelViewTextSize="25sp"/>

</LinearLayout>
Expand Up @@ -13,8 +13,7 @@
android:layout_marginLeft="1dp"
android:layout_marginStart="1dp"
android:layout_weight="1"
app:wheelViewTextSize="25sp"
app:wheelViewIsLoopEnabled="false"/>
app:wheelViewTextSize="25sp"/>

<io.blackbox_vision.wheelview.view.WheelView
android:id="@+id/picker_month"
Expand All @@ -23,15 +22,13 @@
android:layout_marginLeft="1dp"
android:layout_marginStart="1dp"
android:layout_weight="1"
app:wheelViewTextSize="25sp"
app:wheelViewIsLoopEnabled="false"/>
app:wheelViewTextSize="25sp"/>

<io.blackbox_vision.wheelview.view.WheelView
android:id="@+id/picker_year"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
app:wheelViewTextSize="25sp"
app:wheelViewIsLoopEnabled="false"/>
app:wheelViewTextSize="25sp"/>

</LinearLayout>

0 comments on commit e29d335

Please sign in to comment.