基于Android的手机计步器的设计与实现源代码

合集下载

基于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 编写一个简单的计算器

安卓Android 编写一个简单的计算器

<LinearLayout xmlns:android="/apk/res/android"xmlns:tools="/tools"android:id="@+id/LayoutMain"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical"><EditTextandroid:id="@+id/inputString"android:layout_width="fill_parent"android:layout_height="60dp"android:layout_weight="1"android:ems="10"android:inputType="none" ><requestFocus /></EditText><LinearLayoutandroid:id="@+id/LayoutButtons1"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_weight="1"android:orientation="horizontal" ><Buttonandroid:id="@+id/clear"android:layout_width="wrap_content"android:layout_height="fill_parent"android:layout_weight="1"android:text="@string/clear" /><Buttonandroid:id="@+id/delete"android:layout_width="wrap_content"android:layout_height="fill_parent"android:layout_weight="1"android:text="@string/delete" /><Buttonandroid:id="@+id/divided"android:layout_width="wrap_content"android:layout_height="fill_parent"android:layout_weight="1"android:text="@string/divided" /><Buttonandroid:id="@+id/multi"android:layout_width="wrap_content"android:layout_height="fill_parent"android:layout_weight="1"android:text="@string/multi" /></LinearLayout><LinearLayoutandroid:id="@+id/LayoutButtons2"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_weight="1"android:orientation="horizontal" ><Buttonandroid:id="@+id/seven"android:layout_width="wrap_content"android:layout_height="fill_parent"android:layout_weight="1"android:text="@string/seven" /><Buttonandroid:id="@+id/eight"android:layout_width="wrap_content"android:layout_height="fill_parent"android:layout_weight="1"android:text="@string/eight" /><Buttonandroid:id="@+id/nine"android:layout_width="wrap_content"android:layout_height="fill_parent"android:layout_weight="1"android:text="@string/nine" /><Buttonandroid:id="@+id/minus"android:layout_width="wrap_content"android:layout_height="fill_parent"android:layout_weight="1"android:text="@string/minus" /></LinearLayout><LinearLayoutandroid:id="@+id/LayoutButtons3"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_weight="1"android:orientation="horizontal" ><Buttonandroid:id="@+id/four"android:layout_width="wrap_content"android:layout_height="fill_parent"android:layout_weight="1"android:text="@string/four" /><Buttonandroid:id="@+id/five"android:layout_width="wrap_content"android:layout_height="fill_parent"android:layout_weight="1"android:text="@string/five" /><Buttonandroid:id="@+id/six"android:layout_width="wrap_content"android:layout_height="fill_parent"android:layout_weight="1"android:text="@string/six" /><Buttonandroid:id="@+id/plus"android:layout_width="wrap_content"android:layout_height="fill_parent"android:layout_weight="1"android:text="@string/plus" /></LinearLayout><LinearLayoutandroid:id="@+id/LayoutButtons4"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_weight="2"android:orientation="horizontal" ><LinearLayoutandroid:id="@+id/LayoutButtons41"android:layout_width="wrap_content"android:layout_height="fill_parent"android:layout_weight="3"android:orientation="vertical" ><LinearLayoutandroid:id="@+id/LayoutButtons411"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_weight="1"android:orientation="horizontal" ><Buttonandroid:id="@+id/one"android:layout_width="wrap_content"android:layout_height="fill_parent"android:layout_weight="1"android:text="@string/one" /><Buttonandroid:id="@+id/two"android:layout_width="wrap_content"android:layout_height="fill_parent"android:layout_weight="1"android:text="@string/two" /><Buttonandroid:id="@+id/three"android:layout_width="wrap_content"android:layout_height="fill_parent"android:layout_weight="1"android:text="@string/three" /></LinearLayout><LinearLayoutandroid:id="@+id/LayoutButtons412"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_weight="1"android:orientation="horizontal" ><Buttonandroid:id="@+id/doublezero"android:layout_width="wrap_content"android:layout_height="fill_parent"android:layout_weight="1"android:text="@string/double_zero" /><Buttonandroid:id="@+id/zero"android:layout_width="wrap_content"android:layout_height="fill_parent"android:layout_weight="1"android:text="@string/zero" /><Buttonandroid:id="@+id/point"android:layout_width="wrap_content"android:layout_height="fill_parent"android:layout_weight="1"android:text="@string/point" /></LinearLayout></LinearLayout><LinearLayoutandroid:id="@+id/LayoutButtons42"android:layout_width="wrap_content"android:layout_height="fill_parent"android:layout_weight="1"android:orientation="horizontal" ><Buttonandroid:id="@+id/equal"android:layout_width="fill_parent"android:layout_height="fill_parent"android:text="@string/equal" /></LinearLayout></LinearLayout></LinearLayout>package com.nullpointer.calculator.buttons;import java.math.BigDecimal;import java.util.ArrayList;import java.util.Arrays;import java.util.List;import mon.constants.AppConstants; import mon.utils.StringUtils;/***** @author Null Pointer**/public class FunctionButton extends CalculatorButton {/***** @param originalText** @param buttonValue** @return*/@Overridepublic String getResult(String originalText, String buttonValue) { if (AppConstants.CLEAR_STRING.equals(buttonValue)) {return AppConstants.EMPTY_STRING;} else if (AppConstants.DELETE_STRING.equals(buttonValue)) { if (StringUtils.isNotEmpty(originalText)) {return originalText.substring(0, originalText.length() - 1);} else {return AppConstants.EMPTY_STRING;}} else if (AppConstants.EQUAL_STRING.equals(buttonValue)) { return eval(originalText);} else {return AppConstants.EMPTY_STRING;}}/***** @param expression** @return*/private String eval(String expression) {List<String> items = new ArrayList<String>(Arrays.asList(expression .split("\\+|\\-|×|÷")));char[] operators = expression.replaceAll("[^\\+\\-×÷]",AppConstants.EMPTY_STRING).toCharArray();if (items.size() != operators.length + 1) {return AppConstants.ERROR_MESSAGE;}double result = 0d;for (int i = operators.length - 1; i >= 0; i--) {switch (operators[i]) {case AppConstants.OPERATOR_MULTI:result = this.multi(Double.valueOf(items.get(i)),Double.valueOf(items.get(i + 1)));items.remove(i + 1);items.set(i, String.valueOf(result));break;case AppConstants.OPERATOR_DIVIDED:result = this.divided(Double.valueOf(items.get(i)),Double.valueOf(items.get(i + 1)));items.remove(i + 1);items.set(i, String.valueOf(result));break;default:break;}}if (items.size() == 1) {return items.get(0);}operators = expression.replaceAll("[^\\+\\-]",AppConstants.EMPTY_STRING).toCharArray(); for (int i = operators.length - 1; i >= 0; i--) {switch (operators[i]) {case AppConstants.OPERATOR_PLUS:result = this.plus(Double.valueOf(items.get(i)),Double.valueOf(items.get(i + 1)));items.remove(i + 1);items.set(i, String.valueOf(result));break;case AppConstants.OPERATOR_MINUS:result = this.minus(Double.valueOf(items.get(i)),Double.valueOf(items.get(i + 1)));items.remove(i + 1);items.set(i, String.valueOf(result));break;default:break;}}if (items.size() == 1) {return items.get(0);} else {return AppConstants.ERROR_MESSAGE;}}private double plus(double v1, double v2) {BigDecimal b1 = new BigDecimal(Double.toString(v1));BigDecimal b2 = new BigDecimal(Double.toString(v2));return b1.add(b2).doubleValue();}private double minus(double v1, double v2) {BigDecimal b1 = new BigDecimal(Double.toString(v1));BigDecimal b2 = new BigDecimal(Double.toString(v2));return b1.subtract(b2).doubleValue();}private double multi(double v1, double v2) {BigDecimal b1 = new BigDecimal(Double.toString(v1));BigDecimal b2 = new BigDecimal(Double.toString(v2));return b1.multiply(b2).doubleValue();}private double divided(double v1, double v2) {BigDecimal b1 = new BigDecimal(Double.toString(v1));BigDecimal b2 = new BigDecimal(Double.toString(v2));return b1.divide(b2, 10, BigDecimal.ROUND_HALF_UP).doubleValue();}}需要完整的源代码私信我或者发我邮箱*****************明情况(注:下载才发!)。

基于Android的人体运动计步器系统的设计与实现[权威资料]

基于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实现计算器功能示例分享(计算器源码)

从零开始学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的手机计步器的设计与实现+源代码

基于Android的手机计步器的设计与实现+源代码
Android平台对于Google和用户的意义不在于手机本身,而在于为了推动移动互联网产业链的迅速成型。具有开源性的Android手机平台与之前Symbian、windowsmobile等操作系统不同,它们收取高额的授权费用,而Android不需要,这样使得应用开发成本大大降低;也正是由于它的源代码是开放的,使得开发者可以随心所欲的开发应用。同时,手机生产商和软件开发商也能够在这里得到利润,手机软件得到有效的维护协调发展。这正是Google发布Android平台的意义,也是Android平台的使命所在。
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

基于Android的手机计步器的设计与实现源代码

基于Android的手机计步器的设计与实现源代码

专业工程综合实训设计报告目录第一章绪论...............................................................课题的背景及意义......................................................系统框架.............................................................. 第二章系统分析...........................................................系统可行性分析.......................................................功能可行性分析...................................................运行环境可行性分析...............................................开发环境简介.........................................................Java Development kit(JDK)介绍..................................Android SDK 介绍.................................................Eclipse开发工具介绍.............................................Android Development Tools(ADT)介绍............................. 第三章 Android开发常用到的技术及环境搭建.................................Android开发常用到的技术.............................................Activity.........................................................Service..........................................................Content Provider 内容提供者......................................Intent 信使......................................................环境搭建..............................................................安装JDK..........................................................安装Eclipse......................................................Android SDK安装................................................ADT安装........................................................ 第四章手机计步器的设计与实现.............................................计步器功能的设计......................................................计步器功能的实现......................................................计步开始及暂停...................................................复位键...........................................................设置步长..........................................................设置体重..........................................................历史记录的查看及删除.............................................. 第五章计步器的界面效果...................................................用户界面..............................................................设置界面..............................................................历史界面..............................................................日历选择界面..........................................................用户离开界面.......................................................... 第六章系统测试与分析.....................................................测试过程.............................................................测试分析............................................................. 结论.................................................................. 参考文献..................................................................第一章绪论课题的背景及意义当今社会,手机已经成为人们工作生活中必不可少的一项通讯和娱乐工具,随着手机的不断更新,手机的各种高层服务和应用层出不穷。

安卓开发的自制计算器源代码

安卓开发的自制计算器源代码

这是本人自己用安卓编写的计算器,代码的优化可能有所问题,不过大家都在学习阶段,欢迎大家批评指正,还是上源码吧。

先来运行图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计步模块实例代码(类似微信运动)

Android计步模块实例代码(类似微信运动)

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项⽬获取当前步数展⽰。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

专业工程综合实训设计报告目录第一章绪论...............................................................课题的背景及意义......................................................系统框架.............................................................. 第二章系统分析...........................................................系统可行性分析.......................................................功能可行性分析...................................................运行环境可行性分析...............................................开发环境简介.........................................................Java Development kit(JDK)介绍..................................Android SDK 介绍.................................................Eclipse开发工具介绍.............................................Android Development Tools(ADT)介绍............................. 第三章 Android开发常用到的技术及环境搭建.................................Android开发常用到的技术.............................................Activity.........................................................Service..........................................................Content Provider 内容提供者......................................Intent 信使......................................................环境搭建..............................................................安装JDK..........................................................安装Eclipse......................................................Android SDK安装................................................ADT安装........................................................ 第四章手机计步器的设计与实现.............................................计步器功能的设计......................................................计步器功能的实现......................................................计步开始及暂停...................................................复位键...........................................................设置步长..........................................................设置体重..........................................................历史记录的查看及删除.............................................. 第五章计步器的界面效果...................................................用户界面..............................................................设置界面..............................................................历史界面..............................................................日历选择界面..........................................................用户离开界面.......................................................... 第六章系统测试与分析.....................................................测试过程.............................................................测试分析............................................................. 结论.................................................................. 参考文献..................................................................第一章绪论课题的背景及意义当今社会,手机已经成为人们工作生活中必不可少的一项通讯和娱乐工具,随着手机的不断更新,手机的各种高层服务和应用层出不穷。

现在智能手机可谓是爆发式增长,与此同时传统手机在不断地消失,诺基亚就是在这样的环境中受到了重创。

现在主要有三个使用率和关注度最高的手机平台,分别是:Android,ios和windows phone平台,在这三个平台中Android的占有率最高。

自2007年11月Google公司发布Android系统以来,短短几年时间,Android已经占据了智能手机市场的半壁江山,成为目前最为炙手可热的智能手机操作系统。

Android走进了越来越多人的生活,成为他们获取信息的主要平台。

Android平台对于Google和用户的意义不在于手机本身,而在于为了推动移动互联网产业链的迅速成型。

具有开源性的Android手机平台与之前Symbian、windows mobile等操作系统不同,它们收取高额的授权费用,而Android不需要,这样使得应用开发成本大大降低;也正是由于它的源代码是开放的,使得开发者可以随心所欲的开发应用。

同时,手机生产商和软件开发商也能够在这里得到利润,手机软件得到有效的维护协调发展。

这正是Google发布Android平台的意义,也是Android平台的使命所在。

同时目前搭载Android平台的应用有很多,但针对传感器而开发的应用市场上还不多见。

本应用正是针对Android手机内置的加速度传感器而特别设计的应用。

所以鉴于移动端应用开发是目前软件开发行业正在兴起并会越来越炙手可热的一个分支,并且针对传感器的开发相对空白我选择了研究此课题。

系统框架在设计一款软件时一般都会把它分成几个模块,在模块的基础上还会再分小模块,这样就达到了软件模块化设计的要求,然后再对各个小模块进行详细设计和编写,采用模块化的管理方式可以使软件结构更清晰,也使得软件的管理更有秩序,使别人容易理解和阅读,但是这些模块也要根据别的模块来设计和约束,不能随便设计脱离框架,设计完成后需要把每个设计完成的模块根据总体框架结合起来。

根据本软件的功能需求,将本软件分为以下几个功能模块,如图 1-1所示:图1-1 整体框架图第二章系统分析系统可行性分析可行性分析(Feasibility?Analysis)也称为可行性研究,是在系统调查的基础上,针对刚刚开发打算进一步应用的系统的必要性和可能性的分析和研究。

可行性研究的目的主要在于,用最小的代价在尽可能短的时间内确定问题是否能够解决。

[1]该阶段通过对系统总目标的初步调研与分析,提出可行性方案并进行论证。

功能可行性分析1、计步功能:根据用户设置的步长和体重,估算用户步行运动所消耗的热量。

当距离发生改变时在前台界面上刷新用户步行的步数、距离、和消耗的卡路里;该计步功能还实现了Notification后台运行的功能。

2、设置参数功能:设置用户的步长、体重2个参数信息。

通过设置体重可以估算出不同体重的人运动所消耗的卡路里量。

3、退出系统功能:当用户想终止计步软件时,可以点击退出菜单后退出本系统。

4、历史记录功能: 用户可以查看以往的历史记录。

5、保存功能:有户可以保存当天的运动量,以便之后查看。

运行环境可行性分析本软件是在windows 7 操作系统中,利用Eclipse 开发工具搭载Android SDK工具包,结合Android手机自带的sqlite数据库进行开发。

开发环境简介Java Development kit(JDK)介绍JDK是Java语言的软件开发工具包。

本应用用的是JDK的J2ME版,它主要用于移动设备、嵌入式设备上的Java应用程序。

没有JDK的话,无法编译Java程序,所以这是开发Java 程序必须安装的工具。

Android SDK 介绍SDK(software development kit)软件开发工具包。

被软件开发工程师用于为特定的软件包、软件框架、硬件平台、操作系统等建立应用软件的开发工具的集合。

因此,Android SDK 指的是Android专属的软件开发工具包。

Eclipse开发工具介绍Eclipse是一个开放源代码的、基于插件的可扩展性平台。

也可以说它只是一个框架和一组服务,用于通过插件组件构建开发环境。

相关文档
最新文档