変数とかの名前の修正 #29

Merged
asura146 merged 1 commits from hotfix-notification into main 2024-07-25 17:59:54 +00:00
3 changed files with 41 additions and 42 deletions
Showing only changes of commit e906343619 - Show all commits

View File

@ -139,14 +139,17 @@ public class HomeFragment extends Fragment implements OnEventListener {
return true; return true;
} }
/**
* Bluetoothの接続状態の画面を切り替える
*/
private boolean updateBluetoothSituation(Boolean BluetoothConnect) { private boolean updateBluetoothSituation(Boolean BluetoothConnect) {
FrameLayout frameLayout; FrameLayout frameLayout;
TextView textView; TextView textView;
ImageView imageView; ImageView imageView;
try { try {
frameLayout = requireView().findViewById(R.id.situation_bg2); frameLayout = requireView().findViewById(R.id.situation_bg_bluetooth);
textView = requireView().findViewById(R.id.Bluetoothsituation); textView = requireView().findViewById(R.id.BluetoothSituation);
imageView = requireView().findViewById(R.id.Bluetoothsituationimage); imageView = requireView().findViewById(R.id.BluetoothSituationImage);
} catch (NullPointerException e) { } catch (NullPointerException e) {
Log.d("HomeFragment", "updateUiState: view is null"); Log.d("HomeFragment", "updateUiState: view is null");
return false; return false;
@ -156,17 +159,17 @@ public class HomeFragment extends Fragment implements OnEventListener {
updateBluetoothSituation(BluetoothConnect); updateBluetoothSituation(BluetoothConnect);
return false; return false;
} }
String connect = "接続中"; final String CONNECT = "接続中";
String disconnect = "切断中"; final String DISCONNECT = "切断中";
if (BluetoothConnect) { if (BluetoothConnect) {
//接続状態にする //接続状態にする
frameLayout.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.frame_style_orange, null)); frameLayout.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.frame_style_orange, null));
textView.setText(connect); textView.setText(CONNECT);
imageView.setVisibility(View.GONE); imageView.setVisibility(View.GONE);
} else { } else {
//降車状態にする //降車状態にする
frameLayout.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.frame_style, null)); frameLayout.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.frame_style, null));
textView.setText(disconnect); textView.setText(DISCONNECT);
imageView.setVisibility(View.VISIBLE); imageView.setVisibility(View.VISIBLE);
} }

View File

@ -52,7 +52,6 @@ public class MainActivity extends AppCompatActivity {
public static final String TAG = "InspirationQuote"; public static final String TAG = "InspirationQuote";
private final ActivityResultLauncher<ScanOptions> QrLauncher = registerForActivityResult( private final ActivityResultLauncher<ScanOptions> QrLauncher = registerForActivityResult(
new ScanContract(), new ScanContract(),
result -> { result -> {
@ -76,10 +75,9 @@ public class MainActivity extends AppCompatActivity {
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
//Bluetooth接続判定用 //Bluetooth接続判定用
SharedPreferences pref=PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor e=pref.edit(); SharedPreferences.Editor e = pref.edit();
e.putBoolean("connection_status",false); e.putBoolean("connection_status", false);
if (!hasPermissions()) { if (!hasPermissions()) {
@ -149,7 +147,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);
@ -187,7 +185,6 @@ public class MainActivity extends AppCompatActivity {
} }
} }
}); });
} }
private boolean hasPermissions() { private boolean hasPermissions() {
@ -229,18 +226,18 @@ public class MainActivity extends AppCompatActivity {
} }
/**
* FireBaseのIDの取得
*/
public void firebaseLink() {//Firebaseのドキュメントの取得 public void firebaseLink() {//Firebaseのドキュメントの取得
//共有プリファレンス全体の準備 //共有プリファレンス全体の準備
SharedPreferences sharedPreferences = getSharedPreferences("app_situation", MODE_PRIVATE); SharedPreferences sharedPreferences = getSharedPreferences("app_situation", MODE_PRIVATE);
String IdPref = sharedPreferences.getString("ID", null);////アプリに記録されているIDの取得 String IdPref = sharedPreferences.getString("ID", null);//アプリに記録されているIDの取得
if (IdPref == null) {//FireBaseのIDがアプリに登録されているとき if (IdPref == null) {//FireBaseのIDがアプリに登録されているとき
Log.d("onResume", "ID not initialized."); Log.d("onResume", "ID not initialized.");
} else { } else {
mDocRef = FirebaseFirestore.getInstance().document("status/" + IdPref);//現在の位置を取得 mDocRef = FirebaseFirestore.getInstance().document("status/" + IdPref);//現在の位置を取得
initNotification(mDocRef);//現在の位置を引数に initNotification()を処理 initNotification(mDocRef);//現在の位置を引数に initNotification()を処理
} }
} }
@ -261,19 +258,20 @@ public class MainActivity extends AppCompatActivity {
//共有プリファレンス 書き込みの準備 //共有プリファレンス 書き込みの準備
SharedPreferences.Editor E = sharedPreferences.edit(); SharedPreferences.Editor E = sharedPreferences.edit();
String IdPref = sharedPreferences.getString("ID", null);//アプリに記録されているIDの取得 String IdPref = sharedPreferences.getString("ID", null);//アプリに記録されているIDの取得
Boolean change=sharedPreferences.getBoolean("change",false); Boolean change = sharedPreferences.getBoolean("change", false);
db = FirebaseFirestore.getInstance();//Firebaseとの紐づけ db = FirebaseFirestore.getInstance();//Firebaseとの紐づけ
DocumentReference isReported = db.collection("status").document(IdPref);//更新するドキュメントとの紐づけ DocumentReference isReported = db.collection("status").document(IdPref);//更新するドキュメントとの紐づけ
Map<String, Boolean> DEFAULT_ITEM = new HashMap<>();//mapの宣言 Map<String, Boolean> DEFAULT_ITEM = new HashMap<>();//mapの宣言
if (!change) { if (!change) {
//isInCarをtrueに更新 //isInCarをtrueに更新
E.putBoolean("change",true); E.putBoolean("change", true);
}else{ } else {
E.putBoolean("change",false); 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)); isReported.update("isInCar", change).addOnSuccessListener(unused -> Log.d(TAG, "DocumentSnapshot successfully updated!")).addOnFailureListener(e -> Log.w(TAG, "Error updating document", e));
E.apply(); E.apply();
} }
public void NotificationSetting() {//通知に関する設定の処理を行うメソッド public void NotificationSetting() {//通知に関する設定の処理を行うメソッド
int importance = NotificationManager.IMPORTANCE_DEFAULT; int importance = NotificationManager.IMPORTANCE_DEFAULT;
//通知チャネルの実装 //通知チャネルの実装
@ -380,7 +378,7 @@ public class MainActivity extends AppCompatActivity {
} }
NotificationManager notificationManager = (NotificationManager)context.getSystemService(context.NOTIFICATION_SERVICE); NotificationManager notificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
return; return;
} }
@ -388,9 +386,6 @@ public class MainActivity extends AppCompatActivity {
} }
public void Bluetooth_status() { public void Bluetooth_status() {
IntentFilter intentFilter = new IntentFilter(); IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED); intentFilter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED);
@ -413,8 +408,8 @@ public class MainActivity extends AppCompatActivity {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
SharedPreferences pref=getSharedPreferences("Bluetooth_situation",MODE_PRIVATE); SharedPreferences pref = getSharedPreferences("Bluetooth_situation", MODE_PRIVATE);
SharedPreferences.Editor e=pref.edit(); SharedPreferences.Editor e = pref.edit();
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);
@ -437,16 +432,16 @@ public class MainActivity extends AppCompatActivity {
if (deviceHardwareAddress.equals(registeredId)) { if (deviceHardwareAddress.equals(registeredId)) {
//登録済みのデバイスだったときの処理 //登録済みのデバイスだったときの処理
Log.d("BT_Judge", "登録済み"); Log.d("BT_Judge", "登録済み");
e.putBoolean("connection_status",true); e.putBoolean("connection_status", true);
} else{ } else {
//登録していないデバイスだったときの処理 //登録していないデバイスだったときの処理
Log.d("BT_Judge", "未登録"); Log.d("BT_Judge", "未登録");
e.putBoolean("connection_status",false); e.putBoolean("connection_status", false);
} }
e.apply(); e.apply();
} else if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)&&!isInCar) {//bluetoothが切断されたときに乗車状態のとき } else if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action) && !isInCar) {//bluetoothが切断されたときに乗車状態のとき
//Do something if disconnected //Do something if disconnected
//デバイスが切断されたときの処理 //デバイスが切断されたときの処理
@ -457,20 +452,21 @@ public class MainActivity extends AppCompatActivity {
handler.postDelayed(new Runnable() { handler.postDelayed(new Runnable() {
@Override @Override
public void run() { public void run() {
if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)&&!isInCar) {//その後bluetoothを再接続したり降車状態になったりしていない置き去りが発生した可能性大 if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action) && !isInCar) {//その後bluetoothを再接続したり降車状態になったりしていない置き去りが発生した可能性大
NotificationBluetooth(getApplicationContext());//通知を行うメソッド NotificationBluetooth(getApplicationContext());//通知を行うメソッド
}} }
}
}, 5 *60*1000); // 5分をミリ秒に変換 }, 5 * 1000); // 5分をミリ秒に変換
} }
}else { } else {
Log.d("BT", "Device disconnected"); Log.d("BT", " Device disconnected");
} }
} }
}; };
public void changeBluetooth(boolean actual){ public void changeBluetooth(boolean actual) {
getSharedPreferences("Bluetooth_situation",MODE_PRIVATE).edit().putBoolean("status",actual).apply(); getSharedPreferences("Bluetooth_situation", MODE_PRIVATE).edit().putBoolean("status", actual).apply();
} }
} }

View File

@ -49,7 +49,7 @@
</FrameLayout> </FrameLayout>
<FrameLayout <FrameLayout
android:id="@+id/situation_bg2" android:id="@+id/situation_bg_bluetooth"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="20dp" android:layout_marginLeft="20dp"
@ -58,7 +58,7 @@
android:background="@drawable/frame_style"> android:background="@drawable/frame_style">
<TextView <TextView
android:id="@+id/Bluetoothsituation" android:id="@+id/BluetoothSituation"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="5dp" android:layout_marginTop="5dp"
@ -75,7 +75,7 @@
android:textAlignment="center" /> android:textAlignment="center" />
<ImageView <ImageView
android:id="@+id/Bluetoothsituationimage" android:id="@+id/BluetoothSituationImage"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="100dp" android:layout_height="100dp"
android:layout_marginTop="50dp" android:layout_marginTop="50dp"