Android - Home bookkeeping 6

Posted by Roxie on Sat, 05 Feb 2022 05:05:13 +0100

Yesterday, the function of recording revenue and expenditure was completed, and the details were improved. The time can be recorded and notes can be added. To complete this function, the time calendar control and a layout layout are also required.

Today, after completing the search function of the main interface, first create a layout

 

 

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="50dp">
        <ImageView
            android:id="@+id/search_iv_back"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:onClick="onClick"
            android:layout_marginLeft="10dp"
            android:src="@mipmap/it_back"/>
        <EditText
            android:id="@+id/search_et"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/search_iv_back"
            android:background="@drawable/dialog_btn_bg"
            android:layout_centerVertical="true"
            android:textSize="16sp"
            android:paddingTop="10dp"
            android:paddingLeft="20dp"
            android:layout_marginLeft="10dp"
            android:hint="@string/search_info">
            <requestFocus/>
        </EditText>
        <ImageView
            android:id="@+id/search_iv_sh"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@mipmap/search"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:paddingRight="20dp"
            android:onClick="onClick"/>
    </RelativeLayout>
    <ListView
        android:id="@+id/search_lv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:dividerHeight="6dp"
        android:divider="@color/grey_f3f3f3" />
    <TextView
        android:id="@+id/search_tv_empty"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/data_empty"
        android:gravity="center"
        android:textSize="22sp"
        android:drawableTop="@mipmap/it_searchtext"
        android:layout_marginTop="250dp"/>


</LinearLayout>

 

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@color/grey_f3f3f3">

    <RelativeLayout
        android:id="@+id/main_top_layout"
        android:layout_width="match_parent"
        android:layout_height="50dp">

        <TextView
            android:text="@string/app_name"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:gravity="center"
            android:padding="10dp"
            android:textStyle="bold"
            android:textSize="20sp"
            android:textColor="@color/black"/>
        <ImageView
            android:id="@+id/main_iv_search"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:src="@mipmap/search"
            android:layout_alignParentRight="true"
            android:padding="10dp"/>
    </RelativeLayout>
    <ListView
        android:id="@+id/main_lv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/main_top_layout"
        android:padding="10dp"
        android:divider="@null"
        android:dividerHeight="6dp"
        android:scrollbars="none"
        android:background="@color/grey_f3f3f3"/>
    <ImageButton
        android:id="@+id/main_btn_more"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:src="@mipmap/more"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"
        android:layout_margin="20dp"
        android:background="@drawable/main_morebtn_bg"/>
    <Button
        android:id="@+id/main_btn_edit"
        android:layout_width="100dp"
        android:layout_height="50dp"
        android:layout_alignBottom="@id/main_btn_more"
        android:background="@drawable/main_record_bg"
        android:layout_toLeftOf="@id/main_btn_more"
        android:text="@string/editone"
        android:textStyle="bold"
        android:textColor="@color/white"
        android:drawableLeft="@mipmap/edit"
        android:gravity="center_vertical"/>
</RelativeLayout>

After completing this layout, define the method directly in DBManger to search the records of consumption and income through comments

//Search records based on notes
    public static List<AccountBean> getAccountListByRemark(String beizhu){
        List<AccountBean> list = new ArrayList<>();
        String sql = "select * from accounttb where beizhu like '%"+beizhu+"%'";
        Cursor cursor = db.rawQuery(sql,null);
        while (cursor.moveToNext()){
            int id = cursor.getInt(cursor.getColumnIndex("id"));
            String typename = cursor.getString(cursor.getColumnIndex("typename"));
            String bz = cursor.getString(cursor.getColumnIndex("beizhu"));
            String time = cursor.getString(cursor.getColumnIndex("time"));
            int simageId = cursor.getInt(cursor.getColumnIndex("simageId"));
            int kind = cursor.getInt(cursor.getColumnIndex("kind"));
            float money = cursor.getFloat(cursor.getColumnIndex("money"));
            int year = cursor.getInt(cursor.getColumnIndex("year"));
            int month = cursor.getInt(cursor.getColumnIndex("month"));
            int day = cursor.getInt(cursor.getColumnIndex("day"));
            AccountBean accountBean = new AccountBean(id,typename,simageId,bz,money,time,year,month,day,kind);
            list.add(accountBean);
        }
        return list;
    }

In this method, I pass the searched data into a List collection.

The background code of the search function has been completed. Before interacting with the foreground, list the possible situations:

① Before the user searches for data, the data cannot be displayed. Here I use a layout to display it.

② The user searches without entering data, prompting the user not to enter empty data.

Show pages without data

 

<TextView
        android:id="@+id/search_tv_empty"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/data_empty"
        android:gravity="center"
        android:textSize="22sp"
        android:drawableTop="@mipmap/it_searchtext"
        android:layout_marginTop="250dp"/>

Prompt the user that empty data cannot be entered

This is implemented directly in code, similar to the confirm() in JS

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search);
        initView();
        mDatas = new ArrayList<>();
        adapter = new AccountAdapter(this,mDatas);
        searchLv.setAdapter(adapter);
        searchLv.setEmptyView(emptyTv);//Sets the control to display when there is no data
    }

    private void initView() {
        searchEt = findViewById(R.id.search_et);
        searchLv = findViewById(R.id.search_lv);
        emptyTv = findViewById(R.id.search_tv_empty);
    }

    public void onClick(View view){
        switch (view.getId()) {
            case R.id.search_iv_back:
                finish();
                break;
            case R.id.search_iv_sh://Perform a search operation
                String msg = searchEt.getText().toString().trim();
                //Judge whether the input content is empty and prompt
                if(TextUtils.isEmpty(msg)){
                    Toast.makeText(this,"The input content cannot be empty",Toast.LENGTH_SHORT).show();;
                    return;
                }
                //Start search
                List<AccountBean> list = DBManger.getAccountListByRemark(msg);
                mDatas.clear();
                mDatas.addAll(list);
                adapter.notifyDataSetChanged();
                break;
        }
    }

After this function is realized, the following layout in the main interface is realized

 

There are 6 controls in total. The eyes have the function of hiding and displaying. You can view all your accounting records by viewing the chart. Click budget to set the budget of this month and add or subtract according to consumption. First implement this layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/grey_f3f3f3">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/white"
    android:padding="20dp">
    <TextView
        android:id="@+id/item_mainlv_top_tv1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/month_out"/>
    <TextView
        android:id="@+id/item_mainlv_top_tv_out"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="¥ 0"
        android:layout_below="@id/item_mainlv_top_tv1"
        android:textSize="25sp"
        android:textStyle="bold"
        android:textColor="@color/black"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"/>
    <ImageView
        android:id="@+id/item_mainlv_top_iv_hide"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:src="@mipmap/ih_show"
        android:layout_alignTop="@id/item_mainlv_top_tv_out"/>
    <TextView
        android:id="@+id/item_mainlv_top_tv2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/month_in"
        android:layout_below="@id/item_mainlv_top_tv_out"/>
    <TextView
        android:id="@+id/item_mainlv_top_tv_in"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/black"
        android:text="¥ 0"
        android:layout_below="@id/item_mainlv_top_tv_out"
        android:layout_toRightOf="@id/item_mainlv_top_tv2"
        android:layout_marginLeft="3dp"/>
    <TextView
        android:id="@+id/item_mainlv_top_tv_budget"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="¥ 0"
        android:textColor="@color/black"
        android:layout_alignParentRight="true"
        android:layout_alignBottom="@id/item_mainlv_top_tv2"
        android:layout_marginLeft="5dp"/>
    <TextView
        android:id="@+id/item_mainlv_top_tv3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/budget"
        android:layout_toLeftOf="@id/item_mainlv_top_tv_budget"
        android:layout_alignBottom="@id/item_mainlv_top_tv2"/>
    <TextView
        android:id="@+id/item_mainlv_top_tv4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawableLeft="@mipmap/ih_biaoge"
        android:layout_below="@id/item_mainlv_top_tv2"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:text="@string/table"
        android:textColor="@color/green_006400"
        android:drawablePadding="10dp"/>
</RelativeLayout>
    <TextView
        android:id="@+id/item_mainlv_top_tv_day"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Expenditure today ¥0 income ¥0"
        android:textStyle="bold"
        android:layout_marginTop="20dp"
        android:layout_marginBottom="10dp"/>
</LinearLayout>

Next, the hidden function is realized, and the effect is as follows

 

This eye is a click event, which is implemented in the background code, and the conversion between plaintext and ciphertext

boolean isShow = true;
    //Method for switching plaintext and ciphertext
    private void toggleShow() {
        if(isShow){//Plaintext->ciphertext
            PasswordTransformationMethod passwordMethod = PasswordTransformationMethod.getInstance();
            topInTv.setTransformationMethod(passwordMethod);
            topOutTv.setTransformationMethod(passwordMethod);
            topbudgetTv.setTransformationMethod(passwordMethod);
            topShowIv.setImageResource(R.mipmap.ih_hide);
            isShow=false;//Set the flag bit to hidden
        }else {
            HideReturnsTransformationMethod hideMethod = HideReturnsTransformationMethod.getInstance();
            topInTv.setTransformationMethod(hideMethod);
            topOutTv.setTransformationMethod(hideMethod);
            topbudgetTv.setTransformationMethod(hideMethod);
            topShowIv.setImageResource(R.mipmap.ih_show);
            isShow=true;//Set the flag bit to display status
        }
    }

That's all for today's function realization. Tomorrow, we will realize the remaining functions.