Design and implementation of Finance app

I. Main Interface

  1. Interface Effect

   2. Preparations

(1) Create a folder under the project package name Select the package name of the project - right-click - new - package - append the input activity after the current content - click the ok button to generate the activity folder.

(2) Create six subpages in the activity folder to select the activity folder, right-click --- new - activity - Empty Activity --- enter the class name: InComeActivity --- click the ok button.

   3. Main Interface Layout activity_main.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=".view.MainActivity">
     <ImageButton
         android:layout_width="match_parent"
         android:layout_height="250dp"
         android:background="@drawable/main_top"/>
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="horizontal"
         android:layout_marginTop="40dp"
         android:gravity="center">
         <Button
             android:id="@+id/bt_newincome_main"
             android:layout_width="90dp"
             android:layout_height="90dp"
             android:background="@drawable/new_pay_in"
             android:layout_marginRight="50dp"/>
         <Button
             android:id="@+id/bt_incomedetail_main"
             android:layout_width="90dp"
             android:layout_height="90dp"
             android:background="@drawable/my_pay_in"
             android:layout_marginRight="50dp"/>
         <Button
             android:id="@+id/bt_newpay_main"
             android:layout_width="90dp"
             android:layout_height="90dp"
             android:background="@drawable/new_pay_out" />
     </LinearLayout>
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="horizontal"
         android:layout_marginTop="20dp"
         android:gravity="center">
         <TextView
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="New Income"
             android:textSize="15sp"
             android:textColor="#ffffff"
             android:layout_marginRight="80dp"/>
         <TextView
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="Detailed Income"
             android:textSize="15sp"
             android:textColor="#ffffff"
             android:layout_marginRight="80dp"/>
         <TextView
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="New Expenses"
             android:textSize="15sp"
             android:textColor="#ffffff"/>
     </LinearLayout>
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="horizontal"
         android:layout_marginTop="40dp"
         android:gravity="center">
         <Button
             android:id="@+id/bt_paydetail_main"
             android:layout_width="90dp"
             android:layout_height="90dp"
             android:background="@drawable/my_pay_out"
             android:layout_marginRight="50dp"/>
         <Button
             android:id="@+id/bt_dataanalyse_main"
             android:layout_width="90dp"
             android:layout_height="90dp"
             android:background="@drawable/data_administration"
             android:layout_marginRight="50dp"/>
         <Button
             android:id="@+id/bt_syssetting_main"
             android:layout_width="90dp"
             android:layout_height="90dp"
             android:background="@drawable/sys_setting" />
     </LinearLayout>
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="horizontal"
         android:layout_marginTop="20dp"
         android:gravity="center">
         <TextView
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="Expense Details"
             android:textSize="15sp"
             android:textColor="#ffffff"
             android:layout_marginRight="80dp"/>
         <TextView
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="Data analysis"
             android:textSize="15sp"
             android:textColor="#ffffff"
             android:layout_marginRight="80dp"/>
         <TextView
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="System Settings"
             android:textSize="15sp"
             android:textColor="#ffffff"/>
     </LinearLayout>
</LinearLayout>

   4. Main interface class file MainActivity.java

public class MainActivity extends AppCompatActivity {
//Define Objects
     Button bt_newincome,bt_incomedetail,btn_newpay,btn_paydetail,bt_dataanalyse,btn_setting;
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
         // Bind Control
         initView();
         //Button Click Event
         btnOnClick();
     }
     // Bind Controls------------------------------------------------------- Code
     private void initView() {
         bt_newincome=findViewById(R.id.bt_newincome_main);
         bt_incomedetail=findViewById(R.id.bt_incomedetail_main);
         btn_newpay=findViewById(R.id.bt_newpay_main);
         btn_paydetail=findViewById(R.id.bt_paydetail_main);
         bt_dataanalyse=findViewById(R.id.bt_dataanalyse_main);
         btn_setting=findViewById(R.id.bt_syssetting_main);
     }
     //Button Click Event--------------------------------- Code
     private void btnOnClick() {
         bt_newincome.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 Intent intent=new Intent(MainActivity.this, NewInComeActivity.class);
                 startActivity(intent);
             }
         });
         bt_incomedetail.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 Intent intent=new Intent(MainActivity.this, InComeDetailActivity.class);
                 startActivity(intent);
             }
         });
         btn_newpay.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 Intent intent=new Intent(MainActivity.this, NewPayActivity.class);
                 startActivity(intent);
             }
         });
         btn_paydetail.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 Intent intent=new Intent(MainActivity.this, PayDetailActivity.class);
                 startActivity(intent);
             }
         });
         bt_dataanalyse.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 Intent intent=new Intent(MainActivity.this, DataAnalyseActivity.class);
                 startActivity(intent);
             }
         });
         btn_setting.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 Intent intent=new Intent(MainActivity.this, SysSettingActivity.class);
                 startActivity(intent);
             }
         });
     }
}

   5. Code Explanation

    ImageButton is used in the project, but when you set the specific size of the picture, you find that it is still the original size, and then you can turn the ImageButton into an ImageView.First, let's look at the difference between the two from the source point of view.

ImageView inherits View         ImageButton inherits ImageView

    Let's analyze the differences between the two in several different situations.

    1. Neither set the specific width or height.

    It shows no difference.

    2. Specific width and height are set.

    ImageView changes in size depending on the width and height of the image, but ImageButton only shows the original pixel size of the image.ImageView works if you set the scaleType property on ImageButton, but the picture will be distorted.

    3. Set the background selector.

    ImageView requires the control to be focused in order for the selector effect to take effect.You need to add android:clickable=true;

    ImageButton does not need to be processed because setFocusable(true) has already been set in the constructor of ImageButton in the source code.

    4. Settings background No specific width or height.

     The effect is the same.

    5. Set background s with specific width and height.

     The effect is the same.Unlike src, both of them change with specific width and height.

2. New revenue interface

  1. Interface Effect

  2. preparation in advance

    (1) Prepare data for spinner controls

(1) Create a new xml file under values, as follows:

 (2) Add two string numbers to the file

 (3) Referencing an array of strings with the entries attribute in the layout file

    (2) Add income and expense tables to the database file

//Create an income table
 db.execSQL("create table in_come(id integer primary key autoincrement,inmoney double,intime varchar(20),intype varchar(30),inpayer varchar(100),inremark varchar(500))");
//Create an expense table
db.execSQL("create table out_pay(id integer primary key autoincrement,outmoney double,outtime varchar(20),outtype varchar(30),outpayee varchar(100),outremark varchar(500))");

  3. New Revenue Layout Interface activity_new_income.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/new_income_bg"
     tools:context=".activity.NewInComeActivity">
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="horizontal"
         android:layout_marginTop="220dp"
         android:layout_marginLeft="30dp"
         android:layout_marginRight="30dp">
         <TextView
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="Amount of money:"
             android:textColor="#000000"
             android:textSize="20sp"
             android:textStyle="bold"/>
         <EditText
             android:id="@+id/et_money_newin"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:hint="0.00"
             android:textColor="#000000"
             android:textSize="20sp"
             android:textStyle="bold"
             android:gravity="center"/>
     </LinearLayout>
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="horizontal"
         android:layout_marginTop="10dp"
         android:layout_marginLeft="30dp"
         android:layout_marginRight="30dp">
         <TextView
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="Date:"
             android:textColor="#000000"
             android:textSize="20sp"
             android:textStyle="bold"/>
         <EditText
             android:id="@+id/et_time_newin"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:hint="2020-05-12"
             android:textColor="#000000"
             android:textSize="20sp"
             android:textStyle="bold"
             android:gravity="center"/>
     </LinearLayout>
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="horizontal"
         android:layout_marginTop="10dp"
         android:layout_marginLeft="30dp"
         android:layout_marginRight="30dp">
         <TextView
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="Type:"
             android:textColor="#000000"
             android:textSize="20sp"
             android:textStyle="bold"/>
         <Spinner
             android:id="@+id/sp_type_newin"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:entries="@array/incometype"/>
     </LinearLayout>
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="horizontal"
         android:layout_marginTop="10dp"
         android:layout_marginLeft="30dp"
         android:layout_marginRight="30dp">
         <TextView
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="Payer:"
             android:textColor="#000000"
             android:textSize="20sp"
             android:textStyle="bold"/>
         <EditText
             android:id="@+id/et_payer_newin"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:hint="Haiming Company Limited"
             android:textColor="#000000"
             android:textSize="20sp"
             android:textStyle="bold"
             android:gravity="center"/>
     </LinearLayout>
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="horizontal"
         android:layout_marginTop="10dp"
         android:layout_marginLeft="30dp"
         android:layout_marginRight="30dp">
         <TextView
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="Remarks:"
             android:textColor="#000000"
             android:textSize="20sp"
             android:textStyle="bold"/>
         <EditText
             android:id="@+id/et_remark_newin"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:hint="Remote Technical Guidance Fee"
             android:textColor="#000000"
             android:textSize="20sp"
             android:textStyle="bold"
             android:gravity="center"/>
     </LinearLayout>
     <Button
         android:id="@+id/bt_save_newin"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:text="Preservation"
         android:textSize="20sp"
         android:textColor="#ffffff"
         android:layout_marginLeft="60dp"
         android:layout_marginRight="60dp"
         android:background="@drawable/btn_style_one"
         android:layout_marginTop="40dp"/>
     <Button
         android:id="@+id/bt_cancel_newin"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:text="cancel"
         android:textSize="20sp"
         android:textColor="#000000"
         android:layout_marginLeft="60dp"
         android:layout_marginRight="60dp"
         android:background="@drawable/btn_style_two"
         android:layout_marginTop="20dp"/>
</LinearLayout>

  4. New Income File NewInComeActivity.java

public class NewInComeActivity extends AppCompatActivity {
//1 Define Objects
     EditText et_money,et_time,et_payer,et_remark;
     Spinner sp_type;
     Button bt_sava,bt_cancel;
     MyDBHelper mhelper;
     SQLiteDatabase db;
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_new_in_come);
         //2 Bind controls
         initView();
         //3 Implementation of Save Button Function
         btnSave();
         //4 Implementation of Cancel Button Function
         btnCancel();
     }
     //2 Bind Controls------------------------------------- Code
     private void initView() {
         et_money=findViewById(R.id.et_money_newin);
         et_time=findViewById(R.id.et_time_newin);
         sp_type=findViewById(R.id.sp_type_newin);
         et_payer=findViewById(R.id.et_payer_newin);
         et_remark=findViewById(R.id.et_remark_newin);
         bt_sava=findViewById(R.id.bt_save_newin);
         bt_cancel=findViewById(R.id.bt_cancel_newin);
         mhelper=new MyDBHelper(NewInComeActivity.this);
         db=mhelper.getWritableDatabase();
     }
     //3 Realization of Save Button Function-------Code
     private void btnSave() {
         bt_sava.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 //Get the input and save it in the revenue table of the database
                 ContentValues values=new ContentValues();
                 values.put("inmoney",et_money.getText().toString());
                 values.put("intime",et_time.getText().toString());
                 values.put("intype",sp_type.getSelectedItem().toString());
                 values.put("inpayer",et_payer.getText().toString());
                 values.put("inremark",et_remark.getText().toString());
                 db.insert("in_come",null,values);
                 Toast.makeText(NewInComeActivity.this,"Save Successfully",Toast.LENGTH_SHORT).show();
                 //Refresh this page
                 Intent intent=new Intent(NewInComeActivity.this,NewInComeActivity.class);
                 startActivity(intent);
                 finish();
             }
         });
     }
     //4 Cancel the implementation of button function-------Code
     private void btnCancel() {
         bt_cancel.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 Intent intent=new Intent(NewInComeActivity.this, MainActivity.class);
                 startActivity(intent);
                 finish();
             }    
         });
     }
}

3. New Expense Interface

  1. Interface Effect

   3. New Expense Layout Interface activity_new_pay.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/new_pay_bg"
     tools:context=".activity.NewPayActivity">
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="horizontal"
         android:layout_marginTop="220dp"
         android:layout_marginLeft="30dp"
         android:layout_marginRight="30dp">
         <TextView
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="Amount of money:"
             android:textColor="#000000"
             android:textSize="20sp"
             android:textStyle="bold"/>
         <EditText
             android:id="@+id/et_money_newout"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:hint="0.00"
             android:textColor="#000000"
             android:textSize="20sp"
             android:textStyle="bold"
             android:gravity="center"/>
     </LinearLayout>
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="horizontal"
         android:layout_marginTop="10dp"
         android:layout_marginLeft="30dp"
         android:layout_marginRight="30dp">
         <TextView
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="Date:"
             android:textColor="#000000"
             android:textSize="20sp"
             android:textStyle="bold"/>
         <EditText
             android:id="@+id/et_time_newout"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:hint="2020-05-12"
             android:textColor="#000000"
             android:textSize="20sp"
             android:textStyle="bold"
             android:gravity="center"/>
     </LinearLayout>
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="horizontal"
         android:layout_marginTop="10dp"
         android:layout_marginLeft="30dp"
         android:layout_marginRight="30dp">
         <TextView
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="Type:"
             android:textColor="#000000"
             android:textSize="20sp"
             android:textStyle="bold"/>
         <Spinner
             android:id="@+id/sp_type_newout"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:entries="@array/paytype"/>
     </LinearLayout>
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="horizontal"
         android:layout_marginTop="10dp"
         android:layout_marginLeft="30dp"
         android:layout_marginRight="30dp">
         <TextView
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="Payee:"
             android:textColor="#000000"
             android:textSize="20sp"
             android:textStyle="bold"/>
         <EditText
             android:id="@+id/et_payer_newout"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:hint="Haiming Company Limited"
             android:textColor="#000000"
             android:textSize="20sp"
             android:textStyle="bold"
             android:gravity="center"/>
     </LinearLayout>
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="horizontal"
         android:layout_marginTop="10dp"
         android:layout_marginLeft="30dp"
         android:layout_marginRight="30dp">
         <TextView
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="Remarks:"
             android:textColor="#000000"
             android:textSize="20sp"
             android:textStyle="bold"/>
         <EditText
             android:id="@+id/et_remark_newout"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:hint="Remote Technical Guidance Fee"
             android:textColor="#000000"
             android:textSize="20sp"
             android:textStyle="bold"
             android:gravity="center"/>
     </LinearLayout>
     <Button
         android:id="@+id/bt_save_newout"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:text="Preservation"
         android:textSize="20sp"
         android:textColor="#ffffff"
         android:layout_marginLeft="60dp"
         android:layout_marginRight="60dp"
         android:background="@drawable/btn_style_one"
         android:layout_marginTop="40dp"/>
     <Button
         android:id="@+id/bt_cancel_newout"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:text="cancel"
         android:textSize="20sp"
         android:textColor="#000000"
         android:layout_marginLeft="60dp"
         android:layout_marginRight="60dp"
         android:background="@drawable/btn_style_two"
         android:layout_marginTop="20dp"/>
</LinearLayout>

 4. New Expense Class File NewPayActivity.java

public class NewPayActivity extends AppCompatActivity {
//Define Objects
EditText et_money,et_time,et_payer,et_remark;
     Spinner sp_type;
     Button bt_sava,bt_cancel;
     MyDBHelper mhelper;
     SQLiteDatabase db;
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_new_pay);
         //2 Bind controls
         initView();
         //3 Implementation of Save Button Function
         btnSave();
         //4 Implementation of Cancel Button Function
         btnCancel();
     }
     //2 Bind Controls------------------------------------- Code
     private void initView() {
         et_money=findViewById(R.id.et_money_newout);
         et_time=findViewById(R.id.et_time_newout);
         sp_type=findViewById(R.id.sp_type_newout);
         et_payer=findViewById(R.id.et_payer_newout);
         et_remark=findViewById(R.id.et_remark_newout);
         bt_sava=findViewById(R.id.bt_save_newout);
         bt_cancel=findViewById(R.id.bt_cancel_newout);
         mhelper=new MyDBHelper(NewPayActivity.this);
         db=mhelper.getWritableDatabase();
     }
     //3 Realization of Save Button Function-------Code
     private void btnSave() {
         bt_sava.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 //Get the input and save it in the revenue table of the database
                 ContentValues values=new ContentValues();
                 values.put("outmoney",et_money.getText().toString());
                 values.put("outtime",et_time.getText().toString());
                 values.put("outtype",sp_type.getSelectedItem().toString());
                 values.put("outpayee",et_payer.getText().toString());
                 values.put("outremark",et_remark.getText().toString());
                 db.insert("pay_out",null,values);
                 Toast.makeText(NewPayActivity.this,"Save Successfully",Toast.LENGTH_SHORT).show();
                 //Refresh this page
                 Intent intent=new Intent(NewPayActivity.this,NewPayActivity.class);
                 startActivity(intent);
                 finish();
             }
         });
     }
     //4 Cancel the implementation of button function-------Code
     private void btnCancel() {
         bt_cancel.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 Intent intent=new Intent(NewPayActivity.this, MainActivity.class);
                 startActivity(intent);
                 finish();
             }
         });
     }
}

Tags: Java Android Android Studio SQLite Vue.js

Posted on Sat, 04 Sep 2021 12:29:23 -0400 by temujinleal