Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private ProgressDialog pDialog;
- private SessionManager session;
- private SQLiteHandler db;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_login);
- inputEmail = (EditText) findViewById(R.id.email);
- inputPassword = (EditText) findViewById(R.id.password);
- btnLogin = (Button) findViewById(R.id.btnLogin);
- btnLinkToRegister = (Button) findViewById(R.id.btnLinkToRegisterScreen);
- // Progress dialog
- pDialog = new ProgressDialog(this);
- pDialog.setCancelable(false);
- // SQLite database handler
- db = new SQLiteHandler(getApplicationContext());
- // Session manager
- session = new SessionManager(getApplicationContext());
- // Check if user is already logged in or not
- if (session.isLoggedIn()) {
- // User is already logged in. Take him to main activity
- Intent intent = new Intent(LoginActivity.this, MainActivity.class);
- startActivity(intent);
- finish();
- }
- // Login button Click Event
- btnLogin.setOnClickListener(new View.OnClickListener() {
- @SuppressLint("NewApi")
- public void onClick(View view) {
- String email = inputEmail.getText().toString().trim();
- String password = inputPassword.getText().toString().trim();
- // Check for empty data in the form
- if (!email.isEmpty() && !password.isEmpty()) {
- // login user
- checkLogin(email, password);
- } else {
- // Prompt user to enter credentials
- Toast.makeText(getApplicationContext(),
- "Please enter the credentials!", Toast.LENGTH_LONG)
- .show();
- }
- }
- });
- // Link to Register Screen
- btnLinkToRegister.setOnClickListener(new View.OnClickListener() {
- public void onClick(View view) {
- Intent i = new Intent(getApplicationContext(),
- RegisterActivity.class);
- startActivity(i);
- finish();
- }
- });
- }
- /**
- * function to verify login details in mysql db
- * */
- private void checkLogin(final String email, final String password) {
- // Tag used to cancel the request
- String tag_string_req = "req_login";
- pDialog.setMessage("Logging in ...");
- showDialog();
- StringRequest strReq = new StringRequest(Method.POST,
- AppConfig.URL_LOGIN, new Response.Listener<String>() {
- @Override
- public void onResponse(String response) {
- Log.d(TAG, "Login Response: " + response.toString());
- hideDialog();
- try {
- JSONObject jObj = new JSONObject(response);
- boolean error = jObj.getBoolean("error");
- // Check for error node in json
- if (!error) {
- // user successfully logged in
- // Create login session
- session.setLogin(true);
- // Now store the user in SQLite
- String uid = jObj.getString("uid");
- JSONObject user = jObj.getJSONObject("user");
- String name = user.getString("name");
- String email = user.getString("email");
- String phone = user.getString("phone");
- String created_at = user.getString("created_at");
- // Inserting row in users table
- db.addUser(name, email,phone, uid, created_at);
- // Launch main activity
- Intent intent = new Intent(LoginActivity.this,
- MainActivity.class);
- startActivity(intent);
- finish();
- } else {
- // Error in login. Get the error message
- String errorMsg = jObj.getString("error_msg");
- Toast.makeText(getApplicationContext(),
- errorMsg, Toast.LENGTH_LONG).show();
- }
- } catch (JSONException e) {
- // JSON error
- e.printStackTrace();
- Toast.makeText(getApplicationContext(), "Json error: " + e.getMessage(), Toast.LENGTH_LONG).show();
- }
- }
- }, new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError error) {
- Log.e(TAG, "Login Error: " + error.getMessage());
- Toast.makeText(getApplicationContext(),
- error.getMessage(), Toast.LENGTH_LONG).show();
- hideDialog();
- }
- }) {
- @Override
- protected Map<String, String> getParams() {
- // Posting parameters to login url
- Map<String, String> params = new HashMap<String, String>();
- params.put("email", email);
- params.put("password", password);
- return params;
- }
- };
- // Adding request to request queue
- AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
- }
- private void showDialog() {
- if (!pDialog.isShowing())
- pDialog.show();
- }
- private void hideDialog() {
- if (pDialog.isShowing())
- pDialog.dismiss();
- }
- private TextView txtName;
- private TextView txtEmail;
- //private TextView txtPhone;
- private Button btnLogout;
- ImageButton button2,button1,button3;
- private SQLiteHandler db;
- private SessionManager session;
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- txtName = (TextView) findViewById(R.id.name);
- txtEmail = (TextView) findViewById(R.id.email);
- button1 = (ImageButton) findViewById(R.id.Button);
- // button3 = (ImageButton) findViewById(R.id.Button2);
- //txtPhone = (TextView) findViewById(R.id.phone);
- btnLogout = (Button) findViewById(R.id.btnLogout);
- // button2 = (ImageButton) findViewById(R.id.Button1);
- //button3 = (ImageButton) findViewById(R.id.Button2);
- // m = new Mail("[email protected]", "internshipait!!");
- // Add your mail Id and Password
- // SqLite database handler
- db = new SQLiteHandler(getApplicationContext());
- // session manager
- session = new SessionManager(getApplicationContext());
- if (!session.isLoggedIn()) {
- logoutUser();
- }
- // Fetching user details from SQLite
- HashMap<String, String> user = db.getUserDetails();
- String name = user.get("name");
- String email = user.get("email");
- //String phone=user.get("phone");
- // Displaying the user details on the screen
- txtName.setText(name);
- txtEmail.setText(email);
- //txtPhone.setText(phone);
- // Logout button click event
- btnLogout.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- logoutUser();
- }
- });
- /*button1.setOnClickListener(new View.OnClickListener() {
- public void onClick(View view) {
- Intent myIntent = new Intent(view.getContext(), insert.class);
- startActivityForResult(myIntent, 0);
- finish();
- }});
- button2.setOnClickListener(new View.OnClickListener() {
- public void onClick(View view) {
- Intent myIntent = new Intent(view.getContext(), insert1.class);
- startActivityForResult(myIntent, 0);
- finish();
- }});*/
- /* button3.setOnClickListener(new View.OnClickListener() {
- public void onClick(View view) {
- Intent myIntent = new Intent(view.getContext(), ReadData.class);
- startActivityForResult(myIntent, 0);
- finish();
- }});*/
- View.OnClickListener handler = new View.OnClickListener() {
- public void onClick(View v) {
- switch (v.getId()) {
- case R.id.buttonShareTextUrl:
- shareTextUrl();
- break;
- }
- }
- };
- // our buttons
- findViewById(R.id.buttonShareTextUrl).setOnClickListener(handler);
- }
- public void process(View view){
- Intent intent=null,chooser=null;
- if(view.getId()==R.id.send_email)
- {
- intent=new Intent(Intent.ACTION_SEND);
- intent.setData(Uri.parse("mailto:"));
- String[] to={"[email protected]",};
- intent.putExtra(Intent.EXTRA_EMAIL,to);
- intent.putExtra(Intent.EXTRA_SUBJECT, "INTERESTED IN SPONSPORING A CHILD");
- intent.putExtra(Intent.EXTRA_TEXT, "FHHHHHHHHHHHHHHHHHHHHH");
- intent.setType("message/rfc822");
- chooser=Intent.createChooser(intent,"send email");
- startActivity(chooser);
- }
- }
- private void shareTextUrl() {
- Intent share = new Intent(android.content.Intent.ACTION_SEND);
- share.setType("text/plain");
- share.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
- // Add data to the intent, the receiving app will decide
- // what to do with it.
- share.putExtra(Intent.EXTRA_SUBJECT, "Title Of The Post");
- share.putExtra(Intent.EXTRA_TEXT, "please why don't u download sponsor app to sponsor amount to needy child. ");
- //share.putExtra(Intent.EXTRA_TEXT, "");
- startActivity(Intent.createChooser(share, "Share link!"));
- }
- /**
- * Logging out the user. Will set isLoggedIn flag to false in shared
- * preferences Clears the user data from sqlite users table
- * */
- private void logoutUser() {
- session.setLogin(false);
- db.deleteUsers();
- // Launching the login activity
- Intent intent = new Intent(MainActivity.this, LoginActivity.class);
- startActivity(intent);
- finish();
- }
- }
- <LinearLayout
- android:layout_width="fill_parent"
- android:layout_height="48dp"
- android:background="#30D5C8"
- android:orientation="horizontal" >
- <ImageView
- android:layout_width="40dp"
- android:layout_height="40dp"
- android:layout_gravity="center"
- android:layout_marginLeft="10dp"
- android:background="@drawable/ambu" />
- <TextView
- android:layout_width="126dp"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:layout_marginLeft="25dp"
- android:text="Login"
- android:textColor="#00008B"
- android:textSize="18sp"
- android:textStyle="bold" />
- </LinearLayout>
- <LinearLayout
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:layout_marginBottom="30dp"
- android:layout_marginLeft="16dp"
- android:layout_marginRight="16dp"
- android:layout_marginTop="16dp"
- android:background="@drawable/greybackground"
- android:gravity="center_horizontal"
- android:orientation="vertical" >
- <TextView
- android:id="@+id/textView"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentTop="true"
- android:layout_centerHorizontal="true"
- android:layout_gravity="center"
- android:textStyle="bold"
- android:text="Welcome to Vidya app"
- android:textColor="#E75480" />
- <ImageView
- android:layout_width="100dp"
- android:layout_height="100dp"
- android:layout_marginTop="15dp"
- android:background="@drawable/kavi" />
- </LinearLayout>
- <EditText
- android:id="@+id/email"
- android:layout_width="280dp"
- android:layout_height="fill_parent"
- android:layout_gravity="center"
- android:layout_marginBottom="10dp"
- android:background="@color/grey"
- android:ems="10"
- android:hint="@string/hint_email"
- android:inputType="textEmailAddress"
- android:padding="10dp"
- android:singleLine="true"
- android:textColor="@drawable/cl"
- android:textColorHint="@color/input_login_hint" />
- <EditText
- android:id="@+id/password"
- android:layout_width="280dp"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:layout_marginBottom="10dp"
- android:background="@color/grey"
- android:ems="10"
- android:hint="@string/hint_password"
- android:inputType="textPassword"
- android:padding="10dp"
- android:singleLine="true"
- android:textColor="@color/input_login"
- android:textColorHint="@color/input_login_hint" >
- <requestFocus />
- </EditText>
- <!-- Login Button -->
- <Button
- android:id="@+id/btnLogin"
- android:layout_width="190dp"
- android:layout_height="38dp"
- android:layout_gravity="center_horizontal"
- android:layout_marginTop="16dip"
- android:background="@drawable/btn"
- android:text="@string/btn_login"
- android:textColor="@color/btn_login"
- android:textSize="13dp" />
- <Button
- android:id="@+id/btnLinkToRegisterScreen"
- android:layout_width="293dp"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:layout_marginTop="10dip"
- android:background="@null"
- android:text="@string/btn_link_to_register"
- android:textAllCaps="false"
- android:textSize="10dp" />
- <!-- Link to Login Screen -->
- </LinearLayout>
- </ScrollView>
- <LinearLayout
- android:layout_width="fill_parent"
- android:layout_height="500dp"
- android:background="@color/white"
- android:orientation="vertical" />
- <LinearLayout android:id="@+id/linearLayout1"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_centerHorizontal="true"
- android:layout_marginLeft="20dp"
- android:layout_marginRight="20dp"
- android:gravity="center"
- android:orientation="vertical">
- <ImageButton
- android:id="@+id/Button"
- android:layout_width="62dp"
- android:layout_height="65dp"
- android:adjustViewBounds="true"
- android:background="@null"
- android:scaleType="fitCenter"
- android:src="@drawable/search2" />
- <Button
- android:id="@+id/send_email"
- android:layout_width="147dp"
- android:layout_height="wrap_content"
- android:layout_marginTop="20dp"
- android:background="@drawable/cl"
- android:text="@string/faid"
- android:onClick="process"/>
- <Button
- android:id="@+id/buttonShareTextUrl"
- android:layout_width="208dp"
- android:layout_height="wrap_content"
- android:layout_marginTop="20dp"
- android:background="@drawable/greybackground"
- android:text="@string/ex" />
- <RelativeLayout
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:layout_alignParentLeft="true"
- android:layout_alignParentRight="true"
- android:layout_alignParentTop="true"
- android:gravity="bottom"
- android:orientation="vertical" >
- </RelativeLayout>
- </LinearLayout>
- <ScrollView
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:id="@+id/scrollView1"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent" >
- <LinearLayout
- android:layout_width="fill_parent"
- android:layout_height="500dp"
- android:background="#89CFF0"
- android:orientation="vertical" >
- <LinearLayout
- android:layout_width="fill_parent"
- android:layout_height="48dp"
- android:layout_alignParentTop="true"
- android:background="#89CFF0"
- android:orientation="horizontal" >
- <ImageView
- android:layout_width="40dp"
- android:layout_height="40dp"
- android:layout_marginLeft="10dp"
- android:background="@drawable/kavi" />
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center_horizontal|center_vertical"
- android:layout_marginLeft="25dp"
- android:text="Registration form"
- android:textColor="#00008B"
- android:textSize="18sp"
- android:textStyle="bold" />
- <LinearLayout
- android:layout_width="fill_parent"
- android:layout_height="48dp"
- android:gravity="right"
- android:orientation="horizontal" >
- <ImageView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="@drawable/tick" />
- </LinearLayout>
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="520dp"
- android:layout_marginBottom="30dp"
- android:layout_marginLeft="16dp"
- android:layout_marginRight="18dp"
- android:layout_marginTop="16dp"
- android:layout_weight="0.01"
- android:background="@drawable/cl"
- android:orientation="vertical" >
- <ImageView
- android:layout_width="136dp"
- android:layout_height="100dp"
- android:layout_gravity="center"
- android:layout_marginTop="15dp"
- android:background="@drawable/kavi" />
- <EditText
- android:id="@+id/name"
- android:layout_width="fill_parent"
- android:layout_height="40dp"
- android:layout_marginTop="30dp"
- android:background="#f3f3f3"
- android:hint="name"
- android:inputType="textCapWords"
- android:paddingLeft="5dp" />
- <EditText
- android:id="@+id/email"
- android:layout_width="fill_parent"
- android:layout_height="40dp"
- android:layout_marginTop="15dp"
- android:background="#f3f3f3"
- android:hint="email"
- android:inputType="textEmailAddress"
- android:paddingLeft="5dp" />
- <EditText
- android:id="@+id/phone"
- android:layout_width="fill_parent"
- android:layout_height="40dp"
- android:layout_marginTop="15dp"
- android:background="#f3f3f3"
- android:hint="Phone"
- android:inputType="number"
- android:paddingLeft="5dp" />
- <EditText
- android:id="@+id/password"
- android:layout_width="fill_parent"
- android:layout_height="40dp"
- android:layout_marginTop="15dp"
- android:background="#f3f3f3"
- android:hint="Password"
- android:inputType="textPassword"
- android:paddingLeft="5dp" />
- <requestFocus />
- <Button
- android:id="@+id/btnRegister"
- android:layout_width="190dp"
- android:layout_height="38dp"
- android:layout_gravity="center_horizontal"
- android:layout_marginTop="16dp"
- android:background="@drawable/btn"
- android:text="Register"
- android:textColor="#fff" />
- <Button
- android:id="@+id/btnLinkToLoginScreen"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="20dip"
- android:background="@null"
- android:text="@string/btn_link_to_login"
- android:textAllCaps="false"
- android:textSize="12dp" />
- </LinearLayout>
- <LinearLayout
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical" >
- </LinearLayout>
- </LinearLayout>
- </ScrollView>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement