基于Android的手机计步器的设计与实现+源代码
基于Android开发的智能健身跟踪器设计与实现

基于Android开发的智能健身跟踪器设计与实现智能健身跟踪器是一种结合了传感技术、数据分析和移动应用的智能设备,可以帮助用户记录运动数据、分析运动状态、制定健身计划等。
随着人们对健康生活的重视和智能设备的普及,智能健身跟踪器在市场上受到越来越多的关注和需求。
本文将介绍基于Android开发的智能健身跟踪器的设计与实现过程。
1. 智能健身跟踪器的功能需求分析在设计智能健身跟踪器之前,首先需要明确其功能需求。
一般而言,智能健身跟踪器应该具备以下功能:记录运动数据:包括步数、距离、卡路里消耗等。
分析运动状态:根据用户的运动数据,分析用户的运动状态,如跑步速度、心率等。
制定健身计划:根据用户的运动数据和目标,制定个性化的健身计划。
提供实时反馈:在运动过程中提供实时反馈,引导用户正确进行运动。
数据同步:将用户的运动数据同步到云端,方便用户随时查看和管理。
2. 技术选型与架构设计基于Android开发智能健身跟踪器,需要选择合适的技术和架构。
一般可以采用MVVM(Model-View-ViewModel)架构,使用Kotlin语言进行开发。
同时,可以利用Android Jetpack组件库提供的LiveData、ViewModel等组件来简化开发流程。
在技术选型方面,可以利用Android传感器API获取设备的加速度、陀螺仪等传感数据;使用Room数据库存储用户的运动数据;通过Retrofit库实现与后端服务器的数据交互;借助Google Fit API获取用户的健康数据等。
3. 功能模块设计与实现3.1 用户登录模块用户登录模块是智能健身跟踪器的入口,用户可以通过输入账号密码或第三方登录方式登录应用。
在登录成功后,可以同步用户的个人信息和历史运动数据。
3.2 运动数据记录模块运动数据记录模块负责记录用户的运动数据,包括步数、距离、卡路里消耗等。
可以通过Android传感器获取用户的步数和运动轨迹,并将数据存储到本地数据库中。
一个稳定好用的android计步器源代码

private int CountTimeState = 0;
public static int CURRENT_SETP = 0;
public static int TEMP_STEP = 0;
private int lastStep = -1;
float betweentime = System.currentTimeMillis()
- perCalTime;
if (betweentime >= minTime && betweentime < maxTime) {
return onSensorChangeListener;
}
public void setOnSensorChangeListener(
OnSensorChangeListener onSensorChangeListener) {
perCalTime = System.currentTimeMillis();
}
} else if (average >= vermaxValue) {
if (average >= maxValue) {
CountTimeState = 3;
} else if (CountTimeState == 3) {
CURRENT_SETP++;
}
}
};
timer.schedule(task, 0, 2000);
private final String TAG = "StepDcretor";
// alpha 由 t / (t + dT)计算得来,其中 t 是低通滤波器的时间常数,dT 是事件报送频率
基于Android的人体运动计步器系统的设计与实现[权威资料]
![基于Android的人体运动计步器系统的设计与实现[权威资料]](https://img.taocdn.com/s3/m/33ccdab2f5335a8103d220bd.png)
基于Android的人体运动计步器系统的设计与实现[权威资料]基于Android的人体运动计步器系统的设计与实现摘要:随着Android智能手机的进一步普及,针对Android智能手机内嵌的加速度传感器进行研究,利用人体行走过程中加速度传感器采集数据信息的变化规律,实现对行人脚步探测与计步系统。
该系统内容包括两部分:行人运动数据采集与预处理模块设计和行人脚步识别探测模块设计,能够有效的实现运动数据采集、预处理、步态探测和计步的功能。
关键词:Android;加速度传感器;步态探测TP393 A 1009-3044(2016)15-0094-04Abstract: With the further popularization of Android smartphones,aimed at the acceleration sensor embedded in the Android smartphone conduct a study , based on the changing law of the data information collected by the acceleration sensor during the walking process of human body to realize the pedestrian detection and measurement system. The system consist of two parts: data acquisition andpretreatment module design and pedestrian detection module design,it can effectively achieve the movement of data acquisition, pre-processing, gaitdetection and step counter function.Key words: Android; acceleration sensor;gait detection随着科技的发展,多功能智能设备的应用越来越受到人们的关注,智能手机作为人们工作生活中的必需品,不断地为人们带来快捷和方便。
从零开始学android实现计算器功能示例分享(计算器源码)

从零开始学android实现计算器功能⽰例分享(计算器源码)下⾯是效果展⽰:复制代码代码如下:<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical" ><LinearLayout android:layout_width="fill_parent"android:layout_height="wrap_content"><TextViewandroid:id="@+id/tvResult"android:layout_width="fill_parent"android:layout_height="wrap_content"android:height="50dp"android:text="@string/tvResult"/></LinearLayout><LinearLayout android:layout_width="fill_parent"android:layout_height="wrap_content"><Buttonandroid:id="@+id/btnBackspace"android:layout_width="wrap_content"android:layout_height="wrap_content"android:width="150dp"android:layout_marginLeft="10dp"android:text="@string/btnbackspace"/><Buttonandroid:id="@+id/btnCE"android:layout_width="wrap_content"android:layout_height="wrap_content"android:width="150dp"android:text="@string/btnCE"/></LinearLayout><LinearLayout android:layout_width="fill_parent"android:layout_height="wrap_content"><Buttonandroid:id="@+id/btn7"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="10dp"android:width="75dp"android:text="@string/btn7"/><Buttonandroid:id="@+id/btn8"android:layout_width="wrap_content"android:layout_height="wrap_content"android:width="75dp"android:text="@string/btn8"/><Buttonandroid:id="@+id/btnDiv"android:layout_width="wrap_content"android:layout_height="wrap_content"android:width="75dp"android:text="@string/btnDiv"/></LinearLayout><LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content"><Buttonandroid:id="@+id/btn4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="10dp"android:width="75dp"android:text="@string/btn4"/><Buttonandroid:id="@+id/btn5"android:layout_width="wrap_content"android:layout_height="wrap_content"android:width="75dp"android:text="@string/btn5"/><Buttonandroid:id="@+id/btn6"android:layout_width="wrap_content"android:layout_height="wrap_content"android:width="75dp"android:text="@string/btn6"/><Buttonandroid:id="@+id/btnMul"android:layout_width="wrap_content"android:layout_height="wrap_content"android:width="75dp"android:text="@string/btnMul"/></LinearLayout><LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content"><Buttonandroid:id="@+id/btn1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="10dp"android:width="75dp"android:text="@string/btn1"/><Buttonandroid:id="@+id/btn2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:width="75dp"android:text="@string/btn2"/><Buttonandroid:id="@+id/btn3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:width="75dp"android:text="@string/btn3"/></LinearLayout><LinearLayout android:layout_width="fill_parent"android:layout_height="wrap_content"><Buttonandroid:id="@+id/btn0"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="10dp"android:width="75dp"android:text="@string/btn0"/><Buttonandroid:id="@+id/btnC"android:layout_width="wrap_content"android:layout_height="wrap_content"android:width="75dp"android:text="@string/btnC"/><Buttonandroid:id="@+id/btnEqu"android:layout_width="wrap_content"android:layout_height="wrap_content"android:width="75dp"android:text="@string/btnEqu"/><Buttonandroid:id="@+id/btnSub"android:layout_width="wrap_content"android:layout_height="wrap_content"android:width="75dp"android:text="@string/btnSub"/></LinearLayout></LinearLayout>复制代码代码如下:package com.example.week2;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.TextView;import android.app.Activity;public class MainActivity extends Activity implements OnClickListener{ //声明⼀些控件Button btn0=null;Button btn1=null;Button btn2=null;Button btn3=null;Button btn4=null;Button btn5=null;Button btn6=null;Button btn7=null;Button btn8=null;Button btn9=null;Button btnBackspace=null;Button btnCE=null;Button btnMul=null;Button btnDiv=null;Button btnEqu=null;TextView tvResult=null;//声明两个参数。
Android计算器源码

计算器源码Java程序代码:package ymq.demo03;import android.app.Activity;import android.os.Bundle;import android.view.*;import android.widget.*;public class demo03 extends Activity {/** Called when the activity is first created. */String str="";EditText et;int c=0,flag=0;double b=0.0,g=0.0,f=0.0;View vi;public boolean onCreateOptionsMenu(Menu menu) { // TODO Auto-generated method stubmenu.add(0, 1, 1, "退出");return super.onCreateOptionsMenu(menu);}@Overridepublic boolean onOptionsItemSelected(MenuItem item) { // TODO Auto-generated method stubif(item.getItemId()==1){finish();}return super.onOptionsItemSelected(item);}//计算方法public double calculater(){switch(c){case 0:f=g;break;case 1:f=b+g;break;case 2:f=b-g;break;case 3:f=b*g;break;case 4:f=b/g;break;}b=f;return f;}@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(yout.main);//获得按键final Button number[]=new Button[10];final Button fuhao[]=new Button[11];fuhao[0]=(Button)findViewById(R.id.button01);fuhao[1]=(Button)findViewById(R.id.button02);fuhao[2]=(Button)findViewById(R.id.button03);fuhao[3]=(Button)findViewById(R.id.button04);fuhao[4]=(Button)findViewById(R.id.button05);fuhao[5]=(Button)findViewById(R.id.button06);fuhao[6]=(Button)findViewById(R.id.buttonce);fuhao[7]=(Button)findViewById(R.id.buttonc);fuhao[8]=(Button)findViewById(R.id.zheng);fuhao[9]=(Button)findViewById(R.id.kaifang);fuhao[10]=(Button)findViewById(R.id.pingfang);number[0]=(Button)findViewById(R.id.button0);number[1]=(Button)findViewById(R.id.button1);number[2]=(Button)findViewById(R.id.button2);number[3]=(Button)findViewById(R.id.button3);number[4]=(Button)findViewById(R.id.button4);number[5]=(Button)findViewById(R.id.button5);number[6]=(Button)findViewById(R.id.button6);number[7]=(Button)findViewById(R.id.button7);number[8]=(Button)findViewById(R.id.button8);number[9]=(Button)findViewById(R.id.button9);et=(EditText) findViewById(R.id.textView1);et.setText(str);fuhao[6].setOnClickListener(new View.OnClickListener() {public void onClick(View v) {// TODO Auto-generated method stubstr="";et.setText(str);vi=v;}});fuhao[7].setOnClickListener(new View.OnClickListener() {public void onClick(View v) {// TODO Auto-generated method stubb=0.0;c=0;g=0.0;str="";et.setText(str);}});fuhao[8].setOnClickListener(new View.OnClickListener() {public void onClick(View v) {// TODO Auto-generated method stubif(vi!=fuhao[5]&&str!=""){char ch=str.charAt(0);if(ch=='-')str=str.replace("-","");elsestr="-"+str;et.setText(str);}}});fuhao[9].setOnClickListener(new View.OnClickListener() {public void onClick(View v) {// TODO Auto-generated method stubif(str!=""){double a=Double.parseDouble(str);str=Math.sqrt(a)+"";et.setText(str);});fuhao[10].setOnClickListener(new View.OnClickListener() {public void onClick(View v) {// TODO Auto-generated method stubif(str!=""){double a=Double.parseDouble(str);str=""+a*a;et.setText(str);}}});//设定数字按键number[0].setOnClickListener(new View.OnClickListener() {public void onClick(View v) {// TODO Auto-generated method stubif(flag==1){str="";str+=0;et.setText(str);flag=0;}else{char ch1[];ch1=str.toCharArray();if(!(ch1.length==1&&ch1[0]=='0')){str+=0;et.setText(str);}}vi=v;}});number[1].setOnClickListener(new View.OnClickListener() {public void onClick(View v) {// TODO Auto-generated method stubif(flag==1){str="";str+=1;et.setText(str);flag=0;}else{str+=1;et.setText(str);}vi=v;}});number[2].setOnClickListener(new View.OnClickListener() {public void onClick(View v) {// TODO Auto-generated method stubif(flag==1){str="";str+=2;et.setText(str);flag=0;}else{str+=2;et.setText(str);}vi=v;}});number[3].setOnClickListener(new View.OnClickListener() {public void onClick(View v) {// TODO Auto-generated method stubif(flag==1){str="";str+=3;et.setText(str);flag=0;}else{str+=3;et.setText(str);}vi=v;}});number[4].setOnClickListener(new View.OnClickListener() {public void onClick(View v) {// TODO Auto-generated method stubif(flag==1){str="";str+=4;et.setText(str);flag=0;}else{str+=4;et.setText(str);}vi=v;}});number[5].setOnClickListener(new View.OnClickListener() {public void onClick(View v) {// TODO Auto-generated method stubif(flag==1){str="";str+=5;et.setText(str);flag=0;}else{str+=5;et.setText(str);}vi=v;}});number[6].setOnClickListener(new View.OnClickListener() {public void onClick(View v) {// TODO Auto-generated method stubif(flag==1){str="";str+=6;et.setText(str);flag=0;}else{str+=6;et.setText(str);}vi=v;}});number[7].setOnClickListener(new View.OnClickListener() {public void onClick(View v) {// TODO Auto-generated method stubif(flag==1){str="";str+=7;et.setText(str);flag=0;}else{str+=7;et.setText(str);}vi=v;}});number[8].setOnClickListener(new View.OnClickListener() {public void onClick(View v) {// TODO Auto-generated method stubif(flag==1){str="";str+=8;et.setText(str);flag=0;}else{str+=8;et.setText(str);}vi=v;}});number[9].setOnClickListener(new View.OnClickListener() {public void onClick(View v) {// TODO Auto-generated method stubif(flag==1){str="";str+=9;et.setText(str);flag=0;}else{str+=9;et.setText(str);}vi=v;}});//设定符号键//加fuhao[0].setOnClickListener(new View.OnClickListener() {public void onClick(View v) {// TODO Auto-generated method stubif(str!=""){if(vi==fuhao[0]||vi==fuhao[1]||vi==fuhao[2]||vi==fuhao[3]){c=1;}else{g=Double.parseDouble(str);calculater();str=""+f;et.setText(str);c=1;flag=1;}}}});//减fuhao[1].setOnClickListener(new View.OnClickListener() {public void onClick(View v) {// TODO Auto-generated method stubif(str!=""){if(vi==fuhao[0]||vi==fuhao[1]||vi==fuhao[2]||vi==fuhao[3]){c=2;}else{g=Double.parseDouble(str);calculater();str=""+f;et.setText(str);c=2;flag=1;vi=v;}}}});//乘fuhao[2].setOnClickListener(new View.OnClickListener() {public void onClick(View v) {// TODO Auto-generated method stubif(str!=""){if(vi==fuhao[0]||vi==fuhao[1]||vi==fuhao[2]||vi==fuhao[3]){c=3;}else{g=Double.parseDouble(str);calculater();str=""+f;et.setText(str);flag=1;vi=v;}}}});//除fuhao[3].setOnClickListener(new View.OnClickListener() {public void onClick(View v) {// TODO Auto-generated method stubif(str!=""){if(vi==fuhao[0]||vi==fuhao[1]||vi==fuhao[2]||vi==fuhao[3]){c=4;}else{g=Double.parseDouble(str);calculater();str=""+f;et.setText(str);c=4;flag=1;vi=v;}}}});//等号fuhao[4].setOnClickListener(new View.OnClickListener() {public void onClick(View v) {// TODO Auto-generated method stubif(str!=""&&vi!=fuhao[0]&&vi!=fuhao[1]&&vi!=fuhao[2]&&vi!=fuhao[3 ]){g=Double.parseDouble(str);calculater();str=""+f;et.setText(str);flag=1;vi=v;}}});//小数点fuhao[5].setOnClickListener(new View.OnClickListener() {public void onClick(View v) {// TODO Auto-generated method stubif(str==""){str+=".";et.setText(str);}else{char ch1[];int x=0;ch1=str.toCharArray();for(int i=0;i<ch1.length;i++)if(ch1[i]=='.')x++;if(x==0){str+=".";et.setText(str);}}}});}}布局文件:main.xml<?xml version="1.0"encoding="utf-8"?><LinearLayoutandroid:background="#ff808080"xmlns:android="/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical"android:layout_gravity="center_vertical"android:id="@+id/zhengfu"><EditTextandroid:text="TextView"android:id="@+id/textView1"android:textSize="25sp"android:textColor="#000000"android:layout_gravity="center"android:gravity="left"android:cursorVisible="false"android:editable = "false"android:layout_height="wrap_content"android:layout_width="fill_parent"android:layout_marginLeft="4dip"android:layout_marginRight="4dip"android:layout_marginTop="4dip"android:layout_weight="1.5"></EditText><TableLayoutandroid:id="@+id/tablelayout"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_margin="4dip"android:layout_weight="10"><LinearLayoutandroid:id="@+id/linearlayout02"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_weight="1"><Buttonandroid:layout_width="50dip"android:layout_height="fill_parent"android:layout_weight="1"android:textSize="25sp"android:id="@+id/buttonc"android:text="@string/shan"></Button><Buttonandroid:layout_width="50dip"android:layout_height="fill_parent"android:layout_weight="1"android:textSize="25sp"android:id="@+id/buttonce" android:text="@string/shanchu"></Button></LinearLayout><TableRowandroid:id="@+id/row0"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_weight="1"><Buttonandroid:layout_width="40dip"android:layout_height="fill_parent"android:layout_weight="1"android:textSize="25sp"android:text="@string/one" android:id="@+id/button1"></Button><Buttonandroid:layout_width="40dip"android:layout_height="fill_parent"android:layout_weight="1"android:textSize="25sp"android:text="@string/two" android:id="@+id/button2"></Button><Buttonandroid:layout_width="40dip"android:layout_height="fill_parent"android:layout_weight="1"android:textSize="25sp"android:text="@string/three" android:id="@+id/button3"></Button><Buttonandroid:layout_width="40dip"android:layout_height="fill_parent"android:layout_weight="1"android:textSize="25sp"android:text="@string/jia" android:id="@+id/button01"></Button></TableRow><TableRowandroid:id="@+id/row1"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_weight="1"><Buttonandroid:layout_width="40dip"android:layout_height="fill_parent"android:layout_weight="1"android:textSize="25sp"android:text="@string/fore" android:id="@+id/button4"></Button><Buttonandroid:layout_width="40dip"android:layout_height="fill_parent"android:layout_weight="1"android:textSize="25sp"android:text="@string/five" android:id="@+id/button5"></Button><Buttonandroid:layout_width="40dip"android:layout_height="fill_parent"android:layout_weight="1"android:textSize="25sp"android:text="@string/six" android:id="@+id/button6"></Button><Buttonandroid:layout_width="40dip"android:layout_height="fill_parent"android:layout_weight="1"android:textSize="25sp"android:text="@string/jian" android:id="@+id/button02"></Button></TableRow><TableRowandroid:id="@+id/row2"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_weight="1"><Buttonandroid:layout_width="40dip"android:layout_height="fill_parent"android:layout_weight="1"android:textSize="25sp"android:text="@string/seven" android:id="@+id/button7"></Button><Buttonandroid:layout_width="40dip"android:layout_height="fill_parent"android:layout_weight="1"android:textSize="25sp"android:text="@string/eight" android:id="@+id/button8"></Button><Buttonandroid:layout_width="40dip"android:layout_height="fill_parent"android:layout_weight="1"android:textSize="25sp"android:text="@string/nine" android:id="@+id/button9"></Button><Buttonandroid:layout_width="40dip"android:layout_height="fill_parent"android:layout_weight="1"android:textSize="25sp"android:text="@string/cheng" android:id="@+id/button03"></Button></TableRow><TableRowandroid:id="@+id/row3"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_weight="1"><Buttonandroid:layout_width="40dip"android:layout_height="fill_parent"android:layout_weight="1"android:textSize="25sp"android:text="@string/zero" android:id="@+id/button0"></Button><Buttonandroid:layout_width="40dip"android:layout_height="fill_parent"android:layout_weight="1"android:textSize="25sp"android:id="@+id/button06" android:text="@string/dihao"></Button><Buttonandroid:layout_width="40dip"android:layout_height="fill_parent"android:layout_weight="1"android:textSize="25sp"android:text="@string/dengyu" android:id="@+id/button05"></Button><Buttonandroid:layout_width="40dip"android:layout_height="fill_parent"android:layout_weight="1"android:textSize="25sp"android:text="@string/chu" android:id="@+id/button04"></Button></TableRow><LinearLayoutandroid:id="@+id/tableRow1"android:layout_width="fill_parent"android:layout_height="wrap_content"android:orientation="horizontal"android:layout_weight="1"><Buttonandroid:textSize="25sp"android:layout_height="fill_parent"android:layout_width="50dp"android:layout_weight="1" android:text="@string/zhengfu"android:id="@+id/zheng"></Button><Buttonandroid:id="@+id/pingfang"android:textSize="25sp"android:layout_height="fill_parent"android:layout_width="50dp"android:layout_weight="1" android:text="@string/ping"></Button><Buttonandroid:id="@+id/kaifang"android:textSize="25sp"android:layout_height="fill_parent"android:layout_width="50dp"android:layout_weight="1" android:text="@string/kai"></Button></LinearLayout></TableLayout></LinearLayout>主配置文件:<?xml version="1.0"encoding="utf-8"?><manifest xmlns:android="/apk/res/android"package="ymq.demo03"android:versionCode="1"android:versionName="1.0"><uses-sdk android:minSdkVersion="7"/><application android:icon="@drawable/icon"android:label="@string/app_name"><activity android:name=".demo03"android:label="@string/app_name"><intent-filter><action android:name="android.intent.action.MAIN"/><categoryandroid:name="UNCHER"/></intent-filter></activity></application></manifest>。
基于Android的手机计步器的设计与实现+源代码

专业工程综合实训设计报告目录第一章绪论 (1)1.1课题的背景及意义 (1)1.2系统框架 (1)第二章系统分析 (3)2.1 系统可行性分析 (3)2.1.1 功能可行性分析 (3)2.1.2 运行环境可行性分析 (3)2.2 开发环境简介 (3)2.2.1 Java Development kit(JDK)介绍 (3)2.2.2 Android SDK 介绍 (3)2.2.3 Eclipse开发工具介绍 (4)2.2.4 Android Development Tools(ADT)介绍 (4)第三章 Android开发常用到的技术及环境搭建 (5)3.1 Android开发常用到的技术 (5)3.1.1 Activity (5)3.1.2 Service (6)3.1.3 Content Provider 内容提供者 (7)3.1.4 Intent 信使 (7)3.2环境搭建 (7)3.2.1安装JDK (7)3.2.2安装Eclipse (8)3.2.3 Android SDK安装 (8)3.2.4 ADT安装 (8)第四章手机计步器的设计与实现 (9)4.1计步器功能的设计 (9)4.2计步器功能的实现 (11)4.2.1 计步开始及暂停 (11)4.2.2 复位键 (12)4.2.3设置步长 (12)4.2.4设置体重 (12)4.2.5历史记录的查看及删除 (13)第五章计步器的界面效果 (19)5.1用户界面 (19)5.2设置界面 (20)5.3历史界面 (22)5.4日历选择界面 (23)5.5用户离开界面 (24)第六章系统测试与分析 (25)6.1 测试过程 (25)6.2 测试分析 (38)结论 (39)参考文献 (40)第一章绪论1.1课题的背景及意义当今社会,手机已经成为人们工作生活中必不可少的一项通讯和娱乐工具,随着手机的不断更新,手机的各种高层服务和应用层出不穷。
安卓开发的自制计算器源代码

这是本人自己用安卓编写的计算器,代码的优化可能有所问题,不过大家都在学习阶段,欢迎大家批评指正,还是上源码吧。
先来运行图package com.example.nanchen.exam_1_1;import android.content.DialogInterface;import android.support.v7.app.AlertDialog;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.TextView;public class MainActivity extends AppCompatActivity implements View.OnClickListener{private Button btn0;private Button btn1;private Button btn2;private Button btn3;private Button btn4;private Button btn5;private Button btn6;private Button btn7;private Button btn8;private Button btn9;private Button btnAdd;private Button btnSub;private Button btnMul;private Button btnDiv;private Button btnDec;private Button btnEqual;private Button btnClear;private Button btnBackSpace;private TextView textView_result;double num1 = 0,num2 = 0,result = 0;//定义存储结果和两个操作数boolean isCheckEqu = false;//检测是否点击了等于int op = 0;//定义运算符boolean hasDec = false;boolean hasOp = false;@Overrideprotected void onCreate Bundle savedInstanceStatesuper.onCreate savedInstanceState;setContentView yout.activity_main;textView_result = TextView findViewById R.id.result;btn0 = Button findViewById R.id.btn0;btn1 = Button findViewById R.id.btn1;btn2 = Button findViewById R.id.btn2;btn3 = Button findViewById R.id.btn3;btn4 = Button findViewById R.id.btn4;btn5 = Button findViewById R.id.btn5;btn6 = Button findViewById R.id.btn6;btn7 = Button findViewById R.id.btn7;btn8 = Button findViewById R.id.btn8;btn9 = Button findViewById R.id.btn9;btnAdd = Button findViewById R.id.btn10;btnSub = Button findViewById R.id.btn11;btnMul = Button findViewById R.id.btn12;btnDiv = Button findViewById R.id.btn13;btnDec = Button findViewById R.id.btn14;btnEqual = Button findViewById R.id.btn15;btnClear = Button findViewById R.id.clear;btnBackSpace = Button findViewById R.id.backSpace;btn0.setOnClickListener this;btn1.setOnClickListener this;btn2.setOnClickListener this;btn3.setOnClickListener this;btn4.setOnClickListener this;btn5.setOnClickListener this;btn6.setOnClickListener this;btn7.setOnClickListener this;btn8.setOnClickListener this;btn9.setOnClickListener this;btnAdd.setOnClickListener this;btnSub.setOnClickListener this;btnDec.setOnClickListener this;btnDiv.setOnClickListener this;btnEqual.setOnClickListener this;btnMul.setOnClickListener this;btnClear.setOnClickListener this;btnBackSpace.setOnClickListener this;@Overridepublic void onClick View vswitch v.getIdcase R.id.btn0:if isCheckEqutextView_result.setText null;isCheckEqu=false;String myString0 =textView_result.getText.toString;if myString0.equals"0"myString0 = "";myString0 += "0";textView_result.setText myString0;break;case R.id.btn1:if isCheckEqutextView_result.setText null;isCheckEqu=false;String myString1 =textView_result.getText.toString;if myString1.equals"0"myString1 = "";myString1 += "1";textView_result.setText myString1;break;case R.id.btn2:if isCheckEqutextView_result.setText null;isCheckEqu=false;String myString2 =textView_result.getText.toString;if myString2.equals"0"myString2 = "";myString2 += "2";textView_result.setText myString2;break;case R.id.btn3:if isCheckEqutextView_result.setText null;isCheckEqu=false;String myString3 =textView_result.getText.toString;if myString3.equals"0"myString3 = "";myString3 += "3";textView_result.setText myString3;break;case R.id.btn4:if isCheckEqutextView_result.setText null;isCheckEqu=false;String myString4 =textView_result.getText.toString;if myString4.equals"0"myString4 = "";myString4 += "4";textView_result.setText myString4;break;case R.id.btn5:if isCheckEqutextView_result.setText null;isCheckEqu=false;String myString5 =textView_result.getText.toString;if myString5.equals"0"myString5 = "";myString5 += "5";textView_result.setText myString5;break;case R.id.btn6:if isCheckEqutextView_result.setText null;isCheckEqu=false;String myString6 =textView_result.getText.toString;if myString6.equals"0"myString6 = "";myString6 += "6";textView_result.setText myString6;break;case R.id.btn7:if isCheckEqutextView_result.setText null;isCheckEqu=false;String myString7 =textView_result.getText.toString;if myString7.equals"0"myString7 = "";myString7 += "7";textView_result.setText myString7;break;case R.id.btn8:if isCheckEqutextView_result.setText null;isCheckEqu=false;String myString8 =textView_result.getText.toString;if myString8.equals"0"myString8 = "";myString8 += "8";textView_result.setText myString8;break;case R.id.btn9:if isCheckEqutextView_result.setText null;isCheckEqu=false;String myString9 =textView_result.getText.toString;if myString9.equals"0"myString9 = "";myString9 += "9";textView_result.setText myString9;break;case R.id.btn10:if hasOpdoEqual;//显示出来当前的答案String myStringAdd =textView_result.getText.toString;if myStringAdd.equals nullreturn;num1 = Double.valueOf myStringAdd;textView_result.setText null;// 这里被清除了op = 1;isCheckEqu = false;hasDec = false;hasOp = true;break;case R.id.btn11:if hasOpdoEqual;String myStringSub =textView_result.getText.toString;if myStringSub.equals nullreturn;num1 = Double.valueOf myStringSub;textView_result.setText null;op = 2;isCheckEqu = false;hasDec = false;hasOp = true;break;case R.id.btn12:if hasOpdoEqual;String myStringMul =textView_result.getText.toString;if myStringMul.equals nullreturn;num1 = Double.valueOf myStringMul;textView_result.setText null;op = 3;isCheckEqu = false;hasDec = false;hasOp = true;break;case R.id.btn13:if hasOpdoEqual;String myStringDiv =textView_result.getText.toString;if myStringDiv.equals nullreturn;num1 = Double.valueOf myStringDiv;textView_result.setText null;op = 4;hasDec = false;isCheckEqu = false;hasOp = true;break;case R.id.btn14:if isCheckEqutextView_result.setText null;isCheckEqu=false;if hasDec//如果已经有小数点了,则弹出一个对话框AlertDialog.Builder builder = new AlertDialog.Builder MainActivity.this;builder.setTitle"警告";builder.setMessage"输入错误,一个数字不能有两个小数点!";builder.setNegativeButton"取消", new DialogInterface.OnClickListener@Overridepublic void onClick DialogInterface dialog, int which;builder.show;return;hasDec = true;String myString14 =textView_result.getText.toString;myString14 += ".";textView_result.setText myString14;break;case R.id.btn15:doEqual;hasOp = false;break;case R.id.backSpace:String myString =textView_result.getText.toString;trytextView_result.setText myString.substring0,myString.length -1;catch Exception etextView_result.setText"0";break;case R.id.clear:textView_result.setText"0";break;default:break;/*** 按下等于*/private void doEqualStringmyStringEqu=textView_result.getText.toString;if myStringEqu.equals nullreturn;num2=Double.valueOf myStringEqu;textView_result.setText null;switch opcase 0:result=num2;break;case 1:result=num1+num2;break;case 2:result=num1-num2;break;case 3:result=num1*num2;break;case 4:result=num1/num2;break;default:result=0;break;textView_result.setText String.valueOf result;isCheckEqu=true;<?xml version="1.0" encoding="utf-8"?>LinearLayoutxmlns:android="/apk/res/android"xmlns:tools="/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"tools:context="com.example.nanchen.exam_1_1.MainActivity"<!--显示结果-->LinearLayoutandroid:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"TextViewandroid:layout_width="match_parent"android:layout_height="match_parent"android:id="@+id/result"android:gravity="end"android:textSize="40sp"android:text="@string/zero"LinearLayoutLinearLayoutandroid:layout_width="match_parent"android:layout_height="0dp"android:orientation="horizontal"android:layout_weight="1"Buttonandroid:layout_width="0dp"android:layout_weight="1"android:layout_height="wrap_content"android:text="@string/clear"android:id="@+id/clear"android:textAllCaps="false"android:gravity="center"android:textSize="25sp"Buttonandroid:layout_width="0dp"android:layout_weight="1"android:layout_height="wrap_content"android:text="@string/backspace"android:id="@+id/backSpace"android:textAllCaps="false"android:gravity="center"android:textSize="25sp" LinearLayout<!--789/-->LinearLayoutandroid:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"Buttonandroid:layout_width="0dp"android:text="@string/seven"android:id="@+id/btn7"android:textSize="30sp"android:gravity="center"android:layout_height="wrap_content"android:layout_weight="1"Buttonandroid:layout_width="0dp"android:text="@string/eight"android:id="@+id/btn8"android:textSize="30sp"android:gravity="center"android:layout_height="wrap_content"android:layout_weight="1"Buttonandroid:layout_width="0dp"android:text="@string/nine"android:id="@+id/btn9"android:textSize="30sp"android:gravity="center"android:layout_height="wrap_content"android:layout_weight="1"Buttonandroid:layout_width="0dp"android:text="@string/del"android:id="@+id/btn13"android:textSize="30sp"android:gravity="center"android:layout_height="wrap_content"android:layout_weight="1" LinearLayout<!--456*-->LinearLayoutandroid:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"Buttonandroid:layout_width="0dp"android:text="@string/four"android:id="@+id/btn4"android:textSize="30sp"android:gravity="center"android:layout_height="wrap_content"android:layout_weight="1"Buttonandroid:layout_width="0dp"android:text="@string/five"android:id="@+id/btn5"android:textSize="30sp"android:gravity="center"android:layout_height="wrap_content"android:layout_weight="1"Buttonandroid:layout_width="0dp"android:text="@string/six"android:id="@+id/btn6"android:textSize="30sp"android:gravity="center"android:layout_height="wrap_content"android:layout_weight="1"Buttonandroid:layout_width="0dp"android:text="@string/mul"android:id="@+id/btn12"android:textSize="30sp"android:gravity="center"android:layout_height="wrap_content"android:layout_weight="1" LinearLayout<!--123- -->LinearLayoutandroid:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"Buttonandroid:layout_width="0dp"android:text="@string/one"android:textSize="30sp"android:id="@+id/btn1"android:gravity="center"android:layout_height="wrap_content"android:layout_weight="1"Buttonandroid:layout_width="0dp"android:text="@string/two"android:id="@+id/btn2"android:textSize="30sp"android:gravity="center"android:layout_height="wrap_content"android:layout_weight="1"Buttonandroid:layout_width="0dp"android:text="@string/three"android:id="@+id/btn3"android:textSize="30sp"android:gravity="center"android:layout_height="wrap_content"android:layout_weight="1"Buttonandroid:layout_width="0dp"android:text="@string/sub"android:id="@+id/btn11"android:textSize="30sp"android:gravity="center"android:layout_height="wrap_content"android:layout_weight="1" LinearLayout<!--0.=+-->LinearLayoutandroid:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"Buttonandroid:layout_width="0dp"android:text="@string/zero1"android:id="@+id/btn0"android:textSize="30sp"android:gravity="center"android:layout_height="wrap_content"android:layout_weight="1"Buttonandroid:layout_width="0dp"android:text="@string/dec"android:id="@+id/btn14"android:textSize="30sp"android:gravity="center"android:layout_height="wrap_content"android:layout_weight="1"Buttonandroid:layout_width="0dp"android:text="@string/equal"android:id="@+id/btn15"android:textSize="30sp"android:gravity="center"android:layout_height="wrap_content"android:layout_weight="1"Buttonandroid:layout_width="0dp"android:text="@string/add"android:id="@+id/btn10"android:textSize="30sp"android:gravity="center"android:layout_height="wrap_content"android:layout_weight="1"LinearLayoutLinearLayoutandroid:layout_weight="4"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="0dp"TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:textSize="20sp"android:text="@string/string1"TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/string2"android:textSize="20sp"LinearLayoutLinearLayout。
基于Android平台的计步器的设计与实现-软件工程毕业论文

南阳理工学院本科生毕业设计(论文)学院(系):软件学院专业:软件工程学生:张三指导教师:张三完成日期 2016 年 04 月南阳理工学院本科生毕业设计(论文)基于Android平台的爱运动计步器的设计与实现Design and Implementation of the Loving Sports Pedometer Based on Android Platform总计:毕业设计(论文) 33页表格:1个图片:1个南阳理工学院本科毕业设计(论文)基于Android平台的爱运动计步器的设计与实现Design and Implementation of the Loving Sports Pedometer Based on Android Platform学院(系):软件学院专业:软件工程学生姓名:张三学号: 111指导教师(职称):张三讲师评阅教师:张三完成日期: 2016年04月30日南阳理工学院Nanyang Institute of Technology基于Android平台的爱运动计步器的设计与实现软件工程张三[摘要]随着人们生活水平和生活质量的提高,人们越来越关注自己的身体健康。
而跑步成为人们最受欢迎的运动方式,运动软件可以在人们锻炼身体的时候提供极大的帮助。
本文针对运动轨迹和计步,设计一款基于Android平台的运动软件。
本系统通过使用百度鹰眼、重力传感器和数据库技术,实现了运动轨迹追踪、计步、查看运动记录等功能。
本系统界面友好,操作简单,可以稳定运行。
本款运动软件适合空闲时间不足的人群,方便人们随时锻炼身体,并查看自己的运动情况。
[关键词]运动软件;运动轨迹;Android;百度鹰眼Design and Implementation of the Loving SportsPedometer Based on Android PlatformSoftware Engineering Major zhangsanAbstract:With the improvement of people's living standards and quality of life, people pay more and more attention to their health.Running has become one of the most popular ways of exercise,and sports software can provide great convenience for the people to exercise.The thesis designs a sports software based on Android platform for the sports trace and the step counting. The system uses baidu hawkeye, gravity sensors and database technology realizing the trajectory tracking,step counting,viewing athletic records and other functions.The system provides a friendly user interface,simple operation and can be stable operation.The sports software is suitable for people having less time and it is also convenient for people to exercise at any time and viewing athletic records.Key words:s ports software;sports trace; Android;baidu hawkeye目录1绪论11.1软件开发背景11.2论文研究的目的和意义11.3论文主要研究内容11.4论文组织结构12相关技术介绍22.1 Android系统的组成22.1.1应用程序层22.1.2应用程序框架层22.1.3系统运行库层22.1.4 Linux内核层32.2 Activity的生命周期32.3 Android平台的搭建42.3.1 JDK的安装42.3.2 Eclipse的安装52.3.3 Android SDK 的安装52.3.4 ADT的安装52.3.5创建DVD53需求分析53.1可行性分析63.1.1经济可行性分析63.1.2技术可行性分析63.1.3操作可行分析63.2功能需求分析63.3非功能性需求分析73.3.1易用性73.3.2可靠性83.3.3安全性83.3.4运行环境83.4面向对象分析83.4.1设置信息用例分析83.4.2运动记录用例分析83.4.3计步信息用例分析93.4.4系统用例分析94系统设计104.1概要设计104.2详细设计114.2.1系统总体设计114.2.2计步模块详细设计114.2.3轨迹追踪模块详细设计124.2.4音乐播放模块详细设计134.2.5闹铃模块详细设计134.2.6平台分享模块详细设计144.2.7天气预报模块详细设计154.2.8更换主题模块详细设计154.2.9运动记录模块详细设计164.3数据库设计164.3.1数据库分析164.3.2数据库概念设计及表结构18 5系统实现195.1计步模块实现195.2轨迹追踪模块实现205.3音乐播放模块实现225.4闹铃模块实现225.5天气预报模块实现235.6平台分享模块实现245.7更换主题模块实现255.8运动记录模块实现266测试286.1计步模块测试286.2轨迹追踪模块测试296.3运动记录模块测试30结束语31参考文献32致谢331 绪论1.1 软件开发背景随着人们生活水平和生活质量的提高,人们在日常通讯、娱乐的过程中越来越多的使用手机,但是随着手机的不断更新,人们也对手机的要求越来越高,也越来越关注手机的高层服务和各种应用。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
5.1用户界面ﻩ16
5.2设置界面ﻩ17
5.3历史界面ﻩ20
5.4日历选择界面ﻩ21
5.5用户离开界面22
第六章系统测试与分析23
6.1测试过程ﻩ23
6.2测试分析ﻩ36
结论ﻩ36
参考文献37
第一章 绪论
1.1课题的背景及意义
当今社会,手机已经成为人们工作生活中必不可少的一项通讯和娱乐工具,随着手机的不断更新,手机的各种高层服务和应用层出不穷。现在智能手机可谓是爆发式增长,与此同时传统手机在不断地消失,诺基亚就是在这样的环境中受到了重创。现在主要有三个使用率和关注度最高的手机平台,分别是:Android,ios和windows phone平台,在这三个平台中Android的占有率最高。自2007年11月Google公司发布Android系统以来,短短几年时间,Android已经占据了智能手机市场的半壁江山,成为目前最为炙手可热的智能手机操作系统。Android走进了越来越多人的生活,成为他们获取信息的主境搭建ﻩ4
3.1 Android开发常用到的技术ﻩ4
3.1.1 Activity4
3.1.2 Service6
3.1.3 Content Provider内容提供者ﻩ6
3.1.4 Intent信使ﻩ6
3.2环境搭建6
3.2.1安装JDK6
3.2.2安装Eclipseﻩ7
3.2.3 Android SDK安装7
3.2.4 ADT安装7
第四章手机计步器的设计与实现8
4.1计步器功能的设计ﻩ8
4.2计步器功能的实现ﻩ10
4.2.1计步开始及暂停10
4.2.2复位键ﻩ11
4.2.3设置步长11
4.2.4设置体重11
4.2.5历史记录的查看及删除12
第五章计步器的界面效果16
SDK(software development kit)软件开发工具包。被软件开发工程师用于为特定的软件包、软件框架、硬件平台、操作系统等建立应用软件的开发工具的集合。因此,AndroidSDK指的是Android专属的软件开发工具包。
2.2.3Eclipse开发工具介绍
Eclipse是一个开放源代码的、基于插件的可扩展性平台。也可以说它只是一个框架和一组服务,用于通过插件组件构建开发环境。Eclipse附带了一些标准的插件集,包括Java开发工具(JDK)。
3、退出系统功能:当用户想终止计步软件时,可以点击退出菜单后退出本系统。
4、历史记录功能:用户可以查看以往的历史记录。
5、保存功能:有户可以保存当天的运动量,以便之后查看。
2.1.2运行环境可行性分析
本软件是在windows 7操作系统中,利用Eclipse 开发工具搭载Android SDK工具包,结合Android手机自带的sqlite数据库进行开发。
根据本软件的功能需求,将本软件分为以下几个功能模块,如图 1-1所示:
图1-1 整体框架图
ﻬ第二章 系统分析
2.1 系统可行性分析
可行性分析(FeasibilityAnalysis)也称为可行性研究,是在系统调查的基础上,针对刚刚开发打算进一步应用的系统的必要性和可能性的分析和研究。可行性研究的目的主要在于,用最小的代价在尽可能短的时间内确定问题是否能够解决。[1]
同时目前搭载Android平台的应用有很多,但针对传感器而开发的应用市场上还不多见。本应用正是针对Android手机内置的加速度传感器而特别设计的应用。所以鉴于移动端应用开发是目前软件开发行业正在兴起并会越来越炙手可热的一个分支,并且针对传感器的开发相对空白我选择了研究此课题。
1.2系统框架
在设计一款软件时一般都会把它分成几个模块,在模块的基础上还会再分小模块,这样就达到了软件模块化设计的要求,然后再对各个小模块进行详细设计和编写,采用模块化的管理方式可以使软件结构更清晰,也使得软件的管理更有秩序,使别人容易理解和阅读,但是这些模块也要根据别的模块来设计和约束,不能随便设计脱离框架,设计完成后需要把每个设计完成的模块根据总体框架结合起来。
2.2开发环境简介
2.2.1JavaDevelopment kit(JDK)介绍
JDK是Java语言的软件开发工具包。本应用用的是JDK的J2ME版,它主要用于移动设备、嵌入式设备上的Java应用程序。没有JDK的话,无法编译Java程序,所以这是开发Java程序必须安装的工具。
2.2.2 AndroidSDK介绍
2.1.1功能可行性分析ﻩ3
2.1.2运行环境可行性分析3
2.2开发环境简介3
2.2.1Java Development kit(JDK)介绍ﻩ3
2.2.2 Android SDK介绍ﻩ3
2.2.3 Eclipse开发工具介绍4
2.2.4 Android Development Tools(ADT)介绍4
该阶段通过对系统总目标的初步调研与分析,提出可行性方案并进行论证。
2.1.1功能可行性分析
1、计步功能:根据用户设置的步长和体重,估算用户步行运动所消耗的热量。当距离发生改变时在前台界面上刷新用户步行的步数、距离、和消耗的卡路里;该计步功能还实现了Notification后台运行的功能。
2、设置参数功能:设置用户的步长、体重2个参数信息。通过设置体重可以估算出不同体重的人运动所消耗的卡路里量。
基于Android的手机计步器的设计与实现+源代码
———————————————————————————————— 作者:
———————————————————————————————— 日期:
ﻩ
专业工程综合实训设计报告
目 录
第一章绪论ﻩ1
1.1课题的背景及意义1
1.2系统框架1
第二章系统分析3
2.1系统可行性分析ﻩ3