From 1cf5a920b8085347f6ef859a5ba3089643e01577 Mon Sep 17 00:00:00 2001 From: Asura146 Date: Thu, 1 Aug 2024 10:20:24 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Bluetooth=E3=81=AE=E5=88=A4=E5=AE=9A?= =?UTF-8?q?=E5=87=A6=E7=90=86=E3=81=8B=E3=82=89=E9=80=9A=E7=9F=A5=E6=A9=9F?= =?UTF-8?q?=E8=83=BD=E3=82=92=E6=B6=88=E3=81=97=E9=A3=9B=E3=81=B0=E3=81=97?= =?UTF-8?q?=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/childguard/HomeFragment.java | 2 +- .../com/example/childguard/MainActivity.java | 39 ++++++++++--------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/com/example/childguard/HomeFragment.java b/app/src/main/java/com/example/childguard/HomeFragment.java index 6c2d776..c0c71e8 100644 --- a/app/src/main/java/com/example/childguard/HomeFragment.java +++ b/app/src/main/java/com/example/childguard/HomeFragment.java @@ -167,7 +167,7 @@ public class HomeFragment extends Fragment implements OnEventListener { textView.setText(CONNECT); imageView.setVisibility(View.GONE); } else { - //降車状態にする + //切断状態にする frameLayout.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.frame_style, null)); textView.setText(DISCONNECT); imageView.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/com/example/childguard/MainActivity.java b/app/src/main/java/com/example/childguard/MainActivity.java index 7df7664..077adf6 100644 --- a/app/src/main/java/com/example/childguard/MainActivity.java +++ b/app/src/main/java/com/example/childguard/MainActivity.java @@ -441,30 +441,33 @@ public class MainActivity extends AppCompatActivity { } e.apply(); - } else if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action) && !isInCar) {//bluetoothが切断されたときに乗車状態のとき - - //Do something if disconnected + }else if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action) && !isInCar) {//bluetoothが切断されたときに乗車状態のとき +// +// //Do something if disconnected //デバイスが切断されたときの処理 changeBluetooth(false); - if (deviceHardwareAddress.equals(registeredId)) { - // 5分待機する - Handler handler = new Handler(); - handler.postDelayed(new Runnable() { - @Override - public void run() { - if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action) && !isInCar) {//その後bluetoothを再接続したり降車状態になったりしていない=置き去りが発生した可能性大 - NotificationBluetooth(getApplicationContext());//通知を行うメソッド - } - } - - }, 5 * 1000); // 5分をミリ秒に変換 - } - } else { - Log.d("BT", " Device disconnected"); +// if (deviceHardwareAddress.equals(registeredId)) { +// // 5分待機する +// Handler handler = new Handler(); +// handler.postDelayed(new Runnable() { +// @Override +// public void run() { +// if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action) && !isInCar) {//その後bluetoothを再接続したり降車状態になったりしていない=置き去りが発生した可能性大 +// NotificationBluetooth(getApplicationContext());//通知を行うメソッド +// } +// } +// +// }, 5 * 1000); // 5分をミリ秒に変換 +// } +// } else { +// Log.d("BT", " Device disconnected"); } } }; + /** + * Bluetoothの接続状態を変更するメソッド + */ public void changeBluetooth(boolean actual) { getSharedPreferences("Bluetooth_situation", MODE_PRIVATE).edit().putBoolean("status", actual).apply(); } From 9d92652385a09dec89e31441b5f5de44f4d1d99a Mon Sep 17 00:00:00 2001 From: Asura146 Date: Sun, 4 Aug 2024 00:18:43 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88?= =?UTF-8?q?=E3=82=A2=E3=82=A6=E3=83=88=E3=81=A8=E3=81=8B=E3=81=84=E3=82=8D?= =?UTF-8?q?=E3=81=84=E3=82=8D=E7=B4=B0=E3=81=8B=E3=81=84=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=E3=82=92=E5=8A=A0=E3=81=88=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/childguard/HomeFragment.java | 13 +++++++++---- .../com/example/childguard/MainActivity.java | 16 +++++++++++++--- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/example/childguard/HomeFragment.java b/app/src/main/java/com/example/childguard/HomeFragment.java index c0c71e8..daac6de 100644 --- a/app/src/main/java/com/example/childguard/HomeFragment.java +++ b/app/src/main/java/com/example/childguard/HomeFragment.java @@ -31,6 +31,9 @@ public class HomeFragment extends Fragment implements OnEventListener { private String str_key; private String mParam2; + final String GET_ON = "\n乗車状態"; + final String GET_OFF = "\n降車状態"; + public HomeFragment() { // Required empty public constructor @@ -107,6 +110,9 @@ public class HomeFragment extends Fragment implements OnEventListener { transaction.commit(); } + /** + * 乗車状態の画面を切り替える + */ private boolean updateUiState(boolean isInCar) { Log.d("HomeFragment", "updateUiState: called"); // Init @@ -124,16 +130,15 @@ public class HomeFragment extends Fragment implements OnEventListener { updateUiState(isInCar); return false; } - String get_on = "\n乗車状態"; - String get_off = "\n降車状態"; + if (!isInCar) { //乗車状態にする fl.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.frame_style_orange, null)); - tv.setText(get_on); + tv.setText(GET_ON); } else { //降車状態にする fl.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.frame_style, null)); - tv.setText(get_off); + tv.setText(GET_OFF); } return true; diff --git a/app/src/main/java/com/example/childguard/MainActivity.java b/app/src/main/java/com/example/childguard/MainActivity.java index 077adf6..ec2e48d 100644 --- a/app/src/main/java/com/example/childguard/MainActivity.java +++ b/app/src/main/java/com/example/childguard/MainActivity.java @@ -240,8 +240,10 @@ public class MainActivity extends AppCompatActivity { initNotification(mDocRef);//現在の位置を引数に initNotification()を処理 } } - - public void ResetReported() {//FireBaseのisReportedをfalseに初期化するメソッド + /** + * FireBaseのisReportedをfalseに初期化するメソッド + */ + public void ResetReported() { //共有プリファレンス全体の準備 SharedPreferences sharedPreferences = MainActivity.this.getSharedPreferences("app_situation", MODE_PRIVATE); String IdPref = sharedPreferences.getString("ID", null);//アプリに記録されているIDの取得 @@ -252,6 +254,9 @@ public class MainActivity extends AppCompatActivity { isReported.update("isReported", false).addOnSuccessListener(unused -> Log.d(TAG, "DocumentSnapshot successfully updated!")).addOnFailureListener(e -> Log.w(TAG, "Error updating document", e)); } + /** + * 乗車状態の変更 + */ public void changeIsInCar() { //共有プリファレンス全体の準備 SharedPreferences sharedPreferences = MainActivity.this.getSharedPreferences("app_situation", MODE_PRIVATE); @@ -272,6 +277,9 @@ public class MainActivity extends AppCompatActivity { E.apply(); } + /** + * 第三者通知に関する設定のメソッド + */ public void NotificationSetting() {//通知に関する設定の処理を行うメソッド int importance = NotificationManager.IMPORTANCE_DEFAULT; //通知チャネルの実装 @@ -280,9 +288,11 @@ public class MainActivity extends AppCompatActivity { NotificationManager notificationManager = getSystemService(NotificationManager.class); notificationManager.createNotificationChannel(channel); - } + /** + * 第三者通知を行うメソッド + */ public void Notification(Context context) {//実際に通知を行うメソッド final String CHANNEL_ID = "my_channel_id"; // 通知がクリックされたときに送信されるIntent