Commit dd79da49 by German Callejas

Interfaz terminada para editar picto o añadir uno nuevo en cuadro libre

parent 7e52e135
......@@ -4,6 +4,7 @@ import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
......@@ -50,6 +51,14 @@ public class EditPictoActivity extends Activity {
if(legendText != null) {
Log.i("DETALLES","Llega el intent al layout recortar, con texto: " + legendText);
legend.setText(legendText);
}else{
legend.setTextColor(Color.GRAY);
legend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
legend.setText("");
}
});
}
byte[] byteArray = getIntent().getByteArrayExtra(EditPictoActivity.IMAGE_PICTO);
Bitmap imagePicto = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
......
......@@ -10,6 +10,7 @@ import android.provider.MediaStore;
import android.text.InputType;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
......@@ -22,6 +23,7 @@ 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,8 +60,38 @@ public class PictoMenu {
*/
public void addPicto(int row, int col) {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
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);
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(activity.getString(R.string.dialogTitle));
builder.setAdapter( adapter, new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dialog, int item ) {
if (item == 0) { //Pick from camera
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
activity.startActivityForResult(cameraIntent,CAMERA_PIC_REQUEST);
} else { //Pick from file
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
activity.startActivityForResult(intent,GALLERY_PIC_REQUEST);
}
}
} );
builder.setNegativeButton(activity.getString(R.string.dialogCancel),new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, just close
// the dialog box and do nothing
dialog.cancel();
}
});
final AlertDialog dialog = builder.create();
dialog.show();
/*Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image*//*");
if (PCBcontext.getPcbdb().getCurrentUser().has_categories()) {
activity.getIntent().putExtra(Picto.JSON_ATTTRS.ROW, row);
activity.getIntent().putExtra(Picto.JSON_ATTTRS.COLUMN, col);
......@@ -67,7 +99,7 @@ public class PictoMenu {
activity.getIntent().putExtra(Picto.JSON_ATTTRS.FREE_ROW, row);
activity.getIntent().putExtra(Picto.JSON_ATTTRS.FREE_COLUMN, col);
}
activity.startActivityForResult(intent,SELECT_PICTURE);
activity.startActivityForResult(intent,CAMERA_PIC_REQUEST);*/
}
......@@ -331,9 +363,6 @@ public class PictoMenu {
{
ll.getChildAt(1).setX(ll.getChildAt(1).getX() + 30);
children = new ArrayList<>(Arrays.asList(new PickFromCamera(p),new PickFromGallery(p)));
//ll.setVisibility(View.GONE);
//ll.removeAllViewsInLayout();
}
public void menuDisabled(){
......@@ -356,9 +385,8 @@ public class PictoMenu {
{
ll.setVisibility(View.GONE);
ll.removeAllViewsInLayout();
/**Al presionar el boton de ajustes lanza la actividad de la camara*/
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
Log.i("DETALLES","Texto del picto "+"'"+p.get_translation()+"'");
if(p!=null) {
//cameraIntent.putExtra("pictoLegend", p.get_translation());
......@@ -381,7 +409,7 @@ public class PictoMenu {
public List<RadialMenuWidget.RadialMenuEntry> getChildren() { return null; }
public void menuActiviated()
{
Toast.makeText(PCBcontext.getContext(),"Editar Imagen", Toast.LENGTH_SHORT).show();
ll.setVisibility(View.GONE);
ll.removeAllViewsInLayout();
if(p!=null) {
//cameraIntent.putExtra("pictoLegend", p.get_translation());
......
......@@ -75,6 +75,10 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
private Picto picto = null;
private static final int CAMERA_PIC_REQUEST = 1;
private static final int GALLERY_PIC_REQUEST = 2;
private static final int MAX_WIDTH = 700;
private static final int MAX_HEIGHT = 350;
// Main layout for this activity
RelativeLayout mainLayout;
// Adapter for de grid showing the categories grid (and main pictos)
......@@ -1089,38 +1093,39 @@ protected void showOnlyTape(boolean onlyTape) {
super.onActivityResult(requestCode, resultCode, data);
Bitmap imagen = null;
String legend = null;
switch(requestCode) {
case CAMERA_PIC_REQUEST: //Captura de foto
if (data != null) {
if (data != null && resultCode==RESULT_OK) {
imagen = (Bitmap) data.getExtras().get("data");
legend = data.getExtras().getString("pictoText"); /**AQUI DEBERIA OBTENER EL LEGEND EN EL CASO DE QUE QUIERA EDITAR LA IMAGEN DE UN PICTO
NO FUNCIONA DEVUELVE NULL ¿?¿?¿WHY?¿?¿*/
Log.i("DETALLES", "Llega el intent del menú, con texto: " + legend);
this.launchActivity(imagen);
//Log.i("DETALLES", "Llega el intent del menú, con texto: " + legend);
} else {
Log.i("DETALLES", "Fallo al tomar foto");
if(resultCode!=RESULT_OK) //Si no quieres la foto que has echado
startActivityForResult(new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE),CAMERA_PIC_REQUEST);
if(data==null) //Si te sales de la camara dandole al boton atras de android
startActivity(new Intent(this, PictogramActivity.class));
}
/** 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(legend, imagen);
break;
case GALLERY_PIC_REQUEST: //Galeria
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
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(legend, imagen);
if(data!=null){
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
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);
}else{
startActivity(new Intent(this, PictogramActivity.class));
}
break;
case EditPictoActivity.EDIT_PICTO_REQUEST:
if (resultCode == RESULT_OK)
......@@ -1131,26 +1136,54 @@ protected void showOnlyTape(boolean onlyTape) {
/**Para cambiar la activity de PictogramActivity a EditPictoActivity
* @param textLegend
* @param image
*/
public void launchActivity(String textLegend, Bitmap image){
public void launchActivity(Bitmap image){
Intent intent = new Intent(this, EditPictoActivity.class);
if(image!=null) {
int bWidth = image.getWidth();
int bHeight = image.getHeight();
//GERMAN: AQUI TIENES QUE PONER UN TAMAÑO ADECUADO que se calcule en funcion del tamaño de la pantalla y manteniendo la proporcion, SI NO DA EL MENSAJE FAILED BINDER TRANSACTION !!! ”
// http://stackoverflow.com/questions/23407821/how-to-solve-error-failed-binder-transaction-in-android-4-4
Bitmap rescaled = Bitmap.createScaledBitmap(image, 50, 50, true);
float aspectFactor = 1;
float bWidth = image.getWidth();
float bHeight = image.getHeight();
//Reducir la imagen a la mitad de su aspect ratio que viene de galería(Suele ser mayor que el tamaño maximo)
if(bWidth>MAX_WIDTH || bHeight>MAX_HEIGHT){
image = Bitmap.createScaledBitmap(image,(int) bWidth/2,(int) bHeight/2,true);
bWidth = image.getWidth();
bHeight = image.getHeight();
}
//Ir ampliando el alto y ancho hasta lo máximo posible (sin perder el ratio original), sin pasarse de los límites
while(bWidth < MAX_WIDTH && bHeight<MAX_HEIGHT){
bWidth = bWidth * aspectFactor;
bHeight = bHeight * aspectFactor;
aspectFactor += 0.1;
}
Bitmap rescaled = Bitmap.createScaledBitmap(image,(int) bWidth, (int) bHeight, true);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
rescaled.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
intent.putExtra(EditPictoActivity.IMAGE_PICTO, byteArray);
intent.putExtra(EditPictoActivity.TRANSCRIPTION, textLegend==null ? " " : textLegend);
if(picto!=null) {
intent.putExtra(EditPictoActivity.TRANSCRIPTION, picto.get_translation());
picto = 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);
}*/
}
......@@ -8,12 +8,12 @@
android:id="@+id/TotalLayout"
android:background="#b4000000">-->
<FrameLayout
<!--<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent">-->
<!--<ImageView
android:layout_width="match_parent"
......@@ -23,6 +23,9 @@
app:srcCompat="@color/black_translucent" />-->
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
......@@ -42,23 +45,28 @@
android:textAlignment="center"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_marginTop="@dimen/activity_vertical_margin" />
android:layout_marginTop="@dimen/activity_vertical_margin"
android:layout_alignStart="@+id/linearLayout2"
android:layout_centerVertical="false"
android:layout_centerHorizontal="true" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:layout_centerVertical="false"
android:layout_centerHorizontal="true">
<com.yottacode.pictogram.tabletlibrary.cropper.CropImageView
android:id="@+id/CropImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:adjustViewBounds="true"
android:scaleType="centerInside"
android:layout_marginLeft="5dp"
android:maxWidth="650px"
android:maxHeight="250px"
android:maxWidth="700px"
android:maxHeight="350px"
android:layout_below="@+id/title"
android:layout_alignParentStart="true"
android:layout_marginTop="55dp"
......@@ -120,4 +128,4 @@
</RelativeLayout>
</FrameLayout>
<!--</FrameLayout>-->
......@@ -40,5 +40,9 @@
<string name="cancel">Cancel</string>
<string name="accept">Accept</string>
<string name="legendText">Legend</string>
<string name="dialogCamera">Take a Picture</string>
<string name="dialogGallery">Pick from Gallery</string>
<string name="dialogTitle">Choose Method</string>
<string name="dialogCancel">Cancel</string>
</resources>
......@@ -40,4 +40,8 @@
<string name="cancel">Cancelar</string>
<string name="accept">Aceptar</string>
<string name="legendText">Leyenda</string>
<string name="dialogCamera">Hacer Foto</string>
<string name="dialogGallery">Seleccionar de Galería</string>
<string name="dialogTitle">Seleccionar Método</string>
<string name="dialogCancel">Cancelar</string>
</resources>
......@@ -38,6 +38,11 @@
<string name="session_eval_discarded">inválido</string>
<!-- Dialog for add new picto -->
<string name="dialogTitle">Seleccionar método</string>
<string name="dialogCamera">Hacer Foto</string>
<string name="dialogGallery">Seleccionar de Galería</string>
<string name="dialogCancel">Cancelar</string>
<!-- Cropper -->
<string name="legendText">Leyenda</string>
<string name="titleCropper">Editar Picto</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