Commit d2c1a88e by german

Interfaz del menu de los pictos modificado, añadido abrir desde galeria(falta funcionalidad)

parent de4d53ee
...@@ -59,7 +59,7 @@ public class EditPictoActivity extends Activity { ...@@ -59,7 +59,7 @@ public class EditPictoActivity extends Activity {
Bitmap imagePicto = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length); Bitmap imagePicto = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
cropImageView.setImageBitmap(imagePicto); cropImageView.setImageBitmap(imagePicto);
/* byteArray = getIntent().getByteArrayExtra("imageBackground"); /*byteArray = getIntent().getByteArrayExtra("imageBackground");
Bitmap imageBackground = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length); Bitmap imageBackground = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
backgroundImage.setImageBitmap(imageBackground);*/ backgroundImage.setImageBitmap(imageBackground);*/
......
...@@ -40,6 +40,8 @@ import com.yottacode.pictogram.tools.PCBcontext; ...@@ -40,6 +40,8 @@ import com.yottacode.pictogram.tools.PCBcontext;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import static android.graphics.Color.BLACK; import static android.graphics.Color.BLACK;
...@@ -53,6 +55,7 @@ public class PictoMenu { ...@@ -53,6 +55,7 @@ public class PictoMenu {
//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 static final int CAMERA_PIC_REQUEST = 1;
private static final int GALLERY_PIC_REQUEST = 2;
private RadialMenuWidget PieMenu; private RadialMenuWidget PieMenu;
private ImageView detail; private ImageView detail;
...@@ -83,8 +86,7 @@ public class PictoMenu { ...@@ -83,8 +86,7 @@ public class PictoMenu {
activity.getIntent().putExtra(Picto.JSON_ATTTRS.FREE_ROW, row); activity.getIntent().putExtra(Picto.JSON_ATTTRS.FREE_ROW, row);
activity.getIntent().putExtra(Picto.JSON_ATTTRS.FREE_COLUMN, col); activity.getIntent().putExtra(Picto.JSON_ATTTRS.FREE_COLUMN, col);
} }
activity.startActivityForResult(intent, SELECT_PICTURE); activity.startActivityForResult(intent,SELECT_PICTURE);
} }
...@@ -190,173 +192,9 @@ public class PictoMenu { ...@@ -190,173 +192,9 @@ 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
*
* @param picto
*/
public void createViewForExpression(final Picto picto){
ll = new RelativeLayout(PCBcontext.getContext());
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.MATCH_PARENT);
activity.addContentView(ll, params);
ll.setBackgroundColor(argb(180,0,0,0));
ll.setClickable(false);
//Parameters for hide navigation bar when u save or cancel
final View decorView = activity.getWindow().getDecorView();
final int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
/*| View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE*/;
final EditText leyenda = new EditText(PCBcontext.getContext());
leyenda.setBackgroundColor(rgb(221, 221, 211));
leyenda.setWidth(400);
leyenda.setMaxLines(1);
leyenda.setClickable(true);
leyenda.setTextSize(25);
leyenda.setX(activity.getResources().getDisplayMetrics().widthPixels/2 - 300);
leyenda.setY(activity.getResources().getDisplayMetrics().heightPixels/2 - 50);
leyenda.setTextColor(BLACK);
if(picto.get_translation()!= null && picto != null){
leyenda.setText(picto.get_translation());
}else{
leyenda.setText("Sin Descripción");
}
//Mostrar teclado automaticamente
final InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
ImageButton botonOk = new ImageButton(PCBcontext.getContext());
botonOk.setImageResource(android.R.drawable.ic_menu_save);
botonOk.setX(activity.getResources().getDisplayMetrics().widthPixels/2 + 110);
botonOk.setY(activity.getResources().getDisplayMetrics().heightPixels/2 - 50);
botonOk.setBackgroundColor(rgb(221,221,221));
botonOk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
picto.set_translation(leyenda.getText().toString());
imm.hideSoftInputFromWindow(leyenda.getWindowToken(), 0);
picto.set_local_status(true);
if (!picto.is_local()) {
new PictoUploader(picto).uploadState();
PCBcontext.getActionLog().log(new VocabularyAction(VocabularyAction.ALTERATTRS, picto));
}
activity.getCurrentPictoGridAdapter().notifyDataSetChanged();
ll.setVisibility(View.GONE);
ll.removeAllViewsInLayout();
//Hide navigation bar
//activity.refresh();
decorView.setSystemUiVisibility(uiOptions);
}
});
ImageButton botonSalir = new ImageButton(PCBcontext.getContext());
botonSalir.setImageResource(android.R.drawable.ic_menu_close_clear_cancel);
botonSalir.setX(activity.getResources().getDisplayMetrics().widthPixels/2 + 150);
botonSalir.setY(activity.getResources().getDisplayMetrics().heightPixels/2 - 50);
botonSalir.setBackgroundColor(rgb(221,221,221));
botonSalir.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
imm.hideSoftInputFromWindow(leyenda.getWindowToken(), 0);
ll.setVisibility(View.GONE);
ll.removeAllViewsInLayout();
//Hide navigation bar
//activity.refresh();
decorView.setSystemUiVisibility(uiOptions);
}
});
ll.addView(leyenda);
ll.addView(botonOk);
ll.addView(botonSalir);
leyenda.requestFocus();
imm.showSoftInput(leyenda, InputMethodManager.SHOW_FORCED);
}
/**Function for build a radial menu /**Function for build a radial menu
* *
...@@ -420,7 +258,7 @@ public class PictoMenu { ...@@ -420,7 +258,7 @@ public class PictoMenu {
} }
public String getName() { return "Close"; } public String getName() { return "Close"; }
public String getLabel() { return null; } public String getLabel() { return null; }
public int getIcon() { return android.R.drawable.ic_menu_close_clear_cancel; } public int getIcon() { return android.R.drawable.ic_menu_revert; }
public List<RadialMenuWidget.RadialMenuEntry> getChildren() { return null; } public List<RadialMenuWidget.RadialMenuEntry> getChildren() { return null; }
//Metodo para realizar acciones si se pulsa //Metodo para realizar acciones si se pulsa
public void menuActiviated() public void menuActiviated()
...@@ -505,24 +343,17 @@ public class PictoMenu { ...@@ -505,24 +343,17 @@ public class PictoMenu {
} }
public String getName() { return "edit"; } public String getName() { return "edit"; }
public String getLabel() { return null; } public String getLabel() { return null; }
public int getIcon() { return R.drawable.edit; } public int getIcon() { return android.R.drawable.ic_menu_edit; }
private List<RadialMenuWidget.RadialMenuEntry> children; private List<RadialMenuWidget.RadialMenuEntry> children;
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 PickFromCamera(p),new PickFromGallery(p)));
ll.setVisibility(View.GONE); //ll.setVisibility(View.GONE);
ll.removeAllViewsInLayout(); //ll.removeAllViewsInLayout();
/**Al presionar el boton de ajustes lanza la actividad de la camara*/
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
Log.i("DETALLES","Texto del picto "+"'"+p.get_translation()+"'");
if(p!=null)
cameraIntent.putExtra("pictoLegend",p.get_translation());
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);
...@@ -530,79 +361,57 @@ public class PictoMenu { ...@@ -530,79 +361,57 @@ public class PictoMenu {
} }
//Edit legend text of picto button //Edit legend text of picto button
public class EditTextPicto implements RadialMenuWidget.RadialMenuEntry public class PickFromCamera implements RadialMenuWidget.RadialMenuEntry
{ {
Picto p; Picto p;
public EditTextPicto(Picto picto){ public PickFromCamera(Picto picto){
p = picto; p = picto;
} }
public String getName() { return "editText"; } public String getName() { return "editText"; }
public String getLabel() { return null; } public String getLabel() { return null; }
public int getIcon() { return R.drawable.edit_text; } public int getIcon() { return android.R.drawable.ic_menu_camera; }
public List<RadialMenuWidget.RadialMenuEntry> getChildren() { return null; } public List<RadialMenuWidget.RadialMenuEntry> getChildren() { return null; }
public void menuActiviated() public void menuActiviated()
{ {
ll.setVisibility(View.GONE); ll.setVisibility(View.GONE);
ll.removeAllViewsInLayout(); ll.removeAllViewsInLayout();
createViewForExpression(p); /**Al presionar el boton de ajustes lanza la actividad de la camara*/
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
Log.i("DETALLES","Texto del picto "+"'"+p.get_translation()+"'");
if(p!=null) {
//cameraIntent.putExtra("pictoLegend", p.get_translation());
activity.setPicto(p);
}
activity.startActivityForResult(cameraIntent,CAMERA_PIC_REQUEST);
} }
public void menuDisabled(){} public void menuDisabled(){}
} }
public class EditImage implements RadialMenuWidget.RadialMenuEntry public class PickFromGallery implements RadialMenuWidget.RadialMenuEntry
{ {
Picto p; Picto p;
public EditImage(Picto picto){ public PickFromGallery(Picto picto){
p = picto; p = picto;
} }
public String getName() { return "editImage"; } public String getName() { return "editImage"; }
public String getLabel() { return null; } public String getLabel() { return null; }
public int getIcon() { return R.drawable.edit_picture; } public int getIcon() { return android.R.drawable.ic_menu_gallery; }
public List<RadialMenuWidget.RadialMenuEntry> getChildren() { return null; } public List<RadialMenuWidget.RadialMenuEntry> getChildren() { return null; }
public void menuActiviated() public void menuActiviated()
{ {
/**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(); ll.removeAllViewsInLayout();
createViewForCrop(p); if(p!=null) {
//activity.setContentView(R.layout.edit_picto_layout); //cameraIntent.putExtra("pictoLegend", p.get_translation());
/* activity.setPicto(p);
ll = (RelativeLayout) activity.findViewById(R.id.TotalLayout); }
Intent intent = new Intent();
activity.addContentView(ll,ll.getLayoutParams()); intent.setType("image/*");
ll.setBackgroundColor(argb(180,0,0,0)); intent.setAction(Intent.ACTION_GET_CONTENT);
activity.startActivityForResult(intent,GALLERY_PIC_REQUEST);
final CropImageView cropImageView = (CropImageView) activity.findViewById(R.id.CropImageView); //addPicto(p.get_row(),p.get_column());
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(){}
} }
} }
...@@ -63,7 +63,9 @@ import org.json.JSONException; ...@@ -63,7 +63,9 @@ import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.LinkedList; import java.util.LinkedList;
...@@ -74,6 +76,7 @@ import java.util.concurrent.TimeUnit; ...@@ -74,6 +76,7 @@ import java.util.concurrent.TimeUnit;
public class PictogramActivity extends Activity implements VocabularyTalk.iVocabularyListener { public class PictogramActivity extends Activity implements VocabularyTalk.iVocabularyListener {
private Picto picto = null;
private static final int CAMERA_PIC_REQUEST = 1; private static final int CAMERA_PIC_REQUEST = 1;
private static final int GALLERY_PIC_REQUEST = 2; private static final int GALLERY_PIC_REQUEST = 2;
// Main layout for this activity // Main layout for this activity
...@@ -684,6 +687,14 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab ...@@ -684,6 +687,14 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
} }
} }
public Picto getPicto() {
return picto;
}
public void setPicto(Picto picto) {
this.picto = picto;
}
/* ********************************************************************************************* /* *********************************************************************************************
* Event listener classes * Event listener classes
* ********************************************************************************************/ * ********************************************************************************************/
...@@ -1090,7 +1101,7 @@ protected void showOnlyTape(boolean onlyTape) { ...@@ -1090,7 +1101,7 @@ protected void showOnlyTape(boolean onlyTape) {
case CAMERA_PIC_REQUEST: //Captura de foto case CAMERA_PIC_REQUEST: //Captura de foto
if (data != null) { if (data != null) {
imagen = (Bitmap) data.getExtras().get("data"); 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 legend = data.getExtras().getString("pictoLegend"); /**AQUI DEBERIA OBTENER EL LEGEND EN EL CASO DE QUE QUIERA EDITAR LA IMAGEN DE UN PICTO
NO FUNCIONA DEVUELVE NULL ¿?¿?¿WHY?¿?¿*/ NO FUNCIONA DEVUELVE NULL ¿?¿?¿WHY?¿?¿*/
Log.i("DETALLES","Llega el intent del menú, con texto: " + legend); Log.i("DETALLES","Llega el intent del menú, con texto: " + legend);
...@@ -1100,6 +1111,19 @@ protected void showOnlyTape(boolean onlyTape) { ...@@ -1100,6 +1111,19 @@ protected void showOnlyTape(boolean onlyTape) {
break; break;
case GALLERY_PIC_REQUEST: //Galeria case GALLERY_PIC_REQUEST: //Galeria
Uri selectedImage = data.getData(); Uri selectedImage = data.getData();
if (selectedImage != null) {
InputStream imageStream = null;
try {
imageStream = getContentResolver().openInputStream(selectedImage);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
// Transformamos la URI de la imagen a inputStream y este a un Bitmap
imagen = BitmapFactory.decodeStream(imageStream);
}
/*Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA}; String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null); Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
...@@ -1109,32 +1133,22 @@ protected void showOnlyTape(boolean onlyTape) { ...@@ -1109,32 +1133,22 @@ protected void showOnlyTape(boolean onlyTape) {
String filePath = cursor.getString(columnIndex); String filePath = cursor.getString(columnIndex);
cursor.close(); cursor.close();
imagen = BitmapFactory.decodeFile(filePath); imagen = BitmapFactory.decodeFile(filePath);*/
break; 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 */ /** 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); this.launchActivity(imagen);
} }
/**Para cambiar la activity de PictogramActivity a EditPictoActivity /**Para cambiar la activity de PictogramActivity a EditPictoActivity
* *
* @param textLegend
* @param image * @param image
*/ */
public void launchActivity(String textLegend, Bitmap image){ public void launchActivity(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); Intent intent = new Intent(this, EditPictoActivity.class);
finish(); finish();
...@@ -1149,9 +1163,9 @@ protected void showOnlyTape(boolean onlyTape) { ...@@ -1149,9 +1163,9 @@ protected void showOnlyTape(boolean onlyTape) {
byte[] byteArray = stream.toByteArray(); byte[] byteArray = stream.toByteArray();
intent.putExtra("imagePicto",byteArray); intent.putExtra("imagePicto",byteArray);
if(textLegend!=null) { //Si es editar un picto anterior if(picto != null) { //Si es editar un picto anterior
Log.i("DETALLES", "Lanza el intent a recortar con texto: " + textLegend); intent.putExtra("textPicto", picto.get_translation());
intent.putExtra("textPicto", textLegend); picto = null;
} }
}else{ }else{
Log.i("Detalles","Activity sin imagen"); Log.i("Detalles","Activity sin imagen");
......
...@@ -56,7 +56,6 @@ ...@@ -56,7 +56,6 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:adjustViewBounds="true" android:adjustViewBounds="true"
android:scaleType="centerInside" android:scaleType="centerInside"
app:srcCompat="@drawable/descarga"
android:layout_marginLeft="5dp" android:layout_marginLeft="5dp"
android:maxWidth="650px" android:maxWidth="650px"
android:maxHeight="250px" android:maxHeight="250px"
......
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