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());
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()));
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
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