团队成员:陈淑筠、杨家安、陈曦
团队选题:小学四则运算APP
第一次冲刺阶段时间:11.17~11.27
本次发布我们增加了CalculatorsActivity.java、YunsuanActivity.java、ResultActivity.java这三个Activity,主要有MainActivity.java、TypesActivity.java、CalculatorActivity.java、CalculatorsActivity.java、YunsuanActivity.java、ResultActivity.java这六个Actvity,其中MainActivity.java:主界面,TypesActivity.java:按了主界面中的“进入”按钮后,跳到练习题类型选择“单题练习”或“多选择练习”,CalculatorActivity.java:是“单题练习“界面,CalculatorsActivity.java:是”多选择练习“的提供给用户的选择功能界面,YunsuanActivity.java:是”多选择练习“的按用户选择的功能的出题界面。
新增的代码和界面如下:
CalculatorsActivity.java:
package com.example.calculator; import android.os.Bundle; import android.app.ActionBar; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.RadioGroup.OnCheckedChangeListener; public class CalculatorsActivity extends Activity { private Button beginbtn; private RadioGroup choice; private int[] string=new int[]{1,2,3,4}; private EditText edweishu,editshu,timeminutes,timeseconds; @Override protected void onCreate(Bundle savedInstanceState) { ActionBar actionBar=getActionBar(); actionBar.setDisplayShowHomeEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true); super.onCreate(savedInstanceState); setContentView(R.layout.activity_calculators); beginbtn=(Button)findViewById(R.id.button1); final RadioGroup choice=(RadioGroup)findViewById(R.id.group); final int[] string=new int[]{1,2,3,4}; choice.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup arg0, int arg1) { // TODO Auto-generated method stub RadioButton r=(RadioButton)findViewById(arg1); r.getText(); } }); edweishu=(EditText)findViewById(R.id.editText1); editshu=(EditText)findViewById(R.id.editText2); timeminutes=(EditText)findViewById(R.id.editText3); timeseconds=(EditText)findViewById(R.id.editText4); //"开始"按钮的点击事件 beginbtn.setOnClickListener(new OnClickListener() { int send=0; @Override public void onClick(View arg0) { // TODO Auto-generated method stub for(int i=0;i<4;i++){ RadioButton r=(RadioButton)choice.getChildAt(i); if(r.isChecked()){ send=string[i]; break; } } String strweishu=edweishu.getText().toString(); String strtishu=editshu.getText().toString(); String strtimeminutes=timeminutes.getText().toString(); String strtimeseconds=timeseconds.getText().toString(); int intweishu=Integer.parseInt(strweishu); int inttishu=Integer.parseInt(strtishu); int inttimeminutes=Integer.parseInt(strtimeminutes); int inttimeseconds=Integer.parseInt(strtimeseconds); Intent intent=new Intent(CalculatorsActivity.this,YunsuanActivity.class); Bundle bundle=new Bundle(); bundle.putInt("suanfa", send); bundle.putInt("tishu", inttishu); bundle.putInt("weishu",intweishu); bundle.putInt("timeminutes", inttimeminutes); bundle.putInt("timeseconds", inttimeseconds); intent.putExtras(bundle); startActivity(intent); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.calculators, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // TODO Auto-generated method stub switch (item.getItemId()) { case android.R.id.home: //创建启动MainActivity的Intent Intent intent=new Intent(this,TypesActivity.class); //添加额外的Flag,将Activity栈中处于MainActivity之上的Activity弹出 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); break; default: break; } return super.onOptionsItemSelected(item); } }
activity_calculators.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:background="@drawable/animal" tools:context=".CalculatorsActivity" > <TableLayout android:layout_width="fill_parent" android:layout_height="fill_parent" > <TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content" android:layout_height="wrap_content" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="输入位数" /> <EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ems="5" android:inputType="number" > <requestFocus /> </EditText> </TableRow> <TableRow android:id="@+id/tableRow2" android:layout_width="wrap_content" android:layout_height="wrap_content" > <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="输入题数" /> <EditText android:id="@+id/editText2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ems="5" android:inputType="number" /> </TableRow> <TableRow android:id="@+id/tableRow3" android:layout_width="wrap_content" android:layout_height="wrap_content" > <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="输入时间" /> <EditText android:id="@+id/editText3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ems="3" android:inputType="number" /> <TextView android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="分" /> <EditText android:id="@+id/editText4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ems="3" android:inputType="number"/> <TextView android:id="@+id/textView5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="秒" /> </TableRow> <TableRow android:id="@+id/tableRow4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10dp" > <RadioGroup android:id="@+id/group" android:layout_width="wrap_content" android:layout_height="wrap_content" > <RadioButton android:id="@+id/radio0" android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true" android:text="@string/add" /> <RadioButton android:id="@+id/radio2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/radio0" android:layout_below="@+id/radio0" android:text="@string/jian" /> <RadioButton android:id="@+id/radio1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/cheng" /> <RadioButton android:id="@+id/radio3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/chu" /> </RadioGroup> </TableRow> <TableRow android:id="@+id/tableRow5" android:layout_width="wrap_content" android:layout_height="wrap_content" > </TableRow> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="开始" /> </TableLayout> </RelativeLayout>
运行界面:
YunsuanActivity.java:
package com.example.calculator; import android.os.Bundle; import android.os.SystemClock; import android.app.ActionBar; import android.app.Activity; import android.content.Intent; import android.text.InputType; import android.text.TextUtils; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Chronometer; import android.widget.Chronometer.OnChronometerTickListener; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.TextView; public class YunsuanActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { ActionBar actionBar=getActionBar(); actionBar.setDisplayShowHomeEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true); super.onCreate(savedInstanceState); setContentView(R.layout.activity_yunsuan); final LinearLayout ll=(LinearLayout)findViewById(R.id.yunsuan); Intent inten=getIntent(); Bundle bundle=inten.getExtras(); final int tishu=bundle.getInt("tishu"); int weishu=bundle.getInt("tishu"); int inttimeminutes=bundle.getInt("timeminutes"); int inttimeseconds=bundle.getInt("timeseconds"); final int suanfa=bundle.getInt("suanfa"); final EditText[] input=new EditText[tishu]; TextView[] showti=new TextView[tishu]; final int[] shu1=new int[tishu]; final int[] shu2=new int[tishu]; final int[] result=new int[tishu]; final String[] user=new String[tishu]; final Chronometer ch=new Chronometer(this); ch.setBase(SystemClock.elapsedRealtime()); ch.setFormat("已用时间,%s"); ch.start(); String show=""; String suan=""; ll.addView(ch); //题数设定 int setweishu=1; for(int i=0;i<weishu;i++){ setweishu*=10; } //加法 if(suanfa==1){ suan="+"; for(int i=0;i<tishu;i++){ show=""; int a=(int)(Math.random()*setweishu); int b=(int)(Math.random()*setweishu); shu1[i]=a; shu2[i]=b; result[i]=a+b; String sa=Integer.toString(a); String sb=Integer.toString(b); showti[i]=new TextView(this); show+=" "+sa+suan+sb+"="; showti[i].setText(show); input[i]=new EditText(this); input[i].setInputType(InputType.TYPE_CLASS_NUMBER); ll.addView(showti[i]); ll.addView(input[i]); } final Button finish=new Button(this); finish.setText("完成"); ll.addView(finish); //计时器时间到 final int timeover=inttimeminutes*60+inttimeseconds; ch.setOnChronometerTickListener(new OnChronometerTickListener() { @Override public void onChronometerTick(Chronometer arg0) { // TODO Auto-generated method stub if(SystemClock.elapsedRealtime()-ch.getBase()>=timeover*1000){ finish.callOnClick(); } } }); //点击“完成”按钮事件 finish.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub for(int i=0;i<user.length;i++){ if(TextUtils.isEmpty(input[i].getText())){ user[i]="null"; } else{ user[i]=input[i].getText().toString(); } } ch.stop(); String time=ch.getText().toString(); Intent intent=new Intent(YunsuanActivity.this,ResultActivity.class); Bundle bundle=new Bundle(); bundle.putIntArray("shu1", shu1); bundle.putIntArray("shu2", shu2); bundle.putStringArray("user", user); bundle.putInt("suanfa", suanfa); bundle.putIntArray("result", result); bundle.putString("time", time); intent.putExtras(bundle); startActivity(intent); } }); } //减法 if(suanfa==2){ suan="-"; for(int i=0;i<tishu;i++){ show=""; int a=(int)(Math.random()*setweishu); int b=(int)(Math.random()*setweishu); if(a<b){ int c=a;a=b;b=c; } shu1[i]=a; shu2[i]=b; result[i]=a-b; String sa=Integer.toString(a); String sb=Integer.toString(b); showti[i]=new TextView(this); show+=" "+sa+suan+sb+"="; showti[i].setText(show); input[i]=new EditText(this); input[i].setInputType(InputType.TYPE_CLASS_NUMBER); ll.addView(showti[i]); ll.addView(input[i]); } final Button finish=new Button(this); finish.setText("完成"); ll.addView(finish); final int timeover=inttimeminutes*60+inttimeseconds; ch.setOnChronometerTickListener(new OnChronometerTickListener() { @Override public void onChronometerTick(Chronometer arg0) { // TODO Auto-generated method stub if(SystemClock.elapsedRealtime()-ch.getBase()>=timeover*1000){ finish.callOnClick(); } } }); finish.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub for(int i=0;i<user.length;i++){ if(TextUtils.isEmpty(input[i].getText())){ user[i]="null"; } else{ user[i]=input[i].getText().toString(); } } ch.stop(); String time=ch.getText().toString(); Intent intent=new Intent(YunsuanActivity.this,ResultActivity.class); Bundle bundle=new Bundle(); bundle.putIntArray("shu1", shu1); bundle.putIntArray("shu2", shu2); bundle.putStringArray("user", user); bundle.putInt("suanfa", suanfa); bundle.putIntArray("result", result); bundle.putString("time", time); intent.putExtras(bundle); startActivity(intent); } }); } //乘法 if(suanfa==3){ suan="*"; for (int i=0;i<tishu;i++){ show=""; int a=(int)(Math.random() * setweishu); int b=(int)(Math.random() * setweishu); shu1[i]=a; shu2[i]=b; result[i]=a*b; String sa=Integer.toString(a); String sb=Integer.toString(b); showti[i]=new TextView(this); show+=" "+sa+suan+sb+"="; showti[i].setText(show); input[i]=new EditText(this); input[i].setInputType(InputType.TYPE_CLASS_NUMBER); ll.addView(showti[i]); ll.addView(input[i]); } final Button finish=new Button(this); finish.setText("完成"); ll.addView(finish); final int timeover=inttimeminutes*60+inttimeseconds; ch.setOnChronometerTickListener(new OnChronometerTickListener() { @Override public void onChronometerTick(Chronometer arg0) { // TODO Auto-generated method stub if(SystemClock.elapsedRealtime()-ch.getBase()>=timeover*1000){ finish.callOnClick(); } } }); finish.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub for(int i=0;i<user.length;i++){ if(TextUtils.isEmpty(input[i].getText())){ user[i]="null"; } else{ user[i]=input[i].getText().toString(); } } ch.stop(); String time=ch.getText().toString(); Intent intent=new Intent(YunsuanActivity.this,ResultActivity.class); Bundle bundle=new Bundle(); bundle.putIntArray("shu1", shu1); bundle.putIntArray("shu2", shu2); bundle.putStringArray("user", user); bundle.putInt("suanfa", suanfa); bundle.putIntArray("result", result); bundle.putString("time", time); intent.putExtras(bundle); startActivity(intent); } }); } //除法 if(suanfa==4){ suan="/"; for (int i=0;i<tishu;i++){ show=""; int a=(int)(Math.random() * setweishu); int b=(int)(Math.random() * setweishu); if(a<b){int c=a;a=b;b=c;} shu1[i]=a; shu2[i]=b; result[i]=a/b; String sa=Integer.toString(a); String sb=Integer.toString(b); showti[i]=new TextView(this); show+=" "+sa+suan+sb+"="; showti[i].setText(show); input[i]=new EditText(this); input[i].setInputType(InputType.TYPE_CLASS_NUMBER); ll.addView(showti[i]); ll.addView(input[i]); } final Button finish=new Button(this); finish.setText("完成"); ll.addView(finish); final int timeover=inttimeminutes*60+inttimeseconds; ch.setOnChronometerTickListener(new OnChronometerTickListener() { @Override public void onChronometerTick(Chronometer arg0) { // TODO Auto-generated method stub if(SystemClock.elapsedRealtime()-ch.getBase()>=timeover*1000){ finish.callOnClick(); } } }); finish.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub for(int i=0;i<user.length;i++){ if(TextUtils.isEmpty(input[i].getText())){ user[i]="null"; } else{ user[i]=input[i].getText().toString(); } } ch.stop(); String time=ch.getText().toString(); Intent intent=new Intent(YunsuanActivity.this,ResultActivity.class); Bundle bundle=new Bundle(); bundle.putIntArray("shu1", shu1); bundle.putIntArray("shu2", shu2); bundle.putStringArray("user", user); bundle.putInt("suanfa", suanfa); bundle.putIntArray("result", result); bundle.putString("time", time); intent.putExtras(bundle); startActivity(intent); } }); } } private void setContentView( android.widget.LinearLayout.LayoutParams layoutParams) { // TODO 自动生成的方法存根 } private void addContentView(TextView textView, android.widget.LinearLayout.LayoutParams[] p) { // TODO 自动生成的方法存根 } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.yunsuan, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // TODO Auto-generated method stub switch (item.getItemId()) { case android.R.id.home: //创建启动MainActivity的Intent Intent intent=new Intent(this,CalculatorsActivity.class); //添加额外的Flag,将Activity栈中处于MainActivity之上的Activity弹出 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); break; default: break; } return super.onOptionsItemSelected(item); } }
运行界面:
ResultActivity.java:
package com.example.calculator; import android.os.Bundle; import android.app.ActionBar; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.MenuItem; import android.widget.TextView; public class ResultActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { ActionBar actionBar=getActionBar(); actionBar.setDisplayShowHomeEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true); super.onCreate(savedInstanceState); setContentView(R.layout.activity_result); Intent inten=getIntent(); Bundle bundle=inten.getExtras(); TextView text=(TextView)findViewById(R.id.textresult); TextView text2=(TextView)findViewById(R.id.textView1); int[] shu1=inten.getIntArrayExtra("shu1"); int[] shu2=inten.getIntArrayExtra("shu2"); int[] result=inten.getIntArrayExtra("result"); int suanfa=bundle.getInt("suanfa"); String time=bundle.getString("time"); String showfa=""; if(suanfa==1){showfa="+";} if(suanfa==2){showfa="-";} if(suanfa==3){showfa="*";} if(suanfa==4){showfa="/";} String[] user=inten.getStringArrayExtra("user"); String aaa=""; int score=0; String show4; String[] jie=new String[]{"正确","错误"}; for (int i=0;i<shu1.length;i++){ String show1=""; String show2=""; String show3=""; show1=Integer.toString(shu1[i]); show2=Integer.toString(shu2[i]); show3=Integer.toString(result[i]); if(user[i].equals(show3)){show4=jie[0];score++;} else { show4=jie[1];} aaa+=show1+showfa+show2+"="+show3+" "+user[i]+" "+show4+" "; text.setText(aaa); } text2.setText(time+"总得分为"+score*10); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.result, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // TODO Auto-generated method stub switch (item.getItemId()) { case android.R.id.home: //创建启动MainActivity的Intent Intent intent=new Intent(this,CalculatorsActivity.class); //添加额外的Flag,将Activity栈中处于MainActivity之上的Activity弹出 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); break; default: break; } return super.onOptionsItemSelected(item); } }
activity_result.xml:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:background="@drawable/animal" android:scrollbars="vertical" tools:context=".ResultActivity" > <LinearLayout android:layout_width="fill_parent" android:layout_height="202dp" android:orientation="vertical" > <TextView android:id="@+id/texttitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="55dp" android:text=" 正确答案 你的答案 判断" /> <TextView android:id="@+id/textresult" android:layout_width="wrap_content" android:layout_height="match_parent" android:text="TextView" /> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" /> </LinearLayout> </ScrollView>
运行界面:
接下来,我们会继续完善APP,根据更多用户的需求去改变我们APP的功能,以获得更多用户的喜爱,得以推广。