Commit 94e87157 by Arturo Montejo Ráez

Merge branch 'develop' of http://scm.ujaen.es/softuno/pictogram into develop

parents 78aa7f7e 6c649e07
...@@ -278,8 +278,8 @@ public class RestapiWrapper { ...@@ -278,8 +278,8 @@ public class RestapiWrapper {
@Override @Override
protected void onPostExecute(HttpAsyncTaskParams params) { protected void onPostExecute(HttpAsyncTaskParams params) {
if (params.error!=null) { if (params.error!=null) {
if (params.error.getCode()==401 && silentLogin!=null) { if (silentLogin!=null && !silentLogin.isValidToken(params.error, params.result)) {
// silentLogin.login(); silentLogin.login();
Log.e(LOG_TAG,"Silent login executed because of invalid token:"+params.error.getMessage()); Log.e(LOG_TAG,"Silent login executed because of invalid token:"+params.error.getMessage());
} }
else else
...@@ -319,5 +319,6 @@ public class RestapiWrapper { ...@@ -319,5 +319,6 @@ public class RestapiWrapper {
*/ */
public interface iSilentLogin { public interface iSilentLogin {
void login(); void login();
boolean isValidToken(HTTPException error, Object result);
} }
} }
...@@ -117,6 +117,18 @@ Picto extends Img { ...@@ -117,6 +117,18 @@ Picto extends Img {
*/ */
public String get_url() {return this.url;} public String get_url() {return this.url;}
/**
*
* @param newTranslation
*/
public void set_translation(String newTranslation){
this.translation = newTranslation;
try {
this.attributes.put(JSON_ATTTRS.EXPRESSION,newTranslation);
} catch (JSONException e) {
e.printStackTrace();
}
}
/** /**
* *
...@@ -378,9 +390,6 @@ Picto extends Img { ...@@ -378,9 +390,6 @@ Picto extends Img {
* @return true if current status is enabled. False in other case. * @return true if current status is enabled. False in other case.
*/ */
public boolean alter_status(String status) { public boolean alter_status(String status) {
/*status = is_enabled() ? JSON_ATTTR_STATUS_VALUES.DISABLED
: is_disabled() ? JSON_ATTTR_STATUS_VALUES.INVISIBLE
: JSON_ATTTR_STATUS_VALUES.ENABLED;*/
Log.i(this.getClass().getCanonicalName(),"Picto id. "+get_id()+" status enabled/disabled modified to "+is_enabled()); Log.i(this.getClass().getCanonicalName(),"Picto id. "+get_id()+" status enabled/disabled modified to "+is_enabled());
try { try {
this.attributes.put(JSON_ATTTRS.STATUS, status); this.attributes.put(JSON_ATTTRS.STATUS, status);
......
...@@ -266,11 +266,7 @@ public class User { ...@@ -266,11 +266,7 @@ public class User {
* @return input feedback of the student configuration (default: "vibration") * @return input feedback of the student configuration (default: "vibration")
*/ */
public boolean delete_tape_after_delivery() { public boolean delete_tape_after_delivery() {
try { return input_feedback_on(JSON_STUDENT_ATTTRS.DELETE_STRIP);
return this.attributes_stu.getBoolean(JSON_STUDENT_ATTTRS.DELETE_STRIP);
} catch (JSONException e) {
return false;
}
} }
/** /**
......
...@@ -170,17 +170,18 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -170,17 +170,18 @@ public class Vocabulary implements Iterable<Picto> {
final String jexpression_text = "text"; final String jexpression_text = "text";
Picto[] pictos = new Picto[result.length()]; Picto[] pictos = new Picto[result.length()];
JSONObject picto = null, expression = null, attributes = null; JSONObject picto = null, attributes = null;
String expression;
JSONObject ojpicto=null; JSONObject ojpicto=null;
try { try {
for (int i=0; i < result.length(); i++) { for (int i=0; i < result.length(); i++) {
ojpicto=result.getJSONObject(i); ojpicto=result.getJSONObject(i);
picto = ojpicto.getJSONObject(jpicto); picto = ojpicto.getJSONObject(jpicto);
expression = ojpicto.getJSONObject(jexpression); expression = ojpicto.getString(jexpression);
attributes = ojpicto.getJSONObject(jattributes); attributes = ojpicto.getJSONObject(jattributes);
pictos[i] = new Picto(picto.getInt(jid), pictos[i] = new Picto(picto.getInt(jid),
picto.getString(juri), picto.getString(juri),
expression.getString(jexpression_text), expression,
attributes); attributes);
} }
synchronizeImgs(pictos); synchronizeImgs(pictos);
......
...@@ -110,6 +110,17 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin { ...@@ -110,6 +110,17 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
} }
}); });
} }
@Override
public boolean isValidToken(RestapiWrapper.HTTPException error, Object result) {
try {
return error.getCode()!=401 || (((JSONObject)result).getString("err").equalsIgnoreCase("Invalid token undefined"));
} catch (JSONException e) {
Log.e(LOG_TAG,e.getMessage());
return true;
}
}
public boolean online() {return updated;} public boolean online() {return updated;}
public void restart_app(boolean direct_login) { public void restart_app(boolean direct_login) {
......
...@@ -14,8 +14,6 @@ import android.database.Cursor; ...@@ -14,8 +14,6 @@ import android.database.Cursor;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.PixelFormat; import android.graphics.PixelFormat;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.DrawableContainer;
import android.media.Ringtone; import android.media.Ringtone;
import android.media.RingtoneManager; import android.media.RingtoneManager;
import android.net.Uri; import android.net.Uri;
...@@ -38,6 +36,7 @@ import android.view.WindowManager; ...@@ -38,6 +36,7 @@ import android.view.WindowManager;
import android.view.animation.AccelerateDecelerateInterpolator; import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.Animation; import android.view.animation.Animation;
import android.view.animation.TranslateAnimation; import android.view.animation.TranslateAnimation;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.EditText; import android.widget.EditText;
...@@ -50,6 +49,7 @@ import android.widget.Toast; ...@@ -50,6 +49,7 @@ import android.widget.Toast;
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.action.VocabularyAction;
import com.yottacode.pictogram.dao.Picto; import com.yottacode.pictogram.dao.Picto;
import com.yottacode.pictogram.dao.User; import com.yottacode.pictogram.dao.User;
import com.yottacode.pictogram.grammar.Vocabulary; import com.yottacode.pictogram.grammar.Vocabulary;
...@@ -69,7 +69,6 @@ import org.json.JSONException; ...@@ -69,7 +69,6 @@ import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteOrder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.LinkedList; import java.util.LinkedList;
...@@ -80,6 +79,7 @@ import java.util.concurrent.TimeUnit; ...@@ -80,6 +79,7 @@ import java.util.concurrent.TimeUnit;
import static android.graphics.Color.BLACK; import static android.graphics.Color.BLACK;
import static android.graphics.Color.argb; import static android.graphics.Color.argb;
import static android.graphics.Color.rgb;
public class PictogramActivity extends Activity implements VocabularyTalk.iVocabularyListener { public class PictogramActivity extends Activity implements VocabularyTalk.iVocabularyListener {
...@@ -1261,6 +1261,93 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab ...@@ -1261,6 +1261,93 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
} }
/**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);
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 = getWindow().getDecorView();
final int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN;
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(PictogramActivity.this.getResources().getDisplayMetrics().widthPixels/2 - 400);
leyenda.setY(PictogramActivity.this.getResources().getDisplayMetrics().heightPixels/2 - 50);
leyenda.setTextColor(BLACK);
if(picto.get_translation()!=null){
leyenda.setText(picto.get_translation());
}else{
leyenda.setText("Sin Descripción");
}
//Mostrar teclado automaticamente
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
ImageButton botonOk = new ImageButton(PCBcontext.getContext());
botonOk.setImageResource(android.R.drawable.ic_menu_save);
botonOk.setX(PictogramActivity.this.getResources().getDisplayMetrics().widthPixels/2 + 10);
botonOk.setY(PictogramActivity.this.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));
}
getCurrentPictoGridAdapter().notifyDataSetChanged();
ll.setVisibility(View.GONE);
//Hide navigation bar
decorView.setSystemUiVisibility(uiOptions);
}
});
ImageButton botonSalir = new ImageButton(PCBcontext.getContext());
botonSalir.setImageResource(android.R.drawable.ic_menu_close_clear_cancel);
botonSalir.setX(PictogramActivity.this.getResources().getDisplayMetrics().widthPixels/2 + 80);
botonSalir.setY(PictogramActivity.this.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);
//Hide navigation bar
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
*
* @param tamPicto
* @param picto
*/
private void createMenuForPicto(int tamPicto, Picto picto){ private void createMenuForPicto(int tamPicto, Picto picto){
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,
...@@ -1349,26 +1436,6 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab ...@@ -1349,26 +1436,6 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
} }
} }
//Edit legend of picto menu button
public class EditMenu implements RadialMenuWidget.RadialMenuEntry
{
Picto p;
public EditMenu(Picto picto){
this.p = picto;
}
public String getName() { return "edit"; }
public String getLabel() { return null; }
public int getIcon() { return R.drawable.edit; }
public List<RadialMenuWidget.RadialMenuEntry> getChildren() { return null; }
public void menuActiviated()
{
/**TODO: Llamar a la interfaz de editar foto y leyenda*/
Toast.makeText(PCBcontext.getContext(),"Editar Picto", Toast.LENGTH_SHORT).show();
ll.setVisibility(View.GONE);
((RelativeLayout)PieMenu.getParent()).removeView(PieMenu);
}
}
//Change image of picto menu button //Change image of picto menu button
public class SetInvisibleMenu implements RadialMenuWidget.RadialMenuEntry public class SetInvisibleMenu implements RadialMenuWidget.RadialMenuEntry
{ {
...@@ -1411,4 +1478,61 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab ...@@ -1411,4 +1478,61 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
} }
} }
//Edit menu button
public class EditMenu implements RadialMenuWidget.RadialMenuEntry
{
Picto p;
public EditMenu(Picto picto){
this.p = picto;
}
public String getName() { return "edit"; }
public String getLabel() { return null; }
public int getIcon() { return R.drawable.edit; }
private List<RadialMenuWidget.RadialMenuEntry> children = new ArrayList<>(Arrays.asList( new EditTextPicto(this.p), new EditImage(this.p)));
public List<RadialMenuWidget.RadialMenuEntry> getChildren() { return children; }
public void menuActiviated()
{
/**TODO: Llamar a la interfaz de editar foto y leyenda*/
Toast.makeText(PCBcontext.getContext(),"Editar Picto", Toast.LENGTH_SHORT).show();
}
}
//Edit legend text of picto button
public class EditTextPicto implements RadialMenuWidget.RadialMenuEntry
{
Picto p;
public EditTextPicto(Picto picto){
this.p = picto;
}
public String getName() { return "editText"; }
public String getLabel() { return null; }
public int getIcon() { return R.drawable.edit_text; }
public List<RadialMenuWidget.RadialMenuEntry> getChildren() { return null; }
public void menuActiviated()
{
Toast.makeText(PCBcontext.getContext(),"Editar Texto", Toast.LENGTH_SHORT).show();
ll.setVisibility(View.GONE);
((RelativeLayout)PieMenu.getParent()).removeView(PieMenu);
createViewForExpression(this.p);
}
}
public class EditImage implements RadialMenuWidget.RadialMenuEntry
{
Picto p;
public EditImage(Picto picto){
this.p = picto;
}
public String getName() { return "editImage"; }
public String getLabel() { return null; }
public int getIcon() { return R.drawable.edit_picture; }
public List<RadialMenuWidget.RadialMenuEntry> getChildren() { return null; }
public void menuActiviated()
{
/**TODO: Llamar a la interfaz de editar foto*/
Toast.makeText(PCBcontext.getContext(),"Editar Imagen", Toast.LENGTH_SHORT).show();
}
}
} }
...@@ -39,14 +39,16 @@ public class RadialMenuWidget extends View { ...@@ -39,14 +39,16 @@ public class RadialMenuWidget extends View {
} }
private List<RadialMenuEntry> menuEntries = new ArrayList<RadialMenuEntry>(); private List<RadialMenuEntry> menuEntries = new ArrayList<RadialMenuEntry>();
private List<RadialMenuEntry> menuEntries2 = new ArrayList<RadialMenuEntry>();
private RadialMenuEntry centerCircle = null; private RadialMenuEntry centerCircle = null;
private int variable;
private float screen_density = getContext().getResources().getDisplayMetrics().density; private float screen_density = getContext().getResources().getDisplayMetrics().density;
private int defaultColor = Color.rgb(221, 221, 211); //default color of wedge pieces private int defaultColor = Color.rgb(221, 221, 211); //default color of wedge pieces
private int defaultAlpha = 255; //transparency of the colors, 255=Opague, 0=Transparent private int defaultAlpha = 255; //transparency of the colors, 255=Opague, 0=Transparent
private int wedge2Color = Color.rgb(50, 50, 50); //default color of wedge pieces private int wedge2Color = Color.rgb(221, 221, 211); //default color of wedge pieces
private int wedge2Alpha = 210; private int wedge2Alpha = 255;
private int outlineColor = Color.rgb(150, 150, 150); //color of outline private int outlineColor = Color.rgb(150, 150, 150); //color of outline
private int outlineAlpha = 255; //transparency of outline private int outlineAlpha = 255; //transparency of outline
private int selectedColor = Color.rgb(70, 130, 180); //color to fill when something is selected private int selectedColor = Color.rgb(70, 130, 180); //color to fill when something is selected
...@@ -221,13 +223,12 @@ public class RadialMenuWidget extends View { ...@@ -221,13 +223,12 @@ public class RadialMenuWidget extends View {
//If outer ring is not enabled, then executes event //If outer ring is not enabled, then executes event
} else { } else {
menuEntries.get(i).menuActiviated(); menuEntries.get(i).menuActiviated();
variable = i;
//Figures out how many outer rings //Figures out how many outer rings
if (menuEntries.get(i).getChildren() != null) { if (menuEntries.get(i).getChildren() != null) {
determineOuterWedges(menuEntries.get(i)); determineOuterWedges(menuEntries.get(i));
enabled = f; enabled = f;
animateOuterOut = true; //sets Wedge2Shown = true; animateOuterOut = true; //sets Wedge2Shown = true;
} else { } else {
Wedge2Shown = false; Wedge2Shown = false;
} }
...@@ -237,14 +238,18 @@ public class RadialMenuWidget extends View { ...@@ -237,14 +238,18 @@ public class RadialMenuWidget extends View {
} }
} }
} else if (selected2 != null){ } else if (selected2 != null){
for (int i = 0; i < Wedges2.length; i++) { for (int i = 0; i < Wedges2.length; i++) {
Wedge f = Wedges2[i]; //for (int j = 0; j < menuEntries.get(i).getChildren().size(); j++) {
if (f == selected2) { Wedge f = Wedges2[i];
animateOuterIn = true; //sets Wedge2Shown = false; if (f == selected2) {
enabled = null; animateOuterIn = true; //sets Wedge2Shown = false;
selected = null; enabled = null;
} selected = null;
} menuEntries.get(variable).getChildren().get(i).menuActiviated();
}
//}
}
} else { } else {
//This is when something outside the circle or any of the rings is selected //This is when something outside the circle or any of the rings is selected
Toast.makeText(getContext(), "Pulse dentro del menú", Toast.LENGTH_SHORT ).show(); Toast.makeText(getContext(), "Pulse dentro del menú", Toast.LENGTH_SHORT ).show();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment