/* * File: accumulated_cells.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 android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; import android.net.Uri; import android.widget.ImageView; import android.widget.RelativeLayout; /** * Defines a accumulated_cells and its attributes. * * @author Eduardo Ferrer * @version 1.0 Jan, 2012 */ public class accumulated_cells { ImageView imagesVector[]; ImageView imagesVectorLandscape[]; public String soundsVector[]; int length=0; RelativeLayout accumulatedCells; RelativeLayout accumulatedCellsLandscape; int maxLength; /** * Creates a new accumulated_cells. * @param lay The relative layout lay of the accumulated cells for the portrait orientation * @param layLandscape The relative layout layLandscape of the accumulated cells for the landscape orientation */ accumulated_cells(RelativeLayout lay,RelativeLayout layLandscape){ maxLength=TICO.res.getInteger(R.integer.accumulated_cells_length);//por config.xml imagesVector=new ImageView[maxLength]; imagesVectorLandscape=new ImageView[maxLength]; soundsVector=new String[maxLength]; accumulatedCells=lay; accumulatedCellsLandscape=layLandscape; } /** * Delete the last cell added (if there is) in accumulated_cells. */ public void deleteCell(){ if(length>0){ length--; accumulatedCells.removeView(imagesVector[length]); accumulatedCellsLandscape.removeView(imagesVectorLandscape[length]); imagesVector[length]=null; soundsVector[length]=null; } } /** * Delete all the cells added in accumulated_cells. */ public void deleteAllCells(){ accumulatedCells.removeAllViews(); accumulatedCellsLandscape.removeAllViews(); for(int i=0;iaccumulated_cells. * @param root The URL root of the folder with the sounds of the project */ /* public void play_sentence(String root){ // TODO Auto-generated method stub //reproduccion de sonido MediaPlayer mp=new MediaPlayer(); for(int i=0;isize){ h=size; w=bm.getWidth()*size/bm.getHeight(); }*/ }else{ // Log.d("control"," bitmap ancho " + bm.getWidth()+" bitmap alto "+bm.getHeight() ); if(bm.getWidth()>size){ bm=Bitmap.createScaledBitmap(bm, size, bm.getHeight()*size/bm.getWidth(), true); //Log.d("control","reducimos por ancho "+" bitmap ancho " + bm.getWidth()+" bitmap alto "+bm.getHeight()); //image.setImageBitmap(bm); } if(bm.getHeight()>size){ bm=Bitmap.createScaledBitmap(bm, bm.getWidth() * size/bm.getHeight(), size, true); //Log.d("control","reducimos por alto "); //image.setImageBitmap(bm); } imagesVector[length].setImageBitmap(bm); /*RelativeLayout.LayoutParams pimage = new RelativeLayout.LayoutParams(bm.getWidth()-2*marcoSize,bm.getHeight()-2*marcoSize); image.setLayoutParams(pimage);*/ } } /*FIN*/ }else{ imagesVector[length]=new ImageView(context); imagesVector[length].setBackgroundColor(Color.WHITE); } RelativeLayout.LayoutParams pimage = new RelativeLayout.LayoutParams(96*accumulatedCells.getLayoutParams().height/100, 96*accumulatedCells.getLayoutParams().height/100); int marginLeft=((length)*96)* accumulatedCells.getLayoutParams().height / 100 + TICO.res.getInteger(R.integer.image_margin_accumulated_cells_portrait) *length; int marginTop=2* accumulatedCells.getLayoutParams().height/100; pimage.setMargins(marginLeft, marginTop,0, 0); imagesVector[length].setLayoutParams(pimage); accumulatedCells.addView(imagesVector[length]); //} soundsVector[length]=cellView.getSound(); //anyadimos la imagen tambien al layout Landscape if(imageName!=null && !imageName.equals("")){ /*Uri uriImage=Uri.parse(imageName); System.gc(); imagesVectorLandscape[length]=new ImageView(context); imagesVectorLandscape[length].setImageURI(uriImage);*/ System.gc(); imagesVectorLandscape[length]=new ImageView(context); /*Uri uriImage=Uri.parse(imageName); imagesVector[length].setImageURI(uriImage);*/ /*PRINCIPIO*/ /*prueba reducir tamanyo*/ Bitmap bm=null; bm=BitmapFactory.decodeFile(imageName); int size=98*accumulatedCellsLandscape.getLayoutParams().height/100; if(bm!=null){ if(bm.getHeight()<=size && bm.getWidth()<=size){ Uri uriImage=Uri.parse(imageName); imagesVectorLandscape[length].setImageURI(uriImage); /*int w,h; w=size; h=bm.getHeight()*size/bm.getWidth(); if(h>size){ h=size; w=bm.getWidth()*size/bm.getHeight(); }*/ }else{ // Log.d("control"," bitmap ancho " + bm.getWidth()+" bitmap alto "+bm.getHeight() ); if(bm.getWidth()>size){ bm=Bitmap.createScaledBitmap(bm, size, bm.getHeight()*size/bm.getWidth(), true); //Log.d("control","reducimos por ancho "+" bitmap ancho " + bm.getWidth()+" bitmap alto "+bm.getHeight()); } if(bm.getHeight()>size){ bm=Bitmap.createScaledBitmap(bm, bm.getWidth() * size/bm.getHeight(), size, true); //Log.d("control","reducimos por alto "); } imagesVectorLandscape[length].setImageBitmap(bm); } } /*FIN*/ }else{ imagesVectorLandscape[length]=new ImageView(context); imagesVectorLandscape[length].setBackgroundColor(Color.WHITE); } RelativeLayout.LayoutParams pimageLandscape = new RelativeLayout.LayoutParams(98*accumulatedCellsLandscape.getLayoutParams().height/100, 98*accumulatedCellsLandscape.getLayoutParams().height/100); int marginLeftLandscape=((length)*98)* accumulatedCellsLandscape.getLayoutParams().height / 100 +TICO.res.getInteger(R.integer.image_margin_accumulated_cell_landscape)*length; int marginTopLandscape=1* accumulatedCellsLandscape.getLayoutParams().height/100; pimageLandscape.setMargins(marginLeftLandscape, marginTopLandscape,0, 0); imagesVectorLandscape[length].setLayoutParams(pimageLandscape); accumulatedCellsLandscape.addView(imagesVectorLandscape[length]); //} //Incrementamos en 1 las celdas acumuladas length++; } public int getLength(){ return length; } }