Itazuraboushi #14
|
@ -1,6 +1,7 @@
|
||||||
package com.example.childguard;
|
package com.example.childguard;
|
||||||
|
|
||||||
import static android.content.ContentValues.TAG;
|
import static android.content.ContentValues.TAG;
|
||||||
|
import static android.content.Context.MODE_PRIVATE;
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -83,21 +84,21 @@ public class HomeFragment extends Fragment {
|
||||||
// Inflate the layout for this fragment
|
// Inflate the layout for this fragment
|
||||||
View view = inflater.inflate(R.layout.fragment_home, container, false);
|
View view = inflater.inflate(R.layout.fragment_home, container, false);
|
||||||
MainActivity activity = (MainActivity) getActivity();
|
MainActivity activity = (MainActivity) getActivity();
|
||||||
//共有プリファレンス 全体の準備
|
//共有プリファレンス全体の準備
|
||||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
SharedPreferences sharedPreferences = getActivity().getSharedPreferences("app_situation", MODE_PRIVATE);
|
||||||
//QRコード印刷の処理
|
//QRコード印刷の処理
|
||||||
Button bt1 = view.findViewById(R.id.QRprinting);
|
Button bt1 = view.findViewById(R.id.QRprinting);
|
||||||
bt1.setOnClickListener(v -> {
|
bt1.setOnClickListener(v -> {
|
||||||
//初回起動かを保存する変数
|
//初回起動かを保存する変数
|
||||||
boolean alreadySaved = preferences.getBoolean("alreadySaved", false);
|
boolean alreadySaved = sharedPreferences.getBoolean("alreadySaved", false);
|
||||||
//ボタン変数の宣言
|
//ボタン変数の宣言
|
||||||
Button parent = view.findViewById(R.id.QRprinting);
|
Button parent = view.findViewById(R.id.QRprinting);
|
||||||
Button born = view.findViewById(R.id.QRprinting);
|
Button born = view.findViewById(R.id.QRprinting);
|
||||||
//falseのときにFirebaseへの登録
|
//falseのときにFirebaseへの登録
|
||||||
if (alreadySaved) {
|
if (alreadySaved) {
|
||||||
Log.d("HomeFragment", "already printed");
|
Log.d("HomeFragment", "already printed");
|
||||||
//画面遷移&ID受け渡し
|
//画面遷移&ID受け渡し
|
||||||
Toast.makeText(getActivity(),"再印刷",Toast.LENGTH_SHORT).show();
|
Toast.makeText(getActivity(), "再印刷", Toast.LENGTH_SHORT).show();
|
||||||
QrPrintFragment qrPrintFragment = new QrPrintFragment();
|
QrPrintFragment qrPrintFragment = new QrPrintFragment();
|
||||||
replaceFragment(qrPrintFragment);
|
replaceFragment(qrPrintFragment);
|
||||||
return;
|
return;
|
||||||
|
@ -121,17 +122,17 @@ public class HomeFragment extends Fragment {
|
||||||
//成功したら
|
//成功したら
|
||||||
//documentReference.getId()でID取得
|
//documentReference.getId()でID取得
|
||||||
Log.d(TAG, "DocumentSnapshot added with ID: " + documentReference.getId());
|
Log.d(TAG, "DocumentSnapshot added with ID: " + documentReference.getId());
|
||||||
SharedPreferences.Editor e = preferences.edit();
|
SharedPreferences.Editor e = sharedPreferences.edit();
|
||||||
// キー"alreadySaved"の値をtrueにする
|
// キー"alreadySaved"の値をtrueにする
|
||||||
e.putBoolean("alreadySaved", true);
|
e.putBoolean("alreadySaved", true);
|
||||||
//確定処理
|
//確定処理
|
||||||
e.apply();
|
e.apply();
|
||||||
//画面遷移&ID受け渡し
|
//画面遷移&ID受け渡し
|
||||||
str_key = "" + documentReference.getId();
|
str_key = "" + documentReference.getId();
|
||||||
Toast.makeText(getActivity(),"初回登録",Toast.LENGTH_SHORT).show();
|
Toast.makeText(getActivity(), "初回登録", Toast.LENGTH_SHORT).show();
|
||||||
QrPrintFragment qrPrintFragment = new QrPrintFragment();
|
QrPrintFragment qrPrintFragment = new QrPrintFragment();
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putString("STR_KEY",str_key);
|
bundle.putString("STR_KEY", str_key);
|
||||||
//値を書き込む
|
//値を書き込む
|
||||||
qrPrintFragment.setArguments(bundle);
|
qrPrintFragment.setArguments(bundle);
|
||||||
replaceFragment(qrPrintFragment);
|
replaceFragment(qrPrintFragment);
|
||||||
|
@ -158,10 +159,7 @@ public class HomeFragment extends Fragment {
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
Log.d("HomeFragment", "onResume: called");
|
Log.d("HomeFragment", "onResume: called");
|
||||||
Bundle args = getArguments();
|
Cargettingonandoff();//メソッドCargettingonandoff()を実行
|
||||||
if (args != null) {//argsの中に値が入っている。
|
|
||||||
Cargettingonandoff();//メソッドCargettingonandoff()を実行
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//画面遷移メソッド
|
//画面遷移メソッド
|
||||||
|
@ -177,12 +175,13 @@ public class HomeFragment extends Fragment {
|
||||||
// フラグメントトランザクションをコミット
|
// フラグメントトランザクションをコミット
|
||||||
transaction.commit();
|
transaction.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Cargettingonandoff() {
|
public void Cargettingonandoff() {
|
||||||
//共有プリファレンス 全体の準備
|
//共有プリファレンス全体の準備
|
||||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
SharedPreferences sharedPreferences = getActivity().getSharedPreferences("app_situation", MODE_PRIVATE);
|
||||||
//車の乗り降りを管理するtrue=乗車、false=降車
|
//車の乗り降りを管理するtrue=乗車、false=降車
|
||||||
boolean zyoukouzyoutai = preferences.getBoolean("car", false);
|
Boolean zyoukouzyoutai = sharedPreferences.getBoolean("car", false);
|
||||||
SharedPreferences.Editor e = preferences.edit();
|
SharedPreferences.Editor e = sharedPreferences.edit();
|
||||||
String get_on = "\n乗車状態";
|
String get_on = "\n乗車状態";
|
||||||
String get_off = "\n降車状態";
|
String get_off = "\n降車状態";
|
||||||
TextView tv = getView().findViewById(R.id.situation);
|
TextView tv = getView().findViewById(R.id.situation);
|
||||||
|
@ -192,14 +191,11 @@ public class HomeFragment extends Fragment {
|
||||||
//降車状態にする
|
//降車状態にする
|
||||||
fl.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.frame_style, null));
|
fl.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.frame_style, null));
|
||||||
tv.setText(get_off);
|
tv.setText(get_off);
|
||||||
e.putBoolean("car", false);
|
|
||||||
e.apply();
|
|
||||||
} else {
|
} else {
|
||||||
//乗車状態にする
|
//乗車状態にする
|
||||||
fl.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.frame_style_orange, null));
|
fl.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.frame_style_orange, null));
|
||||||
tv.setText(get_on);
|
tv.setText(get_on);
|
||||||
e.putBoolean("car", true);
|
|
||||||
e.apply();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
BluetoothAdapter bluetoothAdapter;
|
BluetoothAdapter bluetoothAdapter;
|
||||||
|
|
||||||
public static final String TAG = "InspirationQuote";
|
public static final String TAG = "InspirationQuote";
|
||||||
private DocumentReference mDocRef = FirebaseFirestore.getInstance().document("users/rrVGKi77MAemxvPZrktm");//現在の位置を取得
|
|
||||||
boolean flg = false;
|
boolean flg = false;
|
||||||
|
|
||||||
//↓日付を取得するやつ
|
//↓日付を取得するやつ
|
||||||
|
@ -86,34 +86,71 @@ 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>() {
|
mDocRef.addSnapshotListener(this, new EventListener<DocumentSnapshot>() {
|
||||||
@Override
|
@Override
|
||||||
public void onEvent(@Nullable DocumentSnapshot documentSnapshot, @Nullable FirebaseFirestoreException e) {
|
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()) {
|
if (flg && documentSnapshot != null && documentSnapshot.exists()) {
|
||||||
|
|
||||||
String parent = documentSnapshot.getString("parent");
|
String parent = documentSnapshot.getString("parent");
|
||||||
Log.d("nt", "レスポンスを検知しました1");
|
Log.d("nt", "レスポンスを検知しました1");
|
||||||
if (parent.equals("s")) {
|
|
||||||
|
|
||||||
//通知のやつ↓
|
if (parent.equals("s")) {//FireBaseの更新情報が"S"のとき=サイト上で第三者ボタンが押されたとき
|
||||||
int importance = NotificationManager.IMPORTANCE_DEFAULT;
|
if(zyoukouzyoutai==false) {//いたずら防止
|
||||||
|
//通知のやつ↓
|
||||||
|
|
||||||
NotificationChannel channel = new NotificationChannel("CHANNEL_ID", "通報通知", importance);
|
int importance = NotificationManager.IMPORTANCE_DEFAULT;
|
||||||
//説明・説明 ここに通知の説明を書くことができる↓
|
|
||||||
channel.setDescription("第3者からの通報を検知しました");
|
|
||||||
|
|
||||||
NotificationManager notificationManager = getSystemService(NotificationManager.class);
|
NotificationChannel channel = new NotificationChannel("CHANNEL_ID", "通報通知", importance);
|
||||||
notificationManager.createNotificationChannel(channel);
|
//説明・説明 ここに通知の説明を書くことができる↓
|
||||||
//通知のやつ↑
|
channel.setDescription("第3者からの通報を検知しました");
|
||||||
Log.d("nt", "レスポンスを検知しました2");
|
|
||||||
|
|
||||||
notifyMain();
|
NotificationManager notificationManager = getSystemService(NotificationManager.class);
|
||||||
|
notificationManager.createNotificationChannel(channel);
|
||||||
|
//通知のやつ↑
|
||||||
|
Log.d("nt", "レスポンスを検知しました2");
|
||||||
|
|
||||||
|
notifyMain();
|
||||||
|
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if(zyoukouzyoutai==true){//乗降状態の判定
|
||||||
|
E.putBoolean("car", false);//降車状態にする
|
||||||
|
E.apply();//確定処理
|
||||||
|
}else{
|
||||||
|
E.putBoolean("car", true);//乗車状態にする
|
||||||
|
E.apply();//確定処理
|
||||||
|
}
|
||||||
Log.w(TAG, "Got an exceptiion!", e);
|
Log.w(TAG, "Got an exceptiion!", e);
|
||||||
|
//HomeFragmentへ遷移する
|
||||||
HomeFragment fragment = new HomeFragment();
|
HomeFragment fragment = new HomeFragment();
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putBoolean("親",true);
|
bundle.putBoolean("親",zyoukouzyoutai);
|
||||||
fragment.setArguments(bundle);
|
fragment.setArguments(bundle);
|
||||||
getSupportFragmentManager()
|
getSupportFragmentManager()
|
||||||
.beginTransaction()
|
.beginTransaction()
|
||||||
|
@ -161,4 +198,4 @@ public class MainActivity extends AppCompatActivity {
|
||||||
ActionBar actionBar = getSupportActionBar();
|
ActionBar actionBar = getSupportActionBar();
|
||||||
actionBar.setDisplayHomeAsUpEnabled(enableBackButton);
|
actionBar.setDisplayHomeAsUpEnabled(enableBackButton);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.example.childguard;
|
package com.example.childguard;
|
||||||
|
|
||||||
|
import static android.content.Context.MODE_PRIVATE;
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
|
@ -75,10 +77,10 @@ public class QrPrintFragment extends Fragment {
|
||||||
// @Override
|
// @Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
//共有プリファレンス 全体の準備
|
//共有プリファレンス全体の準備
|
||||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
SharedPreferences sharedPreferences = getActivity().getSharedPreferences("app_situation", MODE_PRIVATE);
|
||||||
//User毎のドメインを保存する
|
//User毎のドメインを保存する
|
||||||
String IdPref=preferences.getString("ID",null);
|
String IdPref=sharedPreferences.getString("ID",null);
|
||||||
// Inflate the layout for this fragment
|
// Inflate the layout for this fragment
|
||||||
View view=inflater.inflate(R.layout.fragment_qr_print, container, false);;
|
View view=inflater.inflate(R.layout.fragment_qr_print, container, false);;
|
||||||
//固定のドメイン
|
//固定のドメイン
|
||||||
|
@ -90,7 +92,7 @@ public class QrPrintFragment extends Fragment {
|
||||||
//User毎のドメイン
|
//User毎のドメイン
|
||||||
String userURL = getArguments().getString("STR_KEY");
|
String userURL = getArguments().getString("STR_KEY");
|
||||||
//キー"ID"の値をuserURLの値にする
|
//キー"ID"の値をuserURLの値にする
|
||||||
SharedPreferences.Editor e = preferences.edit();
|
SharedPreferences.Editor e = sharedPreferences.edit();
|
||||||
e.putString("ID", userURL);
|
e.putString("ID", userURL);
|
||||||
//確定処理
|
//確定処理
|
||||||
e.apply();
|
e.apply();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user