入力した情報を変数に入れる機能を作成しました、後はRoomに受け渡すだけです

This commit is contained in:
Ekamo-11 2024-06-14 12:32:56 +09:00
parent efbd0703be
commit 1e15a0626a
3 changed files with 165 additions and 55 deletions

View File

@ -6,14 +6,18 @@ import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.DialogFragment;
import android.annotation.SuppressLint;
import android.graphics.Paint;
import android.os.Bundle;
import android.app.TimePickerDialog;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;
import java.util.Locale;
@ -24,98 +28,153 @@ public class SetUpActivity extends FragmentActivity
String startPoint;
String startTime;
String endTime;
String breakTime;
String intervalTime;
String startBreakTime;
String endBreakTime;
int totalStudent;
private TextView setTeacherName;
private TextView setStartPoint;
private TextView setStartTime;
private TextView setEndTime;
private TextView setBreakTime;
private RadioButton setTenMinute;
private RadioButton setFifteenMinute;
private RadioButton setThirtyMinute;
private TextView setStartBreakTime;
private TextView setEndBreakTime;
private TextView setTotalStudent;
private Button setUp;
private boolean isStartTimeSelected = true; // デフォルトはstartTimeを選択
private int isStartTimeSelected;
String startHourOfDay;
String startMinute;
String endHourOfDay;
String endMinute;
String stringHourOfDay;
String stringMinute;
Button startTimeSetButton;
Button endTimeSetButton;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_set_up);
setTeacherName = findViewById(R.id.teacherName);
setStartPoint = findViewById(R.id.startPoint);
setStartTime = findViewById(R.id.startTime);
setEndTime = findViewById(R.id.endTime);
setBreakTime = findViewById(R.id.breakTime);
setTenMinute = findViewById(R.id.tenMinute);
setFifteenMinute = findViewById(R.id.fifteenMinute);
setThirtyMinute = findViewById(R.id.thirtyMinute);
setTotalStudent = findViewById(R.id.totalStudent);
setTeacherName = findViewById(R.id.teacherName); //先生の名前
setStartPoint = findViewById(R.id.startPoint); //開始地点
setStartTime = findViewById(R.id.startTime); //開始時刻
setStartTime.setPaintFlags(Paint.UNDERLINE_TEXT_FLAG); //下線を引く
setEndTime = findViewById(R.id.endTime); //終了時刻
setEndTime.setPaintFlags(Paint.UNDERLINE_TEXT_FLAG);
RadioButton setTenMinute = findViewById(R.id.tenMinute); //訪問間隔10分
RadioButton setFifteenMinute = findViewById(R.id.fifteenMinute); //訪問間隔15分
RadioButton setThirtyMinute = findViewById(R.id.thirtyMinute); //訪問間隔30分
setStartBreakTime = findViewById(R.id.startBreakTime); //休憩開始時刻
setStartBreakTime.setPaintFlags(Paint.UNDERLINE_TEXT_FLAG);
setEndBreakTime = findViewById(R.id.endBreakTime); //休憩終了時刻
setEndBreakTime.setPaintFlags(Paint.UNDERLINE_TEXT_FLAG);
setTotalStudent = findViewById(R.id.totalStudent); //クラスの人数
startTimeSetButton = findViewById(R.id.startTimeSetButton); //開始時刻を設定するためのボタン
endTimeSetButton = findViewById(R.id.endTimeSetButton); //終了時刻を設定するためのボタン
Button setUp = findViewById(R.id.setUpButton); //画面下の設定ボタン
setUp = findViewById(R.id.setUpButton);
setUp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
teacherName = setTeacherName.getText().toString();
teacherName = setTeacherName.getText().toString(); //各変数に値を挿入
Log.d(TAG, "Teacher Name: " + teacherName);
startPoint = setStartPoint.getText().toString();
Log.d(TAG, "Start Point: " + startPoint);
startTime = startHourOfDay + startMinute;
Log.d(TAG, "Start Time: " + startTime);
endTime = endHourOfDay + endMinute;
Log.d(TAG, "End Time: " + endTime);
breakTime = setBreakTime.getText().toString();
Log.d(TAG, "Break Time: " + breakTime);
Log.d(TAG, "Start Time" + startTime);
Log.d(TAG, "End Time" + endTime);
if (setTenMinute.isChecked()){ //ラジオボタンの状態を取得
intervalTime = "10";
} else if (setFifteenMinute.isChecked()) {
intervalTime = "15";
} else if (setThirtyMinute.isChecked()) {
intervalTime = "30";
} else {
intervalTime = "0";
}
Log.d(TAG, "Interval Time" + intervalTime);
Log.d(TAG, "Start Break Time" + startBreakTime);
Log.d(TAG, "End Break Time" + endBreakTime);
totalStudent = Integer.parseInt(setTotalStudent.getText().toString());
Log.d(TAG, "Total Student" + totalStudent);
Log.d(TAG, "onClick: できてるよ");
}
});
setStartTime.setOnClickListener(new View.OnClickListener() {
startTimeSetButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
isStartTimeSelected = true;
isStartTimeSelected = 1; //ボタンの判別
showTimePickerDialog(); //TimePeckerの表示
}
});
endTimeSetButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
isStartTimeSelected = 2;
showTimePickerDialog();
}
});
setEndTime.setOnClickListener(new View.OnClickListener() {
setStartBreakTime.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
isStartTimeSelected = false;
isStartTimeSelected = 3;
showTimePickerDialog();
}
});
setEndBreakTime.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
isStartTimeSelected = 4;
showTimePickerDialog();
}
});
}
@SuppressLint("DefaultLocale")
@SuppressLint({"DefaultLocale", "SetTextI18n"})
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
String str = String.format(Locale.US, "%d:%d", hourOfDay, minute); // Textviewに保存する形式を設定
String str = String.format(Locale.US, "%02d:%02d", hourOfDay, minute); // Textviewに保存する形式を設定
if (isStartTimeSelected) { //押した場所を判定して押したほうにだけ挿入する
startHourOfDay = String.format("%02d", hourOfDay);
startMinute = String.format("%02d", minute);
setStartTime.setText(str);
if (isStartTimeSelected == 1) { //押した場所を判定して押したほうにだけ挿入する
stringHourOfDay = String.format("%02d", hourOfDay); //時を取得
stringMinute = String.format("%02d", minute); //分を取得
startTime = stringHourOfDay + stringMinute; //時と分を結合し四桁の文字列に
setStartTime.setText(" " + str + " "); //画面に出力
} else if (isStartTimeSelected == 2) {
stringHourOfDay = String.format("%02d", hourOfDay);
stringMinute = String.format("%02d", minute);
endTime = stringHourOfDay + stringMinute;
setEndTime.setText(" " + str + " ");
} else {
endHourOfDay = String.format("%02d", hourOfDay);
endMinute = String.format("%02d", minute);
setEndTime.setText(str);
} else if (isStartTimeSelected == 3) {
stringHourOfDay = String.format("%02d", hourOfDay);
stringMinute = String.format("%02d", minute);
startBreakTime =stringHourOfDay + stringMinute;
setStartBreakTime.setText(" " + str + " ");
} else if (isStartTimeSelected == 4) {
stringHourOfDay = String.format("%02d", hourOfDay);
stringMinute = String.format("%02d", minute);
endBreakTime = stringHourOfDay + stringMinute;
setEndBreakTime.setText(" " + str + " ");
}
}
private void showTimePickerDialog() { // Dialogを表示する
DialogFragment newFragment = new TimePick();
newFragment.show(getSupportFragmentManager(), "timePicker");

View File

@ -11,9 +11,10 @@
<TextView
android:id="@+id/toMain"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:layout_gravity="left"
android:paddingStart="20dp"
android:text="🔙"
android:textSize="50dp"
tools:ignore="RtlCompat" />
@ -85,14 +86,26 @@
android:text="@string/startTime"
android:gravity="center"/>
<EditText
<TextView
android:id="@+id/startTime"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="   "
android:textSize="20dp"
android:textAlignment="center"
android:autofillHints=""
android:inputType=""
tools:ignore="LabelFor"/>
<Button
android:id="@+id/startTimeSetButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="65dp"
android:layout_marginEnd="65dp"
android:text="@string/timeSet"
tools:ignore="DuplicateIds" />
</LinearLayout>
<LinearLayout
@ -108,14 +121,25 @@
android:text="@string/endTime"
android:gravity="center"/>
<EditText
<TextView
android:id="@+id/endTime"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="   "
android:textSize="20dp"
android:textAlignment="center"
android:autofillHints=""
android:inputType=""
tools:ignore="LabelFor"/>
<Button
android:id="@+id/endTimeSetButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/timeSet"
android:layout_marginStart="65dp"
android:layout_marginEnd="65dp"
tools:ignore="DuplicateIds" />
</LinearLayout>
<LinearLayout
@ -172,25 +196,51 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:orientation="horizontal"
android:padding="10dp"
android:weightSum="10"
android:gravity="center">
<TextView
android:layout_width="90sp"
android:layout_height="wrap_content"
android:text="@string/breakTime"
android:gravity="center"/>
android:gravity="center"
android:layout_weight="1"
android:text="@string/breakTime" />
<EditText
android:id="@+id/breakTime"
android:layout_width="match_parent"
<TextView
android:id="@+id/startBreakTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="例30分➝30 1時間半➝90"
android:hint=" から "
android:textSize="20dp"
android:textAlignment="center"
android:autofillHints=""
android:layout_weight="4"
android:inputType=""
tools:ignore="LabelFor"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="30dp"
android:paddingStart="30dp"
android:paddingEnd="30dp" />
<TextView
android:id="@+id/endBreakTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:hint=" まで "
android:textAlignment="center"
android:autofillHints=""
android:layout_weight="4"
android:inputType=""
tools:ignore="LabelFor"/>
</LinearLayout>
<LinearLayout

View File

@ -10,4 +10,5 @@
<string name="intervalTime">訪問間隔</string>
<string name="breakTime">休憩時間</string>
<string name="totalStudent">生徒の人数</string>
<string name="timeSet">時刻設定</string>
</resources>