Skip to content

Commit 4c5c49f

Browse files
author
CNCoderX
committed
Optimize the 3D display
1 parent 984cf6d commit 4c5c49f

17 files changed

Lines changed: 273 additions & 253 deletions

File tree

app/src/main/AndroidManifest.xml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,25 @@
77
android:icon="@mipmap/ic_launcher"
88
android:label="@string/app_name"
99
android:supportsRtl="true"
10-
android:theme="@style/AppTheme">
11-
<activity android:name=".MainActivity">
10+
android:theme="@android:style/Theme.Holo.Light">
11+
<activity
12+
android:name=".MainActivity"
13+
android:screenOrientation="portrait">
1214
<intent-filter>
1315
<action android:name="android.intent.action.MAIN"/>
1416

1517
<category android:name="android.intent.category.LAUNCHER"/>
1618
</intent-filter>
1719
</activity>
20+
<activity android:name=".SimpleTestActivity"
21+
android:label="Simple Test"
22+
android:screenOrientation="portrait"
23+
/>
24+
25+
<activity android:name=".DatePickerTestActivity"
26+
android:label="Date Picker Test"
27+
android:screenOrientation="portrait"
28+
android:theme="@android:style/Theme.Holo"/>
1829
</application>
1930

2031
</manifest>
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
package com.cncoderx.test.wheelview;
2+
3+
import android.app.Activity;
4+
import android.os.Bundle;
5+
import android.widget.TextView;
6+
7+
import com.cncoderx.wheelview.OnWheelChangedListener;
8+
import com.cncoderx.wheelview.WheelView;
9+
10+
import java.util.Calendar;
11+
12+
/**
13+
* @author cncoderx
14+
*/
15+
public class DatePickerTestActivity extends Activity {
16+
TextView mTextView;
17+
WheelView wvYear, wvMonth, wvDay;
18+
19+
int mYear, mMonth, mDay;
20+
21+
@Override
22+
protected void onCreate(Bundle savedInstanceState) {
23+
super.onCreate(savedInstanceState);
24+
setContentView(R.layout.activity_main);
25+
mTextView = (TextView) findViewById(R.id.textView2);
26+
wvYear = (WheelView) findViewById(R.id.wv_year);
27+
wvMonth = (WheelView) findViewById(R.id.wv_month);
28+
wvDay = (WheelView) findViewById(R.id.wv_day);
29+
30+
wvYear.setEntries(new String[]{
31+
"1980年", "1981年", "1982年", "1983年", "1984年", "1985年", "1986年", "1987年", "1988年", "1989年",
32+
"1990年", "1991年", "1992年", "1993年", "1994年", "1995年", "1996年", "1997年", "1998年", "1999年",
33+
"2000年", "2001年", "2002年", "2003年", "2004年", "2005年", "2006年", "2007年", "2008年", "2009年",
34+
"2010年", "2011年", "2012年", "2013年", "2014年", "2015年", "2016年", "2017年", "2018年", "2019年", "2020年"});
35+
36+
wvMonth.setEntries(new String[] {"1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"});
37+
38+
wvYear.setOnWheelChangedListener(new OnWheelChangedListener() {
39+
@Override
40+
public void onChanged(WheelView wheel, int oldIndex, int newIndex) {
41+
String text = (String) wvYear.getItem(newIndex);
42+
mYear = Integer.parseInt(text.substring(0, text.length() - 1));
43+
updateDayEntries();
44+
updateTextView();
45+
}
46+
});
47+
wvMonth.setOnWheelChangedListener(new OnWheelChangedListener() {
48+
@Override
49+
public void onChanged(WheelView wheel, int oldIndex, int newIndex) {
50+
String text = (String) wvMonth.getItem(newIndex);
51+
mMonth = Integer.parseInt(text.substring(0, text.length() - 1));
52+
updateDayEntries();
53+
updateTextView();
54+
}
55+
});
56+
wvDay.setOnWheelChangedListener(new OnWheelChangedListener() {
57+
@Override
58+
public void onChanged(WheelView wheel, int oldIndex, int newIndex) {
59+
String text = (String) wvDay.getItem(newIndex);
60+
mDay = Integer.parseInt(text.substring(0, text.length() - 1));
61+
updateTextView();
62+
}
63+
});
64+
65+
mYear = 1980;
66+
mMonth = 1;
67+
mDay = 1;
68+
updateDayEntries();
69+
updateTextView();
70+
}
71+
72+
private void updateDayEntries() {
73+
Calendar calendar = Calendar.getInstance();
74+
calendar.set(Calendar.YEAR, mYear);
75+
calendar.set(Calendar.MONTH, mMonth - 1);
76+
77+
int days = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
78+
switch (days) {
79+
case 28:
80+
wvDay.setEntries(new String[] {
81+
"1日", "2日", "3日", "4日", "5日", "6日", "7日", "8日", "9日", "10日",
82+
"11日", "12日", "13日", "14日", "15日", "16日", "17日", "18日", "19日", "20日",
83+
"21日", "22日", "23日", "24日", "25日", "26日", "27日", "28日"});
84+
break;
85+
case 29:
86+
wvDay.setEntries(new String[] {
87+
"1日", "2日", "3日", "4日", "5日", "6日", "7日", "8日", "9日", "10日",
88+
"11日", "12日", "13日", "14日", "15日", "16日", "17日", "18日", "19日", "20日",
89+
"21日", "22日", "23日", "24日", "25日", "26日", "27日", "28日", "29日"});
90+
break;
91+
case 30:
92+
wvDay.setEntries(new String[] {
93+
"1日", "2日", "3日", "4日", "5日", "6日", "7日", "8日", "9日", "10日",
94+
"11日", "12日", "13日", "14日", "15日", "16日", "17日", "18日", "19日", "20日",
95+
"21日", "22日", "23日", "24日", "25日", "26日", "27日", "28日", "29日", "30日"});
96+
break;
97+
case 31:
98+
default:
99+
wvDay.setEntries(new String[] {
100+
"1日", "2日", "3日", "4日", "5日", "6日", "7日", "8日", "9日", "10日",
101+
"11日", "12日", "13日", "14日", "15日", "16日", "17日", "18日", "19日", "20日",
102+
"21日", "22日", "23日", "24日", "25日", "26日", "27日", "28日", "29日", "30日",
103+
"31日"});
104+
break;
105+
}
106+
}
107+
108+
private void updateTextView() {
109+
String text = String.format("%04d年%d月%d日", mYear, mMonth, mDay);
110+
mTextView.setText(text);
111+
}
112+
}
Lines changed: 16 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,31 @@
11
package com.cncoderx.test.wheelview;
22

3-
import android.app.Activity;
3+
import android.app.ListActivity;
4+
import android.content.Intent;
45
import android.os.Bundle;
5-
import android.widget.TextView;
6+
import android.view.View;
7+
import android.widget.ArrayAdapter;
8+
import android.widget.ListView;
69

7-
import com.cncoderx.wheelview.OnWheelChangedListener;
8-
import com.cncoderx.wheelview.WheelView;
9-
10-
import java.util.Calendar;
11-
12-
public class MainActivity extends Activity {
13-
TextView mTextView;
14-
WheelView wvYear, wvMonth, wvDay;
15-
16-
int mYear, mMonth, mDay;
10+
public class MainActivity extends ListActivity {
1711

1812
@Override
1913
protected void onCreate(Bundle savedInstanceState) {
2014
super.onCreate(savedInstanceState);
21-
setContentView(R.layout.activity_main);
22-
mTextView = (TextView) findViewById(R.id.textView2);
23-
wvYear = (WheelView) findViewById(R.id.wv_year);
24-
wvMonth = (WheelView) findViewById(R.id.wv_month);
25-
wvDay = (WheelView) findViewById(R.id.wv_day);
26-
27-
wvYear.setEntries(new String[]{
28-
"1980年", "1981年", "1982年", "1983年", "1984年", "1985年", "1986年", "1987年", "1988年", "1989年",
29-
"1990年", "1991年", "1992年", "1993年", "1994年", "1995年", "1996年", "1997年", "1998年", "1999年",
30-
"2000年", "2001年", "2002年", "2003年", "2004年", "2005年", "2006年", "2007年", "2008年", "2009年",
31-
"2010年", "2011年", "2012年", "2013年", "2014年", "2015年", "2016年", "2017年", "2018年", "2019年", "2020年"});
32-
33-
wvMonth.setEntries(new String[] {"1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"});
34-
35-
wvYear.setOnWheelChangedListener(new OnWheelChangedListener() {
36-
@Override
37-
public void onChanged(WheelView wheel, int oldIndex, int newIndex) {
38-
String text = (String) wvYear.getItem(newIndex);
39-
mYear = Integer.parseInt(text.substring(0, text.length() - 1));
40-
updateDayEntries();
41-
updateTextView();
42-
}
43-
});
44-
wvMonth.setOnWheelChangedListener(new OnWheelChangedListener() {
45-
@Override
46-
public void onChanged(WheelView wheel, int oldIndex, int newIndex) {
47-
String text = (String) wvMonth.getItem(newIndex);
48-
mMonth = Integer.parseInt(text.substring(0, text.length() - 1));
49-
updateDayEntries();
50-
updateTextView();
51-
}
52-
});
53-
wvDay.setOnWheelChangedListener(new OnWheelChangedListener() {
54-
@Override
55-
public void onChanged(WheelView wheel, int oldIndex, int newIndex) {
56-
String text = (String) wvDay.getItem(newIndex);
57-
mDay = Integer.parseInt(text.substring(0, text.length() - 1));
58-
updateTextView();
59-
}
60-
});
61-
62-
mYear = 1980;
63-
mMonth = 1;
64-
mDay = 1;
65-
updateDayEntries();
66-
updateTextView();
15+
setListAdapter(new ArrayAdapter<String>(
16+
this, android.R.layout.simple_list_item_1,
17+
new String[]{"Simple Test", "Date Picker Test"}));
6718
}
6819

69-
private void updateDayEntries() {
70-
Calendar calendar = Calendar.getInstance();
71-
calendar.set(Calendar.YEAR, mYear);
72-
calendar.set(Calendar.MONTH, mMonth - 1);
73-
74-
int days = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
75-
switch (days) {
76-
case 28:
77-
wvDay.setEntries(new String[] {
78-
"1日", "2日", "3日", "4日", "5日", "6日", "7日", "8日", "9日", "10日",
79-
"11日", "12日", "13日", "14日", "15日", "16日", "17日", "18日", "19日", "20日",
80-
"21日", "22日", "23日", "24日", "25日", "26日", "27日", "28日"});
81-
break;
82-
case 29:
83-
wvDay.setEntries(new String[] {
84-
"1日", "2日", "3日", "4日", "5日", "6日", "7日", "8日", "9日", "10日",
85-
"11日", "12日", "13日", "14日", "15日", "16日", "17日", "18日", "19日", "20日",
86-
"21日", "22日", "23日", "24日", "25日", "26日", "27日", "28日", "29日"});
87-
break;
88-
case 30:
89-
wvDay.setEntries(new String[] {
90-
"1日", "2日", "3日", "4日", "5日", "6日", "7日", "8日", "9日", "10日",
91-
"11日", "12日", "13日", "14日", "15日", "16日", "17日", "18日", "19日", "20日",
92-
"21日", "22日", "23日", "24日", "25日", "26日", "27日", "28日", "29日", "30日"});
20+
@Override
21+
protected void onListItemClick(ListView l, View v, int position, long id) {
22+
switch (position) {
23+
case 0:
24+
startActivity(new Intent(this, SimpleTestActivity.class));
9325
break;
94-
case 31:
95-
default:
96-
wvDay.setEntries(new String[] {
97-
"1日", "2日", "3日", "4日", "5日", "6日", "7日", "8日", "9日", "10日",
98-
"11日", "12日", "13日", "14日", "15日", "16日", "17日", "18日", "19日", "20日",
99-
"21日", "22日", "23日", "24日", "25日", "26日", "27日", "28日", "29日", "30日",
100-
"31日"});
26+
case 1:
27+
startActivity(new Intent(this, DatePickerTestActivity.class));
10128
break;
10229
}
10330
}
104-
105-
private void updateTextView() {
106-
String text = String.format("%04d年%d月%d日", mYear, mMonth, mDay);
107-
mTextView.setText(text);
108-
}
10931
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.cncoderx.test.wheelview;
2+
3+
import android.app.Activity;
4+
import android.os.Bundle;
5+
6+
/**
7+
* @author cncoderx
8+
*/
9+
public class SimpleTestActivity extends Activity {
10+
11+
@Override
12+
protected void onCreate(Bundle savedInstanceState) {
13+
super.onCreate(savedInstanceState);
14+
setContentView(R.layout.activity_wheel_view_test);
15+
}
16+
}

app/src/main/res/layout/activity_main.xml

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,6 @@
2929
android:textColor="#fff"
3030
android:textSize="18sp"/>
3131

32-
<!--<LinearLayout-->
33-
<!--android:layout_width="240dp"-->
34-
<!--android:layout_height="wrap_content"-->
35-
<!--android:layout_centerInParent="true">-->
36-
37-
<!--<com.cncoderx.wheelview.Wheel3DView-->
38-
<!--android:id="@+id/wv_year"-->
39-
<!--android:layout_width="0dp"-->
40-
<!--android:layout_height="wrap_content"-->
41-
<!--android:layout_weight="1"-->
42-
<!--app:toward="left"-->
43-
<!--style="@style/DatePickerStyle"/>-->
44-
45-
<!--<com.cncoderx.wheelview.Wheel3DView-->
46-
<!--android:id="@+id/wv_month"-->
47-
<!--android:layout_width="0dp"-->
48-
<!--android:layout_height="wrap_content"-->
49-
<!--android:layout_weight="1"-->
50-
<!--app:cyclic="true"-->
51-
<!--style="@style/DatePickerStyle"/>-->
52-
53-
<!--<com.cncoderx.wheelview.Wheel3DView-->
54-
<!--android:id="@+id/wv_day"-->
55-
<!--android:layout_width="0dp"-->
56-
<!--android:layout_height="wrap_content"-->
57-
<!--android:layout_weight="1"-->
58-
<!--app:cyclic="true"-->
59-
<!--app:toward="right"-->
60-
<!--style="@style/DatePickerStyle"/>-->
61-
<!--</LinearLayout>-->
62-
6332
<LinearLayout
6433
android:layout_width="wrap_content"
6534
android:layout_height="wrap_content"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:app="http://schemas.android.com/apk/res-auto"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
android:gravity="center">
8+
9+
<com.cncoderx.wheelview.WheelView
10+
android:id="@+id/wheel"
11+
android:layout_width="wrap_content"
12+
android:layout_height="wrap_content"
13+
app:cyclic="true"
14+
app:entries="@array/default_array"
15+
app:visibleItems="9"
16+
app:toward="none"
17+
app:textSize="24sp"
18+
app:lineSpace="20dp"/>
19+
20+
<com.cncoderx.wheelview.Wheel3DView
21+
android:id="@+id/wheel3d"
22+
android:layout_width="wrap_content"
23+
android:layout_height="wrap_content"
24+
android:layout_marginLeft="20dp"
25+
app:cyclic="true"
26+
app:entries="@array/default_array"
27+
app:visibleItems="9"
28+
app:toward="none"
29+
app:textSize="24sp"
30+
app:lineSpace="20dp"/>
31+
32+
</LinearLayout>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,41 @@
11
<resources>
22
<string name="app_name">WheelView</string>
3+
4+
<string-array name="default_array">
5+
<item>北京</item>
6+
<item>天津</item>
7+
<item>上海</item>
8+
<item>重庆</item>
9+
<item>河北</item>
10+
<item>河南</item>
11+
<item>云南</item>
12+
<item>辽宁</item>
13+
<item>黑龙江</item>
14+
<item>湖南</item>
15+
<item>安徽</item>
16+
<item>山东</item>
17+
<item>新疆</item>
18+
<item>江苏</item>
19+
<item>浙江</item>
20+
<item>江西</item>
21+
<item>湖北</item>
22+
<item>广西</item>
23+
<item>甘肃</item>
24+
<item>山西</item>
25+
<item>内蒙古</item>
26+
<item>陕西</item>
27+
<item>吉林</item>
28+
<item>福建</item>
29+
<item>贵州</item>
30+
<item>广东</item>
31+
<item>青海</item>
32+
<item>西藏</item>
33+
<item>四川</item>
34+
<item>宁夏</item>
35+
<item>海南</item>
36+
<item>台湾</item>
37+
<item>香港</item>
38+
<item>澳门</item>
39+
</string-array>
40+
341
</resources>

0 commit comments

Comments
 (0)