working on PCB core vocabulary preloaded

parent fb7fb727
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" /> <excludeFolder url="file://$MODULE_DIR$/.gradle" />
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
</module> </module>
\ No newline at end of file
...@@ -3,6 +3,7 @@ package com.yottacode.pictogram.dao; ...@@ -3,6 +3,7 @@ package com.yottacode.pictogram.dao;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.content.res.AssetManager;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory; import android.database.sqlite.SQLiteDatabase.CursorFactory;
...@@ -11,9 +12,12 @@ import android.os.AsyncTask; ...@@ -11,9 +12,12 @@ import android.os.AsyncTask;
import android.util.Log; import android.util.Log;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream;
import java.util.Vector; import java.util.Vector;
...@@ -21,6 +25,7 @@ import com.yottacode.pictogram.gui.LoginActivity; ...@@ -21,6 +25,7 @@ import com.yottacode.pictogram.gui.LoginActivity;
import com.yottacode.pictogram.tools.Img; import com.yottacode.pictogram.tools.Img;
import com.yottacode.pictogram.net.ImgDownloader; import com.yottacode.pictogram.net.ImgDownloader;
import com.yottacode.pictogram.net.iImgDownloaderListener; import com.yottacode.pictogram.net.iImgDownloaderListener;
import com.yottacode.pictogram.tools.PCBcontext;
import org.json.JSONException; import org.json.JSONException;
...@@ -406,14 +411,63 @@ public class Device extends SQLiteOpenHelper { ...@@ -406,14 +411,63 @@ public class Device extends SQLiteOpenHelper {
public void onCreate(SQLiteDatabase db) throws RuntimeException { public void onCreate(SQLiteDatabase db) throws RuntimeException {
try { try {
executeSQLScript(db, DeviceHelper.getDBScriptStream(this.context)); executeSQLScript(db, DeviceHelper.getDBScriptStream(this.context));
copyCoreVocabulary();
Img.mkDirs(this.context); Img.mkDirs(this.context);
} catch (java.io.IOException io) { } catch (java.io.IOException io) {
throw new RuntimeException("Update database error", io); throw new RuntimeException("Update database error", io);
} }
} }
@Override private void copyCoreVocabulary() {
AssetManager assetManager = this.context.getAssets();
String[] files = null;
try {
files = assetManager.list("core_vocabulary");
} catch (IOException e) {
Log.e(this.getClass().getCanonicalName(), "Failed to get asset file list.", e);
}
if (files != null) for (String filename : files) {
InputStream in = null;
OutputStream out = null;
try {
in = assetManager.open("core_vocabulary/"+"java"+"/"+filename);
File outFile = new File(Img.path(this.context, Img.VOCABULARY));
out = new FileOutputStream(outFile);
copyFile(in, out);
} catch(IOException e) {
Log.e(this.getClass().getCanonicalName(), "Failed to copy asset file: " + filename, e);
}
finally {
if (in != null) {
try {
in.close();
Log.i(Device.class.getName(), "Core vocabulary copied ("+files.length+" pictos)");
} catch (IOException e) {
Log.e(this.getClass().getCanonicalName(), "Failed to copy asset file: " + filename, e);
}
}
if (out != null) {
try {
out.close();
} catch (IOException e) {
Log.e(this.getClass().getCanonicalName(), "Failed to copy asset file: " + filename, e);
}
}
}
}
}
private void copyFile(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[8192];
int read;
while((read = in.read(buffer)) != -1){
out.write(buffer, 0, read);
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
} }
} }
\ No newline at end of file
...@@ -69,4 +69,4 @@ public class PictoGridAdapter extends ArrayAdapter { ...@@ -69,4 +69,4 @@ public class PictoGridAdapter extends ArrayAdapter {
tts.speak(input, TextToSpeech.QUEUE_FLUSH, params, null); tts.speak(input, TextToSpeech.QUEUE_FLUSH, params, null);
} }
} }
} }
\ No newline at end of file
package com.yottacode.pictogram.gui; package com.yottacode.pictogram.gui;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
...@@ -40,7 +41,11 @@ public class PictoItemViewGenerator { ...@@ -40,7 +41,11 @@ public class PictoItemViewGenerator {
pictoImage.setScaleY(1.0f); pictoImage.setScaleY(1.0f);
pictoImage.setVisibility(View.GONE); pictoImage.setVisibility(View.GONE);
if (picto != null) { if (picto==null) {
layoutWrapper.setVisibility(View.VISIBLE);
layoutWrapper.setBackground(convertView.getResources()
.getDrawable(R.drawable.picto_grid_item_border));
} else {
if (!picto.is_invisible() && !picto.is_disabled()) { if (!picto.is_invisible() && !picto.is_disabled()) {
layoutWrapper.setAlpha(1.00f); layoutWrapper.setAlpha(1.00f);
} }
......
...@@ -594,10 +594,13 @@ public class PictogramActivity extends Activity implements iVocabularyListener, ...@@ -594,10 +594,13 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
*/ */
private class OnPictoLongClickListener implements AdapterView.OnItemLongClickListener { private class OnPictoLongClickListener implements AdapterView.OnItemLongClickListener {
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
Log.d(LOG_TAG, "long click 1");
if (PCBcontext.getPcbdb().getCurrentUser().is_supervisor()) { if (PCBcontext.getPcbdb().getCurrentUser().is_supervisor()) {
Log.d(LOG_TAG, "long click 2");
// Si es supervisor al hacer longClick deshabilito ese pictograma o lo habilito // Si es supervisor al hacer longClick deshabilito ese pictograma o lo habilito
Picto p = getCurrentPictoGridAdapter().getItem(position); Picto p = getCurrentPictoGridAdapter().getItem(position);
if (p == null) { if (p == null) {
Log.d(LOG_TAG, "long click 3");
// No tengo pictograma. Abro una nueva ventana de selección desde el Carrete del device si no es categoria // No tengo pictograma. Abro una nueva ventana de selección desde el Carrete del device si no es categoria
if (currentCategory != null) { if (currentCategory != null) {
Log.d(LOG_TAG, "No tengo pictograma. Abro carrete..."); Log.d(LOG_TAG, "No tengo pictograma. Abro carrete...");
...@@ -608,7 +611,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener, ...@@ -608,7 +611,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
} else { } else {
p.alter_status(); p.alter_status();
showPictoMainGridView(); pictoCategoryGridAdapter.notifyDataSetChanged();
} }
} else { } else {
ClipData.Item item = new ClipData.Item("" + position); ClipData.Item item = new ClipData.Item("" + position);
......
...@@ -131,6 +131,7 @@ public class StudentFragmentGrid extends Fragment{ ...@@ -131,6 +131,7 @@ public class StudentFragmentGrid extends Fragment{
} }
}); });
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
Log.e(StudentFragmentGrid.this.getClass().getCanonicalName(), e.getMessage()); Log.e(StudentFragmentGrid.this.getClass().getCanonicalName(), e.getMessage());
...@@ -290,4 +291,4 @@ public class StudentFragmentGrid extends Fragment{ ...@@ -290,4 +291,4 @@ public class StudentFragmentGrid extends Fragment{
if (offline || onlineStudentsOK) showStudentsGrid(); if (offline || onlineStudentsOK) showStudentsGrid();
return view; return view;
} }
} }
\ No newline at end of file
...@@ -157,7 +157,7 @@ public class NetService implements Runnable { ...@@ -157,7 +157,7 @@ public class NetService implements Runnable {
if (updated) if (updated)
builder.setSmallIcon(R.drawable.application_online) builder.setSmallIcon(R.drawable.application_online)
.setContentTitle("Pictogram online") .setContentTitle("Pictogram online")
.setContentText(PCBcontext.getContext().getResources().getString(R.string.pictogram_online)); .setContentText(PCBcontext.getContext().getResources().getString(R.string.pictogram_online)+":"+PCBcontext.getContext().getResources().getString(R.string.server));
else else
builder.setSmallIcon(R.drawable.application_offline) builder.setSmallIcon(R.drawable.application_offline)
.setContentTitle("Pictogram offline") .setContentTitle("Pictogram offline")
...@@ -168,4 +168,4 @@ public class NetService implements Runnable { ...@@ -168,4 +168,4 @@ public class NetService implements Runnable {
// mId allows you to update the notification later on. // mId allows you to update the notification later on.
mNotificationManager.notify(notifyID, builder.build()); mNotificationManager.notify(notifyID, builder.build());
} }
} }
\ No newline at end of file
package com.yottacode.pictogram.net; package com.yottacode.pictogram.net;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log; import android.util.Log;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
...@@ -11,6 +13,7 @@ import com.yottacode.pictogram.action.VocabularyAction; ...@@ -11,6 +13,7 @@ import com.yottacode.pictogram.action.VocabularyAction;
import com.yottacode.pictogram.dao.Picto; import com.yottacode.pictogram.dao.Picto;
import com.yottacode.pictogram.tools.Img; import com.yottacode.pictogram.tools.Img;
import com.yottacode.pictogram.tools.PCBcontext; import com.yottacode.pictogram.tools.PCBcontext;
import com.yottacode.tools.BitmapTools;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
...@@ -33,15 +36,21 @@ public class PictoUploader { ...@@ -33,15 +36,21 @@ public class PictoUploader {
private int uploadImg( Img img) throws UnsupportedEncodingException { private int uploadImg( Img img) throws UnsupportedEncodingException {
int img_id; int img_id;
Bitmap bmp=null;
if (!img.get_filetype().equalsIgnoreCase("png")) if (!img.get_filetype().equalsIgnoreCase("png"))
throw new UnsupportedEncodingException("Extension "+img.get_filetype()+" is not supported. Only png files"); throw new UnsupportedEncodingException("Extension "+img.get_filetype()+" is not supported. Only png files");
Ion ion = Ion.getDefault(PCBcontext.getContext()); Ion ion = Ion.getDefault(PCBcontext.getContext());
try {
Log.i(this.getClass().getCanonicalName(), "Uploading Picto img" + img.file_name() + " from " + img.get_type() + "size:" + img.get_bitmap(PCBcontext.getContext()).getWidth() + " " + img.get_bitmap(PCBcontext.getContext()).getHeight()); try {
} catch (IOException e) { bmp=img.get_bitmap(PCBcontext.getContext());
Log.i(this.getClass().getCanonicalName(), "Uploading Picto img" + img.file_name() + " from " + img.get_type()); } catch (IOException e) {
} Log.e(Img.class.getCanonicalName(), "Error when decoding "+img.file_name());
}
Log.i(this.getClass().getCanonicalName(), "Uploading Picto img" + img.file_name() + " from " + img.get_type() + "size:" + bmp.getWidth() + " " + bmp.getHeight());
File file = img.file(PCBcontext.getContext()); File file = img.file(PCBcontext.getContext());
Response<JsonObject> response=null; Response<JsonObject> response=null;
...@@ -160,7 +169,6 @@ public class PictoUploader { ...@@ -160,7 +169,6 @@ public class PictoUploader {
* *
**/ **/
public void upload() throws IOException { public void upload() throws IOException {
int old_picto=this.picto.get_id();
int img_id = uploadImg(this.picto); int img_id = uploadImg(this.picto);
if (img_id > 0) { if (img_id > 0) {
uploadAttributes(img_id); uploadAttributes(img_id);
......
...@@ -27,7 +27,7 @@ public class Img { ...@@ -27,7 +27,7 @@ public class Img {
static public String VOCABULARY="vocabulary"; static public String VOCABULARY="vocabulary";
static public String STUDENT="student"; static public String STUDENT="student";
static public String SUPERVISOR="supervisor"; static public String SUPERVISOR="supervisor";
static public float MAX_WIDTH=100;
public static final void mkDirs(Context context) { public static final void mkDirs(Context context) {
File file; File file;
file = new File(path(context, Img.VOCABULARY)); file = new File(path(context, Img.VOCABULARY));
...@@ -126,7 +126,6 @@ public class Img { ...@@ -126,7 +126,6 @@ public class Img {
* @throws IOException * @throws IOException
*/ */
public int save_bitmap(Context context, InputStream is) throws IOException { public int save_bitmap(Context context, InputStream is) throws IOException {
final float MAX_WIDTH=100;
File file = file(context); File file = file(context);
FileOutputStream os = new FileOutputStream(file); FileOutputStream os = new FileOutputStream(file);
try { try {
......
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
<string name="serverError">There is a server error. Try again later</string> <string name="serverError">There is a server error. Try again later</string>
<!--Semantic grammar --> <!--Semantic grammar -->
<string name="loadingGrammar">Please wait, loading semmantic grammar</string> <string name="loadingGrammar">Please wait, loading vocabulary</string>
<string name="naturalgrammar">SUpO_EN</string> <string name="naturalgrammar">SUpO_EN</string>
<string name="pictogrammar">SUpO_PICTOEN</string> <string name="pictogrammar">SUpO_PICTOEN</string>
<string name="nogrammar">Warning: unknown language</string> <string name="nogrammar">Warning: unknown language</string>
......
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
<string name="serverError">Error en el servidor de datos. Inténtelo más tarde</string> <string name="serverError">Error en el servidor de datos. Inténtelo más tarde</string>
<!--Semantic grammar --> <!--Semantic grammar -->
<string name="loadingGrammar">Por favor espere, cargando gramática semántica</string> <string name="loadingGrammar">Por favor espere, cargando vocabulario</string>
<string name="naturalgrammar">SUpO_ES</string> <string name="naturalgrammar">SUpO_ES</string>
<string name="grammar">SUpO_ES</string> <string name="grammar">SUpO_ES</string>
<string name="nogrammar">Advertencia: Lenguaje no soportado</string> <string name="nogrammar">Advertencia: Lenguaje no soportado</string>
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
<dimen name="picto_grid_spacing">4dp</dimen> <dimen name="picto_grid_spacing">4dp</dimen>
<dimen name="picto_border_width">1dp</dimen> <dimen name="picto_border_width">1dp</dimen>
<dimen name="picto_padding">4dp</dimen> <dimen name="picto_padding">4dp</dimen>
<dimen name="picto_normal_height">80dp</dimen> <dimen name="picto_normal_height">75dp</dimen>
<dimen name="picto_normal_width">80dp</dimen> <dimen name="picto_normal_width">75dp</dimen>
<dimen name="tape_normal_height">100dp</dimen> <dimen name="tape_normal_height">90dp</dimen>
</resources> </resources>
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
<string name="serverError">Error en el servidor de datos. Inténtelo más tarde</string> <string name="serverError">Error en el servidor de datos. Inténtelo más tarde</string>
<!--Semantic grammar --> <!--Semantic grammar -->
<string name="loadingGrammar">Please wait, loading semmantic grammar</string> <string name="loadingGrammar">Please wait, loading vocabulary</string>
<string name="naturalgrammar">SUpO_EN</string> <string name="naturalgrammar">SUpO_EN</string>
<string name="grammar">SUpO_EN</string> <string name="grammar">SUpO_EN</string>
<string name="nogrammar">Warning: unknown language</string> <string name="nogrammar">Warning: unknown language</string>
...@@ -75,4 +75,4 @@ ...@@ -75,4 +75,4 @@
<string name="pictogram_offline">Compruebe si tiene conexión a Internet. </string> <string name="pictogram_offline">Compruebe si tiene conexión a Internet. </string>
<string name="pictogram_online">Conexón con el servidor establecida. </string> <string name="pictogram_online">Conexón con el servidor establecida. </string>
</string> </string>
</resources> </resources>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment