From 1a33e070b51b62f0b1d6e762d0239f2fccec7c54 Mon Sep 17 00:00:00 2001 From: it232115 Date: Fri, 12 Jan 2024 11:31:27 +0900 Subject: [PATCH 1/4] =?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()); From afc0f02378fcf0e2acf734de1869731508c8fb86 Mon Sep 17 00:00:00 2001 From: it232115 Date: Fri, 12 Jan 2024 11:32:50 +0900 Subject: [PATCH 2/4] =?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 From 0dac52e0fba9eb6a3fa40954886326ec3647024e Mon Sep 17 00:00:00 2001 From: it232115 Date: Fri, 12 Jan 2024 11:33:29 +0900 Subject: [PATCH 3/4] =?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 From eb4e3b4a38acedc62cb883843a3a654fb28b5889 Mon Sep 17 00:00:00 2001 From: it232115 Date: Fri, 12 Jan 2024 11:34:16 +0900 Subject: [PATCH 4/4] =?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()));