package com.nagazuka.mobile.android.goedkooptanken;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;

import com.nagazuka.mobile.android.goedkooptanken.R;

public class GoedkoopTankenActivity extends Activity {

	private GoedkoopTankenApp app;
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.main);
		
		app = (GoedkoopTankenApp) getApplication();
		
	    Spinner spinner = (Spinner) findViewById(R.id.spinner);
	    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
	            this, R.array.gastypes, android.R.layout.simple_spinner_item);
	    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
	    spinner.setAdapter(adapter);

		Button gpsButton = (Button) findViewById(R.id.gpsButton);
		gpsButton.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent switchIntent = new Intent(v.getContext(),
						PlacesTabActivity.class);
				Spinner spinner = (Spinner) findViewById(R.id.spinner);
				String fuelChoice = (String) spinner.getSelectedItem();
				app.setFuelChoice(fuelChoice);
				app.setPlaces(null);
				startActivityForResult(switchIntent, 0);
			}
		});
	}
}
@@ -106,16 +106,58 @@
 Intent;%0A
+import android.content.SharedPreferences;%0A
 import a
@@ -174,16 +174,16 @@
 Bundle;%0A
-
 import a
@@ -302,62 +302,8 @@
 r;%0A%0A
-import com.nagazuka.mobile.android.goedkooptanken.R;%0A%0A
 publ
@@ -352,16 +352,95 @@
 tivity %7B
+%0A%09public static final String PREFERENCE_FILENAME = %22GoedkoopTankenPreferences%22;
 %0A%0A%09priva
@@ -465,18 +465,17 @@
 pp app;%0A
-%09
 %0A
+
 %09/** Cal
@@ -651,19 +651,17 @@
 .main);%0A
-%09%09
 %0A
+
 %09%09app = 
@@ -702,16 +702,184 @@
 ();%0A
+%0A
 %09%09
-%0A%09    
+// Restore preferences%0A%09%09SharedPreferences settings = getSharedPreferences(PREFERENCE_FILENAME,%0A%09%09%09%090);%0A%09%09String prefFuelChoice = settings.getString(%22fuelChoice%22, null);%0A%0A%09%09
 Spin
@@ -931,20 +931,17 @@
 nner);%0A%09
-    
+%09
 ArrayAda
@@ -1007,20 +1007,11 @@
 e(%0A%09
-            
+%09%09%09
 this
@@ -1074,19 +1074,21 @@
 );%0A%09
-    
+%09
 adapter
+%0A%09%09%09%09
 .set
@@ -1161,12 +1161,9 @@
 );%0A%09
-    
+%09
 spin
@@ -1188,16 +1188,143 @@
 pter);%0A%0A
+%09%09if (prefFuelChoice != null) %7B%0A%09%09%09int position = adapter.getPosition(prefFuelChoice);%0A%09%09%09spinner.setSelection(position);%0A%09%09%7D%0A%0A
 %09%09Button
@@ -1722,16 +1722,16 @@
 hoice);%0A
-
 %09%09%09%09app.
@@ -1747,16 +1747,359 @@
 (null);%0A
+%0A%09%09%09%09// We need an Editor object to make preference changes.%0A%09%09%09%09// All objects are from android.context.Context%0A%09%09%09%09SharedPreferences settings = getSharedPreferences(PREFERENCE_FILENAME, 0);%0A%09%09%09%09SharedPreferences.Editor editor = settings.edit();%0A%09%09%09%09editor.putString(%22fuelChoice%22, fuelChoice);%0A%0A%09%09%09%09// Commit the edits!%0A%09%09%09%09editor.commit();%0A%0A
 %09%09%09%09star

Store fuel choice in SharedPreferences