Hotfix 1 #18
@ -1,5 +1,6 @@
 | 
				
			|||||||
package com.example.childguard;
 | 
					package com.example.childguard;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import android.content.SharedPreferences;
 | 
				
			||||||
import android.os.Bundle;
 | 
					import android.os.Bundle;
 | 
				
			||||||
import android.util.Log;
 | 
					import android.util.Log;
 | 
				
			||||||
import android.view.LayoutInflater;
 | 
					import android.view.LayoutInflater;
 | 
				
			||||||
@ -76,6 +77,12 @@ public class HomeFragment extends Fragment implements OnEventListener{
 | 
				
			|||||||
    public void onResume() {
 | 
					    public void onResume() {
 | 
				
			||||||
        super.onResume();
 | 
					        super.onResume();
 | 
				
			||||||
        Log.d("HomeFragment", "onResume: called");
 | 
					        Log.d("HomeFragment", "onResume: called");
 | 
				
			||||||
 | 
					        this.updateUiState(getIsInCarLocal());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private boolean getIsInCarLocal() {
 | 
				
			||||||
 | 
					        SharedPreferences pref = requireActivity().getSharedPreferences("app_situation", requireActivity().MODE_PRIVATE);
 | 
				
			||||||
 | 
					        return pref.getBoolean("isInCar", false);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //画面遷移メソッド
 | 
					    //画面遷移メソッド
 | 
				
			||||||
 | 
				
			|||||||
@ -131,13 +131,11 @@ public class MainActivity extends AppCompatActivity {
 | 
				
			|||||||
            Log.d("BT", "Permission to connect bluetooth devices granted");
 | 
					            Log.d("BT", "Permission to connect bluetooth devices granted");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        registerReceiver(receiver, intentFilter);
 | 
					        registerReceiver(receiver, intentFilter);
 | 
				
			||||||
        changessituation();
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    protected void onResume() {
 | 
					    protected void onResume() {
 | 
				
			||||||
        super.onResume();
 | 
					        super.onResume();
 | 
				
			||||||
        changessituation();
 | 
					 | 
				
			||||||
        Log.d("onResume", "called");
 | 
					        Log.d("onResume", "called");
 | 
				
			||||||
        Log.d("onResume", "mDocRef is null");
 | 
					        Log.d("onResume", "mDocRef is null");
 | 
				
			||||||
        firebaselink();
 | 
					        firebaselink();
 | 
				
			||||||
@ -162,7 +160,8 @@ public class MainActivity extends AppCompatActivity {
 | 
				
			|||||||
                //FireBaseで更新された情報の判定
 | 
					                //FireBaseで更新された情報の判定
 | 
				
			||||||
                if (documentSnapshot.getBoolean("isReported") == false) {//isReportedがfalseのとき=サイト上で保護者ボタンが押されたとき
 | 
					                if (documentSnapshot.getBoolean("isReported") == false) {//isReportedがfalseのとき=サイト上で保護者ボタンが押されたとき
 | 
				
			||||||
                    if (fragment instanceof HomeFragment) {//fragementがHomeFragmentのインスタンスかの判定
 | 
					                    if (fragment instanceof HomeFragment) {//fragementがHomeFragmentのインスタンスかの判定
 | 
				
			||||||
                        changessituation();//  changessituation()メソッドを処理→アプリ側の乗降状態を変化
 | 
					//                        changessituation();//  changessituation()メソッドを処理→アプリ側の乗降状態を変化
 | 
				
			||||||
 | 
					                        ((HomeFragment) fragment).onEvent(!isInCar);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                } else if (isInCar) {//第三者ボタンが押されたときにisInCarがtrueのとき=乗車状態のとき→いたずら防止
 | 
					                } else if (isInCar) {//第三者ボタンが押されたときにisInCarがtrueのとき=乗車状態のとき→いたずら防止
 | 
				
			||||||
                    int importance = NotificationManager.IMPORTANCE_DEFAULT;
 | 
					                    int importance = NotificationManager.IMPORTANCE_DEFAULT;
 | 
				
			||||||
@ -302,17 +301,6 @@ public class MainActivity extends AppCompatActivity {
 | 
				
			|||||||
        notificationManager.notify(R.string.app_name, builder.build());//通知の表示
 | 
					        notificationManager.notify(R.string.app_name, builder.build());//通知の表示
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void changessituation() {//乗降状態の管理をするためにHomeFramgentを呼び出すメソッド
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        SharedPreferences sharedPreferences = getSharedPreferences("app_situation", MODE_PRIVATE);
 | 
					 | 
				
			||||||
        //共有プリファレンス 書き込みの準備
 | 
					 | 
				
			||||||
        SharedPreferences.Editor E = sharedPreferences.edit();
 | 
					 | 
				
			||||||
        Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragmentContainerView);
 | 
					 | 
				
			||||||
        Boolean isInCar = sharedPreferences.getBoolean("isInCarPref", false);//現在の乗降状態を保存する共有プリファレンス
 | 
					 | 
				
			||||||
        ((HomeFragment) fragment).onEvent(!isInCar);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public void onStop() {//アプリをバックグラウンドにした時のメソッド
 | 
					    public void onStop() {//アプリをバックグラウンドにした時のメソッド
 | 
				
			||||||
        super.onStop();
 | 
					        super.onStop();
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user