Commit d7dfd909 by German Callejas

Nueva forma para añadir pictos nuevos hecha (Arreglar tema del path, no lo crea el picto)

parent 3120a70c
......@@ -2,6 +2,8 @@ package com.yottacode.pictogram.dao;
import android.graphics.Color;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;
import com.yottacode.pictogram.action.VocabularyAction;
......@@ -12,6 +14,8 @@ import com.yottacode.pictogram.tools.PCBcontext;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.Serializable;
/**
* A object which represents a pictogram
......@@ -19,9 +23,7 @@ import org.json.JSONObject;
* @author Fernando Martinez Santiago
* @version 1.0
*/
public class
Picto extends Img {
public class Picto extends Img {
public final static class JSON_ATTTRS {
public static String CATEGORY = "id_cat";
......
......@@ -253,10 +253,8 @@ public class CropImageView extends ImageView {
* Gets the cropped image based on the current crop window.
*
* @return a new Bitmap representing the cropped image
* @param origin
* @param orientation
*/
public Bitmap getCroppedImage(int origin, int orientation) {
public Bitmap getCroppedImage() {
final Drawable drawable = this.getDrawable();
if (drawable == null || !(drawable instanceof BitmapDrawable)) {
return null;
......@@ -271,8 +269,8 @@ public class CropImageView extends ImageView {
final float scaleY = matrixValues[Matrix.MSCALE_Y]; //==1
// Extract the translation values.
final float transX = (origin == CAMERA_PIC_REQUEST && orientation== HORIZONTAL_ORIENTATION ) ? matrixValues[Matrix.MTRANS_Y] : matrixValues[Matrix.MTRANS_X];
final float transY = (origin == CAMERA_PIC_REQUEST && orientation== HORIZONTAL_ORIENTATION ) ? matrixValues[Matrix.MTRANS_X] : matrixValues[Matrix.MTRANS_Y];
final float transX = matrixValues[Matrix.MTRANS_X];
final float transY = matrixValues[Matrix.MTRANS_Y];
final Bitmap originalBitmap = ((BitmapDrawable) drawable).getBitmap();
/*Log.i("DETALLES","ScaleX: "+scaleX + "- ScaleY: "+scaleY);
......
package com.yottacode.pictogram.tabletlibrary.cropper;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.media.effect.Effect;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.text.InputType;
import android.util.Log;
import android.view.View;
import android.view.Window;
......@@ -13,7 +19,16 @@ import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import com.yottacode.pictogram.dao.Picto;
import com.yottacode.pictogram.grammar.Vocabulary;
import com.yottacode.pictogram.grammar.iLocalPicto;
import com.yottacode.pictogram.net.PictoUploader;
import com.yottacode.pictogram.tabletlibrary.R;
import com.yottacode.pictogram.tabletlibrary.gui.communicator.PictogramActivity;
import com.yottacode.pictogram.tools.PCBcontext;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
/**
* Created by German on 06/02/2017.
......@@ -23,13 +38,14 @@ public class EditPictoActivity extends Activity {
// Private Constants ///////////////////////////////////////////////////////////////////////////
public static final int EDIT_PICTO_REQUEST = 2288;
public static final int UPLOAD_NEW_PICTO = 200;
public static final String TRANSCRIPTION = "textPicto";
public static final String PATH = "pathImage";
public static final String IMAGE_PICTO = "imagePicto";
public static final String IMAGE_ORIGIN = "imageOrigin";
public static final String IMAGE_ORIENTATION = "imageOrientation";
// Activity Methods ////////////////////////////////////////////////////////////////////////////
@Override
public void onCreate(Bundle savedInstanceState) {
......@@ -38,25 +54,20 @@ public class EditPictoActivity extends Activity {
setContentView(R.layout.edit_picto_layout);
// Initialize Views.
final CropImageView cropImageView = (CropImageView) findViewById(R.id.CropImageView);
final EditText legend = (EditText) findViewById(R.id.legend);
final Button okButton = (Button) findViewById(R.id.okButton);
final Button cancelButton = (Button) findViewById(R.id.cancelButton);
//final ImageView backgroundImage = (ImageView) findViewById(R.id.backgroundImage);
cropImageView.setFixedAspectRatio(true);
cropImageView.setGuidelines(2);
cropImageView.setAspectRatio(1,1);
final int orientation = getIntent().getExtras().getInt(EditPictoActivity.IMAGE_ORIENTATION);
final int origin = getIntent().getExtras().getInt(EditPictoActivity.IMAGE_ORIGIN);
//Obtener leyenda
String legendText = getIntent().getExtras().getString(EditPictoActivity.TRANSCRIPTION);
if(legendText != null) {
Log.i("DETALLES","Llega el intent al layout recortar, con texto: " + legendText);
if(legendText != null) { //Si tenia leyenda(editarlo)
legend.setText(legendText);
}else{
}else{ //Si no tenia el picto leyenda
legend.setTextColor(Color.GRAY);
legend.setOnClickListener(new View.OnClickListener() {
@Override
......@@ -65,27 +76,39 @@ public class EditPictoActivity extends Activity {
}
});
}
//Obtener imagen del intent
byte[] byteArray = getIntent().getByteArrayExtra(EditPictoActivity.IMAGE_PICTO);
Bitmap imagePicto = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
cropImageView.setImageBitmap(imagePicto);
/*byteArray = getIntent().getByteArrayExtra("imageBackground");
Bitmap imageBackground = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
backgroundImage.setImageBitmap(imageBackground);*/
//Gestion de botones
okButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Bitmap croppedImage = cropImageView.getCroppedImage(origin,orientation);
//Escalar y guardarla al server
Bitmap finalImage = null;
finalImage.createScaledBitmap(croppedImage,96,96,true);
Intent intent = getIntent();
intent.putExtra(EditPictoActivity.TRANSCRIPTION,legend.getText().toString());
Log.i("DETALLES","sale el intent al layout recortar, con texto: " + legend.getText().toString());
final Bitmap croppedImage = cropImageView.getCroppedImage();
//Escalar imagen
Bitmap finalImage = croppedImage.createScaledBitmap(croppedImage,96,96,true);
//Guardar imagen en galeria y obtener la ruta
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
finalImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = MediaStore.Images.Media.insertImage(PCBcontext.getContext().getContentResolver(), finalImage, legend.getText()+"-recorte", null);
Uri pathImage = Uri.parse(path);
Intent intent = new Intent(EditPictoActivity.this,PictogramActivity.class); //Mandar a pictogram activity el path y el texto de la imagen
intent.putExtra(PATH,pathImage.toString());
intent.putExtra(TRANSCRIPTION,legend.getText().toString());
cropImageView.setImageBitmap(finalImage);
setResult(RESULT_OK,intent);
finish();
finish(); //Termina la actividad de editar
startActivityForResult(intent,UPLOAD_NEW_PICTO); //Llama a pictogramActivity de nuevo
//setResult(RESULT_OK,intent);
}
});
......@@ -93,7 +116,9 @@ public class EditPictoActivity extends Activity {
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(EditPictoActivity.this,PictogramActivity.class);
finish();
startActivity(intent);
}
});
}
......@@ -125,6 +150,4 @@ public class EditPictoActivity extends Activity {
legend.setText(text.toString());
}
}
......@@ -14,7 +14,6 @@ import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Toast;
import com.yottacode.pictogram.dao.Picto;
import com.yottacode.pictogram.grammar.Vocabulary;
......@@ -23,7 +22,6 @@ import com.yottacode.pictogram.net.PictoUploader;
import com.yottacode.pictogram.tabletlibrary.R;
import com.yottacode.pictogram.tools.PCBcontext;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
......@@ -58,7 +56,7 @@ public class PictoMenu {
* @param row
* @param col
*/
public void addPicto(int row, int col) {
public void addPicto(final int row,final int col, final int cat) {
final String [] items = new String [] {activity.getString(R.string.dialogCamera), activity.getString(R.string.dialogGallery)};
ArrayAdapter<String> adapter = new ArrayAdapter<>(activity, android.R.layout.select_dialog_item, items);
......@@ -76,6 +74,17 @@ public class PictoMenu {
intent.setAction(Intent.ACTION_GET_CONTENT);
activity.startActivityForResult(intent,GALLERY_PIC_REQUEST);
}
//Enviar al PictogramActivity los datos necesarios para crear el picto despues
if (PCBcontext.getPcbdb().getCurrentUser().has_categories()) {
activity.getIntent().putExtra("cat", cat);
activity.getIntent().putExtra(Picto.JSON_ATTTRS.ROW, row);
activity.getIntent().putExtra(Picto.JSON_ATTTRS.COLUMN, col);
} else {
activity.getIntent().putExtra(Picto.JSON_ATTTRS.FREE_ROW, row);
activity.getIntent().putExtra(Picto.JSON_ATTTRS.FREE_COLUMN, col);
}
}
} );
builder.setNegativeButton(activity.getString(R.string.dialogCancel),new DialogInterface.OnClickListener() {
......@@ -86,10 +95,11 @@ public class PictoMenu {
}
});
final AlertDialog dialog = builder.create();
dialog.show();
/*Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image*//*");
if (PCBcontext.getPcbdb().getCurrentUser().has_categories()) {
......@@ -103,10 +113,11 @@ public class PictoMenu {
}
/**
* 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) {
/*public void chooseTextAndSavePicto(final String selectedImagePath, final int row, final int col, final int freeRow, final int freeColumn) {
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(activity.getResources().getString(R.string.enterImgLabel));
......@@ -121,8 +132,8 @@ public class PictoMenu {
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
int cat = activity.currentCategory != null
? activity.currentCategory.get_id()
int cat = activity.getCurrentCategory() != null
? activity.getCurrentCategory().get_id()
: Picto.NO_CATEGORY;
PCBcontext.getVocabulary().saveLocalPicto(
selectedImagePath,
......@@ -149,7 +160,7 @@ public class PictoMenu {
builder.show();
}
}*/
/**
* Función para la selección de una foto del carrete
......@@ -174,7 +185,7 @@ public class PictoMenu {
activity.getIntent().removeExtra(Picto.JSON_ATTTRS.COLUMN);
activity.getIntent().removeExtra(Picto.JSON_ATTTRS.FREE_ROW);
activity.getIntent().removeExtra(Picto.JSON_ATTTRS.FREE_COLUMN);
chooseTextAndSavePicto(selectedImagePath, row, col, freeRow, freeColumn);
//chooseTextAndSavePicto(selectedImagePath, row, col, freeRow, freeColumn);
}
}
}
......
......@@ -46,7 +46,9 @@ 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.grammar.iLocalPicto;
import com.yottacode.pictogram.net.ImgDownloader;
import com.yottacode.pictogram.net.PictoUploader;
import com.yottacode.pictogram.net.websockets.ActionTalk;
import com.yottacode.pictogram.net.websockets.VocabularyTalk;
import com.yottacode.pictogram.tabletlibrary.R;
......@@ -63,6 +65,7 @@ import org.json.JSONException;
import org.json.JSONObject;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
......@@ -77,9 +80,6 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
private static final int CAMERA_PIC_REQUEST = 1;
private static final int GALLERY_PIC_REQUEST = 2;
private static final int VERTICAL_ORIENTATION = 200;
private static final int HORIZONTAL_ORIENTATION = 300;
private static final int MAX_WIDTH = 700;
private static final int MAX_HEIGHT = 350;
......@@ -98,7 +98,7 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
// Tape view (list of pictos to send to the server)
GridView tapeGridView;
// Current picto category, if not null the corresponding category grid will be shown
Picto currentCategory;
private Picto currentCategory;
// Object used for reading text
TTSHelper tts;
// Element used for loading new pictos (while changing categories)
......@@ -249,7 +249,7 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
this.generateAnimations();
if (this.currentCategory != null) {
if (this.getCurrentCategory() != null) {
this.hidePictoMainGridView();
} else {
this.showPictoMainGridView();
......@@ -470,11 +470,11 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
private void hidePictoMainGridView() {
this.pictoCategoryGridAdapter.clear();
this.pictoCategoryGridAdapter.addAll(this.sort(this.vocabulary.next(this.currentCategory)));
this.pictoCategoryGridAdapter.addAll(this.sort(this.vocabulary.next(this.getCurrentCategory())));
this.pictoCategoryGridAdapter.notifyDataSetChanged();
if (this.currentCategory.get_color() != -1)
this.pictoCategoryGridView.setBackgroundColor(this.currentCategory.get_color());
if (this.getCurrentCategory().get_color() != -1)
this.pictoCategoryGridView.setBackgroundColor(this.getCurrentCategory().get_color());
this.pictoMainGridView.setEnabled(false);
this.pictoCategoryGridView.setEnabled(true);
......@@ -488,7 +488,7 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
* Returns pictoCategoryGridAdapter or pictoMainGridAdapter depending on the current View
*/
protected PictoGridAdapter getCurrentPictoGridAdapter() {
return (currentCategory == null) ? this.pictoMainGridAdapter : this.pictoCategoryGridAdapter;
return (getCurrentCategory() == null) ? this.pictoMainGridAdapter : this.pictoCategoryGridAdapter;
}
/**
......@@ -548,7 +548,7 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
runOnUiThread(new Runnable() {
@Override
public void run() {
if (currentCategory != null) {
if (getCurrentCategory() != null) {
hidePictoMainGridView();
} else {
showPictoMainGridView();
......@@ -691,6 +691,10 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
}
}
public Picto getCurrentCategory() {
return currentCategory;
}
public Picto getPicto() {
return picto;
}
......@@ -845,8 +849,8 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
Picto p = getCurrentPictoGridAdapter().getItem(position);
if (p == null) {
// No tengo pictograma. Abro una nueva ventana de selección desde el Carrete del device si no es categoria
if (currentCategory != null || !PCBcontext.getPcbdb().getCurrentUser().has_categories()) {
new PictoMenu(PictogramActivity.this).addPicto(position % maxColumns, (int) (position / maxColumns));
if (getCurrentCategory() != null || !PCBcontext.getPcbdb().getCurrentUser().has_categories()) {
new PictoMenu(PictogramActivity.this).addPicto(position % maxColumns, (int) (position / maxColumns), currentCategory.get_id());
} else
Toast.makeText(PictogramActivity.this, PictogramActivity.this.getResources().getString(R.string.notNewCats), Toast.LENGTH_SHORT).show();
......@@ -939,8 +943,6 @@ protected void showOnlyTape(boolean onlyTape) {
this.showPictoCategoriesViewButton.setAlpha(1f);
}
}
}
......@@ -980,7 +982,6 @@ protected void showOnlyTape(boolean onlyTape) {
//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;
......@@ -1102,14 +1103,20 @@ protected void showOnlyTape(boolean onlyTape) {
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Bitmap imagen = null;
int row = getIntent().getIntExtra(Picto.JSON_ATTTRS.ROW, -1);
int col = getIntent().getIntExtra(Picto.JSON_ATTTRS.COLUMN, -1);
int freeRow = getIntent().getIntExtra(Picto.JSON_ATTTRS.FREE_ROW, -1);
int freeColumn = getIntent().getIntExtra(Picto.JSON_ATTTRS.FREE_COLUMN, -1);
int cat = getIntent().getIntExtra("cat", -1);
Log.i("DETALLES", "Picto nuevo en: " + " fila: " + row + " col: " + col + " cat: "+cat);
Bitmap imagen = null;
switch(requestCode) {
case CAMERA_PIC_REQUEST: //Captura de foto
if (data != null && resultCode==RESULT_OK) {
imagen = (Bitmap) data.getExtras().get("data");
this.launchActivity(imagen,CAMERA_PIC_REQUEST);
//Log.i("DETALLES", "Llega el intent del menú, con texto: " + legend);
this.launchActivity(imagen);
} else {
if(resultCode!=RESULT_OK) //Si no quieres la foto que has echado
startActivityForResult(new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE),CAMERA_PIC_REQUEST);
......@@ -1130,9 +1137,7 @@ protected void showOnlyTape(boolean onlyTape) {
cursor.close();
imagen = BitmapFactory.decodeFile(filePath);
/** Tras echar foto llamar a la actividad de recortar y le paso la leyenda para si tiene anteriormente o null, y la imagen a recortar */
//-->GERMAN: legend != null ? legend : null es lo mismo que simplemente legend
this.launchActivity(imagen,GALLERY_PIC_REQUEST);
this.launchActivity(imagen);
}else{
startActivity(new Intent(this, PictogramActivity.class));
}
......@@ -1140,19 +1145,58 @@ protected void showOnlyTape(boolean onlyTape) {
case EditPictoActivity.EDIT_PICTO_REQUEST:
if (resultCode == RESULT_OK)
Log.i("DETALLES", "Llega el intent de recorte 2, texto: " + data.getExtras().getString(EditPictoActivity.TRANSCRIPTION));
break;
case EditPictoActivity.UPLOAD_NEW_PICTO:
String path = getIntent().getExtras().getString(EditPictoActivity.PATH);
Log.i("DETALLES","Path de la imagen tras llamar a gestionarlo: "+ path);
String legend = getIntent().getExtras().getString(EditPictoActivity.TRANSCRIPTION);
chooseTextAndSavePicto(path,row,col,freeRow,freeColumn,cat,legend);
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) {
// Set up the buttons
int cat = category != -1 ? category : Picto.NO_CATEGORY;
Log.i("DETALLES","Path de la imagen: "+ selectedImagePath);
PCBcontext.getVocabulary().saveLocalPicto(
selectedImagePath,
legend,
cat,
row,
col,
freeRow,
freeColumn,
new iLocalPicto() {
@Override
public void saved(Picto localPicto) {
refresh();
try {
if (PCBcontext.is_user_online())
new PictoUploader(localPicto).upload(PCBcontext.getContext());
} catch (IOException e) {
Log.e(Vocabulary.class.getCanonicalName(), e.getMessage());
}
}
});
}
/**Para cambiar la activity de PictogramActivity a EditPictoActivity
* @param image
*/
public void launchActivity(Bitmap image, int originImage){
public void launchActivity(Bitmap image){
Intent intent = new Intent(this, EditPictoActivity.class);
if(image!=null) {
float aspectFactor = 1;
float bWidth = image.getWidth();
......@@ -1179,26 +1223,12 @@ protected void showOnlyTape(boolean onlyTape) {
byte[] byteArray = stream.toByteArray();
intent.putExtra(EditPictoActivity.IMAGE_PICTO, byteArray);
intent.putExtra(EditPictoActivity.IMAGE_ORIGIN, originImage == CAMERA_PIC_REQUEST ? CAMERA_PIC_REQUEST : GALLERY_PIC_REQUEST);
intent.putExtra(EditPictoActivity.IMAGE_ORIENTATION, bWidth > bHeight ? HORIZONTAL_ORIENTATION : VERTICAL_ORIENTATION);
if(picto!=null) {
intent.putExtra(EditPictoActivity.TRANSCRIPTION, picto.get_translation());
picto = null;
if(getPicto() !=null) {
intent.putExtra(EditPictoActivity.TRANSCRIPTION, getPicto().get_translation());
setPicto(null);
}
startActivityForResult(intent, EditPictoActivity.EDIT_PICTO_REQUEST);
}
}
/*@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
// Esto es lo que hace mi botón al pulsar ir a atrás
finish();
Intent intent =
return true;
}
return super.onKeyDown(keyCode, event);
}*/
}
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