安卓APP源碼和設(shè)計(jì)報(bào)告——智能垃圾桶
課程名稱:?移動(dòng)互聯(lián)網(wǎng)應(yīng)用開發(fā)
實(shí)驗(yàn)名稱:
姓名/學(xué)號(hào):
專業(yè)/班級(jí):
指導(dǎo)教師:
實(shí)驗(yàn)時(shí)間:
一、案例功能需求
該系統(tǒng)是了解垃圾分類以及物品查詢屬于哪類垃圾的智能化APP。該系統(tǒng)可以實(shí)現(xiàn)用戶登陸注冊(cè),登錄成功后用到Frament分為三頁(yè),首頁(yè)、分類百科和搜索實(shí)現(xiàn)的。首頁(yè)可以查看四大類垃圾分類詳情,分類百科可以拍照上傳物品然后識(shí)別出屬于什么類別的垃圾,搜索可以實(shí)現(xiàn)你想要搜索的商品是什么類型的垃圾。如下圖,圖1.1。
圖1.1
二、文件結(jié)構(gòu)
1、開發(fā)環(huán)境
Windows10 x64、Android Studio 2020.3.1 Patch2
2、運(yùn)行環(huán)境
Android 11(R) skd14
3、是否需要聯(lián)網(wǎng)
否
三、項(xiàng)目配置文件及工程結(jié)構(gòu)
1、工程配置文件
表一:工程文件位置
圖一,圖二:manifest
2、工程結(jié)構(gòu)目錄
圖三:java工程結(jié)構(gòu)
圖四:layout工程結(jié)構(gòu)
圖五:drawable工程目錄
三、程序詳細(xì)分析
1、項(xiàng)目源碼中含有數(shù)據(jù)庫(kù)frgment、RALD數(shù)據(jù)庫(kù)連接、數(shù)字轉(zhuǎn)換等。
2、frgment:(3)將Fragment加入到動(dòng)態(tài)數(shù)組ArrayList<Fragment>中,實(shí)例化適配器,并綁定到ViewPager上,設(shè)置ViewPager2切換監(jiān)聽器,改變下方按鈕圖片——initFragment();
RALD數(shù)據(jù)庫(kù)連接:
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());
}
}
}
數(shù)字轉(zhuǎn)換:
public class DigitalConversion {
private static String?nums[] = {“零”, “一”, “二”, “三”, “四”, “五”, “六”, “七”, “八”, “九”};
private static String?pos_units[] = {“”, “十”, “百”, “千”};
private static String?weight_units[] = {“”, “萬”, “億”};
/**
* 數(shù)字轉(zhuǎn)漢字【新】
*
* @param num
* @return
*/
public static String numberToChinese(int num) {
if (num == 0) {
return “零”;
}
int weigth = 0;//節(jié)權(quán)位
String chinese = “”;
String chinese_section = “”;
boolean setZero = false;//下一小節(jié)是否需要零,第一次沒有上一小節(jié)所以為false
while (num > 0) {
int section = num % 10000;//得到最后面的小節(jié)
if (setZero) {//判斷上一小節(jié)的千位是否為零,是就設(shè)置零
chinese =?nums[0] + chinese;
}
chinese_section =?sectionTrans(section);
if (section != 0) {//判斷是都加節(jié)權(quán)位
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;
}
/**
* 將每段數(shù)字轉(zhuǎn)漢子
*
* @param section
* @return
*/
public static String sectionTrans(int section) {
StringBuilder section_chinese = new StringBuilder();
int pos = 0;//小節(jié)內(nèi)部權(quán)位的計(jì)數(shù)器
boolean zero = true;//小節(jié)內(nèi)部的置零判斷,每一個(gè)小節(jié)只能有一個(gè)零。
while (section > 0) {
int v = section % 10;//得到最后一個(gè)數(shù)
if (v == 0) {
if (!zero) {
zero = true;//需要補(bǔ)零的操作,確保對(duì)連續(xù)多個(gè)零只是輸出一個(gè)
section_chinese.insert(0,?nums[0]);
}
} else {
zero = false;//有非零數(shù)字就把置
section_chinese.insert(0,?pos_units[pos]);
section_chinese.insert(0,?nums[v]);
}
pos++;
section = section / 10;
}
return section_chinese.toString();
}
}
四、主要流程分析
登錄、登錄信息存儲(chǔ)
用戶輸入賬號(hào)密碼登陸,沒有就可以注冊(cè)并登陸,如果賬號(hào)密碼輸入不正確,就會(huì)無法登錄,賬號(hào)密碼輸入正確則登陸成功。
圖六?登錄界面圖
注冊(cè)
圖七?注冊(cè)界面圖
平臺(tái)主頁(yè)
可以查看垃圾種類的分類百科
圖八?平臺(tái)主頁(yè)圖
查詢結(jié)果
可以查看垃圾的分類情況
拍照識(shí)別功能
對(duì)垃圾進(jìn)行拍照并識(shí)別垃圾屬于那種類別
?