package com.aj.wagon.examples;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.aj.wagon.Crate;
import com.aj.wagon.R;
import com.aj.wagon.R.id;
import com.aj.wagon.Wagon;
import com.aj.wagon.WoodBox;

public class MainActivity extends Activity {

	// All fields in crates will be copied to
	// another instance in the next activity
	@Crate(key = "theCrate")
	public CrateExample crateExample = new CrateExample(new ArrayList<String>() {
		{
			add("listInsideCrate0");
			add("listInsideCrate1");
			add("listInsideCrate2");
		}
	}, "stringInsideCrate", 43, 77.5f, (long) 43214);

	@WoodBox(key = "theList")
	public ArrayList<String> lIST = new ArrayList<String>() {
		{
			add("dasds0");
			add("dasds1");
			add("dasds2");
			add("dasds3");
		}
	};

	@WoodBox(key = "theString")
	public String sTRING = "I'm a string";

	@WoodBox(key = "aValue")
	public String value = "default";

	private Button btnSave;
	private Button btnStartNext;
	private EditText etValue;
	private Wagon<MainActivity> wagon;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		((TextView) findViewById(id.tv_title)).setText("Main");
		btnSave = (Button) findViewById(id.btn_save_prefs);
		btnStartNext = (Button) findViewById(id.btn_start_next);
		btnSave.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				save();
			}
		});
		btnStartNext.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				startNextAcitivity();
			}
		});

		etValue = (EditText) findViewById(id.etValue);
		//
		wagon = new Wagon<MainActivity>(this.getClass(), this);
		load();
	}

	private void load() {
		String msg = "";
		if (wagon.unpack(getPreferences(MODE_PRIVATE))) {
			msg = "Loaded!";
		} else {
			msg = "Problem Loading!";
		}
		Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
		etValue.setText(value);
	}

	private void save() {
		String msg = "";
		if (wagon.pack(getPreferences(MODE_PRIVATE))) {
			msg = "Saved!";
		} else {
			msg = "Problem saving!";
		}
		Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
	}

	private void startNextAcitivity() {
		final Intent intent = new Intent(getApplicationContext(), OtherActivity.class);
		wagon.pack(intent);

		startActivity(intent);
		finish();
	}
}

@@ -29,37 +29,8 @@
 s;%0A%0A
-import java.util.ArrayList;%0A%0A
 impo
@@ -307,35 +307,8 @@
 t;%0A%0A
-import com.aj.wagon.Crate;%0A
 impo
@@ -541,16 +541,19 @@
 tivity%0A%09
+// 
 @Crate(k
@@ -566,24 +566,27 @@
 theCrate%22)%0A%09
+// 
 public Crate
@@ -628,16 +628,20 @@
 mple(new
+%0A%09//
  ArrayLi
@@ -652,30 +652,33 @@
 tring%3E() %7B%0A%09
-%09%7B%0A%09%09%09
+// %7B%0A%09// 
 add(%22listIns
@@ -687,26 +687,27 @@
 eCrate0%22);%0A%09
-%09%09
+// 
 add(%22listIns
@@ -716,26 +716,27 @@
 eCrate1%22);%0A%09
-%09%09
+// 
 add(%22listIns
@@ -749,20 +749,25 @@
 te2%22);%0A%09
-%09%7D%0A%09
+// %7D%0A%09// 
 %7D, %22stri
@@ -808,18 +808,24 @@
 43214);%0A
-%0A
 %09
+//%0A%09// 
 @WoodBox
@@ -839,24 +839,27 @@
 %22theList%22)%0A%09
+// 
 public Array
@@ -909,14 +909,17 @@
  %7B%0A%09
-%09%7B%0A%09%09%09
+// %7B%0A%09// 
 add(
@@ -926,26 +926,27 @@
 %22dasds0%22);%0A%09
-%09%09
+// 
 add(%22dasds1%22
@@ -945,26 +945,27 @@
 %22dasds1%22);%0A%09
-%09%09
+// 
 add(%22dasds2%22
@@ -968,18 +968,19 @@
 ds2%22);%0A%09
-%09%09
+// 
 add(%22das
@@ -991,17 +991,28 @@
 );%0A%09
-%09%7D%0A%09%7D;%0A%0A%09
+// %7D%0A%09// %7D;%0A%09//%0A%09// 
 @Woo
@@ -1032,24 +1032,27 @@
 heString%22)%0A%09
+// 
 public Strin
@@ -1129,20 +1129,8 @@
 alue
- = %22default%22
 ;%0A%0A%09
@@ -1350,16 +1350,37 @@
 State);%0A
+%09%09value = %22default%22;%0A
 %09%09setCon
@@ -1678,24 +1678,36 @@
 %09%09%09%09save();%0A
+%09%09%09%09load();%0A
 %09%09%09%7D%0A%09%09%7D);%0A%09
@@ -2237,32 +2237,72 @@
 tring msg = %22%22;%0A
+%09%09value = etValue.getText().toString();%0A
 %09%09if (wagon.pack

pref load works. need2fix return false