アプリでQRを読み取った瞬間に乗降状態が変更されるように処理を変更
This commit is contained in:
parent
fab0f75d1a
commit
d3f4c83d2b
|
@ -176,8 +176,8 @@ public class HomeFragment extends Fragment implements OnEventListener{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onEvent2(boolean BluetoothConnect) {
|
public void onEvent2(boolean BluetoothConnect) {
|
||||||
return false;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -65,12 +65,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
if (!contents.contains("https://practicefirestore1-8808c.web.app/")) {
|
if (!contents.contains("https://practicefirestore1-8808c.web.app/")) {
|
||||||
Toast.makeText(this, "Child Guardに対応するQRコードではありません", Toast.LENGTH_LONG).show();
|
Toast.makeText(this, "Child Guardに対応するQRコードではありません", Toast.LENGTH_LONG).show();
|
||||||
} else {
|
} else {
|
||||||
//URLの表示
|
changeisInCar();
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,7 +82,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
SharedPreferences.Editor e=pref.edit();
|
SharedPreferences.Editor e=pref.edit();
|
||||||
e.putBoolean("connection_status",false);
|
e.putBoolean("connection_status",false);
|
||||||
|
|
||||||
db = FirebaseFirestore.getInstance();//Firebaseとの紐づけ
|
|
||||||
|
|
||||||
if (!hasPermissions()) {
|
if (!hasPermissions()) {
|
||||||
requestPermissions();
|
requestPermissions();
|
||||||
|
@ -108,7 +103,6 @@ public class MainActivity extends AppCompatActivity {
|
||||||
.commit();
|
.commit();
|
||||||
firebaselink();
|
firebaselink();
|
||||||
|
|
||||||
|
|
||||||
} else if (v.getItemId() == findViewById(R.id.navigation_settings).getId()) {
|
} else if (v.getItemId() == findViewById(R.id.navigation_settings).getId()) {
|
||||||
findViewById(R.id.fab_scan_qr_code).setVisibility(FrameLayout.GONE);
|
findViewById(R.id.fab_scan_qr_code).setVisibility(FrameLayout.GONE);
|
||||||
getSupportFragmentManager().beginTransaction()
|
getSupportFragmentManager().beginTransaction()
|
||||||
|
@ -130,12 +124,12 @@ public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
//Bluetooth検知機能
|
//Bluetooth検知機能
|
||||||
IntentFilter intentFilter = new IntentFilter();
|
IntentFilter intentFilter = new IntentFilter();
|
||||||
intentFilter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED);
|
intentFilter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED);
|
||||||
intentFilter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
|
intentFilter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
|
||||||
|
|
||||||
|
db = FirebaseFirestore.getInstance();//Firebaseとの紐づけ
|
||||||
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
|
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
|
||||||
Log.d("BT", "No permission to connect bluetooth devices");
|
Log.d("BT", "No permission to connect bluetooth devices");
|
||||||
return;
|
return;
|
||||||
|
@ -155,7 +149,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
firebaselink();
|
firebaselink();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initNotification(DocumentReference mDocRef) {//サイト上で押されたボタンの管理
|
private void initNotification(DocumentReference mDocRef) {//サイト上で押されたボタンの管理
|
||||||
// 共有プリファレンス全体の準備
|
// 共有プリファレンス全体の準備
|
||||||
SharedPreferences sharedPreferences = getSharedPreferences("app_situation", MODE_PRIVATE);
|
SharedPreferences sharedPreferences = getSharedPreferences("app_situation", MODE_PRIVATE);
|
||||||
|
|
||||||
|
@ -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));
|
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() {//通知に関する設定の処理を行うメソッド
|
public void NotificationSetting() {//通知に関する設定の処理を行うメソッド
|
||||||
int importance = NotificationManager.IMPORTANCE_DEFAULT;
|
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
|
String action = intent.getAction(); // may need to chain this to a recognizing function
|
||||||
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
||||||
Boolean isInCar = pref.getBoolean("isInCarPref", false);
|
Boolean isInCar = pref.getBoolean("isInCarPref", false);
|
||||||
|
Boolean Bluetoothconnect = pref.getBoolean("change", false);
|
||||||
|
|
||||||
if (ActivityCompat.checkSelfPermission(context, android.Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
|
if (ActivityCompat.checkSelfPermission(context, android.Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
|
||||||
Log.d("BT", "No permission to connect bluetooth devices");
|
Log.d("BT", "No permission to connect bluetooth devices");
|
||||||
return;
|
return;
|
||||||
|
@ -418,9 +430,9 @@ public class MainActivity extends AppCompatActivity {
|
||||||
if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) {
|
if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) {
|
||||||
//Do something if connected
|
//Do something if connected
|
||||||
//Bluetoothデバイスが接続されたときの処理
|
//Bluetoothデバイスが接続されたときの処理
|
||||||
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragmentContainerView);
|
e.putBoolean("change", true);
|
||||||
Boolean Bluetoothconnect=true;
|
e.apply();
|
||||||
((HomeFragment) fragment).onEvent2(Bluetoothconnect);//HomeFragmentの表示を接続にする
|
changeBluetooth();//HomeFragmentの表示を接続にする
|
||||||
Log.d("BT", "Device connected");
|
Log.d("BT", "Device connected");
|
||||||
|
|
||||||
Log.d("BT_Judge", "Registered: " + registeredId);
|
Log.d("BT_Judge", "Registered: " + registeredId);
|
||||||
|
@ -441,9 +453,9 @@ public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
//Do something if disconnected
|
//Do something if disconnected
|
||||||
//デバイスが切断されたときの処理
|
//デバイスが切断されたときの処理
|
||||||
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragmentContainerView);
|
e.putBoolean("change", false);
|
||||||
Boolean Bluetoothconnect=false;
|
e.apply();
|
||||||
((HomeFragment) fragment).onEvent2(Bluetoothconnect);//HomeFragmentの表示を切断にする
|
changeBluetooth();//HomeFragmentの表示を切断にする
|
||||||
if (deviceHardwareAddress.equals(registeredId)) {
|
if (deviceHardwareAddress.equals(registeredId)) {
|
||||||
// 5分待機する
|
// 5分待機する
|
||||||
Handler handler = new Handler();
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ public interface OnEventListener {
|
||||||
|
|
||||||
boolean onEvent(boolean state);
|
boolean onEvent(boolean state);
|
||||||
|
|
||||||
boolean onEvent2(boolean BluetoothConnect);
|
void onEvent2(boolean BluetoothConnect);
|
||||||
|
|
||||||
boolean onEvent2(Boolean Bluetoothconnect);
|
boolean onEvent2(Boolean Bluetoothconnect);
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ public class QrUtils {
|
||||||
throw new AndroidRuntimeException("Barcode Error.", e);
|
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 width = bitmap.getWidth();
|
||||||
int height = bitmap.getHeight();
|
int height = bitmap.getHeight();
|
||||||
QRGazou = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
QRGazou = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||||
|
@ -72,7 +72,7 @@ public class QrUtils {
|
||||||
|
|
||||||
// 画面密度に基づいてQRコードのサイズを計算
|
// 画面密度に基づいてQRコードのサイズを計算
|
||||||
float density = context.getResources().getDisplayMetrics().density;
|
float density = context.getResources().getDisplayMetrics().density;
|
||||||
return (int) (800 * density);
|
return (int) (700 * density);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
BIN
app/src/main/res/drawable/a_group_qr_sos_2.png
Normal file
BIN
app/src/main/res/drawable/a_group_qr_sos_2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 50 KiB |
Loading…
Reference in New Issue
Block a user