Android Open Source - PlayTogether Login Activity






From Project

Back to project page PlayTogether.

License

The source code is released under:

This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a co...

If you think the Android project PlayTogether listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.rockylearnstodevelop.playtogether;
/*w w  w  .jav  a 2 s  .c  o  m*/
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

import com.parse.LogInCallback;
import com.parse.ParseException;
import com.parse.ParseUser;

public class LoginActivity extends Activity {

  protected TextView mUsername;
  protected TextView mPassword;
  
  protected Button mLoginButton;
  
  private String userName;
  private String password;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.activity_login);
    
    TextView signupTextView = (TextView) findViewById(R.id.signup);
    signupTextView.setOnClickListener(new View.OnClickListener() {
      
      @Override
      public void onClick(View v) {
        Intent intent = new Intent(LoginActivity.this, SignupActivity.class);
        startActivity(intent);
      }
    });
    
    mUsername = (TextView) findViewById(R.id.userName);
    mPassword = (TextView) findViewById(R.id.password);

    mLoginButton = (Button) findViewById(R.id.login_button);
    mLoginButton.setOnClickListener(new View.OnClickListener() {
      
      @Override
      public void onClick(View v) {
        userName = mUsername.getText().toString();
        password = mPassword.getText().toString();
        
        userName = userName.trim();      
        password = password.trim();
        
        //Check if the name and password if empty
        if(userName.isEmpty() || password.isEmpty()){
          //warning dialog
          AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
          builder.setMessage(R.string.log_in_error_message);
          builder.setTitle(R.string.log_in_error_title);
          builder.setPositiveButton(android.R.string.ok, null);
          AlertDialog dialog = builder.create();
          dialog.show();
        }
        else{
          //check if the user name and password are correct
          setProgressBarIndeterminateVisibility(true);
          ParseUser.logInInBackground(userName, password, new LogInCallback() {
            
            @Override
            public void done(ParseUser user, ParseException e) {
              setProgressBarIndeterminateVisibility(false);
              if(e == null){
                //start the main activity
                Intent intent = new Intent(LoginActivity.this, MainActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(intent);
              }
              else{
                AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
                builder.setMessage(e.getMessage());
                builder.setTitle(R.string.log_in_error_title);
                builder.setPositiveButton(android.R.string.ok, null);
                AlertDialog dialog = builder.create();
                dialog.show();
              }
            }
          });
        }
      }
    });
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.login, menu);
    return true;
  }

}




Java Source Code List

com.rockylearnstodevelop.playtogether.ActivitiesFragment.java
com.rockylearnstodevelop.playtogether.ActivityAdapter.java
com.rockylearnstodevelop.playtogether.FileHelper.java
com.rockylearnstodevelop.playtogether.ImageResizer.java
com.rockylearnstodevelop.playtogether.LoginActivity.java
com.rockylearnstodevelop.playtogether.MainActivity.java
com.rockylearnstodevelop.playtogether.MatchActivity.java
com.rockylearnstodevelop.playtogether.NoMatchActivity.java
com.rockylearnstodevelop.playtogether.ParseConstants.java
com.rockylearnstodevelop.playtogether.PlayWithMe2Application.java
com.rockylearnstodevelop.playtogether.RequestAdapter.java
com.rockylearnstodevelop.playtogether.RequestFragment.java
com.rockylearnstodevelop.playtogether.SectionsPagerAdapter.java
com.rockylearnstodevelop.playtogether.SignupActivity.java
com.rockylearnstodevelop.playtogether.UserInfoActivity.java
com.rockylearnstodevelop.playtogether.WannaPlayFragment.java