NowLoading作成完了 #54

Merged
murakumo merged 1 commits from murakumo_NowLoading into master 2024-07-16 05:20:05 +00:00

View File

@ -1,5 +1,6 @@
package com.example.oplogy; package com.example.oplogy;
import android.app.ProgressDialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
@ -322,6 +323,12 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
} }
private void createRoute(ExecutorService executor) { private void createRoute(ExecutorService executor) {
// ProgressDialogを作成
ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setMessage("Loading...");
progressDialog.setCancelable(false);
progressDialog.show();
executor.execute(() -> { executor.execute(() -> {
List<MyDataClass> myDataList = null; List<MyDataClass> myDataList = null;
while (myDataList == null) { while (myDataList == null) {
@ -330,11 +337,11 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
Thread.sleep(3000); Thread.sleep(3000);
} catch (InterruptedException e) { } catch (InterruptedException e) {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
runOnUiThread(progressDialog::dismiss); // 進行状況ダイアログを閉じる
return; return;
} }
} }
//final宣言することによってスレッドセーフになる(ラムダ式内で使えるようにする)
final List<MyDataClass> finalMyDataList = myDataList; final List<MyDataClass> finalMyDataList = myDataList;
CreateSchedule createSchedule = new CreateSchedule(MainActivity.this); CreateSchedule createSchedule = new CreateSchedule(MainActivity.this);
String startPointLatLngString = createSchedule.receiveData(myDataList, getApplicationContext()); String startPointLatLngString = createSchedule.receiveData(myDataList, getApplicationContext());
@ -349,7 +356,9 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
} }
Boolean finalNotDuplicatesBoolean = notDuplicatesBoolean; Boolean finalNotDuplicatesBoolean = notDuplicatesBoolean;
Log.d("MainActivity", "重複判定" + String.valueOf(finalNotDuplicatesBoolean)); Log.d("MainActivity", "重複判定" + String.valueOf(finalNotDuplicatesBoolean));
runOnUiThread(() -> { runOnUiThread(() -> {
progressDialog.dismiss(); // 進行状況ダイアログを閉じる
if (finalNotDuplicatesBoolean) { if (finalNotDuplicatesBoolean) {
Log.d("MainActivity", "スケジュール作成成功"); Log.d("MainActivity", "スケジュール作成成功");
saveMyDataList(finalMyDataList); saveMyDataList(finalMyDataList);
@ -367,6 +376,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
}); });
} }
private void saveMyDataList(List<MyDataClass> myDataList) { private void saveMyDataList(List<MyDataClass> myDataList) {
// 共有プリファレンスのインスタンスを取得 // 共有プリファレンスのインスタンスを取得
SharedPreferences sharedPreferences = getSharedPreferences("MyDataList", MODE_PRIVATE); SharedPreferences sharedPreferences = getSharedPreferences("MyDataList", MODE_PRIVATE);