/* * File: fileDialog.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: Nov, 2011 * * Company: Universidad de Zaragoza, CPS, DIIS * * 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 android.TICO; import java.io.File; import java.io.IOException; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.TransformerException; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.Color; import android.media.AudioManager; import android.os.Bundle; import android.os.Environment; import android.util.DisplayMetrics; import android.view.Display; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup.LayoutParams; import android.view.WindowManager; import android.widget.Button; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.Toast; import android.widget.ScrollView; import android.widget.TextView; import configuration.TSetup; /** * Defines the fileDialog activity, where we * can explore and open the Tico projects located in * the Android device memory * @author Eduardo Ferrer * @version 1.0 Nov, 2011 */ public class fileDialog extends Activity{ private float SIZE;//=22.0f; File baseDir; File file; RelativeLayout marco; Button abrir; ScrollView scroll; // ScrollView scrollLandscape; LinearLayout botones; Display display; DisplayMetrics metrics=new DisplayMetrics(); LinearLayout layoutFicheros; Resources res; /** * Change the orientation of fileDialog * when the orientation of the device changes. */ @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); } @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); //configurar los botones fisicos de sonido al audio multimedia this.setVolumeControlStream(AudioManager.STREAM_MUSIC); res = getResources(); SIZE=Float.parseFloat(res.getString(R.string.text_size_default)); String InterpreterHomeURL=TSetup.getInterpreterHome(); if(InterpreterHomeURL.length()>0){ baseDir=new File(InterpreterHomeURL); } if(baseDir==null || !baseDir.exists() || !baseDir.canRead()){ if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){ baseDir=Environment.getExternalStorageDirectory(); }else{ baseDir=Environment.getRootDirectory(); } } marco=new RelativeLayout(this); gestor(); } /** * Manage the working of fileDialog * for select a .tcoa file in the Android device memory */ public void gestor(){ file=null; marco.removeAllViews(); layoutFicheros=new LinearLayout(this); layoutFicheros.setOrientation(LinearLayout.VERTICAL); scroll=new ScrollView(this); // scrollLandscape=new ScrollView(this); display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); display.getMetrics(metrics); ScrollView.LayoutParams panelSize; panelSize=new ScrollView.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT); scroll.setLayoutParams(panelSize); layoutFicheros.setVerticalScrollBarEnabled(true); layoutFicheros.computeScroll(); final File ficheros[]=baseDir.listFiles(); Quicksort(ficheros,0,ficheros.length-1); LinearLayout layoutDirectorioAtras=new LinearLayout(this); layoutDirectorioAtras.setOrientation(LinearLayout.HORIZONTAL); ImageView carpetaAtras=new ImageView(this); carpetaAtras.setImageResource(R.drawable.carpeta); LinearLayout.LayoutParams pcarpetaAtras = new LinearLayout.LayoutParams(2*(int)(SIZE/metrics.scaledDensity),2*(int)(SIZE/metrics.scaledDensity)); pcarpetaAtras.setMargins(0, 2, 0, 2); carpetaAtras.setLayoutParams(pcarpetaAtras); layoutDirectorioAtras.addView(carpetaAtras); TextView atras=new TextView(this); atras.setTextSize(SIZE/metrics.scaledDensity); final String rutaAtras=baseDir.getParent(); atras.setText(" .."); layoutDirectorioAtras.addView(atras); layoutFicheros.addView(layoutDirectorioAtras); layoutDirectorioAtras.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub if(rutaAtras!=null){ baseDir=new File(rutaAtras); gestor(); } } }); layoutDirectorioAtras.setFocusable(true); layoutDirectorioAtras.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { // TODO Auto-generated method stub if(hasFocus){ abrir.setEnabled(false); v.setBackgroundColor(Color.RED); }else{ v.setBackgroundColor(Color.TRANSPARENT); } } }); //separador LinearLayout separadorLayout=new LinearLayout(this); LinearLayout.LayoutParams pseparadorLayout=new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,2); separadorLayout.setLayoutParams(pseparadorLayout); separadorLayout.setBackgroundColor(Color.WHITE); layoutFicheros.addView(separadorLayout); //mostramos las carpetas for(int i=0;i