Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
54950e9d38 | ||
|
|
9d431bd297 | ||
|
|
e84b21288f | ||
|
|
b28911f386 |
No files matched your search
@@ -1,5 +1,6 @@
|
|||||||
package com.example.childguard;
|
package com.example.childguard;
|
||||||
|
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@@ -76,6 +77,12 @@ public class HomeFragment extends Fragment implements OnEventListener{
|
|||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
Log.d("HomeFragment", "onResume: called");
|
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");
|
Log.d("BT", "Permission to connect bluetooth devices granted");
|
||||||
}
|
}
|
||||||
registerReceiver(receiver, intentFilter);
|
registerReceiver(receiver, intentFilter);
|
||||||
changessituation();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
changessituation();
|
|
||||||
Log.d("onResume", "called");
|
Log.d("onResume", "called");
|
||||||
Log.d("onResume", "mDocRef is null");
|
Log.d("onResume", "mDocRef is null");
|
||||||
firebaselink();
|
firebaselink();
|
||||||
@@ -162,7 +160,8 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
//FireBaseで更新された情報の判定
|
//FireBaseで更新された情報の判定
|
||||||
if (documentSnapshot.getBoolean("isReported") == false) {//isReportedがfalseのとき=サイト上で保護者ボタンが押されたとき
|
if (documentSnapshot.getBoolean("isReported") == false) {//isReportedがfalseのとき=サイト上で保護者ボタンが押されたとき
|
||||||
if (fragment instanceof HomeFragment) {//fragementがHomeFragmentのインスタンスかの判定
|
if (fragment instanceof HomeFragment) {//fragementがHomeFragmentのインスタンスかの判定
|
||||||
changessituation();// changessituation()メソッドを処理→アプリ側の乗降状態を変化
|
// changessituation();// changessituation()メソッドを処理→アプリ側の乗降状態を変化
|
||||||
|
((HomeFragment) fragment).onEvent(!isInCar);
|
||||||
}
|
}
|
||||||
} else if (isInCar) {//第三者ボタンが押されたときにisInCarがtrueのとき=乗車状態のとき→いたずら防止
|
} else if (isInCar) {//第三者ボタンが押されたときにisInCarがtrueのとき=乗車状態のとき→いたずら防止
|
||||||
int importance = NotificationManager.IMPORTANCE_DEFAULT;
|
int importance = NotificationManager.IMPORTANCE_DEFAULT;
|
||||||
@@ -302,17 +301,6 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
notificationManager.notify(R.string.app_name, builder.build());//通知の表示
|
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
|
@Override
|
||||||
public void onStop() {//アプリをバックグラウンドにした時のメソッド
|
public void onStop() {//アプリをバックグラウンドにした時のメソッド
|
||||||
super.onStop();
|
super.onStop();
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import android.os.Looper;
|
|||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.core.app.ActivityCompat;
|
import androidx.core.app.ActivityCompat;
|
||||||
@@ -86,13 +85,9 @@ public class TestService extends Service {
|
|||||||
} else if(isInCar){//Bluetoothの切断後5分以上乗車状態のままのとき→QRコード読み取りを忘れているとき→置き去り発生
|
} else if(isInCar){//Bluetoothの切断後5分以上乗車状態のままのとき→QRコード読み取りを忘れているとき→置き去り発生
|
||||||
ResetReported();//ResetReported();を処理→FireBaseのisReportedをfalseにする
|
ResetReported();//ResetReported();を処理→FireBaseのisReportedをfalseにする
|
||||||
periodicTaskManager.startPeriodicTask();//通知のループをストップする
|
periodicTaskManager.startPeriodicTask();//通知のループをストップする
|
||||||
E.putBoolean("isInCarPref", !documentSnapshot.getBoolean("isInCar"));//乗降状態の判定
|
|
||||||
E.apply();//確定処理
|
|
||||||
}else {
|
}else {
|
||||||
ResetReported();//ResetReported();を処理→FireBaseのisReportedをfalseにする
|
ResetReported();//ResetReported();を処理→FireBaseのisReportedをfalseにする
|
||||||
periodicTaskManager.stopPeriodicTask();//5分毎に通知を行う
|
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分毎に通知を送るメソッド
|
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 Handler handler;
|
||||||
private final Runnable periodicTask;
|
private final Runnable periodicTask;
|
||||||
|
|
||||||
@@ -237,7 +232,7 @@ public class TestService extends Service {
|
|||||||
E.putInt("time",5);
|
E.putInt("time",5);
|
||||||
E.apply();;
|
E.apply();;
|
||||||
}else {
|
}else {
|
||||||
E.putInt("time",time+5);
|
E.putInt("time",time*2);
|
||||||
E.apply();
|
E.apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,14 +251,6 @@ public class TestService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void stopPeriodicTask() {
|
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);
|
handler.removeCallbacks(periodicTask);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user