This commit is contained in:
it232115 2024-01-15 10:04:53 +09:00
parent c603d516e8
commit 114faf1ac0
5 changed files with 73 additions and 59 deletions

View File

@ -1,6 +1,7 @@
plugins { plugins {
id 'com.android.application' id 'com.android.application'
id 'org.jetbrains.kotlin.android' id 'org.jetbrains.kotlin.android'
id 'com.google.gms.google-services'
} }
android { android {
@ -58,6 +59,7 @@ dependencies {
implementation 'androidx.compose.ui:ui-graphics' implementation 'androidx.compose.ui:ui-graphics'
implementation 'androidx.compose.ui:ui-tooling-preview' implementation 'androidx.compose.ui:ui-tooling-preview'
implementation 'androidx.compose.material3:material3' implementation 'androidx.compose.material3:material3'
implementation 'com.google.firebase:firebase-firestore:24.4.1'
testImplementation 'junit:junit:4.13.2' testImplementation 'junit:junit:4.13.2'

View File

@ -1,34 +1,31 @@
package com.example.childguard; package com.example.childguard;
import static android.content.ContentValues.TAG;
import android.content.SharedPreferences; 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 android.os.Bundle;
import android.preference.PreferenceManager;
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.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import com.google.zxing.BarcodeFormat; import androidx.annotation.NonNull;
import com.google.zxing.WriterException; import androidx.core.content.res.ResourcesCompat;
import com.journeyapps.barcodescanner.BarcodeEncoder; 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. * A simple {@link Fragment} subclass.
@ -37,6 +34,8 @@ import com.journeyapps.barcodescanner.BarcodeEncoder;
*/ */
public class HomeFragment extends Fragment { public class HomeFragment extends Fragment {
FirebaseFirestore db = FirebaseFirestore.getInstance();//Firebaseとの紐づけ
// TODO: Rename parameter arguments, choose names that match // TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1"; private static final String ARG_PARAM1 = "param1";
@ -80,20 +79,58 @@ public class HomeFragment extends Fragment {
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
// Log.d("HomeFlagment_cnt", "aaaaa");
// Inflate the layout for this fragment // 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(); MainActivity activity = (MainActivity) getActivity();
//共有プリファレンス 全体の準備
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
//QRコード印刷の処理 //QRコード印刷の処理
Button bt1=view.findViewById(R.id.QRprinting); Button bt1 = view.findViewById(R.id.QRprinting);
bt1.setOnClickListener(new View.OnClickListener() { bt1.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { 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<String, String> 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<DocumentReference>() {
@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設定ボタンの処理 //bluetooth設定ボタンの処理
Button bt2=view.findViewById(R.id.Bluetooth_setup); Button bt2 = view.findViewById(R.id.Bluetooth_setup);
bt2.setOnClickListener(new View.OnClickListener() { bt2.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -108,11 +145,11 @@ public class HomeFragment extends Fragment {
super.onResume(); super.onResume();
Log.d("HomeFragment", "onResume: called"); Log.d("HomeFragment", "onResume: called");
TextView situationTextView = getView().findViewById(R.id.situation); TextView situationTextView = getView().findViewById(R.id.situation);
FrameLayout situation_bg=getView().findViewById(R.id.situation_bg); FrameLayout situation_bg = getView().findViewById(R.id.situation_bg);
updateInCarStatus(situationTextView,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); SharedPreferences sharedPreferences = getActivity().getSharedPreferences("default", 0);
Log.d("HomeFragment", "updateInCarStatus: " + sharedPreferences.getBoolean("inCar", false)); 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()? FragmentManager manager = getParentFragmentManager(); // アクティビティではgetSupportFragmentManager()?
// フラグメントトランザクションの開始 // フラグメントトランザクションの開始

View File

@ -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);
}
}

View File

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".UrlPageActivity">
<WebView
android:id="@+id/url_page"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -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 { plugins {
id 'com.android.application' version '8.0.2' apply false id 'com.android.application' version '8.0.2' apply false
id 'com.android.library' version '8.0.2' apply false id 'com.android.library' version '8.0.2' apply false