From 114faf1ac0b13e5b72cc313c358236840e256ceb Mon Sep 17 00:00:00 2001 From: it232115 Date: Mon, 15 Jan 2024 10:04:53 +0900 Subject: [PATCH 1/8] 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 From 004a0820e2e5fb172ffc2a488c92097fdf49fd93 Mon Sep 17 00:00:00 2001 From: it232115 Date: Mon, 15 Jan 2024 11:43:49 +0900 Subject: [PATCH 2/8] 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 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 3/8] =?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' 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 4/8] =?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()); } }); From 98578291ea5b1089ebf7f23530e1b2a3dca30f07 Mon Sep 17 00:00:00 2001 From: it232115 Date: Tue, 16 Jan 2024 10:51:13 +0900 Subject: [PATCH 5/8] =?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"> - -