アプリでQRを読み取った瞬間に乗降状態が変更されるように処理を変更

This commit is contained in:
it232115 2024-01-24 12:56:02 +09:00
parent fab0f75d1a
commit d3f4c83d2b
5 changed files with 43 additions and 23 deletions

View File

@ -176,8 +176,8 @@ public class HomeFragment extends Fragment implements OnEventListener{
}
@Override
public boolean onEvent2(boolean BluetoothConnect) {
return false;
public void onEvent2(boolean BluetoothConnect) {
return ;
}

View File

@ -65,12 +65,7 @@ public class MainActivity extends AppCompatActivity {
if (!contents.contains("https://practicefirestore1-8808c.web.app/")) {
Toast.makeText(this, "Child Guardに対応するQRコードではありません", Toast.LENGTH_LONG).show();
} else {
//URLの表示
Toast.makeText(this, contents, Toast.LENGTH_SHORT).show();
//ブラウザを起動しURL先のサイトを開く
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(this, Uri.parse(contents));
changeisInCar();
}
}
}
@ -87,7 +82,7 @@ public class MainActivity extends AppCompatActivity {
SharedPreferences.Editor e=pref.edit();
e.putBoolean("connection_status",false);
db = FirebaseFirestore.getInstance();//Firebaseとの紐づけ
if (!hasPermissions()) {
requestPermissions();
@ -108,7 +103,6 @@ public class MainActivity extends AppCompatActivity {
.commit();
firebaselink();
} else if (v.getItemId() == findViewById(R.id.navigation_settings).getId()) {
findViewById(R.id.fab_scan_qr_code).setVisibility(FrameLayout.GONE);
getSupportFragmentManager().beginTransaction()
@ -130,12 +124,12 @@ public class MainActivity extends AppCompatActivity {
});
//Bluetooth検知機能
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED);
intentFilter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
db = FirebaseFirestore.getInstance();//Firebaseとの紐づけ
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
Log.d("BT", "No permission to connect bluetooth devices");
return;
@ -261,6 +255,25 @@ public class MainActivity extends AppCompatActivity {
isReported.update("isReported", false).addOnSuccessListener(unused -> Log.d(TAG, "DocumentSnapshot successfully updated!")).addOnFailureListener(e -> Log.w(TAG, "Error updating document", e));
}
public void changeisInCar() {
//共有プリファレンス全体の準備
SharedPreferences sharedPreferences = MainActivity.this.getSharedPreferences("app_situation", MODE_PRIVATE);
//共有プリファレンス 書き込みの準備
SharedPreferences.Editor E = sharedPreferences.edit();
String IdPref = sharedPreferences.getString("ID", null);//アプリに記録されているIDの取得
Boolean change=sharedPreferences.getBoolean("change",false);
db = FirebaseFirestore.getInstance();//Firebaseとの紐づけ
DocumentReference isReported = db.collection("status").document(IdPref);//更新するドキュメントとの紐づけ
Map<String, Boolean> DEFAULT_ITEM = new HashMap<>();//mapの宣言
if (!change) {
//isInCarをtrueに更新
E.putBoolean("change",true);
}else{
E.putBoolean("change",false);
}
isReported.update("isInCar", change).addOnSuccessListener(unused -> Log.d(TAG, "DocumentSnapshot successfully updated!")).addOnFailureListener(e -> Log.w(TAG, "Error updating document", e));
E.apply();
}
public void NotificationSetting() {//通知に関する設定の処理を行うメソッド
int importance = NotificationManager.IMPORTANCE_DEFAULT;
//通知チャネルの実装
@ -405,8 +418,7 @@ public class MainActivity extends AppCompatActivity {
String action = intent.getAction(); // may need to chain this to a recognizing function
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
Boolean isInCar = pref.getBoolean("isInCarPref", false);
Boolean Bluetoothconnect = pref.getBoolean("change", false);
if (ActivityCompat.checkSelfPermission(context, android.Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
Log.d("BT", "No permission to connect bluetooth devices");
return;
@ -418,9 +430,9 @@ public class MainActivity extends AppCompatActivity {
if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) {
//Do something if connected
//Bluetoothデバイスが接続されたときの処理
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragmentContainerView);
Boolean Bluetoothconnect=true;
((HomeFragment) fragment).onEvent2(Bluetoothconnect);//HomeFragmentの表示を接続にする
e.putBoolean("change", true);
e.apply();
changeBluetooth();//HomeFragmentの表示を接続にする
Log.d("BT", "Device connected");
Log.d("BT_Judge", "Registered: " + registeredId);
@ -441,9 +453,9 @@ public class MainActivity extends AppCompatActivity {
//Do something if disconnected
//デバイスが切断されたときの処理
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragmentContainerView);
Boolean Bluetoothconnect=false;
((HomeFragment) fragment).onEvent2(Bluetoothconnect);//HomeFragmentの表示を切断にする
e.putBoolean("change", false);
e.apply();
changeBluetooth();//HomeFragmentの表示を切断にする
if (deviceHardwareAddress.equals(registeredId)) {
// 5分待機する
Handler handler = new Handler();
@ -461,5 +473,13 @@ public class MainActivity extends AppCompatActivity {
}
}
};
public void changeBluetooth(){
SharedPreferences pref=getSharedPreferences("Bluetooth_situation",MODE_PRIVATE);
SharedPreferences.Editor e=pref.edit();
Boolean Bluetoothconnect = pref.getBoolean("change", false);
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragmentContainerView);
((HomeFragment) fragment).onEvent2(Bluetoothconnect);
}
}

View File

@ -4,7 +4,7 @@ public interface OnEventListener {
boolean onEvent(boolean state);
boolean onEvent2(boolean BluetoothConnect);
void onEvent2(boolean BluetoothConnect);
boolean onEvent2(Boolean Bluetoothconnect);
}

View File

@ -48,7 +48,7 @@ public class QrUtils {
throw new AndroidRuntimeException("Barcode Error.", e);
}
// 画像合成の準備
Bitmap bitmap = BitmapFactory.decodeResource(this.context.getResources(), R.drawable.a_group_qr_sos);
Bitmap bitmap = BitmapFactory.decodeResource(this.context.getResources(), R.drawable.a_group_qr_sos_2);
int width = bitmap.getWidth();
int height = bitmap.getHeight();
QRGazou = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
@ -72,7 +72,7 @@ public class QrUtils {
// 画面密度に基づいてQRコードのサイズを計算
float density = context.getResources().getDisplayMetrics().density;
return (int) (800 * density);
return (int) (700 * density);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB