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
|
|
|
|
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;
|
|
|
|
import android.content.pm.PackageManager;
|
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-11 07:30:02 +00:00
|
|
|
import java.util.Random;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
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;
|
|
|
|
|
2023-12-18 07:07:21 +00:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_main);
|
|
|
|
|
2024-01-11 07:30:02 +00:00
|
|
|
|
2023-12-22 03:00:58 +00:00
|
|
|
//通知のやつ↓
|
|
|
|
int importance = NotificationManager.IMPORTANCE_DEFAULT;
|
|
|
|
|
|
|
|
NotificationChannel channel = new NotificationChannel("CHANNEL_ID", "サンプルアプリ", importance);
|
|
|
|
channel.setDescription("説明・説明 ここに通知の説明を書くことができる");
|
|
|
|
|
|
|
|
NotificationManager notificationManager = getSystemService(NotificationManager.class);
|
|
|
|
notificationManager.createNotificationChannel(channel);
|
|
|
|
//通知のやつ↑
|
|
|
|
|
2023-12-18 07:07:21 +00:00
|
|
|
|
|
|
|
BottomNavigationView bottomNavigationView = findViewById(R.id.nav_view);
|
|
|
|
|
|
|
|
bottomNavigationView.setOnNavigationItemSelectedListener(v -> {
|
|
|
|
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;
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
2023-12-22 03:00:58 +00:00
|
|
|
|
|
|
|
//↓通知のやつ
|
|
|
|
public void notifyTest() {
|
|
|
|
((Vibrator)getSystemService(Context.VIBRATOR_SERVICE)).vibrate(1000);
|
|
|
|
NotificationCompat.Builder builder = new NotificationCompat
|
|
|
|
.Builder(this, "CHANNEL_ID")
|
|
|
|
.setSmallIcon(android.R.drawable.ic_menu_info_details)
|
|
|
|
.setContentTitle("タイトル")
|
|
|
|
.setContentText("メッセージ・メッセージ")
|
|
|
|
.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
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
//Bluetooth_setupの戻るボタン
|
|
|
|
public void setupBackButton(boolean enableBackButton){
|
|
|
|
ActionBar actionBar = getSupportActionBar();
|
|
|
|
actionBar.setDisplayHomeAsUpEnabled(enableBackButton);
|
2023-12-22 03:00:58 +00:00
|
|
|
}
|
2023-12-18 07:07:21 +00:00
|
|
|
}
|