VOCA class defined

parent 5fb8e46c
Showing with 1329 additions and 1336 deletions
......@@ -49,7 +49,7 @@
android:label="@string/title_activity_login_activity_fragments"
android:screenOrientation="landscape" />
<activity
android:name="com.yottacode.pictogram.tabletlibrary.gui.communicator.VocabularyViewer"
android:name="com.yottacode.pictogram.tabletlibrary.gui.communicator.VOCA"
android:exported="true"
android:label="@string/app_name"
android:launchMode="singleTop"
......
......@@ -31,7 +31,7 @@ public class PictoAnimation {
private final static String LOG_TAG = PictoAnimation.class.getCanonicalName();
public void animateTapeView(final VocabularyViewer activity, final int position, final ViewGroup view) {
public void animateTapeView(final VOCA activity, final int position, final ViewGroup view) {
final GridView gridview = (GridView) view.getChildAt(1);
final TapeAdapter tapeAdapter=(TapeAdapter)gridview.getAdapter();
......@@ -104,7 +104,7 @@ public class PictoAnimation {
return argb(alpha, red, green, blue);
}
public void animateTapeViewVertical(final VocabularyViewer activity, final boolean up) {
public void animateTapeViewVertical(final VOCA activity, final boolean up) {
final View v = activity.findViewById(R.id.pictogramLayout);
int y=v.getHeight()/2-activity.tapeGridView.getHeight()/2;
final ValueAnimator moveAnim = up
......@@ -147,7 +147,7 @@ public class PictoAnimation {
public void animateOnDeleteView(final VocabularyViewer activity, View view, final int position) {
public void animateOnDeleteView(final VOCA activity, View view, final int position) {
if (activity.deleting) return;
View borderlayout=((RelativeLayout)view).getChildAt(0);
......@@ -222,7 +222,7 @@ public class PictoAnimation {
public static void animateOnGridView(final RelativeLayout layout) {
final VocabularyViewer activity=(VocabularyViewer)PCBcontext.getActivityContext();
final VOCA activity=(VOCA)PCBcontext.getActivityContext();
if (activity.inserting) return;
FrameLayout borderlayout=(FrameLayout)layout.getChildAt(0);
......@@ -275,7 +275,7 @@ public class PictoAnimation {
public static void animateOutGridView(final PictoGridAdapter pictoGridAdapter, final Picto picto, RelativeLayout layout, final Vector<Picto> pictoLinkedList_inTape) {
final VocabularyViewer activity=(VocabularyViewer)PCBcontext.getActivityContext();
final VOCA activity=(VOCA)PCBcontext.getActivityContext();
if (activity.inserting) return;
FrameLayout borderlayout=(FrameLayout)layout.getChildAt(0);
......
......@@ -73,7 +73,7 @@ public class PictoItemViewGenerator {
}
/**
* Pictogramas no habilitados se muestran sólo en VocabularyManager
*
* @param picto Pictogram to show
* @param convertView View object
* @param parent
......
......@@ -26,7 +26,7 @@ public class PictoMenu {
public static final String IMAGE_PICTO = "imagePicto";
public static final String PATH_SOUND = "pathSound";
VocabularyViewer activity;
VOCA activity;
//Variables used on the picto menu (only supervisors)
private static final int CAMERA_PIC_REQUEST = 1;
......@@ -40,7 +40,7 @@ public class PictoMenu {
// TODO describe this variable
static final int SELECT_PICTURE = 1;
public PictoMenu(VocabularyViewer activity) {
public PictoMenu(VOCA activity) {
this.activity=activity;
}
......@@ -81,7 +81,7 @@ public class PictoMenu {
public void addPicto(int row, int col, int cat, int source) {
//Enviar al VocabularyViewer los datos necesarios para crear el picto despues
//Enviar al VOCA los datos necesarios para crear el picto despues
if (/*PCBcontext.getPcbdb().getCurrentUser().has_categories()*/PCBcontext.getVocabulary().has_categories()) {
activity.getIntent().putExtra(Picto.JSON_ATTTRS.CATEGORY, cat);
activity.getIntent().putExtra(Picto.JSON_ATTTRS.ROW, row);
......@@ -107,7 +107,7 @@ public class PictoMenu {
Intent intent = new Intent(activity, EditPictoActivity.class);
intent.putExtra(ID_PICTO_IMAGE,id_picto);
//Enviar al VocabularyViewer los datos necesarios para editar el picto despues
//Enviar al VOCA los datos necesarios para editar el picto despues
if (/*PCBcontext.getPcbdb().getCurrentUser().has_categories()*/PCBcontext.getVocabulary().has_categories()) {
intent.putExtra(Picto.JSON_ATTTRS.CATEGORY, cat);
intent.putExtra(Picto.JSON_ATTTRS.ROW, row);
......
package com.yottacode.pictogram.tabletlibrary.gui.communicator;
/**
* Created by scollado on 17/07/17.
*/
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ClipData;
import android.content.ClipDescription;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.speech.tts.UtteranceProgressListener;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.DragEvent;
import android.view.Gravity;
import android.view.HapticFeedbackConstants;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.AdapterView;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.Toast;
public class VOCA extends VocabularyViewer {
import com.yottacode.pictogram.action.PictosAction;
import com.yottacode.pictogram.action.TalkAction;
import com.yottacode.pictogram.dao.Picto;
import com.yottacode.pictogram.dao.User;
import com.yottacode.pictogram.grammar.Vocabulary;
import com.yottacode.pictogram.net.ImgDownloader;
import com.yottacode.pictogram.net.websockets.ActionTalk;
import com.yottacode.pictogram.net.websockets.VocabularyTalk;
import com.yottacode.pictogram.tabletlibrary.R;
import com.yottacode.pictogram.tabletlibrary.gui.session.SessionActivity;
import com.yottacode.pictogram.tabletlibrary.net.NetServiceTablet;
import com.yottacode.pictogram.tools.Img;
import com.yottacode.pictogram.tools.PCBcontext;
import com.yottacode.pictogram.tts.TTSHelper;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
public class VOCA extends Activity implements VocabularyTalk.iVocabularyListener {
private static final int CAMERA_PIC_REQUEST = 1;
private static final int GALLERY_PIC_REQUEST = 2;
// Main layout for this activity
RelativeLayout mainLayout;
// Adapter for de grid showing the categories grid (and main pictos)
PictoGridAdapter pictoMainGridAdapter;
// Grid showing the categories grid (and main pictos)
GridView pictoMainGridView;
// Adapter for the grid showing pictos from a category (initially hidden)
PictoGridAdapter pictoCategoryGridAdapter;
// Grid showing pictos from a category (initially hidden)
GridView pictoCategoryGridView;
// 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
private Picto currentCategory;
// Object used for reading text
TTSHelper tts;
// Element used for loading new pictos (while changing categories)
Vocabulary vocabulary;
// 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 hidePictoMainViewAnimation;
// Animation for showing the picto category view
Animation showPictoMainViewAnimation;
// Button used for showing the picto category view
ImageButton showPictoCategoriesViewButton;
ImageButton deleteButton;
ImageButton ttsButton;
int maxColumns, maxRows, maxInTape;
ScheduledThreadPoolExecutor exec_mirror = null;
Picto prev_picto = null;
private boolean feedback_read;
private boolean feedback_highlight;
protected boolean deleting;
protected boolean tape_delivered=false;
float firstTouchX = -1;
public boolean inserting=false;
@TargetApi(Build.VERSION_CODES.M)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// blockNotificationBar();
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
// after a long inactivity, the pcbdb is discarded
if (!PCBcontext.is_user_logged()) {
Log.i(LOG_TAG,"PCBDB was discarded. App restarting");
NetServiceTablet.restart_PictogramTablet(this);
return;
}
setContentView(PCBcontext.getPcbdb().getCurrentUser().is_picto_size_big() ? R.layout.activity_pictogram_big : R.layout.activity_pictogram);
this.mainLayout = (RelativeLayout) findViewById(R.id.pictogramLayout);
this.currentCategory = null;
this.count_deletelong = 0;
if (!PCBcontext.is_user_logged()) {
Log.i(LOG_TAG, "No user logged. Restarting app");
NetServiceTablet.restart_PictogramTablet(this);
return;
}
this.vocabulary = PCBcontext.getVocabulary();
this.vocabulary.listen(PCBcontext.getRoom(), this, new ActionTalk.iActionListener() {
@Override
public void action(action action, int picto_cat, int picto_id, JSONObject msg) {
Log.i(this.getClass().getCanonicalName(), action + " from " + picto_cat + "," + picto_id + " catched");
if (action==ActionTalk.iActionListener.action.show) {
Log.i("TAG_PRUEBAS","show message received:"+msg.toString());
JSONObject msg_attrs = null;
JSONArray pictos = null;
String mensaje= "";
try {
msg_attrs = msg.getJSONObject("attributes");
pictos = msg_attrs.getJSONArray("pictos");
String user = pictos.getJSONObject(0).getJSONObject("attributes").getString("user_avatar");
if(user.equals(PCBcontext.getPcbdb().getCurrentUser().get_email_sup())){ //si el primer picto tiene ese sup asociado
mensaje += getResources().getString(R.string.message_from)+": "+PCBcontext.getPcbdb().getCurrentUser().get_name_stu()+", "+ PCBcontext.getPcbdb().getCurrentUser().get_surname_stu()+"\n";
mensaje += getResources().getString(R.string.says)+": ";
for(int i = 0; i < pictos.length(); i++) {
JSONObject picto = pictos.getJSONObject(i).getJSONObject("attributes");
mensaje += (i != pictos.length()-1 ? picto.get("expression").toString()+" - " : picto.get("expression").toString());
}
Log.i(LOG_TAG,"Mensaje: "+msg.toString());
final AlertDialog.Builder builder = new AlertDialog.Builder(VOCA.this);
builder.setMessage(mensaje)
.setPositiveButton("Vale", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
// Create the AlertDialog object and return it
runOnUiThread(new Runnable() {
@Override
public void run() {
AlertDialog alert = builder.create();
alert.show();
}
});
}
} catch (JSONException e) {
e.printStackTrace();
}
}
else if (PCBcontext.getPcbdb().getCurrentUser().is_mirror_on()) {
Picto picto = vocabulary.get_picto(picto_cat, picto_id);
VOCA.this.execHighligthFeeback(picto, true);
}
}
});
this.vocabulary.setImgDownloaderListener(new ImgDownloader.iImgDownloaderListener() {
@Override
public void loadComplete() {
VOCA.this.refresh();
}
@Override
public void loadImg(Img image) {
}
@Override
public void error(Exception err) {
}
});
this.tapeAdapter = new TapeAdapter();
this.tapeGridView = (GridView) this.findViewById(R.id.tape_grid_view);
this.tapeGridView.setAdapter(this.tapeAdapter);
this.pictoMainGridAdapter = new PictoGridAdapter(new LinkedList<Picto>());
this.pictoMainGridView = (GridView) this.findViewById(R.id.picto_main_grid_view);
this.pictoMainGridView.setAdapter(this.pictoMainGridAdapter);
this.pictoCategoryGridAdapter = new PictoGridAdapter(new LinkedList<Picto>());
this.pictoCategoryGridView = (GridView) this.findViewById(R.id.picto_category_grid_view);
this.pictoCategoryGridView.setAdapter(this.pictoCategoryGridAdapter);
this.pictoMainGridView.setOnDragListener(new OnPictoDragListener());
this.pictoCategoryGridView.setOnDragListener(new OnPictoDragListener());
this.pictoMainGridView.setOnItemClickListener(new OnPictoClickListener());
this.pictoCategoryGridView.setOnItemClickListener(new OnPictoClickListener());
this.pictoMainGridView.setOnItemLongClickListener(new OnPictoLongClickListener());
this.pictoCategoryGridView.setOnItemLongClickListener(new OnPictoLongClickListener());
this.deleteButton = (ImageButton) findViewById(R.id.button_delete);
this.ttsButton = (ImageButton) findViewById(R.id.button_tts);
ttsButton.setOnClickListener(new OnTTSButtonClickListener());
ttsButton.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
Log.i(this.getClass().getCanonicalName(), " Changing mirror mode");
if (PCBcontext.getPcbdb().getCurrentUser().is_supervisor()) {
int res_id = PCBcontext.getPcbdb().getCurrentUser().alter_mirror_mode() == true ? R.string.mirror_mode_on : R.string.mirror_mode_off;
Toast.makeText(VOCA.this, res_id, Toast.LENGTH_SHORT).show();
}
return true;
}
});
this.deleteButton.setOnClickListener(new OnDeleteButtonClickListener());
this.deleteButton.setOnLongClickListener(new OnDeleteButtonLongClickListener());
this.showPictoCategoriesViewButton = (ImageButton) this.findViewById(R.id.showPictoCategoriesViewButton);
this.showPictoCategoriesViewButton.setOnClickListener(new OnShowPictoCategoriesViewButtonClick());
this.tapeGridView.setOnDragListener(new OnPictoDragListener());
this.tapeGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (!deleting) {
Log.i(VOCA.class.getCanonicalName(), " Deleting item " + position + "-" + id + "(" + VOCA.this.tapeAdapter.getItem(position).get_translation() + ")");
Picto deletedPicto=VOCA.this.tapeAdapter.getItem(position);
new PictoAnimation().animateOnDeleteView(VOCA.this,view, position);
VOCA.this.tapeAdapter.notifyDataSetChanged();
if (pictoMainGridAdapter.pictoInThisCategory(deletedPicto))
pictoMainGridAdapter.pictoInGrid(deletedPicto);
if (pictoCategoryGridAdapter.pictoInThisCategory(deletedPicto))
pictoCategoryGridAdapter.pictoInGrid(deletedPicto);
PCBcontext.getActionLog().log(new TalkAction(TalkAction.DELETE, deletedPicto));
}
}});
((NetServiceTablet) PCBcontext.getNetService().getNetServiceDevice()).setVOCA(this);
if (PCBcontext.getPcbdb().getCurrentUser().is_picto_size_big()) {
maxColumns = getResources().getInteger(R.integer.columns_big);
maxRows = getResources().getInteger(R.integer.rows_big);
maxInTape = getResources().getInteger(R.integer.maxInTape_big);
} else {
maxColumns = getResources().getInteger(R.integer.columns);
maxRows = getResources().getInteger(R.integer.rows);
maxInTape = getResources().getInteger(R.integer.maxInTape);
}
VOCA.this.pictoMainGridView.setNumColumns(VOCA.this.maxColumns);
VOCA.this.pictoCategoryGridView.setNumColumns(VOCA.this.maxColumns);
this.generateAnimations();
if (this.getCurrentCategory() != null) {
this.hidePictoMainGridView();
} else {
this.showPictoMainGridView();
}
}
@Override
protected void onResume() {
super.onResume();
Log.i(LOG_TAG, "Resuming Pictogram Activity");
PCBcontext.setActivityContext(this);
setConfig();
startTTS();
Toast.makeText(this.getBaseContext(), PCBcontext.getPcbdb().getCurrentUser().get_name_stu()+" "+PCBcontext.getPcbdb().getCurrentUser().get_surname_stu()+
(PCBcontext.getPcbdb().getCurrentUser().is_supervisor()
? " ("+ PCBcontext.getPcbdb().getCurrentUser().get_name_sup()+" "+PCBcontext.getPcbdb().getCurrentUser().get_surname_sup()+")"
:"")
, Toast.LENGTH_SHORT).show();
}
private void blockNotificationBar() {
WindowManager manager = ((WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE));
WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams();
localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
localLayoutParams.gravity = Gravity.TOP;
localLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
// this is to enable the notification to recieve touch events
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
// Draws over status bar
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
localLayoutParams.height = (int) (50 * getResources().getDisplayMetrics().scaledDensity);
localLayoutParams.format = PixelFormat.TRANSPARENT;
customViewGroup view = new customViewGroup(this);
manager.addView(view, localLayoutParams);
}
public void setConfig() {
setFeedback(new View[]{deleteButton, ttsButton, this.showPictoCategoriesViewButton, this.pictoCategoryGridView, this.pictoMainGridView});
}
private void setFeedback(View views[]) {
boolean vibration = PCBcontext.getPcbdb().getCurrentUser().input_feedback_on(User.JSON_STUDENT_INPUT_FEEDBACK.VIBRATION);
boolean click = PCBcontext.getPcbdb().getCurrentUser().input_feedback_on(User.JSON_STUDENT_INPUT_FEEDBACK.BEEP);
this.feedback_read = PCBcontext.getPcbdb().getCurrentUser().input_feedback_on(User.JSON_STUDENT_INPUT_FEEDBACK.READ);
this.feedback_highlight = PCBcontext.getPcbdb().getCurrentUser().input_feedback_on(User.JSON_STUDENT_INPUT_FEEDBACK.HIGHLIGHT);
Log.i(this.getClass().getCanonicalName(), "Feedback:" + " vibration:" + vibration + " Beep:" + click + " Read:" + feedback_read + " Highlight:" + feedback_highlight);
View.OnTouchListener touchListener;
touchListener =
vibration ? new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
boolean enable_haptic;
enable_haptic = !(v instanceof GridView);
if (!enable_haptic) {
int x = Math.round(event.getX());
int y = Math.round(event.getY());
int position = ((GridView) v).pointToPosition(x, y);
Picto p = position > -1 ? (Picto) ((GridView) v).getItemAtPosition(position) : null;
enable_haptic = (p != null && p.get_id() != 0 && !p.is_invisible() && p.is_enabled());
}
if (enable_haptic)
v.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
return false;
}
}
: click
? new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
try {
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
}
: new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return false;
}
};
for (View view : views)
view.setOnTouchListener(touchListener);
}
public void startTTS() {
String engine = PCBcontext.getPcbdb().getCurrentUser().get_tts_engine_sup() == null
? getString(R.string.default_tts_engine)
: PCBcontext.getPcbdb().getCurrentUser().get_tts_engine_sup();
String tts_voice = PCBcontext.getPcbdb().getCurrentUser().get_json_attr("tts voice") == null
? PCBcontext.getPcbdb().getCurrentUser().get_gender_stu().charAt(0) == 'M'
? getString(R.string.default_tts_voice_male)
: getString(R.string.default_tts_voice_female)
: PCBcontext.getPcbdb().getCurrentUser().get_json_attr("tts voice");
tts = new TTSHelper(this, engine, new Locale(PCBcontext.getPcbdb().getCurrentUser().get_lang_stu()), tts_voice);
tts.setOnUtteranceProgressListener(new UtteranceProgressListener() {
@Override
public void onStart(String utteranceId) {
Log.d(LOG_TAG, "TTS tape read start" + utteranceId);
}
@Override
public void onDone(String utteranceId) {
Log.d(LOG_TAG, "TTS tape read end");
this.finishSpeech();
}
@Override
public void onError(String utteranceId) {
Log.d(LOG_TAG, "TTS tape read error");
this.finishSpeech();
}
private void finishSpeech() {
}
});
}
@Override
protected void onPause() {
super.onPause();
this.pictoCategoryGridAdapter.allPictosInGrid();
this.pictoMainGridAdapter.allPictosInGrid();
}
@Override
protected void onStop() {
super.onStop();
tts.destroy();
Log.e(LOG_TAG, "Closing Pictogram Activity");
PCBcontext.getNetService().closeNotifyStatus();
}
@Override
protected void onDestroy() {
super.onDestroy();
if (tts != null) {
tts.destroy();
}
}
/**
* 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.hidePictoMainViewAnimation = new TranslateAnimation(0, -animationWidth, 0, 0);
this.hidePictoMainViewAnimation.setDuration(animationDuration);
this.hidePictoMainViewAnimation.setFillAfter(true);
this.hidePictoMainViewAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
this.hidePictoMainViewAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
pictoMainGridView.setTranslationZ(-1000.0f);
pictoMainGridView.setVisibility(View.GONE);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
this.showPictoMainViewAnimation = new TranslateAnimation(-animationWidth, 0, 0, 0);
this.showPictoMainViewAnimation.setDuration(animationDuration);
this.showPictoMainViewAnimation.setFillAfter(true);
this.showPictoMainViewAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
this.showPictoMainViewAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
pictoMainGridView.setTranslationZ(1000.0f);
pictoMainGridView.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationEnd(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
}
/**
* Show the main category grid view and hide the pictoGrid, unloading all pictos
* if necesary.
*/
private void showPictoMainGridView() {
this.pictoMainGridAdapter.clear();
this.pictoMainGridAdapter.addAll(this.sort(this.vocabulary.startSentence()));
this.pictoMainGridAdapter.notifyDataSetChanged();
this.pictoMainGridView.setEnabled(true);
this.pictoCategoryGridView.setEnabled(false);
if (this.pictoMainGridView.getAnimation() == this.hidePictoMainViewAnimation) {
this.pictoMainGridView.startAnimation(this.showPictoMainViewAnimation);
}
this.currentCategory = null;
}
/**
* Hides the main category grid view and show a concrete category (this.currentCategory)
*/
private void hidePictoMainGridView() {
this.pictoCategoryGridAdapter.clear();
this.pictoCategoryGridAdapter.addAll(this.sort(this.vocabulary.next(this.getCurrentCategory())));
this.pictoCategoryGridAdapter.notifyDataSetChanged();
if (this.getCurrentCategory().get_color() != -1)
this.pictoCategoryGridView.setBackgroundColor(this.getCurrentCategory().get_color());
this.pictoMainGridView.setEnabled(false);
this.pictoCategoryGridView.setEnabled(true);
if (this.pictoMainGridView.getAnimation() != this.hidePictoMainViewAnimation) {
this.pictoMainGridView.startAnimation(this.hidePictoMainViewAnimation);
}
}
/**
* Returns pictoCategoryGridAdapter or pictoMainGridAdapter depending on the current View
*/
protected PictoGridAdapter getCurrentPictoGridAdapter() {
return (getCurrentCategory() == null) ? this.pictoMainGridAdapter : this.pictoCategoryGridAdapter;
}
/**
* Order a linked list of pictos with "blank spaces" between them
*
* @param list
* @return
*/
public LinkedList<Picto> sort(LinkedList<Picto> list) {
if (list == null) {
list = new LinkedList<>();
}
LinkedList<Picto> ll = new LinkedList<>();
// This is to show the pictos ordered in the 2D Array that represents the panel
Picto[][] mp = new Picto[maxRows][maxColumns];
Iterator<Picto> pictos=list.iterator();
while (pictos.hasNext()) {
Picto p= pictos.next();
if (/*PCBcontext.getPcbdb().getCurrentUser().has_categories()*/PCBcontext.getVocabulary().has_categories()) {
if (p.get_column() != -1 && p.get_row() != -1
&& p.get_column() < maxRows && p.get_row() < maxColumns) {
mp[p.get_column()][p.get_row()] = p;
}
} else {
if (p.getFreeColumn() != -1 && p.getFreeRow() != -1
&& p.getFreeColumn() < maxRows && p.getFreeRow() < maxColumns) {
mp[p.getFreeColumn()][p.getFreeRow()] = p;
}
}
}
try {
/*
Picto blankPicto = new Picto(0,
"/symbolstx/color/png/arts_crafts/eraser.png", // TODO Definir imagen para picto en blanco
"Blank picto",
"{\"magnify\":false,\"highlight\":false,\"coord_y\":1,\"id_cat\":12303,\"status\":\"invisible\",\"coord_x\":4}");
*/
for (int i = 0; i < maxRows; i++)
for (int j = 0; j < maxColumns; j++)
ll.add(mp[i][j]);
} catch (Exception e) {
e.printStackTrace();
}
return ll;
}
/**
* Background task that updates the ui into the main thread
*/
public void refresh() {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (getCurrentCategory() != null) {
hidePictoMainGridView();
} else {
showPictoMainGridView();
}
}
});
}
/**
* @TODO check documentation
* De la interfaz iVocabularyListener
*/
@Override
public void change(action action, int picto_cat, int picto_id, JSONObject args) {
Log.i(LOG_TAG, "Vocabulary action listened: " + action);
if (args != null) Log.d(LOG_TAG, "args: " + args.toString());
refresh();
}
/**
* Disable Back Button --> Kiosk mode
*/
@Override
public void onBackPressed() {
// Inflate the layout for the AlertDialog
View dialogEscape = View.inflate(this, R.layout.dialog_escape, null);
final CheckBox checkBox = (CheckBox) dialogEscape.findViewById(R.id.checkBox);
final EditText input = (EditText) dialogEscape.findViewById(R.id.editText);
// Build de AlertDialog
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getResources().getString(R.string.exitPictogram));
builder.setView(dialogEscape);
// Set up the buttons
builder.setPositiveButton(getResources().getString(R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String m_Text = input.getText().toString();
String keyword = PCBcontext.getDevice().getKeyword();
if (m_Text.equalsIgnoreCase(keyword)) {
// Change the password
if (checkBox.isChecked()) {
// Show a new dialog
View dialogChangeEscapeCode = View.inflate(PCBcontext.getContext(), R.layout.dialog_change_escape_code, null);
final EditText input1 = (EditText) dialogChangeEscapeCode.findViewById(R.id.editText1);
final EditText input2 = (EditText) dialogChangeEscapeCode.findViewById(R.id.editText2);
// Build the AlertDialog
AlertDialog.Builder builder = new AlertDialog.Builder(PCBcontext.getContext());
builder.setTitle(PCBcontext.getContext().getResources().getString(R.string.newEscapeCode));
builder.setView(dialogChangeEscapeCode);
// Set up the buttons
builder.setPositiveButton(getResources().getString(R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Retrieve the text of the 2 password inputs
String m_Text1 = input1.getText().toString();
String m_Text2 = input2.getText().toString();
// If they are equal
if (m_Text1.equalsIgnoreCase(m_Text2)) {
// Change the keyword
PCBcontext.getDevice().setKeyword(m_Text1);
Toast.makeText(PCBcontext.getContext(), getResources().getString(R.string.codeModified), Toast.LENGTH_SHORT).show();
// And exit VOCA
finish();
} else
Toast.makeText(PCBcontext.getContext(), getResources().getString(R.string.codesNotEqual), Toast.LENGTH_SHORT).show();
}
});
builder.setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.show();
} else {
// Finish this Activity it the code is ok and is not checked the checkbox to change the code
finish();
/*
// Start the main activity
Intent mainActivity = new Intent(context, MainActivity.class);
startActivity(mainActivity);
*/
}
// Wrong code
} else
Toast.makeText(PCBcontext.getContext(), getResources().getString(R.string.wrongCode), Toast.LENGTH_SHORT).show();
}
});
builder.setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.show();
}
/**
* Disable long power button press (system menu)
*
* @param hasFocus
*/
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
);
}
}
/**
* Disable volume button on key event
*
* @param event
*/
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (blockedKeys.contains(event.getKeyCode())) {
return true;
} else {
return super.dispatchKeyEvent(event);
}
}
/**
*
* @return
*/
public Picto getCurrentCategory() {
return currentCategory;
}
/* *********************************************************************************************
* Event listener classes
* ********************************************************************************************/
/**
* Class used for dragging pictos to the tape
*/
private class OnPictoDragListener implements View.OnDragListener {
@Override
public boolean onDrag(View v, DragEvent event) {
// Handles each of the expected events
switch (event.getAction()) {
//signal for the start of a drag and drop operation.
case DragEvent.ACTION_DRAG_STARTED:
// do nothing
break;
//the drag point has entered the bounding box of the View
case DragEvent.ACTION_DRAG_ENTERED:
//v.setBackground(targetShape); //change the shape of the view
break;
//the user has moved the drag shadow outside the bounding box of the View
case DragEvent.ACTION_DRAG_EXITED:
//v.setBackground(normalShape); //change the shape of the view back to normal
break;
//drag shadow has been released,the drag point is within the bounding box of the View
case DragEvent.ACTION_DROP:
View view = (View) event.getLocalState();
ViewGroup viewgroup = (ViewGroup) view.getParent();
int position = Integer.parseInt((String) event.getClipDescription().getLabel());
Log.d("Drag:", "Posición: " + position + " es categoria:" + v.getTransitionName()+" "+viewgroup.getTransitionName());
// 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.picto_category_grid_view) || viewgroup == findViewById(R.id.picto_main_grid_view))) {
Picto p = viewgroup == findViewById(R.id.picto_category_grid_view) ? pictoCategoryGridAdapter.getItem(position)
: pictoMainGridAdapter.getItem(position);
if (!p.is_category()) addPictoWord(view, p);
}
// Si el destino es el panel y el origen la cinta de frase
else if (v == findViewById(R.id.picto_category_grid_view) && viewgroup == findViewById(R.id.tape_grid_view)) {
Picto p = tapeAdapter.getItem(position);
tapeAdapter.deleteItem(position);
tapeAdapter.notifyDataSetChanged();
getCurrentPictoGridAdapter().pictoInGrid(p);
getCurrentPictoGridAdapter().notifyDataSetChanged();
}
break;
//the drag and drop operation has concluded.
case DragEvent.ACTION_DRAG_ENDED:
// v.setBackground(normalShape); //go back to normal shape
default:
break;
}
return false;
}
}
/**f
* Class used for picto clicking feedback
*/
private class OnPictoClickListener implements AdapterView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (inserting) return;
Picto p = getCurrentPictoGridAdapter().getItem(position);
if (p != null && p.get_id() != 0 && !p.is_invisible() && p.is_enabled()) {
p.set_mirror(false, false);
// If the picto is a category
if (p.is_category()) {
currentCategory = p;
PCBcontext.getActionLog().log(new TalkAction(TalkAction.SELECT, p));
hidePictoMainGridView();
} else if (tapeAdapter.getCount() < VOCA.this.maxInTape && !VOCA.this.tapeAdapter.play()) {
addPictoWord(parent.getChildAt(position),p);
}
}
}
}
/**
*
* @param view
* @param p
*/
private void addPictoWord(View view, Picto p) {
tapeAdapter.addItem(p);
getCurrentPictoGridAdapter().pictoInTape(view,p);
currentCategory = null;
tapeAdapter.notifyDataSetChanged();
showPictoMainGridView();
PCBcontext.getActionLog().log(new TalkAction(TalkAction.ADD, p));
if (VOCA.this.feedback_read && !VOCA.this.tapeAdapter.play() && !p.is_category()) {
File audioFile = p.get_audioFile();
Log.e(LOG_TAG,"AUDIO:"+(audioFile!=null)+":"+p.get_audioPath());
if (audioFile != null)
VOCA.this.tts.playRecord(audioFile);
else
VOCA.this.tts.play(p.get_translation());
}
if (VOCA.this.feedback_highlight) execHighligthFeeback(p, false);
}
/**
*
* @param picto
* @param highlight_background
*/
private void execHighligthFeeback(final Picto picto, boolean highlight_background) {
boolean same_picto = false;
picto.set_mirror(true, highlight_background); //comienza feedback
if (exec_mirror != null) { //se cancela ejecución del feedbcack anterior, si lo hay
exec_mirror.shutdown();
exec_mirror = null;
}
if (prev_picto != null) { //se cancela marca de feedback del anterior, si lo hay
prev_picto.set_mirror(false, false);
same_picto = prev_picto == picto;
}
if (same_picto)
prev_picto = null; //por si se pulsaa el mismo boton varias veces
else {
prev_picto = picto;
exec_mirror = new ScheduledThreadPoolExecutor(1);
prev_picto = picto;
exec_mirror.scheduleAtFixedRate(new Runnable() {
int repeating = 0;
@Override
public void run() {
refresh();
if (repeating++ == 20) {
picto.set_mirror(false, false);
if (exec_mirror != null) {
exec_mirror.shutdown();
exec_mirror = null;
}
}
}
}, 0, 250, TimeUnit.MILLISECONDS);
}
}
// TODO: REVISAR
/**
* 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 (getCurrentCategory() != null || *//*!PCBcontext.getPcbdb().getCurrentUser().has_categories()*//*!PCBcontext.getVocabulary().has_categories()) {
int cat = getCurrentCategory() != null ? currentCategory.get_id() : Picto.NO_CATEGORY;
new PictoMenu(VOCA.this).createMenuForNewPicto(position % maxColumns, (int) (position / maxColumns), cat);
} else
Toast.makeText(VOCA.this, VOCA.this.getResources().getString(R.string.notNewCats), Toast.LENGTH_SHORT).show();
} else {
//Si es supervisor hacer aparecer el menú de opciones del picto
new PictoMenu(VOCA.this).createMenuForPicto(PCBcontext.getPcbdb().getCurrentUser().is_picto_size_big(),p);
getCurrentPictoGridAdapter().notifyDataSetChanged();
}
} 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() < VOCA.this.maxInTape) {
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) {
LinkedList<Picto> lp = tapeAdapter.getAll();
// This triggers the "Show" websocket action SI hay algo en la cinta y esta no está vacia
if (lp.size()>0 && !VOCA.this.tapeAdapter.play()) {
PCBcontext.getActionLog().log(new PictosAction(lp));
tapeAdapter.ttsAllNew(tts);
new PictoAnimation().animateTapeView(VOCA.this,0,(ViewGroup)arg0.getParent());
if (PCBcontext.getPcbdb().getCurrentUser().delivery()!= User.JSON_STUDENT_ATTTRS.delivery.clean) {
showOnlyTape(true);
}
}
}
}
/**
*
* @param onlyTape
*/
protected void showOnlyTape(boolean onlyTape) {
boolean tape_delivered_prev=this.tape_delivered;
Log.e(LOG_TAG,"ONLY TAPE->"+onlyTape+" "+ttsButton.isEnabled());
this.tape_delivered=onlyTape;
if (onlyTape) {
if (!tape_delivered_prev) {
if (PCBcontext.getPcbdb().getCurrentUser().delivery()== User.JSON_STUDENT_ATTTRS.delivery.one)
ttsButton.setEnabled(false);
Log.e(LOG_TAG,"ONLY TAPE0->"+onlyTape+" "+ttsButton.isEnabled());
if (this.pictoMainGridView.getAnimation() != this.hidePictoMainViewAnimation) {
this.showPictoCategoriesViewButton.setVisibility(View.INVISIBLE);
this.pictoCategoryGridView.setVisibility(View.INVISIBLE);
this.pictoMainGridView.setAlpha(0.25f);
this.pictoMainGridView.setEnabled(false);
} else {
this.pictoCategoryGridView.setAlpha(0.25f);
this.pictoCategoryGridView.setEnabled(false);
this.showPictoCategoriesViewButton.setAlpha(0f);
}
new PictoAnimation().animateTapeViewVertical(this, false);
}
}
else {
ttsButton.setEnabled(true);
ttsButton.refreshDrawableState();
Log.e(LOG_TAG,"ONLY TAPE1->"+onlyTape+" "+ttsButton.isEnabled());
new PictoAnimation().animateTapeViewVertical(this,true);
if (this.pictoMainGridView.getAnimation() != this.hidePictoMainViewAnimation) {
this.showPictoCategoriesViewButton.setVisibility(View.VISIBLE);
this.pictoCategoryGridView.setVisibility(View.VISIBLE);
this.pictoMainGridView.setAlpha(1f);
this.pictoMainGridView.setEnabled(true);
this.showPictoCategoriesViewButton.setAlpha(1f);
}
else {
this.pictoCategoryGridView.setAlpha(1f);
this.pictoCategoryGridView.setEnabled(true);
this.showPictoCategoriesViewButton.setAlpha(1f);
}
}
}
/**
* 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
Picto last=tapeAdapter.deleteLastView();
tapeAdapter.notifyDataSetChanged();
if (pictoMainGridAdapter.pictoInThisCategory(last))
pictoMainGridAdapter.pictoInGrid(last);
if (pictoCategoryGridAdapter.pictoInThisCategory(last))
pictoCategoryGridAdapter.pictoInGrid(last);
}
if (!tapeAdapter.hasElements() && tape_delivered) showOnlyTape(false);
}
}
/**
* 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) {
//TODO: COMPROBAR SI LOS USUARIOS QUE BUSCO EXISTEN: SI NO PONER LOS DATOS POR DEFECTO*******************************************************************/
//Cojo los id del ultimo estudiante y el ultimo supervisor
int lastIdStu = PCBcontext.getDevice().getLastStuId();
User actual = PCBcontext.getPcbdb().getCurrentUser();
User usuario_anterior;
String lastUserName = null;
String lastPassword = null;
if (actual.is_supervisor()) //Si el que habia es supervisor busco el ultimo niño
try {
usuario_anterior = PCBcontext.getDevice().findUser(lastIdStu, User.NO_SUPERVISOR);
if (usuario_anterior != null) {
lastUserName = usuario_anterior.get_nickname_stu();
lastPassword = usuario_anterior.get_pwd_stu();
}
} catch (JSONException e) {
e.printStackTrace();
}
else {
int lastIdSup = PCBcontext.getDevice().getLastSupId();
try {
usuario_anterior = PCBcontext.getDevice().findUser(lastIdStu, lastIdSup);
if (usuario_anterior != null) {
lastUserName = usuario_anterior.get_email_sup();
lastPassword = usuario_anterior.get_pwd_sup();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
Intent serialActivity = new Intent(getBaseContext(), com.yottacode.pictogram.tabletlibrary.gui.login.SerialActivity.class);
if (lastUserName != null) {
Log.i(this.getClass().getCanonicalName(), "Switch user to " + lastUserName);
serialActivity.putExtra("switch_usr", lastUserName);
serialActivity.putExtra("switch_pwd", lastPassword);
}
pictoCategoryGridAdapter.notifyDataSetInvalidated();
pictoMainGridAdapter.notifyDataSetInvalidated();
VOCA.this.finish();
if (SessionActivity.session!=null) SessionActivity.session.finish();
PCBcontext.getNetService().restart_app(true);
}
return true;
}
}
/**
* Listener used for bringing back the picto categories grid when clicked.
*/
private class OnShowPictoCategoriesViewButtonClick implements View.OnClickListener {
@Override
public void onClick(View v) {
showPictoMainGridView();
}
}
/*@Override
public boolean dispatchTouchEvent(MotionEvent event) {
int in=0,out=0;
Intent nextActivity=null;
Intent intent = getIntent();
boolean student_view=intent.getBooleanExtra("student_view",false);
if (PCBcontext.getPcbdb()!=null && (PCBcontext.getPcbdb().getCurrentUser().is_supervisor() || student_view) ) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
firstTouchX = event.getX();
break;
case MotionEvent.ACTION_UP:
if (event.getX() > firstTouchX + 150) { //izquierda a derecha
if (!student_view || !PCBcontext.getPcbdb().getCurrentUser().is_teacher()) {
PCBcontext.getPcbdb().getCurrentUser().get_Img_sup().update_id(student_view ? PCBcontext.getDevice().getLastSupId() : User.NO_SUPERVISOR);
nextActivity = intent;
} else
if (!PCBcontext.getNetService().online())
GUITools.show_alert(VOCA.this, R.string.session_noinet);
else {
PCBcontext.getPcbdb().getCurrentUser().get_Img_sup().update_id(PCBcontext.getDevice().getLastSupId());
nextActivity = new Intent(this, SessionActivity.class);
}
in = R.anim.rightin;
out = R.anim.rightout;
overridePendingTransition(R.anim.leftin, R.anim.leftout);
} else if (firstTouchX > event.getX() + 150) { //derecha a izquierda
if (!student_view && PCBcontext.getPcbdb().getCurrentUser().is_teacher() ) {
if (!PCBcontext.getNetService().online())
GUITools.show_alert(VOCA.this, R.string.session_noinet);
else
nextActivity = new Intent(this, SessionActivity.class);
} else {
PCBcontext.getPcbdb().getCurrentUser().get_Img_sup().update_id(student_view ? PCBcontext.getDevice().getLastSupId() : User.NO_SUPERVISOR);
nextActivity = intent;
}
in = R.anim.leftin;
out = R.anim.leftout;
}
if (nextActivity != null) {
tape_delivered=false;
intent.putExtra("student_view", !PCBcontext.getPcbdb().getCurrentUser().is_supervisor());
finish();
startActivity(nextActivity);
overridePendingTransition(in, out);
}
break;
}
}
return super.dispatchTouchEvent(event);
}*/
/**
* Para capturar el evento para abrir camara o galeria y procesar
* @param requestCode
* @param resultCode
* @param data
*/
/*protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Bitmap imagen;
switch(requestCode) {
case CAMERA_PIC_REQUEST: //Captura de foto
if (data != null && resultCode==RESULT_OK) {
imagen = (Bitmap) data.getExtras().get("data");
this.launchEditPictoActivity(imagen);
}
break;
case GALLERY_PIC_REQUEST: //Galeria
if(data!=null){
Uri selectedImage = data.getData();
Bitmap bitmap = null;
try {
bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImage);
} catch (IOException e) {
e.printStackTrace();
}
this.launchEditPictoActivity(bitmap);
}
break;
case EditPictoActivity.EDIT_PICTO_REQUEST:
if (resultCode == RESULT_OK) {
boolean edit = data.getBooleanExtra(PictoMenu.IS_EDIT,false);
int row = edit ? data.getExtras().getInt(Picto.JSON_ATTTRS.ROW) : getIntent().getIntExtra(Picto.JSON_ATTTRS.ROW, -1);
int col = edit ? data.getExtras().getInt(Picto.JSON_ATTTRS.COLUMN) : getIntent().getIntExtra(Picto.JSON_ATTTRS.COLUMN, -1);
int freeRow = edit ? data.getExtras().getInt(Picto.JSON_ATTTRS.FREE_ROW) : getIntent().getIntExtra(Picto.JSON_ATTTRS.FREE_ROW, -1);
int freeColumn = edit ? data.getExtras().getInt(Picto.JSON_ATTTRS.FREE_COLUMN) : getIntent().getIntExtra(Picto.JSON_ATTTRS.FREE_COLUMN, -1);
String path_sound = data.getExtras().getString(PictoMenu.PATH_SOUND);
String user_avatar = data.getExtras().getString(Picto.JSON_ATTTRS.USER_AVATAR)*//* : getIntent().getStringExtra(Picto.JSON_ATTTRS.USER_AVATAR, "----")*//*;
int cat = edit ? data.getIntExtra(Picto.JSON_ATTTRS.CATEGORY, -1) : getIntent().getIntExtra(Picto.JSON_ATTTRS.CATEGORY, -1);
String path = data.getExtras().getString(PictoMenu.PATH);
String legend = data.getExtras().getString(Picto.JSON_ATTTRS.EXPRESSION);
chooseTextAndSavePicto(path, row, col, freeRow, freeColumn, cat, legend, path_sound ,user_avatar);
refresh();
}
break;
}
}*/
/**
* 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, final int freeRow, final int freeColumn,
final int category, final String legend,final String path_sound ,final String user_avatar) {
// Set up the buttons
PCBcontext.getVocabulary().saveLocalPicto(
selectedImagePath,
legend,
category,
row,
col,
freeRow,
freeColumn,
user_avatar,
path_sound,
new iLocalPicto() {
@Override
public void saved(Picto localPicto) {
refresh();
try {
if (PCBcontext.is_user_online())
new PictoUploader(localPicto).upload();
} catch (IOException e) {
Log.e(Vocabulary.class.getCanonicalName(), e.getMessage());
}
}
});
}*/
/**Para cambiar la activity de VOCA a EditPictoActivity
* @param image
*/
/*public void launchEditPictoActivity(Bitmap image){
Intent intent = new Intent(this, EditPictoActivity.class);
BitmapTools.save_temporal(image);
startActivityForResult(intent, EditPictoActivity.EDIT_PICTO_REQUEST);
}*/
}
package com.yottacode.pictogram.tabletlibrary.gui.communicator;
/**
* Created by scollado on 19/07/17.
*/
public class VocabularyManager extends VocabularyViewer {
}
package com.yottacode.pictogram.tabletlibrary.gui.communicator;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ClipData;
import android.content.ClipDescription;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.speech.tts.UtteranceProgressListener;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.DragEvent;
import android.view.Gravity;
import android.view.HapticFeedbackConstants;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.AdapterView;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.Toast;
import com.yottacode.pictogram.action.PictosAction;
import com.yottacode.pictogram.action.TalkAction;
import com.yottacode.pictogram.dao.Picto;
import com.yottacode.pictogram.dao.User;
import com.yottacode.pictogram.grammar.Vocabulary;
import com.yottacode.pictogram.net.ImgDownloader;
import com.yottacode.pictogram.net.websockets.ActionTalk;
import com.yottacode.pictogram.net.websockets.VocabularyTalk;
import com.yottacode.pictogram.tabletlibrary.R;
import com.yottacode.pictogram.tabletlibrary.gui.session.SessionActivity;
import com.yottacode.pictogram.tabletlibrary.net.NetServiceTablet;
import com.yottacode.pictogram.tools.Img;
import com.yottacode.pictogram.tools.PCBcontext;
import com.yottacode.pictogram.tts.TTSHelper;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
public class VocabularyViewer extends Activity implements VocabularyTalk.iVocabularyListener {
private static final int CAMERA_PIC_REQUEST = 1;
private static final int GALLERY_PIC_REQUEST = 2;
// Main layout for this activity
RelativeLayout mainLayout;
// Adapter for de grid showing the categories grid (and main pictos)
PictoGridAdapter pictoMainGridAdapter;
// Grid showing the categories grid (and main pictos)
GridView pictoMainGridView;
// Adapter for the grid showing pictos from a category (initially hidden)
PictoGridAdapter pictoCategoryGridAdapter;
// Grid showing pictos from a category (initially hidden)
GridView pictoCategoryGridView;
// 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
private Picto currentCategory;
// Object used for reading text
TTSHelper tts;
// Element used for loading new pictos (while changing categories)
Vocabulary vocabulary;
// 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 hidePictoMainViewAnimation;
// Animation for showing the picto category view
Animation showPictoMainViewAnimation;
// Button used for showing the picto category view
ImageButton showPictoCategoriesViewButton;
ImageButton deleteButton;
ImageButton ttsButton;
int maxColumns, maxRows, maxInTape;
ScheduledThreadPoolExecutor exec_mirror = null;
Picto prev_picto = null;
private boolean feedback_read;
private boolean feedback_highlight;
protected boolean deleting;
protected boolean tape_delivered=false;
float firstTouchX = -1;
public boolean inserting=false;
@TargetApi(Build.VERSION_CODES.M)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// blockNotificationBar();
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
// after a long inactivity, the pcbdb is discarded
if (!PCBcontext.is_user_logged()) {
Log.i(LOG_TAG,"PCBDB was discarded. App restarting");
NetServiceTablet.restart_PictogramTablet(this);
return;
}
setContentView(PCBcontext.getPcbdb().getCurrentUser().is_picto_size_big() ? R.layout.activity_pictogram_big : R.layout.activity_pictogram);
this.mainLayout = (RelativeLayout) findViewById(R.id.pictogramLayout);
this.currentCategory = null;
this.count_deletelong = 0;
if (!PCBcontext.is_user_logged()) {
Log.i(LOG_TAG, "No user logged. Restarting app");
NetServiceTablet.restart_PictogramTablet(this);
return;
}
this.vocabulary = PCBcontext.getVocabulary();
this.vocabulary.listen(PCBcontext.getRoom(), this, new ActionTalk.iActionListener() {
@Override
public void action(action action, int picto_cat, int picto_id, JSONObject msg) {
Log.i(this.getClass().getCanonicalName(), action + " from " + picto_cat + "," + picto_id + " catched");
if (action==ActionTalk.iActionListener.action.show) {
Log.i("TAG_PRUEBAS","show message received:"+msg.toString());
JSONObject msg_attrs = null;
JSONArray pictos = null;
String mensaje= "";
try {
msg_attrs = msg.getJSONObject("attributes");
pictos = msg_attrs.getJSONArray("pictos");
String user = pictos.getJSONObject(0).getJSONObject("attributes").getString("user_avatar");
if(user.equals(PCBcontext.getPcbdb().getCurrentUser().get_email_sup())){ //si el primer picto tiene ese sup asociado
mensaje += getResources().getString(R.string.message_from)+": "+PCBcontext.getPcbdb().getCurrentUser().get_name_stu()+", "+ PCBcontext.getPcbdb().getCurrentUser().get_surname_stu()+"\n";
mensaje += getResources().getString(R.string.says)+": ";
for(int i = 0; i < pictos.length(); i++) {
JSONObject picto = pictos.getJSONObject(i).getJSONObject("attributes");
mensaje += (i != pictos.length()-1 ? picto.get("expression").toString()+" - " : picto.get("expression").toString());
}
Log.i(LOG_TAG,"Mensaje: "+msg.toString());
final AlertDialog.Builder builder = new AlertDialog.Builder(VocabularyViewer.this);
builder.setMessage(mensaje)
.setPositiveButton("Vale", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
// Create the AlertDialog object and return it
runOnUiThread(new Runnable() {
@Override
public void run() {
AlertDialog alert = builder.create();
alert.show();
}
});
}
} catch (JSONException e) {
e.printStackTrace();
}
}
else if (PCBcontext.getPcbdb().getCurrentUser().is_mirror_on()) {
Picto picto = vocabulary.get_picto(picto_cat, picto_id);
VocabularyViewer.this.execHighligthFeeback(picto, true);
}
}
});
this.vocabulary.setImgDownloaderListener(new ImgDownloader.iImgDownloaderListener() {
@Override
public void loadComplete() {
VocabularyViewer.this.refresh();
}
@Override
public void loadImg(Img image) {
}
@Override
public void error(Exception err) {
}
});
this.tapeAdapter = new TapeAdapter();
this.tapeGridView = (GridView) this.findViewById(R.id.tape_grid_view);
this.tapeGridView.setAdapter(this.tapeAdapter);
this.pictoMainGridAdapter = new PictoGridAdapter(new LinkedList<Picto>());
this.pictoMainGridView = (GridView) this.findViewById(R.id.picto_main_grid_view);
this.pictoMainGridView.setAdapter(this.pictoMainGridAdapter);
this.pictoCategoryGridAdapter = new PictoGridAdapter(new LinkedList<Picto>());
this.pictoCategoryGridView = (GridView) this.findViewById(R.id.picto_category_grid_view);
this.pictoCategoryGridView.setAdapter(this.pictoCategoryGridAdapter);
this.pictoMainGridView.setOnDragListener(new OnPictoDragListener());
this.pictoCategoryGridView.setOnDragListener(new OnPictoDragListener());
this.pictoMainGridView.setOnItemClickListener(new OnPictoClickListener());
this.pictoCategoryGridView.setOnItemClickListener(new OnPictoClickListener());
this.pictoMainGridView.setOnItemLongClickListener(new OnPictoLongClickListener());
this.pictoCategoryGridView.setOnItemLongClickListener(new OnPictoLongClickListener());
this.deleteButton = (ImageButton) findViewById(R.id.button_delete);
this.ttsButton = (ImageButton) findViewById(R.id.button_tts);
ttsButton.setOnClickListener(new OnTTSButtonClickListener());
ttsButton.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
Log.i(this.getClass().getCanonicalName(), " Changing mirror mode");
if (PCBcontext.getPcbdb().getCurrentUser().is_supervisor()) {
int res_id = PCBcontext.getPcbdb().getCurrentUser().alter_mirror_mode() == true ? R.string.mirror_mode_on : R.string.mirror_mode_off;
Toast.makeText(VocabularyViewer.this, res_id, Toast.LENGTH_SHORT).show();
}
return true;
}
});
this.deleteButton.setOnClickListener(new OnDeleteButtonClickListener());
this.deleteButton.setOnLongClickListener(new OnDeleteButtonLongClickListener());
this.showPictoCategoriesViewButton = (ImageButton) this.findViewById(R.id.showPictoCategoriesViewButton);
this.showPictoCategoriesViewButton.setOnClickListener(new OnShowPictoCategoriesViewButtonClick());
this.tapeGridView.setOnDragListener(new OnPictoDragListener());
this.tapeGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (!deleting) {
Log.i(VocabularyViewer.class.getCanonicalName(), " Deleting item " + position + "-" + id + "(" + VocabularyViewer.this.tapeAdapter.getItem(position).get_translation() + ")");
Picto deletedPicto=VocabularyViewer.this.tapeAdapter.getItem(position);
new PictoAnimation().animateOnDeleteView(VocabularyViewer.this,view, position);
VocabularyViewer.this.tapeAdapter.notifyDataSetChanged();
if (pictoMainGridAdapter.pictoInThisCategory(deletedPicto))
pictoMainGridAdapter.pictoInGrid(deletedPicto);
if (pictoCategoryGridAdapter.pictoInThisCategory(deletedPicto))
pictoCategoryGridAdapter.pictoInGrid(deletedPicto);
PCBcontext.getActionLog().log(new TalkAction(TalkAction.DELETE, deletedPicto));
}
}});
((NetServiceTablet) PCBcontext.getNetService().getNetServiceDevice()).setVocabularyViewer(this);
if (PCBcontext.getPcbdb().getCurrentUser().is_picto_size_big()) {
maxColumns = getResources().getInteger(R.integer.columns_big);
maxRows = getResources().getInteger(R.integer.rows_big);
maxInTape = getResources().getInteger(R.integer.maxInTape_big);
} else {
maxColumns = getResources().getInteger(R.integer.columns);
maxRows = getResources().getInteger(R.integer.rows);
maxInTape = getResources().getInteger(R.integer.maxInTape);
}
VocabularyViewer.this.pictoMainGridView.setNumColumns(VocabularyViewer.this.maxColumns);
VocabularyViewer.this.pictoCategoryGridView.setNumColumns(VocabularyViewer.this.maxColumns);
this.generateAnimations();
if (this.getCurrentCategory() != null) {
this.hidePictoMainGridView();
} else {
this.showPictoMainGridView();
}
}
@Override
protected void onResume() {
super.onResume();
Log.i(LOG_TAG, "Resuming Pictogram Activity");
PCBcontext.setActivityContext(this);
setConfig();
startTTS();
Toast.makeText(this.getBaseContext(), PCBcontext.getPcbdb().getCurrentUser().get_name_stu()+" "+PCBcontext.getPcbdb().getCurrentUser().get_surname_stu()+
(PCBcontext.getPcbdb().getCurrentUser().is_supervisor()
? " ("+ PCBcontext.getPcbdb().getCurrentUser().get_name_sup()+" "+PCBcontext.getPcbdb().getCurrentUser().get_surname_sup()+")"
:"")
, Toast.LENGTH_SHORT).show();
}
private void blockNotificationBar() {
WindowManager manager = ((WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE));
WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams();
localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
localLayoutParams.gravity = Gravity.TOP;
localLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
// this is to enable the notification to recieve touch events
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
// Draws over status bar
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
localLayoutParams.height = (int) (50 * getResources().getDisplayMetrics().scaledDensity);
localLayoutParams.format = PixelFormat.TRANSPARENT;
customViewGroup view = new customViewGroup(this);
manager.addView(view, localLayoutParams);
}
public void setConfig() {
setFeedback(new View[]{deleteButton, ttsButton, this.showPictoCategoriesViewButton, this.pictoCategoryGridView, this.pictoMainGridView});
}
private void setFeedback(View views[]) {
boolean vibration = PCBcontext.getPcbdb().getCurrentUser().input_feedback_on(User.JSON_STUDENT_INPUT_FEEDBACK.VIBRATION);
boolean click = PCBcontext.getPcbdb().getCurrentUser().input_feedback_on(User.JSON_STUDENT_INPUT_FEEDBACK.BEEP);
this.feedback_read = PCBcontext.getPcbdb().getCurrentUser().input_feedback_on(User.JSON_STUDENT_INPUT_FEEDBACK.READ);
this.feedback_highlight = PCBcontext.getPcbdb().getCurrentUser().input_feedback_on(User.JSON_STUDENT_INPUT_FEEDBACK.HIGHLIGHT);
Log.i(this.getClass().getCanonicalName(), "Feedback:" + " vibration:" + vibration + " Beep:" + click + " Read:" + feedback_read + " Highlight:" + feedback_highlight);
View.OnTouchListener touchListener;
touchListener =
vibration ? new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
boolean enable_haptic;
enable_haptic = !(v instanceof GridView);
if (!enable_haptic) {
int x = Math.round(event.getX());
int y = Math.round(event.getY());
int position = ((GridView) v).pointToPosition(x, y);
Picto p = position > -1 ? (Picto) ((GridView) v).getItemAtPosition(position) : null;
enable_haptic = (p != null && p.get_id() != 0 && !p.is_invisible() && p.is_enabled());
}
if (enable_haptic)
v.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
return false;
}
}
: click
? new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
try {
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
}
: new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return false;
}
};
for (View view : views)
view.setOnTouchListener(touchListener);
}
public void startTTS() {
String engine = PCBcontext.getPcbdb().getCurrentUser().get_tts_engine_sup() == null
? getString(R.string.default_tts_engine)
: PCBcontext.getPcbdb().getCurrentUser().get_tts_engine_sup();
String tts_voice = PCBcontext.getPcbdb().getCurrentUser().get_json_attr("tts voice") == null
? PCBcontext.getPcbdb().getCurrentUser().get_gender_stu().charAt(0) == 'M'
? getString(R.string.default_tts_voice_male)
: getString(R.string.default_tts_voice_female)
: PCBcontext.getPcbdb().getCurrentUser().get_json_attr("tts voice");
tts = new TTSHelper(this, engine, new Locale(PCBcontext.getPcbdb().getCurrentUser().get_lang_stu()), tts_voice);
tts.setOnUtteranceProgressListener(new UtteranceProgressListener() {
@Override
public void onStart(String utteranceId) {
Log.d(LOG_TAG, "TTS tape read start" + utteranceId);
}
@Override
public void onDone(String utteranceId) {
Log.d(LOG_TAG, "TTS tape read end");
this.finishSpeech();
}
@Override
public void onError(String utteranceId) {
Log.d(LOG_TAG, "TTS tape read error");
this.finishSpeech();
}
private void finishSpeech() {
}
});
}
@Override
protected void onPause() {
super.onPause();
this.pictoCategoryGridAdapter.allPictosInGrid();
this.pictoMainGridAdapter.allPictosInGrid();
}
@Override
protected void onStop() {
super.onStop();
tts.destroy();
Log.e(LOG_TAG, "Closing Pictogram Activity");
PCBcontext.getNetService().closeNotifyStatus();
}
@Override
protected void onDestroy() {
super.onDestroy();
if (tts != null) {
tts.destroy();
}
}
/**
* 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.hidePictoMainViewAnimation = new TranslateAnimation(0, -animationWidth, 0, 0);
this.hidePictoMainViewAnimation.setDuration(animationDuration);
this.hidePictoMainViewAnimation.setFillAfter(true);
this.hidePictoMainViewAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
this.hidePictoMainViewAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
pictoMainGridView.setTranslationZ(-1000.0f);
pictoMainGridView.setVisibility(View.GONE);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
this.showPictoMainViewAnimation = new TranslateAnimation(-animationWidth, 0, 0, 0);
this.showPictoMainViewAnimation.setDuration(animationDuration);
this.showPictoMainViewAnimation.setFillAfter(true);
this.showPictoMainViewAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
this.showPictoMainViewAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
pictoMainGridView.setTranslationZ(1000.0f);
pictoMainGridView.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationEnd(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
}
/**
* Show the main category grid view and hide the pictoGrid, unloading all pictos
* if necesary.
*/
private void showPictoMainGridView() {
this.pictoMainGridAdapter.clear();
this.pictoMainGridAdapter.addAll(this.sort(this.vocabulary.startSentence()));
this.pictoMainGridAdapter.notifyDataSetChanged();
this.pictoMainGridView.setEnabled(true);
this.pictoCategoryGridView.setEnabled(false);
if (this.pictoMainGridView.getAnimation() == this.hidePictoMainViewAnimation) {
this.pictoMainGridView.startAnimation(this.showPictoMainViewAnimation);
}
this.currentCategory = null;
}
/**
* Hides the main category grid view and show a concrete category (this.currentCategory)
*/
private void hidePictoMainGridView() {
this.pictoCategoryGridAdapter.clear();
this.pictoCategoryGridAdapter.addAll(this.sort(this.vocabulary.next(this.getCurrentCategory())));
this.pictoCategoryGridAdapter.notifyDataSetChanged();
if (this.getCurrentCategory().get_color() != -1)
this.pictoCategoryGridView.setBackgroundColor(this.getCurrentCategory().get_color());
this.pictoMainGridView.setEnabled(false);
this.pictoCategoryGridView.setEnabled(true);
if (this.pictoMainGridView.getAnimation() != this.hidePictoMainViewAnimation) {
this.pictoMainGridView.startAnimation(this.hidePictoMainViewAnimation);
}
}
/**
* Returns pictoCategoryGridAdapter or pictoMainGridAdapter depending on the current View
*/
protected PictoGridAdapter getCurrentPictoGridAdapter() {
return (getCurrentCategory() == null) ? this.pictoMainGridAdapter : this.pictoCategoryGridAdapter;
}
/**
* Order a linked list of pictos with "blank spaces" between them
*
* @param list
* @return
*/
public LinkedList<Picto> sort(LinkedList<Picto> list) {
if (list == null) {
list = new LinkedList<>();
}
LinkedList<Picto> ll = new LinkedList<>();
// This is to show the pictos ordered in the 2D Array that represents the panel
Picto[][] mp = new Picto[maxRows][maxColumns];
Iterator<Picto> pictos=list.iterator();
while (pictos.hasNext()) {
Picto p= pictos.next();
if (/*PCBcontext.getPcbdb().getCurrentUser().has_categories()*/PCBcontext.getVocabulary().has_categories()) {
if (p.get_column() != -1 && p.get_row() != -1
&& p.get_column() < maxRows && p.get_row() < maxColumns) {
mp[p.get_column()][p.get_row()] = p;
}
} else {
if (p.getFreeColumn() != -1 && p.getFreeRow() != -1
&& p.getFreeColumn() < maxRows && p.getFreeRow() < maxColumns) {
mp[p.getFreeColumn()][p.getFreeRow()] = p;
}
}
}
try {
/*
Picto blankPicto = new Picto(0,
"/symbolstx/color/png/arts_crafts/eraser.png", // TODO Definir imagen para picto en blanco
"Blank picto",
"{\"magnify\":false,\"highlight\":false,\"coord_y\":1,\"id_cat\":12303,\"status\":\"invisible\",\"coord_x\":4}");
*/
for (int i = 0; i < maxRows; i++)
for (int j = 0; j < maxColumns; j++)
ll.add(mp[i][j]);
} catch (Exception e) {
e.printStackTrace();
}
return ll;
}
/**
* Background task that updates the ui into the main thread
*/
public void refresh() {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (getCurrentCategory() != null) {
hidePictoMainGridView();
} else {
showPictoMainGridView();
}
}
});
}
/**
* @TODO check documentation
* De la interfaz iVocabularyListener
*/
@Override
public void change(action action, int picto_cat, int picto_id, JSONObject args) {
Log.i(LOG_TAG, "Vocabulary action listened: " + action);
if (args != null) Log.d(LOG_TAG, "args: " + args.toString());
refresh();
}
/**
* Disable Back Button --> Kiosk mode
*/
@Override
public void onBackPressed() {
// Inflate the layout for the AlertDialog
View dialogEscape = View.inflate(this, R.layout.dialog_escape, null);
final CheckBox checkBox = (CheckBox) dialogEscape.findViewById(R.id.checkBox);
final EditText input = (EditText) dialogEscape.findViewById(R.id.editText);
// Build de AlertDialog
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getResources().getString(R.string.exitPictogram));
builder.setView(dialogEscape);
// Set up the buttons
builder.setPositiveButton(getResources().getString(R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String m_Text = input.getText().toString();
String keyword = PCBcontext.getDevice().getKeyword();
if (m_Text.equalsIgnoreCase(keyword)) {
// Change the password
if (checkBox.isChecked()) {
// Show a new dialog
View dialogChangeEscapeCode = View.inflate(PCBcontext.getContext(), R.layout.dialog_change_escape_code, null);
final EditText input1 = (EditText) dialogChangeEscapeCode.findViewById(R.id.editText1);
final EditText input2 = (EditText) dialogChangeEscapeCode.findViewById(R.id.editText2);
// Build the AlertDialog
AlertDialog.Builder builder = new AlertDialog.Builder(PCBcontext.getContext());
builder.setTitle(PCBcontext.getContext().getResources().getString(R.string.newEscapeCode));
builder.setView(dialogChangeEscapeCode);
// Set up the buttons
builder.setPositiveButton(getResources().getString(R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Retrieve the text of the 2 password inputs
String m_Text1 = input1.getText().toString();
String m_Text2 = input2.getText().toString();
// If they are equal
if (m_Text1.equalsIgnoreCase(m_Text2)) {
// Change the keyword
PCBcontext.getDevice().setKeyword(m_Text1);
Toast.makeText(PCBcontext.getContext(), getResources().getString(R.string.codeModified), Toast.LENGTH_SHORT).show();
// And exit VocabularyViewer
finish();
} else
Toast.makeText(PCBcontext.getContext(), getResources().getString(R.string.codesNotEqual), Toast.LENGTH_SHORT).show();
}
});
builder.setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.show();
} else {
// Finish this Activity it the code is ok and is not checked the checkbox to change the code
finish();
/*
// Start the main activity
Intent mainActivity = new Intent(context, MainActivity.class);
startActivity(mainActivity);
*/
}
// Wrong code
} else
Toast.makeText(PCBcontext.getContext(), getResources().getString(R.string.wrongCode), Toast.LENGTH_SHORT).show();
}
});
builder.setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.show();
}
/**
* Disable long power button press (system menu)
*
* @param hasFocus
*/
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
);
}
}
/**
* Disable volume button on key event
*
* @param event
*/
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (blockedKeys.contains(event.getKeyCode())) {
return true;
} else {
return super.dispatchKeyEvent(event);
}
}
/**
*
* @return
*/
public Picto getCurrentCategory() {
return currentCategory;
}
/* *********************************************************************************************
* Event listener classes
* ********************************************************************************************/
/**
* Class used for dragging pictos to the tape
*/
private class OnPictoDragListener implements View.OnDragListener {
@Override
public boolean onDrag(View v, DragEvent event) {
// Handles each of the expected events
switch (event.getAction()) {
//signal for the start of a drag and drop operation.
case DragEvent.ACTION_DRAG_STARTED:
// do nothing
break;
//the drag point has entered the bounding box of the View
case DragEvent.ACTION_DRAG_ENTERED:
//v.setBackground(targetShape); //change the shape of the view
break;
//the user has moved the drag shadow outside the bounding box of the View
case DragEvent.ACTION_DRAG_EXITED:
//v.setBackground(normalShape); //change the shape of the view back to normal
break;
//drag shadow has been released,the drag point is within the bounding box of the View
case DragEvent.ACTION_DROP:
View view = (View) event.getLocalState();
ViewGroup viewgroup = (ViewGroup) view.getParent();
int position = Integer.parseInt((String) event.getClipDescription().getLabel());
Log.d("Drag:", "Posición: " + position + " es categoria:" + v.getTransitionName()+" "+viewgroup.getTransitionName());
// 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.picto_category_grid_view) || viewgroup == findViewById(R.id.picto_main_grid_view))) {
Picto p = viewgroup == findViewById(R.id.picto_category_grid_view) ? pictoCategoryGridAdapter.getItem(position)
: pictoMainGridAdapter.getItem(position);
if (!p.is_category()) addPictoWord(view, p);
}
// Si el destino es el panel y el origen la cinta de frase
else if (v == findViewById(R.id.picto_category_grid_view) && viewgroup == findViewById(R.id.tape_grid_view)) {
Picto p = tapeAdapter.getItem(position);
tapeAdapter.deleteItem(position);
tapeAdapter.notifyDataSetChanged();
getCurrentPictoGridAdapter().pictoInGrid(p);
getCurrentPictoGridAdapter().notifyDataSetChanged();
}
break;
//the drag and drop operation has concluded.
case DragEvent.ACTION_DRAG_ENDED:
// v.setBackground(normalShape); //go back to normal shape
default:
break;
}
return false;
}
}
/**f
* Class used for picto clicking feedback
*/
private class OnPictoClickListener implements AdapterView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (inserting) return;
Picto p = getCurrentPictoGridAdapter().getItem(position);
if (p != null && p.get_id() != 0 && !p.is_invisible() && p.is_enabled()) {
p.set_mirror(false, false);
// If the picto is a category
if (p.is_category()) {
currentCategory = p;
PCBcontext.getActionLog().log(new TalkAction(TalkAction.SELECT, p));
hidePictoMainGridView();
} else if (tapeAdapter.getCount() < VocabularyViewer.this.maxInTape && !VocabularyViewer.this.tapeAdapter.play()) {
addPictoWord(parent.getChildAt(position),p);
}
}
}
}
/**
*
* @param view
* @param p
*/
private void addPictoWord(View view, Picto p) {
tapeAdapter.addItem(p);
getCurrentPictoGridAdapter().pictoInTape(view,p);
currentCategory = null;
tapeAdapter.notifyDataSetChanged();
showPictoMainGridView();
PCBcontext.getActionLog().log(new TalkAction(TalkAction.ADD, p));
if (VocabularyViewer.this.feedback_read && !VocabularyViewer.this.tapeAdapter.play() && !p.is_category()) {
File audioFile = p.get_audioFile();
Log.e(LOG_TAG,"AUDIO:"+(audioFile!=null)+":"+p.get_audioPath());
if (audioFile != null)
VocabularyViewer.this.tts.playRecord(audioFile);
else
VocabularyViewer.this.tts.play(p.get_translation());
}
if (VocabularyViewer.this.feedback_highlight) execHighligthFeeback(p, false);
}
/**
*
* @param picto
* @param highlight_background
*/
private void execHighligthFeeback(final Picto picto, boolean highlight_background) {
boolean same_picto = false;
picto.set_mirror(true, highlight_background); //comienza feedback
if (exec_mirror != null) { //se cancela ejecución del feedbcack anterior, si lo hay
exec_mirror.shutdown();
exec_mirror = null;
}
if (prev_picto != null) { //se cancela marca de feedback del anterior, si lo hay
prev_picto.set_mirror(false, false);
same_picto = prev_picto == picto;
}
if (same_picto)
prev_picto = null; //por si se pulsaa el mismo boton varias veces
else {
prev_picto = picto;
exec_mirror = new ScheduledThreadPoolExecutor(1);
prev_picto = picto;
exec_mirror.scheduleAtFixedRate(new Runnable() {
int repeating = 0;
@Override
public void run() {
refresh();
if (repeating++ == 20) {
picto.set_mirror(false, false);
if (exec_mirror != null) {
exec_mirror.shutdown();
exec_mirror = null;
}
}
}
}, 0, 250, TimeUnit.MILLISECONDS);
}
}
// TODO: REVISAR
/**
* 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 (getCurrentCategory() != null || *//*!PCBcontext.getPcbdb().getCurrentUser().has_categories()*//*!PCBcontext.getVocabulary().has_categories()) {
int cat = getCurrentCategory() != null ? currentCategory.get_id() : Picto.NO_CATEGORY;
new PictoMenu(VocabularyViewer.this).createMenuForNewPicto(position % maxColumns, (int) (position / maxColumns), cat);
} else
Toast.makeText(VocabularyViewer.this, VocabularyViewer.this.getResources().getString(R.string.notNewCats), Toast.LENGTH_SHORT).show();
} else {
//Si es supervisor hacer aparecer el menú de opciones del picto
new PictoMenu(VocabularyViewer.this).createMenuForPicto(PCBcontext.getPcbdb().getCurrentUser().is_picto_size_big(),p);
getCurrentPictoGridAdapter().notifyDataSetChanged();
}
} 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() < VocabularyViewer.this.maxInTape) {
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) {
LinkedList<Picto> lp = tapeAdapter.getAll();
// This triggers the "Show" websocket action SI hay algo en la cinta y esta no está vacia
if (lp.size()>0 && !VocabularyViewer.this.tapeAdapter.play()) {
PCBcontext.getActionLog().log(new PictosAction(lp));
tapeAdapter.ttsAllNew(tts);
new PictoAnimation().animateTapeView(VocabularyViewer.this,0,(ViewGroup)arg0.getParent());
if (PCBcontext.getPcbdb().getCurrentUser().delivery()!= User.JSON_STUDENT_ATTTRS.delivery.clean) {
showOnlyTape(true);
}
}
}
}
/**
*
* @param onlyTape
*/
protected void showOnlyTape(boolean onlyTape) {
boolean tape_delivered_prev=this.tape_delivered;
Log.e(LOG_TAG,"ONLY TAPE->"+onlyTape+" "+ttsButton.isEnabled());
this.tape_delivered=onlyTape;
if (onlyTape) {
if (!tape_delivered_prev) {
if (PCBcontext.getPcbdb().getCurrentUser().delivery()== User.JSON_STUDENT_ATTTRS.delivery.one)
ttsButton.setEnabled(false);
Log.e(LOG_TAG,"ONLY TAPE0->"+onlyTape+" "+ttsButton.isEnabled());
if (this.pictoMainGridView.getAnimation() != this.hidePictoMainViewAnimation) {
this.showPictoCategoriesViewButton.setVisibility(View.INVISIBLE);
this.pictoCategoryGridView.setVisibility(View.INVISIBLE);
this.pictoMainGridView.setAlpha(0.25f);
this.pictoMainGridView.setEnabled(false);
} else {
this.pictoCategoryGridView.setAlpha(0.25f);
this.pictoCategoryGridView.setEnabled(false);
this.showPictoCategoriesViewButton.setAlpha(0f);
}
new PictoAnimation().animateTapeViewVertical(this, false);
}
}
else {
ttsButton.setEnabled(true);
ttsButton.refreshDrawableState();
Log.e(LOG_TAG,"ONLY TAPE1->"+onlyTape+" "+ttsButton.isEnabled());
new PictoAnimation().animateTapeViewVertical(this,true);
if (this.pictoMainGridView.getAnimation() != this.hidePictoMainViewAnimation) {
this.showPictoCategoriesViewButton.setVisibility(View.VISIBLE);
this.pictoCategoryGridView.setVisibility(View.VISIBLE);
this.pictoMainGridView.setAlpha(1f);
this.pictoMainGridView.setEnabled(true);
this.showPictoCategoriesViewButton.setAlpha(1f);
}
else {
this.pictoCategoryGridView.setAlpha(1f);
this.pictoCategoryGridView.setEnabled(true);
this.showPictoCategoriesViewButton.setAlpha(1f);
}
}
}
/**
* 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
Picto last=tapeAdapter.deleteLastView();
tapeAdapter.notifyDataSetChanged();
if (pictoMainGridAdapter.pictoInThisCategory(last))
pictoMainGridAdapter.pictoInGrid(last);
if (pictoCategoryGridAdapter.pictoInThisCategory(last))
pictoCategoryGridAdapter.pictoInGrid(last);
}
if (!tapeAdapter.hasElements() && tape_delivered) showOnlyTape(false);
}
}
/**
* 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) {
//TODO: COMPROBAR SI LOS USUARIOS QUE BUSCO EXISTEN: SI NO PONER LOS DATOS POR DEFECTO*******************************************************************/
//Cojo los id del ultimo estudiante y el ultimo supervisor
int lastIdStu = PCBcontext.getDevice().getLastStuId();
User actual = PCBcontext.getPcbdb().getCurrentUser();
User usuario_anterior;
String lastUserName = null;
String lastPassword = null;
if (actual.is_supervisor()) //Si el que habia es supervisor busco el ultimo niño
try {
usuario_anterior = PCBcontext.getDevice().findUser(lastIdStu, User.NO_SUPERVISOR);
if (usuario_anterior != null) {
lastUserName = usuario_anterior.get_nickname_stu();
lastPassword = usuario_anterior.get_pwd_stu();
}
} catch (JSONException e) {
e.printStackTrace();
}
else {
int lastIdSup = PCBcontext.getDevice().getLastSupId();
try {
usuario_anterior = PCBcontext.getDevice().findUser(lastIdStu, lastIdSup);
if (usuario_anterior != null) {
lastUserName = usuario_anterior.get_email_sup();
lastPassword = usuario_anterior.get_pwd_sup();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
Intent serialActivity = new Intent(getBaseContext(), com.yottacode.pictogram.tabletlibrary.gui.login.SerialActivity.class);
if (lastUserName != null) {
Log.i(this.getClass().getCanonicalName(), "Switch user to " + lastUserName);
serialActivity.putExtra("switch_usr", lastUserName);
serialActivity.putExtra("switch_pwd", lastPassword);
}
pictoCategoryGridAdapter.notifyDataSetInvalidated();
pictoMainGridAdapter.notifyDataSetInvalidated();
VocabularyViewer.this.finish();
if (SessionActivity.session!=null) SessionActivity.session.finish();
PCBcontext.getNetService().restart_app(true);
}
return true;
}
}
/**
* Listener used for bringing back the picto categories grid when clicked.
*/
private class OnShowPictoCategoriesViewButtonClick implements View.OnClickListener {
@Override
public void onClick(View v) {
showPictoMainGridView();
}
}
/*@Override
public boolean dispatchTouchEvent(MotionEvent event) {
int in=0,out=0;
Intent nextActivity=null;
Intent intent = getIntent();
boolean student_view=intent.getBooleanExtra("student_view",false);
if (PCBcontext.getPcbdb()!=null && (PCBcontext.getPcbdb().getCurrentUser().is_supervisor() || student_view) ) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
firstTouchX = event.getX();
break;
case MotionEvent.ACTION_UP:
if (event.getX() > firstTouchX + 150) { //izquierda a derecha
if (!student_view || !PCBcontext.getPcbdb().getCurrentUser().is_teacher()) {
PCBcontext.getPcbdb().getCurrentUser().get_Img_sup().update_id(student_view ? PCBcontext.getDevice().getLastSupId() : User.NO_SUPERVISOR);
nextActivity = intent;
} else
if (!PCBcontext.getNetService().online())
GUITools.show_alert(VocabularyViewer.this, R.string.session_noinet);
else {
PCBcontext.getPcbdb().getCurrentUser().get_Img_sup().update_id(PCBcontext.getDevice().getLastSupId());
nextActivity = new Intent(this, SessionActivity.class);
}
in = R.anim.rightin;
out = R.anim.rightout;
overridePendingTransition(R.anim.leftin, R.anim.leftout);
} else if (firstTouchX > event.getX() + 150) { //derecha a izquierda
if (!student_view && PCBcontext.getPcbdb().getCurrentUser().is_teacher() ) {
if (!PCBcontext.getNetService().online())
GUITools.show_alert(VocabularyViewer.this, R.string.session_noinet);
else
nextActivity = new Intent(this, SessionActivity.class);
} else {
PCBcontext.getPcbdb().getCurrentUser().get_Img_sup().update_id(student_view ? PCBcontext.getDevice().getLastSupId() : User.NO_SUPERVISOR);
nextActivity = intent;
}
in = R.anim.leftin;
out = R.anim.leftout;
}
if (nextActivity != null) {
tape_delivered=false;
intent.putExtra("student_view", !PCBcontext.getPcbdb().getCurrentUser().is_supervisor());
finish();
startActivity(nextActivity);
overridePendingTransition(in, out);
}
break;
}
}
return super.dispatchTouchEvent(event);
}*/
/**
* Para capturar el evento para abrir camara o galeria y procesar
* @param requestCode
* @param resultCode
* @param data
*/
/*protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Bitmap imagen;
switch(requestCode) {
case CAMERA_PIC_REQUEST: //Captura de foto
if (data != null && resultCode==RESULT_OK) {
imagen = (Bitmap) data.getExtras().get("data");
this.launchEditPictoActivity(imagen);
}
break;
case GALLERY_PIC_REQUEST: //Galeria
if(data!=null){
Uri selectedImage = data.getData();
Bitmap bitmap = null;
try {
bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImage);
} catch (IOException e) {
e.printStackTrace();
}
this.launchEditPictoActivity(bitmap);
}
break;
case EditPictoActivity.EDIT_PICTO_REQUEST:
if (resultCode == RESULT_OK) {
boolean edit = data.getBooleanExtra(PictoMenu.IS_EDIT,false);
int row = edit ? data.getExtras().getInt(Picto.JSON_ATTTRS.ROW) : getIntent().getIntExtra(Picto.JSON_ATTTRS.ROW, -1);
int col = edit ? data.getExtras().getInt(Picto.JSON_ATTTRS.COLUMN) : getIntent().getIntExtra(Picto.JSON_ATTTRS.COLUMN, -1);
int freeRow = edit ? data.getExtras().getInt(Picto.JSON_ATTTRS.FREE_ROW) : getIntent().getIntExtra(Picto.JSON_ATTTRS.FREE_ROW, -1);
int freeColumn = edit ? data.getExtras().getInt(Picto.JSON_ATTTRS.FREE_COLUMN) : getIntent().getIntExtra(Picto.JSON_ATTTRS.FREE_COLUMN, -1);
String path_sound = data.getExtras().getString(PictoMenu.PATH_SOUND);
String user_avatar = data.getExtras().getString(Picto.JSON_ATTTRS.USER_AVATAR)*//* : getIntent().getStringExtra(Picto.JSON_ATTTRS.USER_AVATAR, "----")*//*;
int cat = edit ? data.getIntExtra(Picto.JSON_ATTTRS.CATEGORY, -1) : getIntent().getIntExtra(Picto.JSON_ATTTRS.CATEGORY, -1);
String path = data.getExtras().getString(PictoMenu.PATH);
String legend = data.getExtras().getString(Picto.JSON_ATTTRS.EXPRESSION);
chooseTextAndSavePicto(path, row, col, freeRow, freeColumn, cat, legend, path_sound ,user_avatar);
refresh();
}
break;
}
}*/
/**
* 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, final int freeRow, final int freeColumn,
final int category, final String legend,final String path_sound ,final String user_avatar) {
// Set up the buttons
PCBcontext.getVocabulary().saveLocalPicto(
selectedImagePath,
legend,
category,
row,
col,
freeRow,
freeColumn,
user_avatar,
path_sound,
new iLocalPicto() {
@Override
public void saved(Picto localPicto) {
refresh();
try {
if (PCBcontext.is_user_online())
new PictoUploader(localPicto).upload();
} catch (IOException e) {
Log.e(Vocabulary.class.getCanonicalName(), e.getMessage());
}
}
});
}*/
/**Para cambiar la activity de VocabularyViewer a EditPictoActivity
* @param image
*/
/*public void launchEditPictoActivity(Bitmap image){
Intent intent = new Intent(this, EditPictoActivity.class);
BitmapTools.save_temporal(image);
startActivityForResult(intent, EditPictoActivity.EDIT_PICTO_REQUEST);
}*/
}
......@@ -23,7 +23,6 @@ import com.yottacode.pictogram.dao.User;
import com.yottacode.pictogram.dao.UserLogin;
import com.yottacode.pictogram.tabletlibrary.R;
import com.yottacode.pictogram.tabletlibrary.gui.communicator.VOCA;
import com.yottacode.pictogram.tabletlibrary.gui.communicator.VocabularyViewer;
import com.yottacode.pictogram.tabletlibrary.net.NetServiceTablet;
import com.yottacode.pictogram.tools.PCBcontext;
......@@ -100,7 +99,7 @@ public class SerialActivity extends Activity {
editor.putString("password", supUsers.elementAt(position).get_pwd_sup());
editor.commit();
new UserLogin().login(supUsers.elementAt(position).get_email_sup(),
supUsers.elementAt(position).get_pwd_sup(), SerialActivity.this, VocabularyViewer.class, LoginActivity.class);
supUsers.elementAt(position).get_pwd_sup(), SerialActivity.this, VOCA.class, LoginActivity.class);
}
}
});
......@@ -134,7 +133,7 @@ public class SerialActivity extends Activity {
editor.putString("password", stuUsers.elementAt(position).get_pwd_stu());
editor.commit();
new UserLogin().login(stuUsers.elementAt(position).get_nickname_stu(),
stuUsers.elementAt(position).get_pwd_stu(),SerialActivity.this, VocabularyViewer.class, LoginActivity.class);
stuUsers.elementAt(position).get_pwd_stu(),SerialActivity.this, VOCA.class, LoginActivity.class);
}
});
}
......@@ -173,7 +172,7 @@ public class SerialActivity extends Activity {
editor.putString("password", password);
editor.commit();
if (!username.equals("") && !password.equals(""))
new UserLogin().login(username, password, SerialActivity.this, VocabularyViewer.class, LoginActivity.class);
new UserLogin().login(username, password, SerialActivity.this, VOCA.class, LoginActivity.class);
}
});
......@@ -194,7 +193,7 @@ public class SerialActivity extends Activity {
mSerialViewPass.setText(password);
if (!username.equals("") && !password.equals("") && !getIntent().getBooleanExtra("resetPrevUser", true))
new UserLogin().login(username, password, SerialActivity.this, VocabularyViewer.class, LoginActivity.class);
new UserLogin().login(username, password, SerialActivity.this, VOCA.class, LoginActivity.class);
super.onStart();
try {
......
......@@ -17,7 +17,7 @@ import com.yottacode.net.RestapiWrapper;
import com.yottacode.pictogram.dao.User;
import com.yottacode.pictogram.net.ImgDownloader;
import com.yottacode.pictogram.tabletlibrary.R;
import com.yottacode.pictogram.tabletlibrary.gui.communicator.VocabularyViewer;
import com.yottacode.pictogram.tabletlibrary.gui.communicator.VOCA;
import com.yottacode.pictogram.tools.Img;
import com.yottacode.pictogram.tools.PCBcontext;
import com.yottacode.tools.GUITools;
......@@ -80,7 +80,7 @@ public class StudentFragmentGrid extends Fragment{
Log.e(StudentFragmentGrid.this.getClass().getCanonicalName(), e.getMessage());
}
PCBcontext.set_user(currentUser, null, null);
Intent pictogramActivity = new Intent(getActivity(), VocabularyViewer.class);
Intent pictogramActivity = new Intent(getActivity(), VOCA.class);
startActivity(pictogramActivity);
} else {
new_user(i);
......@@ -124,7 +124,7 @@ public class StudentFragmentGrid extends Fragment{
@Override
public void loadComplete() {
if (progressDialog!=null && progressDialog.isShowing()) progressDialog.dismiss();
Intent pictogramActivity = new Intent(getActivity(), VocabularyViewer.class);
Intent pictogramActivity = new Intent(getActivity(), VOCA.class);
startActivity(pictogramActivity);
}
......
......@@ -15,7 +15,7 @@ import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import com.yottacode.pictogram.tabletlibrary.gui.communicator.VocabularyViewer;
import com.yottacode.pictogram.tabletlibrary.gui.communicator.VOCA;
import com.yottacode.pictogram.tabletlibrary.net.SessionWrapper;
import com.yottacode.pictogram.tabletlibrary.R;
import com.yottacode.pictogram.tools.PCBcontext;
......@@ -116,7 +116,7 @@ public class ListInstructionsFragment extends Fragment{
}
void close() {
ListInstructionsFragment.this.getActivity().finish();
startActivity(new Intent(getActivity(), VocabularyViewer.class));
startActivity(new Intent(getActivity(), VOCA.class));
}
private void checkStudent() {
SessionWrapper.validateStudent(new SessionWrapper.iValidateStudent() {
......
......@@ -21,7 +21,7 @@ import android.widget.ToggleButton;
import com.yottacode.pictogram.dao.User;
import com.yottacode.pictogram.net.NetService;
import com.yottacode.pictogram.tabletlibrary.R;
import com.yottacode.pictogram.tabletlibrary.gui.communicator.VocabularyViewer;
import com.yottacode.pictogram.tabletlibrary.gui.communicator.VOCA;
import com.yottacode.pictogram.tabletlibrary.net.SessionWrapper;
import com.yottacode.pictogram.tools.PCBcontext;
import com.yottacode.tools.GUITools;
......@@ -273,13 +273,13 @@ public class SessionActivity extends FragmentActivity implements ListInstruction
break;
case MotionEvent.ACTION_UP:
if (event.getX()> firstTouchX+100) { //izquierda->derecha
nextActivity=new Intent(this,VocabularyViewer.class);
nextActivity=new Intent(this,VOCA.class);
nextActivity.putExtra("student_view", false);
in=R.anim.rightin;
out=R.anim.rightout;
}
else if (firstTouchX > event.getX()+100) { //derecha->izquierda
nextActivity=new Intent(this,VocabularyViewer.class);
nextActivity=new Intent(this,VOCA.class);
nextActivity.putExtra("student_view", true);
PCBcontext.getPcbdb().getCurrentUser().get_Img_sup().update_id(User.NO_SUPERVISOR);
in=R.anim.leftin;
......@@ -345,7 +345,7 @@ public class SessionActivity extends FragmentActivity implements ListInstruction
}
void close() {
finish();
startActivity(new Intent(SessionActivity.this, VocabularyViewer.class));
startActivity(new Intent(SessionActivity.this, VOCA.class));
}
private void set_fragment(boolean isChecked, final ToggleButton onoffBtn) {
if (isChecked) {
......
......@@ -12,7 +12,7 @@ import android.util.Log;
import com.yottacode.pictogram.dao.User;
import com.yottacode.pictogram.net.NetService;
import com.yottacode.pictogram.tabletlibrary.R;
import com.yottacode.pictogram.tabletlibrary.gui.communicator.VocabularyViewer;
import com.yottacode.pictogram.tabletlibrary.gui.communicator.VOCA;
import com.yottacode.pictogram.tools.PCBcontext;
/**
......@@ -25,15 +25,15 @@ public class NetServiceTablet implements NetService.iNetServiceDevice {
private static final String LOG_TAG = NetServiceTablet.class.getName();
private static NotificationCompat.Builder builder;
private VocabularyViewer vocabularyViewer;
private VOCA VOCA;
int notifyID = 666;
public void build() {
this.builder = new NotificationCompat.Builder(PCBcontext.getContext()).setAutoCancel(true).setOngoing(PCBcontext.getContext().getResources().getBoolean(R.bool.NotifyAllwaysVisible));
Intent resultIntent = new Intent(PCBcontext.getContext(), VocabularyViewer.class);
Intent resultIntent = new Intent(PCBcontext.getContext(), VOCA.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(PCBcontext.getContext());
stackBuilder.addParentStack(VocabularyViewer.class);
stackBuilder.addParentStack(VOCA.class);
stackBuilder.addNextIntent(resultIntent);
if (PCBcontext.getContext().getResources().getBoolean(R.bool.NotifyAllwaysVisible)){
PendingIntent resultPendingIntent =
......@@ -96,8 +96,8 @@ public class NetServiceTablet implements NetService.iNetServiceDevice {
context.startActivity(serialActivity);
}
public void setVocabularyViewer(VocabularyViewer vocabularyViewer) {this.vocabularyViewer = vocabularyViewer;}
public void setVOCA(VOCA VOCA) {this.VOCA = VOCA;}
public void updateUserConfig(User user) {
if (this.vocabularyViewer !=null) this.vocabularyViewer.setConfig();
if (this.VOCA !=null) this.VOCA.setConfig();
}
}
......@@ -7,7 +7,7 @@
android:orientation="horizontal"
android:background="#BDBDBD"
android:keepScreenOn="true"
tools:context="com.yottacode.pictogram.tabletlibrary.gui.communicator.VocabularyViewer"
tools:context="com.yottacode.pictogram.tabletlibrary.gui.communicator.VOCA"
android:padding="@dimen/small_padding">
<RelativeLayout
......
......@@ -7,7 +7,7 @@
android:orientation="horizontal"
android:background="#BDBDBD"
android:keepScreenOn="true"
tools:context="com.yottacode.pictogram.tabletlibrary.gui.communicator.VocabularyViewer"
tools:context="com.yottacode.pictogram.tabletlibrary.gui.communicator.VOCA"
android:padding="@dimen/small_padding">
<RelativeLayout
......
......@@ -62,13 +62,6 @@
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
......@@ -76,6 +69,13 @@
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/annotations" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
......@@ -121,5 +121,16 @@
<orderEntry type="library" exported="" name="play-services-ads-9.2.1" level="project" />
<orderEntry type="library" exported="" name="play-services-ads-lite-9.2.1" level="project" />
<orderEntry type="module" module-name="commonlibrary" exported="" />
<orderEntry type="library" exported="" name="okhttp-ws-2.3.0" level="project" />
<orderEntry type="library" exported="" name="socket.io-client-0.5.0" level="project" />
<orderEntry type="library" exported="" name="okhttp-2.3.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-23.0.0" level="project" />
<orderEntry type="library" exported="" name="okio-1.3.0" level="project" />
<orderEntry type="library" exported="" name="gson-2.3" level="project" />
<orderEntry type="library" exported="" name="engine.io-client-0.5.0" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-21.0.3" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-core-1.3" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="junit-4.12" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="json-20090211" level="project" />
</component>
</module>
\ No newline at end of file
......@@ -50,7 +50,7 @@
android:label="@string/title_activity_login_activity_fragments"
android:screenOrientation="landscape" />
<activity
android:name="com.yottacode.pictogram.tabletlibrary.gui.communicator.VocabularyViewer"
android:name="com.yottacode.pictogram.tabletlibrary.gui.communicator.VOCA"
android:exported="true"
android:label="@string/app_name"
android:launchMode="singleTop"
......
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