package com.apigee.appservices.android_template;

import java.util.HashMap;
import java.util.Map;

//import org.springframework.http.HttpMethod;

import org.usergrid.android.client.Client;
import org.usergrid.android.client.callbacks.ApiResponseCallback;
//import org.usergrid.android.client.callbacks.ClientCallback;
import org.usergrid.android.client.response.ApiResponse;

import android.os.Bundle;
import android.app.Activity;
import android.widget.TextView;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    	setContentView(R.layout.activity_main);
    	final TextView text = (TextView) findViewById(R.id.mainActivityText);
    	
	/* 
	 	1. Set your account details

        - Enter your ORGNAME below — it’s the username you picked when you signed up at apigee.com
        - Keep the APPNAME as “sandbox”: it’s a context we automatically created for you.
          It’s completely open by default, but don’t worry, other apps you create are not!      */
    	
    	String ORGNAME = "YOUR APIGEE.COM USERNAME";
    	String APPNAME = "sandbox";
    	
    	Client client = new Client(ORGNAME+"/"+APPNAME).withApiUrl("https://api.usergrid.com");
   
    	
	/*
        2. Let’s save an object!

        Great, we know where your account is now!
        Let’s try to create a book in the system and output it on the page.
        
        - Keep the type as “book”
        - Enter some other attributes below.    */
    	
       	Map<String, Object> data = new HashMap<String, Object>();
    	data.put("type", "book");
    	data.put("title", "the old man and the sea");
    
    	
    /*
        3. Run the app!
        
        You’re good to go! If you’re in Eclipse, just Run the code to your preferred device or emulator.
        
        - In the menus, select Run > Run, or hit the green “play” button in your toolbar.
        - Make sure you’ve followed these steps to add a device to your environment: http://developer.android.com/tools/building/building-eclipse.html
        - If everything is working as expected, you will get a visual confirmation in the app!		*/
    	

    	client.createEntityAsync(data, new ApiResponseCallback() {
            @Override
            public void onException(Exception e) { // Error - the book was not saved properly
            	text.setText("Could not create the book.\n\nDid you enter your username correctly on line 32 of src/com/apigee/appservices/android_template/MainActivity.java ?");
            }

            @Override
            public void onResponse(ApiResponse response) { // Success - the book was created properly
            	try { 
	                if (response != null) { 
	                	// The saved object is returned in the “response” variable
	                	// defined on line 69. The code below outputs it on the page!
	                	String successMessage =	"Success! Here is the object we stored; "
	                						+   "notice the timestamps and unique id we created for you:\n\n"
	                						+ 	response.getEntities().get(0).toString();
	                	text.setText(successMessage);
	                }
            	} catch (Exception e) {
                	text.setText("Could not create the book.\n\nDid you enter your username correctly on line 32 of src/com/apigee/appservices/android_template/MainActivity.java ?");            		
            	}
            }
        });
    	
    	
    /*
        4. Congrats, you’re done!

        - You can try adding more properties after line 49 and reloading the app!
        - You can then see the admin view of this data by logging in at https://apigee.com/usergrid
        - Or you can go explore more advanced examples in our docs: http://apigee.com/docs/usergrid         */
    }
    
}



@@ -96,55 +96,8 @@
 p;%0A%0A
-//import org.springframework.http.HttpMethod;%0A%0A
 impo
@@ -205,71 +205,8 @@
 ck;%0A
-//import org.usergrid.android.client.callbacks.ClientCallback;%0A
 impo
@@ -1283,22 +1283,28 @@
 book
- in the system
+, save it on Apigee,
  and
@@ -1314,27 +1314,26 @@
 tput it 
-o
+i
 n the 
-page
+app
 .%0A      
@@ -1389,35 +1389,83 @@
 ter 
-some other attributes below
+the title of your favorite book below, instead of %E2%80%9Cthe old man and the sea%E2%80%9D
 .   
@@ -2409,34 +2409,34 @@
 rrectly on line 
-3
 2
+9
  of src/com/apig
@@ -2806,17 +2806,17 @@
 n line 6
-9
+6
 . The co
@@ -3304,10 +3304,10 @@
 ine 
-3
 2
+9
  of 
@@ -3539,17 +3539,17 @@
 r line 4
-9
+6
  and rel

Clean up and tighten language