Añadida a la vista de editar picto el layout para realizar grabaciones (Falta pulir)

parent 29a221a0
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.yottacode.pictogram.tabletlibrary">
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<application
android:allowBackup="true"
android:label="@string/app_name"
......
package com.yottacode.pictogram.tabletlibrary.gui.communicator;
import com.yottacode.pictogram.tabletlibrary.R;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.ColorRes;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.widget.ImageView;
public class BotonCircular extends android.support.v7.widget.AppCompatImageView {
private static final int PRESSED_COLOR_LIGHTUP = 255 / 25;
private static final int PRESSED_RING_ALPHA = 75;
private static final int DEFAULT_PRESSED_RING_WIDTH_DIP = 4;
private static final int ANIMATION_TIME_ID = android.R.integer.config_shortAnimTime;
private int centerY;
private int centerX;
private int outerRadius;
private int pressedRingRadius;
private Paint circlePaint;
private Paint focusPaint;
private float animationProgress;
private int pressedRingWidth;
private int defaultColor;
private int pressedColor;
private ObjectAnimator pressedAnimator;
public BotonCircular(Context context) {
super(context);
init(context, null);
}
public BotonCircular(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public BotonCircular(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context, attrs);
}
@Override
public void setPressed(boolean pressed) {
super.setPressed(pressed);
if (circlePaint != null) {
circlePaint.setColor(pressed ? pressedColor : defaultColor);
}
if (pressed) {
showPressedRing();
} else {
hidePressedRing();
}
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawCircle(centerX, centerY, pressedRingRadius + animationProgress, focusPaint);
canvas.drawCircle(centerX, centerY, outerRadius - pressedRingWidth, circlePaint);
super.onDraw(canvas);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
centerX = w / 2;
centerY = h / 2;
outerRadius = Math.min(w, h) / 2;
pressedRingRadius = outerRadius - pressedRingWidth - pressedRingWidth / 2;
}
public float getAnimationProgress() {
return animationProgress;
}
public void setAnimationProgress(float animationProgress) {
this.animationProgress = animationProgress;
this.invalidate();
}
public void setColor(int color) {
this.defaultColor = color;
this.pressedColor = getHighlightColor(color,PRESSED_COLOR_LIGHTUP);
circlePaint.setColor(defaultColor);
focusPaint.setColor(pressedColor);
focusPaint.setAlpha(PRESSED_RING_ALPHA);
this.invalidate();
}
/**Esconder anillo exterior animacion*/
private void hidePressedRing() {
pressedAnimator.setFloatValues(pressedRingWidth, 0f);
pressedAnimator.start();
}
public void PhidePressedRing() {
pressedAnimator.setFloatValues(pressedRingWidth, 0f);
pressedAnimator.start();
}
/**Mostrar anillo exterior animacion*/
private void showPressedRing() {
pressedAnimator.setFloatValues(animationProgress, pressedRingWidth);
pressedAnimator.start();
}
public void PshowPressedRing() {
pressedAnimator.setFloatValues(animationProgress, pressedRingWidth);
pressedAnimator.start();
}
private void init(Context context, AttributeSet attrs) {
this.setFocusable(true);
this.setScaleType(ScaleType.CENTER_INSIDE);
setClickable(true);
circlePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
circlePaint.setStyle(Paint.Style.FILL);
focusPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
focusPaint.setStyle(Paint.Style.STROKE);
pressedRingWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_PRESSED_RING_WIDTH_DIP, getResources()
.getDisplayMetrics());
//int color = Color.rgb(106, 142, 26);
/*if (attrs != null) {
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircleButton);
color = a.getColor(R.styleable.CircleButton_cb_color, color);
pressedRingWidth = (int) a.getDimension(R.styleable.CircleButton_cb_pressedRingWidth, pressedRingWidth);
a.recycle();
}*/
int color = getResources().getColor(R.color.VerdeApp);
setColor(color);
focusPaint.setStrokeWidth(pressedRingWidth);
final int pressedAnimationTime = getResources().getInteger(ANIMATION_TIME_ID);
pressedAnimator = ObjectAnimator.ofFloat(this, "animationProgress", 0f, 0f);
pressedAnimator.setDuration(pressedAnimationTime);
}
private int getHighlightColor(int color, int amount) {
return Color.argb(Math.min(255, Color.alpha(color)), Math.min(255, Color.red(color) + amount),
Math.min(255, Color.green(color) + amount), Math.min(255, Color.blue(color) + amount));
}
}
package com.yottacode.pictogram.tabletlibrary.gui.communicator;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import com.yottacode.pictogram.dao.Picto;
import com.yottacode.pictogram.tabletlibrary.R;
import com.yottacode.pictogram.tabletlibrary.gui.communicator.cropper.EditPictoActivity;
import com.yottacode.pictogram.tabletlibrary.gui.login.MainActivity;
import com.yottacode.pictogram.tools.PCBcontext;
import com.yottacode.tools.GUITools;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
......@@ -100,6 +106,42 @@ public class PictoMenu {
}
public void setPicto(int row, int col, int cat, String expression, Bitmap bitmap){
Intent intent = new Intent(activity, EditPictoActivity.class);
intent.putExtra(Picto.JSON_ATTTRS.EXPRESSION, expression);
//Enviar al PictogramActivity los datos necesarios para editar el picto despues
if (PCBcontext.getPcbdb().getCurrentUser().has_categories()) {
intent.putExtra("cat", cat);
intent.putExtra(Picto.JSON_ATTTRS.ROW, row);
intent.putExtra(Picto.JSON_ATTTRS.COLUMN, col);
} else {
intent.putExtra(Picto.JSON_ATTTRS.FREE_ROW, row);
intent.putExtra(Picto.JSON_ATTTRS.FREE_COLUMN, col);
}
if(bitmap!=null) {
Point size= GUITools.getScreenSize(activity);
float bWidth = bitmap.getWidth();
float bHeight = bitmap.getHeight();
float factorX=size.x*0.7f/bWidth;
float factorY=size.y*0.7f/bHeight;
float factor= factorY>factorX ? factorX : factorY;
bWidth=bWidth*factor;
bHeight=bHeight*factor;
Bitmap rescaled = Bitmap.createScaledBitmap(bitmap,(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("tipo",true);
activity.startActivity(intent);
}
/**Function for build a radial menu
*
* @param is_picto_big
......@@ -245,21 +287,29 @@ public class PictoMenu {
}
public String getName() { return "edit"; }
public String getLabel() { return null; }
public int getIcon() { return R.drawable.edit_picture; }
public int getIcon() { return R.drawable.edit; }
private List<RadialMenuWidget.RadialMenuEntry> children;
public List<RadialMenuWidget.RadialMenuEntry> getChildren() { return children; }
public void menuActiviated()
{
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();
try {
setPicto(p.get_row(),p.get_column(),p.get_category(),p.get_translation(),p.get_bitmap(PCBcontext.getContext()));
} catch (IOException e) {
e.printStackTrace();
}
//ll.getChildAt(1).setX(ll.getChildAt(1).getX() + 30);
//children = new ArrayList<>(Arrays.asList(new PickFromCamera(p),new PickFromGallery(p)));
}
public void menuDisabled(){
ll.getChildAt(1).setX(ll.getChildAt(1).getX() - 30);
//ll.getChildAt(1).setX(ll.getChildAt(1).getX() - 30);
}
}
public class PickFromCamera implements RadialMenuWidget.RadialMenuEntry
/*public class PickFromCamera implements RadialMenuWidget.RadialMenuEntry
{
Picto p;
public PickFromCamera(Picto picto){
......@@ -296,7 +346,7 @@ public class PictoMenu {
addPicto(p.get_row(),p.get_column(),p.get_category(),p.get_translation(),1);
}
public void menuDisabled(){}
}
}*/
public class newPickFromCamera implements RadialMenuWidget.RadialMenuEntry
{
......
......@@ -1151,6 +1151,7 @@ protected void showOnlyTape(boolean onlyTape) {
break;
case EditPictoActivity.EDIT_PICTO_REQUEST:
if (resultCode == RESULT_OK) {
Log.i("TAG_PRUEBAS","Llega a fin de nuevo");
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);
......@@ -1161,6 +1162,17 @@ protected void showOnlyTape(boolean onlyTape) {
chooseTextAndSavePicto(path, row, col, freeRow, freeColumn, cat, legend);
}
break;
case EditPictoActivity.FINISH_EDIT:
Log.i("TAG_PRUEBAS","Llega a fin de editar");
int row = data.getIntExtra(Picto.JSON_ATTTRS.ROW, -1);
int col = data.getIntExtra(Picto.JSON_ATTTRS.COLUMN, -1);
int freeRow = data.getIntExtra(Picto.JSON_ATTTRS.FREE_ROW, -1);
int freeColumn = data.getIntExtra(Picto.JSON_ATTTRS.FREE_COLUMN, -1);
String path = data.getExtras().getString(EditPictoActivity.PATH);
String legend = data.getExtras().getString(Picto.JSON_ATTTRS.EXPRESSION);
chooseTextAndSavePicto(path, row, col, freeRow, freeColumn, cat, legend);
break;
}
}
......
package com.yottacode.pictogram.tabletlibrary.gui.communicator.cropper;
import android.Manifest;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Point;
import android.media.MediaPlayer;
import android.media.MediaRecorder;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
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.BotonCircular;
import com.yottacode.pictogram.tabletlibrary.gui.communicator.PictogramActivity;
import com.yottacode.pictogram.tabletlibrary.gui.login.MainActivity;
import com.yottacode.pictogram.tools.PCBcontext;
import com.yottacode.tools.GUITools;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import static java.lang.Thread.sleep;
/**
* Created by German on 06/02/2017.
*/
public class EditPictoActivity extends Activity {
// Private Constants ///////////////////////////////////////////////////////////////////////////
private boolean editar;
private static final int CAMERA_PIC_REQUEST = 1;
private static final int GALLERY_PIC_REQUEST = 2;
private static final String DEBUG_MESSAGE = "Pruebas";
public static final int EDIT_PICTO_REQUEST = 2288;
public static final int FINISH_EDIT = 2500;
//Botones Final/////////////////////////////////////////////////////////////////////
Button okButton;
Button cancelButton;
//Titulo//////////////////////////////////////////////////////////////////////////////
TextView titulo;
//For Cropper/////////////////////////////////////////////////////////////////////////
CropImageView cropImageView;
BotonCircular camara;
BotonCircular galeria;
public static final String PATH = "pathImage";
public static final String IMAGE_PICTO = "imagePicto";
private static final String LOG_PATH = EditPictoActivity.class.getName();
//For Legend//////////////////////////////////////////////////////////////////////////
EditText legend;
//For Audio///////////////////////////////////////////////////////////////////////////
private static final int REQUEST_RECORD_AUDIO_PERMISSION = 200;
private static String mFileName = null;
private MediaRecorder mRecorder = null;
private MediaPlayer mPlayer = null;
BotonCircular botonGrabar;
BotonCircular botonReproducir;
BotonCircular botonBorrar;
SeekBar barraReproducir;
TextView textoTTotal;
TextView textoTGrabacion;
LinearLayout layoutPreview;
LinearLayout layoutGrabacion;
RecordTask tareaGrabacion;
PlayTask tareaReproduccion;
//boolean grabando;
boolean reproduciendo;
int tiempoGrabado;
int tiempoReproducir;
int tiempoTotal;
// Requesting permission to RECORD_AUDIO
private boolean permissionToRecordAccepted = false;
private String [] permissions = {Manifest.permission.RECORD_AUDIO};
/**
* Tarea para gestionar tiempo de grabacion
*/
private class RecordTask extends AsyncTask<Integer, Integer, Void> {
protected Void doInBackground(Integer... params) {
while(!isCancelled() && tiempoGrabado < 10){
publishProgress(tiempoGrabado);
try {
sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
this.cancel(true);
return null;
}
protected void onProgressUpdate(Integer... progress) {
textoTGrabacion.setText("00:" + (tiempoGrabado == 10 ? tiempoGrabado : "0"+tiempoGrabado)+" | 00:10");
botonGrabar.PshowPressedRing();
tiempoGrabado += 1;
}
protected void onCancelled(){
stopRecording();
botonReproducir.setEnabled(tiempoGrabado > 1 ? true : false);
layoutPreview.setVisibility(tiempoGrabado > 1 ? View.VISIBLE : View.GONE);
layoutGrabacion.setVisibility(tiempoGrabado > 1 ? View.GONE : View.VISIBLE);
textoTTotal.setText(tiempoGrabado == 10 ? "00:00 | 00:" + tiempoGrabado : "00:00 | 00:0" + tiempoGrabado );
tiempoTotal = tiempoGrabado-1;
barraReproducir.setMax(tiempoTotal);
botonGrabar.PhidePressedRing();
reiniciarGrabacion();
Log.i(DEBUG_MESSAGE,"Fin Grabacion..");
}
}
/**
* Tarea para gestionar barra y tiempo de reproducion
*/
private class PlayTask extends AsyncTask <Integer, Integer, Void> {
protected Void doInBackground(Integer... params) {
while(!isCancelled() && tiempoReproducir < tiempoTotal){
try {
sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
publishProgress(tiempoReproducir);
}
this.cancel(true);
return null;
}
protected void onProgressUpdate(Integer... progress) {
tiempoReproducir+=1;
barraReproducir.setProgress(tiempoReproducir);
textoTTotal.setText(tiempoReproducir == 10 ? ("00:" + tiempoReproducir + " | 00:" + (tiempoTotal == 10 ? tiempoTotal : ("0" + tiempoTotal))) :
("00:0"+tiempoReproducir+" | 00:" +(tiempoTotal == 10 ? tiempoTotal: ("0" + tiempoTotal))));
}
protected void onCancelled(){
stopPlaying();
reiniciarReproducción();
Log.i(DEBUG_MESSAGE,"Fin Reproducion..");
}
}
// Activity Methods ////////////////////////////////////////////////////////////////////////////
@Override
public void onCreate(Bundle savedInstanceState) {
......@@ -44,37 +189,34 @@ public class EditPictoActivity extends Activity {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.edit_picto_layout);
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
LinearLayout ll = (LinearLayout)findViewById(R.id.image_layout);
Log.i("DETALLES", "Tam menu imagen: "+ ll.getLayoutParams().width);
ll.getLayoutParams().width = (int) (metrics.widthPixels * 0.75 ) - (int) getResources().getDimension(R.dimen.activity_vertical_margin) *2;
Log.i("DETALLES", "Tam menu imagen: "+ ll.getLayoutParams().width);
LinearLayout ll = (LinearLayout) findViewById(R.id.image_layout);
Log.i("DETALLES", "Tam menu imagen: " + ll.getLayoutParams().width);
ll.getLayoutParams().width = (int) (metrics.widthPixels * 0.65) - (int) getResources().getDimension(R.dimen.activity_vertical_margin) * 2;
Log.i("DETALLES", "Tam menu imagen: " + ll.getLayoutParams().width);
ll.requestLayout();
FrameLayout fl = (FrameLayout)findViewById(R.id.legend_menu);
Log.i("DETALLES", "Tam menu leyenda: "+ fl.getLayoutParams().width);
FrameLayout fl = (FrameLayout) findViewById(R.id.legend_menu);
Log.i("DETALLES", "Tam menu leyenda: " + fl.getLayoutParams().width);
fl.getLayoutParams().width = (int) (metrics.widthPixels * 0.25) - (int) getResources().getDimension(R.dimen.activity_vertical_margin);
Log.i("DETALLES", "Tam menu leyenda: "+ fl.getLayoutParams().width);
Log.i("DETALLES", "Tam menu leyenda: " + fl.getLayoutParams().width);
fl.requestLayout();
// Initialize Views.
final CropImageView cropImageView = (CropImageView) findViewById(R.id.CropImageView);
final EditText legend = (EditText) findViewById(R.id.edtLegend);
final Button okButton = (Button) findViewById(R.id.okButton);
final Button cancelButton = (Button) findViewById(R.id.cancelButton);
String transcription=getIntent().getExtras().getString(Picto.JSON_ATTTRS.EXPRESSION);
titulo = (TextView) findViewById(R.id.crop_title);
cropImageView = (CropImageView) findViewById(R.id.CropImageView);
legend = (EditText) findViewById(R.id.edtLegend);
okButton = (Button) findViewById(R.id.okButton);
cancelButton = (Button) findViewById(R.id.cancelButton);
String transcription = getIntent().getExtras().getString(Picto.JSON_ATTTRS.EXPRESSION);
cropImageView.setFixedAspectRatio(true);
cropImageView.setGuidelines(2);
cropImageView.setAspectRatio(1,1);
cropImageView.setAspectRatio(1, 1);
if(transcription != null && transcription.length()>0)
if (transcription != null && transcription.length() > 0)
legend.setText(transcription);
legend.setHorizontallyScrolling(false);
legend.setMaxLines(1);
......@@ -86,34 +228,53 @@ public class EditPictoActivity extends Activity {
cropImageView.setImageBitmap(imagePicto);
cropImageView.setMaxWidth(imagePicto.getWidth());
cropImageView.setMaxHeight(imagePicto.getHeight());
if (transcription!=null && transcription.length()>0)
if (transcription != null && transcription.length() > 0)
legend.setText(transcription);
editar = getIntent().getBooleanExtra("tipo",false);
titulo.setText(editar ? R.string.titleCropperEdit : R.string.titleCropperNew);
//Gestion de botones
okButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (legend.getText().toString().trim().length()>0) {
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 title = getResources().getString(R.string.app_name) + ' ' + legend.getText().toString();
String path = MediaStore.Images.Media.insertImage(PCBcontext.getContext().getContentResolver(), finalImage, 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());
cropImageView.setImageBitmap(finalImage);
setResult(RESULT_OK, intent);
finish(); //Termina la actividad de editar
}
else Toast.makeText(getBaseContext(),R.string.crop_TextRequired, Toast.LENGTH_LONG).show();
if (legend.getText().toString().trim().length() > 0) {
final Bitmap croppedImage = cropImageView.getCroppedImage();
//Escalar imagen
Bitmap finalImage = croppedImage.createScaledBitmap(croppedImage, 100, 100, true);
//Guardar imagen en galeria y obtener la ruta
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
finalImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String title = getResources().getString(R.string.app_name) + ' ' + legend.getText().toString();
String path = MediaStore.Images.Media.insertImage(PCBcontext.getContext().getContentResolver(), finalImage, title, null);
path = getRealPathFromURI(Uri.parse(path));
Log.i(LOG_PATH, " New image " + title + " saved at " + path);
//Intent intent = new Intent(EditPictoActivity.this,PictogramActivity.class);//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());
cropImageView.setImageBitmap(finalImage);
if(editar){
Log.i("TAG_PRUEBAS","Lanza ok de editar");
//Intent intent = new Intent(EditPictoActivity.this,PictogramActivity.class);//Mandar a pictogram activity el path y el texto de la imagen
Intent intent = getIntent();
intent.putExtra(PATH, path);
intent.putExtra(Picto.JSON_ATTTRS.EXPRESSION, legend.getText().toString());
intent.setAction(String.valueOf(FINISH_EDIT));
//startActivityForResult(intent, EditPictoActivity.EDIT_PICTO_REQUEST);
}else{
Log.i("TAG_PRUEBAS","Lanza ok de nuevo");
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());
setResult(RESULT_OK, intent);
}
finish(); //Termina la actividad de editar
} else
Toast.makeText(getBaseContext(), R.string.crop_TextRequired, Toast.LENGTH_LONG).show();
}
});
......@@ -122,7 +283,114 @@ public class EditPictoActivity extends Activity {
@Override
public void onClick(View v) {
finish();
setResult(RESULT_CANCELED,getIntent());
setResult(RESULT_CANCELED, getIntent());
}
});
// Record to the external cache directory for visibility
mFileName = getFilesDir().getPath();
mFileName += "/audiorecordtest.3gp";
ContentValues values = new ContentValues(3);
values.put(MediaStore.MediaColumns.TITLE, mFileName);
ActivityCompat.requestPermissions(this, permissions, REQUEST_RECORD_AUDIO_PERMISSION);
//Initialize elements and variables
botonGrabar = (BotonCircular) findViewById(R.id.botonGrabar);
botonReproducir = (BotonCircular) findViewById(R.id.reproducir);
botonBorrar = (BotonCircular) findViewById(R.id.botonBorrar);
camara = (BotonCircular) findViewById(R.id.camara);
galeria = (BotonCircular) findViewById(R.id.galeria);
barraReproducir = (SeekBar) findViewById(R.id.barraReproducir);
textoTTotal = (TextView) findViewById(R.id.tiempoTotal);
textoTGrabacion = (TextView) findViewById(R.id.tiempoActual);
layoutPreview = (LinearLayout) findViewById(R.id.layoutPreview);
layoutGrabacion = (LinearLayout) findViewById(R.id.layout_record);
botonReproducir.setEnabled(false);
layoutPreview.setVisibility(View.INVISIBLE);
reproduciendo = false;
tiempoGrabado = 0;
tiempoReproducir = 0;
tiempoTotal = 0;
//TODO: Aqui comprobar si ya hay grabación
//if (hayGrabacion){
layoutGrabacion.setVisibility(View.VISIBLE);
layoutPreview.setVisibility(View.GONE);
//}else{ Cargar el audio en el mediaPlayer
//layoutGrabacion.setVisibility(View.GONE);
//layoutPreview.setVisibility(View.VISIBLE);
//}
botonGrabar.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
tareaGrabacion = (RecordTask) new RecordTask().execute(tiempoGrabado);
startRecording();
Log.i(DEBUG_MESSAGE,"Grabando..");
return true;
case MotionEvent.ACTION_UP:
tareaGrabacion.cancel(true);
return true;
}
return false;
}
});
botonReproducir.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(reproduciendo){
tareaReproduccion.cancel(true);
reproduciendo = false;
Log.i(DEBUG_MESSAGE,"parar");
botonReproducir.setImageResource(android.R.drawable.ic_media_play);
}else{
reproduciendo = true;
startPlaying();
Log.i(DEBUG_MESSAGE,"Reproducir");
tareaReproduccion = (PlayTask) new PlayTask().execute(tiempoReproducir);
botonReproducir.setImageResource(android.R.drawable.ic_media_pause);
}
}
});
botonBorrar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
layoutGrabacion.setVisibility(View.VISIBLE);
layoutPreview.setVisibility(View.GONE);
}
});
camara.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent,CAMERA_PIC_REQUEST);
}
});
galeria.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, GALLERY_PIC_REQUEST);
}
});
/**Para bloquear de desplazamiento al pulsar las barras*/
barraReproducir.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
}
......@@ -142,4 +410,162 @@ public class EditPictoActivity extends Activity {
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode){
case REQUEST_RECORD_AUDIO_PERMISSION:
permissionToRecordAccepted = grantResults[0] == PackageManager.PERMISSION_GRANTED;
break;
}
if (!permissionToRecordAccepted ) finish();
}
private void startPlaying() {
mPlayer = new MediaPlayer();
try {
mPlayer.setDataSource(mFileName);
mPlayer.prepare();
mPlayer.start();
} catch (IOException e) {
Log.e(DEBUG_MESSAGE, "prepare() failed");
}
}
private void stopPlaying() {
mPlayer.release();
mPlayer = null;
}
private void startRecording() {
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
Log.i(DEBUG_MESSAGE,mFileName);
mRecorder.setOutputFile(mFileName);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
try {
mRecorder.prepare();
} catch (IOException e) {
Log.e(DEBUG_MESSAGE, "prepare() failed");
}
mRecorder.start();
}
private void stopRecording() {
try{
mRecorder.stop();
mRecorder.release();
}catch(RuntimeException e){
Log.i(DEBUG_MESSAGE, "Fallo en stop. No hay grabacion");
}
mRecorder = null;
}
private void reiniciarGrabacion(){
tiempoGrabado = 0;
textoTGrabacion.setText("00:00 | 00:10");
}
private void reiniciarReproducción(){
tiempoReproducir = 0;
barraReproducir.setProgress(0);
reproduciendo = false;
botonReproducir.setImageResource(android.R.drawable.ic_media_play);
textoTTotal.setText("00:00 | 00:"+(tiempoTotal == 10 ? tiempoTotal : "0" + tiempoTotal));
}
@Override
public void onStop() {
super.onStop();
if (mRecorder != null) {
mRecorder.release();
mRecorder = null;
}
if (mPlayer != null) {
mPlayer.release();
mPlayer = null;
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
int cat = getIntent().getIntExtra("cat", -1);
Bitmap imagen = null;
Bitmap rescaled = null;
switch(requestCode) {
case CAMERA_PIC_REQUEST: //Captura de foto
if (data != null && resultCode==RESULT_OK) {
imagen = (Bitmap) data.getExtras().get("data");
if(imagen!=null) {
Point size= GUITools.getScreenSize(EditPictoActivity.this);
float bWidth = imagen.getWidth();
float bHeight = imagen.getHeight();
float factorX=size.x*0.7f/bWidth;
float factorY=size.y*0.7f/bHeight;
float factor= factorY>factorX ? factorX : factorY;
bWidth=bWidth*factor;
bHeight=bHeight*factor;
rescaled = Bitmap.createScaledBitmap(imagen,(int) bWidth, (int) bHeight, true);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
rescaled.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
getIntent().putExtra(EditPictoActivity.IMAGE_PICTO, byteArray);
}
cropImageView.setImageBitmap(rescaled);
}
break;
case GALLERY_PIC_REQUEST: //Galeria
if(data!=null){
Uri selectedImage = data.getData();
Bitmap bitmap = null;
try {
bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImage);
} catch (IOException e) {
e.printStackTrace();
}
if(bitmap!=null) {
Point size= GUITools.getScreenSize(EditPictoActivity.this);
float bWidth = bitmap.getWidth();
float bHeight = bitmap.getHeight();
float factorX=size.x*0.7f/bWidth;
float factorY=size.y*0.7f/bHeight;
float factor= factorY>factorX ? factorX : factorY;
bWidth=bWidth*factor;
bHeight=bHeight*factor;
rescaled = Bitmap.createScaledBitmap(bitmap,(int) bWidth, (int) bHeight, true);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
rescaled.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
getIntent().putExtra(EditPictoActivity.IMAGE_PICTO, byteArray);
}
cropImageView.setImageBitmap(rescaled);
}
break;
/*case EditPictoActivity.EDIT_PICTO_REQUEST:
if (resultCode == RESULT_OK) {
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);
String path = data.getExtras().getString(EditPictoActivity.PATH);
String legend = data.getExtras().getString(Picto.JSON_ATTTRS.EXPRESSION);
chooseTextAndSavePicto(path, row, col, freeRow, freeColumn, cat, legend);
}
break;*/
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- main color -->
<item
android:bottom="2dp"
android:left="2dp"
android:right="2dp">
<shape>
<solid android:color="#FFFFFF" />
</shape>
</item>
<item>
<selector >
<item android:state_enabled="true"
android:state_focused="true">
<shape>
<stroke
android:width="2dp"
android:color="@color/VerdeApp"/>
</shape>
</item>
<item android:state_enabled="true">
<shape>
<stroke
android:width="2dp"
android:color="#ffffffff"/>
</shape>
</item>
</selector>
</item>
<!-- draw another block to cut-off the left and right bars -->
<item android:bottom="5.0dp">
<shape>
<solid android:color="#ffffff" />
</shape>
</item>
</layer-list>
......@@ -10,16 +10,17 @@
android:background="@android:color/white">
<TextView
android:paddingTop="@dimen/content_padding_half"
android:id="@+id/crop_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/titleCropper"
android:textSize="24sp"
android:textColor="@color/black"
android:textAlignment="center"
android:layout_gravity="center_horizontal"
android:background="@color/gray_blue" />
android:background="@color/VerdeApp"
android:paddingBottom="8dp"
android:paddingTop="@dimen/content_padding_half"
android:text="@string/titleCropperNew"
android:textAlignment="center"
android:textColor="@color/BlancoApp"
android:textSize="24sp" />
<LinearLayout
android:orientation="horizontal"
......@@ -29,23 +30,53 @@
android:layout_gravity="center_horizontal">
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/image_layout"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/activity_vertical_margin"
android:gravity="center">
android:layout_marginTop="@dimen/activity_vertical_margin"
android:gravity="center"
android:orientation="horizontal">
<com.yottacode.pictogram.tabletlibrary.gui.communicator.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_gravity="center"
android:adjustViewBounds="true"
android:cropToPadding="false"
/>
android:orientation="horizontal"
android:scaleType="centerInside" />
</LinearLayout>
<LinearLayout
android:id="@+id/botonera"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="25dp"
android:orientation="vertical">
<com.yottacode.pictogram.tabletlibrary.gui.communicator.BotonCircular
android:id="@+id/camara"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_alignParentBottom="false"
android:layout_centerHorizontal="false"
android:layout_weight="0.01"
android:background="#00ffffff"
android:src="@drawable/photo_camera" />
<com.yottacode.pictogram.tabletlibrary.gui.communicator.BotonCircular
android:id="@+id/galeria"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_alignParentBottom="false"
android:layout_centerHorizontal="false"
android:layout_weight="0.02"
android:background="#00ffffff"
android:src="@drawable/photo_gallery" />
</LinearLayout>
......@@ -54,83 +85,207 @@
android:layout_height="match_parent"
android:background="@android:color/darker_gray"
android:layout_marginRight="@dimen/activity_vertical_margin" />
<FrameLayout
android:orientation="vertical"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:id="@+id/legend_menu"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right"
android:layout_marginRight="@dimen/activity_vertical_margin"
android:weightSum="1"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:gravity="center_vertical|center">
android:gravity="center"
android:orientation="vertical"
android:paddingRight="5dp"
android:weightSum="1">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginBottom="40dp">
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:textColor= "@color/gray"
android:textSize="20sp"
android:text="@string/legendText"
android:id="@+id/textLegend"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textLegend"
android:layout_gravity="center" />
android:layout_gravity="center"
android:text="@string/legendText"
android:textColor="@color/gray"
android:textSize="20sp" />
<EditText
android:textSize="20sp"
android:imeOptions="actionDone"
android:id="@+id/edtLegend"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:id="@+id/edtLegend"
android:textColor="@color/black"
android:layout_below="@+id/textLegend"
android:layout_gravity="center"
android:background="@drawable/editpicto_edittext_style"
android:ems="10"
android:gravity="center"
android:textColorLink="?android:attr/colorAccent"
android:imeOptions="actionDone"
android:maxLines="1"
android:textColor="@color/black"
android:textColorLink="?android:attr/colorAccent"
android:textCursorDrawable="@null"
/>
android:textSize="20sp" />
<TextView
android:id="@+id/textView_Audio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="Audio"
android:textColor="@color/gray"
android:textSize="20sp" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp">
<LinearLayout
android:id="@+id/layout_record"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="horizontal"
android:paddingTop="5dp"
android:visibility="visible"
android:weightSum="1">
<com.yottacode.pictogram.tabletlibrary.gui.communicator.BotonCircular
android:id="@+id/gifGrabar"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_alignParentBottom="false"
android:layout_centerHorizontal="false"
android:layout_gravity="center"
android:layout_weight="0.38"
android:background="#00ffffff"
android:src="@android:drawable/ic_menu_delete" />
<TextView
android:id="@+id/tiempoActual"
android:layout_width="125dp"
android:layout_height="match_parent"
android:gravity="center"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="00:00 | 00:10"
android:textColor="@color/VerdeApp" />
<com.yottacode.pictogram.tabletlibrary.gui.communicator.BotonCircular
android:id="@+id/botonGrabar"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_alignParentBottom="false"
android:layout_centerHorizontal="false"
android:background="#00ffffff"
android:clickable="true"
android:src="@drawable/micro" />
</LinearLayout>
<LinearLayout
android:id="@+id/layoutPreview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="@color/BlancoApp"
android:orientation="vertical"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"
android:visibility="invisible">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.02"
android:text="Preview"
android:textAlignment="center"
android:textColor="@android:color/black" />
<LinearLayout
android:id="@+id/LinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal">
<com.yottacode.pictogram.tabletlibrary.gui.communicator.BotonCircular
android:id="@+id/reproducir"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_alignParentBottom="false"
android:layout_centerHorizontal="false"
android:background="#00ffffff"
android:src="@android:drawable/ic_media_play" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.00"
android:orientation="vertical">
<SeekBar
android:id="@+id/barraReproducir"
style="@style/Widget.AppCompat.SeekBar"
android:layout_width="125dp"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tiempoTotal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top|center"
android:text="00:00 | 00:00"
android:textColor="@color/VerdeApp" />
</LinearLayout>
<com.yottacode.pictogram.tabletlibrary.gui.communicator.BotonCircular
android:id="@+id/botonBorrar"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_alignParentBottom="false"
android:layout_centerHorizontal="false"
android:background="#00ffffff"
android:src="@android:drawable/ic_menu_delete" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_width="260dp"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_gravity="bottom|center"
android:layout_marginBottom="10dp"
android:gravity="bottom|center_horizontal"
android:layout_marginBottom="40dp">
android:orientation="horizontal">
<Button
android:id="@+id/okButton"
android:layout_width="120dp"
android:layout_width="110dp"
android:layout_height="wrap_content"
android:textColor="?android:attr/textColorPrimary"
android:textSize="18sp"
android:textAlignment="center"
android:text="@string/accept"
android:gravity="center_horizontal"
android:layout_marginLeft="10dp"
android:capitalize="sentences" />
android:textAlignment="center"
android:textColor="?android:attr/textColorPrimary"
android:textSize="18sp" />
<Button
android:id="@+id/cancelButton"
android:layout_width="110dp"
android:layout_height="wrap_content"
android:textColor="?android:attr/textColorPrimary"
android:textSize="18sp"
android:textAlignment="center"
android:text="@string/cancel"
android:gravity="center_horizontal"
android:layout_marginRight="10dp"
android:capitalize="sentences"
android:layout_width="120dp" />
android:textAlignment="center"
android:textColor="?android:attr/textColorPrimary"
android:textSize="18sp" />
</LinearLayout>
......
......@@ -37,7 +37,6 @@
<string name="session_eval_notevuated">not evaluated</string>
<string name="session_eval_discarded">discarded</string>
<string name="crop">Crop</string>
<string name="titleCropper">Edit Picto</string>
<string name="cancel">Cancel</string>
<string name="legendText">Legend</string>
......@@ -45,6 +44,8 @@
<!-- Cropper -->
<string name="crop_TextRequired">Por favor, introduzca una leyenda para el pictograma</string>
<string name="uploadingImage">Subiendo imagen al servidor</string>
<string name="titleCropperEdit">Edit Picto</string>
<string name="titleCropperNew">New Picto</string>
</resources>
......@@ -37,14 +37,14 @@
<string name="session_eval_notevuated">no evaluado</string>
<string name="session_eval_discarded">inválido</string>
<string name="crop">Recortar</string>
<string name="titleCropper">Nuevo Pictograma</string>
<string name="crop_TextRequired">Por favor, introduzca una leyenda para el pictograma</string>
<!-- Cropper -->
<string name="legendText">Leyenda:</string>
<string name="uploadingImage">Subiendo imagen al servidor</string>
<string name="cancel">Cancelar</string>
<string name="titleCropperEdit">Editar Pictograma</string>
<string name="titleCropperNew">Nuevo Pictograma</string>
</resources>
......@@ -42,8 +42,9 @@
<string name="legendText">Leyenda:</string>
<string name="crop">Recortar</string>
<string name="titleCropper">Nuevo Pictograma</string>
<string name="titleCropperNew">Nuevo Pictograma</string>
<string name="titleCropperEdit">Editar Pictograma</string>
<string name="crop_TextRequired">Por favor, introduzca una leyenda para el pictograma</string>
<string name="uploadingImage">Subiendo imagen al servidor</string>
<string name="cancel">Cancel</string>
</resources>
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":tabletlibrary" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" version="4">
<module external.linked.project.id=":tabletlibrary" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
......
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