/*
 * Copyright (c) 2015 Justin White <jw@justinwhite.net>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 *
 * 3. Neither the name of the copyright holder nor the names of its
 * contributors may be used to endorse or promote products derived from this
 * software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 */

package net.justinwhite.score10;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.SeekBar;
import android.widget.TextView;
import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;


public class MainActivity extends Activity implements SeekBar.OnSeekBarChangeListener {
    static final String EXTRA_NUM_PLAYERS;
    static final int SEEKBAR_OFFSET;

    static int INITIAL_NUM_PLAYERS;
    static int MIN_NUM_PLAYERS;
    static int MAX_NUM_PLAYERS;

    static {
        EXTRA_NUM_PLAYERS = "net.justinwhite.score10.NUM_PLAYERS_MESSAGE";
        SEEKBAR_OFFSET = 2;
    }

    private int numPlayers;

    @InjectView(R.id.seekNumPlayers)
    protected SeekBar seekNumPlayers;
    @InjectView(R.id.labelNumPlayers)
    protected TextView labelNumPlayers;

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

        INITIAL_NUM_PLAYERS = this.getResources().getInteger(R.integer.initial_num_players);
        MIN_NUM_PLAYERS = this.getResources().getInteger(R.integer.min_num_players);
        MAX_NUM_PLAYERS = this.getResources().getInteger(R.integer.max_num_players);

        numPlayers = INITIAL_NUM_PLAYERS;

        seekNumPlayers.setProgress(numPlayers - SEEKBAR_OFFSET);
        seekNumPlayers.setMax(MAX_NUM_PLAYERS - SEEKBAR_OFFSET);
        seekNumPlayers.setOnSeekBarChangeListener(this);

        labelNumPlayers.setText(Integer.toString(numPlayers));
        labelNumPlayers.clearFocus();
    }

    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
        if (fromTouch) {
            numPlayers = progress + SEEKBAR_OFFSET;
            labelNumPlayers.setText(Integer.toString(numPlayers));
        }
    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {

    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {

    }

    @OnClick(R.id.buttonStartGame)
    protected void StartNewGame(View view) {
        Intent intent = new Intent(this, NewGameActivity.class);
        intent.putExtra(EXTRA_NUM_PLAYERS, numPlayers);
        startActivity(intent);
    }

}

@@ -1672,22 +1672,96 @@
 content.
-Intent
+Context;%0Aimport android.content.Intent;%0Aimport android.content.SharedPreferences
 ;%0Aimport
@@ -2847,37 +2847,32 @@
 N_NUM_PLAYERS = 
-this.
 getResources().g
@@ -2901,32 +2901,32 @@
 n_num_players);%0A
+
         MAX_NUM_
@@ -3034,24 +3034,177 @@
 M_PLAYERS;%0A%0A
+        SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE);%0A        numPlayers = sharedPref.getInt(%22CURRENT_NUM_PLAYERS%22, numPlayers);%0A%0A
         seek
@@ -3434,32 +3434,32 @@
 g(numPlayers));%0A
-
         labelNum
@@ -3479,32 +3479,334 @@
 Focus();%0A    %7D%0A%0A
+    @Override%0A    protected void onDestroy() %7B%0A        super.onDestroy();%0A%0A        SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE);%0A        SharedPreferences.Editor editor = sharedPref.edit();%0A        editor.putInt(%22CURRENT_NUM_PLAYERS%22, numPlayers);%0A        editor.apply();%0A    %7D%0A%0A
     @Override%0A  

Use key-values prefs to remember last player count.