From dfc9440ab57cc21015ff6e5a01f8dfbb1c307c84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 14:00:58 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=E5=A4=89=E6=9B=B4=E3=82=92=E6=A4=9C?= =?UTF-8?q?=E7=9F=A5=E3=81=97=E3=81=9F=E3=81=A8=E3=81=8D=E3=81=ABSharedPre?= =?UTF-8?q?ference=E3=82=92=E6=9B=B8=E3=81=8D=E6=8F=9B=E3=81=88=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/childguard/MainActivity.java | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/example/childguard/MainActivity.java b/app/src/main/java/com/example/childguard/MainActivity.java index c67c8ea..23550df 100644 --- a/app/src/main/java/com/example/childguard/MainActivity.java +++ b/app/src/main/java/com/example/childguard/MainActivity.java @@ -427,9 +427,7 @@ public class MainActivity extends AppCompatActivity { if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) { //Do something if connected //Bluetoothデバイスが接続されたときの処理 - e.putBoolean("change", true); - e.apply(); - changeBluetooth();//HomeFragmentの表示を接続にする + changeBluetooth(true); Log.d("BT", "Device connected"); Log.d("BT_Judge", "Registered: " + registeredId); @@ -450,9 +448,7 @@ public class MainActivity extends AppCompatActivity { //Do something if disconnected //デバイスが切断されたときの処理 - e.putBoolean("change", false); - e.apply(); - changeBluetooth();//HomeFragmentの表示を切断にする + changeBluetooth(false); if (deviceHardwareAddress.equals(registeredId)) { // 5分待機する Handler handler = new Handler(); @@ -471,12 +467,8 @@ public class MainActivity extends AppCompatActivity { } }; - public void changeBluetooth(){ - SharedPreferences pref=getSharedPreferences("Bluetooth_situation",MODE_PRIVATE); - SharedPreferences.Editor e=pref.edit(); - Boolean BluetoothConnect = pref.getBoolean("change", false); - Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragmentContainerView); - ((HomeFragment) fragment).onEvent2(BluetoothConnect); + public void changeBluetooth(boolean actual){ + getSharedPreferences("Bluetooth_situation",MODE_PRIVATE).edit().putBoolean("status",actual).apply(); } } From d817dfaf58e3e9dd83ae460a4b4a390611ed0ace Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 14:01:16 +0900 Subject: [PATCH 2/3] =?UTF-8?q?onResume=E3=81=A7SharedPreference=E3=81=8B?= =?UTF-8?q?=E3=82=89=E8=AA=AD=E3=81=BF=E5=8F=96=E3=81=A3=E3=81=A6UI?= =?UTF-8?q?=E3=82=92=E6=9B=B4=E6=96=B0=E3=81=99=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=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 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/main/java/com/example/childguard/HomeFragment.java b/app/src/main/java/com/example/childguard/HomeFragment.java index 9058f94..5f462f3 100644 --- a/app/src/main/java/com/example/childguard/HomeFragment.java +++ b/app/src/main/java/com/example/childguard/HomeFragment.java @@ -80,6 +80,12 @@ public class HomeFragment extends Fragment implements OnEventListener { super.onResume(); Log.d("HomeFragment", "onResume: called"); this.updateUiState(getIsInCarLocal()); + this.updateBluetoothSituation(isBluetoothConnected()); + } + + private boolean isBluetoothConnected() { + SharedPreferences pref = requireActivity().getSharedPreferences("Bluetooth_situation", requireActivity().MODE_PRIVATE); + return pref.getBoolean("status", false); } private boolean getIsInCarLocal() { From aa6ee4f035bfafbffda53241a774139fc45bb302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 14:08:51 +0900 Subject: [PATCH 3/3] =?UTF-8?q?void=20onEvent2,=20boolean=20onEvent2?= =?UTF-8?q?=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/childguard/HomeFragment.java | 12 ------------ .../java/com/example/childguard/OnEventListener.java | 4 ---- 2 files changed, 16 deletions(-) diff --git a/app/src/main/java/com/example/childguard/HomeFragment.java b/app/src/main/java/com/example/childguard/HomeFragment.java index 5f462f3..fab5664 100644 --- a/app/src/main/java/com/example/childguard/HomeFragment.java +++ b/app/src/main/java/com/example/childguard/HomeFragment.java @@ -180,17 +180,5 @@ public class HomeFragment extends Fragment implements OnEventListener { return updateUiState(isInCar); } - - @Override - public void onEvent2(boolean BluetoothConnect) { - return; - } - - - @Override - public boolean onEvent2(Boolean BluetoothConnect) {//Bluetoothの接続切断を受け取ってupdateBluetoothSituation()に渡す - updateBluetoothSituation(BluetoothConnect); - return false; - } } diff --git a/app/src/main/java/com/example/childguard/OnEventListener.java b/app/src/main/java/com/example/childguard/OnEventListener.java index 1782b5f..8bf8757 100644 --- a/app/src/main/java/com/example/childguard/OnEventListener.java +++ b/app/src/main/java/com/example/childguard/OnEventListener.java @@ -3,8 +3,4 @@ package com.example.childguard; public interface OnEventListener { boolean onEvent(boolean state); - - void onEvent2(boolean BluetoothConnect); - - boolean onEvent2(Boolean BluetoothConnect); }