package com.example.android.androidsimulator;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class AddContactsActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_contacts);
    }
}

@@ -59,299 +59,2290 @@
 oid.
-support.v7.app.AppCompatActivity;%0Aimport android.os.Bundle;%0A%0Apublic class AddContactsActivity extends AppCompatActivity %7B%0A%0A    @Override%0A    protected void onCreate(Bundle savedInstanceState) %7B%0A        super.onCreate(savedInstanceState);%0A        setContentView(R.layout.activity_add_contacts
+content.SharedPreferences;%0Aimport android.preference.PreferenceManager;%0Aimport android.support.v7.app.AppCompatActivity;%0Aimport android.os.Bundle;%0Aimport android.view.View;%0Aimport android.widget.Button;%0Aimport android.widget.EditText;%0Aimport android.widget.Toast;%0A%0Apublic class AddContactsActivity extends AppCompatActivity %7B%0A%0A    Toast toast;%0A    SharedPreferences preferences;%0A    SharedPreferences.Editor editor;%0A    EditText nameContact;%0A    EditText numberContact;%0A    Button buttonAddContact;%0A%0A    @Override%0A    protected void onCreate(Bundle savedInstanceState) %7B%0A        super.onCreate(savedInstanceState);%0A        setContentView(R.layout.activity_add_contacts);%0A%0A        nameContact = (EditText) findViewById(R.id.nameContact_editText);%0A        numberContact = (EditText) findViewById(R.id.numberContact_editText);%0A        buttonAddContact = (Button) findViewById(R.id.addContact_button);%0A%0A        buttonAddContact.setOnClickListener(new View.OnClickListener() %7B%0A            @Override%0A            public void onClick(View v) %7B%0A                addContact();%0A            %7D%0A        %7D);%0A    %7D%0A%0A    private void addContact() %7B%0A        // SharedPreferences to save data on internal storage%0A        preferences = PreferenceManager.getDefaultSharedPreferences(this);%0A        editor = preferences.edit();%0A%0A        int totalContacts = preferences.getInt(%22totalContacts%22, 0);%0A%0A        CharSequence validationMessage;%0A        String name = String.valueOf(nameContact.getText());%0A        String number = String.valueOf(numberContact.getText());%0A%0A        // validation of contact%0A        if (name.isEmpty()) %7B%0A            validationMessage = %22You need to insert a name%22;%0A        %7D%0A        else if (number.isEmpty()) %7B%0A            validationMessage = %22You need to insert a number%22;%0A        %7D%0A        else %7B%0A            validationMessage = %22Added contact%22;%0A            totalContacts += 1;%0A%0A            // add info of contact on internal storage%0A            editor.putInt(%22totalContacts%22, totalContacts);%0A            editor.putString(%22nameContact%22 + totalContacts, name);%0A            editor.putInt(%22numberContact%22 + totalContacts, Integer.valueOf(number));%0A            editor.apply();%0A        %7D%0A%0A       toast = Toast.makeText(this, validationMessage, Toast.LENGTH_SHORT);%0A       toast.show(
 );%0A 

Add contacts to internal storage