package com.example.shalantor.connect4;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.graphics.Point;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;

public class RegisterFragment extends Fragment{

    public static final int SCREEN_TO_TEXT_SIZE_RATIO = 20;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        return inflater.inflate(R.layout.register_fragment, container, false);
    }

    public void adjustButtons(){

        Activity activity = getActivity();

        /*Get screen dimensions*/
        Display display = activity.getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        int displayHeight = size.y;

        /*Get references to components*/
        EditText usernamePrompt = (EditText) activity.findViewById(R.id.register_username);
        EditText emailPrompt = (EditText) activity.findViewById(R.id.register_email);
        EditText passwordPrompt = (EditText) activity.findViewById(R.id.register_password);
        EditText passwordVerify = (EditText) activity.findViewById(R.id.register_password_verify);
        Button registerButton = (Button) activity.findViewById(R.id.register_button_final);

        /*Set text sizes*/
        usernamePrompt.setTextSize(displayHeight / SCREEN_TO_TEXT_SIZE_RATIO);
        emailPrompt.setTextSize(displayHeight / SCREEN_TO_TEXT_SIZE_RATIO);
        passwordPrompt.setTextSize(displayHeight / SCREEN_TO_TEXT_SIZE_RATIO);
        passwordVerify.setTextSize(displayHeight / SCREEN_TO_TEXT_SIZE_RATIO);
        registerButton.setTextSize(displayHeight / SCREEN_TO_TEXT_SIZE_RATIO);

    }
}

@@ -383,16 +383,113 @@
 ditText;
+%0Aimport android.widget.TextView;%0A%0Aimport java.util.regex.Matcher;%0Aimport java.util.regex.Pattern;
 %0A%0Apublic
@@ -590,16 +590,176 @@
 IO = 20;
+%0A    public static final Pattern VALID_EMAIL_ADDRESS_REGEX =%0A            Pattern.compile(%22%5E%5BA-Z0-9._%25+-%5D+@%5BA-Z0-9.-%5D+%5C%5C.%5BA-Z%5D%7B2,6%7D$%22, Pattern.CASE_INSENSITIVE);
 %0A%0A    @O
@@ -1544,32 +1544,38 @@
 rname);%0A        
+final 
 EditText emailPr
@@ -1918,16 +1918,114 @@
 _final);
+%0A        final TextView textView = (TextView) activity.findViewById(R.id.error_messages_register);
 %0A%0A      
@@ -2350,32 +2350,32 @@
 XT_SIZE_RATIO);%0A
-
         register
@@ -2434,20 +2434,730 @@
 ZE_RATIO);%0A%0A
+        /*Add listener to register button*/%0A        registerButton.setOnClickListener(new View.OnClickListener() %7B%0A            @Override%0A            public void onClick(View view) %7B%0A%0A                /*Check if email is in right format */%0A                String emailInput = emailPrompt.getText().toString();%0A                Matcher matcher = VALID_EMAIL_ADDRESS_REGEX.matcher(emailInput);%0A                if (!matcher.find())%7B%0A                    String errorMessage = %22Please enter a valid email address format%22;%0A                    textView.setText(errorMessage, TextView.BufferType.NORMAL);%0A                %7D%0A%0A                /*Check if password prompts have the same password*/%0A%0A            %7D%0A        %7D);%0A%0A
     %7D%0A%7D%0A

Add email verification method to register button