issues #795,#797, #798, #801, #803, #806 closed

parent 54299bdf
......@@ -23,6 +23,7 @@ public class ActionTalk implements Emitter.Listener {
private Room room;
Vector<iActionListener> listeners;
private static final String LOG_TAG=ActionTalk.class.getCanonicalName();
public ActionTalk(Room room, iActionListener listener) {
this.room = room;
......@@ -41,13 +42,14 @@ public class ActionTalk implements Emitter.Listener {
final String param_picto_cat="id_cat";
final String action_select="select";
final String action_add="add";
final String action_delete="delete";
final String action_show="show";
JSONObject msg = (JSONObject) args[0];
try {
Log.i(this.getClass().getName(), "Received message (raw): " +msg.toString()+" mirror:"+PCBcontext.getPcbdb().getCurrentUser().is_mirror_on());
String action = msg.getString(param_action).toLowerCase();
if (action.equals(action_add) || action.equals(action_select) ||action.equals(action_show)) {
if (action.equals(action_add) || action.equals(action_select) || action.equals(action_show) || action.equals(action_delete)) {
int picto_id;
int picto_cat;
boolean mirroing=PCBcontext.getPcbdb().getCurrentUser().is_mirror_on();
......@@ -62,14 +64,16 @@ public class ActionTalk implements Emitter.Listener {
mirroing|=attrs_stu_picto.has(Picto.JSON_ATTTRS.MIRROR);
}
if ( mirroing) {
Log.i(this.getClass().getName(), "Received message '" + action +
Log.i(LOG_TAG, "Received message '" + action +
"' for picto " + picto_id + " (cat " + picto_cat);
for (iActionListener listener : this.listeners)
listener.action(action.equals(action_add)
? iActionListener.action.add
: action.equals(action_select)
? iActionListener.action.select
: iActionListener.action.show
: action.equals(action_delete)
? iActionListener.action.delete
: iActionListener.action.show
, picto_cat, picto_id);
}
}
......@@ -96,7 +100,7 @@ public class ActionTalk implements Emitter.Listener {
* @version 1.0
*/
public interface iActionListener {
enum action {add,select,show}
enum action {add,delete,select,show}
void action(action action, int picto_cat, int picto_id);
}
}
......@@ -7,6 +7,7 @@ import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.drawable.BitmapDrawable;
/**
* Created by Fernando on 15/03/2016.
......@@ -157,4 +158,13 @@ public class BitmapTools {
return this;
}
public void paint(BitmapDrawable drawable, double factor) {
Canvas canvas = new Canvas(this.bitmap);
int w=(int)(this.bitmap.getWidth()*factor);
int h=(int)(this.bitmap.getHeight()*factor);
canvas.drawBitmap(new BitmapTools(drawable.getBitmap()).resize(w,h).get(),
(int)((this.bitmap.getWidth()-w)/2),(int)((this.bitmap.getHeight()-h)/2),null);
}
}
......@@ -14,6 +14,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.yottacode.pictogram.tabletlibrary.R;
......@@ -28,6 +29,8 @@ import java.util.Vector;
* Created by Fernando on 18/12/2016.
*/
class PictoAdapter extends BaseAdapter {
private String LOG_TAG=PictoAdapter.class.getCanonicalName();
public void setCurrentMsg(int currentMsg) {
this.currentMsg = currentMsg;
}
......@@ -36,11 +39,10 @@ class PictoAdapter extends BaseAdapter {
public static class Item {
Bitmap img;
String secs;
StringBuilder sentence;
String sentence="";
public Item(Bitmap img, String secs) {
this.img=img;
this.secs=secs;
this.sentence=new StringBuilder("");
}
Bitmap getImg() {
return img;
......@@ -49,9 +51,9 @@ class PictoAdapter extends BaseAdapter {
return secs;
}
public String getMsg() { return sentence.toString();}
public void setImg(Bitmap currmsg, String word) {
public void setImg(Bitmap currmsg, String word, boolean eval) {
this.img=currmsg;
sentence.append(" "+word);
if (eval) sentence=": " +word;
}
}
Context context;
......@@ -103,9 +105,10 @@ public long getItemId(int position) {
vi = inflater.inflate(R.layout.session_picto_view, null);
ImageView picto=(ImageView)vi.findViewById(R.id.session_picto);
picto.setImageBitmap(this.msg.get(position).getImg());
if (currentMsg== position)
if (currentMsg== position) {
vi.setBackgroundColor(Color.LTGRAY);
else
((ListView)parent).smoothScrollToPosition(position);
}else
vi.setBackgroundColor(Color.TRANSPARENT);
return vi;
}
......@@ -116,7 +119,7 @@ public long getItemId(int position) {
bmp=set_text(context,bmp,getTimeDiff(new Date().getTime()));
Bitmap currmsg=combineImages(oldmsg,bmp);
item.setImg(currmsg,text);
item.setImg(currmsg,text,false);
}
......@@ -128,34 +131,30 @@ public long getItemId(int position) {
float height = context.getResources().getDimension(R.dimen.picto_session_height);
bmp=new BitmapTools(bmp).resize((int)width ,(int)height).get();
bmp=set_text(context,bmp,getTimeDiff(new Date().getTime()));
Bitmap currmsg=this.currentMsg==this.msg.size()-1 ? combineImages(oldmsg,bmp) : updateImage(oldmsg,bmp);
item.setImg(currmsg,": "+evaluation);
Bitmap currmsg = position>=this.msg.size()-1 ? combineImages(oldmsg,bmp) : updateImage(oldmsg,bmp);
item.setImg(currmsg,evaluation,true);
}
public int newMsg() {
Bitmap bmp=BitmapFactory.decodeResource(context.getResources(),
R.drawable.application_online);
float width =context.getResources().getDimension(R.dimen.picto_session_width);
float height = context.getResources().getDimension(R.dimen.picto_session_height);
bmp=new BitmapTools(bmp).resize((int)width,(int)height).get();
Calendar calendar = GregorianCalendar.getInstance(); // creates a new calendar instance
calendar.setTime(new Date()); // assigns calendar to given date
String time= calendar.get(Calendar.HOUR_OF_DAY)+":"+calendar.get(Calendar.MINUTE)+":"+calendar.get(Calendar.SECOND);
bmp=set_text(context,bmp,time);
this.currentMsg = this.msg.size();
msg.add(new Item(bmp, time));
if ((msg.size()>0 && msg.get(msg.size()-1).getImg().getWidth()>context.getResources().getDimension(R.dimen.picto_session_width)) || msg.size()==0)
{
Calendar calendar = GregorianCalendar.getInstance(); // creates a new calendar instance
calendar.setTime(new Date()); // assigns calendar to given date
String time = calendar.get(Calendar.HOUR_OF_DAY) + ":" + calendar.get(Calendar.MINUTE) + ":" + calendar.get(Calendar.SECOND);
Bitmap bmp = set_trycount(context,this.msg.size()+1);
this.currentMsg = this.msg.size();
msg.add(new Item(bmp, time));
}
return msg.size()-1;
}
private Bitmap combineImages(Bitmap c, Bitmap s) {
Bitmap cs = null;
int width, height = 0;
width = c.getWidth() + s.getWidth();
height = c.getHeight();
cs = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas comboImage = new Canvas(cs);
......@@ -163,31 +162,71 @@ public long getItemId(int position) {
comboImage.drawBitmap(c, 0f, 0f, null);
comboImage.drawBitmap(s, c.getWidth(), 0f, null);
return cs;
}
private Bitmap updateImage(Bitmap c, Bitmap s) {
Bitmap cs = null;
int width= c.getWidth(), height= c.getHeight();
int cutwidth=c.getWidth()-s.getWidth();
cs = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas comboImage = new Canvas(cs);
comboImage.drawBitmap(Bitmap.createBitmap(c,0,0,cutwidth,height), 0f, 0f, null);
comboImage.drawBitmap(s, c.getWidth()-s.getWidth(), 0f, null);
comboImage.drawBitmap(s, cutwidth, 0f, null);
return cs;
}
static void set_date(Context context, Canvas canvas,String time) {
TextView textView2 = new TextView(context);
textView2.layout(0, 20, 100, 100);
textView2.setPadding(0, 0, 0, 0);
textView2.setTextSize(TypedValue.COMPLEX_UNIT_PX, 13);
textView2.setTextColor(Color.BLACK);
textView2.setBackgroundColor(Color.LTGRAY);
textView2.setWidth(100);
textView2.setGravity(Gravity.CENTER_HORIZONTAL);
textView2.setMaxLines(1);
textView2.setText(time);
textView2.setDrawingCacheEnabled(true);
canvas.drawBitmap(textView2.getDrawingCache(), 0, 60, null);
}
static Bitmap set_trycount(Context context,int pos) {
Bitmap param_bitmap = BitmapFactory.decodeResource(context.getResources(),
R.drawable.try_border);
float width = context.getResources().getDimension(R.dimen.picto_session_width);
float height = context.getResources().getDimension(R.dimen.picto_session_height);
Bitmap bmp =Bitmap.createScaledBitmap(param_bitmap, (int)width, (int)height, false);
Canvas canvas = new Canvas(bmp);
TextView textView = new TextView(context);
String texto=(pos<10 ? "0" :"")+new Integer(pos).toString();
textView.layout(0, 0, 100, 100);
textView.setPadding(0, 0, 0, 0);
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, 40);
textView.setTextColor(Color.BLACK);
textView.setBackgroundColor(Color.TRANSPARENT);
textView.setWidth(100);
textView.setGravity(Gravity.LEFT);
textView.setMaxLines(1);
textView.setText(texto);
textView.setDrawingCacheEnabled(true);
canvas.drawBitmap(textView.getDrawingCache(), 10, 10, null);
Calendar calendar = GregorianCalendar.getInstance(); // creates a new calendar instance
calendar.setTime(new Date()); // assigns calendar to given date
String time= calendar.get(Calendar.HOUR_OF_DAY)+":"+calendar.get(Calendar.MINUTE)+":"+calendar.get(Calendar.SECOND);
set_date(context,canvas,time);
return bmp;
}
static Bitmap set_text(Context context,Bitmap param_bitmap,String texto) {
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
float width = param_bitmap.getWidth();
float height=param_bitmap.getHeight();
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
float width = param_bitmap.getWidth();
float height=param_bitmap.getHeight();
android.graphics.Bitmap.Config bitmapConfig = param_bitmap.getConfig();
android.graphics.Bitmap.Config bitmapConfig = param_bitmap.getConfig();
if (bitmapConfig == null) {
bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888;
}
......@@ -199,20 +238,7 @@ public long getItemId(int position) {
canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); //Poner en blanco el bitmap original para dibujar encima
canvas.drawBitmap(bm, 0, 0, paint);
TextView textView = new TextView(context);
textView.layout(0, 20, 100, 100);
textView.setPadding(0, 0, 0, 0);
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, 13);
textView.setTextColor(Color.BLACK);
textView.setBackgroundColor(Color.LTGRAY);
textView.setWidth(100);
textView.setGravity(Gravity.CENTER_HORIZONTAL);
textView.setMaxLines(1);
textView.setText(texto);
textView.setDrawingCacheEnabled(true);
canvas.drawBitmap(textView.getDrawingCache(), 0, 60, null);
set_date(context,canvas,texto);
return bitmap;
}
......@@ -223,5 +249,7 @@ public long getItemId(int position) {
public String getCurrentMsgText() {
return this.getItem(currentMsg).getMsg();
}
public String getMsgText(int pos) {
return this.getItem(pos).getMsg();
}
}
......@@ -3,9 +3,10 @@ package com.yottacode.pictogram.tabletlibrary.gui.session;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
......@@ -25,9 +26,8 @@ public class SessionFragment extends Fragment implements ActionTalk.iActionListe
interface iSessionFragment {
public void newMsg(int msg_pos);
public void selectedMsg(int msg_pos);
public void play_msg(int msg_pos);
public void play_msg();
}
private iSessionFragment mListener=null;
......@@ -39,6 +39,8 @@ public class SessionFragment extends Fragment implements ActionTalk.iActionListe
public SessionFragment() {
super();
}
......@@ -46,7 +48,9 @@ public class SessionFragment extends Fragment implements ActionTalk.iActionListe
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
adapter_pictomsg=new PictoAdapter(this.getContext());
setRetainInstance(true);
}
@Override
......@@ -55,7 +59,7 @@ public class SessionFragment extends Fragment implements ActionTalk.iActionListe
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_session, container, false);
list_pictomsg = (ListView) view.findViewById(R.id.session_pictomsg_list);
adapter_pictomsg=new PictoAdapter(this.getContext());
list_pictomsg.setAdapter(adapter_pictomsg);
list_pictomsg.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
......@@ -65,7 +69,6 @@ public class SessionFragment extends Fragment implements ActionTalk.iActionListe
((PictoAdapter)list_pictomsg.getAdapter()).notifyDataSetChanged();
}
});
mListener.newMsg(this.adapter_pictomsg.getCount());
return view;
}
......@@ -106,20 +109,28 @@ public class SessionFragment extends Fragment implements ActionTalk.iActionListe
@Override
public void action(action action, int picto_cat, int picto_id) {
if (action==ActionTalk.iActionListener.action.show) {
if (!paused) {
mListener.play_msg(this.adapter_pictomsg.getCount()-1);
mListener.newMsg(this.adapter_pictomsg.getCount());
mListener.play_msg();
}
} else try {
} else if (action==ActionTalk.iActionListener.action.add
|| action==ActionTalk.iActionListener.action.select
|| action==ActionTalk.iActionListener.action.delete) try {
Picto picto=PCBcontext.getVocabulary().get_picto(picto_cat,picto_id);
Bitmap bmp=picto.get_bitmap(getContext());
if (paused) {
if (action==ActionTalk.iActionListener.action.delete) {
bmp = bmp.copy(bmp.getConfig(), true);
new BitmapTools(bmp).paint((BitmapDrawable)getActivity().getResources().getDrawable(R.drawable.disabled_picto,null),1);
} else if (PCBcontext.getVocabulary().get_picto(picto_cat,picto_id).is_category()) {
Log.e("CAT","catcat");
bmp = bmp.copy(bmp.getConfig(), true);
new BitmapTools(bmp).paint((BitmapDrawable)getActivity().getResources().getDrawable(R.drawable.session_category,null),0.5);
}
if (paused) {
bmp=bmp.copy(bmp.getConfig(),true);
new BitmapTools(bmp).paintPause();
}
this.adapter_pictomsg.addItem(bmp,picto.get_translation());
getActivity().runOnUiThread(new Runnable() {
public void run() {
......@@ -162,4 +173,7 @@ public class SessionFragment extends Fragment implements ActionTalk.iActionListe
public int get_last_msg_pos() {
return adapter_pictomsg.getCount()-1;
}
public String get_msg_text(int pos) {
return adapter_pictomsg.getMsgText(pos);
}
}
......@@ -36,7 +36,7 @@ public class SessionWrapper {
public interface iStartSession {
void started(int id_session);
void started(int id_session, int first_try);
void error(String error);
}
public interface iCloseSession {
......@@ -85,7 +85,7 @@ public class SessionWrapper {
@Override
public void result(JSONObject result) {
try {
listener.started(result.getInt("id"));
listener.started(result.getInt("id"),result.getInt("first_try_id"));
} catch (JSONException e) {
listener.error(e.getMessage());
}
......@@ -247,10 +247,10 @@ public class SessionWrapper {
Hashtable<String, String> params=new Hashtable<>(1);
try {
params.put("json", new JSONObject()
.put("ws", Integer.valueOf(ws).toString())
.put("supervisor",Integer.valueOf(PCBcontext.getPcbdb().getCurrentUser().get_id_sup()).toString())
.put("student",Integer.valueOf(PCBcontext.getPcbdb().getCurrentUser().get_id_stu()).toString())
.put("begin",nowAsISO ).toString());
.put("ws", Integer.valueOf(ws).toString())
.put("supervisor",Integer.valueOf(PCBcontext.getPcbdb().getCurrentUser().get_id_sup()).toString())
.put("student",Integer.valueOf(PCBcontext.getPcbdb().getCurrentUser().get_id_stu()).toString())
.put("begin",nowAsISO ).toString());
} catch (JSONException e) {
Log.e(SessionWrapper.LOG_TAG,e.getMessage());
listener.error(e.getMessage());
......@@ -284,7 +284,8 @@ public class SessionWrapper {
});
}
public static void evaluateTry(final int try_id, boolean now, String result, final iTryUpdated listener) {
public static void evaluateTry(final int try_id, final boolean now, String result, final iTryUpdated listener) {
Hashtable<String, String> params=new Hashtable<>(1);
try{
JSONObject jparams=new JSONObject().put("result",result);
......@@ -295,7 +296,6 @@ public class SessionWrapper {
e.printStackTrace();
}
PCBcontext.getRestapiWrapper().ask("try/"+try_id,params,"put",true, new RestapiWrapper.iRestapiListener() {
@Override
......@@ -305,12 +305,20 @@ public class SessionWrapper {
@Override
public void result(JSONArray result) {
listener.update(try_id);
try {
listener.update(result.getJSONObject(0).getInt("next_try_id"));
} catch (JSONException e) {
listener.error(e.getMessage());
}
}
@Override
public void result(JSONObject result) {
listener.update(try_id);
try {
listener.update(result.getInt("next_try_id"));
} catch (JSONException e) {
listener.error(e.getMessage());
}
}
@Override
......
......@@ -184,26 +184,22 @@
</LinearLayout>
</LinearLayout>
<ScrollView
android:id="@+id/SCROLLER_ID"
<ListView
android:id="@+id/session_serverlog"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:layout_toLeftOf="@+id/imageView3"
android:layout_toRightOf="@+id/view_session_buttons0"
android:layout_below="@+id/view_as2"
android:layout_alignBottom="@+id/imageView3"
android:layout_alignTop="@+id/imageView3"
android:fillViewport="true">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:ems="12"
android:id="@+id/session_serverlog"
android:layout_weight="1"
android:transcriptMode="alwaysScroll"
android:stackFromBottom="true"
android:background="@color/common_google_signin_btn_text_light_disabled" />
</ScrollView>
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
......
......@@ -7,6 +7,8 @@
<ListView
android:id="@+id/session_pictomsg_list"
android:transcriptMode="alwaysScroll"
android:stackFromBottom="true"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
......
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/sessionLogEntry"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textAppearance="@android:style/TextAppearance.Material.Small"
android:gravity="left" />
......@@ -73,14 +73,6 @@
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
......@@ -89,6 +81,14 @@
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/annotations" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
......
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