Commit de4d53ee by German Callejas

Vista Para recortar imagen añadida (Falta darle funcionalidad total y ajustar el diseño)

parent 221555ad
...@@ -250,9 +250,6 @@ public class CropImageView extends ImageView { ...@@ -250,9 +250,6 @@ public class CropImageView extends ImageView {
* @return a new Bitmap representing the cropped image * @return a new Bitmap representing the cropped image
*/ */
public Bitmap getCroppedImage() { public Bitmap getCroppedImage() {
// Implementation reference: http://stackoverflow.com/a/26930938/1068656
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,15 +268,15 @@ public class CropImageView extends ImageView { ...@@ -271,15 +268,15 @@ public class CropImageView extends ImageView {
final float transY = 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);
Log.i("DETALLES","transX: "+transX + "- transY: "+transY); Log.i("DETALLES","transX: "+transX + "- transY: "+transY);
Log.i("DETALLES","Edge Left: "+Edge.LEFT.getCoordinate() + "- Edge Top: "+Edge.TOP.getCoordinate()); Log.i("DETALLES","Edge Left: "+Edge.LEFT.getCoordinate() + "- Edge Top: "+Edge.TOP.getCoordinate());
Log.i("DETALLES","ancho original: "+originalBitmap.getWidth() + " Alto original: "+originalBitmap.getHeight()); Log.i("DETALLES","ancho original: "+originalBitmap.getWidth() + " Alto original: "+originalBitmap.getHeight());
final float cropWidth = Edge.getWidth(); final float cropWidth = Edge.getWidth();
final float cropHeight = Edge.getHeight(); final float cropHeight = Edge.getHeight();*/
Log.i("DETALLES","ancho original: "+originalBitmap.getWidth() + " Alto original: "+originalBitmap.getHeight()); /*Log.i("DETALLES","ancho original: "+originalBitmap.getWidth() + " Alto original: "+originalBitmap.getHeight());
Log.i("DETALLES","ancho: "+cropWidth + " Alto: "+cropHeight); Log.i("DETALLES","ancho: "+cropWidth + " Alto: "+cropHeight);*/
// Ensure that the left and top edges are not outside of the ImageView bounds. // Ensure that the left and top edges are not outside of the ImageView bounds.
/*final float bitmapLeft = (transX < 0) ? Math.abs(transX) : 0; /*final float bitmapLeft = (transX < 0) ? Math.abs(transX) : 0;
final float bitmapTop = (transY < 0) ? Math.abs(transY) : 0;*/ final float bitmapTop = (transY < 0) ? Math.abs(transY) : 0;*/
...@@ -287,17 +284,17 @@ public class CropImageView extends ImageView { ...@@ -287,17 +284,17 @@ public class CropImageView extends ImageView {
// Get the original bitmap object. // Get the original bitmap object.
//final Bitmap originalBitmap = ((BitmapDrawable) drawable).getBitmap(); //final Bitmap originalBitmap = ((BitmapDrawable) drawable).getBitmap();
final float bitmapLeft = ((findViewById(R.id.ScrollView)).getWidth() - originalBitmap.getWidth())/2; /*final float bitmapLeft = ((findViewById(R.id.ScrollView)).getWidth() - originalBitmap.getWidth())/2;
final float bitmapTop = ((findViewById(R.id.ScrollView)).getHeight() - originalBitmap.getHeight())/2; final float bitmapTop = ((findViewById(R.id.ScrollView)).getHeight() - originalBitmap.getHeight())/2;*/
Log.i("DETALLES","bitmapLeft: "+bitmapLeft + "- bitmapTop: "+bitmapTop); /* Log.i("DETALLES","bitmapLeft: "+bitmapLeft + "- bitmapTop: "+bitmapTop);
// Calculate the top-left corner of the crop window relative to the ~original~ bitmap size. // Calculate the top-left corner of the crop window relative to the ~original~ bitmap size.
final float cropX = (bitmapLeft + Edge.LEFT.getCoordinate()); final float cropX = (bitmapLeft + Edge.LEFT.getCoordinate());
final float cropY = (bitmapTop + Edge.TOP.getCoordinate()); final float cropY = (bitmapTop + Edge.TOP.getCoordinate());
Log.i("DETALLES","Edge Left: "+Edge.LEFT.getCoordinate() + "- Edge Top: "+Edge.TOP.getCoordinate()); Log.i("DETALLES","Edge Left: "+Edge.LEFT.getCoordinate() + "- Edge Top: "+Edge.TOP.getCoordinate());
Log.i("DETALLES","Posicion X: "+cropX + "- Posicion Y: "+cropY); Log.i("DETALLES","Posicion X: "+cropX + "- Posicion Y: "+cropY);*/
// Calculate the crop window size relative to the ~original~ bitmap size. // Calculate the crop window size relative to the ~original~ bitmap size.
// Make sure the right and bottom edges are not outside the ImageView bounds (this is just to address rounding discrepancies). // Make sure the right and bottom edges are not outside the ImageView bounds (this is just to address rounding discrepancies).
...@@ -308,10 +305,10 @@ public class CropImageView extends ImageView { ...@@ -308,10 +305,10 @@ public class CropImageView extends ImageView {
Log.i("DETALLES","ancho: "+cropWidth + " Alto: "+cropHeight);*/ Log.i("DETALLES","ancho: "+cropWidth + " Alto: "+cropHeight);*/
// Crop the subset from the original Bitmap. // Crop the subset from the original Bitmap.
return Bitmap.createBitmap(originalBitmap, return Bitmap.createBitmap(originalBitmap,
(int) cropX, (int) (Edge.LEFT.getCoordinate() - transX),
(int) cropY, (int) (Edge.TOP.getCoordinate() - transY),
(int) cropWidth, (int) Edge.getWidth(),
(int) cropHeight); (int) Edge.getHeight());
} }
...@@ -573,4 +570,7 @@ public class CropImageView extends ImageView { ...@@ -573,4 +570,7 @@ public class CropImageView extends ImageView {
invalidate(); invalidate();
} }
public void setGravity(int gravity) {
this.setGravity(gravity);
}
} }
package com.yottacode.pictogram.tabletlibrary.cropper;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.yottacode.pictogram.tabletlibrary.R;
import com.yottacode.pictogram.tabletlibrary.gui.communicator.PictogramActivity;
import com.yottacode.pictogram.tools.PCBcontext;
import org.w3c.dom.Text;
/**
* Created by German on 06/02/2017.
*/
public class EditPictoActivity extends Activity {
// Private Constants ///////////////////////////////////////////////////////////////////////////
private static final int GUIDELINES_ON_TOUCH = 1;
// Activity Methods ////////////////////////////////////////////////////////////////////////////
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.edit_picto_layout);
// Initialize Views.
final CropImageView cropImageView = (CropImageView) findViewById(R.id.CropImageView);
final EditText legend = (EditText) findViewById(R.id.legend);
final Button okButton = (Button) findViewById(R.id.okButton);
final Button cancelButton = (Button) findViewById(R.id.cancelButton);
//final ImageView backgroundImage = (ImageView) findViewById(R.id.backgroundImage);
cropImageView.setFixedAspectRatio(true);
cropImageView.setGuidelines(2);
cropImageView.setAspectRatio(1,1);
String legendText = getIntent().getExtras().getString("textPicto");
if(legendText != null) {
Log.i("DETALLES","Llega el intent al layout recortar, con texto: " + legend);
legend.setText(legendText);
}
byte[] byteArray = getIntent().getByteArrayExtra("imagePicto");
Bitmap imagePicto = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
cropImageView.setImageBitmap(imagePicto);
/* byteArray = getIntent().getByteArrayExtra("imageBackground");
Bitmap imageBackground = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
backgroundImage.setImageBitmap(imageBackground);*/
okButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Bitmap croppedImage = cropImageView.getCroppedImage();
//Escalar y guardarla al server
croppedImage.createScaledBitmap(croppedImage,96,96,true);
cropImageView.setImageBitmap(croppedImage);
}
});
//Si cancela, volver a pictogram activity
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
Intent intent = new Intent(EditPictoActivity.this, PictogramActivity.class);
startActivity(intent);
}
});
}
/**
* To set background image for simulate the pictogramActivity
* @param bm
*/
/*public void setBackgroundImage(Bitmap bm){
ImageView backgroundImage = (ImageView) findViewById(R.id.backgroundImage);
backgroundImage.setImageBitmap(bm);
}*/
/**
* To set the image to crop
* @param bm
*/
public void setCropImage(Bitmap bm){
ImageView cropImage = (ImageView) findViewById(R.id.CropImageView);
cropImage.setImageBitmap(bm);
}
/**
* To set the image to crop
* @param text
*/
public void setLegendImage(String text){
EditText legend = (EditText) findViewById(R.id.legend);
legend.setText(text.toString());
}
}
package com.yottacode.pictogram.tabletlibrary.cropper;
import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.ToggleButton;
import com.yottacode.pictogram.tabletlibrary.cropper.CropImageView;
import com.yottacode.pictogram.tabletlibrary.R;
public class MainCropImage extends Activity {
// Private Constants ///////////////////////////////////////////////////////////////////////////
private static final int GUIDELINES_ON_TOUCH = 1;
// Activity Methods ////////////////////////////////////////////////////////////////////////////
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.crop_layout);
// Initialize Views.
//final ToggleButton fixedAspectRatioToggleButton = (ToggleButton) findViewById(R.id.fixedAspectRatioToggle);
//final TextView aspectRatioXTextView = (TextView) findViewById(R.id.aspectRatioX);
//final SeekBar aspectRatioXSeekBar = (SeekBar) findViewById(R.id.aspectRatioXSeek);
//final TextView aspectRatioYTextView = (TextView) findViewById(R.id.aspectRatioY);
//final SeekBar aspectRatioYSeekBar = (SeekBar) findViewById(R.id.aspectRatioYSeek);
//final Spinner guidelinesSpinner = (Spinner) findViewById(R.id.showGuidelinesSpin);
final CropImageView cropImageView = (CropImageView) findViewById(R.id.CropImageView);
final ImageView croppedImageView = (ImageView) findViewById(R.id.croppedImageView);
final Button cropButton = (Button) findViewById(R.id.Button_crop);
cropImageView.setGuidelines(CropImageView.GUIDELINES_ON); //To show the guidelines
cropImageView.setAspectRatio(1,1);
// Initializes fixedAspectRatio toggle button.
/*fixedAspectRatioToggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
cropImageView.setFixedAspectRatio(isChecked);
cropImageView.setAspectRatio(aspectRatioXSeekBar.getProgress(), aspectRatioYSeekBar.getProgress());
aspectRatioXSeekBar.setEnabled(isChecked);
aspectRatioYSeekBar.setEnabled(isChecked);
}
});*/
// Set seek bars to be disabled until toggle button is checked.
/*aspectRatioXSeekBar.setEnabled(false);
aspectRatioYSeekBar.setEnabled(false);
aspectRatioXTextView.setText(String.valueOf(aspectRatioXSeekBar.getProgress()));
aspectRatioYTextView.setText(String.valueOf(aspectRatioXSeekBar.getProgress()));*/
// Initialize aspect ratio X SeekBar.
/*aspectRatioXSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar aspectRatioXSeekBar, int progress, boolean fromUser) {
if (progress < 1) {
aspectRatioXSeekBar.setProgress(1);
}
cropImageView.setAspectRatio(aspectRatioXSeekBar.getProgress(), aspectRatioYSeekBar.getProgress());
aspectRatioXTextView.setText(String.valueOf(aspectRatioXSeekBar.getProgress()));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// Do nothing.
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// Do nothing.
}
});*/
// Initialize aspect ratio Y SeekBar.
/*aspectRatioYSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar aspectRatioYSeekBar, int progress, boolean fromUser) {
if (progress < 1) {
aspectRatioYSeekBar.setProgress(1);
}
cropImageView.setAspectRatio(aspectRatioXSeekBar.getProgress(), aspectRatioYSeekBar.getProgress());
aspectRatioYTextView.setText(String.valueOf(aspectRatioYSeekBar.getProgress()));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// Do nothing.
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// Do nothing.
}
});*/
// Set up the Guidelines Spinner.
/*guidelinesSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
cropImageView.setGuidelines(i);
}
public void onNothingSelected(AdapterView<?> adapterView) {
// Do nothing.
}
});
guidelinesSpinner.setSelection(GUIDELINES_ON_TOUCH);*/
// Initialize the Crop button.
cropButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Bitmap croppedImage = cropImageView.getCroppedImage();
croppedImageView.setImageBitmap(croppedImage);
}
});
}
}
...@@ -29,7 +29,7 @@ import java.util.ArrayList; ...@@ -29,7 +29,7 @@ import java.util.ArrayList;
public class PictoItemViewGenerator { public class PictoItemViewGenerator {
public static final int LAYOUT = R.layout.picto_grid_item; public static final int LAYOUT = R.layout.picto_grid_item;
public static final int LAYOUT_BIG = R.layout.picto_grid_item_big; public static final int LAYOUT_BIG = R.layout.picto_grid_item_big;
private static final byte MAX_LINE_LENGTH = 9; private static final byte MAX_LINE_LENGTH = 12;
private static final byte MAX_LINE_LENGTH_FULL = 7; private static final byte MAX_LINE_LENGTH_FULL = 7;
private static final String LOG_TAG = PictoItemViewGenerator.class.getCanonicalName(); private static final String LOG_TAG = PictoItemViewGenerator.class.getCanonicalName();
public static int mirror_color=0; public static int mirror_color=0;
...@@ -40,8 +40,11 @@ public class PictoItemViewGenerator { ...@@ -40,8 +40,11 @@ public class PictoItemViewGenerator {
* @param picto Pictogram to set the legend text * @param picto Pictogram to set the legend text
* @return the text modified * @return the text modified
*/ */
private static String format_legend(Picto picto, int maxlength) { private static String format_legend(Picto picto, int maxlength,boolean isFull) {
String texto=picto.get_translation().toUpperCase(); String texto=picto.get_translation().toUpperCase();
if(!isFull) return texto;
WordTools wordTools=new WordTools(); WordTools wordTools=new WordTools();
if (texto.length()>maxlength) { if (texto.length()>maxlength) {
String[] words = texto.split(" "); String[] words = texto.split(" ");
...@@ -73,7 +76,7 @@ public class PictoItemViewGenerator { ...@@ -73,7 +76,7 @@ public class PictoItemViewGenerator {
int width = bitmap.getWidth(); //Ancho original int width = bitmap.getWidth(); //Ancho original
int height = bitmap.getHeight(); //Alto original int height = bitmap.getHeight(); //Alto original
String texto = format_legend(picto,MAX_LINE_LENGTH); //String texto = format_legend(picto,MAX_LINE_LENGTH);
/*if(picto.get_legend().equals("normal")) { //Normal legend /*if(picto.get_legend().equals("normal")) { //Normal legend
android.graphics.Bitmap.Config bitmapConfig = bitmap.getConfig(); android.graphics.Bitmap.Config bitmapConfig = bitmap.getConfig();
...@@ -126,7 +129,7 @@ public class PictoItemViewGenerator { ...@@ -126,7 +129,7 @@ public class PictoItemViewGenerator {
textView.setWidth(100); textView.setWidth(100);
textView.setGravity(Gravity.CENTER); textView.setGravity(Gravity.CENTER);
textView.setMaxLines(3); textView.setMaxLines(3);
textView.setText(texto); //textView.setText(texto);
textView.setDrawingCacheEnabled(true); textView.setDrawingCacheEnabled(true);
canvas.drawBitmap(textView.getDrawingCache(), 0, 25, null); canvas.drawBitmap(textView.getDrawingCache(), 0, 25, null);
...@@ -192,12 +195,12 @@ public class PictoItemViewGenerator { ...@@ -192,12 +195,12 @@ public class PictoItemViewGenerator {
legend_full.setVisibility(View.GONE); legend_full.setVisibility(View.GONE);
break; break;
case "normal": case "normal":
legend.setText(format_legend(picto,MAX_LINE_LENGTH)); legend.setText(format_legend(picto,MAX_LINE_LENGTH,false));
legend.setVisibility(View.VISIBLE); legend.setVisibility(View.VISIBLE);
legend_full.setVisibility(View.GONE); legend_full.setVisibility(View.GONE);
break; break;
default: default:
legend_full.setText(format_legend(picto,MAX_LINE_LENGTH_FULL)); legend_full.setText(format_legend(picto,MAX_LINE_LENGTH_FULL,true));
legend.setVisibility(View.GONE); legend.setVisibility(View.GONE);
legend_full.setVisibility(View.VISIBLE); legend_full.setVisibility(View.VISIBLE);
} }
......
...@@ -7,17 +7,25 @@ import android.content.DialogInterface; ...@@ -7,17 +7,25 @@ import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.os.Parcelable;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.text.InputType; import android.text.InputType;
import android.util.AttributeSet;
import android.util.Log; import android.util.Log;
import android.view.Gravity;
import android.view.View; import android.view.View;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.yottacode.pictogram.action.VocabularyAction; import com.yottacode.pictogram.action.VocabularyAction;
...@@ -27,8 +35,10 @@ import com.yottacode.pictogram.grammar.iLocalPicto; ...@@ -27,8 +35,10 @@ import com.yottacode.pictogram.grammar.iLocalPicto;
import com.yottacode.pictogram.net.PictoUploader; import com.yottacode.pictogram.net.PictoUploader;
import com.yottacode.pictogram.tabletlibrary.R; import com.yottacode.pictogram.tabletlibrary.R;
import com.yottacode.pictogram.tabletlibrary.cropper.CropImageView; import com.yottacode.pictogram.tabletlibrary.cropper.CropImageView;
import com.yottacode.pictogram.tabletlibrary.cropper.EditPictoActivity;
import com.yottacode.pictogram.tools.PCBcontext; import com.yottacode.pictogram.tools.PCBcontext;
import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
...@@ -42,6 +52,8 @@ public class PictoMenu { ...@@ -42,6 +52,8 @@ public class PictoMenu {
PictogramActivity activity; PictogramActivity activity;
//Variables used on the picto menu (only supervisors) //Variables used on the picto menu (only supervisors)
private static final int CAMERA_PIC_REQUEST = 1;
private RadialMenuWidget PieMenu; private RadialMenuWidget PieMenu;
private ImageView detail; private ImageView detail;
private RelativeLayout ll; private RelativeLayout ll;
...@@ -178,7 +190,87 @@ public class PictoMenu { ...@@ -178,7 +190,87 @@ public class PictoMenu {
} }
public void createViewForCrop(final Picto picto) {
final RelativeLayout rl = new RelativeLayout(PCBcontext.getContext());
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.MATCH_PARENT);
activity.addContentView(rl, params);
rl.setBackgroundColor(argb(180,0,0,0));
final TextView text = new TextView(PCBcontext.getContext());
final CropImageView imageToCrop = new CropImageView(PCBcontext.getContext());
final Button okButton = new Button(PCBcontext.getContext());
final Button cancelButton = new Button(PCBcontext.getContext());
rl.addView(imageToCrop);
rl.addView(text);
rl.addView(okButton);
rl.addView(cancelButton);
text.setWidth(200);
imageToCrop.setMaxHeight(300);
imageToCrop.setMaxWidth(650);
LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
params2.gravity = Gravity.CENTER;
imageToCrop.setLayoutParams(params2);
//Ponerla en el view
imageToCrop.setImageResource(R.drawable.descarga);
imageToCrop.setGuidelines(CropImageView.GUIDELINES_ON); //To show the guidelines
imageToCrop.setFixedAspectRatio(true);
imageToCrop.setAspectRatio(1,1);
text.setX((activity.getResources().getDisplayMetrics().widthPixels/2) - (text.getWidth()/2));
text.setY(5);
text.setTextColor(Color.WHITE);
text.setText(R.string.titleCropper);
text.setTextSize(24);
//Obtener imagen tras camara
okButton.setText(R.string.crop);
okButton.setTextSize(20);
okButton.setWidth(100);
//okButton.setGravity(Gravity.BOTTOM);
cancelButton.setText(R.string.cancel);
cancelButton.setTextSize(20);
cancelButton.setWidth(100);
//cancelButton.setGravity(Gravity.BOTTOM);
okButton.setX(activity.getResources().getDisplayMetrics().widthPixels/2 - okButton.getWidth() - 10);
okButton.setY(activity.getResources().getDisplayMetrics().heightPixels - 20);
cancelButton.setX((activity.getResources().getDisplayMetrics().widthPixels/2) + cancelButton.getWidth() + 10);
cancelButton.setY(activity.getResources().getDisplayMetrics().heightPixels - 20);
okButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Bitmap croppedImage = imageToCrop.getCroppedImage();
Bitmap scaled = null;
scaled.createScaledBitmap(croppedImage,96,96,false);
imageToCrop.setImageBitmap(scaled);
}
});
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
rl.removeAllViewsInLayout();
rl.removeAllViewsInLayout();
rl.setVisibility(View.GONE);
}
});
}
/**Function for open a new View for change the expression of a picto /**Function for open a new View for change the expression of a picto
* *
...@@ -303,7 +395,7 @@ public class PictoMenu { ...@@ -303,7 +395,7 @@ public class PictoMenu {
PieMenu.addMenuEntry(new UnlockPictoMenu(picto)); PieMenu.addMenuEntry(new UnlockPictoMenu(picto));
PieMenu.addMenuEntry(new DisablePictoMenu(picto)); PieMenu.addMenuEntry(new DisablePictoMenu(picto));
PieMenu.addMenuEntry(new SetInvisibleMenu(picto)); PieMenu.addMenuEntry(new SetInvisibleMenu(picto));
//PieMenu.addMenuEntry(new EditMenu(picto)); PieMenu.addMenuEntry(new EditMenu(picto));
ll.addView(PieMenu); ll.addView(PieMenu);
...@@ -418,29 +510,19 @@ public class PictoMenu { ...@@ -418,29 +510,19 @@ public class PictoMenu {
public List<RadialMenuWidget.RadialMenuEntry> getChildren() { return children; } public List<RadialMenuWidget.RadialMenuEntry> getChildren() { return children; }
public void menuActiviated() public void menuActiviated()
{ {
/*ll.getChildAt(1).setX(ll.getChildAt(1).getX() + 30); //ll.getChildAt(1).setX(ll.getChildAt(1).getX() + 30);
children = new ArrayList<>(Arrays.asList(new EditTextPicto(p),new EditImage(p)));*/ //children = new ArrayList<>(Arrays.asList(new EditTextPicto(p),new EditImage(p)));
activity.setContentView(R.layout.crop_layout); ll.setVisibility(View.GONE);
ll.removeAllViewsInLayout();
final CropImageView cropImageView = (CropImageView) activity.findViewById(R.id.CropImageView);
cropImageView.setImageResource(R.drawable.common_full_open_on_phone);
final ImageView croppedImageView = (ImageView) activity.findViewById(R.id.croppedImageView);
final Button cropButton = (Button) activity.findViewById(R.id.Button_crop);
cropImageView.setGuidelines(CropImageView.GUIDELINES_ON); //To show the guidelines /**Al presionar el boton de ajustes lanza la actividad de la camara*/
cropImageView.setFixedAspectRatio(true); Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cropImageView.setAspectRatio(1,1); Log.i("DETALLES","Texto del picto "+"'"+p.get_translation()+"'");
cropButton.setOnClickListener(new View.OnClickListener() { if(p!=null)
@Override cameraIntent.putExtra("pictoLegend",p.get_translation());
public void onClick(View v) {
final Bitmap croppedImage = cropImageView.getCroppedImage();
croppedImageView.setImageBitmap(croppedImage);
}
});
activity.startActivityForResult(cameraIntent,CAMERA_PIC_REQUEST);
} }
public void menuDisabled(){ public void menuDisabled(){
ll.getChildAt(1).setX(ll.getChildAt(1).getX() - 30); ll.getChildAt(1).setX(ll.getChildAt(1).getX() - 30);
...@@ -481,9 +563,46 @@ public class PictoMenu { ...@@ -481,9 +563,46 @@ public class PictoMenu {
{ {
/**TODO: Llamar a la interfaz de editar foto*/ /**TODO: Llamar a la interfaz de editar foto*/
Toast.makeText(PCBcontext.getContext(),"Editar Imagen", Toast.LENGTH_SHORT).show(); Toast.makeText(PCBcontext.getContext(),"Editar Imagen", Toast.LENGTH_SHORT).show();
ll.removeAllViewsInLayout();
createViewForCrop(p);
//activity.setContentView(R.layout.edit_picto_layout);
/*
ll = (RelativeLayout) activity.findViewById(R.id.TotalLayout);
activity.addContentView(ll,ll.getLayoutParams());
ll.setBackgroundColor(argb(180,0,0,0));
final CropImageView cropImageView = (CropImageView) activity.findViewById(R.id.CropImageView);
cropImageView.setImageResource(R.drawable.descarga);
final ImageView croppedImageView = (ImageView) activity.findViewById(R.id.croppedImageView);
final Button cropButton = (Button) activity.findViewById(R.id.Button_crop);
final Button cancelButton = (Button) activity.findViewById(R.id.Button_cancel);
cropImageView.setGuidelines(CropImageView.GUIDELINES_ON); //To show the guidelines
cropImageView.setFixedAspectRatio(true);
cropImageView.setAspectRatio(1,1);
cropButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Bitmap croppedImage = cropImageView.getCroppedImage();
Bitmap scaled = null;
scaled.createScaledBitmap(croppedImage,96,96,false);
croppedImageView.setImageBitmap(scaled);
}
});
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ll.setVisibility(View.GONE);
ll.removeAllViewsInLayout();
}
});*/
} }
public void menuDisabled(){} public void menuDisabled(){}
} }
} }
...@@ -8,12 +8,16 @@ import android.content.ClipDescription; ...@@ -8,12 +8,16 @@ import android.content.ClipDescription;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.PixelFormat; import android.graphics.PixelFormat;
import android.media.Ringtone; import android.media.Ringtone;
import android.media.RingtoneManager; import android.media.RingtoneManager;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.provider.MediaStore;
import android.speech.tts.UtteranceProgressListener; import android.speech.tts.UtteranceProgressListener;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
...@@ -37,6 +41,7 @@ import android.widget.ImageButton; ...@@ -37,6 +41,7 @@ import android.widget.ImageButton;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.Toast; import android.widget.Toast;
import com.google.android.gms.gcm.GcmNetworkManager;
import com.yottacode.pictogram.action.PictosAction; import com.yottacode.pictogram.action.PictosAction;
import com.yottacode.pictogram.action.TalkAction; import com.yottacode.pictogram.action.TalkAction;
import com.yottacode.pictogram.dao.Picto; import com.yottacode.pictogram.dao.Picto;
...@@ -46,6 +51,7 @@ import com.yottacode.pictogram.net.ImgDownloader; ...@@ -46,6 +51,7 @@ import com.yottacode.pictogram.net.ImgDownloader;
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;
import com.yottacode.pictogram.tabletlibrary.cropper.EditPictoActivity;
import com.yottacode.pictogram.tabletlibrary.gui.login.SerialActivity; import com.yottacode.pictogram.tabletlibrary.gui.login.SerialActivity;
import com.yottacode.pictogram.tabletlibrary.gui.session.SessionActivity; import com.yottacode.pictogram.tabletlibrary.gui.session.SessionActivity;
import com.yottacode.pictogram.tabletlibrary.net.NetServiceTablet; import com.yottacode.pictogram.tabletlibrary.net.NetServiceTablet;
...@@ -56,6 +62,8 @@ import com.yottacode.pictogram.tts.TTSHelper; ...@@ -56,6 +62,8 @@ import com.yottacode.pictogram.tts.TTSHelper;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
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;
...@@ -66,7 +74,8 @@ import java.util.concurrent.TimeUnit; ...@@ -66,7 +74,8 @@ import java.util.concurrent.TimeUnit;
public class PictogramActivity extends Activity implements VocabularyTalk.iVocabularyListener { public class PictogramActivity extends Activity implements VocabularyTalk.iVocabularyListener {
private static final int CAMERA_PIC_REQUEST = 1;
private static final int GALLERY_PIC_REQUEST = 2;
// Main layout for this activity // Main layout for this activity
RelativeLayout mainLayout; RelativeLayout mainLayout;
// Adapter for de grid showing the categories grid (and main pictos) // Adapter for de grid showing the categories grid (and main pictos)
...@@ -1065,4 +1074,88 @@ protected void showOnlyTape(boolean onlyTape) { ...@@ -1065,4 +1074,88 @@ protected void showOnlyTape(boolean onlyTape) {
return super.dispatchTouchEvent(event); return super.dispatchTouchEvent(event);
} }
/**
* Para capturar el evento para abrir camara o galeria y procesar
* @param requestCode
* @param resultCode
* @param data
*/
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Bitmap imagen = null;
String legend = null;
switch(requestCode) {
case CAMERA_PIC_REQUEST: //Captura de foto
if (data != null) {
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);
} else {
Log.i("DETALLES", "Fallo al tomar foto");
}
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);
break;
}
/** 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(legend != null ? legend : null, imagen);
}
/**Para cambiar la activity de PictogramActivity a EditPictoActivity
*
* @param textLegend
* @param image
*/
public void launchActivity(String textLegend, Bitmap image){
//Para hacer el pantallazo
/*View v1 = getWindow().getDecorView().getRootView();
v1.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);*/
Intent intent = new Intent(this, EditPictoActivity.class);
finish();
if(image!=null){
int bWidth = image.getWidth();
int bHeight = image.getHeight();
Bitmap rescaled = Bitmap.createScaledBitmap(image, bWidth * 5, bHeight * 4, true);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
rescaled.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
intent.putExtra("imagePicto",byteArray);
if(textLegend!=null) { //Si es editar un picto anterior
Log.i("DETALLES", "Lanza el intent a recortar con texto: " + textLegend);
intent.putExtra("textPicto", textLegend);
}
}else{
Log.i("Detalles","Activity sin imagen");
}
startActivity(intent);
}
} }
<?xml version="1.0" encoding="utf-8"?>
<!--<ScrollView
android:id="@+id/scrollview"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".cropper.MainCropImage"
android:background="@color/black_translucent">
-->
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black_translucent"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:id="@+id/ScrollView">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/TotalLayout">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/titleCropper"
android:textSize="24sp"
android:textStyle="bold"
android:textColor="@color/common_google_signin_btn_text_dark_pressed"
android:layout_weight="1"
android:textAlignment="center"
android:layout_gravity="top"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
<com.yottacode.pictogram.tabletlibrary.cropper.CropImageView
android:id="@+id/CropImageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:adjustViewBounds="true"
android:scaleType="centerInside"
android:layout_below="@+id/title"
android:layout_alignParentStart="true" />
<Button
android:id="@+id/Button_crop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="120dp"
android:text="@string/crop"
android:textColor="#33B5E5"
android:textSize="20sp"
android:layout_gravity="center_vertical"
android:layout_marginTop="2dp"
android:layout_below="@+id/title"
android:layout_centerHorizontal="true" />
<ImageView
android:id="@+id/croppedImageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:adjustViewBounds="true"
android:contentDescription="@string/croppedImageDesc"
android:scaleType="centerInside"/>
</RelativeLayout>
</ScrollView>
<?xml version="1.0" encoding="utf-8"?>
<!--<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:id="@+id/TotalLayout"
android:background="#b4000000">-->
<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">
<!--<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:id="@+id/backgroundImage"
app:srcCompat="@color/black_translucent" />-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:id="@+id/TotalLayout"
android:background="@color/black_translucent">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/titleCropper"
android:textSize="24sp"
android:textStyle="bold"
android:textColor="@android:color/white"
android:layout_weight="1"
android:layout_gravity="top"
android:textAlignment="center"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_marginTop="@dimen/activity_vertical_margin" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.yottacode.pictogram.tabletlibrary.cropper.CropImageView
android:id="@+id/CropImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="centerInside"
app:srcCompat="@drawable/descarga"
android:layout_marginLeft="5dp"
android:maxWidth="650px"
android:maxHeight="250px"
android:layout_below="@+id/title"
android:layout_alignParentStart="true"
android:layout_marginTop="55dp"
android:minHeight="125dp"
android:layout_gravity="center_horizontal" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text="@string/legendText"
android:ems="10"
android:id="@+id/legend"
android:textAlignment="center"
android:textColor="@android:color/white"
android:layout_above="@+id/linearLayout"
android:layout_centerHorizontal="true"
android:gravity="center_vertical|center_horizontal"
android:layout_gravity="center_horizontal" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="13dp">
<Button
android:id="@+id/okButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:minWidth="120dp"
android:text="@string/accept"
android:textColor="#33B5E5"
android:textSize="20sp"
android:textAlignment="center"
android:layout_alignParentBottom="true"
android:layout_toStartOf="@+id/cancelButton"
android:width="70dp"
android:layout_marginRight="10dp" />
<Button
android:id="@+id/cancelButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:minWidth="120dp"
android:text="@string/cancel"
android:textColor="#33B5E5"
android:textSize="20sp"
android:textAlignment="center"
android:layout_alignBaseline="@+id/okButton"
android:layout_alignBottom="@+id/okButton"
android:layout_toEndOf="@+id/CropImageView"
android:width="70dp"
android:layout_marginLeft="10dp" />
</LinearLayout>
</RelativeLayout>
</FrameLayout>
...@@ -34,5 +34,11 @@ ...@@ -34,5 +34,11 @@
<string name="session_eval_model">modeled</string> <string name="session_eval_model">modeled</string>
<string name="session_eval_notevuated">not evaluated</string> <string name="session_eval_notevuated">not evaluated</string>
<string name="session_eval_discarded">discarded</string> <string name="session_eval_discarded">discarded</string>
<string name="crop">Crop</string>
<string name="titleCropper">Edit Picto</string>
<string name="croppedImageDesc">Preview</string>
<string name="cancel">Cancel</string>
<string name="accept">Accept</string>
<string name="legendText">Legend</string>
</resources> </resources>
...@@ -34,4 +34,10 @@ ...@@ -34,4 +34,10 @@
<string name="session_eval_model">modelado</string> <string name="session_eval_model">modelado</string>
<string name="session_eval_notevuated">no evaluado</string> <string name="session_eval_notevuated">no evaluado</string>
<string name="session_eval_discarded">inválido</string> <string name="session_eval_discarded">inválido</string>
<string name="crop">Recortar</string>
<string name="titleCropper">Editar Picto</string>
<string name="croppedImageDesc">Vista Previa</string>
<string name="cancel">Cancelar</string>
<string name="accept">Aceptar</string>
<string name="legendText">Leyenda</string>
</resources> </resources>
...@@ -14,4 +14,4 @@ ...@@ -14,4 +14,4 @@
</declare-styleable> </declare-styleable>
</resources> </resources>
\ No newline at end of file
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<resources> <resources>
<color name="white_translucent">#AAFFFFFF</color> <color name="white_translucent">#AAFFFFFF</color>
<color name="black_translucent">#b0000000</color> <color name="black_translucent">#b4000000</color>
<color name="border">@color/white_translucent</color> <color name="border">@color/white_translucent</color>
<color name="guideline">@color/white_translucent</color> <color name="guideline">@color/white_translucent</color>
......
...@@ -39,13 +39,15 @@ ...@@ -39,13 +39,15 @@
<!-- Cropper --> <!-- Cropper -->
<string name="titleCropper">Cropper</string> <string name="legendText">Leyenda</string>
<string name="titleCropper">Editar Picto</string>
<string name="fixedAspectRatio">fixedAspectRatio =\u0020</string> <string name="fixedAspectRatio">fixedAspectRatio =\u0020</string>
<string name="aspectRatioXHeader">aspectRatioX =\u0020</string> <string name="aspectRatioXHeader">aspectRatioX =\u0020</string>
<string name="aspectRatioYHeader">aspectRatioY =\u0020</string> <string name="aspectRatioYHeader">aspectRatioY =\u0020</string>
<string name="showGuidelines">showGuidelines =\u0020</string> <string name="showGuidelines">showGuidelines =\u0020</string>
<string name="crop">Crop</string> <string name="accept">Aceptar</string>
<string name="croppedImageDesc">The cropped image.</string> <string name="cancel">Cancel</string>
<string name="croppedImageDesc">Vista Previa</string>
<string-array name="showGuidelinesArray"> <string-array name="showGuidelinesArray">
<item>Off</item> <item>Off</item>
......
...@@ -73,5 +73,12 @@ ...@@ -73,5 +73,12 @@
android:launchMode="singleInstance" android:launchMode="singleInstance"
android:screenOrientation="landscape" /> android:screenOrientation="landscape" />
<activity
android:name="com.yottacode.pictogram.tabletlibrary.cropper.EditPictoActivity"
android:exported="true"
android:label="@string/app_name"
android:launchMode="singleInstance"
android:screenOrientation="landscape" />
</application> </application>
</manifest> </manifest>
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