基于Android的手机计步器的设计与实现+源代码
- 格式:doc
- 大小:1.32 MB
- 文档页数:88
基于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的人体运动计步器系统的设计与实现[权威资料]基于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实现计算器功能⽰例分享(计算器源码)下⾯是效果展⽰:复制代码代码如下:<?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;//声明两个参数。
计算器源码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>。
专业工程综合实训设计报告目录第一章绪论 (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。
南阳理工学院本科生毕业设计(论文)学院(系):软件学院专业:软件工程学生:张三指导教师:张三完成日期 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 软件开发背景随着人们生活水平和生活质量的提高,人们在日常通讯、娱乐的过程中越来越多的使用手机,但是随着手机的不断更新,人们也对手机的要求越来越高,也越来越关注手机的高层服务和各种应用。
摘要随着社会的变革,科学技术的进步,如何利用最新的科技为运动爱好者提供合理化,人性化的建议越来成为学者和企业研究的热点。
其中由于手表传感器的灵敏性,利用手表传感器记录下运动爱好者的运动数据并进行分析的技术得到了广泛的发展.因为手表的便捷便携性,获得了一大部分人的喜爱。
近年来,Android操作系统在移动智能手机领域的较好的应用,使得基于Android操作系统的移动软件的应用越来越广泛,移动软件也使得人们的生活变得越来越方便,让生活更加的智能化。
其中,基于Android操作系统的计步软件开发也引起了人们的关注。
然而,由于手机传感器的局限性,使得利用手机传感器对软件用户的运动数据进行采集时会容易出现较大的误差。
例如走路的时候如果把手机拿在手里步数有时不会增加,但是放在衣服口袋里就可以计步,另外如果跑步时带着手机也会给用户带来许多的不方便。
因此,本文结合手机的显示、分析功能和手表传感器的灵敏性和手表本身的可便携性开发了一款基于Android的计步软件,该软件可以通过蓝牙技术获取手表通过手表传感器采集来的数据并进行分析与显示等。
该软件的功能主要分为三大模块:第一,通过蓝牙传输协议实现手表到手机的计步数据传输功能;第二,手机接收到传输来的计步数据后对数据进行分析、显示和管理;第三,把分析后的计步数据同步到阿里云计算中心实现数据的共享和备份功能。
在系统的设计过程中,首先分析了系统的功能需求和非功能需求,在此基础上,对系统进行了详细地设计,对系统各子模块:个人信息、账户管理、意见反馈、账户管理、登陆、注册和帮助等的功能的实现进行了分析,最后,对系统的功能和性能进行了测试。
该系统在功能上能实现并满足客户的需求,性能很好,达到要求。
关键字:计步软件;Android;蓝牙技术ABSTRACTWith the change of the society, the progress of science and technology, how to make use of the latest technology to provide sports enthusiasts with a reasonable and humanized suggestion is to become a hot research for sports enthusiasts. Due to the sensitivity of the watch sensor, the use of the watch sensor to record the motion data and the analysis of the movement of the data and has been widely developed. Because of the convenience of the watch, so it gets a large part of people's love.In recent years, the application of Android operating system in the field of mobile smart phones, the application of mobile software based on Android operating system is becoming more and more popular. Mobile software also makes people's life more convenient and intelligent. Among them, the software development based on the Android operating system has caused the attention of people. However, due to the limitations of the mobile sensor, it is easy to make error of the mobile sensor to collect the motion data of the software users. For example, if you walk the phone in the hands, the number of steps will not increase, but placed in the pocket of the clothes can be taken. In addition to running with a mobile phone will give users a lot of inconvenience.Therefore, this paper combines the mobile phone's display, analysis function and the sensitivity of the watch sensor and the portability of the watch itself. And it developed a Android based software, the software can be acquired through the Bluetooth technology watch sensor data collected to analyze and display, etc. The function of the software is divided into three major modules: first, through the Bluetooth transmission protocol to achieve the mobile phone's data transfer function; second, the mobile phone to receive data after the transfer of the data analysis, display and management; third, the analysis of the number of steps to achieve data sharing and backup functions of Ali cloud computing center. In the process of system design, the functional requirements and non-functional requirements of the system are analyzed, and the functions of the system are analyzed, such as personal information, account management, feedback, account management, login, registration and help. The system can achieve the function and meet the needs of customers, the performance is very good, to meet the requirements.KEYWORDS: step software; Android; Bluetooth technology目录摘要 (i)ABSTRACT ...................................................................................................................... i i 1 绪论 . (1)1.1研究背景及意义 (1)1.2国内外研究现状 (3)1.2.1 Android平台 (3)1.2.2 计步器 (3)1.3研究目的 (5)1.4本文结构 (5)1.5本章小结 (6)2 相关技术介绍 (7)2.1W EB服务技术 (7)2.2SQL ITE数据库技术 (8)2.3基于A NDROID操作系统 (8)2.3.1 Android简介 (8)2.3.2 Android操作系统优势 (9)2.3.3 Android 基本框架 (10)2.4蓝牙通信技术 (12)2.5开发工具介绍 (12)2.5.1 Java Development kit(JDK)介绍 (13)2.5.2 Android SDK 介绍 (13)2.5.3 Eclipse开发工具介绍 (13)2.5.4 Android Development Tools(ADT)介绍 (13)2.5.5 Android开发常用到的技术 (14)2.6GPS相关理论技术知识 (15)2.6.1 GPS定位原理 (15)2.6.2 Android中GPS类简介 (16)2.7本章小结 (16)3 用户需求分析及可行性分析 (17)3.1用户总体需求分析 (17)3.2功能性需求分析 (18)3.2.1 计步数据分析子系统 (18)3.2.2 系统管理子系统 (19)3.2.3 计步数据采集与同步子系统 (19)3.3非功能性需求分析 (21)3.3.1 性能需求 (21)3.3.2 可靠性需求 (21)3.3.2 安全性需求 (21)3.3.3 适用性需求 (22)3.4可行性分析 (22)3.4.1 经济可行性 (22)3.4.2 技术可行性 (22)3.5本章小结 (23)4 系统设计 (24)4.1软件架构设计 (24)4.1.1 UI层 (25)4.1.2 Domain层 (26)4.1.3 Resource层 (26)4.2业务逻辑及业务实体类设计 (28)4.2.1 数据存储设计 (28)4.2.2 计步数据分析子系统 (29)4.2.2 系统管理子系统 (31)4.2.3 计步数据采集与同步子系统 (32)4.3系统界面设计 (33)4.3.1 主界面设计 (33)4.3.2 历史界面分析 (34)4.3.3 设置界面分析 (35)4.3.4 分享界面分析 (36)4.4数据库设计 (37)4.4.1 数据库ER图 (38)4.4.2 数据库表详细说明 (38)4.5本章小结 (39)5 计步软件的实现 (40)5.1计步数据分析子系统的实现 (40)5.1.1 数据显示 (40)5.1.2 历史数据 (43)5.2系统管理子系统的实现 (45)5.2.1 个人信息 (45)5.2.2 账户管理 (46)5.2.3 意见反馈 (47)5.2.4 登录 (47)5.2.5 注册 (49)5.2.6 帮助 (51)5.3计步数据采集与同步子系统 (52)5.3.1 计步数据采集硬件电路 (52)5.3.2 手表同步到手机 (53)5.3.3 手机同步到云服务器 (54)5.4本章小结 (55)6 计步软件的测试 (56)6.1配置测试环境 (56)6.2设计测试用例 (56)6.3编写测试代码 (57)6.4测试案例分析 (58)6.5测试结果 (58)6.6本章小结 (58)7 总结与展望 (59)7.1总结 (59)7.2展望 (60)参考文献 (61)作者简历及攻读硕士学位期间取得的研究成果 (63)独创性声明 (64)学位论文数据集 (65)1 绪论本章主要介绍本文的研究背景及意义和对本文进行研究时做的相关的调研工作,国内外研究的现状,最后简要阐述了本文的研究内容与目标以及本文的组织结构。
Android计步模块实例代码(类似微信运动)最近在项⽬中研究计步模块,每天0点开始记录当天的步数,类似微信运动。
碰到了不少坑今天有时间整理出来给⼤家看看。
做之前在google、baidu、github上搜了个遍没找到好的,⼤多数都是需要在后台存活,需要后台Service。
对于现在的各⼤⼿机⼚商为了提⾼电池的续航⾥程(省电),基本上AlertManager、android.intent.action.BOOT_COMPLETED、后台Service都是被⼲掉的。
后台保活策略Service,基本上没什么⽤,被⼿机系统⼲掉只是时间问题,所以我认为最好也不要去做,就算后台存活了,⽤户看到这个app⾮常费电也会被删除的。
⽬前android计步有两种⽅式系统计步芯⽚在Android4.4版本之后,部分机型实现了Sensor.TYPE_STEP_COUNTER传感器,⽤于纪录⽤户⾏⾛的步数。
从⼿机开机开始纪录,⼿机关机时重置为0。
这个记步芯⽚是系统级别的,相对之前⽼版本的传感器记步,性能有⼀些优化:不会因为App单独⽤了记步的功能⽽额外耗电系统芯⽚记步是持续的,能够优化部分机型后台不记步的问题。
加速度传感器计算⽅式加速度传感器⾮常耗电,导致App的耗电量很⾼,影响⽤户体验。
需要后台实时运⾏才能实现记步的功能,如果App进程被系统或者安全软件杀死,导致记步功能没办法使⽤根据以上两种⽅式实现计步,⼿机提供计步传感器就使⽤Sensor.TYPE_STEP_COUNTER⽅式(app后台关闭也可以计步),如果不提供就使⽤SensorManager.SENSOR_DELAY_UI⽅式(app需要保持后台运⾏)。
项⽬结构:计步Service使⽤单独进程,所以使⽤到进程间通信aidl,todaystepcounterlib为库⽂件⽤于在单独进程中实现计步算法,app 依赖todaystepcounterlib项⽬获取当前步数展⽰。