wip
This commit is contained in:
parent
c603d516e8
commit
114faf1ac0
|
@ -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'
|
||||
|
|
|
@ -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,16 +79,54 @@ 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);
|
||||
MainActivity activity = (MainActivity) getActivity();
|
||||
//共有プリファレンス 全体の準備
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
//QRコード印刷の処理
|
||||
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<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設定ボタンの処理
|
||||
|
@ -125,6 +162,7 @@ public class HomeFragment extends Fragment {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
//画面遷移メソッド
|
||||
private void replaceFragment(Fragment fragment) {
|
||||
// フラグメントマネージャーの取得
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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>
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user