Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.53 KB | None | 0 0
  1. public class LoginActivity extends AppCompatActivity {
  2. private ProgressBar spinner;
  3.  
  4. EditText EMAIL, PASSWORD;
  5. Button SIGNIN;
  6. private FirebaseAuth mAuth;
  7. private FirebaseAuth.AuthStateListener mAuthListener;
  8.  
  9.  
  10. @Override
  11. public void onCreate(Bundle savedInstanceState) {
  12. super.onCreate(savedInstanceState);
  13. setContentView(R.layout.activity_login);
  14.  
  15. mAuth = FirebaseAuth.getInstance();
  16.  
  17. EMAIL = (EditText) findViewById(R.id.email);
  18. PASSWORD = (EditText) findViewById(R.id.password);
  19. SIGNIN = (Button) findViewById(R.id.login);
  20. spinner = (ProgressBar) findViewById(R.id.progressBar1);
  21. spinner.setVisibility(View.GONE);
  22.  
  23.  
  24. SIGNIN.setOnClickListener(new View.OnClickListener() {
  25.  
  26.  
  27. @Override
  28. public void onClick(View view) {
  29. if ((TextUtils.isEmpty(EMAIL.getText().toString())) && (TextUtils.isEmpty(PASSWORD.getText().toString()))) {
  30. Toast.makeText(getApplicationContext(), "make sure that you enter full ogin info ", Toast.LENGTH_SHORT).show();
  31. }else if (!isEmailValid(EMAIL.getText().toString())){
  32. Toast.makeText(getApplicationContext(), "enter a valid mail", Toast.LENGTH_SHORT).show();
  33. } else {
  34. SignIn(EMAIL.getText().toString(), PASSWORD.getText().toString());
  35. }
  36.  
  37. }
  38. });
  39. SIGNIN.setOnClickListener(new View.OnClickListener() {
  40. @Override
  41. public void onClick(View view) {
  42. String pass = PASSWORD.getText().toString();
  43.  
  44. if(TextUtils.isEmpty(pass)) {
  45. PASSWORD.setError("kindly enter password ");
  46. return;
  47. }
  48.  
  49.  
  50.  
  51.  
  52.  
  53. if ((TextUtils.isEmpty(EMAIL.getText().toString())) && (TextUtils.isEmpty(PASSWORD.getText().toString()))) {
  54. Toast.makeText(getApplicationContext(), "wrong info", Toast.LENGTH_SHORT).show();
  55. spinner.setVisibility(View.GONE);
  56.  
  57. } else {
  58. spinner.setVisibility(View.VISIBLE);
  59. SignIn(EMAIL.getText().toString(), PASSWORD.getText().toString());
  60. }
  61.  
  62. }
  63. });
  64.  
  65.  
  66. mAuthListener = new FirebaseAuth.AuthStateListener() {
  67. @Override
  68. public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
  69. FirebaseUser user = firebaseAuth.getCurrentUser();
  70. if (user != null) {
  71. finish();
  72. startActivity(new Intent(getApplicationContext(), MainActivity.class));
  73. finish();
  74. }
  75. }
  76. };
  77. mAuth.addAuthStateListener(mAuthListener);
  78.  
  79.  
  80. }
  81.  
  82.  
  83. private void SignIn(String email, String password) {
  84. mAuth.signInWithEmailAndPassword(email, password)
  85. .addOnCompleteListener(new OnCompleteListener<AuthResult>() {
  86. @Override
  87. public void onComplete(@NonNull Task<AuthResult> task) {
  88. if (task.isSuccessful()) {
  89. finish();
  90. Toast.makeText(getApplicationContext(), "login done",
  91. Toast.LENGTH_SHORT).show();
  92. startActivity(new Intent(getApplicationContext(), MainActivity.class));
  93. finish();
  94. } else {
  95. Toast.makeText(getApplicationContext(), "Error username",
  96. Toast.LENGTH_SHORT).show();
  97. spinner.setVisibility(View.GONE);
  98.  
  99. }
  100.  
  101. }
  102. });
  103. }
  104.  
  105. public static boolean isEmailValid(String email) {
  106. boolean isValid = false;
  107.  
  108. String expression = "^[\w\.-]+@([\w\-]+\.)+[A-Z]{2,4}$";
  109. CharSequence inputStr = email;
  110.  
  111. Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
  112. Matcher matcher = pattern.matcher(inputStr);
  113. if (matcher.matches()) {
  114. isValid = true;
  115. }
  116. return isValid;
  117. }
  118. }
  119.  
  120. public class Harsh extends AppCompatActivity {
  121. RadioButton lo, hi, mid;
  122. String sense;
  123. Button submit;
  124.  
  125.  
  126.  
  127. @Override
  128. public void onCreate(Bundle savedInstanceState) {
  129. super.onCreate(savedInstanceState);
  130. setContentView(R.layout.harsh_layout);
  131. lo = (RadioButton) findViewById(R.id.lo_btn);
  132. hi = (RadioButton) findViewById(R.id.hi_btn);
  133. mid = (RadioButton) findViewById(R.id.mid_btn);
  134. submit = (Button) findViewById(R.id.submitButton);
  135.  
  136. SharedPreferences prefs = getSharedPreferences("MyPrefs", MODE_PRIVATE);
  137. final String num = prefs.getString("nameKey", "0");
  138.  
  139. submit.setOnClickListener(new View.OnClickListener() {
  140. @Override
  141. public void onClick(View v) {
  142. if (lo.isChecked()) {
  143. sendSMS( num, " message one");
  144.  
  145. } else if (hi.isChecked()) {
  146. sendSMS( num, " message 2");
  147. // for example save this message for current logged user
  148. } else if (mid.isChecked()) {
  149.  
  150.  
  151. sendSMS( num, " message 3");
  152. }
  153. Toast.makeText(getApplicationContext(), "Command Sent", Toast.LENGTH_LONG).show(); // print the value of selected super star
  154. }
  155. });
  156.  
  157.  
  158.  
  159. }
  160. public void sendSMS(String phoneNo, String msg) {
  161. try {
  162. SmsManager smsManager = SmsManager.getDefault();
  163. smsManager.sendTextMessage(phoneNo, null, msg, null, null);
  164. Toast.makeText(getApplicationContext(), "Command Sent",
  165. Toast.LENGTH_LONG).show();
  166. } catch (Exception ex) {
  167. Toast.makeText(getApplicationContext(),ex.getMessage().toString(),
  168. Toast.LENGTH_LONG).show();
  169. ex.printStackTrace();
  170. }
  171. }
  172. }
  173.  
  174. public class Post {
  175.  
  176. private String message;
  177. private String number;
  178. private String user;
  179. private String date;
  180.  
  181. public String getMessage() {
  182. return message;
  183. }
  184.  
  185. public void setMessage(String message) {
  186. this.message = message;
  187. }
  188.  
  189. public String getNumber() {
  190. return number;
  191. }
  192.  
  193. public void setNumber(String number) {
  194. this.number = number;
  195. }
  196.  
  197. public String getUser() {
  198. return user;
  199. }
  200.  
  201. public void setUser(String user) {
  202. this.user = user;
  203. }
  204. public String getDate() {
  205. return date;
  206. }
  207.  
  208. public void setDate(String date) {
  209. this.date = date;
  210. }
  211. }
  212.  
  213. FirebaseDatabase database = FirebaseDatabase.getInstance();
  214.  
  215. DatabaseReference posts = database.getReference("Messages:");
  216. //this code for keep posts even app offline until the app online again
  217. posts.keepSynced(true);
  218.  
  219. Post post = new Post();
  220. post.setMessage("Messsage");
  221. post.setUser(name);
  222. post.setNumber(num);
  223. post.setDate(s);
  224.  
  225. posts.push().setValue(post);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement