From 1eedc17a6c4f0d78c1f6f88ee4a3015f5e5e815d Mon Sep 17 00:00:00 2001 From: it232115 Date: Tue, 16 Jan 2024 16:00:42 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=B5=E3=82=A4=E3=83=88=E4=B8=8A=E3=81=A7?= =?UTF-8?q?=E3=81=AE=E4=BF=9D=E8=AD=B7=E8=80=85=E3=81=8B=E3=82=89=E3=81=AE?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E3=82=92=E5=8F=97=E3=81=91=E5=8F=96=E3=81=A3?= =?UTF-8?q?=E3=81=9F=E6=99=82=E3=81=AB=E4=B9=97=E9=99=8D=E7=8A=B6=E6=85=8B?= =?UTF-8?q?=E3=82=92=E5=A4=89=E6=9B=B4=E3=81=99=E3=82=8B=E5=87=A6=E7=90=86?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F?= =?UTF-8?q?=E3=80=82(=E5=AE=8C=E6=88=90)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/childguard/HomeFragment.java | 85 ++++++++----------- .../com/example/childguard/MainActivity.java | 38 ++------- 2 files changed, 44 insertions(+), 79 deletions(-) diff --git a/app/src/main/java/com/example/childguard/HomeFragment.java b/app/src/main/java/com/example/childguard/HomeFragment.java index bcd6d86..2ba2d25 100644 --- a/app/src/main/java/com/example/childguard/HomeFragment.java +++ b/app/src/main/java/com/example/childguard/HomeFragment.java @@ -154,28 +154,15 @@ public class HomeFragment extends Fragment { return view; } -// @Override -// public void onResume() { -// super.onResume(); -// Log.d("HomeFragment", "onResume: called"); -// Cargettingonandoff(); -// 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)); -// } -// -// } + @Override + public void onResume() { + super.onResume(); + Log.d("HomeFragment", "onResume: called"); + Bundle args = getArguments(); + if (args != null) {//argsの中に値が入っている。 + Cargettingonandoff();//メソッドCargettingonandoff()を実行 + } + } //画面遷移メソッド private void replaceFragment(Fragment fragment) { @@ -190,31 +177,31 @@ public class HomeFragment extends Fragment { // フラグメントトランザクションをコミット transaction.commit(); } -// public void Cargettingonandoff() { -// //共有プリファレンス 全体の準備 -// SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity()); -// //車の乗り降りを管理するtrue=乗車、false=降車 -// boolean zyoukouzyoutai = preferences.getBoolean("car", false); -// SharedPreferences.Editor e = preferences.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); -// e.putBoolean("car", false); -// e.apply(); -// } else { -// //乗車状態にする -// fl.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.frame_style_orange, null)); -// tv.setText(get_on); -// e.putBoolean("car", true); -// e.apply(); -// } -// -// -// } + public void Cargettingonandoff() { + //共有プリファレンス 全体の準備 + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity()); + //車の乗り降りを管理するtrue=乗車、false=降車 + boolean zyoukouzyoutai = preferences.getBoolean("car", false); + SharedPreferences.Editor e = preferences.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); + e.putBoolean("car", false); + e.apply(); + } else { + //乗車状態にする + fl.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.frame_style_orange, null)); + tv.setText(get_on); + e.putBoolean("car", true); + e.apply(); + } + + + } } \ No newline at end of file diff --git a/app/src/main/java/com/example/childguard/MainActivity.java b/app/src/main/java/com/example/childguard/MainActivity.java index beac7a2..41e12a7 100644 --- a/app/src/main/java/com/example/childguard/MainActivity.java +++ b/app/src/main/java/com/example/childguard/MainActivity.java @@ -111,7 +111,14 @@ public class MainActivity extends AppCompatActivity { notifyMain(); } else { Log.w(TAG, "Got an exceptiion!", e); - Cargettingonandoff(); + HomeFragment fragment = new HomeFragment(); + Bundle bundle = new Bundle(); + bundle.putBoolean("親",true); + fragment.setArguments(bundle); + getSupportFragmentManager() + .beginTransaction() + .add(android.R.id.content, fragment) + .commit(); } } @@ -154,33 +161,4 @@ public class MainActivity extends AppCompatActivity { ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(enableBackButton); } - - public void Cargettingonandoff() { - //共有プリファレンス 全体の準備 - SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); - //車の乗り降りを管理するtrue=乗車、false=降車 - boolean zyoukouzyoutai = preferences.getBoolean("car", false); - SharedPreferences.Editor e = preferences.edit(); - String get_on = "\n乗車状態"; - String get_off = "\n降車状態"; - setContentView(R.layout.fragment_home); - TextView tv = findViewById(R.id.situation); - FrameLayout fl = findViewById(R.id.situation_bg); - - if (zyoukouzyoutai == true) { //乗降状態の判定 - //降車状態にする - fl.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.frame_style, null)); - tv.setText(get_off); - e.putBoolean("car", false); - e.apply(); - } else { - //乗車状態にする - fl.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.frame_style_orange, null)); - tv.setText(get_on); - e.putBoolean("car", true); - e.apply(); - } - - - } } \ No newline at end of file