作業中なう

This commit is contained in:
nemukemo 2024-07-09 09:13:41 +09:00
parent 69cbdf41f0
commit 1e2fcec90b
2 changed files with 75 additions and 32 deletions

View File

@ -2,10 +2,11 @@ package com.example.oplogy;
import static android.content.ContentValues.TAG; import static android.content.ContentValues.TAG;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.DatePickerDialog; import android.app.DatePickerDialog;
import android.app.TimePickerDialog; import android.app.TimePickerDialog;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Paint; import android.graphics.Paint;
@ -44,6 +45,16 @@ public class SetUpActivity extends FragmentActivity
String startBreakTime; String startBreakTime;
String endBreakTime; String endBreakTime;
int totalStudent; int totalStudent;
String stringYear;
String stringMonth;
String stringDayOfMonth;
String stringHourOfDay;
String stringMinute;
Button buttonFirstDay;
Button buttonSecondDay;
Button buttonThirdDay;
Button buttonStartTimeButton;
Button buttonEndTimeButton;
private TextView textViewTeacherName; private TextView textViewTeacherName;
private TextView textViewStartPoint; private TextView textViewStartPoint;
private TextView textViewStartTime; private TextView textViewStartTime;
@ -54,29 +65,13 @@ public class SetUpActivity extends FragmentActivity
private int intIsDateSelected; private int intIsDateSelected;
private int intIsStartTimeSelected; private int intIsStartTimeSelected;
String stringYear;
String stringMonth;
String stringDayOfMonth;
String stringHourOfDay;
String stringMinute;
Button buttonFirstDay;
Button buttonSecondDay;
Button buttonThirdDay;
Button buttonStartTimeButton;
Button buttonEndTimeButton;
@SuppressLint("MissingInflatedId") @SuppressLint("MissingInflatedId")
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_set_up); setContentView(R.layout.activity_set_up);
int classId= getIntent().getIntExtra("classId", 100000); int classId = getIntent().getIntExtra("classId", 100000);
textViewTeacherName = findViewById(R.id.teacherName); //先生の名前 textViewTeacherName = findViewById(R.id.teacherName); //先生の名前
textViewStartPoint = findViewById(R.id.startPoint); //開始地点 textViewStartPoint = findViewById(R.id.startPoint); //開始地点
@ -106,10 +101,13 @@ public class SetUpActivity extends FragmentActivity
Button reset = findViewById(R.id.resetButton); Button reset = findViewById(R.id.resetButton);
toMain.setOnClickListener(view -> { toMain.setOnClickListener(view -> {
Intent intent = new Intent(SetUpActivity.this,MainActivity.class); //main画面へ戻る処理 Intent intent = new Intent(SetUpActivity.this, MainActivity.class); //main画面へ戻る処理
startActivity(intent); startActivity(intent);
}); });
//SetUpTableに情報があった場合それをeditTextに表示するメソッド
showLoadDataYesNoDialog();
setUp.setOnClickListener(view -> { setUp.setOnClickListener(view -> {
teacherName = textViewTeacherName.getText().toString(); //各変数に値を挿入 teacherName = textViewTeacherName.getText().toString(); //各変数に値を挿入
@ -121,7 +119,7 @@ public class SetUpActivity extends FragmentActivity
Log.d(TAG, "Third Day:" + thirdDay); Log.d(TAG, "Third Day:" + thirdDay);
Log.d(TAG, "Start Time" + startTime); Log.d(TAG, "Start Time" + startTime);
Log.d(TAG, "End Time" + endTime); Log.d(TAG, "End Time" + endTime);
if (radioButtonTenMinute.isChecked()){ //ラジオボタンの状態を取得 if (radioButtonTenMinute.isChecked()) { //ラジオボタンの状態を取得
intervalTime = "10"; intervalTime = "10";
} else if (radioButtonFifteenMinute.isChecked()) { } else if (radioButtonFifteenMinute.isChecked()) {
intervalTime = "15"; intervalTime = "15";
@ -189,13 +187,13 @@ public class SetUpActivity extends FragmentActivity
runOnUiThread(() -> Toast.makeText(SetUpActivity.this, "登録しました", Toast.LENGTH_SHORT).show()); runOnUiThread(() -> Toast.makeText(SetUpActivity.this, "登録しました", Toast.LENGTH_SHORT).show());
} }
//家庭訪問日を保存する共有プリファレンス //家庭訪問日を保存する共有プリファレンス
SharedPreferences sharedPreferences=getSharedPreferences("visitingDate",MODE_PRIVATE); SharedPreferences sharedPreferences = getSharedPreferences("visitingDate", MODE_PRIVATE);
SharedPreferences.Editor editor= sharedPreferences.edit(); SharedPreferences.Editor editor = sharedPreferences.edit();
//editorに値を渡す //editorに値を渡す
editor.putString("day1",firstDay); //1日目 editor.putString("day1", firstDay); //1日目
editor.putString("day2",secondDay); //2日目 editor.putString("day2", secondDay); //2日目
editor.putString("day3",thirdDay); //3日目 editor.putString("day3", thirdDay); //3日目
editor.apply(); editor.apply();
@ -205,17 +203,17 @@ public class SetUpActivity extends FragmentActivity
}); });
//DatePicker用 //DatePicker用
buttonFirstDay.setOnClickListener(v ->{ buttonFirstDay.setOnClickListener(v -> {
intIsDateSelected = 1; //ボタンの判別Date intIsDateSelected = 1; //ボタンの判別Date
showDatePickerDialog(); //DatePickerの表示 showDatePickerDialog(); //DatePickerの表示
}); });
buttonSecondDay.setOnClickListener(v ->{ buttonSecondDay.setOnClickListener(v -> {
intIsDateSelected = 2; intIsDateSelected = 2;
showDatePickerDialog(); showDatePickerDialog();
}); });
buttonThirdDay.setOnClickListener(v ->{ buttonThirdDay.setOnClickListener(v -> {
intIsDateSelected = 3; intIsDateSelected = 3;
showDatePickerDialog(); showDatePickerDialog();
}); });
@ -267,7 +265,7 @@ public class SetUpActivity extends FragmentActivity
endTime = ""; endTime = "";
intervalTime = ""; intervalTime = "";
startBreakTime = ""; startBreakTime = "";
endBreakTime ="" ; endBreakTime = "";
ExecutorService executor = Executors.newSingleThreadExecutor(); ExecutorService executor = Executors.newSingleThreadExecutor();
@ -329,7 +327,7 @@ public class SetUpActivity extends FragmentActivity
} else if (intIsStartTimeSelected == 3) { } else if (intIsStartTimeSelected == 3) {
stringHourOfDay = String.format("%02d", hourOfDay); stringHourOfDay = String.format("%02d", hourOfDay);
stringMinute = String.format("%02d", minute); stringMinute = String.format("%02d", minute);
startBreakTime =stringHourOfDay + stringMinute; startBreakTime = stringHourOfDay + stringMinute;
textViewStartBreakTime.setText(" " + str + " "); textViewStartBreakTime.setText(" " + str + " ");
} else if (intIsStartTimeSelected == 4) { } else if (intIsStartTimeSelected == 4) {
@ -350,4 +348,48 @@ public class SetUpActivity extends FragmentActivity
newFragment.show(getSupportFragmentManager(), "timePicker"); newFragment.show(getSupportFragmentManager(), "timePicker");
} }
private void showLoadDataYesNoDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("データの読み込み");
builder.setMessage("SetUpテーブルからデータを読み込みますか");
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
loadSetupData();
dialog.dismiss();
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
private void loadSetupData() {
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.execute(() -> {
AppDatabase db = Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "SetUpTable").build();
SetUpTableDao setUpTableDao = db.setUpTableDao();
String teacherName = setUpTableDao.getTeacherName();
String startPoint = setUpTableDao.getStartPoint();
int totalStudent = setUpTableDao.getTotalStudent();
runOnUiThread(() -> {
textViewTeacherName.setText(teacherName);
textViewStartPoint.setText(startPoint);
textViewTotalStudent.setText(String.valueOf(totalStudent));
});
});
}
} }
//TODO: 教師名開始地点生徒総数を取得し表示する

View File

@ -41,6 +41,7 @@ public interface SetUpTableDao {
//教師名の取得 //教師名の取得
@Query("SELECT teacherName FROM SetUpTable") @Query("SELECT teacherName FROM SetUpTable")
String getTeacherName(); String getTeacherName();
@Query("SELECT intervalTime FROM SetUpTable") @Query("SELECT intervalTime FROM SetUpTable")
String getIntervalTime(); String getIntervalTime();