package me.ryanpetschek.gatekeeper;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;

import org.bouncycastle.jce.ECNamedCurveTable;
import org.bouncycastle.jce.spec.ECParameterSpec;

import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.SecureRandom;

public class SignInActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sign_in);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        setTitle("Sign up");

        final Button button = (Button) findViewById(R.id.signup);
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Intent intent = new Intent(SignInActivity.this, MainActivity.class);
                startActivity(intent);
            }
        });
    }

    protected KeyPair generateKeys() {
        ECParameterSpec specs = ECNamedCurveTable.getParameterSpec("secp256k1");
        try {
            KeyPairGenerator g = KeyPairGenerator.getInstance("ECDSA", "BC");
            g.initialize(specs, new SecureRandom());
            KeyPair pair = g.generateKeyPair();
            return pair;
        }
        catch (java.security.NoSuchAlgorithmException err) {

        }
        catch (java.security.NoSuchProviderException err) {

        }
        catch (java.security.InvalidAlgorithmParameterException err) {

        }
        finally {
            return null;
        }
    }
}

@@ -83,24 +83,67 @@
 .os.Bundle;%0A
+import android.support.v7.app.AlertDialog;%0A
 import andro
@@ -221,16 +221,41 @@
 oolbar;%0A
+import android.util.Log;%0A
 import a
@@ -301,16 +301,79 @@
 .Button;
+%0Aimport android.widget.EditText;%0Aimport android.webkit.URLUtil;
 %0A%0Aimport
@@ -1002,104 +1002,1124 @@
     
-button.setOnClickListener(new View.OnClickListener() %7B%0A            public void onClick(View v) %7B
+final EditText nameField = (EditText) findViewById(R.id.name);%0A        final EditText pictureUrlField = (EditText) findViewById(R.id.photoUrl);%0A        final AlertDialog alertDialog  = new AlertDialog.Builder(this).create();%0A        button.setOnClickListener(new View.OnClickListener() %7B%0A            public void onClick(View v) %7B%0A                // Validate inputs%0A                String name = nameField.getText().toString().trim();%0A                String pictureUrl = pictureUrlField.getText().toString().trim();%0A                if (name.length() == 0 %7C%7C pictureUrl.length() == 0) %7B%0A                    alertDialog.setTitle(%22Error%22);%0A                    alertDialog.setMessage(%22Name or photo URL cannot be left blank%22);%0A                    alertDialog.show();%0A                    return;%0A                %7D%0A                if (!URLUtil.isValidUrl(pictureUrl)) %7B%0A                    alertDialog.setTitle(%22Error%22);%0A                    alertDialog.setMessage(%22Invalid photo URL%22);%0A                    alertDialog.show();%0A                    return;%0A                %7D%0A%0A                KeyPair keyPair = generateKeys();%0A
 %0A   
@@ -2678,41 +2678,10 @@
 ion 
-err) %7B%0A%0A        %7D%0A        catch (
+%7C 
 java
@@ -2718,41 +2718,10 @@
 ion 
-err) %7B%0A%0A        %7D%0A        catch (
+%7C 
 java
@@ -2772,16 +2772,62 @@
  err) %7B%0A
+            Log.e(%22KeyGen%22, err.getMessage());
 %0A       

Validate inputs in sign up activity