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