From 3fa1fe412a17e7fdc5e0d7d74434222161f086d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A3=AF=E9=87=8E?= Date: Tue, 16 Jan 2024 11:21:54 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=E9=80=9A=E7=9F=A5=E3=82=92=E9=80=81?= =?UTF-8?q?=E3=82=8B=E6=A9=9F=E8=83=BD=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 --- app/src/main/java/com/example/childguard/MainActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/example/childguard/MainActivity.java b/app/src/main/java/com/example/childguard/MainActivity.java index 9d01fb7..50dc31a 100644 --- a/app/src/main/java/com/example/childguard/MainActivity.java +++ b/app/src/main/java/com/example/childguard/MainActivity.java @@ -40,7 +40,7 @@ public class MainActivity extends AppCompatActivity { BluetoothAdapter bluetoothAdapter; public static final String TAG = "InspirationQuote"; - private DocumentReference mDocRef = FirebaseFirestore.getInstance().document("users/q6t702C8nsXyehckByrr");//現在の位置を取得 + private DocumentReference mDocRef = FirebaseFirestore.getInstance().document("users/rrVGKi77MAemxvPZrktm");//現在の位置を取得 boolean flg = false; //↓日付を取得するやつ -- 2.45.1 From 6ef92ad3c1ba4ee4e22c4f81655a3fabbf732c97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A3=AF=E9=87=8E?= Date: Mon, 22 Jan 2024 04:23:50 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=E3=83=AA=E3=82=B9=E3=83=88=E5=8C=96?= =?UTF-8?q?=E3=81=99=E3=82=8B=E6=A9=9F=E8=83=BD=E3=82=92=E3=81=A4=E3=81=91?= =?UTF-8?q?=E3=81=BE=E3=81=97=E3=81=9F=E3=80=82=EF=BC=88=E4=B8=80=E9=83=A8?= =?UTF-8?q?=E5=BE=AE=E4=BF=AE=E6=AD=A3=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/childguard/MainActivity.java | 13 ++- .../com/example/childguard/TestService.java | 83 ++++++++++++++++++- .../main/res/layout/fragment_notification.xml | 28 +++++-- 3 files changed, 111 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/example/childguard/MainActivity.java b/app/src/main/java/com/example/childguard/MainActivity.java index 5f1cdef..846a4e2 100644 --- a/app/src/main/java/com/example/childguard/MainActivity.java +++ b/app/src/main/java/com/example/childguard/MainActivity.java @@ -20,6 +20,7 @@ import android.os.Bundle; import android.os.Vibrator; import android.preference.PreferenceManager; import android.util.Log; +import android.view.View; import android.widget.FrameLayout; import android.widget.Toast; @@ -52,6 +53,7 @@ public class MainActivity extends AppCompatActivity { public static final String TAG = "InspirationQuote"; + private final ActivityResultLauncher QrLauncher = registerForActivityResult( new ScanContract(), result -> { @@ -60,7 +62,7 @@ public class MainActivity extends AppCompatActivity { Toast.makeText(this, "QRコードが読み取れませんでした", Toast.LENGTH_LONG).show(); } else { if (!contents.contains("https://practicefirestore1-8808c.web.app/")) { - Toast.makeText(this, "Chiled Guardに対応するQRコードではありません", Toast.LENGTH_LONG).show(); + Toast.makeText(this, "Child Guardに対応するQRコードではありません", Toast.LENGTH_LONG).show(); } else { //URLの表示 Toast.makeText(this, contents, Toast.LENGTH_SHORT).show(); @@ -73,15 +75,17 @@ public class MainActivity extends AppCompatActivity { } ); + @SuppressLint("MissingInflatedId") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + db = FirebaseFirestore.getInstance();//Firebaseとの紐づけ BottomNavigationView bottomNavigationView = findViewById(R.id.nav_view); - this.homeFragment = HomeFragment.newInstance("test", "tset"); + this.homeFragment = HomeFragment.newInstance("test", "test"); bottomNavigationView.setOnNavigationItemSelectedListener(v -> @@ -119,6 +123,7 @@ public class MainActivity extends AppCompatActivity { }); + //Bluetooth検知機能 IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED); @@ -131,8 +136,10 @@ public class MainActivity extends AppCompatActivity { Log.d("BT", "Permission to connect bluetooth devices granted"); } registerReceiver(receiver, intentFilter); + } + @Override protected void onResume() { super.onResume(); @@ -159,7 +166,7 @@ public class MainActivity extends AppCompatActivity { Log.d("nt", "レスポンスを検知しました1"); //FireBaseで更新された情報の判定 if (documentSnapshot.getBoolean("isReported") == false) {//isReportedがfalseのとき=サイト上で保護者ボタンが押されたとき - if (fragment instanceof HomeFragment) {//fragementがHomeFragmentのインスタンスかの判定 + if (fragment instanceof HomeFragment) {//fragmentがHomeFragmentのインスタンスかの判定 // changessituation();// changessituation()メソッドを処理→アプリ側の乗降状態を変化 ((HomeFragment) fragment).onEvent(!isInCar); } diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 28ed5a2..64a8ca4 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -1,6 +1,7 @@ package com.example.childguard; import android.annotation.SuppressLint; +import android.app.Activity; import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; @@ -14,6 +15,7 @@ import android.content.IntentFilter; import android.content.pm.PackageManager; import android.graphics.Color; import android.os.Build; +import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.os.Looper; @@ -25,10 +27,18 @@ import android.widget.Toast; import androidx.annotation.Nullable; import androidx.core.app.ActivityCompat; import androidx.core.app.NotificationCompat; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import com.google.firebase.firestore.DocumentReference; import com.google.firebase.firestore.FirebaseFirestore; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -40,9 +50,76 @@ public class TestService extends Service { public PeriodicTaskManager periodicTaskManager; + //時間を取得するやつ↓ + public static String getNowDate() { + @SuppressLint("SimpleDateFormat") final DateFormat df = new SimpleDateFormat("yyy/MM/dd HH:mm:ss"); + final Date date = new Date(System.currentTimeMillis()); + return df.format(date); + } + + @SuppressLint("NotifyDataSetChanged") + public void NotifityRecycle(){ + + RecyclerView recyclerView = recyclerView().findViewById(R.id.recyclerView1); + + //RecyclerViewのサイズを固定 + recyclerView.setHasFixedSize(true); + + //RecyclerViewに区切り線を入れる + RecyclerView.ItemDecoration itemDecoration = + new DividerItemDecoration(this, DividerItemDecoration.VERTICAL); + recyclerView.addItemDecoration(itemDecoration); + + //レイアウトマネージャを設定 + RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this); + recyclerView.setLayoutManager(layoutManager); + + //①リスト構造(String型の可変長の配列)を宣言 + ArrayList arrayList = new ArrayList<>(); + + //③Adapterとリスト構造を結び付け + //RecyclerAdapterクラスを呼び出す + RecyclerAdapter2 adapter = new RecyclerAdapter2(arrayList, null); + + //④RecyclerViewとAdapterの結び付け + recyclerView.setAdapter(adapter); + + SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this); + + arrayList.add(0,"通知を検知しました: " + getNowDate()); + + //一番下に値が追加されたことをAdapterが画面に通知 + adapter.notifyItemInserted(arrayList.size()); + + //共有プリファレンス 書き込みの準備 + SharedPreferences.Editor e = pref.edit(); + + //リストを,区切りで結合する + String str = String.join(",", arrayList); + + //変数名currentに、値の代入 + e.putString("current", str.toString()); + + //確定処理 + e.apply(); + + String strTo = pref.getString("current", null); + if (strTo == null) return; + + String[] list = strTo.split(","); + arrayList.clear(); + arrayList.addAll(Arrays.asList(list)); + adapter.notifyDataSetChanged(); + } + + private Activity recyclerView() { + return null; + } @Override public int onStartCommand(Intent intent, int flags, int startId) { + + NotifityRecycle(); //共有プリファレンス全体の準備 SharedPreferences sharedPreferences = getSharedPreferences("app_situation", MODE_PRIVATE); String IdPref = sharedPreferences.getString("ID", null);//アプリに記録されているIDの取得 @@ -53,6 +130,8 @@ public class TestService extends Service { initNotification(mDocRef);//現在の位置を引数に initNotification()を処理 } return flags; + + } private void initNotification(DocumentReference mDocRef) {//サイト上で押されたボタンの管理 @@ -173,7 +252,7 @@ public class TestService extends Service { @SuppressLint("NotificationTrampoline") NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "CHANNEL_ID") .setSmallIcon(android.R.drawable.ic_menu_info_details) .setContentTitle("子供の置き去りをしていませんか?")//通知のタイトル - .setContentText("Bluetootと車の切断から"+time+"分が経過しました")//通知の本文 + .setContentText("Bluetoothと車の切断から"+time+"分が経過しました")//通知の本文 .setContentIntent(pendingIntent)//通知をタップするとActivityへ移動する .setAutoCancel(true)//通知をタップすると削除する .setPriority(NotificationCompat.PRIORITY_HIGH) // プライオリティを高く設定 @@ -223,7 +302,7 @@ public class TestService extends Service { int time=sharedPreferences.getInt("time",0); //共有プリファレンス 書き込みの準備 SharedPreferences.Editor E = sharedPreferences.edit(); - if(time==0) {//Bluetoot切断からの時間経過(5分刻み) + if(time==0) {//Bluetooth切断からの時間経過(5分刻み) E.putInt("time",5); E.apply();; }else { diff --git a/app/src/main/res/layout/fragment_notification.xml b/app/src/main/res/layout/fragment_notification.xml index 0d4f90d..51d2ca8 100644 --- a/app/src/main/res/layout/fragment_notification.xml +++ b/app/src/main/res/layout/fragment_notification.xml @@ -6,18 +6,30 @@ tools:context=".NotificationFragment"> - + android:layout_height="match_parent" + android:weightSum="10" + android:orientation="vertical" + tools:context=".MainActivity"> - + android:layout_height="wrap_content" + android:layout_weight="9"> + + + + + + \ No newline at end of file -- 2.45.1 From 39e9336de0bef9db2299b7e18c8f95a3caf5610a Mon Sep 17 00:00:00 2001 From: it232115 Date: Mon, 22 Jan 2024 22:06:37 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=E5=90=84=E7=A8=AE=E3=83=90=E3=82=B0?= =?UTF-8?q?=E3=81=AE=E4=BF=AE=E6=AD=A3=20=E9=80=9A=E7=9F=A5=E3=81=AE?= =?UTF-8?q?=E3=83=AA=E3=82=B9=E3=83=88=E5=8C=96=E6=98=A8=E6=97=A5=E3=81=AE?= =?UTF-8?q?=E6=96=AD=E5=BF=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/example/childguard/HomeFragment.java | 2 ++ .../main/java/com/example/childguard/MainActivity.java | 8 ++------ app/src/main/res/menu/bottom_menu.xml | 5 +---- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/example/childguard/HomeFragment.java b/app/src/main/java/com/example/childguard/HomeFragment.java index d3e093b..e95ce6d 100644 --- a/app/src/main/java/com/example/childguard/HomeFragment.java +++ b/app/src/main/java/com/example/childguard/HomeFragment.java @@ -1,5 +1,6 @@ package com.example.childguard; +import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.util.Log; @@ -62,6 +63,7 @@ public class HomeFragment extends Fragment implements OnEventListener{ mParam2 = getArguments().getString(ARG_PARAM2); } + } @Override diff --git a/app/src/main/java/com/example/childguard/MainActivity.java b/app/src/main/java/com/example/childguard/MainActivity.java index 5f1cdef..02d2ce8 100644 --- a/app/src/main/java/com/example/childguard/MainActivity.java +++ b/app/src/main/java/com/example/childguard/MainActivity.java @@ -94,12 +94,7 @@ public class MainActivity extends AppCompatActivity { .commit(); firebaselink(); - } else if (v.getItemId() == findViewById(R.id.navigation_notification).getId()) { - findViewById(R.id.fab_scan_qr_code).setVisibility(FrameLayout.VISIBLE); - getSupportFragmentManager().beginTransaction() - .replace(findViewById(R.id.fragmentContainerView).getId(), NotificationFragment.newInstance("test", "test")) - .addToBackStack(null) - .commit(); + } else if (v.getItemId() == findViewById(R.id.navigation_settings).getId()) { findViewById(R.id.fab_scan_qr_code).setVisibility(FrameLayout.GONE); getSupportFragmentManager().beginTransaction() @@ -107,6 +102,7 @@ public class MainActivity extends AppCompatActivity { .addToBackStack(null) .commit(); } + firebaselink(); return true; }); diff --git a/app/src/main/res/menu/bottom_menu.xml b/app/src/main/res/menu/bottom_menu.xml index c3e8d9a..0d0305f 100644 --- a/app/src/main/res/menu/bottom_menu.xml +++ b/app/src/main/res/menu/bottom_menu.xml @@ -4,10 +4,7 @@ android:id="@+id/navigation_home" android:icon="@drawable/ic_home_black_24dp" android:title="home"/> - +