Commit 9813ce4a by Pablo Molina

Merge branch 'issue/406' (#406) into develop

parents 0c3bc699 e753900f
...@@ -9,7 +9,7 @@ android { ...@@ -9,7 +9,7 @@ android {
buildToolsVersion "21.1.2" buildToolsVersion "21.1.2"
defaultConfig { defaultConfig {
applicationId "com.yottacode.pictogram" applicationId "com.yottacode.pictogram"
minSdkVersion 19 minSdkVersion 21
targetSdkVersion 21 targetSdkVersion 21
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
......
...@@ -35,7 +35,7 @@ import java.util.ArrayList; ...@@ -35,7 +35,7 @@ import java.util.ArrayList;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.LinkedList; import java.util.LinkedList;
public class PanelAdapter extends ArrayAdapter { public class PictoGridAdapter extends ArrayAdapter {
private LinkedList<Picto> lPictos; private LinkedList<Picto> lPictos;
int color; int color;
...@@ -45,7 +45,7 @@ public class PanelAdapter extends ArrayAdapter { ...@@ -45,7 +45,7 @@ public class PanelAdapter extends ArrayAdapter {
// String constant for logs // String constant for logs
private final String LOG_TAG = this.getClass().getSimpleName(); // Or .getCanonicalName() private final String LOG_TAG = this.getClass().getSimpleName(); // Or .getCanonicalName()
public PanelAdapter(LinkedList<Picto> ll){ public PictoGridAdapter(LinkedList<Picto> ll){
super(PCBcontext.getContext(), R.layout.list_item_img ,ll); super(PCBcontext.getContext(), R.layout.list_item_img ,ll);
//mContext = c; //mContext = c;
lPictos = ll; lPictos = ll;
...@@ -117,7 +117,7 @@ public class PanelAdapter extends ArrayAdapter { ...@@ -117,7 +117,7 @@ public class PanelAdapter extends ArrayAdapter {
/* /*
try{ try{
imageView.setBackgroundColor(lPictos.get(position).get_darkner_color()); imageView.setBackgroundColor(lPictos.get(position).get_darkner_color());
//Log.d("PanelAdapter", "Position: " + position); //Log.d("PictoGridAdapter", "Position: " + position);
} catch (java.lang.IllegalArgumentException e){ } catch (java.lang.IllegalArgumentException e){
e.printStackTrace(); e.printStackTrace();
//imageView.setBackgroundColor(PCBcontext.getContext().getResources().getColor(R.color.blue)); //imageView.setBackgroundColor(PCBcontext.getContext().getResources().getColor(R.color.blue));
......
...@@ -3,31 +3,31 @@ package com.yottacode.pictogram.gui; ...@@ -3,31 +3,31 @@ package com.yottacode.pictogram.gui;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Point;
import android.content.ClipData; import android.content.ClipData;
import android.content.ClipDescription; import android.content.ClipDescription;
import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.provider.Settings;
import android.speech.tts.TextToSpeech; import android.speech.tts.TextToSpeech;
import android.text.InputType; import android.text.InputType;
import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.view.Display;
import android.view.DragEvent; import android.view.DragEvent;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.Window; import android.view.Window;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.Interpolator;
import android.view.animation.TranslateAnimation;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.EditText; import android.widget.EditText;
...@@ -37,21 +37,15 @@ import android.widget.RelativeLayout; ...@@ -37,21 +37,15 @@ import android.widget.RelativeLayout;
import android.widget.Toast; import android.widget.Toast;
import com.yottacode.pictogram.R; import com.yottacode.pictogram.R;
import com.yottacode.pictogram.action.PictoAction;
import com.yottacode.pictogram.action.PictosAction; import com.yottacode.pictogram.action.PictosAction;
import com.yottacode.pictogram.action.TalkAction; import com.yottacode.pictogram.action.TalkAction;
import com.yottacode.pictogram.action.VocabularyAction;
import com.yottacode.pictogram.dao.Picto; import com.yottacode.pictogram.dao.Picto;
import com.yottacode.pictogram.dao.User;
import com.yottacode.pictogram.grammar.Vocabulary; import com.yottacode.pictogram.grammar.Vocabulary;
import com.yottacode.pictogram.grammar.iLocalPicto; import com.yottacode.pictogram.grammar.iLocalPicto;
import com.yottacode.pictogram.grammar.iVocabularyListener; import com.yottacode.pictogram.grammar.iVocabularyListener;
import com.yottacode.pictogram.net.PictoUploader; import com.yottacode.pictogram.net.PictoUploader;
import com.yottacode.pictogram.net.iImgDownloaderListener;
import com.yottacode.pictogram.tools.Img;
import com.yottacode.pictogram.tools.PCBcontext; import com.yottacode.pictogram.tools.PCBcontext;
import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.IOException; import java.io.IOException;
...@@ -60,31 +54,44 @@ import java.util.Arrays; ...@@ -60,31 +54,44 @@ import java.util.Arrays;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Vector;
import android.provider.Settings.Secure;
public class PictogramActivity extends Activity implements iVocabularyListener, TextToSpeech.OnInitListener { public class PictogramActivity extends Activity implements iVocabularyListener, TextToSpeech.OnInitListener {
PanelAdapter panelAdapter; // Main layout for this activity
RelativeLayout mainLayout;
// Adapter for de grid showing the categories grid (and main pictos)
PictoGridAdapter pictoCategoriesGridAdapter;
// Grid showing the categories grid (and main pictos)
GridView pictoCategoriesGridView;
// Adapter for the grid showing pictos from a category (initially hidden)
PictoGridAdapter pictoGridAdapter;
// Grid showing pictos from a category (initially hidden)
GridView pictoGridView;
// Adapter for the tape view (list of pictos to send to the server)
TapeAdapter tapeAdapter; TapeAdapter tapeAdapter;
// Tape view (list of pictos to send to the server)
GridView tapeGridView;
// Current picto category, if not null the corresponding category grid will be shown
Picto currentCategory; Picto currentCategory;
// Object used for reading text
TextToSpeech tts; TextToSpeech tts;
// Element used for loading new pictos (while changing categories)
Vocabulary vocabulary;
// TODO describe this variable
static final int SELECT_PICTURE = 1; static final int SELECT_PICTURE = 1;
// For disabling volume button (See method at the end of the class) // For disabling volume button (See method at the end of the class)
private final List blockedKeys = new ArrayList(Arrays.asList(KeyEvent.KEYCODE_VOLUME_DOWN, KeyEvent.KEYCODE_VOLUME_UP)); private final List blockedKeys = new ArrayList(Arrays.asList(KeyEvent.KEYCODE_VOLUME_DOWN, KeyEvent.KEYCODE_VOLUME_UP));
// String constant for logs // String constant for logs
private final String LOG_TAG = this.getClass().getSimpleName(); // Or .getCanonicalName() private final String LOG_TAG = this.getClass().getSimpleName(); // Or .getCanonicalName()
// Count for delete long press (hidden exit)
private int count_deletelong = 0; private int count_deletelong = 0;
// Animation for hidding the picto category view
Animation hidePictoCategoryViewAnimation;
// Animation for showing the picto category view
Animation showPictoCategoryViewAnimation;
// Button used for showing the picto category view
ImageButton showPictoCategoriesViewButton;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -94,391 +101,180 @@ public class PictogramActivity extends Activity implements iVocabularyListener, ...@@ -94,391 +101,180 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
Intent intent = getIntent(); Intent intent = getIntent();
currentCategory = null; // this for refresh vocabulary when a websocket action arrived from the dashboard this.mainLayout = (RelativeLayout) findViewById(R.id.pictogramLayout);
this.currentCategory = null;
this.count_deletelong = 0;
count_deletelong = 0; this.vocabulary = PCBcontext.getVocabulary();
this.vocabulary.listen(PCBcontext.getRoom(), this);
if (this.vocabulary != null && this.vocabulary.size() > 0) {
// Adapter for grid
panelAdapter = new PanelAdapter(new LinkedList<Picto>());
Vocabulary vocabulary = PCBcontext.getVocabulary();
if (vocabulary != null && vocabulary.size() > 0) {
Log.d(LOG_TAG, "Vocabulario correcto de tam:" + vocabulary.size()); Log.d(LOG_TAG, "Vocabulario correcto de tam:" + vocabulary.size());
LinkedList<Picto> ll;
if (currentCategory != null) ll = order(vocabulary.next(currentCategory));
else ll = order(vocabulary.startSentence());
panelAdapter.clear();
panelAdapter.addAll(ll);
} }
// Open websocket connection
vocabulary.listen(PCBcontext.getRoom(), this);
// Connect the views
final GridView tapeGridView = (GridView) findViewById(R.id.tape_grid_view);
// Cojo el tamaño de la pantalla para poner el ancho dinámico
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
tapeGridView.getLayoutParams().width = width - 120;
//tapeGridView.getLayoutParams().height = height - 40;
tapeGridView.requestLayout();
/*
tapeGridView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
final int actionPeformed = event.getAction();
switch (actionPeformed) {
case MotionEvent.ACTION_DOWN: {
final float x = event.getX();
final float y = event.getY();
lastXAxis = x; this.tapeAdapter = new TapeAdapter();
lastYAxis = y; this.tapeGridView = (GridView) this.findViewById(R.id.tape_grid_view);
this.tapeGridView.setAdapter(this.tapeAdapter);
Log.d(LOG_TAG, "TOUCH X:" + Float.toString(lastXAxis));
Log.d(LOG_TAG, "TOUCH Y:" + Float.toString(lastYAxis)); this.pictoCategoriesGridAdapter = new PictoGridAdapter(new LinkedList<Picto>());
break; this.pictoCategoriesGridView = (GridView) this.findViewById(R.id.picto_categories_grid_view);
} this.pictoCategoriesGridView.setAdapter(this.pictoCategoriesGridAdapter);
this.pictoGridAdapter = new PictoGridAdapter(new LinkedList<Picto>());
this.pictoGridView = (GridView) this.findViewById(R.id.picto_grid_view);
this.pictoGridView.setAdapter(this.pictoGridAdapter);
// @TODO take this value from user configuration (0: normal, 1: large)
int pictogramSize = 0;
if (pictogramSize == 0) {
this.pictoCategoriesGridView.setNumColumns(10);
this.pictoGridView.setNumColumns(10);
} else if (pictogramSize == 1) {
this.pictoCategoriesGridView.setNumColumns(4);
this.pictoGridView.setNumColumns(4);
}
case MotionEvent.ACTION_MOVE: { // tts = new TextToSpeech(this, this, "IVONA Text-to-Speech HQ");
final float x = event.getX(); tts = new TextToSpeech(this, this);
final float y = event.getY();
final float dx = x - lastXAxis; this.tapeGridView.setOnDragListener(new OnPictoDragListener());
final float dy = y - lastYAxis; this.pictoCategoriesGridView.setOnDragListener(new OnPictoDragListener());
this.pictoGridView.setOnDragListener(new OnPictoDragListener());
xAxis += dx; this.pictoCategoriesGridView.setOnItemClickListener(new OnPictoClickListener());
yAxis += dy; this.pictoGridView.setOnItemClickListener(new OnPictoClickListener());
Log.d(LOG_TAG, "MOVE X:" + Float.toString(xAxis)); this.pictoCategoriesGridView.setOnItemLongClickListener(new OnPictoLongClickListener());
Log.d(LOG_TAG, "MOVE Y:" + Float.toString(yAxis)); this.pictoGridView.setOnItemLongClickListener(new OnPictoLongClickListener());
break;
}
}
return true;
}
});
*/
final GridView panelGridView = (GridView) findViewById(R.id.panel_grid_view);
final ImageButton deleteButton = (ImageButton) findViewById(R.id.button_delete); final ImageButton deleteButton = (ImageButton) findViewById(R.id.button_delete);
//final Button deleteAllButton = (Button) findViewById(R.id.button_delete_all);
final ImageButton ttsButton = (ImageButton) findViewById(R.id.button_tts); final ImageButton ttsButton = (ImageButton) findViewById(R.id.button_tts);
ttsButton.setOnClickListener(new OnTTSButtonClickListener());
deleteButton.setOnClickListener(new OnDeleteButtonClickListener());
deleteButton.setOnLongClickListener(new OnDeleteButtonLongClickListener());
// Si los pictogramas son grandes pongo una configuración. Si son pequeños otra this.showPictoCategoriesViewButton = (ImageButton) this.findViewById(R.id.showPictoCategoriesViewButton);
int pictogramSize = 0; // ESTE VALOR SE COGE DE LA CONFIGURACION DEL USUARIO (0:normal; 1:large) this.showPictoCategoriesViewButton.setOnClickListener(new OnShowPictoCategoriesViewButtonClick());
if (pictogramSize == 0) panelGridView.setNumColumns(10);
else if (pictogramSize == 1) panelGridView.setNumColumns(4);
panelGridView.setAdapter(panelAdapter);
// Adapter for tape this.generateAnimations();
tapeAdapter = new TapeAdapter(); if (this.currentCategory != null) {
tapeGridView.setAdapter(tapeAdapter); this.hidePictoCategoriesGridView();
} else {
// Cargo en el TTS el motor definido para ese usuario this.showPictoCategoriesGridView();
//tts = new TextToSpeech(this, this, "IVONA Text-to-Speech HQ"); }
tts = new TextToSpeech(this, this); }
/** @Override
* Event LISTENERS public void onInit(int status) {
*/ if (status == TextToSpeech.SUCCESS) {
tts.setLanguage(Locale.getDefault());
}
}
// Drag para el Panel y Tape @Override
tapeGridView.setOnDragListener(new MyDragListener()); protected void onDestroy() {
panelGridView.setOnDragListener(new MyDragListener()); super.onDestroy();
if (tts != null){
tts.shutdown();
}
}
// onClick picto del panelGridView /**
panelGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { * Creates the animations for moving the picto view
*/
private void generateAnimations() {
DisplayMetrics displayMetrics = new DisplayMetrics();
this.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int animationDuration = 400;
int animationWidth = displayMetrics.widthPixels;
this.hidePictoCategoryViewAnimation = new TranslateAnimation(0, -animationWidth, 0, 0);
this.hidePictoCategoryViewAnimation.setDuration(animationDuration);
this.hidePictoCategoryViewAnimation.setFillAfter(true);
this.hidePictoCategoryViewAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
this.hidePictoCategoryViewAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { public void onAnimationStart(Animation animation) {}
//Toast.makeText(getApplicationContext(), "Position: " + position + "/nid: " + id, Toast.LENGTH_SHORT).show();
//rowNumberAdapter.deleteView(position);
//rowNumberAdapter.notifyDataSetChanged();
Picto p = panelAdapter.getItem(position);
if (p != null && !p.is_invisible() && p.is_enabled()) {
Log.d(LOG_TAG, "Clic en picto: " + p.toString());
//Log.d(LOG_TAG, "STATUS: " + p.get_status());
//QUITAR PARA QUE HABLE panelAdapter.ttsPicto(p, tts);
// If is not the blank picto, it isn't invisible or disabled
if (p.get_id() != 0 &&
!p.get_status().equalsIgnoreCase("invisible") &&
!p.get_status().equalsIgnoreCase("disabled")) {
LinkedList<Picto> ll = order(PCBcontext.getVocabulary().next(p));
//LinkedList<Picto> ll = vocabulary.next(p);
Log.d(LOG_TAG, "Lista de pictos recuperada: " + ll.toString());
int maxInTape = getResources().getInteger(R.integer.maxInTape);
// If the picto is a category
if (p.is_category()) {
panelAdapter.clear();
//if (panelAdapter.isEmpty())
// Log.d(LOG_TAG, "EMPTY !!!!");
//panelAdapter.deleteAll();
panelAdapter.addAll(ll);
//panelAdapter = new PanelAdapter(ll);
// Cambio el color del fondo
RelativeLayout rl = (RelativeLayout) findViewById(R.id.pictogramLayout);
//rl.setBackgroundColor(Color.RED);
if (p.get_color() != -1) {
rl.setBackgroundColor(p.get_color());
panelAdapter.setColor(p.get_darkner_color());
}
currentCategory = p;
PCBcontext.getActionLog().log(new TalkAction(TalkAction.SELECT, p));
} else if (tapeAdapter.getCount() < maxInTape) {
// If the picto selected is not a category and the tape is not full, it is placed in tape
tapeAdapter.addItem(p);
tapeAdapter.notifyDataSetChanged();
Log.d(LOG_TAG, "Picto añadido a la CINTA");
panelAdapter.clear();
panelAdapter.addAll(ll);
panelAdapter.setColor(Color.parseColor("#AFAFAF"));
RelativeLayout rl = (RelativeLayout) findViewById(R.id.pictogramLayout);
rl.setBackgroundColor(Color.parseColor("#BDBDBD"));
// Call to static log method
PCBcontext.getActionLog().log(new TalkAction(TalkAction.ADD, p));
// Send websocket notification
// when clicking a picto, the activity goes to the main category view
currentCategory = null;
}
}
}
}
});
// onLongClick picto del panelGridView (para empezar a arrastrarlo hacia el tape)
panelGridView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override @Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { public void onAnimationEnd(Animation animation) {
if (PCBcontext.getPcbdb().getCurrentUser().is_supervisor()) { pictoCategoriesGridView.setTranslationZ(-1000.0f);
// Si es supervisor al hacer longClick deshabilito ese pictograma o lo habilito pictoCategoriesGridView.setVisibility(View.GONE);
Picto p = panelAdapter.getItem(position);
if (p == null) {
// No tengo pictograma. Abro una nueva ventana de selección desde el Carrete del device si no es categoria
if (PictogramActivity.this.currentCategory!=null) {
Log.d(LOG_TAG, "No tengo pictograma. Abro carrete...");
int cols = getResources().getInteger(R.integer.columns);
addPicto(position % cols, (int) (position / cols));
} else
Toast.makeText(PictogramActivity.this, PictogramActivity.this.getResources().getString(R.string.notNewCats), Toast.LENGTH_SHORT).show();
} else {
p.alter_status();
LinkedList<Picto> ll;
if (currentCategory != null) ll = order(PCBcontext.getVocabulary().next(currentCategory));
else ll = order(PCBcontext.getVocabulary().startSentence());
panelAdapter.clear();
panelAdapter.addAll(ll);
}
} else {
ClipData.Item item = new ClipData.Item("" + position);
String[] mimeTypes = {ClipDescription.MIMETYPE_TEXT_PLAIN};
ClipData data = new ClipData("" + position, mimeTypes, item);
Picto p = panelAdapter.getItem(position);
if (p != null && !p.is_invisible() && p.is_enabled()) {
// If is not the blank picto, it isn't invisible or disabled
if (p.get_id() != 0 &&
!p.get_status().equalsIgnoreCase("invisible") &&
!p.get_status().equalsIgnoreCase("disabled") &&
tapeAdapter.getCount() < 8) {
View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);
view.startDrag(data, //data to be dragged
shadowBuilder, //drag shadow
view, //local data about the drag and drop operation
0 //no needed flags
);
//view.setVisibility(View.INVISIBLE);
}
}
}
return true;
} }
});
// onLongClick picto del tapeGridView (para empezar a arrastrarlo fuera del tape y eliminar de ahí)
/*
tapeGridView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override @Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { public void onAnimationRepeat(Animation animation) {}
ClipData.Item item = new ClipData.Item("" + position);
String[] mimeTypes = {ClipDescription.MIMETYPE_TEXT_PLAIN};
ClipData data = new ClipData("" + position, mimeTypes, item);
View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);
view.startDrag(data, //data to be dragged
shadowBuilder, //drag shadow
view, //local data about the drag and drop operation
0 //no needed flags
);
//view.setVisibility(View.INVISIBLE);
return true;
}
}); });
*/
// onClick ttsButton (enviar frase a server o guardar en log local) this.showPictoCategoryViewAnimation = new TranslateAnimation(-animationWidth, 0, 0, 0);
ttsButton.setOnClickListener(new View.OnClickListener() { this.showPictoCategoryViewAnimation.setDuration(animationDuration);
this.showPictoCategoryViewAnimation.setFillAfter(true);
this.showPictoCategoryViewAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
this.showPictoCategoryViewAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override @Override
public void onClick(View arg0) { public void onAnimationStart(Animation animation) {
// Send websocket action pictoCategoriesGridView.setTranslationZ(1000.0f);
LinkedList<Picto> lp = tapeAdapter.getAll(); pictoCategoriesGridView.setVisibility(View.VISIBLE);
// Call to static log method
PCBcontext.getActionLog().log(new PictosAction(lp));
//send_phrase_action(tapeAdapter.getAll());
// Uncomment next line for locution when the version of Android be greater than 5.0
// (Unsupported on previous versions)
tapeAdapter.ttsAllNew(tts);
tapeAdapter.deleteAll();
tapeAdapter.notifyDataSetChanged();
panelAdapter.setColor(Color.parseColor("#AFAFAF"));
RelativeLayout rl = (RelativeLayout) findViewById(R.id.pictogramLayout);
rl.setBackgroundColor(Color.parseColor("#BDBDBD"));
// Load the categories
load_pictos(arg0);
} }
});
// onClick deleteButton (eliminar del tape el último picto)
deleteButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View arg0) { public void onAnimationEnd(Animation animation) {}
if (tapeAdapter.hasElements()) {
Picto p = tapeAdapter.getLastItem();
// Call to static log method
PCBcontext.getActionLog().log(new TalkAction(TalkAction.DELETE, p));
// Send websocket action
tapeAdapter.deleteLastView();
tapeAdapter.notifyDataSetChanged();
}
}
});
// Acción para volver a la ventana de login
deleteButton.setOnLongClickListener(new AdapterView.OnLongClickListener() {
@Override @Override
public boolean onLongClick(View v) { public void onAnimationRepeat(Animation animation) {}
count_deletelong++;
//Picto picto=PCBcontext.getVocabulary().saveLocalPicto("/sdcard/DCIM/camera/javo.jpg", "javier", 7515, 2, 2);
if (count_deletelong >= 3) {
//Log.d(LOG_TAG, "SALTO A LOGIN");
// Paso un parámetro a la SerialActivity, para controlar de dónde viene
Intent serialActivity = new Intent(getBaseContext(), SerialActivity.class);
serialActivity.putExtra("resetPrevUser", true);
startActivity(serialActivity);
}
return false;
}
}); });
} }
/**
* Show the main category grid view and hide the pictoGrid, unloading all pictos
* if necesary.
*/
private void showPictoCategoriesGridView() {
Log.d(LOG_TAG, "Showing pictoCategoriesGridView");
@Override this.pictoCategoriesGridAdapter.clear();
public void onInit(int status) { this.pictoCategoriesGridAdapter.addAll(this.sort(this.vocabulary.startSentence()));
if (status == TextToSpeech.SUCCESS) { this.pictoCategoriesGridAdapter.notifyDataSetChanged();
tts.setLanguage(Locale.getDefault());
}
}
@Override protected void onStart() {
super.onStart();
// Toast.makeText(this, "onStart", Toast.LENGTH_SHORT).show();
}
@Override protected void onResume() {
super.onResume();
//Toast.makeText(this, "onResume", Toast.LENGTH_SHORT).show();
this.pictoGridAdapter.setColor(Color.parseColor("#AFAFAF"));
// String android_id = Settings.Secure.getString(this.getContentResolver(), this.pictoCategoriesGridView.setEnabled(true);
// Secure.ANDROID_ID); this.pictoGridView.setEnabled(false);
if (this.pictoCategoriesGridView.getAnimation() == this.hidePictoCategoryViewAnimation) {
this.pictoCategoriesGridView.startAnimation(this.showPictoCategoryViewAnimation);
}
// Toast.makeText(this, "onResume - Android ID: " + android_id, Toast.LENGTH_SHORT).show(); this.currentCategory = null;
} }
@Override protected void onPause() { /**
// Toast.makeText(this, "onPause", Toast.LENGTH_SHORT).show(); * Hides the main category grid view and show a concrete category (this.currentCategory)
super.onPause(); */
} private void hidePictoCategoriesGridView() {
Log.d(LOG_TAG, "Hiding pictoCategoriesGridView");
@Override protected void onStop() { this.pictoGridAdapter.clear();
super.onStop(); this.pictoGridAdapter.addAll(this.sort(this.vocabulary.next(this.currentCategory)));
// Toast.makeText(this, "onStop", Toast.LENGTH_SHORT).show(); this.pictoGridAdapter.notifyDataSetChanged();
}
@Override protected void onRestart() { if (this.currentCategory.get_color() != -1) {
super.onRestart(); this.pictoGridAdapter.setColor(this.currentCategory.get_darkner_color());
// Toast.makeText(this, "onRestart", Toast.LENGTH_SHORT).show(); this.pictoGridView.setBackgroundColor(this.currentCategory.get_color());
} }
@Override protected void onDestroy() { this.pictoCategoriesGridView.setEnabled(false);
super.onDestroy(); this.pictoGridView.setEnabled(true);
if (tts != null){
tts.shutdown(); if (this.pictoCategoriesGridView.getAnimation() != this.hidePictoCategoryViewAnimation) {
this.pictoCategoriesGridView.startAnimation(this.hidePictoCategoryViewAnimation);
} }
// Toast.makeText(this, "onDestroy", Toast.LENGTH_SHORT).show();
} }
/** /**
* Load pictos. Asociado a botón provisional para cargar el vocabulario en el adapter * Returns pictoGridAdapter or pictoCategoriesGridAdapter depending on the current View
* @param v
*/ */
public void load_pictos(View v) { private PictoGridAdapter getCurrentPictoGridAdapter() {
if(PCBcontext.getVocabulary() != null) return (currentCategory == null) ? this.pictoCategoriesGridAdapter : this.pictoGridAdapter;
Log.d(LOG_TAG, "4) Vocabulario: " + PCBcontext.getVocabulary().toString());
try {
currentCategory = null;
LinkedList<Picto> ll = order(PCBcontext.getVocabulary().startSentence());
panelAdapter.clear();
panelAdapter.addAll(ll);
}catch(NullPointerException e){
Log.d(LOG_TAG, "El vocabulario todavía no se ha cargado");
}
} }
/** /**
...@@ -486,7 +282,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener, ...@@ -486,7 +282,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
* @param list * @param list
* @return * @return
*/ */
public LinkedList<Picto> order(LinkedList<Picto> list){ public LinkedList<Picto> sort(LinkedList<Picto> list){
LinkedList<Picto> ll = new LinkedList<>(); LinkedList<Picto> ll = new LinkedList<>();
...@@ -522,27 +318,26 @@ public class PictogramActivity extends Activity implements iVocabularyListener, ...@@ -522,27 +318,26 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
return ll; return ll;
} }
/**
* Background task that updates the ui into the main thread
*/
public void refresh() { public void refresh() {
// Background task that updates the ui into the main thread.
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
if (currentCategory != null) {
//stuff that updates ui hidePictoCategoriesGridView();
LinkedList<Picto> ll; } else {
showPictoCategoriesGridView();
if (currentCategory != null) ll = order(PCBcontext.getVocabulary().next(currentCategory)); }
else ll = order(PCBcontext.getVocabulary().startSentence());
panelAdapter.clear();
panelAdapter.addAll(ll);
panelAdapter.notifyDataSetChanged();
} }
}); });
} }
// De la interfaz iVocabularyListener
/**
* @TODO check documentation
* De la interfaz iVocabularyListener
*/
@Override @Override
public void change(action action, int picto_cat, int picto_id, JSONObject args) { public void change(action action, int picto_cat, int picto_id, JSONObject args) {
Log.d(LOG_TAG, "Vocabulary action listened: " + action); Log.d(LOG_TAG, "Vocabulary action listened: " + action);
...@@ -550,7 +345,9 @@ public class PictogramActivity extends Activity implements iVocabularyListener, ...@@ -550,7 +345,9 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
refresh(); refresh();
} }
// Disable Back Button --> Kiosk mode /**
* Disable Back Button --> Kiosk mode
*/
@Override @Override
public void onBackPressed() { public void onBackPressed() {
// Inflate the layout for the AlertDialog // Inflate the layout for the AlertDialog
...@@ -634,7 +431,10 @@ public class PictogramActivity extends Activity implements iVocabularyListener, ...@@ -634,7 +431,10 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
} }
// Disable long power button press /**
* Disable long power button press (system menu)
* @param hasFocus
*/
@Override @Override
public void onWindowFocusChanged(boolean hasFocus) { public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus); super.onWindowFocusChanged(hasFocus);
...@@ -645,7 +445,10 @@ public class PictogramActivity extends Activity implements iVocabularyListener, ...@@ -645,7 +445,10 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
} }
} }
// Disable volume button /**
* Disable volume button on key event
* @param event
*/
@Override @Override
public boolean dispatchKeyEvent(KeyEvent event) { public boolean dispatchKeyEvent(KeyEvent event) {
if (blockedKeys.contains(event.getKeyCode())) { if (blockedKeys.contains(event.getKeyCode())) {
...@@ -655,33 +458,14 @@ public class PictogramActivity extends Activity implements iVocabularyListener, ...@@ -655,33 +458,14 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
} }
} }
// Clase para el evento disparador del Drag & Drop /* *********************************************************************************************
/* * Event listener classes
class MyClickListener implements View.OnLongClickListener { * ********************************************************************************************/
// called when the item is long-clicked
@Override
public boolean onLongClick(View view) {
// TODO Auto-generated method stub
// create it from the object's tag
ClipData.Item item = new ClipData.Item((CharSequence)view.getTag());
String[] mimeTypes = { ClipDescription.MIMETYPE_TEXT_PLAIN };
ClipData data = new ClipData(view.getTag().toString(), mimeTypes, item);
View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);
view.startDrag( data, //data to be dragged
shadowBuilder, //drag shadow
view, //local data about the drag and drop operation
0 //no needed flags
);
view.setVisibility(View.INVISIBLE);
return true;
}
}
*/
class MyDragListener implements View.OnDragListener { /**
* Class used for dragging pictos to the tape
*/
private class OnPictoDragListener implements View.OnDragListener {
//Drawable normalShape = getResources().getDrawable(R.drawable.normal_shape); //Drawable normalShape = getResources().getDrawable(R.drawable.normal_shape);
//Drawable targetShape = getResources().getDrawable(R.drawable.target_shape); //Drawable targetShape = getResources().getDrawable(R.drawable.target_shape);
...@@ -719,73 +503,25 @@ public class PictogramActivity extends Activity implements iVocabularyListener, ...@@ -719,73 +503,25 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
// if the view is the tape_grid_view, we accept the drag item // if the view is the tape_grid_view, we accept the drag item
// Destino tape_grid_view y origen panel_grid_view // Destino tape_grid_view y origen panel_grid_view
if(v == findViewById(R.id.tape_grid_view) && viewgroup == findViewById(R.id.panel_grid_view)) { if(v == findViewById(R.id.tape_grid_view) && viewgroup == findViewById(R.id.picto_grid_view)) {
//viewgroup.removeView(view);
Log.d("Drag:", "Posición: " + position); Log.d("Drag:", "Posición: " + position);
Picto p = pictoGridAdapter.getItem(position);
Picto p = panelAdapter.getItem(position);
if(!p.is_category()) { if(!p.is_category()) {
currentCategory = null;
tapeAdapter.addItem(p); tapeAdapter.addItem(p);
//tapeAdapterPictos.addView(v);
tapeAdapter.notifyDataSetChanged(); tapeAdapter.notifyDataSetChanged();
showPictoCategoriesGridView();
// Go to categories view
load_pictos(view);
// Call to static log method
PCBcontext.getActionLog().log(new TalkAction(TalkAction.ADD, p)); PCBcontext.getActionLog().log(new TalkAction(TalkAction.ADD, p));
// Send websocket notification
/*
try {
Log.d(LOG_TAG, "Picto: " + p.toString());
//room.talk("/stu/action", "select", p);
room.talk("/stu/action", "add", p);
}catch(JSONException e){
e.printStackTrace();
Log.e(LOG_TAG, "Send action: " + e.getMessage());
}
*/
} }
} }
// Si el destino es el panel y el origen la cinta de frase // Si el destino es el panel y el origen la cinta de frase
else if(v == findViewById(R.id.panel_grid_view) && viewgroup == findViewById(R.id.tape_grid_view)){ else if(v == findViewById(R.id.picto_grid_view) && viewgroup == findViewById(R.id.tape_grid_view)){
Log.d("Drag:", "Posición: " + position); Log.d("Drag:", "Posición: " + position);
Picto p = tapeAdapter.getItem(position); Picto p = tapeAdapter.getItem(position);
// Call to static log method
// PCBcontext.getActionLog().log(new Action(ActionLog.Type.Delete, p.get_translation()));
/*
try {
Log.d(LOG_TAG, "Picto: " + p.toString());
room.talk("/stu/action", "delete", p);
}catch(JSONException e){
e.printStackTrace();
Log.e(LOG_TAG, "Send action: " + e.getMessage());
}
*/
// Y se elimina del panel GridView
tapeAdapter.deleteItem(position); tapeAdapter.deleteItem(position);
tapeAdapter.notifyDataSetChanged(); tapeAdapter.notifyDataSetChanged();
} }
/*
else {
view.setVisibility(View.VISIBLE);
Context context = getApplicationContext();
Toast.makeText(context, "No puedes mover la imagen aquí", Toast.LENGTH_LONG).show();
break;
}
*/
break; break;
...@@ -801,10 +537,180 @@ public class PictogramActivity extends Activity implements iVocabularyListener, ...@@ -801,10 +537,180 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
} }
} }
/* /**
* Methods for add a new picto from pcb * Class used for picto clicking feedback
* */
*/ private class OnPictoClickListener implements AdapterView.OnItemClickListener{
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Picto p = getCurrentPictoGridAdapter().getItem(position);
if (p != null && !p.is_invisible() && p.is_enabled()) {
Log.d(LOG_TAG, "Clic en picto: " + p.toString());
//Log.d(LOG_TAG, "STATUS: " + p.get_status());
//QUITAR PARA QUE HABLE pictoGridAdapter.ttsPicto(p, tts);
// If is not the blank picto, it isn't invisible or disabled
if (p.get_id() != 0 &&
!p.get_status().equalsIgnoreCase("invisible") &&
!p.get_status().equalsIgnoreCase("disabled")) {
LinkedList<Picto> ll = sort(PCBcontext.getVocabulary().next(p));
//LinkedList<Picto> ll = vocabulary.next(p);
Log.d(LOG_TAG, "Lista de pictos recuperada: " + ll.toString());
int maxInTape = getResources().getInteger(R.integer.maxInTape);
// If the picto is a category
if (p.is_category()) {
currentCategory = p;
PCBcontext.getActionLog().log(new TalkAction(TalkAction.SELECT, p));
hidePictoCategoriesGridView();
} else if (tapeAdapter.getCount() < maxInTape) {
currentCategory = null;
tapeAdapter.addItem(p);
tapeAdapter.notifyDataSetChanged();
PCBcontext.getActionLog().log(new TalkAction(TalkAction.ADD, p));
showPictoCategoriesGridView();
}
}
}
}
}
/**
* Class used for long pressing on pictos (start drag)
*/
private class OnPictoLongClickListener implements AdapterView.OnItemLongClickListener {
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
if (PCBcontext.getPcbdb().getCurrentUser().is_supervisor()) {
// Si es supervisor al hacer longClick deshabilito ese pictograma o lo habilito
Picto p = getCurrentPictoGridAdapter().getItem(position);
if (p == null) {
// No tengo pictograma. Abro una nueva ventana de selección desde el Carrete del device si no es categoria
if (currentCategory != null) {
Log.d(LOG_TAG, "No tengo pictograma. Abro carrete...");
int cols = getResources().getInteger(R.integer.columns);
addPicto(position % cols, (int) (position / cols));
} else
Toast.makeText(PictogramActivity.this, PictogramActivity.this.getResources().getString(R.string.notNewCats), Toast.LENGTH_SHORT).show();
} else {
p.alter_status();
showPictoCategoriesGridView();
}
} else {
ClipData.Item item = new ClipData.Item("" + position);
String[] mimeTypes = {ClipDescription.MIMETYPE_TEXT_PLAIN};
ClipData data = new ClipData("" + position, mimeTypes, item);
Picto p = getCurrentPictoGridAdapter().getItem(position);
if (p != null && !p.is_invisible() && p.is_enabled()) {
// If is not the blank picto, it isn't invisible or disabled
if (p.get_id() != 0 &&
!p.get_status().equalsIgnoreCase("invisible") &&
!p.get_status().equalsIgnoreCase("disabled") &&
tapeAdapter.getCount() < 8) {
View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);
view.startDrag(data, //data to be dragged
shadowBuilder, //drag shadow
view, //local data about the drag and drop operation
0 //no needed flags
);
//view.setVisibility(View.INVISIBLE);
}
}
}
return true;
}
}
/**
* Class used for reading pictos on TTS button click
*/
private class OnTTSButtonClickListener implements View.OnClickListener {
@Override
public void onClick(View arg0) {
// Send websocket action
LinkedList<Picto> lp = tapeAdapter.getAll();
// Call to static log method
PCBcontext.getActionLog().log(new PictosAction(lp));
//send_phrase_action(tapeAdapter.getAll());
// Uncomment next line for locution when the version of Android be greater than 5.0
// (Unsupported on previous versions)
tapeAdapter.ttsAllNew(tts);
tapeAdapter.deleteAll();
tapeAdapter.notifyDataSetChanged();
pictoGridAdapter.setColor(Color.parseColor("#AFAFAF"));
RelativeLayout rl = (RelativeLayout) findViewById(R.id.pictogramLayout);
rl.setBackgroundColor(Color.parseColor("#BDBDBD"));
// Load the categories
showPictoCategoriesGridView();
}
}
/**
* Class used for canceling a list of pictos on the tape
*/
private class OnDeleteButtonClickListener implements View.OnClickListener {
@Override
public void onClick(View arg0) {
if (tapeAdapter.hasElements()) {
Picto p = tapeAdapter.getLastItem();
// Call to static log method
PCBcontext.getActionLog().log(new TalkAction(TalkAction.DELETE, p));
// Send websocket action
tapeAdapter.deleteLastView();
tapeAdapter.notifyDataSetChanged();
}
}
}
/**
* Class used for long click on delete button. When a press count reaches 3, the application
* exists.
*/
private class OnDeleteButtonLongClickListener implements View.OnLongClickListener {
@Override
public boolean onLongClick(View v) {
count_deletelong++;
if (count_deletelong >= 3) {
// Paso un parámetro a la SerialActivity, para controlar de dónde viene
Intent serialActivity = new Intent(getBaseContext(), SerialActivity.class);
serialActivity.putExtra("resetPrevUser", true);
startActivity(serialActivity);
}
return false;
}
}
/**
* Listener used for bringing back the picto categories grid when clicked.
*/
private class OnShowPictoCategoriesViewButtonClick implements View.OnClickListener {
@Override
public void onClick(View v) {
showPictoCategoriesGridView();
}
}
/* *********************************************************************************************
* Methods for adding a new picto from pcb
* ********************************************************************************************/
/** /**
* add a local picto from pcb * add a local picto from pcb
...@@ -821,10 +727,11 @@ public class PictogramActivity extends Activity implements iVocabularyListener, ...@@ -821,10 +727,11 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
} }
/** /**
* función para la edición de un texto asociado a una nueva imagen y guardar el nuevo picto * función para la edición de un texto asociado a una nueva imagen y guardar el nuevo picto
*/ */
public void chooseTextAndSavePicto(final String selectedImagePath, final int row, final int col) { public void chooseTextAndSavePicto(final String selectedImagePath, final int row, final int col) {
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getResources().getString(R.string.enterImgLabel)); builder.setTitle(getResources().getString(R.string.enterImgLabel));
...@@ -862,6 +769,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener, ...@@ -862,6 +769,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
builder.show(); builder.show();
} }
/** /**
* Función para la selección de una foto del carrete * Función para la selección de una foto del carrete
* @param requestCode * @param requestCode
...@@ -908,6 +816,4 @@ public class PictogramActivity extends Activity implements iVocabularyListener, ...@@ -908,6 +816,4 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
return uri.getPath(); return uri.getPath();
} }
} }
...@@ -2,61 +2,92 @@ ...@@ -2,61 +2,92 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:orientation="horizontal" android:orientation="horizontal"
android:background="#BDBDBD" android:background="#BDBDBD"
android:keepScreenOn="true" android:keepScreenOn="true"
android:id="@+id/pictogramLayout" android:id="@+id/pictogramLayout"
tools:context=".PictogramActivity"> tools:context=".PictogramActivity"
android:padding="8dp">
<!-- android:keepScreenOn - To keep the screen bright as long as the app is visible (also forever) --> <!-- android:keepScreenOn - To keep the screen bright as long as the app is visible (also forever) -->
<GridView <GridView
android:id="@+id/tape_grid_view" android:id="@+id/tape_grid_view"
android:layout_width="850dp" android:layout_width="wrap_content"
android:layout_height="85dp" android:layout_height="64dp"
android:padding="8dp"
android:gravity="center" android:gravity="center"
android:numColumns="@integer/columns" android:numColumns="@integer/columns"
android:accessibilityLiveRegion="none" android:accessibilityLiveRegion="none"
android:background="@android:color/holo_red_light" android:background="@android:color/holo_red_light"
android:clickable="false" android:clickable="false"
android:layout_alignParentTop="true"> android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:paddingRight="192dp">
</GridView> </GridView>
<ImageButton <ImageButton
android:layout_width="wrap_content" android:layout_width="96dp"
android:layout_height="wrap_content" android:layout_height="64dp"
android:paddingLeft="850dp" android:src="@drawable/ic_backspace_white_48dp"
android:paddingTop="20dp"
android:src="@drawable/back64"
android:background="@null"
android:id="@+id/button_delete" android:id="@+id/button_delete"
android:layout_alignParentTop="true"/> android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/button_tts"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:clickable="true"
android:background="@null" />
<ImageButton <ImageButton
android:layout_width="wrap_content" android:layout_width="96dp"
android:layout_height="wrap_content" android:layout_height="64dp"
android:paddingLeft="20dp" android:src="@drawable/ic_play_circle_filled_white_48dp"
android:paddingTop="20dp"
android:src="@drawable/play64"
android:background="@null" android:background="@null"
android:id="@+id/button_tts" android:id="@+id/button_tts"
android:layout_toRightOf="@+id/tape_grid_view" android:adjustViewBounds="true"
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
android:adjustViewBounds="true"/> android:layout_alignParentEnd="true"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:clickable="true" />
<ImageButton
android:layout_width="96dp"
android:layout_height="match_parent"
android:id="@+id/showPictoCategoriesViewButton"
android:layout_alignParentStart="true"
android:src="@drawable/back64"
android:background="#DDDDDD"
android:layout_below="@+id/tape_grid_view" />
<GridView
android:id="@+id/picto_grid_view"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_below="@+id/tape_grid_view"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:numColumns="10"
android:gravity="center_vertical|center|center_horizontal"
android:paddingTop="32dp"
android:verticalSpacing="24dp"
android:background="@color/common_signin_btn_default_background"
android:layout_toEndOf="@+id/showPictoCategoriesViewButton">
</GridView>
<GridView <GridView
android:id="@+id/panel_grid_view" android:id="@+id/picto_categories_grid_view"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_width="match_parent" android:layout_width="match_parent"
android:paddingTop="20dp" android:layout_below="@+id/tape_grid_view"
android:columnWidth="100dp" android:layout_alignParentStart="true"
android:verticalSpacing="1dp" android:layout_alignParentBottom="true"
android:horizontalSpacing="15dp" android:numColumns="10"
android:stretchMode="columnWidth" android:gravity="center_vertical|center|center_horizontal"
android:layout_below="@+id/tape_grid_view"> android:paddingTop="32dp"
android:verticalSpacing="24dp"
android:background="#DDDDDD">
</GridView> </GridView>
</RelativeLayout> </RelativeLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment