Compare commits

..
Author SHA1 Message Date
ろむねこ c90d0b8f6e Merge pull request #16 from child-guardian/fix-1
Fix 1
2024-01-17 20:07:45 +09:00
r-ca 87fbf5659e onStopをコメントアウト 2024-01-17 20:05:49 +09:00
r-ca 39ebdf0259 条件式を変更 2024-01-17 19:55:30 +09:00
r-ca 23be550762 onResumeの場所を変更 2024-01-17 19:50:41 +09:00
r-ca 51fd91027d ShardPreferenceのチェックが異常だったので修正 2024-01-17 19:49:28 +09:00
ろむねこ e4aafc44c6 Merge pull request #15 from child-guardian/rca/fix_ui
Rca/fix UI
2024-01-17 19:27:28 +09:00
meato a4178b6901 onStopを追加 2024-01-17 17:43:54 +09:00
4 changed files with 95 additions and 13 deletions

No files matched your search

+2 -1
View File
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" /> <component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="jbr-17" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">
+2
View File
@@ -10,6 +10,7 @@
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" /> <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<application <application
android:allowBackup="true" android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules" android:dataExtractionRules="@xml/data_extraction_rules"
@@ -34,6 +35,7 @@
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<service android:name=".TestService" />
</application> </application>
</manifest> </manifest>
@@ -23,6 +23,7 @@ import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Paint;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Vibrator; import android.os.Vibrator;
@@ -85,7 +86,8 @@ public class MainActivity extends AppCompatActivity {
String contents = result.getContents(); String contents = result.getContents();
if (contents == null) { if (contents == null) {
Toast.makeText(this, "QRコードが読み取れませんでした", Toast.LENGTH_LONG).show(); Toast.makeText(this, "QRコードが読み取れませんでした", Toast.LENGTH_LONG).show();
} else if (!contents.contains("https://practicefirestore1-8808c.web.app/")) { } else {
if (!contents.contains("https://practicefirestore1-8808c.web.app/")) {
Toast.makeText(this, "Chiled Guardに対応するQRコードではありません", Toast.LENGTH_LONG).show(); Toast.makeText(this, "Chiled Guardに対応するQRコードではありません", Toast.LENGTH_LONG).show();
} else { } else {
//URLの表示 //URLの表示
@@ -96,6 +98,7 @@ public class MainActivity extends AppCompatActivity {
customTabsIntent.launchUrl(this, Uri.parse(contents)); customTabsIntent.launchUrl(this, Uri.parse(contents));
} }
} }
}
); );
@Override @Override
@@ -134,7 +137,7 @@ public class MainActivity extends AppCompatActivity {
}); });
findViewById(R.id.fab_scan_qr_code).setOnClickListener(v -> { findViewById(R.id.fab_scan_qr_code).setOnClickListener(v -> {
Log.d("QRFragment", "onClick: called"); Log.d("MainActivity/Fab", "onClick: called");
//QRリーダ起動 //QRリーダ起動
ScanOptions options = new ScanOptions(); ScanOptions options = new ScanOptions();
options.setPrompt("QRコードを読み取ってください"); options.setPrompt("QRコードを読み取ってください");
@@ -159,19 +162,18 @@ public class MainActivity extends AppCompatActivity {
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume();
Log.d("onResume", "called"); Log.d("onResume", "called");
Log.d("onResume", "mDocRef is null"); Log.d("onResume", "mDocRef is null");
SharedPreferences sharedPreferences = getSharedPreferences("app_situation", MODE_PRIVATE); SharedPreferences sharedPreferences = getSharedPreferences("app_situation", MODE_PRIVATE);
String IdPref = sharedPreferences.getString("ID", null); String IdPref = sharedPreferences.getString("ID", null);
if (IdPref == null) { if (IdPref == null) {
Log.d("onResume", "ID not initialized."); Log.d("onResume", "ID not initialized.");
return; } else {
}
mDocRef = FirebaseFirestore.getInstance().document("users/" + IdPref);//現在の位置を取得 mDocRef = FirebaseFirestore.getInstance().document("users/" + IdPref);//現在の位置を取得
this.flg = false; this.flg = false;
initNotification(mDocRef); initNotification(mDocRef);
}
super.onResume();
} }
private void initNotification(DocumentReference mDocRef) { private void initNotification(DocumentReference mDocRef) {
@@ -192,6 +194,7 @@ public class MainActivity extends AppCompatActivity {
String parent = documentSnapshot.getString("parent"); String parent = documentSnapshot.getString("parent");
Log.d("nt", "レスポンスを検知しました1"); Log.d("nt", "レスポンスを検知しました1");
assert parent != null;
if (parent.equals("s")) {//FireBaseの更新情報が"S"のとき=サイト上で第三者ボタンが押されたとき if (parent.equals("s")) {//FireBaseの更新情報が"S"のとき=サイト上で第三者ボタンが押されたとき
if (isInCar) { if (isInCar) {
int importance = NotificationManager.IMPORTANCE_DEFAULT; int importance = NotificationManager.IMPORTANCE_DEFAULT;
@@ -203,13 +206,8 @@ public class MainActivity extends AppCompatActivity {
notifyMain(); notifyMain();
} }
} else { } else {
if (isInCar) { E.putBoolean("car", !isInCar);
E.putBoolean("car", false);
E.apply(); E.apply();
} else {
E.putBoolean("car", true);
E.apply();
}
// SupportFragmentManagerが現在表示しているFragmentを取得 // SupportFragmentManagerが現在表示しているFragmentを取得
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragmentContainerView); Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragmentContainerView);
if (fragment instanceof HomeFragment) { if (fragment instanceof HomeFragment) {
@@ -291,6 +289,13 @@ public class MainActivity extends AppCompatActivity {
} }
// @Override
// public void onStop() {
// super.onStop();
// Intent intent = new Intent(getApplication(), TestService.class);
// startService(intent);
// }
//Bluetooth_setupの戻るボタン //Bluetooth_setupの戻るボタン
public void setupBackButton(boolean enableBackButton) { public void setupBackButton(boolean enableBackButton) {
ActionBar actionBar = getSupportActionBar(); ActionBar actionBar = getSupportActionBar();
@@ -0,0 +1,74 @@
package com.example.childguard;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.IBinder;
import android.os.Vibrator;
import android.util.Log;
import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
public class TestService extends Service {
public int onStartCommand(Intent intent, int flags, int startId) {
audioStart();
return START_NOT_STICKY;
}
private void audioStart(){
//↓通知をする際に起動するバイブレーション
((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).vibrate(1000);
//通知のやつ↓
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel channel = new NotificationChannel("CHANNEL_ID", "通報通知", importance);
//説明・説明 ここに通知の説明を書くことができる↓
channel.setDescription("第3者からの通報を検知しました");
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
//通知のやつ↑
Log.d("nt","レスポンスを検知しました2");
//↓通知の詳細設定的な奴
NotificationCompat.Builder builder = new NotificationCompat
.Builder(this, "CHANNEL_ID")
.setSmallIcon(android.R.drawable.ic_menu_info_details)
.setContentTitle("通報検知")
.setContentText("子供の置き去りを検知しました。")
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
notificationManager.notify(R.string.app_name, builder.build());
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
}