Advertisement
Guest User

Untitled

a guest
Aug 1st, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.82 KB | None | 0 0
  1. public class JoinUs extends AppCompatActivity {
  2.  
  3. /**
  4. * The {@link android.support.v4.view.PagerAdapter} that will provide
  5. * fragments for each of the sections. We use a
  6. * {@link FragmentPagerAdapter} derivative, which will keep every
  7. * loaded fragment in memory. If this becomes too memory intensive, it
  8. * may be best to switch to a
  9. * {@link android.support.v4.app.FragmentStatePagerAdapter}.
  10. */
  11. private SectionsPagerAdapter mSectionsPagerAdapter;
  12.  
  13. /**
  14. * The {@link ViewPager} that will host the section contents.
  15. */
  16. private ViewPager mViewPager;
  17.  
  18. @Override
  19. protected void onCreate(Bundle savedInstanceState) {
  20. super.onCreate(savedInstanceState);
  21. setContentView(R.layout.join_us);
  22.  
  23. Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  24. setSupportActionBar(toolbar);
  25. // Create the adapter that will return a fragment for each of the three
  26. // primary sections of the activity.
  27. mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
  28.  
  29. // Set up the ViewPager with the sections adapter.
  30. mViewPager = (ViewPager) findViewById(R.id.container);
  31. mViewPager.setAdapter(mSectionsPagerAdapter);
  32.  
  33. TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
  34.  
  35. mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
  36. tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));
  37.  
  38.  
  39. }
  40.  
  41.  
  42. @Override
  43. public boolean onCreateOptionsMenu(Menu menu) {
  44. // Inflate the menu; this adds items to the action bar if it is present.
  45. getMenuInflater().inflate(R.menu.menu_join_us, menu);
  46. return true;
  47. }
  48.  
  49. @Override
  50. public boolean onOptionsItemSelected(MenuItem item) {
  51. // Handle action bar item clicks here. The action bar will
  52. // automatically handle clicks on the Home/Up button, so long
  53. // as you specify a parent activity in AndroidManifest.xml.
  54. int id = item.getItemId();
  55.  
  56. //noinspection SimplifiableIfStatement
  57. if (id == R.id.action_settings) {
  58. return true;
  59. }
  60.  
  61. return super.onOptionsItemSelected(item);
  62. }
  63.  
  64. /**
  65. * A placeholder fragment containing a simple view.
  66. */
  67. public static class PlaceholderFragment extends Fragment {
  68. /**
  69. * The fragment argument representing the section number for this
  70. * fragment.
  71. */
  72. private static final String ARG_SECTION_NUMBER = "section_number";
  73.  
  74. public PlaceholderFragment() {
  75. }
  76.  
  77. /**
  78. * Returns a new instance of this fragment for the given section
  79. * number.
  80. */
  81. public static PlaceholderFragment newInstance(int sectionNumber) {
  82. PlaceholderFragment fragment = new PlaceholderFragment();
  83. Bundle args = new Bundle();
  84. args.putInt(ARG_SECTION_NUMBER, sectionNumber);
  85. fragment.setArguments(args);
  86. return fragment;
  87. }
  88.  
  89. @Override
  90. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  91. Bundle savedInstanceState) {
  92. if ( getArguments().getInt(ARG_SECTION_NUMBER) == 1) {
  93. View rootView = inflater.inflate(R.layout.tab_signin, container, false);
  94. return rootView;
  95. }
  96. else {
  97. View rootView = inflater.inflate(R.layout.tab_signup, container, false);
  98. return rootView;
  99. }
  100. //View rootView = inflater.inflate(R.layout.fragment_join_us, container, false);
  101. //TextView textView = (TextView) rootView.findViewById(R.id.section_label);
  102. //textView.setText(getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER)));
  103. //return rootView;
  104. }
  105. }
  106.  
  107. /**
  108. * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
  109. * one of the sections/tabs/pages.
  110. */
  111. public class SectionsPagerAdapter extends FragmentPagerAdapter {
  112.  
  113. public SectionsPagerAdapter(FragmentManager fm) {
  114. super(fm);
  115. }
  116.  
  117. @Override
  118. public Fragment getItem(int position) {
  119. // getItem is called to instantiate the fragment for the given page.
  120. // Return a PlaceholderFragment (defined as a static inner class below).
  121. return PlaceholderFragment.newInstance(position + 1);
  122. }
  123.  
  124. @Override
  125. public int getCount() {
  126. // Show 3 total pages.
  127. return 2;
  128. }
  129. }
  130.  
  131. public class tabSignUp extends Fragment {
  132.  
  133. DatabaseHelper helper = new DatabaseHelper(getContext());
  134.  
  135. @Override
  136. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  137. Bundle savedInstanceState) {
  138.  
  139. View rootView = inflater.inflate(R.layout.tab_signup, container, false);
  140. return rootView;
  141. }
  142.  
  143. public void onSignUpClick(View v)
  144. {
  145. if (v.getId() == R.id.signmeup) {
  146. EditText name = getActivity().findViewById(R.id.fname);
  147. EditText email = getActivity().findViewById(R.id.email);
  148. EditText username = getActivity().findViewById(R.id.username);
  149. EditText pass = getActivity().findViewById(R.id.password);
  150. EditText pass2 = getActivity().findViewById(R.id.confpassword);
  151.  
  152.  
  153. String nameStr = name.getText().toString();
  154. String emailStr = email.getText().toString();
  155. String usernameStr = username.getText().toString();
  156. String passStr = pass.getText().toString();
  157. String pass2Str = pass2.getText().toString();
  158.  
  159. if (!passStr.equals(pass2Str)) {
  160. Toast.makeText(getActivity(), "Passwords don't match", Toast.LENGTH_SHORT).show();
  161.  
  162. } else {
  163. //insert details in database
  164. Contact c = new Contact();
  165. c.setName(nameStr);
  166. c.setEmail(emailStr);
  167. c.setUsername(usernameStr);
  168. c.setPass(passStr);
  169.  
  170. helper.insertContact(c);
  171.  
  172. }
  173.  
  174. }
  175. }
  176.  
  177.  
  178. }
  179.  
  180. public class tabSignIn extends Fragment {
  181.  
  182. DatabaseHelper helper = new DatabaseHelper(getContext());
  183.  
  184. @Override
  185. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  186. Bundle savedInstanceState) {
  187. View rootView = inflater.inflate(R.layout.tab_signin, container, false);
  188.  
  189. return rootView;
  190. }
  191.  
  192. public void onButtonClick(View v)
  193. {
  194. if (v.getId() == R.id.signmein){
  195. EditText username = (EditText) getActivity().findViewById(R.id.usernamein);
  196. String str = username.getText().toString();
  197.  
  198. EditText passwrd = getActivity().findViewById(R.id.passwordin);
  199. String pass = passwrd.getText().toString();
  200.  
  201. String password = helper.searchPass(str);
  202. if (pass.equals(password))
  203. {
  204. //take me to homepage
  205. Intent i = new Intent (getActivity(),MainActivity.class);
  206. i.putExtra("Username",str);
  207. startActivity(i);
  208. }
  209. else
  210. {
  211. Toast.makeText(getActivity(),"Username and password don't match",Toast.LENGTH_SHORT).show();
  212.  
  213.  
  214. }
  215.  
  216.  
  217.  
  218. }
  219. }
  220. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement