package app.brest.testmin3d;


import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.support.v7.app.ActionBar;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.preference.RingtonePreference;
import android.text.TextUtils;
import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.ToggleButton;

import java.util.List;

import app.brest.utils.Settings;
import app.brest.utils.app.brest.game.Game;

/**
 * A {@link PreferenceActivity} that presents a set of application settings. On
 * handset devices, settings are presented as a single list. On tablets,
 * settings are split by category, with category headers shown to the left of
 * the list of settings.
 * <p/>
 * See <a href="http://developer.android.com/design/patterns/settings.html">
 * Android Design: Settings</a> for design guidelines and the <a
 * href="http://developer.android.com/guide/topics/ui/settings.html">Settings
 * API Guide</a> for more information on developing a Settings UI.
 */
public class SettingsActivity extends Activity {

    protected Game         mGame;
    protected LinearLayout mRoot;
    protected ToggleButton mAccelerometer;
    protected ToggleButton mGPS;
    protected ToggleButton mPlaces;
    protected ToggleButton mAreas;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings);

        mGame = (Game) getIntent().getSerializableExtra("game");

        mAccelerometer = new ToggleButton(this);
        mGPS = new ToggleButton(this);
        mPlaces=new ToggleButton(this);
        mAreas=new ToggleButton(this);
        mRoot = (LinearLayout)findViewById(R.id.root_layout);
        addOptionBool("Données acceleromètre", mAccelerometer);
        addOptionBool("Données GPS", mGPS);
        addOptionBool("Distance Resources", mAreas);
        addOptionBool("Resources affichés", mPlaces);
        preset();
    }



    public void onClick(View v)
    {
        setResults();
        finish();
    }

    public void addOptionBool(String name, ToggleButton v)
    {
        LinearLayout ll = new LinearLayout(this);
        TextView tv = new TextView(this);
        tv.setText(name);
        //tv.setBackgroundColor(0);
        //tv.setTextSize(20);
        //tv.setTextColor(0x33b5e5);

        ll.setOrientation(LinearLayout.HORIZONTAL);
        //v.setBackgroundColor(0);
        ll.addView(tv);
        ll.addView(v);
        mRoot.addView(ll);

    }




    private void setResults()
    {
        mGame.getmSettings().setAccelerometerDebug(mAccelerometer.isChecked());
        mGame.getmSettings().setAreaDebug(mAreas.isChecked());
        mGame.getmSettings().setGPSDebug(mGPS.isChecked());
        mGame.getmSettings().setResourceDebug(mPlaces.isChecked());
    }

    private void preset()
    {
        mAccelerometer.setChecked(mGame.getmSettings().isAccelerometerDebug());
        mAreas.setChecked(mGame.getmSettings().isAreaDebug());
        mGPS.setChecked(mGame.getmSettings().isGPSDebug());
        mPlaces.setChecked(mGame.getmSettings().isResourceDebug());
    }

}
