values = new ArrayList<>();
43 | for (int i = startYear; i < endYear; i++) {
44 | values.add(i);
45 | }
46 |
47 | setData(values);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/Trunk/pickdatetime/src/main/java/com/example/pickdatetime/bean/DateParams.java:
--------------------------------------------------------------------------------
1 | package com.example.pickdatetime.bean;
2 |
3 | import androidx.annotation.IntDef;
4 |
5 | import java.lang.annotation.Retention;
6 | import java.lang.annotation.RetentionPolicy;
7 | import java.util.Date;
8 |
9 | /**
10 | * Created by fhf11991 on 2017/8/29.
11 | */
12 |
13 | public class DateParams {
14 | public int[] types;
15 | public Date currentDate;
16 | public Date startDate;
17 | public Date endDate;
18 |
19 | public DateParams(@Type int... style) {
20 | this.types = style;
21 | }
22 |
23 | @IntDef({TYPE_YEAR, TYPE_MONTH, TYPE_DAY, TYPE_HOUR, TYPE_MINUTE})
24 | @Retention(RetentionPolicy.SOURCE)
25 | public @interface Type {}
26 |
27 | public final static int TYPE_YEAR = 1; // 2 x 0
28 | public final static int TYPE_MONTH = 2; // 2 x 1
29 | public final static int TYPE_DAY = 4; // 2 x 2
30 | public final static int TYPE_HOUR = 8; // 2 x 3
31 | public final static int TYPE_MINUTE = 16; // 2 x 4
32 |
33 | public static String getFormat(int[] types) {
34 | if(types == null) {
35 | return null;
36 | }
37 |
38 | int total = 0;
39 | for(int type : types) {
40 | total = total + type;
41 | }
42 |
43 | StringBuffer format = new StringBuffer();
44 |
45 | // year
46 | boolean hasYear = (total & TYPE_YEAR) == TYPE_YEAR;
47 | if(hasYear) {
48 | format.append("yyyy");
49 | }
50 |
51 | // month
52 | boolean hasMonth = (total & TYPE_MONTH) == TYPE_MONTH;
53 | if(hasMonth) {
54 | format.append(hasYear ? "-" : "");
55 | format.append("MM");
56 | }
57 |
58 | // day
59 | boolean hasDay = (total & TYPE_DAY) == TYPE_DAY;
60 | if(hasDay) {
61 | format.append(hasMonth ? "-" : "");
62 | format.append("dd");
63 | }
64 |
65 | // hour
66 | boolean hasHour = (total & TYPE_HOUR) == TYPE_HOUR;
67 | if(hasHour) {
68 | format.append(" HH");
69 | }
70 |
71 | // minute
72 | if((total & TYPE_MINUTE) == TYPE_MINUTE) {
73 | format.append(hasHour ? ":" : "");
74 | format.append("mm");
75 | }
76 |
77 | return format.toString();
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/Trunk/pickdatetime/src/main/java/com/example/pickdatetime/bean/DatePick.java:
--------------------------------------------------------------------------------
1 | package com.example.pickdatetime.bean;
2 |
3 | import java.util.Calendar;
4 |
5 | /**
6 | * Created by fhf11991 on 2017/8/29.
7 | */
8 |
9 | public class DatePick {
10 |
11 | public int year;
12 | public int month;
13 | public int day;
14 | public int hour;
15 | public int minute;
16 |
17 | public void setData(Calendar calendar) {
18 | year = calendar.get(Calendar.YEAR);
19 | month = calendar.get(Calendar.MONTH) + 1;
20 | day = calendar.get(Calendar.DAY_OF_MONTH);
21 | hour = calendar.get(Calendar.HOUR_OF_DAY);
22 | minute = calendar.get(Calendar.MINUTE);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Trunk/pickdatetime/src/main/java/com/example/pickdatetime/view/ItemsRange.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Android Wheel Control.
3 | * https://code.google.com/p/android-wheel/
4 | *
5 | * Copyright 2011 Yuri Kanivets
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 |
20 | package com.example.pickdatetime.view;
21 |
22 | /**
23 | * Range for visible items.
24 | */
25 | public class ItemsRange {
26 | // First item number
27 | private int first;
28 |
29 | // Items count
30 | private int count;
31 |
32 | /**
33 | * Default constructor. Creates an empty range
34 | */
35 | public ItemsRange() {
36 | this(0, 0);
37 | }
38 |
39 | /**
40 | * Constructor
41 | * @param first the number of first item
42 | * @param count the count of items
43 | */
44 | public ItemsRange(int first, int count) {
45 | this.first = first;
46 | this.count = count;
47 | }
48 |
49 | /**
50 | * Gets number of first item
51 | * @return the number of the first item
52 | */
53 | public int getFirst() {
54 | return first;
55 | }
56 |
57 | /**
58 | * Gets number of last item
59 | * @return the number of last item
60 | */
61 | public int getLast() {
62 | return getFirst() + getCount() - 1;
63 | }
64 |
65 | /**
66 | * Get items count
67 | * @return the count of items
68 | */
69 | public int getCount() {
70 | return count;
71 | }
72 |
73 | /**
74 | * Tests whether item is contained by range
75 | * @param index the item number
76 | * @return true if item is contained
77 | */
78 | public boolean contains(int index) {
79 | return index >= getFirst() && index <= getLast();
80 | }
81 | }
--------------------------------------------------------------------------------
/Trunk/pickdatetime/src/main/java/com/example/pickdatetime/view/OnWheelChangedListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 Yuri Kanivets
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.example.pickdatetime.view;
18 |
19 | /**
20 | * Wheel changed listener interface.
21 | * The onChanged() method is called whenever current wheel2 positions is changed:
22 | *
New Wheel position is set
23 | * Wheel view is scrolled
24 | */
25 | public interface OnWheelChangedListener {
26 | /**
27 | * Callback method to be invoked when current item changed
28 | * @param wheel the wheel2 view whose state has changed
29 | * @param oldValue the old value of current item
30 | * @param newValue the new value of current item
31 | */
32 | void onChanged(WheelView wheel, int oldValue, int newValue);
33 | }
34 |
--------------------------------------------------------------------------------
/Trunk/pickdatetime/src/main/java/com/example/pickdatetime/view/OnWheelClickedListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 Yuri Kanivets
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.example.pickdatetime.view;
18 |
19 | /**
20 | * Wheel clicked listener interface.
21 | * The onItemClicked() method is called whenever a wheel2 item is clicked
22 | *
New Wheel position is set
23 | * Wheel view is scrolled
24 | */
25 | public interface OnWheelClickedListener {
26 | /**
27 | * Callback method to be invoked when current item clicked
28 | * @param wheel the wheel2 view
29 | * @param itemIndex the index of clicked item
30 | */
31 | void onItemClicked(WheelView wheel, int itemIndex);
32 | }
33 |
--------------------------------------------------------------------------------
/Trunk/pickdatetime/src/main/java/com/example/pickdatetime/view/OnWheelScrollListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Yuri Kanivets
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.example.pickdatetime.view;
18 |
19 | /**
20 | * Wheel scrolled listener interface.
21 | */
22 | public interface OnWheelScrollListener {
23 | /**
24 | * Callback method to be invoked when scrolling started.
25 | * @param wheel the wheel2 view whose state has changed.
26 | */
27 | void onScrollingStarted(WheelView wheel);
28 |
29 | /**
30 | * Callback method to be invoked when scrolling ended.
31 | * @param wheel the wheel2 view whose state has changed.
32 | */
33 | void onScrollingFinished(WheelView wheel);
34 | }
35 |
--------------------------------------------------------------------------------
/Trunk/pickdatetime/src/main/java/com/example/pickdatetime/view/WheelRecycle.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Android Wheel Control.
3 | * https://code.google.com/p/android-wheel/
4 | *
5 | * Copyright 2011 Yuri Kanivets
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 |
20 | package com.example.pickdatetime.view;
21 |
22 | import android.view.View;
23 | import android.widget.LinearLayout;
24 |
25 | import java.util.LinkedList;
26 | import java.util.List;
27 |
28 | /**
29 | * Recycle stores wheel2 items to reuse.
30 | */
31 | public class WheelRecycle {
32 | // Cached items
33 | private List items;
34 |
35 | // Cached empty items
36 | private List emptyItems;
37 |
38 | // Wheel view
39 | private WheelView wheel;
40 |
41 | /**
42 | * Constructor
43 | * @param wheel the wheel2 view
44 | */
45 | public WheelRecycle(WheelView wheel) {
46 | this.wheel = wheel;
47 | }
48 |
49 | /**
50 | * Recycles items from specified layout.
51 | * There are saved only items not included to specified range.
52 | * All the cached items are removed from original layout.
53 | *
54 | * @param layout the layout containing items to be cached
55 | * @param firstItem the number of first item in layout
56 | * @param range the range of current wheel2 items
57 | * @return the new value of first item number
58 | */
59 | public int recycleItems(LinearLayout layout, int firstItem, ItemsRange range) {
60 | int index = firstItem;
61 | for (int i = 0; i < layout.getChildCount();) {
62 | if (!range.contains(index)) {
63 | recycleView(layout.getChildAt(i), index);
64 | layout.removeViewAt(i);
65 | if (i == 0) { // first item
66 | firstItem++;
67 | }
68 | } else {
69 | i++; // go to next item
70 | }
71 | index++;
72 | }
73 | return firstItem;
74 | }
75 |
76 | /**
77 | * Gets item view
78 | * @return the cached view
79 | */
80 | public View getItem() {
81 | return getCachedView(items);
82 | }
83 |
84 | /**
85 | * Gets empty item view
86 | * @return the cached empty view
87 | */
88 | public View getEmptyItem() {
89 | return getCachedView(emptyItems);
90 | }
91 |
92 | /**
93 | * Clears all views
94 | */
95 | public void clearAll() {
96 | if (items != null) {
97 | items.clear();
98 | }
99 | if (emptyItems != null) {
100 | emptyItems.clear();
101 | }
102 | }
103 |
104 | /**
105 | * Adds view to specified cache. Creates a cache list if it is null.
106 | * @param view the view to be cached
107 | * @param cache the cache list
108 | * @return the cache list
109 | */
110 | private List addView(View view, List cache) {
111 | if (cache == null) {
112 | cache = new LinkedList();
113 | }
114 |
115 | cache.add(view);
116 | return cache;
117 | }
118 |
119 | /**
120 | * Adds view to cache. Determines view type (item view or empty one) by index.
121 | * @param view the view to be cached
122 | * @param index the index of view
123 | */
124 | private void recycleView(View view, int index) {
125 | int count = wheel.getViewAdapter().getItemsCount();
126 |
127 | if ((index < 0 || index >= count) && !wheel.isCyclic()) {
128 | // empty view
129 | emptyItems = addView(view, emptyItems);
130 | } else {
131 | while (index < 0) {
132 | index = count + index;
133 | }
134 | index %= count;
135 | items = addView(view, items);
136 | }
137 | }
138 |
139 | /**
140 | * Gets view from specified cache.
141 | * @param cache the cache
142 | * @return the first view from cache.
143 | */
144 | private View getCachedView(List cache) {
145 | if (cache != null && cache.size() > 0) {
146 | View view = cache.get(0);
147 | cache.remove(0);
148 | return view;
149 | }
150 | return null;
151 | }
152 |
153 | }
154 |
--------------------------------------------------------------------------------
/Trunk/pickdatetime/src/main/res/layout/cbk_dialog_pick_time.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
23 |
24 |
33 |
34 |
35 |
39 |
40 |
45 |
46 |
50 |
51 |
55 |
56 |
66 |
67 |
73 |
74 |
84 |
85 |
86 |
87 |
88 |
--------------------------------------------------------------------------------
/Trunk/pickdatetime/src/main/res/layout/cbk_wheel_default_inner_text.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/Trunk/pickdatetime/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | pickdatetime
3 |
4 |
--------------------------------------------------------------------------------
/Trunk/pickdatetime/src/main/res/values/style.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | //color
5 | #00000000
6 |
7 | //animal
8 |
12 |
13 | //style
14 |
19 |
20 |
--------------------------------------------------------------------------------
/Trunk/pickdatetime/src/test/java/com/example/pickdatetime/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.example.pickdatetime;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/Trunk/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':pickdatetime'
2 | include ':app'
3 | rootProject.name = "FModule"
--------------------------------------------------------------------------------