Android Open Source - IMFApp Login Activity






From Project

Back to project page IMFApp.

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 IMFApp 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.teamtreehouse.ribbit;
//from  w ww  . j a v  a  2s. co 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.EditText;
import android.widget.TextView;

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

public class LoginActivity extends Activity {
  protected EditText mUsername;
  protected EditText mPassword;
  protected Button mLoginButton;
  
  protected TextView mSignUpTextView;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.activity_login);
    
    mSignUpTextView = (TextView) findViewById(R.id.signupText);
    mSignUpTextView.setOnClickListener(new View.OnClickListener(){
      @Override
      public void onClick(View v) {
        Intent intent = new Intent(LoginActivity.this, SignUpActivity.class);
        startActivity(intent);
      }
    });
    
    mUsername = (EditText) findViewById(R.id.usernameField);
    mPassword = (EditText) findViewById(R.id.passwordField);
    
    mLoginButton = (Button) findViewById(R.id.loginButton);
    mLoginButton.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        String username = mUsername.getText().toString();
        String password = mPassword.getText().toString();
        
        username = username.trim();
        password = password.trim();
        
        if(username.isEmpty() || password.isEmpty()){
          AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
          builder.setMessage(R.string.login_error_message)
              .setTitle(R.string.oops)
              .setPositiveButton(android.R.string.ok, null);
          AlertDialog dialog = builder.create();
          dialog.show();
        }else{
          setProgressBarIndeterminateVisibility(true);
          ParseUser.logInInBackground(username, password, new LogInCallback() {
            @Override
            public void done(ParseUser user, ParseException e) {
              setProgressBarIndeterminateVisibility(false);
              
              if(e == null){
                // Success!
                Intent intent = new Intent(LoginActivity.this, MainActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(intent);
              }else{
                AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
                builder.setMessage(e.getMessage())
                    .setTitle(R.string.oops)
                    .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.teamtreehouse.ribbit.EditFriendsActivity.java
com.teamtreehouse.ribbit.FriendsFragment.java
com.teamtreehouse.ribbit.InboxFragment.java
com.teamtreehouse.ribbit.LoginActivity.java
com.teamtreehouse.ribbit.MainActivity.java
com.teamtreehouse.ribbit.ParseConstants.java
com.teamtreehouse.ribbit.RibbitApplication.java
com.teamtreehouse.ribbit.SectionsPagerAdapter.java
com.teamtreehouse.ribbit.SignUpActivity.java