Compare commits

..
Author SHA1 Message Date
r-ca 54950e9d38 fix 2024-01-19 12:53:19 +09:00
r-ca 9d431bd297 HomeFragmentがResumeされたときにローカルの最新を読み込むように 2024-01-19 12:53:01 +09:00
r-ca e84b21288f changessituationを廃止 2024-01-19 12:49:09 +09:00
ろむねこ b28911f386 Merge pull request #17 from child-guardian/housinnhennkougo
Housinnhennkougo
2024-01-19 12:20:35 +09:00
3 changed files with 11 additions and 29 deletions

No files matched your search

@@ -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);
}
//画面遷移メソッド
@@ -131,13 +131,11 @@ 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 +160,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;
@@ -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();
@@ -20,7 +20,6 @@ import android.os.Looper;
import android.os.Vibrator;
import android.preference.PreferenceManager;
import android.util.Log;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat;
@@ -86,13 +85,9 @@ 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();//確定処理
}
}
@@ -216,7 +211,7 @@ public class TestService extends Service {
}
public class PeriodicTaskManager {//Bluetoothの切断後に乗車状態にならなかった場合に5分毎に通知を送るメソッド
private static final long INTERVAL = 5 * 1000; //300秒
private static final long INTERVAL = 5 *60* 1000; //300秒
private final Handler handler;
private final Runnable periodicTask;
@@ -237,7 +232,7 @@ public class TestService extends Service {
E.putInt("time",5);
E.apply();;
}else {
E.putInt("time",time+5);
E.putInt("time",time*2);
E.apply();
}
@@ -256,14 +251,6 @@ 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);
}