Commit ac0ad839 by Fernando Martínez Santiago

Merge branch 'master' of http://scm.ujaen.es/softuno/pictogram

parents b438422c e5eac320
......@@ -3,10 +3,12 @@ apply plugin: 'com.android.application'
android {
signingConfigs {
release_config {
/*
storeFile file('F:/Users/Fernando/GoogleDrive/tmp/keystore.jks')
keyAlias 'default_key'
keyPassword 'danoia'
storePassword 'danoia'
*/
}
}
compileSdkVersion 21
......@@ -23,7 +25,7 @@ android {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
resValue "string", "server", "https://pre.yottacode.com:1337"
resValue "string", "server", "https://pre.yottacode.com"
resValue "string", "db_name", "PCB.db"
resValue "bool", "force_db_create", "false"
resValue "bool", "ssl_connect", "false"
......@@ -52,7 +54,7 @@ android {
resValue "string", "server", "https://192.168.1.37:1337"
}
DefaultFlavor {
resValue "string", "server", "https://pre.yottacode.com:1337"
resValue "string", "server", "https://pre.yottacode.com"
signingConfig signingConfigs.release_config
}
ArturoFlavorNoSSL {
......
......@@ -37,17 +37,11 @@
android:name=".gui.MainActivity"
android:label="@string/app_name"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity
android:name=".gui.SerialActivity"
android:label="@string/title_activity_serial"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity
android:name=".gui.LoginActivity"
......@@ -55,17 +49,6 @@
android:label="@string/title_activity_login_activity_fragments"
android:screenOrientation="landscape"/>
<activity
android:name="com.yottacode.pictogrammar.UploadActivity"
android:label="@string/app_name"
android:launchMode="singleTop"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".gui.PictogramActivity"
android:exported="true"
android:label="@string/app_name"
......
......@@ -177,16 +177,15 @@ public class RestapiWrapper {
os.close();
int responseCode=urlConnection.getResponseCode();
if (responseCode == HttpsURLConnection.HTTP_OK) {
Log.d(LOG_TAG, "RESPONSECODE: " + responseCode);
String line;
BufferedReader br=new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
BufferedReader br = new BufferedReader(new InputStreamReader(responseCode == HttpsURLConnection.HTTP_OK
? urlConnection.getInputStream()
: urlConnection.getErrorStream()));
while ((line=br.readLine()) != null) {
response+=line;
}
}
else {
response="";
}
} catch (IOException e) {
Log.e(com.yottacode.net.RestapiWrapper.class.getName(), "Error:" + e.getLocalizedMessage() + " when asking for " + surl);
response=e.getMessage();
......@@ -228,6 +227,7 @@ public class RestapiWrapper {
@Override
protected void onPostExecute(HttpAsyncTaskParams params) {
try {
//if (params.e)
if(params.result!=null) {
Log.d(LOG_TAG, "JSON: " + params.result);
......
......@@ -33,6 +33,8 @@ import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Vector;
/**
......@@ -42,7 +44,7 @@ import java.util.Vector;
* @version 1.0
*/
public class LoginActivity extends FragmentActivity implements iRestapiListener {
public class LoginActivity extends FragmentActivity implements iRestapiListener{
private static final String TAG_ID = "id";
private static final String TAG_NAME = "name";
......@@ -154,8 +156,6 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener
public void result(JSONArray students_supervisors) { //FERNANDO
try {
// Saco los pares estudiante-supervisor
//Log.d(LOG_TAG, "JSON:"+students_supervisors);
Log.d(LOG_TAG, "students_supervisors size:" + students_supervisors.length());
// looping through All Students
Vector<User> users = new Vector<User>(students_supervisors.length());
......@@ -205,64 +205,73 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener
}
}
Log.d(LOG_TAG, "users size:" + users.size());
// Si sólo hay 1 estudiante, cargo el st_id
if (students_supervisors.length() == 1)
if (users.size() == 1){
//User student = PCBcontext.getDevice().findUser(st_id_int, sup_id);
PCBcontext.set_user(student, token, null); // no hay que hacer nada cuando termine
} else{
student = new User(-1, "", "", "", "M", "es-es", "",
sup_id, "", "", "", "M", "es-es", "");
PCBcontext.set_user(student, token, new iImgDownloaderListener() {
@Override
public void loadComplete() {
Log.d(LOG_TAG, "Images: Load images complete");
progressDialog.dismiss();
setContentView(R.layout.activity_login);
//close the progress dialog
//progressDialog.dismiss();
//setContentView(R.layout.activity_login);
}
// De la interfaz iImgDownloaderListener
@Override
public void loadImg(Img img) {
public void loadImg(Img image) {
//close the progress dialog
//progressDialog.dismiss();
//setContentView(R.layout.activity_login);
}
}); else{
student = new User(-1, "", "", "", "M", "es-es", "",
sup_id, "", "", "", "M", "es-es", "");
PCBcontext.set_user(student, token, null);
});
}
//Device device = new Device(getApplicationContext(), null, 1);
if (users.size() > 0){
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
String currentDateandTime = sdf.format(new Date());
Log.d(LOG_TAG, "Entro en synchronizeUsers en " + currentDateandTime);
PCBcontext.getDevice().synchronizeUsers(users, new iImgDownloaderListener() {
@Override
public void loadComplete() {
}
@Override
public void loadImg(Img img) {
Log.d(LOG_TAG, "Load a single image with ID: " + img.get_id());
// Aquí filtro si sólo tiene un único usuario o varios
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
String currentDateandTime = sdf.format(new Date());
Log.d(LOG_TAG, "LoadComplete en " + currentDateandTime);
Vector<User> users = null;
try {
users = PCBcontext.getDevice().getUsers();
} catch (JSONException e) {
e.printStackTrace();
}
if (users.size() > 1) {
//close the progress dialog
progressDialog.dismiss();
setContentView(R.layout.activity_login);
}
} catch (JSONException e) {
e.printStackTrace();
}
@Override
public void loadImg(Img image) {
}
});
PCBcontext.getDevice().deleteDeprecatedImgs();
// Si sólo hay 1 estudiante paso a Pictogram
if(users.size()==1)
{
if (users.size() == 1){
//close the progress dialog
progressDialog.dismiss();
Intent pictogramActivity = new Intent(this, PictogramActivity.class);
pictogramActivity.putExtra("isSupervisor",true);
startActivity(pictogramActivity);
}
}else{
} else {
AlertDialog.Builder builder =
new AlertDialog.Builder(this);
......@@ -289,7 +298,6 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener
public void result(JSONObject result) {
}
@Override protected void onResume() {
super.onResume();
Toast.makeText(this, "onResume", Toast.LENGTH_SHORT).show();
......
......@@ -4,6 +4,7 @@ import android.app.Activity;
import android.app.AlertDialog;
import android.content.ServiceConnection;
import android.database.Cursor;
import android.graphics.Color;
import android.graphics.Point;
......@@ -12,7 +13,9 @@ import android.content.ClipDescription;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.provider.Settings;
import android.speech.tts.TextToSpeech;
import android.util.Log;
......@@ -81,6 +84,10 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
private int count_deletelong = 0;
private boolean isSupervisor = false;
private String selectedImagePath;
private static final int SELECT_PICTURE = 1;
/*
float xAxis = 0f;
float yAxis = 0f;
......@@ -95,6 +102,13 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_pictogram);
Intent intent=getIntent();
isSupervisor = intent.getBooleanExtra("isSupervisor", false);
//isSupervisor = true;// QUITAR
//Log.d(LOG_TAG, "isSupervisor vale " + isSupervisor);
context = this;
actualCategory = null; // this for refresh vocabulary when a websocket action arrived from the dashboard
......@@ -183,7 +197,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
*/
final GridView panelGridView = (GridView) findViewById(R.id.panel_grid_view);
//final ImageButton deleteButton = (ImageButton) findViewById(R.id .button_delete);
final ImageButton deleteButton = (ImageButton) findViewById(R.id .button_delete);
//final Button deleteAllButton = (Button) findViewById(R.id.button_delete_all);
final ImageButton ttsButton = (ImageButton) findViewById(R.id.button_tts);
......@@ -288,6 +302,26 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
panelGridView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
if (isSupervisor){
// Si es supervisor al hacer longClick deshabilito ese pictograma o lo habilito
Picto p = panelAdapter.getItem(position);
if (p==null){
// No tengo pictograma. Abro una nueva ventana de selección desde el Carrete del device
Log.d(LOG_TAG, "No tengo pictograma. Abro carrete...");
chooseImage();
// ...
}
else if (p.is_enabled()){
// Lo deshabilito
Log.d(LOG_TAG, "Lo deshabilitaría");
// ....
} else if (!p.is_enabled()){
// Lo habilito
Log.d(LOG_TAG, "Lo habilitaría");
// ....
}
} else{
ClipData.Item item = new ClipData.Item("" + position);
String[] mimeTypes = {ClipDescription.MIMETYPE_TEXT_PLAIN};
ClipData data = new ClipData("" + position, mimeTypes, item);
......@@ -310,11 +344,13 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
//view.setVisibility(View.INVISIBLE);
}
}
}
return true;
}
});
// onLongClick picto del tapeGridView (para empezar a arrastrarlo fuera del tape y eliminar de ahí)
/*
tapeGridView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
......@@ -334,6 +370,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
return true;
}
});
*/
// onClick ttsButton (enviar frase a server o guardar en log local)
ttsButton.setOnClickListener(new View.OnClickListener() {
......@@ -363,7 +400,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
}
});
/* onClick deleteButton (eliminar del tape el último picto)
// onClick deleteButton (eliminar del tape el último picto)
deleteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
......@@ -398,7 +435,58 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
return false;
}
});*/
});
}
/**
* función para la selección de una foto del carrete
*/
public void chooseImage(){
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(intent, SELECT_PICTURE);
}
/**
* Función para la selección de una foto del carrete
* @param requestCode
* @param resultCode
* @param data
*/
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE) {
Uri selectedImageUri = data.getData();
selectedImagePath = getPath(selectedImageUri);
Log.d(LOG_TAG, "selectedImagePath:" + selectedImagePath);
// Ahora guardaría la imagen en la bbdd local y habría que subirla al server y sincronizar las bbdd
// ...
}
}
}
/**
* Función para la selección de una foto del carrete
* @param uri
* @return
*/
public String getPath(Uri uri) {
if( uri == null ) {
return null;
}
// this will only work for images selected from gallery
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
if( cursor != null ){
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
return uri.getPath();
}
@Override
......
......@@ -181,6 +181,13 @@ public class SerialActivity extends Activity implements iRestapiListener {
public void onClick(View view) {
String username = mSerialViewMail.getText().toString();
String password = mSerialViewPass.getText().toString();
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("username", username);
editor.putString("password", password);
editor.commit();
// DE PRUEBA
// Alumno
//username = "faf0001";
......@@ -189,12 +196,6 @@ public class SerialActivity extends Activity implements iRestapiListener {
//username = "dofer@ujaen.es";
//password = "dofer";
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("username", username);
editor.putString("password", password);
editor.commit();
RestapiWrapper wrapper = PCBcontext.getRestapiWrapper();
if (username.contains("@")){
// Es un supervisor
......@@ -246,7 +247,33 @@ public class SerialActivity extends Activity implements iRestapiListener {
public void result(JSONObject result) {
// Si llego aquí es porque hay un único valor, no un array
try {
Log.d(LOG_TAG, "User:"+result.toString());
Log.d(LOG_TAG, "JSON en result:"+result.toString());
if (result.toString().contains("error")){
progressDialog.dismiss();
AlertDialog.Builder builder = new AlertDialog.Builder(SerialActivity.this);
if (result.toString().contains("Invalid password")){
builder.setMessage("La contraseña indicada no es correcta. Inténtelo de nuevo.")
.setCancelable(false)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
} else if (result.toString().contains("User not found")){
builder.setMessage("El usuario indicado no es correcto. Inténtelo de nuevo.")
.setCancelable(false)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
}
AlertDialog alert = builder.create();
alert.show();
} else{ // No hay error. Sigo
// Saco el token y los demás valores
Vector<User> users = new Vector<User>(1);
......@@ -319,6 +346,18 @@ public class SerialActivity extends Activity implements iRestapiListener {
progressDialog.dismiss();
}
/*
AlertDialog.Builder builder = new AlertDialog.Builder(SerialActivity.this);
builder.setMessage("Es un supervisor. Sigo...")
.setCancelable(false)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
AlertDialog alert = builder.create();
alert.show();
*/
// Llamo a LoginActivity
Intent loginActivity = new Intent(this, LoginActivity.class);
loginActivity.putExtra("token", jsonToken);
......@@ -326,9 +365,12 @@ public class SerialActivity extends Activity implements iRestapiListener {
startActivity(loginActivity);
}
} catch (JSONException ex){
//Log.d(LOG_TAG, "ERROR 1");
ex.printStackTrace();
}
}
} catch (JSONException e) {
//Log.d(LOG_TAG, "ERROR 2");
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
......@@ -351,6 +393,3 @@ public class SerialActivity extends Activity implements iRestapiListener {
alert.show();
}
}
\ No newline at end of file
......@@ -146,6 +146,7 @@ public class StudentFragmentGrid extends Fragment{
//Log.d(LOG_TAG, "Vocabulario de tam:" + vocabulary.size());
progressDialog.dismiss();
Intent pictogramActivity = new Intent(getActivity(), PictogramActivity.class);
pictogramActivity.putExtra("isSupervisor",true);
startActivity(pictogramActivity);
}
......
......@@ -18,7 +18,7 @@
<fragment
android:layout_width="fill_parent"
android:layout_height="600px"
android:layout_height="400px"
class="com.yottacode.pictogram.gui.StudentFragmentGrid"
android:id="@+id/alumnos"
android:layout_below="@+id/logintitle"/>
......
......@@ -25,6 +25,15 @@
android:layout_alignParentTop="true">
</GridView>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="850dp"
android:paddingTop="20dp"
android:src="@drawable/back64"
android:background="@null"
android:id="@+id/button_delete"
android:layout_alignParentTop="true"/>
<ImageButton
android:layout_width="wrap_content"
......
......@@ -5,7 +5,7 @@
android:layout_height="fill_parent"
android:padding="2dp"
android:numColumns="5"
android:verticalSpacing="5dp"
android:verticalSpacing="1dp"
android:horizontalSpacing="5dp"
android:gravity="center"
android:layout_alignParentTop="true"
......
......@@ -12,5 +12,6 @@
android:id="@+id/txt"
android:layout_width="140dp"
android:layout_height="140dp"
android:layout_centerHorizontal="true"
android:layout_below="@+id/img"/>
</RelativeLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Strings de serial -->
<string name="title_activity_serial">Access data</string>
<string name="action_entrar">Login</string>
<string name="action_settings">Settings</string>
<string name="app_name">Pictogram</string>
<string name="db_script_error">Fail updating the data base</string>
<string name="error_invalid_serial">These access data are not correct</string>
<string name="prompt_serial_mail">User</string>
<string name="prompt_serial_pass">Password</string>
<string name="title_activity_login">Login</string>
<string name="title_activity_login_activity_fragment">Users login</string>
<string name="title_activity_login_activity_fragments">Users login</string>
<string name="title_activity_pictogram">PictogramActivity</string>
<string name="title_activity_serial">Write the access data</string>
<string name="title_activity_splash_screen">SplashScreenActivity</string>
<string name="db_script_error">Fail updating the data base</string>
<string name="loginTitle">Who are you?</string>
<string name="toggle_turn_on">Supervisor mode off</string>
<string name="toggle_turn_off">Supervisor mode on</string>
<string name="passErrorTxt">Invalid password</string>
<string name="passErrorMsg">This password is not correct. Try again.</string>
<string name="userErrorTxt">User not found</string>
<string name="userErrorMsg">The user is not correct. Inténtelo de nuevo.</string>
<!-- Alert dialogs -->
<string name="exitPictogram">Exit Pictogram</string>
......@@ -33,7 +35,6 @@
<string name="cancel">Cancel</string>
<string name="tabletNoYotta">Important: writes this ID number for your cabinet</string>
<string name="loginNoUsers">There are no students assigned with your tablet. Please, ask your cabinet</string>
<string name="serialRepeated"></string>
<!-- Login -->
<string name="systemMessage">System message</string>
......
......@@ -7,7 +7,7 @@
<string name="title_activity_login_activity_fragments">Entrada de usuarios</string>
<string name="title_activity_login_activity_fragment">Entrada de usuarios</string>
<string name="title_activity_pictogram">PictogramActivity</string>
<string name="db_script_error">Error al actualizar la base de datos</string>
<string name="title_activity_splash_screen">SplashScreenActivity</string>
......@@ -16,11 +16,11 @@
<string name="prompt_serial_mail">Usuario</string>
<string name="prompt_serial_pass">Contraseña</string>
<string name="action_entrar">Entrar</string>
<string name="error_invalid_serial">Este nº de serie no es correcto</string>
<string name="loginTitle">¿Quién eres?</string>
<string name="toggle_turn_on">Desactivar modo supervisor</string>
<string name="toggle_turn_off">Activar modo supervisor</string>
<string name="db_script_error">Error al actualizar la base de datos</string>
<string name="passErrorTxt">Invalid password</string>
<string name="passErrorMsg">La contraseña indicada no es correcta. Inténtelo de nuevo.</string>
<string name="userErrorTxt">User not found</string>
<string name="userErrorMsg">El usuario indicado no es correcto. Inténtelo de nuevo.</string>
<!-- Alert dialogs -->
<string name="exitPictogram">Salir de Pictogram</string>
......@@ -36,7 +36,6 @@
<string name="cancel">Cancelar</string>
<string name="tabletNoYotta">Importante: anote este nº de dispositivo para indicárselo al responsable de su asociación o gabinete</string>
<string name="loginNoUsers">No está asignado ningún alumno con tu tablet. Consulte con el responsable de su asociación o gabinete</string>
<string name="serialRepeated">Este tablet ya ha sido registrado previamente o el nº de serie no es correcto. Inténtelo de nuevo o consulte con nuestro servicio técnico</string>
<!-- Login -->
<string name="systemMessage">Mensaje del sistema</string>
......
......@@ -7,7 +7,7 @@
<string name="title_activity_login_activity_fragments">Entrada de usuarios</string>
<string name="title_activity_login_activity_fragment">Entrada de usuarios</string>
<string name="title_activity_pictogram">PictogramActivity</string>
<string name="db_script_error">Error al actualizar la base de datos</string>
<string name="title_activity_splash_screen">SplashScreenActivity</string>
......@@ -16,11 +16,11 @@
<string name="prompt_serial_mail">Usuario</string>
<string name="prompt_serial_pass">Contraseña</string>
<string name="action_entrar">Entrar</string>
<string name="error_invalid_serial">Este nº de serie no es correcto</string>
<string name="loginTitle">¿Quién eres?</string>
<string name="toggle_turn_on">Desactivar modo supervisor</string>
<string name="toggle_turn_off">Activar modo supervisor</string>
<string name="db_script_error">Error al actualizar la base de datos</string>
<string name="passErrorTxt">Invalid password</string>
<string name="passErrorMsg">La contraseña indicada no es correcta. Inténtelo de nuevo.</string>
<string name="userErrorTxt">User not found</string>
<string name="userErrorMsg">El usuario indicado no es correcto. Inténtelo de nuevo.</string>
<!-- Alert dialogs -->
<string name="exitPictogram">Salir de Pictogram</string>
......@@ -36,7 +36,6 @@
<string name="cancel">Cancelar</string>
<string name="tabletNoYotta">Importante: anote este nº de dispositivo para indicárselo al responsable de su asociación o gabinete</string>
<string name="loginNoUsers">No está asignado ningún alumno con tu tablet. Consulte con el responsable de su asociación o gabinete</string>
<string name="serialRepeated">Este tablet ya ha sido registrado previamente o el nº de serie no es correcto. Inténtelo de nuevo o consulte con nuestro servicio técnico</string>
<!-- Login -->
<string name="systemMessage">Mensaje del sistema</string>
......
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