Commit 9813ce4a by Pablo Molina

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

parents 0c3bc699 e753900f
......@@ -9,7 +9,7 @@ android {
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.yottacode.pictogram"
minSdkVersion 19
minSdkVersion 21
targetSdkVersion 21
versionCode 1
versionName "1.0"
......
......@@ -35,7 +35,7 @@ import java.util.ArrayList;
import java.util.Hashtable;
import java.util.LinkedList;
public class PanelAdapter extends ArrayAdapter {
public class PictoGridAdapter extends ArrayAdapter {
private LinkedList<Picto> lPictos;
int color;
......@@ -45,7 +45,7 @@ public class PanelAdapter extends ArrayAdapter {
// String constant for logs
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);
//mContext = c;
lPictos = ll;
......@@ -117,7 +117,7 @@ public class PanelAdapter extends ArrayAdapter {
/*
try{
imageView.setBackgroundColor(lPictos.get(position).get_darkner_color());
//Log.d("PanelAdapter", "Position: " + position);
//Log.d("PictoGridAdapter", "Position: " + position);
} catch (java.lang.IllegalArgumentException e){
e.printStackTrace();
//imageView.setBackgroundColor(PCBcontext.getContext().getResources().getColor(R.color.blue));
......
......@@ -3,31 +3,31 @@ package com.yottacode.pictogram.gui;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.database.Cursor;
import android.graphics.Color;
import android.graphics.Point;
import android.content.ClipData;
import android.content.ClipDescription;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.provider.Settings;
import android.speech.tts.TextToSpeech;
import android.text.InputType;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
import android.view.DragEvent;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
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.CheckBox;
import android.widget.EditText;
......@@ -37,21 +37,15 @@ import android.widget.RelativeLayout;
import android.widget.Toast;
import com.yottacode.pictogram.R;
import com.yottacode.pictogram.action.PictoAction;
import com.yottacode.pictogram.action.PictosAction;
import com.yottacode.pictogram.action.TalkAction;
import com.yottacode.pictogram.action.VocabularyAction;
import com.yottacode.pictogram.dao.Picto;
import com.yottacode.pictogram.dao.User;
import com.yottacode.pictogram.grammar.Vocabulary;
import com.yottacode.pictogram.grammar.iLocalPicto;
import com.yottacode.pictogram.grammar.iVocabularyListener;
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 org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
......@@ -60,31 +54,44 @@ import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Vector;
import android.provider.Settings.Secure;
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;
// 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;
// Object used for reading text
TextToSpeech tts;
// Element used for loading new pictos (while changing categories)
Vocabulary vocabulary;
// TODO describe this variable
static final int SELECT_PICTURE = 1;
// 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));
// String constant for logs
private final String LOG_TAG = this.getClass().getSimpleName(); // Or .getCanonicalName()
// Count for delete long press (hidden exit)
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
protected void onCreate(Bundle savedInstanceState) {
......@@ -94,391 +101,180 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
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;
// Adapter for grid
panelAdapter = new PanelAdapter(new LinkedList<Picto>());
Vocabulary vocabulary = PCBcontext.getVocabulary();
if (vocabulary != null && vocabulary.size() > 0) {
this.vocabulary = PCBcontext.getVocabulary();
this.vocabulary.listen(PCBcontext.getRoom(), this);
if (this.vocabulary != null && this.vocabulary.size() > 0) {
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;
lastYAxis = y;
Log.d(LOG_TAG, "TOUCH X:" + Float.toString(lastXAxis));
Log.d(LOG_TAG, "TOUCH Y:" + Float.toString(lastYAxis));
break;
}
this.tapeAdapter = new TapeAdapter();
this.tapeGridView = (GridView) this.findViewById(R.id.tape_grid_view);
this.tapeGridView.setAdapter(this.tapeAdapter);
this.pictoCategoriesGridAdapter = new PictoGridAdapter(new LinkedList<Picto>());
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: {
final float x = event.getX();
final float y = event.getY();
// tts = new TextToSpeech(this, this, "IVONA Text-to-Speech HQ");
tts = new TextToSpeech(this, this);
final float dx = x - lastXAxis;
final float dy = y - lastYAxis;
this.tapeGridView.setOnDragListener(new OnPictoDragListener());
this.pictoCategoriesGridView.setOnDragListener(new OnPictoDragListener());
this.pictoGridView.setOnDragListener(new OnPictoDragListener());
xAxis += dx;
yAxis += dy;
this.pictoCategoriesGridView.setOnItemClickListener(new OnPictoClickListener());
this.pictoGridView.setOnItemClickListener(new OnPictoClickListener());
Log.d(LOG_TAG, "MOVE X:" + Float.toString(xAxis));
Log.d(LOG_TAG, "MOVE Y:" + Float.toString(yAxis));
break;
}
}
return true;
}
});
*/
this.pictoCategoriesGridView.setOnItemLongClickListener(new OnPictoLongClickListener());
this.pictoGridView.setOnItemLongClickListener(new OnPictoLongClickListener());
final GridView panelGridView = (GridView) findViewById(R.id.panel_grid_view);
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);
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
int pictogramSize = 0; // ESTE VALOR SE COGE DE LA CONFIGURACION DEL USUARIO (0:normal; 1:large)
if (pictogramSize == 0) panelGridView.setNumColumns(10);
else if (pictogramSize == 1) panelGridView.setNumColumns(4);
panelGridView.setAdapter(panelAdapter);
this.showPictoCategoriesViewButton = (ImageButton) this.findViewById(R.id.showPictoCategoriesViewButton);
this.showPictoCategoriesViewButton.setOnClickListener(new OnShowPictoCategoriesViewButtonClick());
// Adapter for tape
tapeAdapter = new TapeAdapter();
tapeGridView.setAdapter(tapeAdapter);
// Cargo en el TTS el motor definido para ese usuario
//tts = new TextToSpeech(this, this, "IVONA Text-to-Speech HQ");
tts = new TextToSpeech(this, this);
this.generateAnimations();
if (this.currentCategory != null) {
this.hidePictoCategoriesGridView();
} else {
this.showPictoCategoriesGridView();
}
}
/**
* Event LISTENERS
*/
@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
tts.setLanguage(Locale.getDefault());
}
}
// Drag para el Panel y Tape
tapeGridView.setOnDragListener(new MyDragListener());
panelGridView.setOnDragListener(new MyDragListener());
@Override
protected void onDestroy() {
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
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//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);
public void onAnimationStart(Animation animation) {}
// 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
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 = 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;
public void onAnimationEnd(Animation animation) {
pictoCategoriesGridView.setTranslationZ(-1000.0f);
pictoCategoriesGridView.setVisibility(View.GONE);
}
});
// onLongClick picto del tapeGridView (para empezar a arrastrarlo fuera del tape y eliminar de ahí)
/*
tapeGridView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
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;
}
public void onAnimationRepeat(Animation animation) {}
});
*/
// onClick ttsButton (enviar frase a server o guardar en log local)
ttsButton.setOnClickListener(new View.OnClickListener() {
this.showPictoCategoryViewAnimation = new TranslateAnimation(-animationWidth, 0, 0, 0);
this.showPictoCategoryViewAnimation.setDuration(animationDuration);
this.showPictoCategoryViewAnimation.setFillAfter(true);
this.showPictoCategoryViewAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
this.showPictoCategoryViewAnimation.setAnimationListener(new Animation.AnimationListener() {
@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();
panelAdapter.setColor(Color.parseColor("#AFAFAF"));
RelativeLayout rl = (RelativeLayout) findViewById(R.id.pictogramLayout);
rl.setBackgroundColor(Color.parseColor("#BDBDBD"));
// Load the categories
load_pictos(arg0);
public void onAnimationStart(Animation animation) {
pictoCategoriesGridView.setTranslationZ(1000.0f);
pictoCategoriesGridView.setVisibility(View.VISIBLE);
}
});
// onClick deleteButton (eliminar del tape el último picto)
deleteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
if (tapeAdapter.hasElements()) {
Picto p = tapeAdapter.getLastItem();
public void onAnimationEnd(Animation animation) {}
// 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
public boolean onLongClick(View v) {
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;
}
public void onAnimationRepeat(Animation animation) {}
});
}
/**
* 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
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
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.pictoCategoriesGridAdapter.clear();
this.pictoCategoriesGridAdapter.addAll(this.sort(this.vocabulary.startSentence()));
this.pictoCategoriesGridAdapter.notifyDataSetChanged();
this.pictoGridAdapter.setColor(Color.parseColor("#AFAFAF"));
// String android_id = Settings.Secure.getString(this.getContentResolver(),
// Secure.ANDROID_ID);
this.pictoCategoriesGridView.setEnabled(true);
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();
super.onPause();
}
/**
* Hides the main category grid view and show a concrete category (this.currentCategory)
*/
private void hidePictoCategoriesGridView() {
Log.d(LOG_TAG, "Hiding pictoCategoriesGridView");
@Override protected void onStop() {
super.onStop();
// Toast.makeText(this, "onStop", Toast.LENGTH_SHORT).show();
}
this.pictoGridAdapter.clear();
this.pictoGridAdapter.addAll(this.sort(this.vocabulary.next(this.currentCategory)));
this.pictoGridAdapter.notifyDataSetChanged();
@Override protected void onRestart() {
super.onRestart();
// Toast.makeText(this, "onRestart", Toast.LENGTH_SHORT).show();
}
if (this.currentCategory.get_color() != -1) {
this.pictoGridAdapter.setColor(this.currentCategory.get_darkner_color());
this.pictoGridView.setBackgroundColor(this.currentCategory.get_color());
}
@Override protected void onDestroy() {
super.onDestroy();
if (tts != null){
tts.shutdown();
this.pictoCategoriesGridView.setEnabled(false);
this.pictoGridView.setEnabled(true);
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
* @param v
* Returns pictoGridAdapter or pictoCategoriesGridAdapter depending on the current View
*/
public void load_pictos(View v) {
if(PCBcontext.getVocabulary() != null)
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");
}
private PictoGridAdapter getCurrentPictoGridAdapter() {
return (currentCategory == null) ? this.pictoCategoriesGridAdapter : this.pictoGridAdapter;
}
/**
......@@ -486,7 +282,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
* @param list
* @return
*/
public LinkedList<Picto> order(LinkedList<Picto> list){
public LinkedList<Picto> sort(LinkedList<Picto> list){
LinkedList<Picto> ll = new LinkedList<>();
......@@ -522,27 +318,26 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
return ll;
}
/**
* Background task that updates the ui into the main thread
*/
public void refresh() {
// Background task that updates the ui into the main thread.
runOnUiThread(new Runnable() {
@Override
public void run() {
//stuff that updates ui
LinkedList<Picto> ll;
if (currentCategory != null) ll = order(PCBcontext.getVocabulary().next(currentCategory));
else ll = order(PCBcontext.getVocabulary().startSentence());
panelAdapter.clear();
panelAdapter.addAll(ll);
panelAdapter.notifyDataSetChanged();
if (currentCategory != null) {
hidePictoCategoriesGridView();
} else {
showPictoCategoriesGridView();
}
}
});
}
// De la interfaz iVocabularyListener
/**
* @TODO check documentation
* De la interfaz iVocabularyListener
*/
@Override
public void change(action action, int picto_cat, int picto_id, JSONObject args) {
Log.d(LOG_TAG, "Vocabulary action listened: " + action);
......@@ -550,7 +345,9 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
refresh();
}
// Disable Back Button --> Kiosk mode
/**
* Disable Back Button --> Kiosk mode
*/
@Override
public void onBackPressed() {
// Inflate the layout for the AlertDialog
......@@ -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
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
......@@ -645,7 +445,10 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
}
}
// Disable volume button
/**
* Disable volume button on key event
* @param event
*/
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (blockedKeys.contains(event.getKeyCode())) {
......@@ -655,33 +458,14 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
}
}
// Clase para el evento disparador del Drag & Drop
/*
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;
}
}
*/
/* *********************************************************************************************
* Event listener classes
* ********************************************************************************************/
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 targetShape = getResources().getDrawable(R.drawable.target_shape);
......@@ -719,73 +503,25 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
// if the view is the tape_grid_view, we accept the drag item
// Destino tape_grid_view y origen panel_grid_view
if(v == findViewById(R.id.tape_grid_view) && viewgroup == findViewById(R.id.panel_grid_view)) {
//viewgroup.removeView(view);
if(v == findViewById(R.id.tape_grid_view) && viewgroup == findViewById(R.id.picto_grid_view)) {
Log.d("Drag:", "Posición: " + position);
Picto p = panelAdapter.getItem(position);
Picto p = pictoGridAdapter.getItem(position);
if(!p.is_category()) {
currentCategory = null;
tapeAdapter.addItem(p);
//tapeAdapterPictos.addView(v);
tapeAdapter.notifyDataSetChanged();
// Go to categories view
load_pictos(view);
// Call to static log method
showPictoCategoriesGridView();
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
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);
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.notifyDataSetChanged();
}
/*
else {
view.setVisibility(View.VISIBLE);
Context context = getApplicationContext();
Toast.makeText(context, "No puedes mover la imagen aquí", Toast.LENGTH_LONG).show();
break;
}
*/
break;
......@@ -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
......@@ -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
*/
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);
builder.setTitle(getResources().getString(R.string.enterImgLabel));
......@@ -862,6 +769,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
builder.show();
}
/**
* Función para la selección de una foto del carrete
* @param requestCode
......@@ -908,6 +816,4 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
return uri.getPath();
}
}
......@@ -2,61 +2,92 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:orientation="horizontal"
android:background="#BDBDBD"
android:keepScreenOn="true"
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) -->
<GridView
android:id="@+id/tape_grid_view"
android:layout_width="850dp"
android:layout_height="85dp"
android:layout_width="wrap_content"
android:layout_height="64dp"
android:padding="8dp"
android:gravity="center"
android:numColumns="@integer/columns"
android:accessibilityLiveRegion="none"
android:background="@android:color/holo_red_light"
android:clickable="false"
android:layout_alignParentTop="true">
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:paddingRight="192dp">
</GridView>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="850dp"
android:paddingTop="20dp"
android:src="@drawable/back64"
android:background="@null"
android:layout_width="96dp"
android:layout_height="64dp"
android:src="@drawable/ic_backspace_white_48dp"
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
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="20dp"
android:paddingTop="20dp"
android:src="@drawable/play64"
android:layout_width="96dp"
android:layout_height="64dp"
android:src="@drawable/ic_play_circle_filled_white_48dp"
android:background="@null"
android:id="@+id/button_tts"
android:layout_toRightOf="@+id/tape_grid_view"
android:adjustViewBounds="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
android:id="@+id/panel_grid_view"
android:id="@+id/picto_categories_grid_view"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:paddingTop="20dp"
android:columnWidth="100dp"
android:verticalSpacing="1dp"
android:horizontalSpacing="15dp"
android:stretchMode="columnWidth"
android:layout_below="@+id/tape_grid_view">
android:layout_below="@+id/tape_grid_view"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:numColumns="10"
android:gravity="center_vertical|center|center_horizontal"
android:paddingTop="32dp"
android:verticalSpacing="24dp"
android:background="#DDDDDD">
</GridView>
</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