您当前的位置:首页 > 毕业设计

毕业设计- Android的记账APP

时间:2022-03-11 07:16:05 阅读数:55,824人阅读
版权声明:转载请注明出处,谢谢!
—— 人的成就和差异决定于其业余时间。

项目介绍

注册登录进入本系统后,可以查看本月总收入、本月总支出、剩余预算数、本周帐单、近期帐单

1. 首页 首页显示本月收入和支出,近期帐单列表信息如日期、帐单类型、帐单金额,支出金额为绿色,收入金额为红色;

2. 添加记账 点击首页加号即可添加一笔记账,输入帐单日期、帐单名称、帐单金额和选择帐单类型。

3. 帐单统计 可查看月度帐单和年度帐单统计,统计有饼图和曲线图;

4. 设置 可设置每月支出预算、手势密码、退出登录;

本系统使用litepal数据库存储

项目截图

实现原理

布局文件activity_main.xml:

			<?xml version="1.0" encoding="utf-8"?>
			<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
				xmlns:app="http://schemas.android.com/apk/res-auto"
				xmlns:tools="http://schemas.android.com/tools"
				android:id="@+id/drawer_layout"
				android:layout_width="match_parent"
				android:layout_height="match_parent"
				android:fitsSystemWindows="true"
				tools:openDrawer="start">

				<include
					layout="@layout/app_bar_main"
					android:layout_width="match_parent"
					android:layout_height="match_parent" />

				<com.google.android.material.navigation.NavigationView
					android:id="@+id/nav_view"
					android:layout_width="wrap_content"
					android:layout_height="match_parent"
					android:layout_gravity="start"
					android:fitsSystemWindows="true"
					app:headerLayout="@layout/nav_header_main"
					app:menu="@menu/activity_main_drawer" />

			</androidx.drawerlayout.widget.DrawerLayout>
	  
	       /**
			 * APP主页面
			 */
			public class MainActivity extends BaseActivity implements View.OnClickListener {

				private DrawerLayout mDrawerLayout;
				//登陆的用户名
				private String loginName;
				//月预算
				private int budget;
				//recyclerView的adapter绑定的List
				private List<AccountInfo> todayAccountInfo = new ArrayList<>();
				private AccountRecyclerViewAdapter adapter;

				@Override
				protected void onCreate(Bundle savedInstanceState) {
					super.onCreate(savedInstanceState);
					setContentView(R.layout.activity_main);
					setToolbar(R.id.toolbar_main, false);
					//菜单栏点击事件
					navView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
						@Override
						public boolean onNavigationItemSelected(@NonNull MenuItem item) {
							mDrawerLayout.closeDrawers();
							switch (item.getItemId()) {
								case R.id.settings:
									directStartActivity(MainActivity.this, SettingsActivity.class);
								default:
									break;
							}
							return true;
						}
					});
					//点击RecyclerView事件
					adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
						@Override
						public void onItemClick(final BaseQuickAdapter adapter, View view, final int position) {
							AccountRecyclerViewAdapter.onItemSelected(MainActivity.this, adapter, position,
									new AccountRecyclerViewAdapter.SelectCallback() {
										@Override
										public void onDeleteIemClick() {
											setAllData();
										}
									});
						}
					});
				}

				@Override
				public void onClick(View v) {
					switch (v.getId()) {
						//记账按钮
						case R.id.record_now_card:
						case R.id.fab:
							directStartActivity(this, RecordActivity.class);
							break;
						//月账单卡片,进入月数据Activity
						case R.id.month_account_card:
							Intent intent = new Intent(this, MonthAccountActivity.class);
							intent.putExtra("year", Utility.getTime(Calendar.YEAR));
							intent.putExtra("month", Utility.getTime(Type.TIME_MONTH));
							startActivity(intent);
							break;
						//周账单卡片,设置List为本周
						case R.id.week_account_card:
							showTodayText.setVisibility(View.VISIBLE);
							List<AccountInfo> infoList =
									AccountDAO.quickFind(Type.ACCOUNT_THIS_WEEK);
							adapter.setDateType(AccountRecyclerViewAdapter.SHOW_DATE_WEEKDAY);
							weekAccountCard.setEnabled(false);
							setList(infoList);
							accountRecordText.setText("-- 本周账单记录 --");
							break;
						//菜单键打开菜单
						case R.id.menu_button:
							mDrawerLayout.openDrawer(GravityCompat.START);
							break;
						//点击用户名,弹出选择
						case R.id.nav_header_username_layout:
							String[] items = {"修改头像", "更改背景图", "退出登录"};
							new AlertDialog.Builder(this)
									.setItems(items, new DialogInterface.OnClickListener() {
										@Override
										public void onClick(DialogInterface dialog, int which) {
											switch (which) {
												case 0:
													choosePhoto(Type.CHANGE_IMG_PROFILE);
													break;
												case 1:
													choosePhoto(Type.CHANGE_IMG_BG);
													break;
												case 2:
													exitLogin();
													break;
												default:
											}
										}
									}).create().show();

							break;

						case R.id.month_total_layout:
							monthAccountCard.callOnClick();
							break;
						case R.id.show_today_text:
							accountRecordText.setText("-- 今日账单记录 --");
							adapter.setDateType(AccountRecyclerViewAdapter.SHOW_DATE);
							showTodayText.setVisibility(View.INVISIBLE);
							weekAccountCard.setEnabled(true);
							setContentData();
							break;
						default:
					}
				}

				/**
				 * 初始化设置项
				 */
				private void initSettings() {
					//设置登陆的用户名
					loginName = (String) prefs.get("login_name", "");
					//如果不存在用户名, 退出登录回到主界面
					if (TextUtils.isEmpty(loginName)) exitLogin();
					//设置预算
					budget = Integer.parseInt((String) prefs.get("month_budget", "2000"));
					//设置数据库名,默认为用户名
					LitePalDB litePalDB = LitePalDB.fromDefault(loginName);
					LitePal.use(litePalDB);
					//设置头像
					String fileName = (String) prefs.get("profile_path", null);
					if (!TextUtils.isEmpty(fileName)) {
						Uri uri = Uri.fromFile(new File(fileName));
						profileImg.setImageURI(uri);
					}
					//设置菜单栏背景图
					String menuBgUri = (String) prefs.get("menu_bg_uri", null);
					if (!TextUtils.isEmpty(menuBgUri)) {
						Glide.with(this).load(Uri.parse(menuBgUri)).into(menuBgImg);
					}
				}

				/**
				 * 设置所有的数据
				 */
				private void setAllData() {
					setHeaderData();
					setContentData();
				}

				/**
				 * 设置标题栏数据
				 */
				@SuppressLint("SetTextI18n")
				private void setHeaderData() {
					List<AccountInfo> infoList = AccountDAO.quickFind(Type.ACCOUNT_THIS_MONTH);
					monthTotalIncomeText.setText("¥"
							+ Utility.getAccountMoneyNum(infoList, Type.ACCOUNT_TOTAL_INCOME));
				}

				/**
				 * 设置RecyclerView.以及周和月卡片的数据
				 */
				@SuppressLint("SetTextI18n")
				private void setContentData() {
					List<AccountInfo> infoList;
					//设置TodayRecyclerView
					if (showTodayText.getVisibility() == View.VISIBLE) {
						infoList = AccountDAO.quickFind(Type.ACCOUNT_THIS_WEEK);
					} else {
						infoList = AccountDAO.quickFind(Type.ACCOUNT_TODAY);
					}
					setList(infoList);
					//设置本周账单卡片
					infoList = AccountDAO.quickFind(Type.ACCOUNT_THIS_WEEK);
					weekBalanceText.setText("结余 ¥" + Utility.getAccountMoneyNum(
							infoList, Type.ACCOUNT_BALANCE));
					weekIncomeText.setText("+" + Utility.getAccountMoneyNum(
							infoList, Type.ACCOUNT_TOTAL_INCOME));
					weekExpenseText.setText("-" + Utility.getAccountMoneyNum(
							infoList, Type.ACCOUNT_TOTAL_EXPENSE));
					//设置月账单卡片
					infoList = AccountDAO.quickFind(Type.ACCOUNT_THIS_MONTH);
					monthBalanceText.setText("结余 ¥" + Utility.getAccountMoneyNum(
							infoList, Type.ACCOUNT_BALANCE));
					monthIncomeText.setText("+" + Utility.getAccountMoneyNum(
							infoList, Type.ACCOUNT_TOTAL_INCOME));
					monthExpenseText.setText("-" + Utility.getAccountMoneyNum(
							infoList, Type.ACCOUNT_TOTAL_EXPENSE));
				}

				/**
				 * 设置RecyclerView显示为List
				 * @param list
				 */
				private void setList(List<AccountInfo> list) {
					if (todayAccountInfo == null) {
						todayAccountInfo = new ArrayList<>();
					} else {
						todayAccountInfo.clear();
					}
					Collections.reverse(list);
					todayAccountInfo.addAll(list);
					adapter.notifyDataSetChanged();
				}

				/**
				 * 开启图片选择Activity
				 * @param type
				 */
				private void choosePhoto(int type) {
					Intent intent = new Intent(Intent.ACTION_PICK);
					intent.setType("image/*");//相片类型
					startActivityForResult(intent, type);
				}

				/**
				 * 开启裁剪Activity
				 * @param uri
				 */
				public void startPhotoZoom(Uri uri) {
					Intent intent = new Intent("com.android.camera.action.CROP");
					intent.setDataAndType(uri, "image/*");
					// 设置裁剪
					intent.putExtra("crop", "true");
					//宽高的比例
					intent.putExtra("aspectX", 1);
					intent.putExtra("aspectY", 1);
					//裁剪图片宽高
					intent.putExtra("outputX", 196);
					intent.putExtra("outputY", 196);
					intent.putExtra("return-data", true);
					intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
					startActivityForResult(intent, Type.SAVE_PROFILE);
				}

				/**
				 * 图片选择Activity回调
				 * @param requestCode
				 * @param resultCode
				 * @param data
				 */
				@Override
				protected void onActivityResult(int requestCode, int resultCode, Intent data) {
					super.onActivityResult(requestCode, resultCode, data);
					if (resultCode != RESULT_OK) {
						return;
					}
					switch (requestCode) {
						//设置头像,开启裁剪Activity
						case Type.CHANGE_IMG_PROFILE:
							Uri profileUri = data.getData();
							startPhotoZoom(profileUri);
							break;
						//设置背景图
						case Type.CHANGE_IMG_BG:
							Uri bgUri = data.getData();
							//保存背景图的Uri
							prefs.put("menu_bg_uri", bgUri.toString());
							Glide.with(MainActivity.this).load(bgUri).into(menuBgImg);
							break;
						//裁剪回调,设置头像并保存
						case Type.SAVE_PROFILE:
							if (data != null) {
								Bitmap bitmap = data.getParcelableExtra("data");
								profileImg.setImageBitmap(bitmap);
								saveProfile(bitmap);
							}
							break;
						default:
							break;
					}
				}

				/**
				 * 保存头像到SD卡
				 * @param bitmap
				 */
				private void saveProfile(Bitmap bitmap) {
					//保存到SD卡
					FileOutputStream fos = null;
					String fileName = getExternalFilesDir(Environment.DIRECTORY_PICTURES)
							+ "profile.jpg";
					try {
						fos = new FileOutputStream(fileName);
						bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos);
						fos.flush();
						fos.close();
						prefs.put("profile_path", fileName);
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
			}
	  

购买套餐

权益 套餐A 套餐B
完整代码
远程调试 不支持
代码答疑 不支持
价 格 ¥300 ¥460

------转载请注明出处,感谢您对原创作者的支持------

有偿提供技术支持、Bug修复、项目外包、毕业设计、大小作业

Android学习小站

Q Q:1095817610

微信:jx-helu

邮箱:1095817610@qq.com

添加请备注"Android学习小站"