Guest User

Untitled

a guest
Dec 18th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.81 KB | None | 0 0
  1. public class Tab1MyProfile extends Fragment {
  2.  
  3. @Nullable
  4. @Override
  5. public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  6. View rootView = inflater.inflate(R.layout.tab1_my_profile, container, false);
  7. return rootView;
  8. }
  9. }
  10.  
  11. public class GameLive extends AppCompatActivity implements RecognitionListener {
  12. private Intent intent;
  13. private Button mStopButton;
  14.  
  15. public void stopGame (View view) {
  16. AlertDialog.Builder builder = new AlertDialog.Builder(this);
  17. builder.setMessage("Are you sure you want to finish the game?")
  18. .setCancelable(false)
  19. .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
  20. public void onClick(DialogInterface dialog, int id) {
  21. FragmentManager fragmentManager = getSupportFragmentManager();
  22. FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
  23. Tab1MyProfile fragment = new Tab1MyProfile();
  24. fragmentTransaction.replace(android.R.id.content, fragment);
  25. fragmentTransaction.commit();
  26. }
  27. })
  28. .setNegativeButton("No", new DialogInterface.OnClickListener() {
  29. public void onClick(DialogInterface dialog, int id) {
  30. dialog.cancel();
  31. }
  32. });
  33. AlertDialog alert = builder.create();
  34. alert.show();
  35. }
  36.  
  37.  
  38. public void onCreate(Bundle savedInstanceState) {
  39. super.onCreate(savedInstanceState);
  40. setContentView(R.layout.game_live);
  41. mStopButton = (Button) findViewById(R.id.btnEndGame);
  42. mStopButton.setOnClickListener(new View.OnClickListener() {
  43. @Override
  44. public void onClick(View view) {
  45. stopGame(view);
  46. }
  47. });
  48.  
  49. }
  50.  
  51. }
  52.  
  53. public class StartActivity extends AppCompatActivity {
  54.  
  55. private SectionsPagerAdapter mSectionsPagerAdapter;
  56. private ViewPager mViewPager;
  57.  
  58. @TargetApi(Build.VERSION_CODES.M)
  59. @Override
  60. protected void onCreate(Bundle savedInstanceState) {
  61. super.onCreate(savedInstanceState);
  62. setContentView(R.layout.activity_start);
  63.  
  64. mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
  65.  
  66. // Set up the ViewPager with the sections adapter.
  67. mViewPager = (ViewPager) findViewById(R.id.container);
  68. mViewPager.setAdapter(mSectionsPagerAdapter);
  69.  
  70. TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
  71. tabLayout.setupWithViewPager(mViewPager);
  72.  
  73. }
  74.  
  75. @Override
  76. public boolean onCreateOptionsMenu(Menu menu) {
  77. // Inflate the menu; this adds items to the action bar if it is present.
  78. getMenuInflater().inflate(R.menu.menu_start, menu);
  79. return true;
  80. }
  81.  
  82. @Override
  83. public boolean onOptionsItemSelected(MenuItem item) {
  84. // Handle action bar item clicks here. The action bar will
  85. // automatically handle clicks on the Home/Up button, so long
  86. // as you specify a parent activity in AndroidManifest.xml.
  87. int id = item.getItemId();
  88.  
  89. //noinspection SimplifiableIfStatement
  90. if (id == R.id.action_settings) {
  91. return true;
  92. }
  93.  
  94. return super.onOptionsItemSelected(item);
  95. }
  96.  
  97.  
  98. /**
  99. * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
  100. * one of the sections/tabs/pages.
  101. */
  102. public class SectionsPagerAdapter extends FragmentPagerAdapter {
  103.  
  104. public SectionsPagerAdapter(FragmentManager fm) {
  105. super(fm);
  106. }
  107.  
  108. @Override
  109. public Fragment getItem(int position) {
  110. switch (position) {
  111. case 0:
  112. Tab1MyProfile tab1=new Tab1MyProfile();
  113. return tab1;
  114. case 1:
  115. Tab2StartGame tab2=new Tab2StartGame();
  116. return tab2;
  117. case 2:
  118. Tab3StatsArea tab3=new Tab3StatsArea();
  119. return tab3;
  120. case 3:
  121. Tab4Settings tab4=new Tab4Settings();
  122. return tab4;
  123. }
  124. return null;
  125. }
  126.  
  127. @Override
  128. public int getCount() {
  129. // Show 4 total pages.
  130. return 4;
  131. }
  132.  
  133. @Override
  134. public CharSequence getPageTitle(int position) {
  135. switch (position) {
  136. case 0:
  137. return "My profile";
  138. case 1:
  139. return "Start Game";
  140. case 2:
  141. return "Stats Area";
  142. case 3:
  143. return "Settings";
  144. }
  145. return null;
  146. }
  147. }
  148.  
  149.  
  150. }
Add Comment
Please, Sign In to add comment