Published Date : 2021年2月23日15:08

パート4: 給与所得者の所得税と住民税を計算するAndroidアプリ
Part 4: Android App Calculates Income and Resident Taxes for Salaried Workers


This blog has an English translation


ニコニコ動画にアップした動画のまとめ記事です。

This is a summary blog post about a video I uploaded to NicoNico.

細かい部分は動画を参考にしてください。

Please refer to the video for details.


目次

Table of Contents




① 動画の説明
① Video Description



警告:

今回説明する給与所得者の所得税及び住民税を計算するツールは、あくまで簡易的なお遊び用のツールです。

正確な数値、計算方法は各自で調べて下さい。

このツールは大雑把に大体の見積りを計算して楽しむ為のツールです。

決して従業員の年末調整や個人の確定申告等に使用しないでください。

さらに、税金の計算方法は変更される場合があり、控除についても同様です。

また、控除や税金の計算方法が間違っている可能性もありますので、

あまり信用せずに、各自で調べてから実験してみてください。

このツールを使って何かしらの損害が発生したとしても、私は一切の責任を負いません。

Warning:

​The tool I'm going to show you for calculating income and residence taxes for salaried workers is just a simple tool for playing.

​Please check the exact number and calculation method by yourself.

​This tool is used to calculate rough estimates and enjoy them.

​Do not use for year-end adjustment of employees or for individual tax return.

In addition, the method of calculating taxes and deductions may change.

Also, there is a possibility that the deduction and tax calculation methods are incorrect.

Don't trust it too much, and test it yourself.

​I will not be liable for any damage caused by using this tool.

前回の続きです。

Continued from last time.

コメントアウトを外して、クリエイトトーストメソッドを作成しましょう。

Let's undo the commentouted lines and create a CreateToast method.

引数にメッセージテキストとトーストを表示する長さを指定します。

The argument specifies how long to display the message text and toast.

メイクトーストメソッドに引数を渡してトーストインスタンスを作成します。

Create a toast instance by passing an argument to the MakeToast method.

トーストインスタンスのセットグラビティメソッドにセンターヴァーティクルを指定して画面の真ん中にトーストを表示させます。

Specify center vertical for the setGravity method of a toast instance so that the toast is displayed in the center of the screen.

ショウメソッドでトーストを表示させます。

Show method displays toast.

それでは残りのボタンやテキストビュー等をレイアウトファイルに追加していきましょう。

Let's add the rest of the buttons and text views to the layout file.

メインアクティビティのレイアウトファイルに戻り、グリッドレイアウトを配置して、バックグランドにボーダードットエックスエムエルを指定します。

Return to the layout file for the main activity, place the grid layout and Specify [border.xml] for the background.

そして一行二列に指定します。

You then specify one line and two columns.

電卓アクティビティへのボタンを配置しておきます。このアクティビティは後で作成します。

Position the button for the calculator activity. You will create this activity later.

続いてリセットボタンを配置します。こちらもテキストをストリングスドットエックスエムエル内に記述しておきましょう。

Next, position the reset button, then also write the text in [strings.xml].

ついでに他で使うテキストも記述しておきましょう。

While you're at it, write down the text you want to use elsewhere.

レイアウトファイルに戻り、所得税と住民税の計算のタイトルとなるテキストビューを配置します。

Return to the layout file and place the text view that will be the title for the income and residence tax calculation.

またグリッドレイアウトを一行二列に指定して配置します。

Again, place the grid layout as two columns and one row.

所得税と住民税の計算をするアクティビティへのボタンを配置します。

Place a button for the income and residence tax calculation activity.

上部で計算された社会保険料の値をアクティビティへ送り、計算に使うためのボタンを配置します。

Send the social insurance premium value calculated at the top to the activity and place a button to use for the calculation.

このボタンのIDを使い、社会保険料の計算が行われて結果が画面に表示された場合にこのボタンを画面に表示させるようにします。

Use this button's ID to display this button when the social insurance premium is calculated and the result is displayed on the screen.

画面が見やすいように、スペースを設けます。

Provide space to make the screen easier to see.

メインアクティビティのJavaファイルに戻り、先ほどのボタンビューのインスタンスを作成します。

Return to the Java file for the main activity and create an instance of the button view.

社会保険料総額12か月分を格納する変数を用意します。

Prepare a variable to store the total amount of social insurance premiums for 12 months.

そしてこの変数は計算用アクティビティへ送るボタンが押された時にも使用されます。

This variable is also used when the send to calculation activities button is pressed.

ボタンの表示と非表示の処理を記述します。

Write how buttons are displayed and hidden.

では社会保険料を計算するメソッドを作成していきましょう。

Let's create a method to calculate social insurance premiums.

まず、レイアウトファイルで作成した8行分のテキストビューのインスタンスをIDを使って作成していきます。

First, you create instances of the eight-line text views created in the layout file using the IDs.

引数に渡された文字列が空文字でないかどうかをチェックします。

Determines whether the strings passed in the argument are not empty.

渡された文字列には小数点以下が含まれているので、フォーマットメソッドを使い小数点以下を丸めてからカンマ区切りにされた文字列に直して画面に表示させます。

Since the passed string contains decimal places, the format method is used to round the decimal places and then convert them to comma-separated strings for display on the screen.

画面に表示された際にどの種類の社会保険料かを分かりやすくするため、色付きのボーダーを作成してテキストを囲いましょう。

To make it easier to see which types of social insurance premiums appear on the screen, let's create colored borders around the text.

プロパティウィンドウを開いて、ドローアブルフォルダ上で右クリックして画面の指示に従ってボーダーのエックスエムエルファイルを作成しましょう。

Open the properties window, right-click on the drawable folder and follow the instructions on the screen to create the border XML file.

これは単に前回作ったボーダードットエックスエムエルの色の属性値を青色と緑色と赤色に変更しただけです。

They simply changed the color attribute values of the border dot XL I made last time to blue, green and red.

border.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <stroke
        android:width="1dp"
-->     android:color="#000" />
    <padding
        android:top="3dp"
        android:bottom="3dp"
        android:left="3dp"
        android:right="3dp" />

    <corners
        android:radius="3dp" />
</shape>
border_blue.xml
android:color="#00F" />
border_green.xml
android:color="#0F0" />
border_red.xml
android:color="#F00" />

メインアクティビティのJavaファイルに戻ると変更が反映されています。

Return to the main activity's Java file to see the changes.

それでは先ほどの作業の続きを行っていきます。

Then, we will continue the work I just did.

雇用保険料、厚生年金保険料、健康保険料の一か月分と12か月分、それらを合わせた金額の一か月分と12か月分をそれぞれ用意して画面に表示させていきます。

We prepare one month's and 12 months' worth of employment insurance premiums, welfare pension premiums, and health insurance premiums, and prepare one month's worth and 12 months' worth of the sum of those amounts and display them on the screen.

リセットボタンのメソッドは以前の動画シリーズでも作成したので詳しい説明はその動画を参考にしてください。

The reset button method was created in my previous video series, so please refer to that video for further explanation.

インテントのインスタンスを作成して、メインアクティビティ自体のアクティビティをスタートさせて終了させて、オーバーライドペンディングトランジションメソッドを使用して一瞬画面が暗くなるのを防ぎます。

Create an instance of the intent to start and end the activity of the main activity itself, and use the overriding pending transition method to prevent a momentary screen dim.

では途中経過のアプリの動作を確認してみましょう。

Then, let's check the operation of the application in the middle.

チェックボックスがチェックされていない場合は注意文が表示されます。

If the check box is not checked, a note appears.

計算結果の数字はコピー可能です。

The resulting numbers can be copied.

リセットボタンの動作も確認しましょう。

Let's also see how the reset button works.

パートファイブへ続く。

Continue to Part 5.



以上です。お疲れ様です。

That's all. Thank you for your hard work.