package barbarahliskov.cambialibros;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.annotation.TargetApi;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.support.annotation.NonNull;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.app.LoaderManager.LoaderCallbacks;

import android.content.CursorLoader;
import android.content.Loader;
import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;

import android.os.Build;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import static android.Manifest.permission.READ_CONTACTS;

/**
 * A login screen that offers login via email/password.
 */
public class LoginActivity extends AppCompatActivity {



    // UI references.
    private AutoCompleteTextView mEmailView;
    private EditText mPasswordView;
    private View mProgressView;
    private View mLoginFormView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        // Set up the login form.
        mEmailView = (AutoCompleteTextView) findViewById(R.id.email);
        setTitle("Inicie sesión en Cambia Libros");

        mPasswordView = (EditText) findViewById(R.id.password);
        mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
                if (id == R.id.login || id == EditorInfo.IME_NULL) {
                    attemptLogin();
                    return true;
                }
                return false;
            }
        });

        Button mEmailSignInButton = (Button) findViewById(R.id.email_sign_in_button);
        mEmailSignInButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                attemptLogin();
            }
        });

        Button mEmailRegisterButton = (Button) findViewById(R.id.email_resgister_button);
        mEmailRegisterButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(LoginActivity.this, RegisterActivity.class));
            }
        });


        mLoginFormView = findViewById(R.id.login_form);
        mProgressView = findViewById(R.id.login_progress);
    }




    /**
     * Attempts to sign in or register the account specified by the login form.
     * If there are form errors (invalid email, missing fields, etc.), the
     * errors are presented and no actual login attempt is made.
     */
    private void attemptLogin() {


        // Reset errors.
        mEmailView.setError(null);
        mPasswordView.setError(null);

        // Store values at the time of the login attempt.
        String email = mEmailView.getText().toString();
        String password = mPasswordView.getText().toString();

        boolean cancel = false;
        View focusView = null;

        
        

        if (cancel) {
            // There was an error; don't attempt login and focus the first
            // form field with an error.
            focusView.requestFocus();
        } else {
            // Show a progress spinner, and kick off a background task to
            // perform the user login attempt.
            startActivity(new Intent(LoginActivity.this, Novedades.class));
        }
    }

   




}

@@ -4089,13 +4089,1725 @@
 %7D%0A%0A   %0A%0A
+    /**%0A     * Shows the progress UI and hides the login form.%0A     */%0A    @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)%0A    private void showProgress(final boolean show) %7B%0A        // On Honeycomb MR2 we have the ViewPropertyAnimator APIs, which allow%0A        // for very easy animations. If available, use these APIs to fade-in%0A        // the progress spinner.%0A        if (Build.VERSION.SDK_INT %3E= Build.VERSION_CODES.HONEYCOMB_MR2) %7B%0A            int shortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime);%0A%0A            mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);%0A            mLoginFormView.animate().setDuration(shortAnimTime).alpha(%0A                    show ? 0 : 1).setListener(new AnimatorListenerAdapter() %7B%0A                @Override%0A                public void onAnimationEnd(Animator animation) %7B%0A                    mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);%0A                %7D%0A            %7D);%0A%0A            mProgressView.setVisibility(show ? View.VISIBLE : View.GONE);%0A            mProgressView.animate().setDuration(shortAnimTime).alpha(%0A                    show ? 1 : 0).setListener(new AnimatorListenerAdapter() %7B%0A                @Override%0A                public void onAnimationEnd(Animator animation) %7B%0A                    mProgressView.setVisibility(show ? View.VISIBLE : View.GONE);%0A                %7D%0A            %7D);%0A        %7D else %7B%0A            // The ViewPropertyAnimator APIs are not available, so simply show%0A            // and hide the relevant UI components.%0A            mProgressView.setVisibility(show ? View.VISIBLE : View.GONE);%0A            mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);%0A        %7D%0A    %7D%0A%0A
 %0A%0A%0A%7D%0A

version 4 login