Ejemplo n.º 1
0
        public override void OnActivityCreated(Bundle savedInstanceState)
        {
            base.OnActivityCreated(savedInstanceState);

            // Triad libraries
            var majorTriads = new ChordLibrary();

            majorTriads.AddMajorTriads();
            var minorTriads = new ChordLibrary();

            minorTriads.AddMinorTriads();
            var augmentedTriads = new ChordLibrary();

            augmentedTriads.AddAugmentedTriads();
            var diminishedTriads = new ChordLibrary();

            diminishedTriads.AddDiminishedTriads();

            // Seventh libraries
            var majorSevenths = new ChordLibrary();

            majorSevenths.AddMajorSevenths();
            var minorSevenths = new ChordLibrary();

            minorSevenths.AddMinorSevenths();
            var dominantSevenths = new ChordLibrary();

            dominantSevenths.AddDominantSevenths();
            var halfDiminishedSevenths = new ChordLibrary();

            halfDiminishedSevenths.AddHalfDiminishedSevenths();
            var fullyDiminishedSevenths = new ChordLibrary();

            fullyDiminishedSevenths.AddFullyDiminishedSevenths();


            // set up the spinner
            var spinner = this.Activity.FindViewById <Spinner>(Resource.Id.rootSpinner);
            var adapter = ArrayAdapter <String> .CreateFromResource(this.Activity, Resource.Array.roots, Android.Resource.Layout.SimpleSpinnerItem);

            adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
            spinner.Adapter = adapter;

            spinner.ItemSelected += (object sender, AdapterView.ItemSelectedEventArgs e) =>
            {
                spinner      = (Spinner)sender;
                selectedRoot = (string)spinner.GetItemAtPosition(e.Position);
            };


            // toggle buttons to show either triads or sevenths radio groups
            var showTriadsButton   = this.Activity.FindViewById <Button>(Resource.Id.showTriadsButton);
            var showSeventhsButton = this.Activity.FindViewById <Button>(Resource.Id.showSeventhsButton);
            var triadsRadioGroup   = this.Activity.FindViewById <RadioGroup>(Resource.Id.triadsRadioGroup);
            var seventhsRadioGroup = this.Activity.FindViewById <RadioGroup>(Resource.Id.seventhsRadioGroup);


            showTriadsButton.Click += (object sender, EventArgs e) =>
            {
                triadsRadioGroup.Visibility   = ViewStates.Visible;
                seventhsRadioGroup.Visibility = ViewStates.Invisible;
            };


            showSeventhsButton.Click += (object sender, EventArgs e) =>
            {
                seventhsRadioGroup.Visibility = ViewStates.Visible;
                triadsRadioGroup.Visibility   = ViewStates.Invisible;
            };


            // set up the show spelling button
            var showSpellingButton    = this.Activity.FindViewById <Button>(Resource.Id.showSpellingButton);
            var chordNameTextView     = this.Activity.FindViewById <TextView>(Resource.Id.chordNameTextView);
            var chordSpellingTextView = this.Activity.FindViewById <TextView>(Resource.Id.chordSpellingTextView);


            showSpellingButton.Click += (object sender, EventArgs e) =>
            {
                // set the chordToSpell based on which radio group is visible (triads/sevenths), and which radio button is checked
                if (triadsRadioGroup.Visibility == ViewStates.Visible)
                {
                    switch (triadsRadioGroup.CheckedRadioButtonId)
                    {
                    case Resource.Id.majorTriadRadioButton:
                        chordToSpell = majorTriads.SpellChord(selectedRoot);
                        break;

                    case Resource.Id.minorTriadRadioButton:
                        chordToSpell = minorTriads.SpellChord(selectedRoot);
                        break;

                    case Resource.Id.augmentedTriadRadioButton:
                        chordToSpell = augmentedTriads.SpellChord(selectedRoot);
                        break;

                    case Resource.Id.diminishedTriadRadioButton:
                        chordToSpell = diminishedTriads.SpellChord(selectedRoot);
                        break;
                    }
                }
                else // seventhsRadioGroup is visible
                {
                    switch (seventhsRadioGroup.CheckedRadioButtonId)
                    {
                    case (Resource.Id.major7RadioButton):
                        chordToSpell = majorSevenths.SpellChord(selectedRoot);
                        break;

                    case (Resource.Id.minor7RadioButton):
                        chordToSpell = minorSevenths.SpellChord(selectedRoot);
                        break;

                    case (Resource.Id.dominant7RadioButton):
                        chordToSpell = dominantSevenths.SpellChord(selectedRoot);
                        break;

                    case (Resource.Id.halfDim7RadioButton):
                        chordToSpell = halfDiminishedSevenths.SpellChord(selectedRoot);
                        break;

                    case (Resource.Id.fullyDim7RadioButton):
                        chordToSpell = fullyDiminishedSevenths.SpellChord(selectedRoot);
                        break;
                    }
                }

                chordNameTextView.Text     = chordToSpell.Key;
                chordSpellingTextView.Text = chordToSpell.Value;
            };
        }
Ejemplo n.º 2
0
        public override void OnActivityCreated(Bundle savedInstanceState)
        {
            base.OnActivityCreated(savedInstanceState);

            ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this.Activity);

            chordLib = new ChordLibrary();
            // Include specific triads/sevenths based on preferences (all included by default)
            if (prefs.GetBoolean("select_major_triads", true))
            {
                chordLib.AddMajorTriads();
            }
            if (prefs.GetBoolean("select_minor_triads", true))
            {
                chordLib.AddMinorTriads();
            }
            if (prefs.GetBoolean("select_augmented_triads", true))
            {
                chordLib.AddAugmentedTriads();
            }
            if (prefs.GetBoolean("select_diminished_triads", true))
            {
                chordLib.AddDiminishedTriads();
            }
            if (prefs.GetBoolean("select_major_sevenths", true))
            {
                chordLib.AddMajorSevenths();
            }
            if (prefs.GetBoolean("select_minor_sevenths", true))
            {
                chordLib.AddMinorSevenths();
            }
            if (prefs.GetBoolean("select_dominant_sevenths", true))
            {
                chordLib.AddDominantSevenths();
            }
            if (prefs.GetBoolean("select_half_diminished_sevenths", true))
            {
                chordLib.AddHalfDiminishedSevenths();
            }
            if (prefs.GetBoolean("select_fully_diminished_sevenths", true))
            {
                chordLib.AddFullyDiminishedSevenths();
            }


            var newChordButton      = this.Activity.FindViewById <Button>(Resource.Id.newChordButton);
            var checkSpellingButton = this.Activity.FindViewById <Button>(Resource.Id.checkSpellingButton);
            var tryAgainButton      = this.Activity.FindViewById <Button>(Resource.Id.tryAgainButton);
            var showAnswerButton    = this.Activity.FindViewById <Button>(Resource.Id.showAnswerButton);

            var newChordTextView = this.Activity.FindViewById <TextView>(Resource.Id.newChordTextView);

            spellingTextView = this.Activity.FindViewById <TextView>(Resource.Id.spellingTextView);
            var resultTextView = this.Activity.FindViewById <TextView>(Resource.Id.resultTextView);


            var cButton = this.Activity.FindViewById <Button>(Resource.Id.cButton);
            var dButton = this.Activity.FindViewById <Button>(Resource.Id.dButton);
            var eButton = this.Activity.FindViewById <Button>(Resource.Id.eButton);
            var fButton = this.Activity.FindViewById <Button>(Resource.Id.fButton);
            var gButton = this.Activity.FindViewById <Button>(Resource.Id.gButton);
            var aButton = this.Activity.FindViewById <Button>(Resource.Id.aButton);
            var bButton = this.Activity.FindViewById <Button>(Resource.Id.bButton);

            cButton.Click += noteButton_Click;
            dButton.Click += noteButton_Click;
            eButton.Click += noteButton_Click;
            fButton.Click += noteButton_Click;
            gButton.Click += noteButton_Click;
            aButton.Click += noteButton_Click;
            bButton.Click += noteButton_Click;

            var sharpButton = this.Activity.FindViewById <Button>(Resource.Id.sharpButton);
            var flatButton  = this.Activity.FindViewById <Button>(Resource.Id.flatButton);

            sharpButton.Click += accidentalButton_Click;
            flatButton.Click  += accidentalButton_Click;

            newChordButton.Click += (sender, e) =>
            {
                chordLib.GetRandomChord();
                newChordTextView.Text = chordLib.ChordName;
                // reset for next chord
                spellingTextView.Text = "";
                resultTextView.Text   = "";
                userSpelling          = "";
                numClicks             = 0;
            };

            checkSpellingButton.Click += (sender, e) =>
            {
                bool result = chordLib.CheckChordSpelling(userSpelling, chordLib.ChordSpelling);
                if (result)
                {
                    resultTextView.Text = "CORRECT!";
                }
                else
                {
                    resultTextView.Text = "INCORRECT";
                }
            };

            tryAgainButton.Click += (sender, e) =>
            {
                userSpelling          = "";
                spellingTextView.Text = userSpelling;
                resultTextView.Text   = "";
                numClicks             = 0;
            };

            showAnswerButton.Click += (sender, e) =>
            {
                resultTextView.Text = chordLib.ChordSpelling;
            };

            // Quick-and-easy EXCEPTION HANDLING (as opposed to disabling/enabling all those buttons)
            // Set a default C major chord to prevent exceptions when note or accidental buttons are clicked
            // (the checkSpelling, tryAgain, showAnswer buttons don't throw an exception)
            chordLib.ChordName     = "C major";
            chordLib.ChordSpelling = "C-E-G";
        }