package com.joshuahou.survivalphrases;

import android.app.Activity;
import android.media.AudioManager;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.Spinner;

public class Main extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        setVolumeControlStream(AudioManager.STREAM_MUSIC);

        Spinner spinner = (Spinner) findViewById(R.id.spinner);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
                this, R.array.language_array, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);

        GridView gridview = (GridView) findViewById(R.id.gridview);
        int colWidth = getWindowManager().getDefaultDisplay().getWidth() / 3 * 85 / 100;
        gridview.setAdapter(new ImageAdapter(this, spinner, colWidth));
    }

    @Override
    protected void onResume() {
        PlayClip.resume();
        super.onResume();
    }

    @Override
    protected void onPause() {
        PlayClip.release();
        super.onPause();
    }
}

@@ -62,16 +62,58 @@
 tivity;%0A
+import android.content.SharedPreferences;%0A
 import a
@@ -165,16 +165,61 @@
 Bundle;%0A
+import android.preference.PreferenceManager;%0A
 import a
@@ -346,16 +346,88 @@
 tivity %7B
+%0A    private Spinner spinner;%0A    private SharedPreferences preferences;
 %0A%0A    /*
@@ -693,23 +693,91 @@
         
-Spinner
+preferences = PreferenceManager.getDefaultSharedPreferences(this);%0A%0A       
  spinner
@@ -1102,24 +1102,183 @@
 (adapter);%0A%0A
+        // set language selection to what's saved in shared preferences, defaults to English%0A        spinner.setSelection(preferences.getInt(%22position%22, 0));%0A%0A
         Grid
@@ -1710,11 +1710,281 @@
 );%0A    %7D
+%0A%0A    @Override%0A    protected void onDestroy() %7B%0A        // save language selection%0A        SharedPreferences.Editor editor = preferences.edit();%0A        editor.putInt(%22position%22, spinner.getSelectedItemPosition());%0A        editor.commit();%0A        super.onStop();%0A    %7D
 %0A%7D%0A

save language selection in preferences