Android项目-计算器(DOC)

合集下载

基于安卓的计算器的设计与实现

基于安卓的计算器的设计与实现

基于安卓的计算器的设计与实现在设计和实现基于安卓的计算器时,需要考虑以下几个重要的方面:用户界面设计、计算逻辑实现和功能扩展。

首先,用户界面设计是一个计算器的重要组成部分。

一个简洁直观、易于使用的界面可以提供良好的用户体验。

可以考虑使用标准计算器的布局,包括数字键盘、运算符按钮和显示结果的文本框。

此外,还可以添加一些额外的功能,比如一键清除按钮、括号按钮和科学计算模式切换按钮等。

考虑到不同屏幕尺寸和定制化需求,应该使用相对布局或者网格布局来放置UI元素。

其次,计算逻辑实现是计算器的核心部分。

需要支持基本的四则运算,包括加法、减法、乘法和除法。

为了实现连续运算和操作优先级,可以使用栈或者逆波兰表示法。

在用户输入数字和运算符时,应该及时更新显示结果的文本框。

另外,还应该考虑异常情况的处理,比如除数为零的情况。

最后,功能扩展是一个好的设计的关键。

除了基本的四则运算,还可以考虑添加一些其他功能,比如开方、求平方、取余、倒数、阶乘等。

另外,还可以添加一个历史记录功能,记录用户的计算过程和结果,方便用户查看和回顾。

此外,还可以添加一个单位转换功能,支持常见的长度、重量、温度、时间、速度等单位之间的转换。

在实际开发中,可以使用Android Studio作为开发工具。

Android Studio提供了丰富的界面设计工具和模拟器,可以方便地进行界面布局和调试。

可以使用Java语言进行开发,使用Android提供的API来处理用户输入和展示结果。

在代码实现中,可以使用按钮点击事件来处理用户输入。

当用户点击数字按钮时,将所点击的数字添加到一个临时变量中,当用户点击运算符按钮时,将临时变量中的数字和运算符添加到运算式中,并清空临时变量。

当用户点击等号按钮时,根据运算式中的数字和运算符进行实际的计算,并将结果显示在结果文本框中。

当用户点击清空按钮时,将运算式和结果文本框清空。

除了基本逻辑实现外,还可以进行一些优化和改进。

在Android Studio中开发一个简单的计算器应用

在Android Studio中开发一个简单的计算器应用

在Android Studio中开发一个简单的计算器应用随着智能手机的普及,计算器应用成为了人们生活中不可或缺的工具之一。

为了满足用户的需求,我们决定在Android Studio中开发一个简单的计算器应用。

这个应用将提供基本的四则运算功能,并且界面简洁易用。

首先,在Android Studio中创建一个新的项目。

选择合适的应用名称和包名。

接下来,我们需要设计应用的用户界面。

我们希望用户界面简洁明了,方便用户使用。

可以考虑使用一个TextView显示计算结果,以及多个Button用于输入数字和操作符。

在开发计算器的过程中,我们需要处理用户的输入并进行相应的计算。

为此,我们可以使用一个EditText控件来接收用户的输入,并通过按钮的点击事件来获取用户点击的数字和操作符。

然后,我们可以使用Java中的数学库来进行四则运算,并将结果显示在TextView中。

通过Android Studio提供的布局编辑器,我们可以轻松地将TextView和Button布局在界面上。

可以使用LinearLayout或RelativeLayout进行布局,根据需要设置各个控件之间的位置和大小。

此外,还可以设置按钮的点击事件,使其能够响应用户的输入。

在处理用户输入时,需要考虑一些特殊情况。

例如,当用户输入非法字符或进行除法时需要进行错误处理。

可以通过在代码中添加条件判断语句来实现这些功能。

另外,还可以添加一些额外的功能,如清除输入、撤销操作等,以提升用户体验。

在开发过程中,可以使用Android Studio提供的调试工具来检查代码是否正常运行。

可以设置断点,逐步执行代码,并查看变量的值。

这些工具能够帮助我们快速定位和修复错误。

为了使应用具有良好的用户体验,我们还可以添加一些动画效果和过渡效果。

例如,当用户点击按钮时,可以添加按钮缩放、淡入淡出等动画效果,使界面更加生动有趣。

除了基本功能以外,我们还可以考虑添加更多的功能来完善应用。

Android入门程序开发—BMI计算器

Android入门程序开发—BMI计算器

Android入门程序开发—BMI计算器作者:董明华李宏伟来源:《电脑知识与技术》2017年第35期摘要:AndroidStudio已经代替了Eclipse,成为Android官方集成开发工具。

文章基于AndroidStudio设计了一款身高体重计算器,通过介绍常见布局控件的用法,使初学者能够快速入门Android APP开发,了解APP界面设计,用户输入值的获取等知识。

关键词:AndroidStudio;BMI;APP中图分类号:TP311 文献标识码:A 文章编号:1009-3044(2017)35-0136-031 背景BMI指数,即身体质量指数,是用体重公斤数除以身高米数平方得出的数字,是目前国际上常用的衡量人体胖瘦程度以及是否健康的一个标准。

体质指数(BMI)=体重(kg)÷身高^2(m)。

文章根据BMI指数开发一款简易身高体重计算器,通过分析用户的身高体重值,判断其身材是否标准。

2 APP展示最终APP效果如图1所示,用户输入身高体重值后,通过单击计算按钮,可得出身体胖瘦程度的一个提示。

3 知识点分析项目涉及知识点较为简单,界面布局为LinearLayout,控件为EditText和Button,java源代码部分主要是控件的初始化,取得文本输入框的输入值,并转换为数值类型,然后计算出BMI指数值,并通过Toast给出提示。

4 界面设计界面从上向下依次为身高输入框、体重输入框和按钮,输入框对应Android中的EditText 控件,按钮对应Button控件,垂直排列的布局适合用线性布局LinearLayout。

布局主要作用是设置控件在屏幕上的位置,线性布局LinearLayout可以让其中的控件水平排列或者垂直排列。

首先,在res/layout文件夹中找到自动生成的布局文件activity_main.xml。

在此文件中声明父布局LinearLayout的排版方向为垂直排列,通过设置android:orientation的属性值为vertical 实现。

android开发计算器课程设计

android开发计算器课程设计

android开发计算器课程设计一、教学目标本课程旨在通过学习Android开发计算器,使学生掌握Android应用开发的基本知识和技能,能够独立设计和开发简单的Android计算器应用。

1.理解Android开发的基本概念和框架。

2.掌握Android计算器的界面设计和事件处理。

3.熟悉Android计算器的数据存储和运算逻辑。

4.能够使用Android Studio进行基本的Android应用开发。

5.能够设计并实现一个简单的Android计算器应用。

6.能够对Android计算器应用进行调试和优化。

情感态度价值观目标:1.培养学生的创新意识和问题解决能力。

2.培养学生对Android开发技术的兴趣和热情。

3.培养学生的团队合作精神和自主学习能力。

二、教学内容本课程的教学内容主要包括Android开发的基本概念和框架、Android计算器的界面设计和事件处理、Android计算器的数据存储和运算逻辑等。

1.Android开发的基本概念和框架:介绍Android Studio的使用、Android应用的结构和生命周期、Activity和Service的概念和用法。

2.Android计算器的界面设计:介绍布局文件的使用、控件的属性和事件处理。

3.Android计算器的数据存储和运算逻辑:介绍SharedPreferences和SQLite数据库的使用、运算器的实现和数据的存储。

三、教学方法本课程将采用讲授法、案例分析法和实验法等多种教学方法相结合的方式进行教学。

1.讲授法:通过讲解和演示,使学生理解Android开发的基本概念和框架、Android计算器的界面设计和事件处理、Android计算器的数据存储和运算逻辑。

2.案例分析法:通过分析典型的Android计算器应用案例,使学生掌握Android计算器的界面设计和事件处理、数据存储和运算逻辑的实现。

3.实验法:通过实际操作和调试,使学生掌握Android计算器的界面设计和事件处理、数据存储和运算逻辑的实现。

基于Android计算器功能的实现

基于Android计算器功能的实现

基于Android计算器功能的实现摘要随着移动通信技术和网络技术的迅速发展,手机系统发生了巨大的变化,从进行简单通话功能的非智能手机到现在集上网、聊天、收发邮件、视屏电话会议等各种服务于娱乐为一身的智能手机系统。

由Google公司牵头众多实力雄厚的软硬件厂商加盟成立了OMS联盟,并推出的Android平台手机系统。

作为时代的新生儿,Android手机操作平台有着得天独厚的优势广阔的发展前景。

本文正是基于Android平台开发的计算器。

论文主要阐述以面向对象的程序开发语言eclipse为开发工具, 设计并实现基于Android的计算器。

论文首先介绍了Android开发平台和环境以及Android 工程的重要部分,其次对计算器系统和程序进行了分析和设计,再次对计算器进行了系统的实现,并对系统进行了严格的验证,最后本文对所做工作进行了总结。

关键词:手机,Android,用户界面,计算器THE CALCULATOR FUNCTION REALIZATION BASEDON ANDROIDABSTRACTWith the development of mobile communication technology and network technology, great changes have taken place on the mobile phone system. The original mobile phone only has the functions of communication and Smartphone has the functions of internet, chat, video conferencing and other services and entertainment. Android mobile phone platform which was developed by Google Company and many equipment manufacturers of hardware and software vendors, as the era of neonatal has a unique advantage and prospects for development. This article is based on the Android platform calculator. The thesis describes object-oriented programming language eclipse development tools, design and implement a calculator based on the Android. The paper first introduces the Android development platform and environment as well as an important part of the Android project, followed by the calculator systems and procedures analysis and design, the realization of the system once again the calculator, and strict verification, Finally, a summary of the work done.Key words: mobile phone, Android, UI, calculator目录1 引言 (1)1.1 课题背景及意义 (1)1.1.1 课题背景 (1)1.1.2 课题意义 (1)1.2 智能手机平台系统 (2)1.3 课题来源 (3)2 基于Android平台计算器相关技术概述 (4)2.1 Android手机平台 (5)2.1.1 Android起源及优势 (5)2.1.2 Android体系结构 (5)2.1.3 Android平台功能特征 (7)2.2 Android SDK介绍 (9)2.3 XML技术 (10)2.4 JNI技术 (11)3 基于Android平台计算器设计 (12)3.1 系统的总体设计 (12)3.2 程序流程和系统功能设计 (13)3.2.1 程序流程设计 (13)3.2.2 系统功能设计 (14)3.3基于Android平台系统具体设计 (15)3.3.1 总体模块详细设计 (15)3.3.2 输入模块详细设计 (16)3.3.3 显示模块详细设计 (16)3.3.4 计算模块详细设计 (17)4 计算器系统实现 (18)4.1 Android应用程序构成 (18)4.2 Android应用系统文件结构 (19)4.3 构建Android应用程序用户界面 (21)4.3.1 Android应用程序界面组件 (21)4.3.2 Android应用系统界面组件 (22)4.3.3 Android用户界面的实现 (24)4.4 计算模块的实现 (28)4.5 计算器演示 (30)5 结论 (32)谢辞 (33)参考文献 (34)附录1: (36)附录2: (38)1 引言1.1 课题背景及意义1.1.1 课题背景随着社会的发展,经济水平的提高,手机越来越普及。

制作一个简易计算器——基于AndroidStudio实现

制作一个简易计算器——基于AndroidStudio实现

制作⼀个简易计算器——基于AndroidStudio实现⼀个计算器Android程序的源码部分分为主⼲和细节两部分。

⼀、主⼲1. 主⼲的构成计算器的布局事件(即计算器上的按钮、⽂本框)监听实现计算2. 详细解释 假设我们的项⽬名为Calculator,⽽布局名称(Layout Name)为默认的activity_main 。

即设置如下图所⽰: 在这种前提下,有:设置计算器布局的⽂件:Calculator/app/src/main/res/layout/activity_main.xml事件监听和计算实现在同⼀个⽂件⾥:Calculator/app/src/main/java/下的⼀个⼦⽬录⾥的MainActivity.java 即如下图所⽰:计算器布局代码(写在activity_main.xml⽂件⾥):1<?xml version="1.0" encoding="utf-8"?>2<ScrollView xmlns:android="/apk/res/android"3 android:layout_width="fill_parent"4 android:layout_height="wrap_content"5>6<LinearLayout7android:layout_width="fill_parent"8 android:layout_height="fill_parent"9 android:orientation="vertical">10<EditText11android:id="@+id/input"12 android:layout_width="fill_parent"13 android:layout_height="wrap_content"14 android:layout_gravity="center"15 android:editable="false"16 android:hint="@string/shuru"/>1718<EditText19android:id="@+id/output"20 android:layout_width="fill_parent"21 android:layout_height="wrap_content"22 android:layout_gravity="center"23 android:editable="true"24 android:gravity="right"25 android:hint="@string/shuchu"/>2627<RelativeLayout28android:layout_width="fill_parent"29 android:layout_height="wrap_content">3031<Button32android:id="@+id/seven"33 android:layout_width="80dp"34 android:layout_height="70dp"35 android:layout_alignParentLeft="true"36 android:text="@string/seven"37 android:textSize="40sp"/>3839<Button44 android:text="@string/eight"45 android:textSize="40sp"/>4647<Button48android:id="@+id/nine"49 android:layout_width="80dp"50 android:layout_height="70dp"51 android:layout_toRightOf="@id/eight"52 android:text="@string/nine"53 android:textSize="40sp"/>5455<Button56android:id="@+id/add"57 android:layout_width="80dp"58 android:layout_height="70dp"59 android:layout_alignParentRight="true"60 android:layout_toRightOf="@id/nine"61 android:text="@string/add"62 android:textSize="40sp"/>6364<Button65android:id="@+id/four"66 android:layout_width="80dp"67 android:layout_height="70dp"68 android:layout_alignParentLeft="true"69 android:layout_below="@id/seven"70 android:text="@string/four"71 android:textSize="40sp"/>7273<Button74android:id="@+id/five"75 android:layout_width="80dp"76 android:layout_height="70dp"77 android:layout_below="@id/eight"78 android:layout_toRightOf="@id/four"79 android:text="@string/five"80 android:textSize="40sp"/>8182<Button83android:id="@+id/six"84 android:layout_width="80dp"85 android:layout_height="70dp"86 android:layout_below="@id/nine"87 android:layout_toRightOf="@id/five"88 android:text="@string/six"89 android:textSize="40sp"/>9091<Button92android:id="@+id/subtract"93 android:layout_width="80dp"94 android:layout_height="70dp"95 android:layout_alignParentRight="true"96 android:layout_below="@id/add"97 android:layout_toRightOf="@id/six"98 android:text="@string/subtract"99 android:textSize="40sp"/>100101<Button102android:id="@+id/one"103 android:layout_width="80dp"104 android:layout_height="70dp"105 android:layout_alignParentLeft="true" 106 android:layout_below="@id/four"107 android:text="@string/one"108 android:textSize="40sp"/>109110<Button111android:id="@+id/two"112 android:layout_width="80dp"113 android:layout_height="70dp"114 android:layout_below="@id/five"115 android:layout_toRightOf="@id/one" 116 android:text="@string/two"117 android:textSize="40sp"/>118119<Button120android:id="@+id/three"121 android:layout_width="80dp"122 android:layout_height="70dp"123 android:layout_below="@id/six"128<Button129android:id="@+id/multiply"130 android:layout_width="80dp"131 android:layout_height="70dp"132 android:layout_alignParentRight="true" 133 android:layout_below="@id/subtract" 134 android:layout_toRightOf="@id/three" 135 android:text="@string/multiply"136 android:textSize="40sp"/>137138<Button139android:id="@+id/zero"140 android:layout_width="80dp"141 android:layout_height="70dp"142 android:layout_alignParentLeft="true" 143 android:layout_below="@id/one"144 android:text="@string/zero"145 android:textSize="40sp"/>146147<Button148android:id="@+id/clear"149 android:layout_width="80dp"150 android:layout_height="70dp"151 android:layout_below="@id/two"152 android:layout_toRightOf="@id/zero" 153 android:text="@string/clear"154 android:textSize="40sp"/>155156<Button157android:id="@+id/result"158 android:layout_width="80dp"159 android:layout_height="70dp"160 android:layout_below="@id/three"161 android:layout_toRightOf="@id/clear" 162 android:text="@string/result"163 android:textSize="40sp"/>164165<Button166android:id="@+id/divide"167 android:layout_width="80dp"168 android:layout_height="70dp"169 android:layout_alignParentRight="true" 170 android:layout_below="@id/multiply" 171 android:layout_toRightOf="@id/result" 172 android:text="@string/divide"173 android:textSize="40sp"/>174175<Button176android:id="@+id/dot"177 android:layout_width="80dp"178 android:layout_height="70dp"179 android:layout_alignParentLeft="true" 180 android:layout_below="@id/zero"181 android:text="@string/dot"182 android:textSize="40sp"/>183<Button184android:id="@+id/writeButton"185 android:layout_width="wrap_content" 186 android:layout_height="wrap_content" 187 android:layout_alignParentLeft="true" 188 android:layout_below="@id/dot"189 android:text="@string/write"190 android:textSize="40sp"/>191<Button192android:id="@+id/readButton"193 android:layout_width="wrap_content" 194 android:layout_height="wrap_content" 195 android:layout_alignParentRight="true" 196 android:layout_below="@id/dot"197 android:text="@string/read"198 android:textSize="40sp"/>199200<CheckBox201android:id="@+id/appendBox"202 android:text="@string/appendBox"203 android:layout_width="wrap_content" 204 android:layout_height="wrap_content" 205 android:layout_alignParentBottom="true" 206 android:layout_toLeftOf="@+id/divide" 207 android:layout_toStartOf="@+id/divide"212213<EditText214215android:layout_width="match_parent"216 android:layout_height="wrap_content"217 android:id="@+id/textView"/>218219<EditText220221android:layout_width="match_parent"222 android:layout_height="wrap_content"223 android:id="@+id/displayView"/>224225<EditText226android:id="@+id/errorzero"227 android:layout_width="fill_parent"228 android:layout_height="wrap_content"229 android:layout_gravity="center"230 android:editable="false"231 android:gravity="center"232/>233<EditText234android:id="@+id/resultText"235 android:layout_width="fill_parent"236 android:layout_height="wrap_content"237 android:layout_gravity="center"238 android:editable="false"239 android:gravity="left"240 android:text="@string/resultText"241/>242</LinearLayout>243</ScrollView>View Code事件监听和实现计算代码(写在MainActivity.java⽂件⾥)1package com.example.lenovo.calculator;2345import android.app.Activity;6import android.content.Context;7import android.os.Bundle;8import android.view.View;9import android.view.View.OnClickListener;10import android.widget.Button;11import android.widget.CheckBox;12import android.widget.EditText;1314import java.io.FileInputStream;15import java.io.FileNotFoundException;16import java.io.FileOutputStream;17import java.io.IOException;1819public class MainActivity extends Activity {20/**21 * Called when the activity is first created.22*/23private EditText output = null;24private EditText input = null;25private Button btn0 = null;26private Button btn1 = null;27private Button btn2 = null;28private Button btn3 = null;29private Button btn4 = null;30private Button btn5 = null;31private Button btn6 = null;32private Button btn7 = null;33private Button btn8 = null;34private Button btn9 = null;35private Button btnadd = null;36private Button btnsubtract = null;37private Button btnmultiply = null;38private Button btndivide = null;39private Button btnclear = null;40private Button btnresult = null;41private Button btndot = null;46private Button writeButton = null;47private Button readButton = null;48private CheckBox appendBox = null;49private EditText textView = null;50private EditText displayView = null;51public String FILE_NAME = "fileDemo.txt";525354private String str = "";//保存数字55private String strold = "";//原数字56private char act = ' ';//记录“加减乘除等于”符号57private int count = 0;//判断要计算的次数,如果超过⼀个符号,先算出来⼀部分58private Float result = null;//计算的输出结果59private Boolean errBoolean = false;//有错误的时候为true,⽆错为false60private Boolean flagBoolean = false;//⼀个标志,如果为true,可以响应运算消息,如果为false,不响应运算消息,只有前⾯是数字才可以响应运算消息 61private Boolean flagDot = false; //⼩数点标志位62636465 @Override66public void onCreate(Bundle savedInstanceState) {67super.onCreate(savedInstanceState);68 setContentView(yout.activity_main);6970 output = (EditText) findViewById(R.id.output);71 input = (EditText) findViewById(R.id.input);7273 errorzero = (EditText) findViewById(R.id.errorzero);74 resultText = (EditText) findViewById(R.id.resultText);75 writeButton = (Button) findViewById(R.id.writeButton);76 readButton = (Button) findViewById(R.id.readButton);77 textView = (EditText) findViewById(R.id.textView);78 displayView = (EditText) findViewById(R.id.displayView);79 appendBox = (CheckBox) findViewById(R.id.appendBox);8081 btn0 = (Button) findViewById(R.id.zero);82 btn1 = (Button) findViewById(R.id.one);83 btn2 = (Button) findViewById(R.id.two);84 btn3 = (Button) findViewById(R.id.three);85 btn4 = (Button) findViewById(R.id.four);86 btn5 = (Button) findViewById(R.id.five);87 btn6 = (Button) findViewById(R.id.six);88 btn7 = (Button) findViewById(R.id.seven);89 btn8 = (Button) findViewById(R.id.eight);90 btn9 = (Button) findViewById(R.id.nine);91 btnadd = (Button) findViewById(R.id.add);92 btnsubtract = (Button) findViewById(R.id.subtract);93 btnmultiply = (Button) findViewById(R.id.multiply);94 btndivide = (Button) findViewById(R.id.divide);95 btnclear = (Button) findViewById(R.id.clear);96 btnresult = (Button) findViewById(R.id.result);97 btndot = (Button) findViewById(R.id.dot);98//设置按钮侦听事件99 btn0.setOnClickListener(listener);100 btn1.setOnClickListener(listener);101 btn2.setOnClickListener(listener);102 btn3.setOnClickListener(listener);103 btn4.setOnClickListener(listener);104 btn5.setOnClickListener(listener);105 btn6.setOnClickListener(listener);106 btn7.setOnClickListener(listener);107 btn8.setOnClickListener(listener);108 btn9.setOnClickListener(listener);109//执⾏运算110 btnadd.setOnClickListener(listener);111 btnsubtract.setOnClickListener(listener);112 btnmultiply.setOnClickListener(listener);113 btndivide.setOnClickListener(listener);114 btnclear.setOnClickListener(listener);115 btnresult.setOnClickListener(listener);116117 btndot.setOnClickListener(listener);118119 writeButton.setOnClickListener(writelistener);120 readButton.setOnClickListener(readlistener);121122123// ATTENTION: This was auto-generated to implement the App Indexing API.124// See https://g.co/AppIndexing/AndroidStudio for more information.125 }130public void onClick(View v) {131// TODO Auto-generated method stub132switch (v.getId()) {133//输⼊数字134case R.id.zero:135 num(0);136break;137case R.id.one:138 num(1);139break;140case R.id.two:141 num(2);142break;143case R.id.three:144 num(3);145break;146case R.id.four:147 num(4);148break;149case R.id.five:150 num(5);151break;152case R.id.six:153 num(6);154break;155case R.id.seven:156 num(7);157break;158case R.id.eight:159 num(8);160break;161case R.id.nine:162 num(9);163break;164165case R.id.dot:166 dot();167break;168//执⾏运算169case R.id.add:170 add();171break;172case R.id.subtract:173 sub();174break;175case R.id.multiply:176 multiply();177break;178case R.id.divide:179 divide();180break;181case R.id.clear:182 clear();183break;184//计算结果185case R.id.result:186 result();187if (!errBoolean && flagBoolean) {188 output.setText(String.valueOf(result));189 }190 resultText.setText(strold + act + str + "=" + result+" "); 191break;192193default:194break;195196 }197 input.setText(strold + act + str);198 output.setText(String.valueOf(result));199200201 }202 };203204private OnClickListener writelistener = new OnClickListener() {205 @Override206public void onClick(View view) {207//textView.setText("");208209 FileOutputStream fos = null;214 fos = openFileOutput(FILE_NAME, Context.MODE_PRIVATE); 215 }216 String text = resultText.getText().toString();217 fos.write(text.getBytes());218 textView.setText("⽂件写⼊成功,写⼊长度:" + text.length()); 219//resultText.setText("");220221 } catch (FileNotFoundException e) {222 e.printStackTrace();223 } catch (IOException e) {224 e.printStackTrace();225 }226finally {227if (fos != null)228try {229 fos.flush();230 fos.close();231 } catch (IOException e) {232 e.printStackTrace();233 }234 }235 }236 };237private OnClickListener readlistener = new OnClickListener() {238 @Override239public void onClick(View view) {240241 displayView.setText("");242 FileInputStream fis = null;243try {244 fis = openFileInput(FILE_NAME);245if (fis.available() == 0) {246return;247 }248byte[] readBytes = new byte[fis.available()];249while (fis.read(readBytes) != -1) {250251 }252 String text = new String(readBytes);253 displayView.setText(text);254 textView.setText("⽂件读取成功,写⼊长度:" + text.length()); 255256 } catch (FileNotFoundException e) {257 e.printStackTrace();258 } catch (IOException e) {259 e.printStackTrace();260 }261262 }263 };264265private void dot() {266// TODO Auto-generated method stub267268if (!flagDot) {269 str = str + ".";270 flagBoolean = false;271 flagDot = true;272 }273 }274275private void clear() {276// TODO Auto-generated method stub277 str = strold = "";278 count = 0;279 act = ' ';280 result = null;281 flagBoolean = false;282 flagDot = false;283 input.setText(strold + act + str);284 output.setText("");285 errorzero.setText("");286 displayView.setText("");287 textView.setText("");288 resultText.setText("");289 }290291private void divide() {292// TODO Auto-generated method stub293if (flagBoolean) {299300private void multiply() {301// TODO Auto-generated method stub 302if (flagBoolean) {303 check();304 act = '*';305 flagBoolean = false;306 }307 }308309private void sub() {310// TODO Auto-generated method stub 311if (flagBoolean) {312 check();313 act = '-';314 flagBoolean = false;315 }316 }317318private void add() {319// TODO Auto-generated method stub 320if (flagBoolean) {321 check();322 act = '+';323 flagBoolean = false;324 }325 }326327private void check() {328// TODO Auto-generated method stub 329if (count >= 1) {330 result();331 str = String.valueOf(result);332 }333 strold = str;334 str = "";335 count++;336 flagDot = false;337 errorzero.setText("");338 }339340//计算输出结果341private void result() {342// TODO Auto-generated method stub 343if (flagBoolean) {344 Float a, b;345346 a = Float.parseFloat(strold);347 b = Float.parseFloat(str);348349if (b == 0 && act == '/') {350 clear();351 errorzero.setText("除数不能为零!"); 352//output.setText("除数不能为零!"); 353354355//errBoolean=true;356 }357358359if (!errBoolean) {360switch (act) {361case '+':362 result = a + b;363break;364case '-':365 result = a - b;366break;367case '*':368 result = a * b;369break;370case '/':371 result = a / b;372break;373374default:375break;376 }377 }383private void num(int i) {384// TODO Auto-generated method stub385 str = str + String.valueOf(i);386 flagBoolean = true;387 errorzero.setText("");388 }389390 }View Code⼆、细节 仅仅将主⼲部分代码copy下来并不能运⾏程序,因为主⼲代码调⽤了⼀些⽂件的代码,这些⽂件就是我们所说的细节。

Android:实现一个计算器--(四则运算)

Android:实现一个计算器--(四则运算)

Android :实现⼀个计算器--(四则运算)计算器的功能介绍:Dot 的效果展⽰:侃侃 Dot:改进的地⽅:不⾜的地⽅:补充知识:android 中的事件处理步骤如何将信息显⽰到 View(EditText)上:异常的类型:Name: Dot (从某点开始,到某点结束)功能: + 、- 、* 、/ 、%(清零,退格操作)版本:1.0Dot 与其他的计算器相⽐没有太⼤的竞争⼒,甚⾄在处理⼀些极端的问题时还存在很⼤的不⾜,例如:⼤数的四则运算,对于这个问题处理的还不够到位,⽬前只能实现⼀些简单的四则运算(只能说⾃⼰的⽔平太菜,还没有掌握⼀些实质性的内容,这个是⾃⼰需要检讨的)另外:⾮常感谢 Android ⽼师教给我们的知识,使我们可以设计出第⼀款属于⾃⼰的 app.相对于最原始的设计,更新了哪些东西呢?1、改变按钮的形状,由原始的长⽅形 -- 椭圆状,使得按钮更加形象化。

2、增加背景图⽚,使⽤户的体验效果更好。

3、增加退格操作,使得⽤户在输错信息时不⽤全盘清零,可以删除刚刚写的某个字符。

1、未实现⼀些⼤数的运算。

2、当退格退完后,再按退格时会⾃动退出(不影响总体效果,但还是有那么⼀点 bug )3、⽬前两个数操作就需要 '=' ⼀下,但是可以实现多项式的运算,只是每次都需要 '='(后续会进⾏修改,逐渐完善)a 、找到事件⽬标对象(Button),通过 findViewById(),遍历⼦对象。

b 、实现view.onClickLisenter 接⼝,重写 onClick ⽅法。

c 、在事件⽬标对象上注册,btn.setOnClickListener (实现类的对象)a 、为 EditText 定义 id -- etResultb 、通过 findViewById 获取 etResult 对象c 、通过 etResult.setText() 将信息显⽰到计算器界⾯上a 、RuntimeExceptiona、RuntimeException运⾏时异常,不要求处理(但最好处理⼀下),与业务相关,⽐较主观(每个应⽤都可以采⽤⾃⼰的⽅式进⾏处理),⼀般不严重, 对效果不会产⽣太⼤的影响。

Android系统精简列表对照表

Android系统精简列表对照表

安卓系统精简列表对照表,适用于大部分Android系统,大家请参考对照精简。

AirkanPhoneService 可删AntiSpam 可删AdupsFot.apk无线升级(可删)AdupsFotaReboot.apk重启升级操作(可删)ApplicationGuide.apk-应用程度指南(不可删)ApplicationsProvider.apk-应用程序存储服务(不可删)AtciService.apk--系统服务(不可删)Backup.apk 可删BackupRestoreConfirmation.apkGoogle邮箱的备份,可删BasicDreams.apk 4.2新增,休眠模式,不可删BatteryWarning.apk--电池警告(建议保留)Browser.apk-谷歌浏览器(可删)BugReport 可删Calculator.apk---计算器(可删)Calendar.apk日历(可删,换第三方日历)CalendarImporter.apk日历服务(同上)CalendarProvider.apk-日历存储(同上)CDS_INFO.apk--常见数据服务(不可删)CellBroadcastReceiver.apk小区广播(可删)CellConnService.apk---电话连接服务(不可删)CertInstaller.apk-证书安装,可删(亲测,没发现问题)Cit可删CloudService可删ChromeBookmarksSyncAdapter.apk-Google书签同步(可删)com.google.android.apps.docs.apk--云端硬盘(可删)com.google.android.apps.maps.apk-谷歌地图(可删)com.google.android.googlequicksearchbox.apk-Google搜索(可删)com.google.android.street.apk--街景视图(可删)Contacts.apk--通讯录/联系人(不可删)ContactsProvider.apk--通讯录/联系人数据存储服务(不可删)DataHubProvider.apk. 会导致流量红圈不可删DataTransfer.apk-备份与恢复(可删)DataUsageLockScreenClient.apk数据应用和锁定屏幕客户端(不可删)DefaultContainerService.apk-默认存储服务(不可删)DeskClock.apk闹钟,时钟(建议保留)DownloadProvider.apk 下载管理器,可删(删了就不能在谷歌电子市场和谷歌浏览器下载东西了,需要的留着)DownloadProviderUi.apk 下载内容,可删(同上)DrmProvider.apk 受DRM保护的内容的存储,可删(有DRM保护的东西就留着这个)Email.apk-电子邮件(可删)EngineerMode.apk--工程模式(不可删)EngineerModeSim.apksim卡工程模式(不可删)EventReceiver 翻译过来就是事件接收还是别删了这个网上没查到多少资料Exchange2.apk--消息协作服务(可删)Facelock---人脸解锁(可删)FactoryMode.apk工厂模式(不可删)FileManager.apk-文件管理(觉得无用可删)FM 可删FMRadio.apk-收音机(建议保留)FusedLocation.apk-GPS定位辅助文件(不可删)无限重启)Galaxy4.apk--动态壁纸黑洞(可删)Gallery2.apk--图库/相机(建议保留)GenieWidget.apk新闻和天气(可删)Gmail.apk--谷歌邮箱(可删)Gmail2.apk谷歌邮箱(可删)GmsCore.apkGoogleplay服务(可删)GoogleBackupTransport.apk--谷歌备份传输(可删)GoogleCalendarSyncAdapter.apk谷歌日历同步(可删)GoogleContactsSyncAdapter.apk谷歌联系人同步(可删)GoogleEars.apk--GooglePlay声音搜索(可删)GoogleFeedback.apk---谷歌电子市场反馈(可删)GoogleLoginService.apkGoogle账户管理(可删)GoogleOta.apk---谷歌系统升级(可删)GoogleOtaSysOper.apk---谷歌系级升级辅助操作(跟上面是一起的,可删)GoolePartnerSetup.apkGoole合作伙伴设置(可删)GoogleServicesFramework.apk-谷歌同步支持服务架构(可删)GoogleTTSGoogle文字转语音引擎(可删)HoloSpiralWallpaper.apk--壁纸(可删)HTMLViewer.apk查看本地网页(建议保留)HoloSpiralWallpaper 可删InputDevices.apk OTG功能需要的别删KeyChain.apk输入服务(不可删)密码管理--帐号切换、密码存储,建议保留LatinIME.apk-Android键盘(可删)Launcher2.apk---启动器(不可删,可替换)LiveWallpapers.apkAndroid动态壁纸(可删)LBESEC_MIUI.apk 这个是授权管理LBE安全大师MIUI系统专版的安装包可能会影响自带的root功能先不删LiveWallpapersPicker.apk-动态壁纸选择器(不要动态壁纸可删)LocationEM.apk工程师模式(不可删)Matcli 应该是自己装的第三方软件自动装进了系统app文件里吧网上也没详细说明还是别删了怕系统不稳定MagicSmokeWallpapers.apk魔幻动态壁纸(可删)mainkeys.apk虚拟按键开启/关闭(建议保留)MediaProvider.apk--媒体数据存储服务(不可删,删后无法设置铃声)MediaTekLocationProvider.apk-联发科定位存储(可删)MediaUploader.apk---上传的内容(建议保留)MiuiCompass.apk MIUI 指南针可删(可替代)MiuiGallery.apk MIUI 图库勿删MiuiHome.apk MIUI 启动器删之前必须在系统设置——全部设置——显示——默认桌面——自己选择好第三方桌面才行MiuiSystemUI.apk MIUI 系统用户界面勿删MiuiVideo 可删MiuiVideoPlayer 可删MiWallpaper 可删Mms.apk短信和彩信(可用第三方短信软件来代替) MTKAndroidSuiteDaemon.apk-联发科安卓套件精灵(可删)MtkBt.apk-MTK蓝牙(不可删)MTKLogger.apk--MTK移动日志记录器(可删)MTKThermalManager.apk联发科温度检测和管理(建议保留)MtkVideoLiveWallpaper.apk-MTK动态壁纸(可删)MtkWeatherProvider--天气服务(可删)MtkWeatherWidget.apk天气插件(不用系统天气软件的可删)MtkWorldClockWidget.apk-世界时钟插件(可删)Music.apk---音乐播放器(可删,可用第三方程序代替)MusicFX.apk-音乐播放器的音效均衡器(可删)mx86.apk-虚拟按键开启/关闭设置net.cactii.flash2.apk---手电筒(建议保留)Networkassistant.apk 自带流量监控可删NetworkLocation.apk提供网络位置(GPS辅助定位,不能删)NFC.apk 近距离无线通讯技术重要的新鲜的功能别删NoiseField.apk--泡沫动态壁纸(可删)NoteBook.apk---记事本(可删)Notes 小米便签可删nvcplsvc.apk 省电功能别删NvwfdProtocolsPack网上说是跟连接小米盒子有关系可删但还是别删吧网上搜索结果资料很少说明不详细怕不稳定NvwfdService同上还是别删吧Omacp.apk--手机内部配置信息(不可删)OneTimelnitializer.apk谷歌一次性备份恢复(可删)OOBE.apk设置向导(可删)PackageInstaller.apk---APK软件安装器(不可删)PhaseBeam.apk-动态壁纸光之韵律(可删)PhaseBeam.apk-动态壁纸雷光(可删)Phone.apk电话连接服务(不可删)Phonesky.apk谷歌电子商店(可删)PhotoT able.apk 互动屏保,可删(我删了,我不用那屏保)PicoTts.apk文字转语音服务(可删)Protips.apk桌面小绿人插件(可删)Provision.apk系统初始开机引导(不可删)QuickSearchBox.apk---快速搜素(可删)Ringdroid.apk铃声剪辑(可删)SchedulePiowerOnOff.apk定时开关机(建议保留)Settings.apk--系统设置(不可删)SettingsProvider.apk---设置储存(不可删)SetupWizard.apk设置向导(可删)SharedStorageBackup.apk 共享存储备份可删作用不大删了很多游戏就不能玩了SmartcardService.apk 智能卡服务作用大概和电脑的CPU一样,很重要还是别删sougoushurufa.apk--搜狗拼音输入法(可删,安装其它的)SoundRecorder.apk---录音机(建议保留)Stk1.apk卡1的stk开机提示服务(可删)Stk2.apk卡2的STK开机提示服务(可删)StkSelection.apk-SIM卡服务,就是移动和联通的服务(可删)SuperUser.apk---超级用户权限(建议保留)SystemUpdate.apk-安卓4.2.1系统文件(建议保留)tag.apk 据说是NFC近距离无线通信服务和ncf.apk有关的ncf删了的话tag也没用,就可以删了的和nfc一样还是别删了Talk.apk---谷歌语音信息服务(可删)Talkback.apk--系统设置-辅助功能里面的盲人补丁(可删)TaskManager2.apk-任务管理器(可删)TelephonyProvider.apk拨号记录存储服务(不可删)ThemeManager.apk MIUI 主题风格建议保留可删Todos.apk待办事项(可删)Torch.apk-手电筒(建议保留,也可换成别的手电筒)Transfer 快传软件可删Updater.apk MIUI 系统更新可删(影响在线升级)UpdateSystem.apk系统升级(可删)Userbook 用户手册可删UserbookProvider 用户手册存储可删UserDictionaryProvider.apk用户字典存储服务(可删)VideoEditor.apk电影工作室(可删)VideoFavorites.apk最爱联系人(可删)VideoPlayer.apk-视频播放器/视频壁纸选择器(可删)VisualizationWallpapers.apk---音乐可视化壁纸(可删)VoiceAssist 语音助手可删就是类似哦啦语音那种的VioceCommand.apk--声音指命/语音指挥官(可删)VoiceSearchStub.apk-语音搜索存根(可删)VoiceUnilck.apk语音解锁(可删)VpnDialogs.apk--拨号,公司内部登陆和翻墙用的(建议保留)WallpaperChooser.apk---壁纸(可删)XiaomiServiceFramework 可删小米服务框架kYGPS.apkGPS(不可删)YellowPage 不可删未存号码拨打删了就不能打还未保存的号码,只可以打名片夹里有名字的号码。

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

学校代码: 10128学号:课程设计说明书题目:移动版计算器学生姓名:学院:信息工程学院班级:计12-1班指导教师:庄旭菲2015 年 7 月目录第一章总体功能介绍 01.1功能介绍 01.2软件设计 01.2.1系统软件的结构图 01.2.2功能的操作流程 01.2.3计算器模块 (1)第二章各功能模块的具体实现 (2)2.1系统主界面 (2)2.2基本加减乘除界面 (9)2.3其他运算界面 (1)第三章调试及运算结果 (7)3.1加法运算结果 (7)3.2减法运算结果 (8)3.3乘法运算结果 (8)3.4除法运算结果 (8)3.5带括号运算结果 (9)3.6复合运算结果 (9)第四章总结 (9)摘要:Android是当今最重要的手机开发的平台之一,它是建立在Java基础上的,能够迅速建立手机软件的解决方案。

Android的功能十分强大。

成为当今软件行业的一股新兴力量。

Android基于Linux平台,由操作系统、用户界面和应用软件组成,具有以下特点:开放性、应用程序无界限、应用程序是在平等条件下创建的、应用程序可以轻松的嵌入网络、应用程序可以并行运行。

第一章总体功能介绍1.1功能介绍计算器软件的系统功能介绍:(1)实现简单的要实现基本的加、减、乘、除四则运算。

(2)可以实现在前一步计算结果上继续作加、减、乘、除,即连加、减、乘、除。

(3)有清空功能,即清除所有数据,重新开始计算。

(4)拥有后退按键,可以实现清除单个错误数据。

(5)可以实现复合运算。

1.2软件设计1.2.2功能的操作流程首先用户根据自己的实际需要选择计算,得出程序结果,输入数据,选择运算符号,再输入数据,选择等号,即可以得出结果。

1.2.3计算器模块图1-1 MyOntouchListener 类图图1-2 Utils类图图1-3 MainActivity类图程序中的类图如图1-1,1-2,1-3所示。

Utils中主要包含了两个方法。

分别是逆波兰式的生成以及计算结果的输出。

这两个方法为utiNi()以及calculate()图1-1中的类是MainActivity中的子类MainActivity中包含了按钮的点击事件以及触摸设置背景颜色,按钮字体颜色等功能。

第二章各功能模块的具体实现2.1系统主界面本界面是用来线性布局与网格布局,控件有文本框与按钮<LinearLayout xmlns:android=""xmlns:tools=""android:layout_width="match_parent"android:layout_height="match_parent"android:background="#ccd0d1"android:orientation="vertical"android:paddingBottom="@dimen/activity_vertical_margin"android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"> <LinearLayoutandroid:layout_width="match_parent"android:layout_height="116dp"android:background="#ccd0d1"android:orientation="vertical"><EditTextandroid:id="@+id/et_number"android:layout_width="match_parent"android:layout_height="58dp"android:layout_weight="1"android:textColor="@android:color/black"android:background="@drawable/et_bg1_01"android:gravity="right|bottom"android:paddingRight="10dp"android:paddingBottom="5dp"android:focusable="false"android:singleLine="true"android:textSize="20sp"/><EditTextandroid:id="@+id/et_number1"android:layout_marginTop="0dp"android:layout_width="match_parent"android:layout_height="58dp"android:layout_weight="1"android:textColor="@android:color/black"android:background="@drawable/et_bg1_02"android:gravity="right|bottom"android:paddingRight="10dp"android:paddingBottom="5dp"android:hint="0"android:focusable="false"a ndroid:singleLine="true"android:textSize="40sp"/></LinearLayout><Switchandroid:id="@+id/switchButton"android:layout_width="wrap_content"android:layout_height="wrap_content"android:thumb="@drawable/thumb"android:track="@drawable/track"android:layout_gravity="left|top"android:layout_weight="1"android:checked="false"android:textOff=""android:textOn=""/><GridLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="5"android:background="#ccd0d1"android:columnCount="5"android:orientation="horizontal"android:rowCount="6"><Buttonandroid:id="@+id/bt_left"android:layout_width="60dp"android:layout_height="48dp"android:textColor="#616A73"android:background="@drawable/bg_bt2"android:layout_row="1"android:text="("/><Buttonandroid:id="@+id/bt_right"android:layout_width="60dp"android:layout_height="48dp"android:textColor="#616A73"android:background="@drawable/bg_bt2"android:text=")"/><Buttonandroid:id="@+id/bt_C"android:layout_width="60dp"android:layout_height="48dp"android:textColor="#F07E21"android:background="@drawable/bg_bt2"android:text="C"/>android:id="@+id/bt_DEL"android:layout_width="60dp"android:layout_height="48dp"android:textColor="#616A73"android:background="@drawable/bg_bt2"android:layout_columnSpan="2"android:layout_gravity="fill_horizontal"android:text="DEL"/><Buttonandroid:id="@+id/bt_7"android:layout_width="60dp"android:layout_height="48dp"android:textColor="#616A73"android:background="@drawable/bg_bt1"android:text="7"/><Buttonandroid:id="@+id/bt_8"android:layout_width="60dp"android:layout_height="48dp"android:textColor="#616A73"android:background="@drawable/bg_bt1"android:text="8"/><Buttonandroid:id="@+id/bt_9"android:layout_width="60dp"android:layout_height="48dp"android:textColor="#616A73"android:background="@drawable/bg_bt1"android:text="9"/><Buttonandroid:id="@+id/bt_cf"android:layout_width="60dp"android:layout_height="48dp"android:textColor="#616A73"android:background="@drawable/bg_bt2"android:layout_columnSpan="2"android:layout_gravity="fill_horizontal"android:text="/"/>android:id="@+id/bt_4"android:layout_width="60dp"android:layout_height="48dp"android:textColor="#616A73"android:background="@drawable/bg_bt1"android:layout_row="5"android:text="4"/><Buttonandroid:id="@+id/bt_5"android:layout_width="60dp"android:layout_height="48dp"android:textColor="#616A73"android:background="@drawable/bg_bt1"android:text="5"/><Buttonandroid:id="@+id/bt_6"android:layout_width="60dp"android:layout_height="48dp"android:textColor="#616A73"android:background="@drawable/bg_bt1"android:text="6"/><Buttonandroid:id="@+id/bt_mul"android:layout_width="60dp"android:layout_height="48dp"android:textColor="#616A73"android:background="@drawable/bg_bt2"android:layout_columnSpan="2"android:layout_gravity="fill_horizontal"android:text="*"/><Buttonandroid:id="@+id/bt_1"android:layout_width="60dp"android:layout_height="48dp"android:textColor="#616A73"android:background="@drawable/bg_bt1"android:text="1"/><Buttonandroid:layout_width="60dp"android:layout_height="48dp"android:textColor="#616A73"android:background="@drawable/bg_bt1"android:text="2"/><Buttonandroid:id="@+id/bt_3"android:layout_width="60dp"android:layout_height="48dp"android:textColor="#616A73"android:background="@drawable/bg_bt1"android:text="3"/><Buttonandroid:id="@+id/bt_jf"android:layout_width="60dp"android:layout_height="48dp"android:textColor="#616A73"android:background="@drawable/bg_bt2"android:layout_columnSpan="2"android:layout_gravity="fill_horizontal"android:text="-"/><Buttonandroid:id="@+id/bt_0"android:layout_width="60dp"android:layout_height="48dp"android:textColor="#616A73"android:background="@drawable/bg_bt1"android:layout_columnSpan="2"android:layout_gravity="fill_horizontal"android:text="0"/><Buttonandroid:id="@+id/bt_point"android:layout_width="60dp"android:layout_height="48dp"android:textColor="#616A73"android:background="@drawable/bg_bt1"android:text="."/><Buttonandroid:layout_width="60dp"android:layout_height="48dp"android:textColor="#616A73"android:background="@drawable/bg_bt2"android:layout_columnSpan="2"android:layout_gravity="fill"android:layout_rowSpan="2"android:text="+"/><Buttonandroid:id="@+id/bt_sum"android:layout_width="60dp"android:layout_height="48dp"android:textColor="#FFFDFD"android:background="@drawable/ic_launcher"android:layout_columnSpan="3"android:layout_gravity="fill"android:text="="/></GridLayout></LinearLayout>2.2基本加减乘除界面用户在文本框中输入参加运算的数据,并且点击要进行的运算符号,点击等号之后,会显示出计算结果。

相关文档
最新文档