安卓APP源码和设计报告——智能垃圾桶

49 篇文章 0 订阅

课程名称: 移动互联网应用开发

实验名称

姓名/学号

专业/班级

指导教师

实验时间

一、案例功能需求

该系统是了解垃圾分类以及物品查询属于哪类垃圾的智能化APP。该系统可以实现用户登陆注册,登录成功后用到Frament分为三页,首页、分类百科和搜索实现的。首页可以查看四大类垃圾分类详情,分类百科可以拍照上传物品然后识别出属于什么类别的垃圾,搜索可以实现你想要搜索的商品是什么类型的垃圾。如下图,图1.1。

图1.1

二、文件结构

1、开发环境

Windows10 x64、Android Studio 2020.3.1 Patch2

2、运行环境

Android 11(R) skd14

3、是否需要联网

三、项目配置文件工程结构

1、工程配置文件

表一:工程文件位置

图一,图二:manifest

2、工程结构目录

图三:java工程结构

图四:layout工程结构

图五:drawable工程目录

三、程序详细分析

1、项目源码中含有数据库frgment、RALD数据库连接、数字转换等。

2、frgment:(3)将Fragment加入到动态数组ArrayList<Fragment>中,实例化适配器,并绑定到ViewPager上,设置ViewPager2切换监听器,改变下方按钮图片——initFragment();

RALD数据库连接:

public class RALDbConnect extends SQLiteOpenHelper {
public static final String DATABASE_NAME = “UserInfo”;// name of database we want to create
public static final String TABLE_NAME = “mytable“; // name of table we want to create
public static final int DATABASE_VERSION = 1; // version of our database it can be any no
// column names we want in our table
public static final String UID = “_id” ; // primary key field of table(ist column)(_id)
public static final String USERNAME = “Username” ; // 2nd column(Uname) of table
public static final String PASSWORD = “Password” ; // 3rd column (Password) of table
public static final String EMAIL=”Email”;
public static final String PHONENUMBER=”Phonenumber”;
public static final String ADDRESS=”Address”;

private static final String CREATE_TABLE = ” CREATE TABLE ” + TABLE_NAME + ” ( ” + UID +
” INTEGER PRIMARY KEY AUTOINCREMENT, ” + USERNAME + ” VARCHAR(255) , ”
PASSWORD + ” VARCHAR(255),” + EMAIL + ” VARCHAR(255),”+ PHONENUMBER + ” VARCHAR(255),” + ADDRESS + ” VARCHAR(255));”;

private static final String DROP_TABLE = ” DROP TABLE IF EXISTS ” + TABLE_NAME ;
private Context context;
public RALDbConnect(Context context)
{
super(context, DATABASE_NAME, null,DATABASE_VERSION);
this.context = context ;
}

// oncreate() will be called to create database first time it is called only once
@Override
public void onCreate(SQLiteDatabase db) {
try
{
db.execSQL(CREATE_TABLE); // used to create table into database
}
catch(Exception ex)
{
Log.e(“myerror”, ex.getMessage());
}
}
// this method will call when we upgrade our database
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
try
{
Log.i(“currentDb”, “upgraded”);
db.execSQL(DROP_TABLE);
onCreate(db);
}
catch(Exception ex)
{
Log.e(“error on Upgreade”, ex.getMessage());
}

}

}

数字转换:

public class DigitalConversion {

private static String nums[] = {“零”, “一”, “二”, “三”, “四”, “五”, “六”, “七”, “八”, “九”};

private static String pos_units[] = {“”, “十”, “百”, “千”};

private static String weight_units[] = {“”, “万”, “亿”};

/**
* 数字转汉字【新】
*
* @param num
* @return
*/
public static String numberToChinese(int num) {
if (num == 0) {
return “零”;
}

int weigth = 0;//节权位
String chinese = “”;
String chinese_section = “”;
boolean setZero = false;//下一小节是否需要零,第一次没有上一小节所以为false
while (num > 0) {
int section = num % 10000;//得到最后面的小节
if (setZero) {//判断上一小节的千位是否为零,是就设置零
chinese = nums[0] + chinese;
}
chinese_section = sectionTrans(section);
if (section != 0) {//判断是都加节权位
chinese_section = chinese_section + weight_units[weigth];
}
chinese = chinese_section + chinese;
chinese_section = “”;
//Log.d(“TAG”, chinese_section);

setZero = (section < 1000) && (section > 0);
num = num / 10000;
weigth++;
}
if ((chinese.length() == 2 || (chinese.length() == 3)) && chinese.contains(“一十”)) {
chinese = chinese.substring(1, chinese.length());
}
if (chinese.indexOf(“一十”) == 0) {
chinese = chinese.replaceFirst(“一十”, “十”);
}

return chinese;
}

/**
* 将每段数字转汉子
*
* @param section
* @return
*/
public static String sectionTrans(int section) {
StringBuilder section_chinese = new StringBuilder();
int pos = 0;//小节内部权位的计数器
boolean zero = true;//小节内部的置零判断,每一个小节只能有一个零。
while (section > 0) {
int v = section % 10;//得到最后一个数
if (v == 0) {
if (!zero) {
zero = true;//需要补零的操作,确保对连续多个零只是输出一个
section_chinese.insert(0, nums[0]);
}
} else {
zero = false;//有非零数字就把置
section_chinese.insert(0, pos_units[pos]);
section_chinese.insert(0, nums[v]);
}
pos++;
section = section / 10;
}
return section_chinese.toString();
}
}

四、主要流程分析

  1. 登录、登录信息存储

用户输入账号密码登陆,没有就可以注册并登陆,如果账号密码输入不正确,就会无法登录,账号密码输入正确则登陆成功。

图六 登录界面图

  1. 注册

图七 注册界面图

  1. 平台主页
    可以查看垃圾种类的分类百科

图八 平台主页图

  1. 查询结果
    可以查看垃圾的分类情况

  1. 拍照识别功能

对垃圾进行拍照并识别垃圾属于那种类别

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值