From e84b21288ff2aae3f3241703aa5555c60f5a3002 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Fri, 19 Jan 2024 12:49:09 +0900 Subject: [PATCH 1/3] =?UTF-8?q?changessituation=E3=82=92=E5=BB=83=E6=AD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/childguard/MainActivity.java | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/example/childguard/MainActivity.java b/app/src/main/java/com/example/childguard/MainActivity.java index fb3c249..641f1d4 100644 --- a/app/src/main/java/com/example/childguard/MainActivity.java +++ b/app/src/main/java/com/example/childguard/MainActivity.java @@ -131,13 +131,10 @@ public class MainActivity extends AppCompatActivity { Log.d("BT", "Permission to connect bluetooth devices granted"); } registerReceiver(receiver, intentFilter); - changessituation(); } @Override protected void onResume() { - super.onResume(); - changessituation(); Log.d("onResume", "called"); Log.d("onResume", "mDocRef is null"); firebaselink(); @@ -162,7 +159,8 @@ public class MainActivity extends AppCompatActivity { //FireBaseで更新された情報の判定 if (documentSnapshot.getBoolean("isReported") == false) {//isReportedがfalseのとき=サイト上で保護者ボタンが押されたとき if (fragment instanceof HomeFragment) {//fragementがHomeFragmentのインスタンスかの判定 - changessituation();// changessituation()メソッドを処理→アプリ側の乗降状態を変化 +// changessituation();// changessituation()メソッドを処理→アプリ側の乗降状態を変化 + ((HomeFragment) fragment).onEvent(!isInCar); } } else if (isInCar) {//第三者ボタンが押されたときにisInCarがtrueのとき=乗車状態のとき→いたずら防止 int importance = NotificationManager.IMPORTANCE_DEFAULT; @@ -231,6 +229,7 @@ public class MainActivity extends AppCompatActivity { initNotification(mDocRef);//現在の位置を引数に initNotification()を処理 } + super.onResume(); } public void ResetReported() {//FireBaseのisReportedをfalseに初期化するメソッド @@ -302,17 +301,6 @@ public class MainActivity extends AppCompatActivity { notificationManager.notify(R.string.app_name, builder.build());//通知の表示 } - - public void changessituation() {//乗降状態の管理をするためにHomeFramgentを呼び出すメソッド - - SharedPreferences sharedPreferences = getSharedPreferences("app_situation", MODE_PRIVATE); - //共有プリファレンス 書き込みの準備 - SharedPreferences.Editor E = sharedPreferences.edit(); - Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragmentContainerView); - Boolean isInCar = sharedPreferences.getBoolean("isInCarPref", false);//現在の乗降状態を保存する共有プリファレンス - ((HomeFragment) fragment).onEvent(!isInCar); - } - @Override public void onStop() {//アプリをバックグラウンドにした時のメソッド super.onStop(); -- 2.45.1 From 9d431bd2977b00177d674e4ee9249234372a7676 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Fri, 19 Jan 2024 12:53:01 +0900 Subject: [PATCH 2/3] =?UTF-8?q?HomeFragment=E3=81=8CResume=E3=81=95?= =?UTF-8?q?=E3=82=8C=E3=81=9F=E3=81=A8=E3=81=8D=E3=81=AB=E3=83=AD=E3=83=BC?= =?UTF-8?q?=E3=82=AB=E3=83=AB=E3=81=AE=E6=9C=80=E6=96=B0=E3=82=92=E8=AA=AD?= =?UTF-8?q?=E3=81=BF=E8=BE=BC=E3=82=80=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/HomeFragment.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/src/main/java/com/example/childguard/HomeFragment.java b/app/src/main/java/com/example/childguard/HomeFragment.java index 5e852ba..d3e093b 100644 --- a/app/src/main/java/com/example/childguard/HomeFragment.java +++ b/app/src/main/java/com/example/childguard/HomeFragment.java @@ -1,5 +1,6 @@ package com.example.childguard; +import android.content.SharedPreferences; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; @@ -76,6 +77,12 @@ public class HomeFragment extends Fragment implements OnEventListener{ public void onResume() { super.onResume(); Log.d("HomeFragment", "onResume: called"); + this.updateUiState(getIsInCarLocal()); + } + + private boolean getIsInCarLocal() { + SharedPreferences pref = requireActivity().getSharedPreferences("app_situation", requireActivity().MODE_PRIVATE); + return pref.getBoolean("isInCar", false); } //画面遷移メソッド -- 2.45.1 From 54950e9d38e57bf4adca99fe728f3295b0b89d45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Fri, 19 Jan 2024 12:53:19 +0900 Subject: [PATCH 3/3] fix --- app/src/main/java/com/example/childguard/MainActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/example/childguard/MainActivity.java b/app/src/main/java/com/example/childguard/MainActivity.java index 641f1d4..5f1cdef 100644 --- a/app/src/main/java/com/example/childguard/MainActivity.java +++ b/app/src/main/java/com/example/childguard/MainActivity.java @@ -135,6 +135,7 @@ public class MainActivity extends AppCompatActivity { @Override protected void onResume() { + super.onResume(); Log.d("onResume", "called"); Log.d("onResume", "mDocRef is null"); firebaselink(); @@ -229,7 +230,6 @@ public class MainActivity extends AppCompatActivity { initNotification(mDocRef);//現在の位置を引数に initNotification()を処理 } - super.onResume(); } public void ResetReported() {//FireBaseのisReportedをfalseに初期化するメソッド -- 2.45.1