Refactorizado el modo de escalar la imagen, ahora se reescala una vez esta en…

Refactorizado el modo de escalar la imagen, ahora se reescala una vez esta en EditPictoActivity y no antes de pasarla por los intent
parent bf4a834a
...@@ -91,7 +91,7 @@ public class Picto extends Img { ...@@ -91,7 +91,7 @@ public class Picto extends Img {
Log.e(LOG_TAG,e.getMessage()); Log.e(LOG_TAG,e.getMessage());
} }
} }
public Picto(int id, String url, String translation, int cat, int row, int column, int freeRow, int freeColumn, int stupicto_id, String uri_sound, String user_avatar) throws JSONException { public Picto(int id, String url, String translation, int cat, int row, int column, int freeRow, int freeColumn, int stupicto_id, String uri_sound, String user_avatar, String associated_person) throws JSONException {
this(id, url, new JSONObject() this(id, url, new JSONObject()
.put(JSON_ATTTRS.CATEGORY, cat) .put(JSON_ATTTRS.CATEGORY, cat)
.put(JSON_ATTTRS.COLUMN, column) .put(JSON_ATTTRS.COLUMN, column)
...@@ -104,7 +104,7 @@ public class Picto extends Img { ...@@ -104,7 +104,7 @@ public class Picto extends Img {
.put(JSON_ATTTRS.EXPRESSION,translation) .put(JSON_ATTTRS.EXPRESSION,translation)
.put(JSON_ATTTRS.URI_SOUND,uri_sound) .put(JSON_ATTTRS.URI_SOUND,uri_sound)
.put(JSON_ATTTRS.USER_AVATAR,user_avatar) .put(JSON_ATTTRS.USER_AVATAR,user_avatar)
.put(JSON_ATTTRS.ASSOCIATED_PERSON,null) .put(JSON_ATTTRS.ASSOCIATED_PERSON,associated_person)
); );
} }
public Picto(int id, String url,String translation, String attributes) throws JSONException { public Picto(int id, String url,String translation, String attributes) throws JSONException {
...@@ -306,7 +306,7 @@ public class Picto extends Img { ...@@ -306,7 +306,7 @@ public class Picto extends Img {
* @return the associated person of a picto * @return the associated person of a picto
*/ */
public String get_associated_person() { public String get_associated_person() {
return JSON_ATTTRS.ASSOCIATED_PERSON; return JSON_ATTTRS.ASSOCIATED_PERSON != "associated_person" ? JSON_ATTTRS.ASSOCIATED_PERSON : null;
} }
/** /**
......
...@@ -419,7 +419,7 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -419,7 +419,7 @@ public class Vocabulary implements Iterable<Picto> {
int id=PCBcontext.getDevice().getNextLocalPictoID(); int id=PCBcontext.getDevice().getNextLocalPictoID();
try { try {
final Picto picto = new Picto(id, url, exp, cat, coord_x, coord_y, free_category_coord_x, free_category_coord_y,prev_picto!=null ? prev_picto.get_stupicto_id() : Picto.STUPICTO_NULL,uri_sound,user_avatar); final Picto picto = new Picto(id, url, exp, cat, coord_x, coord_y, free_category_coord_x, free_category_coord_y,prev_picto!=null ? prev_picto.get_stupicto_id() : Picto.STUPICTO_NULL,uri_sound,user_avatar,associated_person);
addPicto(picto, ImgDownloader.tsource.local, new ImgDownloader.iImgDownloaderListener() { addPicto(picto, ImgDownloader.tsource.local, new ImgDownloader.iImgDownloaderListener() {
@Override @Override
public void loadComplete() { public void loadComplete() {
......
...@@ -26,8 +26,11 @@ import static android.graphics.Color.argb; ...@@ -26,8 +26,11 @@ import static android.graphics.Color.argb;
public class PictoMenu { public class PictoMenu {
private static final String LOG_TAG = PictoMenu.class.getName();
public static final String ID_PICTO_IMAGE = "id_imagen_picto"; public static final String ID_PICTO_IMAGE = "id_imagen_picto";
public static final String IS_EDIT = "is_edit";
public static final String PATH = "pathImage";
public static final String IMAGE_PICTO = "imagePicto";
PictogramActivity activity; PictogramActivity activity;
//Variables used on the picto menu (only supervisors) //Variables used on the picto menu (only supervisors)
...@@ -51,9 +54,8 @@ public class PictoMenu { ...@@ -51,9 +54,8 @@ public class PictoMenu {
* *
* @param row * @param row
* @param col * @param col
* @param expression
*/ */
public void createMenuForNewPicto(final int row, final int col, final int cat, final String expression) { public void createMenuForNewPicto(final int row, final int col, final int cat) {
ll = new RelativeLayout(PCBcontext.getContext()); ll = new RelativeLayout(PCBcontext.getContext());
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
...@@ -76,16 +78,14 @@ public class PictoMenu { ...@@ -76,16 +78,14 @@ public class PictoMenu {
PieMenu.setCenterCircle(new Close()); PieMenu.setCenterCircle(new Close());
PieMenu.addMenuEntry(new newPickFromCamera(row,col,cat,expression)); PieMenu.addMenuEntry(new newPickFromCamera(row,col,cat/*,expression*/));
PieMenu.addMenuEntry(new newPickFromGallery(row,col,cat,expression)); PieMenu.addMenuEntry(new newPickFromGallery(row,col,cat/*,expression*/));
ll.addView(PieMenu); ll.addView(PieMenu);
} }
public void addPicto(int row, int col, int cat, String expression, int source) { public void addPicto(int row, int col, int cat, int source) {
activity.getIntent().putExtra(Picto.JSON_ATTTRS.EXPRESSION, expression);
//Enviar al PictogramActivity los datos necesarios para crear el picto despues //Enviar al PictogramActivity los datos necesarios para crear el picto despues
if (PCBcontext.getPcbdb().getCurrentUser().has_categories()) { if (PCBcontext.getPcbdb().getCurrentUser().has_categories()) {
activity.getIntent().putExtra(Picto.JSON_ATTTRS.CATEGORY, cat); activity.getIntent().putExtra(Picto.JSON_ATTTRS.CATEGORY, cat);
...@@ -96,7 +96,7 @@ public class PictoMenu { ...@@ -96,7 +96,7 @@ public class PictoMenu {
activity.getIntent().putExtra(Picto.JSON_ATTTRS.FREE_COLUMN, col); activity.getIntent().putExtra(Picto.JSON_ATTTRS.FREE_COLUMN, col);
} }
if (source== 0) { //Pick from camera if (source == 0) { //Pick from camera
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
activity.startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST); activity.startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
} else { //Pick from file } else { //Pick from file
...@@ -108,16 +108,9 @@ public class PictoMenu { ...@@ -108,16 +108,9 @@ public class PictoMenu {
} }
public void setPicto(int row, int col, int cat, String expression, Bitmap bitmap, int id_picto, String uri_sound, String user_avatar, int id_imagen_picto/*, String associated_person*/){ public void setPicto(int row, int col, int cat, Bitmap bitmap, int id_picto){
Intent intent = new Intent(activity, EditPictoActivity.class); Intent intent = new Intent(activity, EditPictoActivity.class);
intent.putExtra(ID_PICTO_IMAGE,id_picto);
intent.putExtra(Picto.JSON_ATTTRS.EXPRESSION, expression);
intent.putExtra(Picto.JSON_ATTTRS.STUPICTO_ID,id_picto);
intent.putExtra(Picto.JSON_ATTTRS.URI_SOUND,uri_sound);
intent.putExtra(ID_PICTO_IMAGE,id_imagen_picto);
//intent.putExtra(Picto.JSON_ATTTRS.ASSOCIATED_PERSON,associated_person);
Log.i(EditPictoActivity.DEBUG_MESSAGE,"Guarda en los intents: id_cat: " +cat+"---id_pic: "+id_picto + "---id_imag: "+id_imagen_picto);
//Enviar al PictogramActivity los datos necesarios para editar el picto despues //Enviar al PictogramActivity los datos necesarios para editar el picto despues
if (PCBcontext.getPcbdb().getCurrentUser().has_categories()) { if (PCBcontext.getPcbdb().getCurrentUser().has_categories()) {
...@@ -129,24 +122,11 @@ public class PictoMenu { ...@@ -129,24 +122,11 @@ public class PictoMenu {
intent.putExtra(Picto.JSON_ATTTRS.FREE_COLUMN, col); intent.putExtra(Picto.JSON_ATTTRS.FREE_COLUMN, col);
} }
if(bitmap!=null) { ByteArrayOutputStream stream = new ByteArrayOutputStream();
Point size= GUITools.getScreenSize(activity); bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
float bWidth = bitmap.getWidth(); byte[] byteArray = stream.toByteArray();
float bHeight = bitmap.getHeight(); intent.putExtra(IMAGE_PICTO, byteArray);
float factorX=size.x*0.7f/bWidth; intent.putExtra(IS_EDIT,true);
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.startActivityForResult(intent,EditPictoActivity.EDIT_PICTO_REQUEST); activity.startActivityForResult(intent,EditPictoActivity.EDIT_PICTO_REQUEST);
} }
...@@ -305,67 +285,22 @@ public class PictoMenu { ...@@ -305,67 +285,22 @@ public class PictoMenu {
ll.removeAllViewsInLayout(); ll.removeAllViewsInLayout();
try { try {
setPicto(p.get_row(),p.get_column(),p.get_category(),p.get_translation(),p.get_bitmap(PCBcontext.getContext()),p.get_stupicto_id(),p.getUriSound(),p.getUserAvatar(),p.get_id()); setPicto(p.get_row(),p.get_column(),p.get_category(),p.get_bitmap(PCBcontext.getContext()),p.get_id());
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); 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);
}
}
/*public class PickFromCamera implements RadialMenuWidget.RadialMenuEntry
{
Picto p;
public PickFromCamera(Picto picto){
p = picto;
}
public String getName() { return "editText"; }
public String getLabel() { return null; }
public int getIcon() { return R.drawable.camera; }
public List<RadialMenuWidget.RadialMenuEntry> getChildren() { return null; }
public void menuActiviated()
{
ll.setVisibility(View.GONE);
ll.removeAllViewsInLayout();
addPicto(p.get_row(),p.get_column(),p.get_category(),p.get_translation(),0);
} }
public void menuDisabled(){} public void menuDisabled(){}
} }
public class PickFromGallery implements RadialMenuWidget.RadialMenuEntry
{
Picto p;
public PickFromGallery(Picto picto){
p = picto;
}
public String getName() { return "editImage"; }
public String getLabel() { return null; }
public int getIcon() { return R.drawable.gallery; }
public List<RadialMenuWidget.RadialMenuEntry> getChildren() { return null; }
public void menuActiviated()
{
ll.setVisibility(View.GONE);
ll.removeAllViewsInLayout();
addPicto(p.get_row(),p.get_column(),p.get_category(),p.get_translation(),1);
}
public void menuDisabled(){}
}*/
public class newPickFromCamera implements RadialMenuWidget.RadialMenuEntry public class newPickFromCamera implements RadialMenuWidget.RadialMenuEntry
{ {
int row,col,cat; int row,col,cat;
String expression; public newPickFromCamera(int row, int col,int cat){
public newPickFromCamera(int row, int col,int cat,String expression){
this.row = row; this.row = row;
this.col = col; this.col = col;
this.cat = cat; this.cat = cat;
this.expression = expression;
} }
public String getName() { return ""; } public String getName() { return ""; }
public String getLabel() { return null; } public String getLabel() { return null; }
...@@ -376,7 +311,7 @@ public class PictoMenu { ...@@ -376,7 +311,7 @@ public class PictoMenu {
ll.setVisibility(View.GONE); ll.setVisibility(View.GONE);
ll.removeAllViewsInLayout(); ll.removeAllViewsInLayout();
addPicto(row,col,cat,expression,0); addPicto(row,col,cat,0);
} }
public void menuDisabled(){} public void menuDisabled(){}
} }
...@@ -384,12 +319,10 @@ public class PictoMenu { ...@@ -384,12 +319,10 @@ public class PictoMenu {
public class newPickFromGallery implements RadialMenuWidget.RadialMenuEntry public class newPickFromGallery implements RadialMenuWidget.RadialMenuEntry
{ {
int row,col,cat; int row,col,cat;
String expression; public newPickFromGallery(int row, int col,int cat){
public newPickFromGallery(int row, int col,int cat,String expression){
this.row = row; this.row = row;
this.col = col; this.col = col;
this.cat = cat; this.cat = cat;
this.expression = expression;
} }
public String getName() { return ""; } public String getName() { return ""; }
public String getLabel() { return null; } public String getLabel() { return null; }
...@@ -399,7 +332,7 @@ public class PictoMenu { ...@@ -399,7 +332,7 @@ public class PictoMenu {
{ {
ll.setVisibility(View.GONE); ll.setVisibility(View.GONE);
ll.removeAllViewsInLayout(); ll.removeAllViewsInLayout();
addPicto(row,col,cat,expression,1); addPicto(row,col,cat,1);
} }
public void menuDisabled(){} public void menuDisabled(){}
} }
......
...@@ -869,7 +869,7 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab ...@@ -869,7 +869,7 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
if (p == null) { if (p == null) {
// No tengo pictograma. Abro una nueva ventana de selección desde el Carrete del device si no es categoria // No tengo pictograma. Abro una nueva ventana de selección desde el Carrete del device si no es categoria
if (getCurrentCategory() != null || !PCBcontext.getPcbdb().getCurrentUser().has_categories()) { if (getCurrentCategory() != null || !PCBcontext.getPcbdb().getCurrentUser().has_categories()) {
new PictoMenu(PictogramActivity.this).createMenuForNewPicto(position % maxColumns, (int) (position / maxColumns), currentCategory.get_id(),null); new PictoMenu(PictogramActivity.this).createMenuForNewPicto(position % maxColumns, (int) (position / maxColumns), currentCategory.get_id());
} else } else
Toast.makeText(PictogramActivity.this, PictogramActivity.this.getResources().getString(R.string.notNewCats), Toast.LENGTH_SHORT).show(); Toast.makeText(PictogramActivity.this, PictogramActivity.this.getResources().getString(R.string.notNewCats), Toast.LENGTH_SHORT).show();
...@@ -1149,7 +1149,7 @@ protected void showOnlyTape(boolean onlyTape) { ...@@ -1149,7 +1149,7 @@ protected void showOnlyTape(boolean onlyTape) {
break; break;
case EditPictoActivity.EDIT_PICTO_REQUEST: case EditPictoActivity.EDIT_PICTO_REQUEST:
if (resultCode == RESULT_OK) { if (resultCode == RESULT_OK) {
boolean edit = data.getBooleanExtra("tipo",false); boolean edit = data.getBooleanExtra(PictoMenu.IS_EDIT,false);
int row = edit ? data.getExtras().getInt(Picto.JSON_ATTTRS.ROW) : getIntent().getIntExtra(Picto.JSON_ATTTRS.ROW, -1); int row = edit ? data.getExtras().getInt(Picto.JSON_ATTTRS.ROW) : getIntent().getIntExtra(Picto.JSON_ATTTRS.ROW, -1);
int col = edit ? data.getExtras().getInt(Picto.JSON_ATTTRS.COLUMN) : getIntent().getIntExtra(Picto.JSON_ATTTRS.COLUMN, -1); int col = edit ? data.getExtras().getInt(Picto.JSON_ATTTRS.COLUMN) : getIntent().getIntExtra(Picto.JSON_ATTTRS.COLUMN, -1);
int freeRow = edit ? data.getExtras().getInt(Picto.JSON_ATTTRS.FREE_ROW) : getIntent().getIntExtra(Picto.JSON_ATTTRS.FREE_ROW, -1); int freeRow = edit ? data.getExtras().getInt(Picto.JSON_ATTTRS.FREE_ROW) : getIntent().getIntExtra(Picto.JSON_ATTTRS.FREE_ROW, -1);
...@@ -1157,13 +1157,14 @@ protected void showOnlyTape(boolean onlyTape) { ...@@ -1157,13 +1157,14 @@ protected void showOnlyTape(boolean onlyTape) {
String uri_sound = edit ? data.getExtras().getString(Picto.JSON_ATTTRS.URI_SOUND) : getIntent().getStringExtra(Picto.JSON_ATTTRS.URI_SOUND); String uri_sound = edit ? data.getExtras().getString(Picto.JSON_ATTTRS.URI_SOUND) : getIntent().getStringExtra(Picto.JSON_ATTTRS.URI_SOUND);
String associated_person = edit ? data.getExtras().getString(Picto.JSON_ATTTRS.ASSOCIATED_PERSON) : getIntent().getStringExtra(Picto.JSON_ATTTRS.ASSOCIATED_PERSON); String associated_person = edit ? data.getExtras().getString(Picto.JSON_ATTTRS.ASSOCIATED_PERSON) : getIntent().getStringExtra(Picto.JSON_ATTTRS.ASSOCIATED_PERSON);
Log.i(EditPictoActivity.DEBUG_MESSAGE,"Antes de chooseText..."+associated_person);
int cat = edit ? data.getIntExtra(Picto.JSON_ATTTRS.CATEGORY, -1) : getIntent().getIntExtra(Picto.JSON_ATTTRS.CATEGORY, -1); int cat = edit ? data.getIntExtra(Picto.JSON_ATTTRS.CATEGORY, -1) : getIntent().getIntExtra(Picto.JSON_ATTTRS.CATEGORY, -1);
String path = data.getExtras().getString(EditPictoActivity.PATH); String path = data.getExtras().getString(PictoMenu.PATH);
String legend = data.getExtras().getString(Picto.JSON_ATTTRS.EXPRESSION); String legend = data.getExtras().getString(Picto.JSON_ATTTRS.EXPRESSION);
//TODO: COGER URI DEL SONIDO,EL USER AVATAR Y LA PERSONA ASOCIADA AL PICTO //TODO: COGER URI DEL SONIDO,EL USER AVATAR Y LA PERSONA ASOCIADA AL PICTO
chooseTextAndSavePicto(path, row, col, freeRow, freeColumn, cat, legend, uri_sound, null,associated_person); chooseTextAndSavePicto(path, row, col, freeRow, freeColumn, cat, legend, uri_sound, null, associated_person);
refresh(); refresh();
} }
break; break;
...@@ -1213,26 +1214,12 @@ protected void showOnlyTape(boolean onlyTape) { ...@@ -1213,26 +1214,12 @@ protected void showOnlyTape(boolean onlyTape) {
Intent intent = new Intent(this, EditPictoActivity.class); Intent intent = new Intent(this, EditPictoActivity.class);
if(image!=null) { ByteArrayOutputStream stream = new ByteArrayOutputStream();
Point size=GUITools.getScreenSize(this); image.compress(Bitmap.CompressFormat.PNG, 100, stream);
float bWidth = image.getWidth(); byte[] byteArray = stream.toByteArray();
float bHeight = image.getHeight(); intent.putExtra(PictoMenu.IMAGE_PICTO, byteArray);
float factorX=size.x*0.7f/bWidth;
float factorY=size.y*0.7f/bHeight; startActivityForResult(intent, EditPictoActivity.EDIT_PICTO_REQUEST);
float factor= factorY>factorX ? factorX : factorY;
bWidth=bWidth*factor;
bHeight=bHeight*factor;
Bitmap rescaled = Bitmap.createScaledBitmap(image,(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(Picto.JSON_ATTTRS.EXPRESSION, getIntent().getStringExtra(Picto.JSON_ATTTRS.EXPRESSION));
startActivityForResult(intent, EditPictoActivity.EDIT_PICTO_REQUEST);
}
} }
} }
...@@ -95,7 +95,7 @@ public class StudentFragmentGrid extends Fragment{ ...@@ -95,7 +95,7 @@ public class StudentFragmentGrid extends Fragment{
try { try {
User new_user = new User( User new_user = new User(
st.getInt(TAG_ID), st.getInt(TAG_ID),
st.getString(TAG_USERNAME), st.getString(TAG_USERNAME),
null, null,
st.getString(TAG_NAME), st.getString(TAG_NAME),
st.getString(TAG_SURNAME), st.getString(TAG_SURNAME),
......
...@@ -106,20 +106,37 @@ ...@@ -106,20 +106,37 @@
android:layout_gravity="center" android:layout_gravity="center"
android:orientation="vertical"> android:orientation="vertical">
<TextView <LinearLayout
android:id="@+id/textAssociated"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Asociar a:" android:orientation="horizontal">
android:textColor="@color/gray"
android:textSize="20sp" />
<Button <TextView
android:id="@+id/botonDesplegable" android:id="@+id/textAssociated"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Asociar a:"
android:textColor="@color/gray"
android:textSize="20sp" />
<Button
android:id="@+id/botonDesplegable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Ver" />
</LinearLayout>
<TextView
android:id="@+id/sup_actual"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="15dp" android:layout_marginBottom="15dp"
android:text="Ver" /> android:textAlignment="center"
android:textColor="@color/black"
android:textSize="18sp" />
<TextView <TextView
android:id="@+id/textLegend" android:id="@+id/textLegend"
......
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