package gr.mybook.mypreferences;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity {
EditText etxt;
Button btn;
SharedPreferences prefs;
String fileName = "myPrefs";

private static final String KEY_1="fontsize";
private static final String KEY_2="textfield";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		etxt=(EditText)findViewById(R.id.text1);
		btn=(Button)findViewById(R.id.btn1);
	}
	
	public void save(View v) {
		// create preferences object
		prefs=getSharedPreferences(fileName,MODE_PRIVATE);
		// open preferences editor
		SharedPreferences.Editor editor = prefs.edit();
		// save data
		editor.putFloat(KEY_1, etxt.getTextSize());
		editor.putString(KEY_2, etxt.getText().toString());
		editor.commit();
		// start new activity
		Intent intent = new Intent(this, MyPreferences.class);
		startActivity(intent);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
}
