/*
* File: TSetup.java
* This file is part of Tico, an application to create and perform
* interactive communication boards to be used by people with
* severe motor disabilities.
*
* Author: Eduardo Ferrer
*
* Date: Jan, 2012
*
* Company: Dept. of Computer Sciences and Systems Engineering, Universidad de Zaragoza, Spain
*
*
* License:
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
package configuration;
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import android.TICO.R;
import android.TICO.TICO;
import android.app.Activity;
import android.media.AudioManager;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
/**
* The class that defines and manage the activity of the settings menu and changes the configuration
*/
public class SetupScreen extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.configuracion);
//configurar los botones fisicos de sonido al audio multimedia
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
//ponemos los valores correctos de la barra de tiempos
TextView tiempoMin=(TextView) findViewById(R.id.textViewMinWaitTime);
TextView tiempoMax=(TextView) findViewById(R.id.textViewMaxWaitTime);
TextView tiempoMed=(TextView) findViewById(R.id.textViewMediumWaitTime);
tiempoMin.setText(""+TICO.res.getInteger(R.integer.barrido_espera_min_milisegundos)/1000.0);
tiempoMax.setText(""+TICO.res.getInteger(R.integer.barrido_espera_max_milisegundos)/1000.0);
tiempoMed.setText(""+(TICO.res.getInteger(R.integer.barrido_espera_min_milisegundos)+TICO.res.getInteger(R.integer.barrido_espera_max_milisegundos))/2000.0);
//posicion del texto
final RadioGroup posicionTexto=(RadioGroup) findViewById(R.id.posicionTexto);
RadioButton textoAbajo=(RadioButton) findViewById(R.id.down_text);
RadioButton textoArriba=(RadioButton) findViewById(R.id.up_text);
RadioButton textoNo=(RadioButton) findViewById(R.id.no_text);
if(TSetup.getCellTextPosition().equals("up")){
textoArriba.toggle();
}else if(TSetup.getCellTextPosition().equals("noText")){
textoNo.toggle();
}else{ //"down" or ""
textoAbajo.toggle();
}
posicionTexto.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
int opcion=posicionTexto.getCheckedRadioButtonId();
switch(opcion){
case R.id.down_text:
TSetup.setCellTextPosition("down");
break;
case R.id.up_text:
TSetup.setCellTextPosition("up");
break;
case R.id.no_text:
TSetup.setCellTextPosition("noText");
break;
}
try {
TSetup.save(getApplicationContext());
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TransformerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
//volumen
final SeekBar volumen= (SeekBar) findViewById(R.id.barraVolumen);
volumen.setMax(100);
volumen.setProgress((int)(TSetup.getVolume() * 100.0f));
volumen.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){
@Override
public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
// TODO Auto-generated method stub
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
TSetup.setVolume((float)(volumen.getProgress())/100.0f);
try {
TSetup.save(getApplicationContext());
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TransformerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
//tipo de seleccion
final RadioGroup modoSeleccion=(RadioGroup) findViewById(R.id.modoSeleccion);
RadioButton seleccionDirecta=(RadioButton) findViewById(R.id.seleccionDirecta);
RadioButton barrido=(RadioButton) findViewById(R.id.barrido);
if(TSetup.getSelectionMode().equals("automatic")){
barrido.toggle();
}else{//direct
seleccionDirecta.toggle();
}
modoSeleccion.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
int opcion=modoSeleccion.getCheckedRadioButtonId();
switch(opcion){
case R.id.seleccionDirecta:
TSetup.setSelectionMode("direct");
break;
case R.id.barrido:
TSetup.setSelectionMode("automatic");
break;
}
try {
TSetup.save(getApplicationContext());
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TransformerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
//tiempo espera del cursor
final SeekBar waitTime= (SeekBar) findViewById(R.id.waitingTimeBar);
final EditText waitTimeText=(EditText) findViewById(R.id.waitingTimeText);
waitTimeText.setText(""+TSetup.getScanWaitTime()/1000.0f);
waitTime.setMax(TICO.res.getInteger(R.integer.barrido_num_divisiones));
final int minIntervalTime=((TICO.res.getInteger(R.integer.barrido_espera_max_milisegundos)
-TICO.res.getInteger(R.integer.barrido_espera_min_milisegundos))
/TICO.res.getInteger(R.integer.barrido_num_divisiones));
waitTime.setProgress((TSetup.getScanWaitTime()-TICO.res.getInteger(R.integer.barrido_espera_min_milisegundos))/minIntervalTime);
waitTime.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){
@Override
public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
// TODO Auto-generated method stub
waitTimeText.setText(""+(waitTime.getProgress()*minIntervalTime+TICO.res.getInteger(R.integer.barrido_espera_min_milisegundos))/1000.0f);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
TSetup.setScanWaitTime(waitTime.getProgress()*minIntervalTime + TICO.res.getInteger(R.integer.barrido_espera_min_milisegundos));
try {
TSetup.save(getApplicationContext());
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TransformerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
final Button minusButton= (Button) findViewById(R.id.wait_time_minus);
final Button plusButton=(Button) findViewById(R.id.wait_time_plus);
minusButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(waitTime.getProgress()>0){
waitTime.setProgress(waitTime.getProgress()-1);
//actualizamos la configuracion
TSetup.setScanWaitTime(waitTime.getProgress()*minIntervalTime + TICO.res.getInteger(R.integer.barrido_espera_min_milisegundos));
try {
TSetup.save(getApplicationContext());
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TransformerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
});
plusButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(waitTime.getProgress()