Itazuraboushi #14

Merged
N-YOKU-jp merged 4 commits from itazuraboushi into main 2024-01-17 03:25:41 +00:00
6 changed files with 179 additions and 130 deletions

View File

@ -1,6 +1,7 @@
package com.example.childguard;
import static android.content.ContentValues.TAG;
import static android.content.Context.MODE_PRIVATE;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
@ -27,7 +28,6 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
@ -101,15 +101,13 @@ public class HomeFragment extends Fragment {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_home, container, false);
MainActivity activity = (MainActivity) getActivity();
//共有プリファレンス 全体の準備
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
//共有プリファレンス全体の準備
SharedPreferences sharedPreferences = getActivity().getSharedPreferences("app_situation", MODE_PRIVATE);
//QRコード印刷の処理
Button bt1 = view.findViewById(R.id.QRprinting);
bt1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
bt1.setOnClickListener(v -> {
//初回起動かを保存する変数
boolean alreadySaved = preferences.getBoolean("alreadySaved", false);
boolean alreadySaved = sharedPreferences.getBoolean("alreadySaved", false);
//ボタン変数の宣言
Button parent = view.findViewById(R.id.QRprinting);
Button born = view.findViewById(R.id.QRprinting);
@ -117,7 +115,7 @@ public class HomeFragment extends Fragment {
if (alreadySaved) {
Log.d("HomeFragment", "already printed");
//画面遷移ID受け渡し
Toast.makeText(getActivity(),"再印刷",Toast.LENGTH_SHORT).show();
Toast.makeText(getActivity(), "再印刷", Toast.LENGTH_SHORT).show();
QrPrintFragment qrPrintFragment = new QrPrintFragment();
replaceFragment(qrPrintFragment);
return;
@ -141,17 +139,17 @@ public class HomeFragment extends Fragment {
//成功したら
//documentReference.getId()でID取得
Log.d(TAG, "DocumentSnapshot added with ID: " + documentReference.getId());
SharedPreferences.Editor e = preferences.edit();
SharedPreferences.Editor e = sharedPreferences.edit();
// キー"alreadySaved"の値をtrueにする
e.putBoolean("alreadySaved", true);
//確定処理
e.apply();
//画面遷移ID受け渡し
str_key = "" + documentReference.getId();
Toast.makeText(getActivity(),"初回登録",Toast.LENGTH_SHORT).show();
Toast.makeText(getActivity(), "初回登録", Toast.LENGTH_SHORT).show();
QrPrintFragment qrPrintFragment = new QrPrintFragment();
Bundle bundle = new Bundle();
bundle.putString("STR_KEY",str_key);
bundle.putString("STR_KEY", str_key);
//値を書き込む
qrPrintFragment.setArguments(bundle);
replaceFragment(qrPrintFragment);
@ -167,7 +165,6 @@ public class HomeFragment extends Fragment {
});
}
});
//bluetooth設定ボタンの処理
Button bt2 = view.findViewById(R.id.Bluetooth_setup);
@ -183,30 +180,13 @@ public class HomeFragment extends Fragment {
Toast.makeText(getContext(), PreferenceManager.getDefaultSharedPreferences(getContext().getApplicationContext()).getString("bluetooth_device_id", "none"), Toast.LENGTH_SHORT).show();
});
return view;
}
@Override
public void onResume() {
super.onResume();
Log.d("HomeFragment", "onResume: called");
TextView situationTextView = getView().findViewById(R.id.situation);
FrameLayout situation_bg = getView().findViewById(R.id.situation_bg);
updateInCarStatus(situationTextView, situation_bg);
}
public void updateInCarStatus(TextView situationTextView, FrameLayout situation_bg) {
SharedPreferences sharedPreferences = getActivity().getSharedPreferences("default", 0);
Log.d("HomeFragment", "updateInCarStatus: " + sharedPreferences.getBoolean("inCar", false));
if (sharedPreferences.getBoolean("inCar", false)) {
situationTextView.setText("\n降車状態");
situation_bg.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.frame_style, null));
} else {
situationTextView.setText("\n乗車状態");
situation_bg.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.frame_style_orange, null));
}
Cargettingonandoff();//メソッドCargettingonandoff()を実行
}
//画面遷移メソッド
@ -223,15 +203,29 @@ public class HomeFragment extends Fragment {
transaction.commit();
}
public void bluetooth_judge(String device_id){
if(device_id.equals(PreferenceManager.getDefaultSharedPreferences(requireContext().getApplicationContext()).getString("Bluetooth_device_id","none"))){
Log.d(" ","登録デバイスです");
}
else {
Log.d(" ","登録デバイスではないです");
}
public void Cargettingonandoff() {
//共有プリファレンス全体の準備
SharedPreferences sharedPreferences = getActivity().getSharedPreferences("app_situation", MODE_PRIVATE);
//車の乗り降りを管理するtrue=乗車false=降車
Boolean zyoukouzyoutai = sharedPreferences.getBoolean("car", false);
SharedPreferences.Editor e = sharedPreferences.edit();
String get_on = "\n乗車状態";
String get_off = "\n降車状態";
TextView tv = getView().findViewById(R.id.situation);
FrameLayout fl = getView().findViewById(R.id.situation_bg);
if (zyoukouzyoutai == true) { //乗降状態の判定
//降車状態にする
fl.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.frame_style, null));
tv.setText(get_off);
} else {
//乗車状態にする
fl.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.frame_style_orange, null));
tv.setText(get_on);
}
}
}

View File

@ -14,9 +14,11 @@ import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Vibrator;
@ -30,10 +32,12 @@ import java.util.UUID;
import android.preference.PreferenceManager;
import android.util.Log;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.res.ResourcesCompat;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
@ -50,7 +54,7 @@ public class MainActivity extends AppCompatActivity {
BluetoothAdapter bluetoothAdapter;
public static final String TAG = "InspirationQuote";
private DocumentReference mDocRef = FirebaseFirestore.getInstance().document("users/q6t702C8nsXyehckByrr");//現在の位置を取得
boolean flg = false;
//日付を取得するやつ
@ -89,17 +93,44 @@ public class MainActivity extends AppCompatActivity {
});
}
@Override
protected void onResume() {
super.onResume();
SharedPreferences sharedPreferences = getSharedPreferences("app_situation", MODE_PRIVATE);
String IdPref = sharedPreferences.getString("ID", null);
if (IdPref == null) {
Log.d("onResume", "ID not initialized.");
return;
}
DocumentReference mDocRef = FirebaseFirestore.getInstance().document("users/" + IdPref);//現在の位置を取得
initNotification(mDocRef);
}
private void initNotification(DocumentReference mDocRef) {
// Init pref
SharedPreferences sharedPreferences = getSharedPreferences("app_situation",MODE_PRIVATE);
mDocRef.addSnapshotListener(this, new EventListener<DocumentSnapshot>() {
@Override
public void onEvent(@Nullable DocumentSnapshot documentSnapshot, @Nullable FirebaseFirestoreException e) {
Log.d("nt","イベント開始");
Log.d("nt", "イベント開始");
//共有プリファレンス 書き込みの準備
SharedPreferences.Editor E=sharedPreferences.edit();
//車の乗り降りを管理するtrue=乗車false=降車
boolean zyoukouzyoutai = sharedPreferences.getBoolean("car", false);
if (flg && documentSnapshot != null && documentSnapshot.exists()) {
String parent = documentSnapshot.getString("parent");
Log.d("nt","レスポンスを検知しました1");
if (parent.equals("s")) {
Log.d("nt", "レスポンスを検知しました1");
if (parent.equals("s")) {//FireBaseの更新情報が"S"のときサイト上で第三者ボタンが押されたとき
if(zyoukouzyoutai==false) {//いたずら防止
//通知のやつ
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel channel = new NotificationChannel("CHANNEL_ID", "通報通知", importance);
@ -109,12 +140,29 @@ public class MainActivity extends AppCompatActivity {
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
//通知のやつ
Log.d("nt","レスポンスを検知しました2");
Log.d("nt", "レスポンスを検知しました2");
notifyMain();
} else if (e != null) {
}
} else {
if(zyoukouzyoutai==true){//乗降状態の判定
E.putBoolean("car", false);//降車状態にする
E.apply();//確定処理
}else{
E.putBoolean("car", true);//乗車状態にする
E.apply();//確定処理
}
Log.w(TAG, "Got an exceptiion!", e);
//HomeFragmentへ遷移する
HomeFragment fragment = new HomeFragment();
Bundle bundle = new Bundle();
bundle.putBoolean("",zyoukouzyoutai);
fragment.setArguments(bundle);
getSupportFragmentManager()
.beginTransaction()
.add(android.R.id.content, fragment)
.commit();
}
}

View File

@ -1,21 +1,21 @@
package com.example.childguard;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class QR extends AppCompatActivity {
String get_on="乗車状態";
String get_off ="降車状態";
TextView tv=findViewById(R.id.situation);
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_qr);
//多分いらないコード
//package com.example.childguard;
//
//import android.graphics.Color;
//import android.graphics.drawable.Drawable;
//import android.os.Bundle;
//import android.widget.TextView;
//
//import androidx.appcompat.app.AppCompatActivity;
//
//public class QR extends AppCompatActivity {
// String get_on="乗車状態";
// String get_off ="降車状態";
// TextView tv=findViewById(R.id.situation);
// @Override
// protected void onCreate(Bundle savedInstanceState){
// super.onCreate(savedInstanceState);
// setContentView(R.layout.fragment_qr);
// //多分いらないコード
// findViewById(R.id.camera).setOnClickListener(
// v -> {
// if(get_on.equals(tv.getText().toString())){
@ -28,6 +28,6 @@ public class QR extends AppCompatActivity {
// }
// }
// );
}
}
// }
//
//}

View File

@ -1,5 +1,7 @@
package com.example.childguard;
import static android.content.Context.MODE_PRIVATE;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@ -75,10 +77,10 @@ public class QrPrintFragment extends Fragment {
// @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
//共有プリファレンス 全体の準備
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
//共有プリファレンス全体の準備
SharedPreferences sharedPreferences = getActivity().getSharedPreferences("app_situation", MODE_PRIVATE);
//User毎のドメインを保存する
String IdPref=preferences.getString("ID",null);
String IdPref=sharedPreferences.getString("ID",null);
// Inflate the layout for this fragment
View view=inflater.inflate(R.layout.fragment_qr_print, container, false);;
//固定のドメイン
@ -90,7 +92,7 @@ public class QrPrintFragment extends Fragment {
//User毎のドメイン
String userURL = getArguments().getString("STR_KEY");
//キー"ID"の値をuserURLの値にする
SharedPreferences.Editor e = preferences.edit();
SharedPreferences.Editor e = sharedPreferences.edit();
e.putString("ID", userURL);
//確定処理
e.apply();

View File

@ -8,7 +8,8 @@
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/white"
tools:context=".MainActivity">
tools:context=".MainActivity"
>
<androidx.fragment.app.FragmentContainerView

View File

@ -6,7 +6,8 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".HomeFragment">
tools:context=".HomeFragment"
>
<ScrollView
@ -14,13 +15,16 @@
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
android:orientation="vertical">
<FrameLayout
android:id="@+id/situation_bg"
android:layout_width="match_parent"