2023-12-18 07:07:21 +00:00
|
|
|
package com.example.childguard;
|
|
|
|
|
2024-01-11 07:30:02 +00:00
|
|
|
import androidx.appcompat.app.ActionBar;
|
2023-12-18 07:07:21 +00:00
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
2023-12-22 03:00:58 +00:00
|
|
|
import androidx.core.app.ActivityCompat;
|
|
|
|
import androidx.core.app.NotificationCompat;
|
|
|
|
import androidx.core.app.NotificationManagerCompat;
|
2023-12-18 07:07:21 +00:00
|
|
|
|
2024-01-12 03:23:22 +00:00
|
|
|
import android.annotation.SuppressLint;
|
2023-12-22 03:00:58 +00:00
|
|
|
import android.app.NotificationChannel;
|
|
|
|
import android.app.NotificationManager;
|
2024-01-11 07:30:02 +00:00
|
|
|
import android.bluetooth.BluetoothAdapter;
|
|
|
|
import android.bluetooth.BluetoothManager;
|
2023-12-22 03:00:58 +00:00
|
|
|
import android.content.Context;
|
2024-01-16 06:51:49 +00:00
|
|
|
import android.content.SharedPreferences;
|
2023-12-22 03:00:58 +00:00
|
|
|
import android.content.pm.PackageManager;
|
2024-01-16 06:51:49 +00:00
|
|
|
import android.graphics.Color;
|
2023-12-18 07:07:21 +00:00
|
|
|
import android.os.Bundle;
|
2023-12-22 03:00:58 +00:00
|
|
|
import android.os.Vibrator;
|
2023-12-18 07:07:21 +00:00
|
|
|
|
|
|
|
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
|
|
|
|
2024-01-12 03:23:22 +00:00
|
|
|
import java.text.DateFormat;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.Date;
|
2024-01-11 07:30:02 +00:00
|
|
|
import java.util.Random;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
2024-01-16 06:51:49 +00:00
|
|
|
import android.preference.PreferenceManager;
|
2024-01-15 07:41:09 +00:00
|
|
|
import android.util.Log;
|
2024-01-16 06:51:49 +00:00
|
|
|
import android.widget.FrameLayout;
|
|
|
|
import android.widget.TextView;
|
2024-01-15 07:41:09 +00:00
|
|
|
import android.widget.Toast;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
2024-01-16 06:51:49 +00:00
|
|
|
import androidx.core.content.res.ResourcesCompat;
|
|
|
|
|
2024-01-15 07:41:09 +00:00
|
|
|
import com.google.firebase.firestore.DocumentReference;
|
|
|
|
import com.google.firebase.firestore.DocumentSnapshot;
|
|
|
|
import com.google.firebase.firestore.EventListener;
|
|
|
|
import com.google.firebase.firestore.FirebaseFirestore;
|
|
|
|
import com.google.firebase.firestore.FirebaseFirestoreException;
|
|
|
|
|
2023-12-18 07:07:21 +00:00
|
|
|
public class MainActivity extends AppCompatActivity {
|
2024-01-11 07:30:02 +00:00
|
|
|
|
|
|
|
BluetoothManager bluetoothManager;
|
|
|
|
BluetoothAdapter bluetoothAdapter;
|
|
|
|
|
2024-01-15 07:41:09 +00:00
|
|
|
public static final String TAG = "InspirationQuote";
|
2024-01-16 06:51:49 +00:00
|
|
|
private DocumentReference mDocRef = FirebaseFirestore.getInstance().document("users/rrVGKi77MAemxvPZrktm");//現在の位置を取得
|
2024-01-15 07:41:09 +00:00
|
|
|
boolean flg = false;
|
|
|
|
|
2024-01-12 03:23:22 +00:00
|
|
|
//↓日付を取得するやつ
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2023-12-18 07:07:21 +00:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_main);
|
2024-01-15 07:41:09 +00:00
|
|
|
super.onStart();
|
2023-12-18 07:07:21 +00:00
|
|
|
|
|
|
|
BottomNavigationView bottomNavigationView = findViewById(R.id.nav_view);
|
|
|
|
|
2024-01-15 07:41:09 +00:00
|
|
|
bottomNavigationView.setOnNavigationItemSelectedListener(v ->
|
|
|
|
|
|
|
|
{
|
2023-12-18 07:07:21 +00:00
|
|
|
if (v.getItemId() == findViewById(R.id.navigation_home).getId()) {
|
|
|
|
getSupportFragmentManager().beginTransaction()
|
|
|
|
.replace(findViewById(R.id.fragmentContainerView).getId(), HomeFragment.newInstance("test", "tset"))
|
|
|
|
.commit();
|
|
|
|
} else if (v.getItemId() == findViewById(R.id.navigation_QR).getId()) {
|
|
|
|
getSupportFragmentManager().beginTransaction()
|
|
|
|
.replace(findViewById(R.id.fragmentContainerView).getId(), QRFragment.newInstance("test", "tset"))
|
|
|
|
.commit();
|
|
|
|
} else if (v.getItemId() == findViewById(R.id.navigation_notification).getId()) {
|
|
|
|
getSupportFragmentManager().beginTransaction()
|
|
|
|
.replace(findViewById(R.id.fragmentContainerView).getId(), NotificationFragment.newInstance("test", "test"))
|
|
|
|
.commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
2024-01-15 07:41:09 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
mDocRef.addSnapshotListener(this, new EventListener<DocumentSnapshot>() {
|
|
|
|
@Override
|
|
|
|
public void onEvent(@Nullable DocumentSnapshot documentSnapshot, @Nullable FirebaseFirestoreException e) {
|
2024-01-16 06:51:49 +00:00
|
|
|
Log.d("nt", "イベント開始");
|
2024-01-15 07:41:09 +00:00
|
|
|
if (flg && documentSnapshot != null && documentSnapshot.exists()) {
|
|
|
|
|
|
|
|
String parent = documentSnapshot.getString("parent");
|
2024-01-16 06:51:49 +00:00
|
|
|
Log.d("nt", "レスポンスを検知しました1");
|
2024-01-15 07:41:09 +00:00
|
|
|
if (parent.equals("s")) {
|
|
|
|
|
|
|
|
//通知のやつ↓
|
|
|
|
int importance = NotificationManager.IMPORTANCE_DEFAULT;
|
|
|
|
|
|
|
|
NotificationChannel channel = new NotificationChannel("CHANNEL_ID", "通報通知", importance);
|
|
|
|
//説明・説明 ここに通知の説明を書くことができる↓
|
|
|
|
channel.setDescription("第3者からの通報を検知しました");
|
|
|
|
|
|
|
|
NotificationManager notificationManager = getSystemService(NotificationManager.class);
|
|
|
|
notificationManager.createNotificationChannel(channel);
|
|
|
|
//通知のやつ↑
|
2024-01-16 06:51:49 +00:00
|
|
|
Log.d("nt", "レスポンスを検知しました2");
|
2024-01-15 07:41:09 +00:00
|
|
|
|
|
|
|
notifyMain();
|
2024-01-16 06:51:49 +00:00
|
|
|
} else {
|
2024-01-15 07:41:09 +00:00
|
|
|
Log.w(TAG, "Got an exceptiion!", e);
|
2024-01-16 07:00:42 +00:00
|
|
|
HomeFragment fragment = new HomeFragment();
|
|
|
|
Bundle bundle = new Bundle();
|
|
|
|
bundle.putBoolean("親",true);
|
|
|
|
fragment.setArguments(bundle);
|
|
|
|
getSupportFragmentManager()
|
|
|
|
.beginTransaction()
|
|
|
|
.add(android.R.id.content, fragment)
|
|
|
|
.commit();
|
2024-01-15 07:41:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
flg = true;
|
|
|
|
}
|
2023-12-18 07:07:21 +00:00
|
|
|
});
|
|
|
|
}
|
2023-12-22 03:00:58 +00:00
|
|
|
|
|
|
|
//↓通知のやつ
|
2024-01-12 01:26:39 +00:00
|
|
|
public void notifyMain() {
|
2024-01-12 03:17:43 +00:00
|
|
|
//↓通知をする際に起動するバイブレーション
|
2024-01-12 02:08:34 +00:00
|
|
|
((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).vibrate(1000);
|
2024-01-12 03:17:43 +00:00
|
|
|
//↓通知の詳細設定的な奴
|
2023-12-22 03:00:58 +00:00
|
|
|
NotificationCompat.Builder builder = new NotificationCompat
|
|
|
|
.Builder(this, "CHANNEL_ID")
|
|
|
|
.setSmallIcon(android.R.drawable.ic_menu_info_details)
|
2024-01-12 01:26:39 +00:00
|
|
|
.setContentTitle("通報検知")
|
|
|
|
.setContentText("子供の置き去りを検知しました。")
|
2023-12-22 03:00:58 +00:00
|
|
|
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
|
|
|
|
|
|
|
|
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
|
|
|
|
|
|
|
|
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());
|
2024-01-11 07:30:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
}
|
2024-01-12 02:08:34 +00:00
|
|
|
|
2024-01-11 07:30:02 +00:00
|
|
|
//Bluetooth_setupの戻るボタン
|
2024-01-12 02:08:34 +00:00
|
|
|
public void setupBackButton(boolean enableBackButton) {
|
2024-01-11 07:30:02 +00:00
|
|
|
ActionBar actionBar = getSupportActionBar();
|
|
|
|
actionBar.setDisplayHomeAsUpEnabled(enableBackButton);
|
2023-12-22 03:00:58 +00:00
|
|
|
}
|
2024-01-16 06:51:49 +00:00
|
|
|
}
|