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" /> +