Issue #94 terminado

parent 3e63ab1a
...@@ -3,6 +3,7 @@ package com.yottacode.pictogram.tabletlibrary.gui.communicator.cropper; ...@@ -3,6 +3,7 @@ package com.yottacode.pictogram.tabletlibrary.gui.communicator.cropper;
import android.Manifest; import android.Manifest;
import android.app.Activity; import android.app.Activity;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.database.Cursor; import android.database.Cursor;
...@@ -14,6 +15,7 @@ import android.media.MediaRecorder; ...@@ -14,6 +15,7 @@ import android.media.MediaRecorder;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat; import android.support.v4.app.ActivityCompat;
...@@ -44,7 +46,11 @@ import com.yottacode.pictogram.tools.PCBcontext; ...@@ -44,7 +46,11 @@ import com.yottacode.pictogram.tools.PCBcontext;
import com.yottacode.tools.GUITools; import com.yottacode.tools.GUITools;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectOutputStream;
import pl.droidsonroids.gif.GifTextView; import pl.droidsonroids.gif.GifTextView;
...@@ -250,24 +256,35 @@ public class EditPictoActivity extends Activity { ...@@ -250,24 +256,35 @@ public class EditPictoActivity extends Activity {
if (legend.getText().toString().trim().length() > 0) { if (legend.getText().toString().trim().length() > 0) {
final Bitmap croppedImage = cropImageView.getCroppedImage(); final Bitmap croppedImage = cropImageView.getCroppedImage();
//Guardar imagen en galeria y obtener la ruta //Guardar imagen en galeria y obtener la ruta
ByteArrayOutputStream bytes = new ByteArrayOutputStream(); try {
croppedImage.compress(Bitmap.CompressFormat.PNG, 100, bytes);
String title = getResources().getString(R.string.app_name) + ' ' + legend.getText().toString(); String title = getResources().getString(R.string.app_name) + ' ' + legend.getText().toString();
String path = MediaStore.Images.Media.insertImage(getContentResolver(), croppedImage, title, null); String path = "/storage/emulated/0/DCIM/Camera/"+title+".png";
path = getRealPathFromURI(Uri.parse(path)); File imageFile = new File(path);
Log.i(LOG_PATH, " New image " + title + " saved at " + path); FileOutputStream outputStream = new FileOutputStream(imageFile);
Bitmap bitmap = Bitmap.createBitmap(cropImageView.getCroppedImage());
Intent intent = getIntent(); //Mandar a pictogram activity el path y el texto de la imagen
intent.putExtra(PATH, path); bitmap.compress(Bitmap.CompressFormat.PNG, 90, outputStream);
intent.putExtra(Picto.JSON_ATTTRS.EXPRESSION, legend.getText().toString()); MediaStore.Images.Media.insertImage(getContentResolver(), bitmap, path, null);
intent.putExtra(Picto.JSON_ATTTRS.CATEGORY,getIntent().getIntExtra(Picto.JSON_ATTTRS.CATEGORY, -1));
intent.putExtra("tipo",editar); //Para saber despues si estas editando o añadiendo nuevo y coger los datos de intent o de data en OnActivityResult outputStream.flush();
setResult(RESULT_OK, intent); outputStream.close();
cropImageView.setImageBitmap(croppedImage);
Intent intent = getIntent(); //Mandar a pictogram activity el path y el texto de la imagen
intent.putExtra(PATH,path);
intent.putExtra(Picto.JSON_ATTTRS.EXPRESSION, legend.getText().toString());
intent.putExtra(Picto.JSON_ATTTRS.CATEGORY,getIntent().getIntExtra(Picto.JSON_ATTTRS.CATEGORY, -1));
intent.putExtra("tipo",editar); //Para saber despues si estas editando o añadiendo nuevo y coger los datos de intent o de data en OnActivityResult
setResult(RESULT_OK, intent);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
finish(); //Termina la actividad de editar finish(); //Termina la actividad de editar
} else } else
Toast.makeText(getBaseContext(), R.string.crop_TextRequired, Toast.LENGTH_LONG).show(); Toast.makeText(getBaseContext(), R.string.crop_TextRequired, Toast.LENGTH_LONG).show();
} }
......
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