working on PCB sessions (3)

parent bf9a9ff0
...@@ -62,7 +62,7 @@ public class RestapiWrapper { ...@@ -62,7 +62,7 @@ public class RestapiWrapper {
ask(operation, params, postOrGet, false, listener); ask(operation, params, postOrGet, false, listener);
} }
public void ask(String operation, Hashtable<String, String> params, String postOrGet, boolean json, iRestapiListener listener) { public void ask(String operation, Hashtable<String, String> params, String postOrGet, boolean json, iRestapiListener listener) {
Log.i(this.getClass().getCanonicalName(),"Asking for "+operation);
// call preExecute listener to show loading window // call preExecute listener to show loading window
listener.preExecute(); listener.preExecute();
// call AsynTask to perform network operation on separate thread // call AsynTask to perform network operation on separate thread
...@@ -130,16 +130,17 @@ public class RestapiWrapper { ...@@ -130,16 +130,17 @@ public class RestapiWrapper {
private static JSONObject resultToJSON(HttpURLConnection urlConnection) throws IOException { private static JSONObject resultToJSON(HttpURLConnection urlConnection) throws IOException {
int responseCode=urlConnection.getResponseCode(); int responseCode=urlConnection.getResponseCode();
String response=""; StringBuilder response=new StringBuilder("");
String line; String line;
JSONObject JSONresponse; JSONObject JSONresponse;
BufferedReader br = new BufferedReader(new InputStreamReader(responseCode == HttpsURLConnection.HTTP_OK BufferedReader br = new BufferedReader(new InputStreamReader(responseCode == HttpsURLConnection.HTTP_OK
? urlConnection.getInputStream() ? urlConnection.getInputStream()
: urlConnection.getErrorStream())); : urlConnection.getErrorStream()));
// Log.i(com.yottacode.net.RestapiWrapper.class.getName(), "starting to read server answer for"+urlConnection.getURL().toString());
while ((line=br.readLine()) != null) { while ((line=br.readLine()) != null) {
response+=line; response.append(line);
} }
if (response.length()==0) response="{\"result\":null}"; if (response.length()==0) response.append("{\"result\":null}");
try { try {
JSONresponse = new JSONObject("{ "+SERVER_RESULT+": " + response + (responseCode == HttpsURLConnection.HTTP_OK JSONresponse = new JSONObject("{ "+SERVER_RESULT+": " + response + (responseCode == HttpsURLConnection.HTTP_OK
...@@ -149,7 +150,7 @@ public class RestapiWrapper { ...@@ -149,7 +150,7 @@ public class RestapiWrapper {
JSONresponse = null; JSONresponse = null;
Log.e(RestapiWrapper.class.getCanonicalName(),e.getMessage()); Log.e(RestapiWrapper.class.getCanonicalName(),e.getMessage());
} }
Log.i(com.yottacode.net.RestapiWrapper.class.getName(), "server answer: " + JSONresponse.toString()); // Log.i(com.yottacode.net.RestapiWrapper.class.getName(), "server answer: " + JSONresponse.toString());
return JSONresponse; return JSONresponse;
} }
...@@ -236,7 +237,7 @@ public class RestapiWrapper { ...@@ -236,7 +237,7 @@ public class RestapiWrapper {
@Override @Override
protected HttpAsyncTaskParams doInBackground(HttpAsyncTaskParams... params) { protected HttpAsyncTaskParams doInBackground(HttpAsyncTaskParams... params) {
try { try {
Log.i(com.yottacode.net.RestapiWrapper.class.getName(), " asking to the server for " + params[0].url+" params:"+params[0].url_params +" JSON?"+params[0].json_params); Log.i(com.yottacode.net.RestapiWrapper.class.getName(), " Asking to the server for " + params[0].url+" params:"+params[0].url_params +" JSON?"+params[0].json_params);
JSONObject jresult = params[0].request_method.equalsIgnoreCase("GET") JSONObject jresult = params[0].request_method.equalsIgnoreCase("GET")
? GET(params[0].url, params[0].url_params) ? GET(params[0].url, params[0].url_params)
: POST(params[0].url, params[0].request_method, params[0].url_params, params[0].json_params); : POST(params[0].url, params[0].request_method, params[0].url_params, params[0].json_params);
......
...@@ -9,6 +9,7 @@ import com.yottacode.pictogram.tools.PCBcontext; ...@@ -9,6 +9,7 @@ import com.yottacode.pictogram.tools.PCBcontext;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.Iterator;
import java.util.Vector; import java.util.Vector;
/** /**
...@@ -69,9 +70,11 @@ public class ActionTalk implements Emitter.Listener { ...@@ -69,9 +70,11 @@ public class ActionTalk implements Emitter.Listener {
public void addListener(iActionListener listener) { public void addListener(iActionListener listener) {
listeners.add(listener); listeners.add(listener);
} }
public void removeListener(iActionListener removedlistener) { public void removeListener(iActionListener removedlistener) {
for (iActionListener listener:this.listeners ) Iterator listeners=this.listeners.iterator();
if (listener==removedlistener) listeners.remove(removedlistener); while (listeners.hasNext() )
if (listeners.next()==removedlistener) listeners.remove();
} }
/** /**
......
...@@ -124,7 +124,6 @@ ...@@ -124,7 +124,6 @@
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/animated-vector-drawable/24.2.1/jars" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/animated-vector-drawable/24.2.1/jars" />
......
...@@ -18,7 +18,6 @@ import com.yottacode.net.iRestapiListener; ...@@ -18,7 +18,6 @@ import com.yottacode.net.iRestapiListener;
import com.yottacode.pictogram.dao.User; import com.yottacode.pictogram.dao.User;
import com.yottacode.pictogram.net.ImgDownloader; import com.yottacode.pictogram.net.ImgDownloader;
import com.yottacode.pictogram.tabletlibrary.R; import com.yottacode.pictogram.tabletlibrary.R;
import com.yottacode.pictogram.tabletlibrary.gui.session.SessionActivity;
import com.yottacode.pictogram.tools.Img; import com.yottacode.pictogram.tools.Img;
import com.yottacode.pictogram.tools.PCBcontext; import com.yottacode.pictogram.tools.PCBcontext;
import com.yottacode.tools.GUITools; import com.yottacode.tools.GUITools;
...@@ -117,10 +116,8 @@ public class StudentFragmentGrid extends Fragment{ ...@@ -117,10 +116,8 @@ public class StudentFragmentGrid extends Fragment{
@Override @Override
public void loadComplete() { public void loadComplete() {
if (progressDialog!=null && progressDialog.isShowing()) progressDialog.dismiss(); if (progressDialog!=null && progressDialog.isShowing()) progressDialog.dismiss();
Intent sessionActivity = new Intent(getActivity(), SessionActivity.class); Intent pictogramActivity = new Intent(getActivity(), PictogramActivity.class);
startActivity(sessionActivity); startActivity(pictogramActivity);
//Intent pictogramActivity = new Intent(getActivity(), PictogramActivity.class);
//startActivity(pictogramActivity);
} }
@Override @Override
......
package com.yottacode.pictogram.tabletlibrary.gui.session; package com.yottacode.pictogram.tabletlibrary.gui.session;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.BaseAdapter; import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.yottacode.pictogram.dao.Picto;
import com.yottacode.pictogram.tabletlibrary.R; import com.yottacode.pictogram.tabletlibrary.R;
import com.yottacode.tools.BitmapTools;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Vector; import java.util.Vector;
/** /**
* Created by Fernando on 18/12/2016. * Created by Fernando on 18/12/2016.
*/ */
class PictoAdapter extends BaseAdapter { class PictoAdapter extends BaseAdapter {
private class Item { public void setCurrentMsg(int currentMsg) {
Picto picto; this.currentMsg = currentMsg;
int secs; }
public static class Item {
Bitmap img;
String secs;
public Item(Bitmap img, String secs) {
this.img=img;
this.secs=secs;
}
Bitmap getImg() {
return img;
}
String getTime() {
return secs;
}
public void setImg(Bitmap currmsg) {
this.img=currmsg;
}
} }
Context context; Context context;
Vector<Item> msg; Vector<Item> msg;
int currentMsg=0;
final long base_time=new Date().getTime();
private static LayoutInflater inflater = null; private static LayoutInflater inflater = null;
public PictoAdapter(Context context) { public PictoAdapter(Context context) {
this.context = context; this.context = context;
msg=new Vector<>(3); msg=new Vector<>(3);
newMsg();
inflater = (LayoutInflater) context inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE); .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
} }
private String getTimeDiff(long time) {
long mills = time - this.base_time;
int mins = (int) (mills / (1000*60));
int secs = (int)(mills/(1000)) - mins*60;
return "+"+mins+ "' " + secs+"''";
}
@Override @Override
public int getCount() { public int getCount() {
return msg.size(); return msg.size();
} }
@Override @Override
public Object getItem(int position) { public Item getItem(int position) {
return msg.get(position); return msg.get(position);
} }
...@@ -49,11 +93,106 @@ public long getItemId(int position) { ...@@ -49,11 +93,106 @@ public long getItemId(int position) {
} }
@Override @Override
public View getView(int position, View convertView, ViewGroup parent) { public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View vi = convertView; View vi = convertView;
if (vi == null) if (vi == null)
vi = inflater.inflate(R.layout.session_picto_view, null); 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)
vi.setBackgroundColor(Color.LTGRAY);
else
vi.setBackgroundColor(Color.TRANSPARENT);
return vi; return vi;
} }
public void addItem(Bitmap bmp) {
Item item=this.msg.get(currentMsg);
Bitmap oldmsg=item.getImg();
// bmp=new BitmapTools(bmp).resize(85,85).get();
bmp=set_text(context,bmp,getTimeDiff(new Date().getTime()));
Bitmap currmsg=combineImages(oldmsg,bmp);
item.setImg(currmsg);
}
public void newMsg() {
Bitmap bmp=BitmapFactory.decodeResource(context.getResources(),
R.drawable.session_starttry);
bmp=new BitmapTools(bmp).resize(75,75).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)+":"+calendar.get(Calendar.MINUTE)+":"+calendar.get(Calendar.SECOND);
bmp=set_text(context,bmp,time);
if (this.currentMsg==this.msg.size()-1 || this.msg.size()==0) {
this.currentMsg = this.msg.size();
msg.add(new Item(bmp, time));
}
else {
this.currentMsg = this.msg.size() - 1;
notifyDataSetChanged();
}
}
private Bitmap combineImages(Bitmap c, Bitmap s) { // can add a 3rd parameter 'String loc' if you want to save the new image - left some code to do that at the bottom
Bitmap cs = null;
int width, height = 0;
if(c.getWidth() > s.getWidth()) {
width = c.getWidth() + s.getWidth();
height = c.getHeight();
} else {
width = s.getWidth() + s.getWidth();
height = c.getHeight();
}
cs = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas comboImage = new Canvas(cs);
comboImage.drawBitmap(c, 0f, 0f, null);
comboImage.drawBitmap(s, c.getWidth(), 0f, null);
return cs;
}
static Bitmap set_text(Context context,Bitmap bitmap,String texto) {
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
int width = bitmap.getWidth(); //Ancho original
int height = bitmap.getHeight(); //Alto original
android.graphics.Bitmap.Config bitmapConfig = bitmap.getConfig();
if (bitmapConfig == null) {
bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888;
}
bitmap = bitmap.copy(bitmapConfig, true);
Canvas canvas = new Canvas(bitmap);
Bitmap bm = Bitmap.createScaledBitmap(bitmap, (int)Math.round(0.9*width), (int)Math.round(0.9*height), false);
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, 50, 100, 100);
textView.setPadding(0, 0, 0, 0);
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, 13);
textView.setTextColor(Color.BLACK);
textView.setBackgroundColor(Color.TRANSPARENT);
textView.setWidth(100);
textView.setGravity(Gravity.CENTER_HORIZONTAL);
textView.setMaxLines(1);
textView.setText(texto);
textView.setDrawingCacheEnabled(true);
canvas.drawBitmap(textView.getDrawingCache(), 0, 60, null);
return bitmap;
}
} }
package com.yottacode.pictogram.tabletlibrary.gui.session; package com.yottacode.pictogram.tabletlibrary.gui.session;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.util.Log; import android.util.Log;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
...@@ -19,16 +20,22 @@ import android.widget.ToggleButton; ...@@ -19,16 +20,22 @@ import android.widget.ToggleButton;
import com.yottacode.pictogram.dao.User; import com.yottacode.pictogram.dao.User;
import com.yottacode.pictogram.tabletlibrary.R; import com.yottacode.pictogram.tabletlibrary.R;
import com.yottacode.pictogram.tabletlibrary.gui.PictogramActivity;
import com.yottacode.pictogram.tools.PCBcontext; import com.yottacode.pictogram.tools.PCBcontext;
import java.io.IOException; import java.io.IOException;
public class SessionActivity extends FragmentActivity implements ListInstructionsFragment.iListInstructionsFragment, SessionFragment.OnFragmentInteractionListener{ public class SessionActivity extends FragmentActivity implements ListInstructionsFragment.iListInstructionsFragment, SessionFragment.OnSessionListener {
private static final String FRAGMENT_SESSION="session"; private static final String FRAGMENT_SESSION="session";
private static final String FRAGMENT_METHOD="method"; private static final String FRAGMENT_METHOD="method";
@Override
public void onSessionInteraction(Uri uri) {
}
class TouchButtonListener implements View.OnTouchListener { class TouchButtonListener implements View.OnTouchListener {
int press,release; int press,release;
...@@ -44,30 +51,30 @@ public class SessionActivity extends FragmentActivity implements ListInstruction ...@@ -44,30 +51,30 @@ public class SessionActivity extends FragmentActivity implements ListInstruction
: getDrawable(release); : getDrawable(release);
v.setBackground(draw); v.setBackground(draw);
if (event.getAction()==MotionEvent.ACTION_UP) {
SessionFragment session = (SessionFragment) getSupportFragmentManager().findFragmentByTag(SessionActivity.FRAGMENT_SESSION);
//Bitmap bitmap=((BitmapDrawable)getDrawable(press)).getBitmap();
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),press);
//Bitmap bm = Bitmap.createScaledBitmap(bitmap, (int)Math.round(0.9*bitmap.getWidth()), (int)Math.round(0.9*bitmap.getHeight()), false);
session.newMsg(bitmap);
}
return true; return true;
} }
} }
float firstTouchX=-1;
SessionFragment sessionFragment = new SessionFragment(); SessionFragment sessionFragment = new SessionFragment();
ListInstructionsFragment listInstructionsFragment= new ListInstructionsFragment(); ListInstructionsFragment listInstructionsFragment= new ListInstructionsFragment();
boolean previous_mirrormode=PCBcontext.getPcbdb().getCurrentUser().is_mirror_on(); boolean previous_mirrormode=PCBcontext.getPcbdb().getCurrentUser().is_mirror_on();
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE); requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_session); setContentView(R.layout.activity_session);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.sessions_fragment_container, listInstructionsFragment)
.commit();
}
@Override
protected void onStart() {
super.onStart();
// Set Student information on topbar
User student=PCBcontext.getPcbdb().getCurrentUser(); User student=PCBcontext.getPcbdb().getCurrentUser();
final TextView StudentFullNameView = (TextView) findViewById(R.id.sessionTopbarStudentFullName); final TextView StudentFullNameView = (TextView) findViewById(R.id.sessionTopbarStudentFullName);
final TextView StudentUserNameView = (TextView) findViewById(R.id.sessionTopbarStudentUserName); final TextView StudentUserNameView = (TextView) findViewById(R.id.sessionTopbarStudentUserName);
...@@ -81,19 +88,76 @@ public class SessionActivity extends FragmentActivity implements ListInstruction ...@@ -81,19 +88,76 @@ public class SessionActivity extends FragmentActivity implements ListInstruction
StudentFullNameView.setText(student.get_name_stu() + " " + student.get_surname_stu()); StudentFullNameView.setText(student.get_name_stu() + " " + student.get_surname_stu());
StudentUserNameView.setText(student.get_nickname_stu()); StudentUserNameView.setText(student.get_nickname_stu());
try {
StudentPhotoView.setImageBitmap(student.get_bitmap_stu(this.getBaseContext()));
} catch (IOException e) {
Log.e(this.getClass().getCanonicalName(),e.getMessage());
}
okBtn.setOnTouchListener(new TouchButtonListener(R.drawable.session_ok,R.drawable.session_ok2)); okBtn.setOnTouchListener(new TouchButtonListener(R.drawable.session_ok,R.drawable.session_ok2));
disBtn.setOnTouchListener(new TouchButtonListener(R.drawable.session_fail,R.drawable.session_fail2)); disBtn.setOnTouchListener(new TouchButtonListener(R.drawable.session_fail,R.drawable.session_fail2));
spoBtn.setOnTouchListener(new TouchButtonListener(R.drawable.session_spontaneous,R.drawable.session_spontaneous2)); spoBtn.setOnTouchListener(new TouchButtonListener(R.drawable.session_spontaneous,R.drawable.session_spontaneous2));
failBtn.setOnTouchListener(new TouchButtonListener(R.drawable.session_fail,R.drawable.session_fail2)); failBtn.setOnTouchListener(new TouchButtonListener(R.drawable.session_fail,R.drawable.session_fail2));
supBtn.setOnTouchListener(new TouchButtonListener(R.drawable.session_supervised,R.drawable.session_supervised2)); supBtn.setOnTouchListener(new TouchButtonListener(R.drawable.session_supervised,R.drawable.session_supervised2));
onoffBtn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { onoffBtn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (!isChecked)
onoffBtn.setEnabled(false);
set_fragment(isChecked);
}
});
onoffBtn.setEnabled(false);
}
@Override
protected void onStart() {
super.onStart();
set_fragment(((ToggleButton)findViewById(R.id.sessionOnOffBtn)).isChecked());
}
@Override
public void instruction_selected(int instruction, String instruction_name) {
((TextView)findViewById(R.id.sessionTopbarInstructionName)).setText(instruction_name);
findViewById(R.id.sessionOnOffBtn).setEnabled(true);
}
@Override
public void method_selected(int method, String method_name) {
((ToggleButton)findViewById(R.id.sessionOnOffBtn)).setEnabled(false);
((TextView)findViewById(R.id.sessionTopbarMethodName)).setText(method_name);
}
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
if (PCBcontext.getPcbdb().getCurrentUser().is_supervisor())
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
firstTouchX = event.getX();
break;
case MotionEvent.ACTION_MOVE:
if (event.getX()> firstTouchX +100) {
Intent pictogramActivity = new Intent(this, PictogramActivity.class);
startActivity(pictogramActivity);
}
break;
case MotionEvent.ACTION_UP:
firstTouchX = 100000;
}
return super.dispatchTouchEvent(event);
}
private void set_fragment(boolean isChecked) {
Fragment fragment; Fragment fragment;
String fragment_label; String fragment_label;
final Button okBtn =((Button)findViewById(R.id.btn_correct));
final Button disBtn =((Button)findViewById(R.id.btn_discarded));
final Button spoBtn =((Button)findViewById(R.id.btn_spontaneous));
final Button failBtn =((Button)findViewById(R.id.btn_fail));
final Button supBtn =((Button)findViewById(R.id.btn_supervised));
int stop; int stop;
if (isChecked) { if (isChecked) {
fragment= sessionFragment; fragment= sessionFragment;
...@@ -110,12 +174,11 @@ public class SessionActivity extends FragmentActivity implements ListInstruction ...@@ -110,12 +174,11 @@ public class SessionActivity extends FragmentActivity implements ListInstruction
PCBcontext.getPcbdb().getCurrentUser().alter_mirror_mode(); PCBcontext.getPcbdb().getCurrentUser().alter_mirror_mode();
} }
FragmentManager fragmentManager = getSupportFragmentManager(); getSupportFragmentManager()
FragmentTransaction fragmentTransaction = fragmentManager .beginTransaction()
.beginTransaction(); .replace(R.id.sessions_fragment_container, fragment,fragment_label)
.commit()
fragmentTransaction.replace(R.id.sessions_fragment_container, fragment,fragment_label); ;
fragmentTransaction.commit();
findViewById(R.id.sessionPauseBtn).setVisibility(stop); findViewById(R.id.sessionPauseBtn).setVisibility(stop);
okBtn.setVisibility(stop); okBtn.setVisibility(stop);
disBtn.setVisibility(stop); disBtn.setVisibility(stop);
...@@ -124,44 +187,7 @@ public class SessionActivity extends FragmentActivity implements ListInstruction ...@@ -124,44 +187,7 @@ public class SessionActivity extends FragmentActivity implements ListInstruction
supBtn.setVisibility(stop); supBtn.setVisibility(stop);
findViewById(R.id.sessionTopbarMethodName).setVisibility(stop); findViewById(R.id.sessionTopbarMethodName).setVisibility(stop);
findViewById(R.id.sessionTopbarInstructionName).setVisibility(stop); findViewById(R.id.sessionTopbarInstructionName).setVisibility(stop);
} }
});
try {
StudentPhotoView.setImageBitmap(student.get_bitmap_stu(this.getBaseContext()));
} catch (IOException e) {
Log.e(this.getClass().getCanonicalName(),"Error setting student image");
}
Fragment currentFragment = getSupportFragmentManager().findFragmentByTag(SessionActivity.FRAGMENT_METHOD);
if (currentFragment == null || !currentFragment.isVisible()) {
findViewById(R.id.sessionTopbarMethodName).setVisibility(View.INVISIBLE);
findViewById(R.id.sessionTopbarInstructionName).setVisibility(View.INVISIBLE);
findViewById(R.id.sessionPauseBtn).setVisibility(View.INVISIBLE);
okBtn.setVisibility(View.INVISIBLE);
disBtn.setVisibility(View.INVISIBLE);
spoBtn.setVisibility(View.INVISIBLE);
failBtn.setVisibility(View.INVISIBLE);
supBtn.setVisibility(View.INVISIBLE);
onoffBtn.setEnabled(false);
}
}
@Override
public void instruction_selected(int instruction, String instruction_name) {
((ToggleButton)findViewById(R.id.sessionOnOffBtn)).setEnabled(true);
((TextView)findViewById(R.id.sessionTopbarInstructionName)).setText(instruction_name);
}
@Override
public void method_selected(int method, String method_name) {
((ToggleButton)findViewById(R.id.sessionOnOffBtn)).setEnabled(false);
((TextView)findViewById(R.id.sessionTopbarMethodName)).setText(method_name);
}
@Override
public void onFragmentInteraction(Uri uri) {
}
} }
...@@ -2,6 +2,7 @@ package com.yottacode.pictogram.tabletlibrary.gui.session; ...@@ -2,6 +2,7 @@ package com.yottacode.pictogram.tabletlibrary.gui.session;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
...@@ -9,16 +10,19 @@ import android.util.Log; ...@@ -9,16 +10,19 @@ import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView; import android.widget.ListView;
import com.yottacode.pictogram.net.websockets.ActionTalk; import com.yottacode.pictogram.net.websockets.ActionTalk;
import com.yottacode.pictogram.tabletlibrary.R; import com.yottacode.pictogram.tabletlibrary.R;
import com.yottacode.pictogram.tools.PCBcontext; import com.yottacode.pictogram.tools.PCBcontext;
import java.io.IOException;
/** /**
* A simple {@link Fragment} subclass. * A simple {@link Fragment} subclass.
* Activities that contain this fragment must implement the * Activities that contain this fragment must implement the
* {@link SessionFragment.OnFragmentInteractionListener} interface * {@link SessionFragment.OnSessionListener } interface
* to handle interaction events. * to handle interaction events.
* Use the {@link SessionFragment#newInstance} factory method to * Use the {@link SessionFragment#newInstance} factory method to
* create an instance of this fragment. * create an instance of this fragment.
...@@ -33,9 +37,10 @@ public class SessionFragment extends Fragment implements ActionTalk.iActionListe ...@@ -33,9 +37,10 @@ public class SessionFragment extends Fragment implements ActionTalk.iActionListe
private String mParam1; private String mParam1;
private String mParam2; private String mParam2;
ListView list_pictomsgs; ListView list_pictomsg;
PictoAdapter adapter_pictomsg;
private OnFragmentInteractionListener mListener; private OnSessionListener mListener=null;
public SessionFragment() { public SessionFragment() {
// Required empty public constructor // Required empty public constructor
...@@ -73,24 +78,28 @@ public class SessionFragment extends Fragment implements ActionTalk.iActionListe ...@@ -73,24 +78,28 @@ public class SessionFragment extends Fragment implements ActionTalk.iActionListe
Bundle savedInstanceState) { Bundle savedInstanceState) {
// Inflate the layout for this fragment // Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_session, container, false); View view = inflater.inflate(R.layout.fragment_session, container, false);
list_pictomsgs = (ListView) this.getActivity().findViewById(R.id.session_pictomsg_list); list_pictomsg = (ListView) view.findViewById(R.id.session_pictomsg_list);
// list_pictomsgs.setAdapter(new PictoAdapter(this.getContext())); adapter_pictomsg=new PictoAdapter(this.getContext());
list_pictomsg.setAdapter(adapter_pictomsg);
list_pictomsg.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
((PictoAdapter)list_pictomsg.getAdapter()).setCurrentMsg(position);
((PictoAdapter)list_pictomsg.getAdapter()).notifyDataSetChanged();
}
});
return view; return view;
} }
// TODO: Rename method, update argument and hook method into UI event
public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onFragmentInteraction(uri);
}
}
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Override @Override
public void onAttach(Activity context) { public void onAttach(Activity context) {
super.onAttach(context); super.onAttach(context);
if (context instanceof OnFragmentInteractionListener) { if ( mListener==null)
mListener = (OnFragmentInteractionListener) context; if (context instanceof OnSessionListener) {
mListener = (OnSessionListener ) context;
PCBcontext.getVocabulary().addActionTalkListener(this); PCBcontext.getVocabulary().addActionTalkListener(this);
} else { } else {
throw new RuntimeException(context.toString() throw new RuntimeException(context.toString()
...@@ -101,8 +110,9 @@ public class SessionFragment extends Fragment implements ActionTalk.iActionListe ...@@ -101,8 +110,9 @@ public class SessionFragment extends Fragment implements ActionTalk.iActionListe
@Override @Override
public void onAttach(Context context) { public void onAttach(Context context) {
super.onAttach(context); super.onAttach(context);
if (context instanceof OnFragmentInteractionListener) { if ( mListener==null)
mListener = (OnFragmentInteractionListener) context; if (context instanceof OnSessionListener ) {
mListener = (OnSessionListener ) context;
PCBcontext.getVocabulary().addActionTalkListener(this); PCBcontext.getVocabulary().addActionTalkListener(this);
} else { } else {
throw new RuntimeException(context.toString() throw new RuntimeException(context.toString()
...@@ -120,6 +130,27 @@ public class SessionFragment extends Fragment implements ActionTalk.iActionListe ...@@ -120,6 +130,27 @@ public class SessionFragment extends Fragment implements ActionTalk.iActionListe
@Override @Override
public void action(action action, int picto_cat, int picto_id) { public void action(action action, int picto_cat, int picto_id) {
Log.e(this.getClass().getCanonicalName(),"ACTION VOC"); Log.e(this.getClass().getCanonicalName(),"ACTION VOC");
try {
Bitmap bmp=PCBcontext.getVocabulary().get_picto(picto_cat,picto_id).get_bitmap(getContext());
this.adapter_pictomsg.addItem(bmp);
getActivity().runOnUiThread(new Runnable() {
public void run() {
adapter_pictomsg.notifyDataSetChanged();
}});
} catch (IOException e) {
e.printStackTrace();
}
}
public void newMsg(Bitmap bmp) {
Log.e(this.getClass().getCanonicalName(),"ACTION VOC");
this.adapter_pictomsg.addItem(bmp);
this.adapter_pictomsg.newMsg();
getActivity().runOnUiThread(new Runnable() {
public void run() {
adapter_pictomsg.notifyDataSetChanged();
}});
} }
/** /**
...@@ -132,8 +163,8 @@ public class SessionFragment extends Fragment implements ActionTalk.iActionListe ...@@ -132,8 +163,8 @@ public class SessionFragment extends Fragment implements ActionTalk.iActionListe
* "http://developer.android.com/training/basics/fragments/communicating.html" * "http://developer.android.com/training/basics/fragments/communicating.html"
* >Communicating with Other Fragments</a> for more information. * >Communicating with Other Fragments</a> for more information.
*/ */
public interface OnFragmentInteractionListener { public interface OnSessionListener {
// TODO: Update argument type and name // TODO: Update argument type and name
void onFragmentInteraction(Uri uri); void onSessionInteraction(Uri uri);
} }
} }
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
android:background="#BDBDBD" android:background="#BDBDBD"
android:keepScreenOn="true" android:keepScreenOn="true"
android:id="@+id/pictogramLayout" android:id="@+id/pictogramLayout"
android:activityOpenEnterAnimation="@anim/slide_in"
android:activityOpenExitAnimation="@anim/slide_out"
tools:context="com.yottacode.pictogram.tabletlibrary.gui.PictogramActivity" tools:context="com.yottacode.pictogram.tabletlibrary.gui.PictogramActivity"
android:padding="@dimen/small_padding"> android:padding="@dimen/small_padding">
<!-- android:keepScreenOn - To keep the screen bright as long as the app is visible (also forever) --> <!-- android:keepScreenOn - To keep the screen bright as long as the app is visible (also forever) -->
......
...@@ -118,7 +118,7 @@ ...@@ -118,7 +118,7 @@
android:id="@+id/sessionFragmentLayout" android:id="@+id/sessionFragmentLayout"
android:layout_below="@+id/view" android:layout_below="@+id/view"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
android:layout_height="328dp"> android:layout_height="300dp">
<FrameLayout <FrameLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
......
...@@ -3,20 +3,14 @@ ...@@ -3,20 +3,14 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context="com.yottacode.pictogram.tabletlibrary.gui.session.SessionFragment" tools:context="com.yottacode.pictogram.tabletlibrary.gui.session.SessionFragment"
android:orientation="vertical"> android:orientation="vertical" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="220dp"
android:orientation="horizontal" >
<ListView <ListView
android:id="@+id/session_pictomsg_list" android:id="@+id/session_pictomsg_list"
android:layout_width="wrap_content" android:orientation="horizontal"
android:layout_height="wrap_content" > android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="left|start">
</ListView> </ListView>
</LinearLayout>
</LinearLayout> </LinearLayout>
...@@ -2,23 +2,15 @@ ...@@ -2,23 +2,15 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:orientation="vertical" android:orientation="vertical"
android:layout_height="90dp" android:layout_height="match_parent"
android:id="@+id/session_picto_layout" android:id="@+id/session_picto_layout"
android:background="@color/picto_default_background" android:background="@color/picto_default_background"
android:padding="@dimen/picto_padding"> android:padding="@dimen/picto_padding">
<ImageView <ImageView
android:id="@+id/session_picto" android:id="@+id/session_picto"
android:layout_height="@dimen/picto_normal_height"
android:layout_width="match_parent"
android:contentDescription="" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/session_picto_time"/> android:layout_width="wrap_content"
android:contentDescription="" />
</LinearLayout> </LinearLayout>
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