1+ package com .bn .activty ;
2+ import android .app .Activity ;
3+ import android .os .Bundle ;
4+ import android .view .Gravity ;
5+ import android .view .View ;
6+ import android .view .ViewGroup ;
7+ import android .view .Window ;
8+ import android .view .WindowManager ;
9+ import android .widget .AdapterView ;
10+ import android .widget .BaseAdapter ;
11+ import android .widget .LinearLayout ;
12+ import android .widget .ListView ;
13+ import android .widget .RadioButton ;
14+ import android .widget .RadioGroup ;
15+ import android .widget .TextView ;
16+
17+ import com .bn .util .Constant ;
18+ import com .bn .util .MyFunction ;
19+
20+
21+ public class MainActivity extends Activity {
22+ private MySurfaceView mGLSurfaceView ;//自己SurfaceView
23+ String organStr []=new String []{"骨骼" ,"大脑" ,"食道" ,"肺" ,"心脏" ,"肝脏" ,"胰脏" ,"胆囊" ,"胃" ,"脾" ,"肠" ,"肾" ,"膀胱" };//男生器官字符串
24+ String womanorganStr []=new String []{"骨骼" ,"大脑" ,"食道" ,"肺" ,"心脏" ,"肝脏" ,"胰脏" ,"胆囊" ,"胃" ,"子宫" ,"肠" ,"肾" ,"膀胱" };//女生器官字符串
25+ int oldSelect =14 ;//记录上次点击的值
26+ float colorRed []=new float []{1.0f ,0.0f ,0.0f ,1.0f };//红色
27+ ListView ls ;//器官的listView
28+ BaseAdapter ba ;//男的Adapter
29+ BaseAdapter baWoman ;//女的Adapter
30+ @ Override
31+ protected void onCreate (Bundle savedInstanceState )
32+ {
33+ super .onCreate (savedInstanceState );
34+ //设置为全屏
35+ requestWindowFeature (Window .FEATURE_NO_TITLE );
36+ getWindow ().setFlags (WindowManager .LayoutParams .FLAG_FULLSCREEN ,
37+ WindowManager .LayoutParams .FLAG_FULLSCREEN );
38+ //设置为横屏模式
39+ //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
40+ setContentView (R .layout .main );
41+ mGLSurfaceView = new MySurfaceView (this );
42+
43+ //将自定义的SurfaceView添加到外层LinearLayout中
44+ LinearLayout ll =(LinearLayout )findViewById (R .id .main_liner );
45+ ll .addView (mGLSurfaceView );
46+ mGLSurfaceView .requestFocus ();//获取焦点
47+ mGLSurfaceView .setFocusableInTouchMode (true );//设置为可触控
48+ //获得单选按钮
49+ RadioButton RadioMan =(RadioButton )this .findViewById (R .id .RadioMan );
50+ RadioButton RadioWoman =(RadioButton )this .findViewById (R .id .RadioWoman );
51+ //获得ListView
52+ ls =(ListView )this .findViewById (R .id .listOrgan );
53+ //男Adapter
54+ ba =new BaseAdapter ()
55+ {
56+ @ Override
57+ public int getCount () {
58+ return organStr .length ;
59+ }
60+
61+ @ Override
62+ public Object getItem (int arg0 ) { return null ; }
63+
64+ @ Override
65+ public long getItemId (int arg0 ) { return 0 ; }
66+
67+ @ Override
68+ public View getView (int arg0 , View arg1 , ViewGroup arg2 ) {
69+ LinearLayout ll =new LinearLayout (MainActivity .this );
70+ ll .setOrientation (LinearLayout .VERTICAL );//设置朝向
71+ //初始化TextView
72+ TextView tv =new TextView (MainActivity .this );
73+ tv .setText (organStr [arg0 ]);
74+ tv .setTextSize (24 );//设置字体大小
75+ tv .setTextColor (MainActivity .this .getResources ().getColor (R .color .white ));//设置字体颜色
76+ tv .setGravity (Gravity .LEFT );//靠左
77+ ll .addView (tv );
78+ return ll ;
79+ }
80+ };
81+ //女Adapter
82+ baWoman =new BaseAdapter ()
83+ {
84+ @ Override
85+ public int getCount () {
86+ return womanorganStr .length ;
87+ }
88+
89+ @ Override
90+ public Object getItem (int arg0 ) { return null ; }
91+
92+ @ Override
93+ public long getItemId (int arg0 ) { return 0 ; }
94+
95+ @ Override
96+ public View getView (int arg0 , View arg1 , ViewGroup arg2 ) {
97+ LinearLayout ll =new LinearLayout (MainActivity .this );
98+ ll .setOrientation (LinearLayout .VERTICAL );//设置朝向
99+ //初始化TextView
100+ TextView tv =new TextView (MainActivity .this );
101+ tv .setText (womanorganStr [arg0 ]);
102+ tv .setTextSize (24 );//设置字体大小
103+ tv .setTextColor (MainActivity .this .getResources ().getColor (R .color .white ));//设置字体颜色
104+ tv .setGravity (Gravity .LEFT );//靠左
105+ ll .addView (tv );
106+ return ll ;
107+ }
108+ };
109+ //男单选按钮
110+ RadioMan .setOnClickListener (new View .OnClickListener () {
111+ @ Override
112+ public void onClick (View v ) {
113+ ls .setAdapter (ba );//设置男Adapter
114+ mGLSurfaceView .manOrWoman =true ;//更改性别标志位
115+ mGLSurfaceView .womanorganColor = MyFunction .initWomanColor ();//初始化女生颜色
116+ oldSelect =14 ;//初始化选择器官
117+ mGLSurfaceView .selectOrgan =14 ;//初始化选择器官
118+ }
119+ });
120+ //女单选按钮
121+ RadioWoman .setOnClickListener (new View .OnClickListener () {
122+ @ Override
123+ public void onClick (View v ) {
124+ ls .setAdapter (baWoman );//设置女Adapter
125+ mGLSurfaceView .manOrWoman =false ;//更改性别标志位
126+ mGLSurfaceView .tempmanOrganColor = MyFunction .initManColor ();//初始化男生颜色
127+ oldSelect =14 ;//初始化选择器官
128+ mGLSurfaceView .selectOrgan =14 ;//初始化选择器官
129+ }
130+ });
131+ //更改菜单界面的方法
132+ ls .setAdapter (ba );
133+ //设置选项被单击的监听器
134+ ls .setOnItemClickListener (
135+ new AdapterView .OnItemClickListener ()
136+ {
137+ @ Override
138+ public void onItemClick (AdapterView <?> arg0 , View arg1 , int arg2 ,
139+ long arg3 ) {//重写选项被单击事件的处理方法
140+ mGLSurfaceView .addOrDec =true ;//设置循环标志位
141+ if (oldSelect >=0 &&oldSelect <=13 )
142+ {
143+ mGLSurfaceView .tempbrightBreath [oldSelect ]=1.0f ;//将上一器官的呼吸系数初始化为1
144+ mGLSurfaceView .tempmanOrganColor [oldSelect ]=Constant .organColor [oldSelect ];//将原颜色给男器官
145+ mGLSurfaceView .womanorganColor [oldSelect ]=Constant .womanorganColor [oldSelect ];//将原颜色给女器官
146+ }
147+ setColor (arg2 );//上红色
148+ setSelectOrgan (arg2 );//更改选中器官
149+ oldSelect =arg2 ;//记录上一次选择的值
150+ }
151+ }
152+ );
153+ }
154+ //设置颜色
155+ public void setColor (int select )
156+ {
157+ if (mGLSurfaceView .manOrWoman ){
158+ mGLSurfaceView .tempmanOrganColor [select ]=colorRed ;
159+ }else
160+ {
161+ mGLSurfaceView .womanorganColor [select ]=colorRed ;
162+ }
163+
164+ }
165+ //设置选中器官
166+ public void setSelectOrgan (int select )
167+ {
168+ mGLSurfaceView .selectOrgan =select ;
169+ }
170+ @ Override
171+ protected void onResume () {
172+ super .onResume ();
173+ mGLSurfaceView .onResume ();
174+ }
175+ @ Override
176+ protected void onPause () {
177+ super .onPause ();
178+ mGLSurfaceView .onPause ();
179+ }
180+ }
0 commit comments