package com.example.theviper;

import android.app.ListActivity;
import android.content.Context;
import android.content.SharedPreferences;
import android.media.MediaPlayer;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;
import android.widget.Toast;

public class Puntuaciones extends ListActivity
{
    private MediaPlayer mp;
    SharedPreferences pref;
    @Override public void onCreate (Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.puntuaciones);
        setListAdapter(new MiAdaptador(this,
                MainActivity.almacen.listaPuntuaciones(50)));
        mp = MediaPlayer.create(this, R.raw.sonido_picadura_cobra);
    }

    @Override protected void onListItemClick(ListView listView,
                                             View view, int position, long id)
    {
        super.onListItemClick(listView, view, position, id);
        Object o = getListAdapter().getItem(position);
        Toast.makeText(this, "Selección: " + Integer.toString(position)
                + " - " + o.toString(), Toast.LENGTH_LONG).show();
    }

    @Override
    protected void onResume() {
        super.onResume();
        pref = PreferenceManager.getDefaultSharedPreferences(this);
        if (pref.getBoolean("musica",true))
            mp.start();
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (pref.getBoolean("musica",true))
            mp.pause();
    }
}