mansi_singhal

java and xml code for User_login_Activity

Jul 11th, 2018
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.29 KB | None | 0 0
  1. #### java code for User_login_Activity
  2.  
  3. package com.example.shikhadwivedi.homeautomation;
  4.  
  5. import android.app.ProgressDialog;
  6. import android.content.Intent;
  7. import android.graphics.Typeface;
  8. import android.os.AsyncTask;
  9. import android.os.Bundle;
  10. import android.support.v7.app.AppCompatActivity;
  11. import android.text.TextUtils;
  12. import android.util.Log;
  13. import android.view.View;
  14. import android.widget.Button;
  15. import android.widget.EditText;
  16. import android.widget.TextView;
  17. import android.widget.Toast;
  18.  
  19. import java.util.HashMap;
  20.  
  21. public class UserLoginActivity extends AppCompatActivity {
  22.  
  23. EditText Email, Password;
  24. Button LogIn ,log_in;
  25. String PasswordHolder, EmailHolder;
  26. String finalResult ;
  27. String HttpURL = "http://192.168.0.17/UserLogin.php";
  28. Boolean CheckEditText ;
  29. ProgressDialog progressDialog;
  30. HashMap<String,String> hashMap = new HashMap<>();
  31. HttpParse httpParse = new HttpParse();
  32. public static final String UserEmail = "";
  33.  
  34. @Override
  35. protected void onCreate(Bundle savedInstanceState) {
  36. super.onCreate(savedInstanceState);
  37. setContentView(R.layout.activity_user_login);
  38. Email = (EditText)findViewById(R.id.email);
  39. Password = (EditText)findViewById(R.id.password);
  40. TextView loginh = findViewById(R.id.loginh);
  41. Typeface typeface = Typeface.createFromAsset(getAssets(), "ladybirds.ttf");
  42. loginh.setTypeface(typeface);
  43. log_in = (Button)findViewById(R.id.register);
  44. log_in.setOnClickListener(new View.OnClickListener() {
  45. @Override
  46. public void onClick(View view) {
  47. Intent intent = new Intent(UserLoginActivity.this, RegistrationActivity.class);
  48. startActivity(intent);
  49.  
  50. }
  51. });
  52. LogIn = (Button)findViewById(R.id.Login);
  53. LogIn.setOnClickListener(new View.OnClickListener() {
  54. @Override
  55. public void onClick(View view) {
  56. CheckEditTextIsEmptyOrNot();
  57. if(CheckEditText){
  58. UserLoginFunction(EmailHolder, PasswordHolder);
  59. }
  60. else {
  61. Toast.makeText(UserLoginActivity.this, "Please fill all form fields.", Toast.LENGTH_LONG).show();
  62. Intent intent = new Intent(UserLoginActivity.this, MainActivity.class);
  63. startActivity(intent);
  64. }
  65.  
  66. }
  67. });
  68. }
  69. public void CheckEditTextIsEmptyOrNot(){
  70. EmailHolder = Email.getText().toString();
  71. PasswordHolder = Password.getText().toString();
  72.  
  73. if(TextUtils.isEmpty(EmailHolder) || TextUtils.isEmpty(PasswordHolder)) {
  74. CheckEditText = false;
  75. }
  76. else {
  77. CheckEditText = true ;
  78. }
  79. }
  80. public void UserLoginFunction(final String email, final String password){
  81. class UserLoginClass extends AsyncTask<String,Void,String> {
  82. @Override
  83. protected void onPreExecute() {
  84. super.onPreExecute();
  85. progressDialog = ProgressDialog.show(UserLoginActivity.this,"Loading Data",null,true,true);
  86. }
  87.  
  88. @Override
  89. protected void onPostExecute(String httpResponseMsg) {
  90. super.onPostExecute(httpResponseMsg);
  91. progressDialog.dismiss();
  92. Log.d("hello",httpResponseMsg);
  93. if(httpResponseMsg.equalsIgnoreCase("\uFEFF\uFEFFData Matched")){
  94. Toast.makeText(UserLoginActivity.this,httpResponseMsg,Toast.LENGTH_LONG).show();
  95. Intent intent = new Intent(UserLoginActivity.this, MainActivity.class);
  96. startActivity(intent);
  97. }
  98.  
  99. else{
  100. Log.d("hel",httpResponseMsg);
  101. Toast.makeText(UserLoginActivity.this,httpResponseMsg,Toast.LENGTH_LONG).show();
  102. }
  103. }
  104. @Override
  105. protected String doInBackground(String... params) {
  106. hashMap.put("email",params[0]);
  107. hashMap.put("password",params[1]);
  108.  
  109. finalResult = httpParse.postRequest(hashMap, HttpURL);
  110. return finalResult;
  111. }
  112. }
  113. UserLoginClass userLoginClass = new UserLoginClass();
  114. userLoginClass.execute(email,password);
  115. }
  116. }
  117.  
  118. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  119.  
  120. ###### Xml code for User_login_Activity
  121.  
  122. <?xml version="1.0" encoding="utf-8"?>
  123. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  124. xmlns:tools="http://schemas.android.com/tools"
  125. android:id="@+id/activity_user_login"
  126. android:layout_width="match_parent"
  127. android:layout_height="match_parent"
  128. tools:context="com.example.shikhadwivedi.homeautomation.UserLoginActivity"
  129. android:padding="30sp"
  130. android:gravity="center"
  131. android:background="@drawable/loginbg"
  132. >
  133. <TextView
  134. android:text="Smart Home"
  135. android:layout_width="wrap_content"
  136. android:layout_height="wrap_content"
  137. android:layout_alignParentTop="true"
  138. android:layout_centerHorizontal="true"
  139. android:id="@+id/loginh"
  140. android:gravity="center"
  141. android:textSize="30sp"
  142. android:textColor="#3c0660"/>
  143.  
  144.  
  145. <EditText
  146. android:layout_width="fill_parent"
  147. android:layout_height="60sp"
  148.  
  149. android:inputType="textPersonName"
  150. android:ems="10"
  151. android:layout_below="@+id/loginh"
  152. android:layout_centerHorizontal="true"
  153. android:layout_marginTop="20sp"
  154. android:id="@+id/email"
  155. android:hint="Enter Email"
  156. android:gravity="center"
  157. android:drawableLeft="@drawable/person"
  158. android:paddingLeft="30sp"/>
  159.  
  160. <EditText
  161. android:layout_width="fill_parent"
  162. android:layout_height="60sp"
  163. android:inputType="textPassword"
  164. android:ems="10"
  165. android:layout_below="@+id/email"
  166. android:layout_centerHorizontal="true"
  167. android:layout_marginTop="20sp"
  168. android:id="@+id/password"
  169. android:hint="Enter Password"
  170. android:gravity="center"
  171. android:drawableLeft="@drawable/lock"
  172. android:paddingLeft="30sp"
  173. />
  174.  
  175. <Button
  176. android:text="Log In"
  177. android:layout_width="fill_parent"
  178. android:layout_height="wrap_content"
  179. android:layout_below="@+id/password"
  180. android:layout_centerHorizontal="true"
  181. android:layout_marginTop="20sp"
  182. android:id="@+id/Login"
  183. android:background="@drawable/oval2"
  184. android:textColor="#ffffff"/>
  185. <Button
  186. android:text="Sign Up"
  187. android:layout_width="match_parent"
  188. android:layout_height="wrap_content"
  189. android:layout_below="@+id/Login"
  190. android:layout_centerHorizontal="true"
  191. android:layout_marginTop="10sp"
  192. android:id="@+id/register"
  193. android:background="@drawable/oval2"
  194. android:textColor="#ffffff"/>
  195.  
  196. </RelativeLayout>
Add Comment
Please, Sign In to add comment