Advertisement
Guest User

Untitled

a guest
Jan 16th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.36 KB | None | 0 0
  1. package com.login.thinkpad.login;
  2.  
  3. import android.app.Dialog;
  4. import android.content.Intent;
  5. import android.os.Handler;
  6. import android.support.v7.app.AppCompatActivity;
  7. import android.os.Bundle;
  8. import android.view.Menu;
  9. import android.view.MenuItem;
  10. import android.view.View;
  11. import android.view.Window;
  12. import android.widget.Button;
  13. import android.widget.DialerFilter;
  14. import android.widget.EditText;
  15. import android.widget.Toast;
  16.  
  17. public class MainActivity extends AppCompatActivity {
  18. EditText username;
  19. EditText password;
  20. Button login;
  21. Button signin;
  22.  
  23. // For Dialog.
  24. //custom dialog
  25. EditText Setname;
  26. EditText SetUserName;
  27. EditText SetPassword;
  28. Button Create;
  29. Button cancel_action;
  30.  
  31. public static String SetUser;
  32. public static String SetPass;
  33.  
  34. @Override
  35. protected void onCreate(Bundle savedInstanceState) {
  36. super.onCreate(savedInstanceState);
  37. setContentView(R.layout.activity_main);
  38.  
  39. username = (EditText)findViewById(R.id.username);
  40. password = (EditText)findViewById(R.id.password);
  41. login = (Button)findViewById(R.id.Login);
  42. signin = (Button)findViewById(R.id.Create);
  43.  
  44.  
  45.  
  46. signin.setOnClickListener(new View.OnClickListener() {
  47.  
  48. @Override
  49. public void onClick(View v) {
  50. final Dialog dialog = new Dialog(MainActivity.this);
  51. dialog.setTitle("Set info");
  52. dialog.setContentView(R.layout.custom);
  53. dialog.show();
  54. Setname = (EditText)dialog.findViewById(R.id.Setname);
  55. SetUserName = (EditText)dialog.findViewById(R.id.SetUserName);
  56. SetPassword = (EditText)dialog.findViewById(R.id.SetPassword);
  57. Create = (Button)dialog.findViewById(R.id.Create);
  58. cancel_action = (Button)dialog.findViewById(R.id.cancel_action);
  59.  
  60. //set username
  61.  
  62. //Check if SetUser and SetPass are entered,
  63. Create.setOnClickListener(new View.OnClickListener() {
  64. @Override
  65. public void onClick(View v) {
  66. SetUser = SetUserName.getText().toString();
  67. SetPass = SetPassword.getText().toString();
  68. if (SetUser.isEmpty() || SetPass.isEmpty()){
  69. Toast.makeText(getApplicationContext(),"you should set username and password", Toast.LENGTH_LONG).show();
  70. }else {
  71. dialog.cancel();
  72. }
  73. }
  74. });
  75.  
  76.  
  77.  
  78.  
  79.  
  80. }
  81. });
  82. login.setOnClickListener(new View.OnClickListener() {
  83.  
  84. @Override
  85. public void onClick(View v) {
  86. String mUserName = username.getText().toString();
  87. String mPassword = password.getText().toString();
  88. if (mPassword.isEmpty()||mUserName.isEmpty()){
  89. Toast.makeText(getApplicationContext(),"Please fill out username password", Toast.LENGTH_LONG).show();
  90.  
  91. }else if (!mUserName.equals(SetUser)|| !mPassword.equals(SetPass)){
  92. Toast.makeText(getApplicationContext(),"Username and Password are not matched. Please Sign Up", Toast.LENGTH_LONG).show();
  93.  
  94. }
  95. else{
  96. Toast.makeText(getApplicationContext(), "Please wait...", Toast.LENGTH_SHORT).show();
  97.  
  98. final Handler handler = new Handler();
  99. handler.postDelayed(new Runnable() {
  100. @Override
  101. public void run() {
  102. //Do something after 100ms
  103. Intent intent = new Intent(getApplicationContext(), SecondActivity.class);
  104. intent.putExtra("SpeicalKey", true);
  105. startActivity(intent);
  106.  
  107. }
  108.  
  109. }, 3000);
  110.  
  111.  
  112. }
  113. }
  114.  
  115. });
  116. }
  117.  
  118. @Override
  119. public boolean onCreateOptionsMenu(Menu menu) {
  120. // Inflate the menu; this adds items to the action bar if it is present.
  121. getMenuInflater().inflate(R.menu.menu_main, menu);
  122. return true;
  123. }
  124.  
  125. @Override
  126. public boolean onOptionsItemSelected(MenuItem item) {
  127. // Handle action bar item clicks here. The action bar will
  128. // automatically handle clicks on the Home/Up button, so long
  129. // as you specify a parent activity in AndroidManifest.xml.
  130. int id = item.getItemId();
  131.  
  132. //noinspection SimplifiableIfStatement
  133. if (id == R.id.action_settings) {
  134. return true;
  135. }
  136.  
  137. return super.onOptionsItemSelected(item);
  138. }
  139. }
  140.  
  141.  
  142.  
  143.  
  144. // Make a new calss and name it (SecondActivity). Copy paste the following code.
  145.  
  146. package com.login.thinkpad.login;
  147.  
  148. import android.content.Intent;
  149. import android.os.Bundle;
  150. import android.support.v7.app.AppCompatActivity;
  151. import android.widget.TextView;
  152.  
  153. /**
  154. * Created by Ahmed Mostfa on Oct30.
  155. */
  156. public class SecondActivity extends AppCompatActivity {
  157. TextView youLoginIn;
  158. @Override
  159. protected void onCreate(Bundle savedInstanceState){
  160. super.onCreate(savedInstanceState);
  161. setContentView(R.layout.second_activity);
  162. youLoginIn = (TextView)findViewById(R.id.youLogined);
  163. Intent intent = getIntent();
  164. intent.getStringExtra("SpeicalKey");
  165. }
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement