From 2eb6c6e68515b90e64085e52e161f611c860b24b 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 Jan 2024 16:37:53 +0900 Subject: [PATCH 01/21] add zxing --- app/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/app/build.gradle b/app/build.gradle index ae602fc..5e7e062 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -63,4 +63,5 @@ dependencies { testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' + implementation 'com.journeyapps:zxing-android-embedded:4.3.0'//QR用zxingライブラリ } \ No newline at end of file -- 2.45.1 From ec6a94515dc98735f86a8680b388b8455bf6cce4 Mon Sep 17 00:00:00 2001 From: it232115 Date: Thu, 11 Jan 2024 16:40:07 +0900 Subject: [PATCH 02/21] =?UTF-8?q?URL=E3=81=AE=E5=8F=97=E3=81=91=E6=B8=A1?= =?UTF-8?q?=E3=81=97=E3=81=AE=E5=87=A6=E7=90=86=E3=82=92=E8=BF=BD=E5=8A=A0?= =?UTF-8?q?=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/childguard/QRFragment.java | 19 +++++++++---------- .../example/childguard/UrlPageActivity.java | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 app/src/main/java/com/example/childguard/UrlPageActivity.java diff --git a/app/src/main/java/com/example/childguard/QRFragment.java b/app/src/main/java/com/example/childguard/QRFragment.java index b073ecc..b028e3e 100644 --- a/app/src/main/java/com/example/childguard/QRFragment.java +++ b/app/src/main/java/com/example/childguard/QRFragment.java @@ -26,7 +26,8 @@ import com.journeyapps.barcodescanner.ScanOptions; * create an instance of this fragment. */ public class QRFragment extends Fragment { - + //QRコードから受け取ったURLの受け渡しの宣言 + OnDataPass dataPass; // TODO: Rename parameter arguments, choose names that match // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER private static final String ARG_PARAM1 = "param1"; @@ -69,25 +70,23 @@ public class QRFragment extends Fragment { } + //FragmentからActivityへデータの受け渡しをするためのInterface + public interface OnDataPass{ + void onDataPass(String urlPass); + } private final ActivityResultLauncher fragmentLauncher = registerForActivityResult(new ScanContract(), result -> { //QRコードからデータを読み取れたかの確認 if(result.getContents() == null) { Toast.makeText(getContext(), "Cancelled from fragment", Toast.LENGTH_LONG).show(); } else { - //共有プリファレンス全体の準備 - SharedPreferences sharedPreferences = getActivity().getSharedPreferences("default", 0); - //共有プリファレンス書き込みの準備 - SharedPreferences.Editor editor = sharedPreferences.edit(); - //共有プリファレンスにURLの書き込み - editor.putString(result.getContents(),""); - //確定処理 - editor.apply(); + dataPass.onDataPass(result.getContents()); + //画面遷移 Intent intent=new Intent(getActivity(),UrlPageActivity.class); startActivity(intent); } - }); + }); @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, diff --git a/app/src/main/java/com/example/childguard/UrlPageActivity.java b/app/src/main/java/com/example/childguard/UrlPageActivity.java new file mode 100644 index 0000000..45b59c0 --- /dev/null +++ b/app/src/main/java/com/example/childguard/UrlPageActivity.java @@ -0,0 +1,16 @@ +package com.example.childguard; + +import androidx.appcompat.app.AppCompatActivity; + +import android.content.SharedPreferences; +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.webkit.WebView; + +public class UrlPageActivity extends AppCompatActivity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_url_page); + } +} \ No newline at end of file -- 2.45.1 From 02b4134d41f346ce77939ae4d927253cadde2ab5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A3=AF=E9=87=8E?= Date: Fri, 12 Jan 2024 10:26:39 +0900 Subject: [PATCH 03/21] =?UTF-8?q?=E9=80=9A=E7=9F=A5=E9=96=A2=E4=BF=82?= =?UTF-8?q?=E3=81=AE=E6=A9=9F=E8=83=BD=E3=82=92=E4=B8=80=E9=83=A8=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/childguard/MainActivity.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/example/childguard/MainActivity.java b/app/src/main/java/com/example/childguard/MainActivity.java index 4cd26ee..a391ccc 100644 --- a/app/src/main/java/com/example/childguard/MainActivity.java +++ b/app/src/main/java/com/example/childguard/MainActivity.java @@ -34,8 +34,9 @@ public class MainActivity extends AppCompatActivity { //通知のやつ↓ int importance = NotificationManager.IMPORTANCE_DEFAULT; - NotificationChannel channel = new NotificationChannel("CHANNEL_ID", "サンプルアプリ", importance); - channel.setDescription("説明・説明 ここに通知の説明を書くことができる"); + NotificationChannel channel = new NotificationChannel("CHANNEL_ID", "通報通知", importance); + //説明・説明 ここに通知の説明を書くことができる↓ + channel.setDescription("第3者からの通報を検知しました"); NotificationManager notificationManager = getSystemService(NotificationManager.class); notificationManager.createNotificationChannel(channel); @@ -65,13 +66,13 @@ public class MainActivity extends AppCompatActivity { } //↓通知のやつ - public void notifyTest() { + public void notifyMain() { ((Vibrator)getSystemService(Context.VIBRATOR_SERVICE)).vibrate(1000); NotificationCompat.Builder builder = new NotificationCompat .Builder(this, "CHANNEL_ID") .setSmallIcon(android.R.drawable.ic_menu_info_details) - .setContentTitle("タイトル") - .setContentText("メッセージ・メッセージ") + .setContentTitle("通報検知") + .setContentText("子供の置き去りを検知しました。") .setPriority(NotificationCompat.PRIORITY_DEFAULT); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); -- 2.45.1 From cd12c890814fc15a63ed224024949de5e1a4c188 Mon Sep 17 00:00:00 2001 From: Asura146 Date: Fri, 12 Jan 2024 10:37:44 +0900 Subject: [PATCH 04/21] =?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=E3=82=AF?= =?UTF-8?q?=E3=83=A9=E3=82=B9=E3=82=92=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../childguard/Bluetooth_device_save.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 app/src/androidTest/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 new file mode 100644 index 0000000..de0df1c --- /dev/null +++ b/app/src/androidTest/java/com/example/childguard/Bluetooth_device_save.java @@ -0,0 +1,21 @@ +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"); + } +} -- 2.45.1 From 8a753ef1fee19472cbf79ade4c94ee8bd2337f8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A3=AF=E9=87=8E?= Date: Fri, 12 Jan 2024 10:46:28 +0900 Subject: [PATCH 05/21] =?UTF-8?q?fragment=5Fnotification.xml=E3=81=AB?= =?UTF-8?q?=E3=83=AA=E3=82=B5=E3=82=A4=E3=82=AF=E3=83=A9=E3=83=BC=E3=83=93?= =?UTF-8?q?=E3=83=A5=E3=83=BC=E3=82=92=E8=BF=BD=E5=8A=A0=E3=81=97=E3=81=BE?= =?UTF-8?q?=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/res/layout/fragment_notification.xml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/src/main/res/layout/fragment_notification.xml b/app/src/main/res/layout/fragment_notification.xml index 1146fca..0d4f90d 100644 --- a/app/src/main/res/layout/fragment_notification.xml +++ b/app/src/main/res/layout/fragment_notification.xml @@ -6,9 +6,18 @@ tools:context=".NotificationFragment"> - + android:layout_height="wrap_content" + android:layout_weight="9" + > + + + + \ No newline at end of file -- 2.45.1 From ff05035662f4c65e0a78cafbddab967a55d30998 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A3=AF=E9=87=8E?= Date: Fri, 12 Jan 2024 11:08:34 +0900 Subject: [PATCH 06/21] =?UTF-8?q?=E3=83=95=E3=82=A9=E3=83=BC=E3=83=9E?= =?UTF-8?q?=E3=83=83=E3=83=88=E3=82=92=E6=95=B4=E3=81=88=E3=81=BE=E3=81=97?= =?UTF-8?q?=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/MainActivity.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/example/childguard/MainActivity.java b/app/src/main/java/com/example/childguard/MainActivity.java index a391ccc..e6a222c 100644 --- a/app/src/main/java/com/example/childguard/MainActivity.java +++ b/app/src/main/java/com/example/childguard/MainActivity.java @@ -67,7 +67,7 @@ public class MainActivity extends AppCompatActivity { //↓通知のやつ public void notifyMain() { - ((Vibrator)getSystemService(Context.VIBRATOR_SERVICE)).vibrate(1000); + ((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).vibrate(1000); NotificationCompat.Builder builder = new NotificationCompat .Builder(this, "CHANNEL_ID") .setSmallIcon(android.R.drawable.ic_menu_info_details) @@ -91,8 +91,9 @@ public class MainActivity extends AppCompatActivity { } + //Bluetooth_setupの戻るボタン - public void setupBackButton(boolean enableBackButton){ + public void setupBackButton(boolean enableBackButton) { ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(enableBackButton); } -- 2.45.1 From c37aee2751b59a737d4aa782139642a2ef3c0a27 Mon Sep 17 00:00:00 2001 From: it232115 Date: Fri, 12 Jan 2024 11:31:27 +0900 Subject: [PATCH 07/21] =?UTF-8?q?QR=E7=94=BB=E5=83=8F=E3=82=92=E7=94=9F?= =?UTF-8?q?=E6=88=90=E3=81=99=E3=82=8B=E3=83=95=E3=83=A9=E3=82=B0=E3=83=A1?= =?UTF-8?q?=E3=83=B3=E3=83=88=E3=81=B8=E3=81=AE=E7=94=BB=E5=83=8F=E9=81=B7?= =?UTF-8?q?=E7=A7=BB=E3=82=92=E8=BF=BD=E5=8A=A0=E3=81=97=E3=81=BE=E3=81=97?= =?UTF-8?q?=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 1 - .../com/example/childguard/HomeFragment.java | 26 ++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 430b05a..cbdd641 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -34,7 +34,6 @@ - \ No newline at end of file diff --git a/app/src/main/java/com/example/childguard/HomeFragment.java b/app/src/main/java/com/example/childguard/HomeFragment.java index 82a8f9c..a5ad221 100644 --- a/app/src/main/java/com/example/childguard/HomeFragment.java +++ b/app/src/main/java/com/example/childguard/HomeFragment.java @@ -1,7 +1,12 @@ package com.example.childguard; import android.content.SharedPreferences; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Canvas; import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.os.Bundle; @@ -9,15 +14,22 @@ import androidx.core.content.res.ResourcesCompat; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentTransaction; +import androidx.print.PrintHelper; +import android.util.AndroidRuntimeException; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.FrameLayout; +import android.widget.ImageView; import android.widget.TextView; +import com.google.zxing.BarcodeFormat; +import com.google.zxing.WriterException; +import com.journeyapps.barcodescanner.BarcodeEncoder; + /** * A simple {@link Fragment} subclass. * Use the {@link HomeFragment#newInstance} factory method to @@ -69,12 +81,20 @@ public class HomeFragment extends Fragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment - //bluetooth設定ボタンの処理 View view=inflater.inflate(R.layout.fragment_home,container,false); MainActivity activity = (MainActivity) getActivity(); - - Button bt1=view.findViewById(R.id.Bluetooth_setup); + //QRコード印刷の処理 + Button bt1=view.findViewById(R.id.QRprinting); bt1.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + replaceFragment(new QrPrintFragment()); + + } + }); + //bluetooth設定ボタンの処理 + Button bt2=view.findViewById(R.id.Bluetooth_setup); + bt2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { replaceFragment(new bluetooth_setupFragment()); -- 2.45.1 From 67df5a3ec29d14a9db3154824e2882988cfed941 Mon Sep 17 00:00:00 2001 From: it232115 Date: Fri, 12 Jan 2024 11:32:50 +0900 Subject: [PATCH 08/21] =?UTF-8?q?=E3=83=A6=E3=83=BC=E3=82=B6=E6=AF=8E?= =?UTF-8?q?=E3=81=AE=E3=83=89=E3=83=A1=E3=82=A4=E3=83=B3=E3=81=8B=E3=82=89?= =?UTF-8?q?QR=E3=82=B3=E3=83=BC=E3=83=89=E3=82=92=E7=94=9F=E6=88=90?= =?UTF-8?q?=E3=81=97=E3=80=81=E3=83=97=E3=83=AA=E3=83=B3=E3=82=BF=E3=83=BC?= =?UTF-8?q?=E3=81=B8=E5=8D=B0=E5=88=B7=E6=8C=87=E7=A4=BA=E3=82=92=E5=87=BA?= =?UTF-8?q?=E3=81=99=E5=87=A6=E7=90=86=E3=82=92=E8=BF=BD=E5=8A=A0=E3=81=97?= =?UTF-8?q?=E3=81=BE=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/childguard/QrPrintFragment.java | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 app/src/main/java/com/example/childguard/QrPrintFragment.java diff --git a/app/src/main/java/com/example/childguard/QrPrintFragment.java b/app/src/main/java/com/example/childguard/QrPrintFragment.java new file mode 100644 index 0000000..d31ac6e --- /dev/null +++ b/app/src/main/java/com/example/childguard/QrPrintFragment.java @@ -0,0 +1,119 @@ +package com.example.childguard; + +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.drawable.BitmapDrawable; +import android.os.Bundle; + +import androidx.fragment.app.Fragment; +import androidx.print.PrintHelper; + +import android.util.AndroidRuntimeException; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; + +import com.google.zxing.BarcodeFormat; +import com.google.zxing.WriterException; +import com.journeyapps.barcodescanner.BarcodeEncoder; + +/** + * A simple {@link Fragment} subclass. + * Use the {@link QrPrintFragment#newInstance} factory method to + * create an instance of this fragment. + */ +public class QrPrintFragment extends Fragment { + + // TODO: Rename parameter arguments, choose names that match + // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER + private static final String ARG_PARAM1 = "param1"; + private static final String ARG_PARAM2 = "param2"; + + // TODO: Rename and change types of parameters + private String mParam1; + private String mParam2; + + public QrPrintFragment() { + // Required empty public constructor + } + + /** + * Use this factory method to create a new instance of + * this fragment using the provided parameters. + * + * @param param1 Parameter 1. + * @param param2 Parameter 2. + * @return A new instance of fragment QrPrintFragment. + */ + // TODO: Rename and change types and number of parameters + public static QrPrintFragment newInstance(String param1, String param2) { + QrPrintFragment fragment = new QrPrintFragment(); + Bundle args = new Bundle(); + args.putString(ARG_PARAM1, param1); + args.putString(ARG_PARAM2, param2); + fragment.setArguments(args); + return fragment; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (getArguments() != null) { + mParam1 = getArguments().getString(ARG_PARAM1); + mParam2 = getArguments().getString(ARG_PARAM2); + + } + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + View view=inflater.inflate(R.layout.fragment_qr_print, container, false); + + //固定のドメイン + String KoteiURL = "https://practicefirestore1-8808c.web.app/?id="; + //User毎のドメイン + String userURL="YKjFsZgJBlZmcyvdZ3Ap"; + //二つのドメインを合成する + String AllURL=KoteiURL+userURL; + + int size = 2500; + ImageView imageViewQrCode; + Bitmap QRGazou; + try { + //QRコード生成 + BarcodeEncoder barcodeEncoder = new BarcodeEncoder(); + Bitmap bitmapqr = barcodeEncoder.encodeBitmap(AllURL, BarcodeFormat.QR_CODE, size, size); + imageViewQrCode = (ImageView) view.findViewById(R.id.qr_view); + imageViewQrCode.setTranslationX(1000); + imageViewQrCode.setTranslationY(1000); + imageViewQrCode.setImageBitmap(bitmapqr); + } catch (WriterException e) { + throw new AndroidRuntimeException("Barcode Error.", e); + } + // 画像合成の準備 + Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.a_group_qr_sos); + Bitmap bitmap1 = ((BitmapDrawable) imageViewQrCode.getDrawable()).getBitmap(); + int width = bitmap.getWidth(); // 元ファイルの幅取得 + int height = bitmap.getHeight(); // 元ファイルの高さ取得 + QRGazou = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); + //Canvasの準備 + Canvas canvas = new Canvas(QRGazou); + //画像のサイズの調整 + int disWidth = (width - bitmap1.getWidth()) / 2; + int disHeight = (int) ((height - bitmap1.getHeight()) / 1.3); + canvas.drawBitmap(bitmap, 0, 0, (Paint) null); // image, x座標, y座標, Paintインスタンス + canvas.drawBitmap(bitmap1, disWidth, disHeight, (Paint) null); // 画像合成 + //Androidからプリンターへ印刷指示を出すサポートライブラリ + PrintHelper printHelper = new PrintHelper(getActivity()); + printHelper.setColorMode(PrintHelper.COLOR_MODE_COLOR); + printHelper.setScaleMode(PrintHelper.SCALE_MODE_FIT); + printHelper.printBitmap("job_name", QRGazou); + + return view; + } +} \ No newline at end of file -- 2.45.1 From 8f769c8e04452bbe6df57d5e58193e4bcac03548 Mon Sep 17 00:00:00 2001 From: it232115 Date: Fri, 12 Jan 2024 11:33:29 +0900 Subject: [PATCH 09/21] =?UTF-8?q?=E5=8D=B0=E5=88=B7=E7=94=BB=E5=83=8F?= =?UTF-8?q?=E3=81=AE=E7=94=9F=E6=88=90=E3=81=AB=E7=94=A8=E3=81=84=E3=82=8B?= =?UTF-8?q?xml=E3=82=92=E8=BF=BD=E5=8A=A0=E3=81=97=E3=81=BE=E3=81=97?= =?UTF-8?q?=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/res/layout/fragment_qr_print.xml | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 app/src/main/res/layout/fragment_qr_print.xml diff --git a/app/src/main/res/layout/fragment_qr_print.xml b/app/src/main/res/layout/fragment_qr_print.xml new file mode 100644 index 0000000..0200695 --- /dev/null +++ b/app/src/main/res/layout/fragment_qr_print.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + \ No newline at end of file -- 2.45.1 From a25ed8d4d3e40c5f313fba0b0afbe821fd0b9041 Mon Sep 17 00:00:00 2001 From: it232115 Date: Fri, 12 Jan 2024 11:34:16 +0900 Subject: [PATCH 10/21] =?UTF-8?q?=E8=AA=AD=E3=81=BF=E5=8F=96=E3=81=A3?= =?UTF-8?q?=E3=81=9FQR=E3=82=B3=E3=83=BC=E3=83=89=E3=81=8CChiled=20Guard?= =?UTF-8?q?=E7=94=A8=E3=82=B5=E3=82=A4=E3=83=88=E3=81=AE=E3=83=89=E3=83=A1?= =?UTF-8?q?=E3=82=A4=E3=83=B3=E3=82=92=E5=90=AB=E3=82=80=E3=81=8B=E3=81=AE?= =?UTF-8?q?=E5=88=A4=E5=AE=9A=E3=82=92=E8=A1=8C=E3=81=86=E5=87=A6=E7=90=86?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/childguard/QRFragment.java | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/example/childguard/QRFragment.java b/app/src/main/java/com/example/childguard/QRFragment.java index ed63a6a..fc0e0a8 100644 --- a/app/src/main/java/com/example/childguard/QRFragment.java +++ b/app/src/main/java/com/example/childguard/QRFragment.java @@ -74,22 +74,16 @@ public class QRFragment extends Fragment { } - //FragmentからActivityへデータの受け渡しをするためのInterface -// public interface OnDataPass{ -// void onDataPass(String urlPass); -// } private final ActivityResultLauncher fragmentLauncher = registerForActivityResult(new ScanContract(), result -> { - //QRコードからデータを読み取れたかの確認 - if(result.getContents() == null) { - Toast.makeText(getContext(), "Cancelled from fragment", Toast.LENGTH_LONG).show(); + //result.getContents()でURLを入手 + //読み取ったQRコードがChiled Guard用サイトのドメインを含むかの判定 + if(!((result.getContents()).contains("https://practicefirestore1-8808c.web.app/"))) { + Toast.makeText(getContext(), "Chiled Guardに対応するQRコードではありません", Toast.LENGTH_LONG).show(); } else { -// dataPass.onDataPass(result.getContents()); - //画面遷移 + //URLの表示 Toast.makeText(getContext(), result.getContents(), Toast.LENGTH_SHORT).show(); -// Intent intent=new Intent(getActivity(),UrlPageActivity.class); -// startActivity(intent); - + //ブラウザを起動し、URL先のサイトを開く CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); CustomTabsIntent customTabsIntent = builder.build(); customTabsIntent.launchUrl(requireContext(), Uri.parse(result.getContents())); -- 2.45.1 From 87c5af9f012beafee3733f79a785dbe50bf52d46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A3=AF=E9=87=8E?= Date: Fri, 12 Jan 2024 12:17:43 +0900 Subject: [PATCH 11/21] =?UTF-8?q?=E6=B3=A8=E9=87=88=E3=82=92=E5=B0=91?= =?UTF-8?q?=E3=81=97=E4=BB=98=E3=81=91=E5=8A=A0=E3=81=88=E3=81=BE=E3=81=97?= =?UTF-8?q?=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/MainActivity.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/com/example/childguard/MainActivity.java b/app/src/main/java/com/example/childguard/MainActivity.java index e6a222c..3b4f32c 100644 --- a/app/src/main/java/com/example/childguard/MainActivity.java +++ b/app/src/main/java/com/example/childguard/MainActivity.java @@ -67,7 +67,9 @@ public class MainActivity extends AppCompatActivity { //↓通知のやつ public void notifyMain() { + //↓通知をする際に起動するバイブレーション ((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).vibrate(1000); + //↓通知の詳細設定的な奴 NotificationCompat.Builder builder = new NotificationCompat .Builder(this, "CHANNEL_ID") .setSmallIcon(android.R.drawable.ic_menu_info_details) -- 2.45.1 From 8a7ab0b7a1398d9bcd9168f4824c067922ac125d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A3=AF=E9=87=8E?= Date: Fri, 12 Jan 2024 12:23:22 +0900 Subject: [PATCH 12/21] =?UTF-8?q?=E6=97=A5=E4=BB=98=E3=82=92=E5=8F=96?= =?UTF-8?q?=E5=BE=97=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/childguard/MainActivity.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/src/main/java/com/example/childguard/MainActivity.java b/app/src/main/java/com/example/childguard/MainActivity.java index 3b4f32c..4de4695 100644 --- a/app/src/main/java/com/example/childguard/MainActivity.java +++ b/app/src/main/java/com/example/childguard/MainActivity.java @@ -6,6 +6,7 @@ import androidx.core.app.ActivityCompat; import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationManagerCompat; +import android.annotation.SuppressLint; import android.app.NotificationChannel; import android.app.NotificationManager; import android.bluetooth.BluetoothAdapter; @@ -17,6 +18,9 @@ import android.os.Vibrator; import com.google.android.material.bottomnavigation.BottomNavigationView; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.Random; import java.util.UUID; @@ -25,6 +29,13 @@ public class MainActivity extends AppCompatActivity { BluetoothManager bluetoothManager; BluetoothAdapter bluetoothAdapter; + //↓日付を取得するやつ + public static String getNowDate() { + @SuppressLint("SimpleDateFormat") final DateFormat df = new SimpleDateFormat("yyy/MM/dd HH:mm:ss"); + final Date date = new Date(System.currentTimeMillis()); + return df.format(date); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); -- 2.45.1 From 114faf1ac0b13e5b72cc313c358236840e256ceb Mon Sep 17 00:00:00 2001 From: it232115 Date: Mon, 15 Jan 2024 10:04:53 +0900 Subject: [PATCH 13/21] wip --- app/build.gradle | 2 + .../com/example/childguard/HomeFragment.java | 94 +++++++++++++------ .../example/childguard/UrlPageActivity.java | 16 ---- app/src/main/res/layout/activity_url_page.xml | 14 --- build.gradle | 6 +- 5 files changed, 73 insertions(+), 59 deletions(-) delete mode 100644 app/src/main/java/com/example/childguard/UrlPageActivity.java delete mode 100644 app/src/main/res/layout/activity_url_page.xml diff --git a/app/build.gradle b/app/build.gradle index 6150f78..71a9f46 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ plugins { id 'com.android.application' id 'org.jetbrains.kotlin.android' + id 'com.google.gms.google-services' } android { @@ -58,6 +59,7 @@ dependencies { implementation 'androidx.compose.ui:ui-graphics' implementation 'androidx.compose.ui:ui-tooling-preview' implementation 'androidx.compose.material3:material3' + implementation 'com.google.firebase:firebase-firestore:24.4.1' testImplementation 'junit:junit:4.13.2' diff --git a/app/src/main/java/com/example/childguard/HomeFragment.java b/app/src/main/java/com/example/childguard/HomeFragment.java index a5ad221..9405ba8 100644 --- a/app/src/main/java/com/example/childguard/HomeFragment.java +++ b/app/src/main/java/com/example/childguard/HomeFragment.java @@ -1,34 +1,31 @@ package com.example.childguard; +import static android.content.ContentValues.TAG; + import android.content.SharedPreferences; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.Paint; -import android.graphics.drawable.BitmapDrawable; -import android.graphics.drawable.Drawable; import android.os.Bundle; - -import androidx.core.content.res.ResourcesCompat; -import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentManager; -import androidx.fragment.app.FragmentTransaction; -import androidx.print.PrintHelper; - -import android.util.AndroidRuntimeException; +import android.preference.PreferenceManager; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.FrameLayout; -import android.widget.ImageView; import android.widget.TextView; -import com.google.zxing.BarcodeFormat; -import com.google.zxing.WriterException; -import com.journeyapps.barcodescanner.BarcodeEncoder; +import androidx.annotation.NonNull; +import androidx.core.content.res.ResourcesCompat; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentTransaction; + +import com.google.android.gms.tasks.OnFailureListener; +import com.google.android.gms.tasks.OnSuccessListener; +import com.google.firebase.firestore.DocumentReference; +import com.google.firebase.firestore.FirebaseFirestore; + +import java.util.HashMap; +import java.util.Map; /** * A simple {@link Fragment} subclass. @@ -37,6 +34,8 @@ import com.journeyapps.barcodescanner.BarcodeEncoder; */ public class HomeFragment extends Fragment { + FirebaseFirestore db = FirebaseFirestore.getInstance();//Firebaseとの紐づけ + // TODO: Rename parameter arguments, choose names that match // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER private static final String ARG_PARAM1 = "param1"; @@ -80,20 +79,58 @@ public class HomeFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + // Log.d("HomeFlagment_cnt", "aaaaa"); // Inflate the layout for this fragment - View view=inflater.inflate(R.layout.fragment_home,container,false); + View view = inflater.inflate(R.layout.fragment_home, container, false); MainActivity activity = (MainActivity) getActivity(); + //共有プリファレンス 全体の準備 + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity()); //QRコード印刷の処理 - Button bt1=view.findViewById(R.id.QRprinting); + Button bt1 = view.findViewById(R.id.QRprinting); bt1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - replaceFragment(new QrPrintFragment()); + //初回起動かを保存する変数 + int i = Integer.parseInt(preferences.getString("kidoukaisuu", "1")); + //ボタン変数の宣言 + Button parent = view.findViewById(R.id.QRprinting); + Button born = view.findViewById(R.id.QRprinting); + if (i == 1) {//QRコード印刷を初めて押したときにFireBaseへの登録を行う + String QRYomitorisya = parent.getText().toString();//変数に文字列を代入 + String valueBorn = born.getText().toString();//変数に文字列を代入 + Map user = new HashMap<>();//mapの宣言 - } + Log.d("HomeFragment", "onClick is called"); + + //mapに入れる + user.put("parent", QRYomitorisya); + user.put("born", valueBorn); + //新しいドキュメントにIDを作って追加 + db.collection("users") + .add(user) + .addOnSuccessListener(new OnSuccessListener() { + @Override + public void onSuccess(DocumentReference documentReference) { + Log.d(TAG, "DocumentSnapshot added with ID: " + documentReference.getId()); + } + }) + .addOnFailureListener(new OnFailureListener() { + @Override + public void onFailure(@NonNull Exception e) {//エラー処理 + Log.w(TAG, "Error adding document", e); + } + + }); + + } + SharedPreferences.Editor e = preferences.edit(); + e.putString("kidoukiroku", "2"); + e.apply(); + replaceFragment(new QrPrintFragment()); + } }); //bluetooth設定ボタンの処理 - Button bt2=view.findViewById(R.id.Bluetooth_setup); + Button bt2 = view.findViewById(R.id.Bluetooth_setup); bt2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -108,11 +145,11 @@ public class HomeFragment extends Fragment { super.onResume(); Log.d("HomeFragment", "onResume: called"); TextView situationTextView = getView().findViewById(R.id.situation); - FrameLayout situation_bg=getView().findViewById(R.id.situation_bg); - updateInCarStatus(situationTextView,situation_bg); + FrameLayout situation_bg = getView().findViewById(R.id.situation_bg); + updateInCarStatus(situationTextView, situation_bg); } - public void updateInCarStatus(TextView situationTextView,FrameLayout situation_bg) { + public void updateInCarStatus(TextView situationTextView, FrameLayout situation_bg) { SharedPreferences sharedPreferences = getActivity().getSharedPreferences("default", 0); Log.d("HomeFragment", "updateInCarStatus: " + sharedPreferences.getBoolean("inCar", false)); @@ -125,8 +162,9 @@ public class HomeFragment extends Fragment { } } + //画面遷移メソッド - private void replaceFragment(Fragment fragment){ + private void replaceFragment(Fragment fragment) { // フラグメントマネージャーの取得 FragmentManager manager = getParentFragmentManager(); // アクティビティではgetSupportFragmentManager()? // フラグメントトランザクションの開始 diff --git a/app/src/main/java/com/example/childguard/UrlPageActivity.java b/app/src/main/java/com/example/childguard/UrlPageActivity.java deleted file mode 100644 index 45b59c0..0000000 --- a/app/src/main/java/com/example/childguard/UrlPageActivity.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.example.childguard; - -import androidx.appcompat.app.AppCompatActivity; - -import android.content.SharedPreferences; -import android.os.Bundle; -import android.preference.PreferenceManager; -import android.webkit.WebView; - -public class UrlPageActivity extends AppCompatActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_url_page); - } -} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_url_page.xml b/app/src/main/res/layout/activity_url_page.xml deleted file mode 100644 index 61bc31b..0000000 --- a/app/src/main/res/layout/activity_url_page.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - \ No newline at end of file diff --git a/build.gradle b/build.gradle index 4314313..e8491f3 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,8 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. +buildscript { + dependencies { + classpath 'com.google.gms:google-services:4.3.14' + } +}// Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { id 'com.android.application' version '8.0.2' apply false id 'com.android.library' version '8.0.2' apply false -- 2.45.1 From 004a0820e2e5fb172ffc2a488c92097fdf49fd93 Mon Sep 17 00:00:00 2001 From: it232115 Date: Mon, 15 Jan 2024 11:43:49 +0900 Subject: [PATCH 14/21] wip --- app/google-services.json | 67 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 app/google-services.json diff --git a/app/google-services.json b/app/google-services.json new file mode 100644 index 0000000..d3d7537 --- /dev/null +++ b/app/google-services.json @@ -0,0 +1,67 @@ +{ + "project_info": { + "project_number": "814788024795", + "project_id": "practicefirestore1-8808c", + "storage_bucket": "practicefirestore1-8808c.appspot.com" + }, + "client": [ + { + "client_info": { + "mobilesdk_app_id": "1:814788024795:android:79602ef613cc9860c76ffe", + "android_client_info": { + "package_name": "com.example.childguard" + } + }, + "oauth_client": [], + "api_key": [ + { + "current_key": "AIzaSyAVpoftIYGZwiPRpuI56hoV8ifA2rbZGb4" + } + ], + "services": { + "appinvite_service": { + "other_platform_oauth_client": [] + } + } + }, + { + "client_info": { + "mobilesdk_app_id": "1:814788024795:android:7c572a838331bba1c76ffe", + "android_client_info": { + "package_name": "com.example.connecttointernet" + } + }, + "oauth_client": [], + "api_key": [ + { + "current_key": "AIzaSyAVpoftIYGZwiPRpuI56hoV8ifA2rbZGb4" + } + ], + "services": { + "appinvite_service": { + "other_platform_oauth_client": [] + } + } + }, + { + "client_info": { + "mobilesdk_app_id": "1:814788024795:android:67c86939b6350f02c76ffe", + "android_client_info": { + "package_name": "com.example.practicefirestore1" + } + }, + "oauth_client": [], + "api_key": [ + { + "current_key": "AIzaSyAVpoftIYGZwiPRpuI56hoV8ifA2rbZGb4" + } + ], + "services": { + "appinvite_service": { + "other_platform_oauth_client": [] + } + } + } + ], + "configuration_version": "1" +} \ No newline at end of file -- 2.45.1 From 00799870756c8f9510830c2ce05f7a519787d98d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Mon, 15 Jan 2024 12:12:22 +0900 Subject: [PATCH 15/21] =?UTF-8?q?=E4=BE=9D=E5=AD=98=E9=96=A2=E4=BF=82?= =?UTF-8?q?=E3=81=AE=E8=A1=A8=E8=A8=98=E3=82=92Google=E3=81=AE=E3=83=89?= =?UTF-8?q?=E3=82=AD=E3=83=A5=E3=83=A1=E3=83=B3=E3=83=88=E3=81=AB=E5=90=88?= =?UTF-8?q?=E3=82=8F=E3=81=9B=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 71a9f46..6ee98c3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -59,8 +59,13 @@ dependencies { implementation 'androidx.compose.ui:ui-graphics' implementation 'androidx.compose.ui:ui-tooling-preview' implementation 'androidx.compose.material3:material3' - implementation 'com.google.firebase:firebase-firestore:24.4.1' + // Import the BoM for the Firebase platform + implementation(platform("com.google.firebase:firebase-bom:32.7.0")) + + // Declare the dependency for the Cloud Firestore library + // When using the BoM, you don't specify versions in Firebase library dependencies + implementation("com.google.firebase:firebase-firestore") testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.5' -- 2.45.1 From f7566d9df06f86b04fd7efaa94a24eb866a55f50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Mon, 15 Jan 2024 12:12:42 +0900 Subject: [PATCH 16/21] =?UTF-8?q?=E5=AE=9F=E8=A3=85=E3=82=92=E6=95=B4?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/childguard/HomeFragment.java | 68 +++++++++++-------- 1 file changed, 40 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/com/example/childguard/HomeFragment.java b/app/src/main/java/com/example/childguard/HomeFragment.java index 9405ba8..03dea26 100644 --- a/app/src/main/java/com/example/childguard/HomeFragment.java +++ b/app/src/main/java/com/example/childguard/HomeFragment.java @@ -12,6 +12,7 @@ import android.view.ViewGroup; import android.widget.Button; import android.widget.FrameLayout; import android.widget.TextView; +import android.widget.Toast; import androidx.annotation.NonNull; import androidx.core.content.res.ResourcesCompat; @@ -91,41 +92,52 @@ public class HomeFragment extends Fragment { @Override public void onClick(View v) { //初回起動かを保存する変数 - int i = Integer.parseInt(preferences.getString("kidoukaisuu", "1")); +// int i = Integer.parseInt(preferences.getString("kidoukaisuu", "1")); + boolean alreadySaved = preferences.getBoolean("alreadySaved", false); //ボタン変数の宣言 Button parent = view.findViewById(R.id.QRprinting); Button born = view.findViewById(R.id.QRprinting); - if (i == 1) {//QRコード印刷を初めて押したときにFireBaseへの登録を行う - String QRYomitorisya = parent.getText().toString();//変数に文字列を代入 - String valueBorn = born.getText().toString();//変数に文字列を代入 - Map user = new HashMap<>();//mapの宣言 + if (alreadySaved) { + Log.d("HomeFragment", "already printed"); + return; + } else Log.d("HomeFragment", "not printed yet"); // debug - Log.d("HomeFragment", "onClick is called"); + String valueParent = parent.getText().toString();//変数に文字列を代入 + String valueBorn = born.getText().toString();//変数に文字列を代入 + Map user = new HashMap<>();//mapの宣言 - //mapに入れる - user.put("parent", QRYomitorisya); - user.put("born", valueBorn); - //新しいドキュメントにIDを作って追加 - db.collection("users") - .add(user) - .addOnSuccessListener(new OnSuccessListener() { - @Override - public void onSuccess(DocumentReference documentReference) { - Log.d(TAG, "DocumentSnapshot added with ID: " + documentReference.getId()); - } - }) - .addOnFailureListener(new OnFailureListener() { - @Override - public void onFailure(@NonNull Exception e) {//エラー処理 - Log.w(TAG, "Error adding document", e); - } + Log.d("HomeFragment", "onClick is called"); - }); + //mapに入れる + user.put("parent", valueParent); + user.put("born", valueBorn); + //新しいドキュメントにIDを作って追加 + db.collection("users") + .add(user) + .addOnSuccessListener(new OnSuccessListener() { + @Override + public void onSuccess(DocumentReference documentReference) { + //成功したら + Log.d(TAG, "DocumentSnapshot added with ID: " + documentReference.getId()); + SharedPreferences.Editor e = preferences.edit(); + e.putBoolean("alreadySaved", true); + e.apply(); + //画面遷移 + replaceFragment(new QrPrintFragment()); + } + }) + .addOnFailureListener(new OnFailureListener() { + @Override + public void onFailure(@NonNull Exception e) { + //失敗したら + Log.w(TAG, "Error adding document", e); + } + }); - } - SharedPreferences.Editor e = preferences.edit(); - e.putString("kidoukiroku", "2"); - e.apply(); +// +// SharedPreferences.Editor e = preferences.edit(); +// e.putString("kidoukiroku", "2"); +// e.apply(); replaceFragment(new QrPrintFragment()); } }); -- 2.45.1 From 7d269853343b9e7859b4e7fa90e3ce880423279f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A3=AF=E9=87=8E?= Date: Mon, 15 Jan 2024 16:41:09 +0900 Subject: [PATCH 17/21] =?UTF-8?q?=E9=80=9A=E7=9F=A5=E3=82=92=E9=80=81?= =?UTF-8?q?=E3=82=8B=E6=A9=9F=E8=83=BD=E3=82=92=E8=BF=BD=E5=8A=A0=E3=81=97?= =?UTF-8?q?=E3=81=BE=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 2 + .../com/example/childguard/MainActivity.java | 67 ++++++++++++++----- build.gradle | 6 +- 3 files changed, 59 insertions(+), 16 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 6150f78..71a9f46 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ plugins { id 'com.android.application' id 'org.jetbrains.kotlin.android' + id 'com.google.gms.google-services' } android { @@ -58,6 +59,7 @@ dependencies { implementation 'androidx.compose.ui:ui-graphics' implementation 'androidx.compose.ui:ui-tooling-preview' implementation 'androidx.compose.material3:material3' + implementation 'com.google.firebase:firebase-firestore:24.4.1' testImplementation 'junit:junit:4.13.2' diff --git a/app/src/main/java/com/example/childguard/MainActivity.java b/app/src/main/java/com/example/childguard/MainActivity.java index 4de4695..9d01fb7 100644 --- a/app/src/main/java/com/example/childguard/MainActivity.java +++ b/app/src/main/java/com/example/childguard/MainActivity.java @@ -24,11 +24,25 @@ import java.util.Date; import java.util.Random; import java.util.UUID; +import android.util.Log; +import android.widget.Toast; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; +import com.google.firebase.firestore.DocumentReference; +import com.google.firebase.firestore.DocumentSnapshot; +import com.google.firebase.firestore.EventListener; +import com.google.firebase.firestore.FirebaseFirestore; +import com.google.firebase.firestore.FirebaseFirestoreException; + public class MainActivity extends AppCompatActivity { BluetoothManager bluetoothManager; BluetoothAdapter bluetoothAdapter; + public static final String TAG = "InspirationQuote"; + private DocumentReference mDocRef = FirebaseFirestore.getInstance().document("users/q6t702C8nsXyehckByrr");//現在の位置を取得 + boolean flg = false; + //↓日付を取得するやつ public static String getNowDate() { @SuppressLint("SimpleDateFormat") final DateFormat df = new SimpleDateFormat("yyy/MM/dd HH:mm:ss"); @@ -40,23 +54,13 @@ public class MainActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - - - //通知のやつ↓ - int importance = NotificationManager.IMPORTANCE_DEFAULT; - - NotificationChannel channel = new NotificationChannel("CHANNEL_ID", "通報通知", importance); - //説明・説明 ここに通知の説明を書くことができる↓ - channel.setDescription("第3者からの通報を検知しました"); - - NotificationManager notificationManager = getSystemService(NotificationManager.class); - notificationManager.createNotificationChannel(channel); - //通知のやつ↑ - + super.onStart(); BottomNavigationView bottomNavigationView = findViewById(R.id.nav_view); - bottomNavigationView.setOnNavigationItemSelectedListener(v -> { + bottomNavigationView.setOnNavigationItemSelectedListener(v -> + + { if (v.getItemId() == findViewById(R.id.navigation_home).getId()) { getSupportFragmentManager().beginTransaction() .replace(findViewById(R.id.fragmentContainerView).getId(), HomeFragment.newInstance("test", "tset")) @@ -73,6 +77,39 @@ public class MainActivity extends AppCompatActivity { return true; + + }); + mDocRef.addSnapshotListener(this, new EventListener() { + @Override + public void onEvent(@Nullable DocumentSnapshot documentSnapshot, @Nullable FirebaseFirestoreException e) { + Log.d("nt","イベント開始"); + if (flg && documentSnapshot != null && documentSnapshot.exists()) { + + String parent = documentSnapshot.getString("parent"); + Log.d("nt","レスポンスを検知しました1"); + if (parent.equals("s")) { + + //通知のやつ↓ + int importance = NotificationManager.IMPORTANCE_DEFAULT; + + NotificationChannel channel = new NotificationChannel("CHANNEL_ID", "通報通知", importance); + //説明・説明 ここに通知の説明を書くことができる↓ + channel.setDescription("第3者からの通報を検知しました"); + + NotificationManager notificationManager = getSystemService(NotificationManager.class); + notificationManager.createNotificationChannel(channel); + //通知のやつ↑ + Log.d("nt","レスポンスを検知しました2"); + + + notifyMain(); + } else if (e != null) { + Log.w(TAG, "Got an exceptiion!", e); + } + + } + flg = true; + } }); } @@ -110,4 +147,4 @@ public class MainActivity extends AppCompatActivity { ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(enableBackButton); } -} \ No newline at end of file +} diff --git a/build.gradle b/build.gradle index 4314313..e8491f3 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,8 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. +buildscript { + dependencies { + classpath 'com.google.gms:google-services:4.3.14' + } +}// Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { id 'com.android.application' version '8.0.2' apply false id 'com.android.library' version '8.0.2' apply false -- 2.45.1 From 98578291ea5b1089ebf7f23530e1b2a3dca30f07 Mon Sep 17 00:00:00 2001 From: it232115 Date: Tue, 16 Jan 2024 10:51:13 +0900 Subject: [PATCH 18/21] =?UTF-8?q?FIreBase=E3=81=B8=E3=81=AE=E7=99=BB?= =?UTF-8?q?=E9=8C=B2=E3=81=A8FireBase=E3=81=AB=E3=82=88=E3=81=A3=E3=81=A6?= =?UTF-8?q?=E7=94=9F=E6=88=90=E3=81=95=E3=82=8C=E3=81=9FID=E3=82=92?= =?UTF-8?q?=E7=94=A8=E3=81=84=E3=81=9FQR=E3=82=B3=E3=83=BC=E3=83=89?= =?UTF-8?q?=E3=81=AE=E7=94=9F=E6=88=90=E3=80=81=E7=99=BB=E9=8C=B2=E6=B8=88?= =?UTF-8?q?=E3=81=BF=E3=81=AE=E5=A0=B4=E5=90=88=E3=81=AF=E9=87=8D=E8=A4=87?= =?UTF-8?q?=E3=81=AE=E7=99=BB=E9=8C=B2=E3=81=AF=E8=A1=8C=E3=82=8F=E3=81=AA?= =?UTF-8?q?=E3=81=84=E3=82=88=E3=81=86=E3=81=AB=E3=81=99=E3=82=8B=E5=87=A6?= =?UTF-8?q?=E7=90=86=E3=82=92=E8=BF=BD=E5=8A=A0=E3=81=97=E3=81=BE=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 | 39 ++++++++++++------- .../main/java/com/example/childguard/QR.java | 26 ++++++------- .../com/example/childguard/QRFragment.java | 3 -- .../example/childguard/QrPrintFragment.java | 35 +++++++++++++---- app/src/main/res/layout/fragment_qr.xml | 7 ---- 5 files changed, 65 insertions(+), 45 deletions(-) diff --git a/app/src/main/java/com/example/childguard/HomeFragment.java b/app/src/main/java/com/example/childguard/HomeFragment.java index 03dea26..0446eb4 100644 --- a/app/src/main/java/com/example/childguard/HomeFragment.java +++ b/app/src/main/java/com/example/childguard/HomeFragment.java @@ -3,6 +3,7 @@ package com.example.childguard; import static android.content.ContentValues.TAG; import android.content.SharedPreferences; +import android.graphics.Bitmap; import android.os.Bundle; import android.preference.PreferenceManager; import android.util.Log; @@ -11,6 +12,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.FrameLayout; +import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; @@ -34,7 +36,6 @@ import java.util.Map; * create an instance of this fragment. */ public class HomeFragment extends Fragment { - FirebaseFirestore db = FirebaseFirestore.getInstance();//Firebaseとの紐づけ // TODO: Rename parameter arguments, choose names that match @@ -43,7 +44,7 @@ public class HomeFragment extends Fragment { private static final String ARG_PARAM2 = "param2"; // TODO: Rename and change types of parameters - private String mParam1; + private String str_key; private String mParam2; public HomeFragment() { @@ -72,7 +73,7 @@ public class HomeFragment extends Fragment { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getArguments() != null) { - mParam1 = getArguments().getString(ARG_PARAM1); + // mParam1 = getArguments().getString(ARG_PARAM1); mParam2 = getArguments().getString(ARG_PARAM2); } } @@ -92,13 +93,17 @@ public class HomeFragment extends Fragment { @Override public void onClick(View v) { //初回起動かを保存する変数 -// int i = Integer.parseInt(preferences.getString("kidoukaisuu", "1")); boolean alreadySaved = preferences.getBoolean("alreadySaved", false); //ボタン変数の宣言 Button parent = view.findViewById(R.id.QRprinting); Button born = view.findViewById(R.id.QRprinting); - if (alreadySaved) { + //falseのときにFirebaseへの登録 + if (!alreadySaved) { Log.d("HomeFragment", "already printed"); + //画面遷移&ID受け渡し + Toast.makeText(getActivity(),"再印刷",Toast.LENGTH_SHORT).show(); + QrPrintFragment qrPrintFragment = new QrPrintFragment(); + replaceFragment(qrPrintFragment); return; } else Log.d("HomeFragment", "not printed yet"); // debug @@ -118,12 +123,23 @@ public class HomeFragment extends Fragment { @Override public void onSuccess(DocumentReference documentReference) { //成功したら + //documentReference.getId()でID取得 Log.d(TAG, "DocumentSnapshot added with ID: " + documentReference.getId()); SharedPreferences.Editor e = preferences.edit(); - e.putBoolean("alreadySaved", true); + // キー"alreadySaved"の値をtrueにする + e.putBoolean("alreadySaved", false); + //確定処理 e.apply(); - //画面遷移 - replaceFragment(new QrPrintFragment()); + //画面遷移&ID受け渡し + str_key = "" + documentReference.getId(); + Toast.makeText(getActivity(),"初回登録",Toast.LENGTH_SHORT).show(); + QrPrintFragment qrPrintFragment = new QrPrintFragment(); + Bundle bundle = new Bundle(); + bundle.putString("STR_KEY",str_key); + //値を書き込む + qrPrintFragment.setArguments(bundle); + replaceFragment(qrPrintFragment); + } }) .addOnFailureListener(new OnFailureListener() { @@ -134,11 +150,7 @@ public class HomeFragment extends Fragment { } }); -// -// SharedPreferences.Editor e = preferences.edit(); -// e.putString("kidoukiroku", "2"); -// e.apply(); - replaceFragment(new QrPrintFragment()); + } }); //bluetooth設定ボタンの処理 @@ -160,7 +172,6 @@ public class HomeFragment extends Fragment { FrameLayout situation_bg = getView().findViewById(R.id.situation_bg); updateInCarStatus(situationTextView, situation_bg); } - public void updateInCarStatus(TextView situationTextView, FrameLayout situation_bg) { SharedPreferences sharedPreferences = getActivity().getSharedPreferences("default", 0); diff --git a/app/src/main/java/com/example/childguard/QR.java b/app/src/main/java/com/example/childguard/QR.java index ebdf156..1d4e862 100644 --- a/app/src/main/java/com/example/childguard/QR.java +++ b/app/src/main/java/com/example/childguard/QR.java @@ -15,19 +15,19 @@ public class QR extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.fragment_qr); - - findViewById(R.id.camera).setOnClickListener( - v -> { - if(get_on.equals(tv.getText().toString())){ - tv.setText(get_off); - findViewById(R.id.situation_bg).setBackgroundColor(Color.parseColor("#dcdcdc")); - } - else { - tv.setText(get_on); - findViewById(R.id.situation_bg).setBackgroundColor(Color.parseColor("#ff4500")); - } - } - ); + //多分いらないコード +// findViewById(R.id.camera).setOnClickListener( +// v -> { +// if(get_on.equals(tv.getText().toString())){ +// tv.setText(get_off); +// findViewById(R.id.situation_bg).setBackgroundColor(Color.parseColor("#dcdcdc")); +// } +// else { +// tv.setText(get_on); +// findViewById(R.id.situation_bg).setBackgroundColor(Color.parseColor("#ff4500")); +// } +// } +// ); } } diff --git a/app/src/main/java/com/example/childguard/QRFragment.java b/app/src/main/java/com/example/childguard/QRFragment.java index fc0e0a8..f97a174 100644 --- a/app/src/main/java/com/example/childguard/QRFragment.java +++ b/app/src/main/java/com/example/childguard/QRFragment.java @@ -97,13 +97,10 @@ public class QRFragment extends Fragment { // Inflate the layout for this fragment View view = inflater.inflate(R.layout.fragment_qr, container, false); - Button cameraButton = view.findViewById(R.id.camera); - cameraButton.setOnClickListener(v -> { Log.d("QRFragment", "onClick: called"); //QRリーダ起動 fragmentLauncher.launch(new ScanOptions()); - }); return view; } diff --git a/app/src/main/java/com/example/childguard/QrPrintFragment.java b/app/src/main/java/com/example/childguard/QrPrintFragment.java index d31ac6e..21c7646 100644 --- a/app/src/main/java/com/example/childguard/QrPrintFragment.java +++ b/app/src/main/java/com/example/childguard/QrPrintFragment.java @@ -1,5 +1,6 @@ package com.example.childguard; +import android.content.SharedPreferences; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; @@ -10,6 +11,7 @@ import android.os.Bundle; import androidx.fragment.app.Fragment; import androidx.print.PrintHelper; +import android.preference.PreferenceManager; import android.util.AndroidRuntimeException; import android.view.LayoutInflater; import android.view.View; @@ -59,7 +61,7 @@ public class QrPrintFragment extends Fragment { } @Override - public void onCreate(Bundle savedInstanceState) { + public void onCreate (Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getArguments() != null) { mParam1 = getArguments().getString(ARG_PARAM1); @@ -68,18 +70,34 @@ public class QrPrintFragment extends Fragment { } } - @Override + // @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + //共有プリファレンス 全体の準備 + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity()); + //User毎のドメインを保存する + String IdPref=preferences.getString("ID",null); // Inflate the layout for this fragment - View view=inflater.inflate(R.layout.fragment_qr_print, container, false); - + View view=inflater.inflate(R.layout.fragment_qr_print, container, false);; //固定のドメイン String KoteiURL = "https://practicefirestore1-8808c.web.app/?id="; - //User毎のドメイン - String userURL="YKjFsZgJBlZmcyvdZ3Ap"; - //二つのドメインを合成する - String AllURL=KoteiURL+userURL; + //すべてのドメイン + String AllURL; + //IdPrefにの値が初期値の場合 + if(IdPref==null) { + //User毎のドメイン + String userURL = getArguments().getString("STR_KEY"); + //キー"ID"の値をuserURLの値にする + SharedPreferences.Editor e = preferences.edit(); + e.putString("ID", userURL); + //確定処理 + e.apply(); + //二つのドメインを合成する + AllURL=KoteiURL+userURL; + }else{ + //二つのドメインを合成する + AllURL=KoteiURL+IdPref; + } int size = 2500; ImageView imageViewQrCode; @@ -96,6 +114,7 @@ public class QrPrintFragment extends Fragment { throw new AndroidRuntimeException("Barcode Error.", e); } // 画像合成の準備 + // ここのエラーは直すと何故か動かなくなる。このままで動くので放置 Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.a_group_qr_sos); Bitmap bitmap1 = ((BitmapDrawable) imageViewQrCode.getDrawable()).getBitmap(); int width = bitmap.getWidth(); // 元ファイルの幅取得 diff --git a/app/src/main/res/layout/fragment_qr.xml b/app/src/main/res/layout/fragment_qr.xml index b66b029..1509787 100644 --- a/app/src/main/res/layout/fragment_qr.xml +++ b/app/src/main/res/layout/fragment_qr.xml @@ -5,13 +5,6 @@ android:layout_height="match_parent" tools:context=".QRFragment"> - -