From a69de31fa27aa8a0b21ae1e61c5cb5ac4ba4bc16 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, 12 Jan 2024 11:55:02 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=E3=82=A2=E3=82=A4=E3=83=86=E3=83=A0?= =?UTF-8?q?=E3=82=92=E3=82=BF=E3=83=83=E3=83=97=E3=81=97=E3=81=9F=E3=81=A8?= =?UTF-8?q?=E3=81=8D=E3=81=AB=E3=82=A2=E3=83=A9=E3=83=BC=E3=83=88=E3=82=92?= =?UTF-8?q?=E8=A1=A8=E7=A4=BA=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/childguard/RecyclerAdapter.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/src/main/java/com/example/childguard/RecyclerAdapter.java b/app/src/main/java/com/example/childguard/RecyclerAdapter.java index ea0eea1..d348ce3 100644 --- a/app/src/main/java/com/example/childguard/RecyclerAdapter.java +++ b/app/src/main/java/com/example/childguard/RecyclerAdapter.java @@ -36,6 +36,17 @@ public class RecyclerAdapter extends RecyclerView.Adapter { Toast.makeText(v.getContext(), deviceList.get(position)[1], Toast.LENGTH_SHORT).show(); + + // アラートダイアログを表示 + new androidx.appcompat.app.AlertDialog.Builder(v.getContext()) + .setTitle("登録") + .setMessage("このデバイスを登録しますか?") + .setPositiveButton(android.R.string.ok, (dialog, which) -> { + // OK button pressed + Toast.makeText(v.getContext(), "OK button clicked", Toast.LENGTH_SHORT).show(); + }) + .setNegativeButton(android.R.string.cancel, null) + .show(); }); } From 6fe06fbf48be8812a70a86c59cf7cd7fd4accee0 Mon Sep 17 00:00:00 2001 From: Asura146 Date: Fri, 12 Jan 2024 14:12:21 +0900 Subject: [PATCH 2/3] =?UTF-8?q?Bluetooth=E3=83=87=E3=83=90=E3=82=A4?= =?UTF-8?q?=E3=82=B9=E3=82=92=E4=BF=9D=E5=AD=98=E3=81=99=E3=82=8B=E6=A9=9F?= =?UTF-8?q?=E8=83=BD=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../childguard/Bluetooth_device_save.java | 21 ------------------ .../childguard/Bluetooth_device_save.java | 22 +++++++++++++++++++ .../com/example/childguard/HomeFragment.java | 7 ++++++ .../example/childguard/RecyclerAdapter.java | 10 +++++++-- .../childguard/bluetooth_setupFragment.java | 3 ++- app/src/main/res/layout/fragment_home.xml | 10 +++++++++ 6 files changed, 49 insertions(+), 24 deletions(-) delete mode 100644 app/src/androidTest/java/com/example/childguard/Bluetooth_device_save.java create mode 100644 app/src/main/java/com/example/childguard/Bluetooth_device_save.java diff --git a/app/src/androidTest/java/com/example/childguard/Bluetooth_device_save.java b/app/src/androidTest/java/com/example/childguard/Bluetooth_device_save.java deleted file mode 100644 index de0df1c..0000000 --- a/app/src/androidTest/java/com/example/childguard/Bluetooth_device_save.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.example.childguard; - -import android.content.Context; -import android.content.SharedPreferences; -import android.preference.PreferenceManager; - -import androidx.appcompat.app.AppCompatActivity; - -public class Bluetooth_device_save extends AppCompatActivity { - final SharedPreferences pref= PreferenceManager.getDefaultSharedPreferences(this); - public Bluetooth_device_save() { - } - public void device_save(String deviceAddress){ - SharedPreferences.Editor e=pref.edit(); - e.putString("bluetooth_device1",deviceAddress); - e.apply(); - } - public String device_info(){ - return pref.getString("bluetooth_device1","not_device"); - } -} diff --git a/app/src/main/java/com/example/childguard/Bluetooth_device_save.java b/app/src/main/java/com/example/childguard/Bluetooth_device_save.java new file mode 100644 index 0000000..5673005 --- /dev/null +++ b/app/src/main/java/com/example/childguard/Bluetooth_device_save.java @@ -0,0 +1,22 @@ +package com.example.childguard; + +import android.content.Context; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.preference.PreferenceManager; + +import androidx.appcompat.app.AppCompatActivity; + +public class Bluetooth_device_save { + SharedPreferences pref; + +// public void device_save(String deviceAddress){ +// pref = PreferenceManager.getDefaultSharedPreferencesName() +// SharedPreferences.Editor e=pref.edit(); +// e.putString("bluetooth_device1",deviceAddress); +// e.apply(); +// } + public String device_info(){ + return pref.getString("bluetooth_device1","not_device"); + } +} diff --git a/app/src/main/java/com/example/childguard/HomeFragment.java b/app/src/main/java/com/example/childguard/HomeFragment.java index a5ad221..88cf221 100644 --- a/app/src/main/java/com/example/childguard/HomeFragment.java +++ b/app/src/main/java/com/example/childguard/HomeFragment.java @@ -16,6 +16,8 @@ import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentTransaction; import androidx.print.PrintHelper; +import android.preference.PreferenceManager; +import android.text.PrecomputedText; import android.util.AndroidRuntimeException; import android.util.Log; import android.view.LayoutInflater; @@ -25,6 +27,7 @@ import android.widget.Button; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.TextView; +import android.widget.Toast; import com.google.zxing.BarcodeFormat; import com.google.zxing.WriterException; @@ -100,6 +103,10 @@ public class HomeFragment extends Fragment { replaceFragment(new bluetooth_setupFragment()); } }); + + view.findViewById(R.id.bt_debug).setOnClickListener( v -> { + Toast.makeText(getContext(), PreferenceManager.getDefaultSharedPreferences(getContext().getApplicationContext()).getString("bluetooth_device1", "none"), Toast.LENGTH_SHORT).show(); + }); return view; } diff --git a/app/src/main/java/com/example/childguard/RecyclerAdapter.java b/app/src/main/java/com/example/childguard/RecyclerAdapter.java index d348ce3..a9f550b 100644 --- a/app/src/main/java/com/example/childguard/RecyclerAdapter.java +++ b/app/src/main/java/com/example/childguard/RecyclerAdapter.java @@ -1,5 +1,7 @@ package com.example.childguard; +import android.content.Context; +import android.preference.PreferenceManager; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -16,11 +18,14 @@ public class RecyclerAdapter extends RecyclerView.Adapter deviceList; + Context applicationContext; + // Constructor - public RecyclerAdapter(ArrayList deviceList) { + public RecyclerAdapter(ArrayList deviceList, Context applicationContext) { // Init Log.d("RecyclerAdapter", "Constructor called"); this.deviceList = deviceList; + this.applicationContext = applicationContext; } @NonNull @@ -35,7 +40,6 @@ public class RecyclerAdapter extends RecyclerView.Adapter { - Toast.makeText(v.getContext(), deviceList.get(position)[1], Toast.LENGTH_SHORT).show(); // アラートダイアログを表示 new androidx.appcompat.app.AlertDialog.Builder(v.getContext()) @@ -44,6 +48,8 @@ public class RecyclerAdapter extends RecyclerView.Adapter { // OK button pressed Toast.makeText(v.getContext(), "OK button clicked", Toast.LENGTH_SHORT).show(); + Toast.makeText(v.getContext(), deviceList.get(position)[1], Toast.LENGTH_SHORT).show(); + PreferenceManager.getDefaultSharedPreferences(this.applicationContext).edit().putString("bluetooth_device1", deviceList.get(position)[1]).apply(); }) .setNegativeButton(android.R.string.cancel, null) .show(); diff --git a/app/src/main/java/com/example/childguard/bluetooth_setupFragment.java b/app/src/main/java/com/example/childguard/bluetooth_setupFragment.java index 2507185..bead941 100644 --- a/app/src/main/java/com/example/childguard/bluetooth_setupFragment.java +++ b/app/src/main/java/com/example/childguard/bluetooth_setupFragment.java @@ -134,7 +134,7 @@ public class bluetooth_setupFragment extends Fragment { Log.d("b", s[0]); } Log.d(" ", String.valueOf(arrayList.size())); - RecyclerAdapter adapter = new RecyclerAdapter(arrayList); + RecyclerAdapter adapter = new RecyclerAdapter(arrayList, requireActivity().getApplicationContext()); //④RecyclerViewとAdapterの結び付け recyclerView.setAdapter(adapter); @@ -144,4 +144,5 @@ public class bluetooth_setupFragment extends Fragment { } + } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index 504ddf1..ef0046a 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -103,6 +103,16 @@ android:textColor="@color/white" android:textSize="40dp" /> +