package com.harmoneye.tonecircle;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;

import com.harmoneye.tonecircle.ToneCircleView.OnTonesChangedListener;

public class MainActivity extends Activity {

	private static final String ACTIVE_TONES = "active_tones";

	private PitchClassSetNamer namer;
	private ToneCircleView toneCircleView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		namer = PitchClassSetNamer.fromJson(getResources()
			.openRawResource(R.raw.chord_names));

		final TextView titleView = (TextView) findViewById(R.id.title);
		toneCircleView = (ToneCircleView) findViewById(R.id.toneCircle);

		toneCircleView.setOnTonesChangedListener(new OnTonesChangedListener() {
			@Override
			public void onTonesChanged(PitchClassSet activeTones) {
				titleView.setText(namer.getName(activeTones));
			}
		});
	}

	@Override
	protected void onResume() {
		SharedPreferences prefs = getPreferences(MODE_PRIVATE);
		int activeTones = prefs.getInt(ACTIVE_TONES, 0);
		if (activeTones > 0) {
			toneCircleView.setActiveTones(PitchClassSet.fromIndex(activeTones));
		}
		super.onResume();
	}

	@Override
	protected void onPause() {
		int activeTones = toneCircleView.getActiveTones().getIndex();
		SharedPreferences prefs = getPreferences(MODE_PRIVATE);
		SharedPreferences.Editor editor = prefs.edit();
		editor.putInt(ACTIVE_TONES, activeTones);
		editor.commit();
		super.onPause();
	}

	@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;
	}

}

@@ -363,16 +363,107 @@
 ones%22;%0A%0A
+%09private static final int DEFAULT_TONE_SET = PitchClassSet.fromArray(0, 4, 7).getIndex();%0A%0A
 %09private
@@ -1266,38 +1266,27 @@
 ES, 
-0);%0A%09%09if (activeTones %3E 0) %7B%0A%09
+DEFAULT_TONE_SET);%0A
 %09%09to
@@ -1352,20 +1352,16 @@
 ones));%0A
-%09%09%7D%0A
 %09%09super.

Set default chord as non-empty.