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/4] =?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/4] =?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/4] 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 From b774658eb4cd20e7bb6aefce3fb88b23f510b84b Mon Sep 17 00:00:00 2001 From: it232115 Date: Fri, 19 Jan 2024 14:11:06 +0900 Subject: [PATCH 4/4] =?UTF-8?q?=E3=82=BF=E3=82=A4=E3=83=9E=E3=81=AE?= =?UTF-8?q?=E7=B5=82=E4=BA=86=E3=82=BF=E3=82=A4=E3=83=9F=E3=83=B3=E3=82=B0?= =?UTF-8?q?=E3=82=92=E8=AA=BF=E6=95=B4=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/childguard/TestService.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 281734f..ff23868 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -16,6 +16,7 @@ import android.os.IBinder; import android.os.Looper; import android.os.Vibrator; import android.util.Log; +import android.widget.Toast; import androidx.annotation.Nullable; import androidx.core.app.ActivityCompat; @@ -81,9 +82,13 @@ public class TestService extends Service { } else if(isInCar){//Bluetoothの切断後5分以上乗車状態のままのとき→QRコード読み取りを忘れているとき→置き去り発生 ResetReported();//ResetReported();を処理→FireBaseのisReportedをfalseにする periodicTaskManager.startPeriodicTask();//通知のループをストップする + E.putBoolean("isInCarPref", !documentSnapshot.getBoolean("isInCar"));//乗降状態の判定 + E.apply();//確定処理 }else { ResetReported();//ResetReported();を処理→FireBaseのisReportedをfalseにする periodicTaskManager.stopPeriodicTask();//5分毎に通知を行う + E.putBoolean("isInCarPref", documentSnapshot.getBoolean("isInCar"));//乗降状態の判定 + E.apply();//確定処理 } } @@ -210,7 +215,7 @@ public class TestService extends Service { } public class PeriodicTaskManager {//Bluetoothの切断後に乗車状態にならなかった場合に5分毎に通知を送るメソッド - private static final long INTERVAL = 5 *60* 1000; //300秒 + private static final long INTERVAL = 5 * 1000; //300秒 private final Handler handler; private final Runnable periodicTask; @@ -231,7 +236,7 @@ public class TestService extends Service { E.putInt("time",5); E.apply();; }else { - E.putInt("time",time*2); + E.putInt("time",time+5); E.apply(); } @@ -250,6 +255,14 @@ public class TestService extends Service { } public void stopPeriodicTask() { + //共有プリファレンス全体の準備 + SharedPreferences sharedPreferences = getSharedPreferences("app_situation", MODE_PRIVATE); + + int time=sharedPreferences.getInt("time",0); + //共有プリファレンス 書き込みの準備 + SharedPreferences.Editor E = sharedPreferences.edit(); + E.putInt("time",0); + E.apply(); // 定期的な処理の停止 handler.removeCallbacks(periodicTask); } -- 2.45.1