Issue #94 terminado

parent 3e63ab1a
......@@ -3,6 +3,7 @@ package com.yottacode.pictogram.tabletlibrary.gui.communicator.cropper;
import android.Manifest;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
......@@ -14,6 +15,7 @@ import android.media.MediaRecorder;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
......@@ -44,7 +46,11 @@ import com.yottacode.pictogram.tools.PCBcontext;
import com.yottacode.tools.GUITools;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import pl.droidsonroids.gif.GifTextView;
......@@ -250,24 +256,35 @@ public class EditPictoActivity extends Activity {
if (legend.getText().toString().trim().length() > 0) {
final Bitmap croppedImage = cropImageView.getCroppedImage();
//Guardar imagen en galeria y obtener la ruta
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
croppedImage.compress(Bitmap.CompressFormat.PNG, 100, bytes);
String title = getResources().getString(R.string.app_name) + ' ' + legend.getText().toString();
String path = MediaStore.Images.Media.insertImage(getContentResolver(), croppedImage, title, null);
path = getRealPathFromURI(Uri.parse(path));
Log.i(LOG_PATH, " New image " + title + " saved at " + path);
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);
cropImageView.setImageBitmap(croppedImage);
try {
String title = getResources().getString(R.string.app_name) + ' ' + legend.getText().toString();
String path = "/storage/emulated/0/DCIM/Camera/"+title+".png";
File imageFile = new File(path);
FileOutputStream outputStream = new FileOutputStream(imageFile);
Bitmap bitmap = Bitmap.createBitmap(cropImageView.getCroppedImage());
bitmap.compress(Bitmap.CompressFormat.PNG, 90, outputStream);
MediaStore.Images.Media.insertImage(getContentResolver(), bitmap, path, null);
outputStream.flush();
outputStream.close();
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
} else
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