diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/MainActivity.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/MainActivity.java index 0649149..5a655c5 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/MainActivity.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/MainActivity.java @@ -9,30 +9,49 @@ import org.ntlab.radishforandroidstudio.cactusClient.views.PlayerFragment; import org.ntlab.radishforandroidstudio.cactusClient.views.StartFragment; +/** + * Cactusのメインアプリケーション + */ public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - //splash - // ここで5秒間スリープし、スプラッシュを表示させたままにする。 + + splash(); + + //fragmentの設定 + Fragment fragment = new StartFragment(); + addFragment(R.id.fragment_place, fragment, "StartFragment"); + setContentView(R.layout.activity_main); + } + + + public void splash() { + //3秒間スリープし、スプラッシュを表示。 try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } - setTheme(R.style.AppTheme_NoActionBar); setContentView(R.layout.activity_main); - - //fragmentの設定 - Fragment fragment; - fragment = new StartFragment(); - getSupportFragmentManager().beginTransaction().add(R.id.fragment_place, fragment).commit(); - setContentView(R.layout.activity_main); } + protected void addFragment(int containerViewId, Fragment fragment, String tag) { + getSupportFragmentManager().beginTransaction().add(containerViewId, fragment, tag).commit(); + } + + protected void replaceFragment(int containerViewId, Fragment fragment, String tag, boolean flag) { + if (flag) { + getSupportFragmentManager().beginTransaction().replace(containerViewId, fragment, tag).addToBackStack(null).commit(); + } else { + getSupportFragmentManager().beginTransaction().replace(containerViewId, fragment, tag).commit(); + } + } + + @Override public void onBackPressed() { FragmentManager manager = getSupportFragmentManager(); @@ -48,7 +67,6 @@ if (fragment instanceof PlayerFragment) { manager.beginTransaction().remove(fragment).commit(); manager.popBackStack(); -// super.onBackPressed(); return; } super.onBackPressed();