理财通app的设计与实现(四)

一、数据分析界面

  1、界面效果

 2、前期准备

    2.1 首先添加 AndroidMPChart 的依赖

(1)在素材文件夹中,选择 jar 包文件:MPAndroidChart-v3.0.3.jar,复制该 文件。

 (2)展开 Android 的工程目录结构,在 app 下方,选择 libs 文件夹,将 jar 包文件粘贴到此文件夹下如图所示:

 (3)展开 Android 的工程目录结构,在 app 下方,打开 build.grandle 文件, 便看到了下方添加进来的依赖

  3、数据分析布局界面 activity_data_analysel.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
     android:layout_height="match_parent"
     android:orientation="vertical"
     android:background="@drawable/welcomebg"
     tools:context=".activity.DataAnalyseActivity">
<TextView
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:text="个人收入预览图"
     android:textColor="#ffffff"
     android:textStyle="bold"
     android:textSize="25sp"
     android:gravity="center"/>
     <com.github.mikephil.charting.charts.LineChart
         android:id="@+id/income_chart_data"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_weight="1"/>
     <View
         android:layout_width="match_parent"
         android:layout_height="2dp"
         android:background="#ffffff"/>
         <TextView
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:text="个人支出预览图"
             android:textColor="#ffffff"
             android:textStyle="bold"
             android:textSize="25sp"
             android:gravity="center"/>
         <com.github.mikephil.charting.charts.LineChart
             android:id="@+id/outpay_chart_data"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_weight="1"/>
</LinearLayout>

  4、数据分析类文件 DataAnalyseActivity.java

public class DataAnalyseActivity extends AppCompatActivity {
//1 定义对象
     LineChart income_chart,outpay_chart;
     MyDBHelper mhelper;
     SQLiteDatabase db;
     String[] indata={"学习-奖金","补助-奖金","比赛-奖励","业余-兼职","基本工资","福利-分红","加班-津贴","其他"};
     //收入类型数据统计的初始值
     int xxjjmoney=0;
     int bzjjmoney=0;
     int bsjlmoney=0;
     int yyjzmoney=0;
     int jbgzmoney=0;
     int flfhmoney=0;
     int jbjtmoney=0;
     int qtmoney=0;
     String[] outdata={"电影-娱乐","美食-畅饮","欢乐-购物","手机-充值","交通-出行","教育-培训","社交-礼仪","生活-日用","其他"};
     //收入类型数据统计的初始值
     int dyylmoney=0;
     int mscymoney=0;
     int hlgwmoney=0;
     int sjczmoney=0;
     int jtcxmoney=0;
     int jypxmoney=0;
     int sjlymoney=0;
     int shrymoney=0;
     int othermoney=0;
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_data_analyse);
         //2 绑定控件
         initView();
         //3 收入汇总分析
         inComeData();
         //4 支出汇总分析
         outComeData();
     }
     //2 绑定控件---------------代码
     private void initView() {
         income_chart=findViewById(R.id.income_chart_data);
         outpay_chart=findViewById(R.id.outpay_chart_data);
         mhelper=new MyDBHelper(DataAnalyseActivity.this);
         db=mhelper.getWritableDatabase();
     }
     //3 收入汇总分析-------------------代码
     private void inComeData() {
         //第一部分:获取数据
         Cursor cursor =db.rawQuery("select * from in_come",null);
         while(cursor.moveToNext()){
             Double mymoney=cursor.getDouble(cursor.getColumnIndex("inmoney"));
             String mytype=cursor.getString(cursor.getColumnIndex("intype"));
             if(mytype.equals("学习-奖金")){
                 xxjjmoney+=mymoney;
             }else if(mytype.equals("补助-奖金")){
                 bzjjmoney+=mymoney;
             }else if(mytype.equals("比赛-奖励")){
                 bzjjmoney+=mymoney;
             }else if(mytype.equals("业余-兼职")){
                 yyjzmoney+=mymoney;
             }else if(mytype.equals("基本-工资")){
                 jbgzmoney+=mymoney;
             }else if(mytype.equals("福利-分红")){
                 flfhmoney+=mymoney;
             }else if(mytype.equals("加班-津贴")){
                 jbjtmoney+=mymoney;
             }else if(mytype.equals("其他")){
                 qtmoney+=mymoney;
             }
         }
         //第二部分:LineChart 图表初始化设置---Xy 轴的设置
             XAxis xAxis=income_chart.getXAxis();//获取此图表的 x 轴轴线
             YAxis yAxisleft =income_chart.getAxisLeft();//获取此图表的 Y 轴左侧轴线
             YAxis yAxisright =income_chart.getAxisRight();//获取此图表的 Y轴右侧轴线
             xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);//设置 X 轴线的位置为底部
             yAxisleft.setAxisMinimum(0f);//保证 Y 轴从 0 开始,不然会上移一点。
             yAxisright.setAxisMinimum(0f);
             xAxis.setValueFormatter(new IAxisValueFormatter() {//x 轴自定义标签的设置
             @Override
             public String getFormattedValue(float v, AxisBase axisBase) {
                 return indata[(int) v];
             }
         });
         //第三部分:LineDataSet 曲线初始化设置
         List<Entry> inentries=new ArrayList<>();//Y 轴的数据
         inentries.add(new Entry(0,xxjjmoney));
         inentries.add(new Entry(1,bzjjmoney));
         inentries.add(new Entry(2,bsjlmoney));
         inentries.add(new Entry(3,yyjzmoney));
         inentries.add(new Entry(4,jbgzmoney));
         inentries.add(new Entry(5,flfhmoney));
         inentries.add(new Entry(6,jbjtmoney));
         inentries.add(new Entry(7,qtmoney));
         LineDataSet lineDataSet=new LineDataSet(inentries,"金额");//代表一条线,“金额”是曲线名称
         lineDataSet.setValueTextSize(25);//曲线上文字的大小
         lineDataSet.setValueTextColor(Color.WHITE);//曲线上文字的颜色
         lineDataSet.setDrawFilled(true);//设置折线图填充
         //第四部分:曲线展示
         LineData data=new LineData(lineDataSet);//创建 LineData 对象 属于LineChart 折线图的数据集合
         income_chart.setData(data);// 添加到图表中
     }
     //4 支出汇总分析--------------------代码
     private void outComeData() {
         //第一部分:获取数据
         Cursor cursor =db.rawQuery("select * from pay_out",null);
         while(cursor.moveToNext()){
             Double mymoney=cursor.getDouble(cursor.getColumnIndex("outmoney"));
             String mytype=cursor.getString(cursor.getColumnIndex("outtype"));
             if(mytype.equals("电影-娱乐")){
                 dyylmoney+=mymoney;
             }else if(mytype.equals("美食-畅饮")){
                 mscymoney+=mymoney;
             }else if(mytype.equals("欢乐-购物")){
                 hlgwmoney+=mymoney;
             }else if(mytype.equals("手机-充值")){
                 sjczmoney+=mymoney;
             }else if(mytype.equals("交通-出行")){
                 jtcxmoney+=mymoney;
             }else if(mytype.equals("教育-培训")){
                 jypxmoney+=mymoney;
             }else if(mytype.equals("社交-礼仪")){
                 sjlymoney+=mymoney;
             }else if(mytype.equals("生活-日用")){
                 shrymoney+=mymoney;
             }else if(mytype.equals("其他")){
                 othermoney+=mymoney;
             }
         }
         //第二部分:LineChart 图表初始化设置---Xy 轴的设置
         XAxis xAxis=outpay_chart.getXAxis();//获取此图表的 x 轴轴线
         YAxis yAxisleft =outpay_chart.getAxisLeft();//获取此图表的 Y 轴左侧轴线
         YAxis yAxisright =outpay_chart.getAxisRight();//获取此图表的 Y 轴右侧轴线
         xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);//设置 X 轴线的位置为底部
         yAxisleft.setAxisMinimum(0f);//保证 Y 轴从 0 开始,不然会上移一点。
         yAxisright.setAxisMinimum(0f);
         xAxis.setValueFormatter(new IAxisValueFormatter() {//x 轴自定义标签的设置
             @Override
             public String getFormattedValue(float v, AxisBase axisBase) {
                 return outdata[(int) v];
             }
         });
         //第三部分:LineDataSet 曲线初始化设置
         List<Entry> outentries=new ArrayList<>();//Y 轴的数据
         outentries.add(new Entry(0,dyylmoney));
         outentries.add(new Entry(1,mscymoney));
         outentries.add(new Entry(2,hlgwmoney));
         outentries.add(new Entry(3,sjczmoney));
         outentries.add(new Entry(4,jtcxmoney));
         outentries.add(new Entry(5,jypxmoney));
         outentries.add(new Entry(6,sjlymoney));
         outentries.add(new Entry(7,shrymoney));
         outentries.add(new Entry(8,othermoney));
         LineDataSet lineDataSet=new LineDataSet(outentries,"金额");//代表一条线,“金额”是曲线名称
         lineDataSet.setValueTextSize(25);//曲线上文字的大小
         lineDataSet.setValueTextColor(Color.WHITE);//曲线上文字的颜色
         lineDataSet.setDrawFilled(true);//设置折线图填充
         //第四部分:曲线展示
         LineData data=new LineData(lineDataSet);//创建 LineData 对象 属于LineChart 折线图的数据集合
         outpay_chart.setData(data);// 添加到图表中
     }
}

  5、AndroidMPChart的步骤

第一步:获取数据

第二步:LineChart 图表初始化设置---Xy 轴的设置

第三步:LineDataSet 曲线初始化设置

第四步:曲线展示

二、系统设置界面

  1、界面效果

   2、前期准备

2.1 打开配置文件,将程序启动的四行代码放到欢迎界面的开始节点与结束节点 之间。

 (2)打开登录界面 LoginActivity.java,在用户名和密码正确时,添加代码, 实现用户名和密码存储到一个键值对里面。

SharedPreferences.Editor editor=getSharedPreferences("userinfo",0).edit(); editor.putString("username",inputname); editor.putString("userpwd",inputpwd); editor.commit();

   3、系统设置布局界面 activity_sys_setting.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
     android:layout_height="match_parent"
     android:orientation="vertical"
     android:background="@drawable/welcomebg"
     tools:context=".activity.SysSettingActivity">
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="horizontal"
         android:layout_marginLeft="10dp">
         <TextView
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="当前用户:"
             android:textColor="#ffffff"/>
         <TextView
             android:id="@+id/txt_name_sys"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:textColor="#ffffff"/>
     </LinearLayout>
     <TextView
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:text="用户密码修改"
         android:textSize="30sp"
         android:textStyle="bold"
         android:textColor="#ffffff"
         android:layout_margin="80dp"
         android:gravity="center"/>
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="horizontal"
         android:layout_marginLeft="20dp"
         android:layout_marginRight="20dp">
         <TextView
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="原始密码:"
             android:textColor="#ffffff"/>
         <EditText
             android:id="@+id/et_ypwd_sys"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:hint="请输入原密码"
             android:textColor="#ffffff"/>
     </LinearLayout>
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="horizontal"
         android:layout_marginLeft="20dp"
         android:layout_marginRight="20dp">
         <TextView
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="新 密 码:"
             android:textColor="#ffffff"/>
         <EditText
             android:id="@+id/et_xpwd_sys"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:hint="请输入新密码"
             android:textColor="#ffffff"/>
     </LinearLayout>
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="horizontal"
         android:layout_marginLeft="20dp"
         android:layout_marginRight="20dp">
         <TextView
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="再次输入:"
             android:textColor="#ffffff"/>
         <EditText
             android:id="@+id/et_zxpwd_sys"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:hint="请再次输入新密码"
             android:textColor="#ffffff"/>
     </LinearLayout>
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="horizontal"
         android:layout_marginLeft="20dp"
         android:layout_marginRight="20dp"
         android:layout_marginTop="80dp">
         <Button
             android:id="@+id/bt_modify_sys"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="确认修改"
             android:textColor="#000000"
             android:background="@drawable/btn_style_two"
             android:layout_marginRight="40dp"
             android:layout_weight="1"/>
         <Button
             android:id="@+id/bt_cancel_sys"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="取消"
             android:textColor="#000000"
             android:background="@drawable/btn_style_two"
             android:layout_weight="1"/>
     </LinearLayout>
</LinearLayout>

   4、数据分析类文件 DataAnalyseActivity.java

public class SysSettingActivity extends AppCompatActivity {
     //1 定义对象
     TextView txt_user;//创建一个显示用户名的文本对象
     EditText et_ypwd, et_xpwd, et_zxpwd;// 创建三个 EditText 对象
     Button bt_modify, bt_cancel;// 创建两个 Button 对象
     MyDBHelper mhelper;
     SQLiteDatabase db;
     String name;
     String pwd;
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_sys_setting);
         //第二步:绑定控件
         initView();
         //第三步:显示当前登录的用户名
         displayInfo();
         //第四步:修改按钮功能
         btnModify();
         //第五步:取消按钮功能
         btncancel();
     }
     //第二步:绑定控件-----------------代码
     private void initView() {
         txt_user=findViewById(R.id.txt_name_sys);
         et_ypwd=findViewById(R.id.et_ypwd_sys);
         et_xpwd=findViewById(R.id.et_xpwd_sys);
         et_zxpwd=findViewById(R.id.et_zxpwd_sys);
         bt_modify=findViewById(R.id.bt_modify_sys);
         bt_cancel=findViewById(R.id.bt_cancel_sys);
         mhelper=new MyDBHelper(SysSettingActivity.this);
         db=mhelper.getWritableDatabase();
     }
     //第三步:显示当前登录的用户名-------代码
     private void displayInfo() { 
         name=getSharedPreferences("userinfo",0).getString("username",""); 
         pwd=getSharedPreferences("userinfo",0).getString("userpwd","");
         txt_user.setText(name);
     }
     //第四步:修改按钮功能----------------------代码
     private void btnModify() {
         bt_modify.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 //获取三个输入框中的内容
                 String ypwd = et_ypwd.getText().toString();//获取输入的原密码
                 String xpwd = et_xpwd.getText().toString();//获取输入的新密码
                 String zxpwd = et_zxpwd.getText().toString();//获取第二次输入的新密码
                 //对每个密码进行逻辑判断
                 if(ypwd.equals("")){
                     Toast.makeText(SysSettingActivity.this, "请输入原始密码", Toast.LENGTH_SHORT).show();
                 }else if(!ypwd.equalsIgnoreCase(pwd)){
                     Toast.makeText(SysSettingActivity.this, "输入的密码与原密码不一致",Toast.LENGTH_SHORT).show();
                 }else if(xpwd.equals("")){
                     Toast.makeText(SysSettingActivity.this, "请输入新密码", Toast.LENGTH_SHORT).show();
                 }else if(xpwd.equalsIgnoreCase(ypwd)){
                     Toast.makeText(SysSettingActivity.this, "所输入的新密码与原密码不能相同", Toast.LENGTH_SHORT).show();
                 }else if(zxpwd.equals("")){
                     Toast.makeText(SysSettingActivity.this, "请再次输入新密码", Toast.LENGTH_SHORT).show();
                 }else if(!zxpwd.equalsIgnoreCase(xpwd)){
                     Toast.makeText(SysSettingActivity.this, "两次输入的新密码不一致",Toast.LENGTH_SHORT).show();
                 }else{
                     ContentValues values =new ContentValues();
                     values.put("pwd",xpwd);
                     db.update("tb_userinfo",values,"name=?",new String[]{name});
                     Toast.makeText(SysSettingActivity.this, "密码修改成功", Toast.LENGTH_SHORT).show();
                     Intent intent=new Intent(SysSettingActivity.this,                   LoginActivity.class);
                     startActivity(intent);
                     finish();
                 }
             }
         });
     }
     //第五步:取消按钮功能-----------------------代码
     private void btncancel() {
         bt_cancel.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 Intent intent=new Intent(SysSettingActivity.this, MainActivity.class);
                 startActivity(intent);
                 finish();
             }
         });
     }
}

  • 3
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

撩得Android一次心动

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值