diff --git a/res/layout-large-land/use_prepared_questions_dialog.xml b/res/layout-large-land/use_prepared_questions_dialog.xml
index b9af050..5bd5170 100644
--- a/res/layout-large-land/use_prepared_questions_dialog.xml
+++ b/res/layout-large-land/use_prepared_questions_dialog.xml
@@ -29,10 +29,11 @@
-
-
-
-
-
-
+ android:dividerHeight="10.0sp" />
@@ -121,11 +88,10 @@
android:id="@+id/sp_hours"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
- android:prompt="@string/hours"
- android:layout_marginLeft="65dip"
- android:layout_marginRight="50dip"
- android:layout_toRightOf="@+id/tv_hours_spinner"
- android:layout_below="@+id/cb_questions"/>
+ android:layout_alignLeft="@+id/sp_seconds"
+ android:layout_below="@+id/cb_questions"
+ android:layout_marginRight="20dip"
+ android:prompt="@string/hours" />
@@ -145,9 +110,9 @@
android:layout_height="wrap_content"
android:prompt="@string/minutes"
android:layout_marginTop="15dip"
- android:layout_marginLeft="55dip"
- android:layout_marginRight="50dip"
- android:layout_toRightOf="@+id/tv_minutes_spinner"
+ android:layout_marginLeft="20dip"
+ android:layout_marginRight="20dip"
+ android:layout_toRightOf="@+id/tv_seconds_spinner"
android:layout_below="@+id/tv_hours_spinner"/>
@@ -168,9 +132,40 @@
android:layout_height="wrap_content"
android:prompt="@string/seconds"
android:layout_marginTop="11dip"
- android:layout_marginLeft="50dip"
- android:layout_marginRight="50dip"
+ android:layout_marginLeft="20dip"
+ android:layout_marginRight="20dip"
android:layout_toRightOf="@+id/tv_seconds_spinner"
android:layout_below="@+id/tv_minutes_spinner"/>
+
+
+
+
+
+
diff --git a/res/layout-large-land/use_prepared_questions_item.xml b/res/layout-large-land/use_prepared_questions_item.xml
index d068322..e415203 100644
--- a/res/layout-large-land/use_prepared_questions_item.xml
+++ b/res/layout-large-land/use_prepared_questions_item.xml
@@ -25,6 +25,26 @@
android:textColor="@color/black"
android:focusable="false"
android:layout_gravity="left|center_vertical"/>
+
+
+
+
diff --git a/res/values/strings.xml b/res/values/strings.xml
index d6ddd48..f609e2c 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -104,7 +104,7 @@
Are you sure you want to restart session?
A Session is already running!
- 10.1.0.1
+ 192.168.1.18
IP
It was not possible to save the questions
It was not possible to save the question(s) because the file already exists. Please try a new filename
diff --git a/src/main/java/org/smilec/smile/bu/QuestionsManager.java b/src/main/java/org/smilec/smile/bu/QuestionsManager.java
index 0f13b8c..82c0a27 100644
--- a/src/main/java/org/smilec/smile/bu/QuestionsManager.java
+++ b/src/main/java/org/smilec/smile/bu/QuestionsManager.java
@@ -162,170 +162,173 @@ public void saveQuestions(Context context, String name, Collection que
}
}
-
- public Collection loadQuestions(String name) {
- int number = 1;
- Collection result = new ArrayList();
- Log.d("QuestionsManager", "Importing Questions: " + name);
-
- File dir = new File(questionsDir, name);
- File file = new File(dir, QUESTIONS_FILE);
-
- if (!file.exists()) {
- Log.d("QuestionsManager", "JSON Questions file doesn't exist: " + file.getAbsolutePath());
- file = new File(dir, dir.getName());
- if (!file.exists()) {
- Log.d("QuestionsManager", "CSV Questions file doesn't exist: " + file.getAbsolutePath());
- return result;
- } else {
- Log.d("QuestionsManager", "CSV Questions file exists: " + file.getAbsolutePath());
- }
- }
-
- // XXX candidate for refactoring
- if (file.getAbsolutePath().endsWith(IQ_MIME_EXT_CSV) == true) {
- Log.d("QuestionsManager", "Load CSV Questions from: " + file.getAbsolutePath());
- //
- // Handle the .csv load
- //
- try {
- CsvReader csvQuestions = new CsvReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
- // CsvReader csvQuestions = new CsvReader(new InputStreamReader(new FileInputStream(file), "Shift_JIS"));
- csvQuestions.readHeaders();
-
- while (csvQuestions.readRecord())
- {
- try {
- String num = csvQuestions.get("num");
- String question = csvQuestions.get("question");
- String option1 = csvQuestions.get("choice1");
- String option2 = csvQuestions.get("choice2");
- String option3 = csvQuestions.get("choice3");
- String option4 = csvQuestions.get("choice4");
- String hasImage = csvQuestions.get("has_image");
- String image = null;
- Log.d("QuestionsManager", "Loading question: " + question + "(a) " + option1 + "(b)" + option2 + "(c)" + option3 + "(d)" + option4);
- if (hasImage != null && hasImage.length() > 0) {
- File img = new File(dir, number + JPG);
- byte[] originalArray = IOUtil.loadBytes(img);
- String encodedString = Base64.encodeBytes(originalArray);
- image = encodedString;
- }
- int answer = Integer.valueOf(csvQuestions.get("answers"));
- String owner = csvQuestions.get("owner_name");
- if (owner == null || owner.length() == 0) {
- owner= TEACHER_NAME;
- }
- String ip = csvQuestions.get("owner_IP");
- if (ip == null || ip.length() == 0) {
- ip = TEACHER_IP;
- }
- Question q = new Question(number, owner, ip, question, option1, option2, option3, option4, answer, image);
- result.add(q);
- number = number + 1;
- } catch(IOException ioe) {
- // XXX Log the error or do something
- Log.e(Constants.LOG_CATEGORY, "CSV Load Error: ", ioe);
- }
- }
- Log.d("QuestionsManager", "Total Number of Questions: " + (number - 1));
- } catch(FileNotFoundException fnfe) {
- // XXX Log the error or do something
- Log.e(Constants.LOG_CATEGORY, "CSV Load Error, cannot find file: ", fnfe);
- } catch(UnsupportedEncodingException uee) {
- // XXX Log the error or do something
- Log.e(Constants.LOG_CATEGORY, "CSV Load Error, unsupported encoding: ", uee);
- } catch(IOException ioe) {
- // XXX Log the error or do something
- Log.e(Constants.LOG_CATEGORY, "CSV Load Error: ", ioe);
- }
- } else {
- Log.d("QuestionsManager", "Load JSON Questions from: " + file.getAbsolutePath());
- do {
-
- FileReader fr = null;
- try {
- fr = new FileReader(file);
- } catch (FileNotFoundException e1) {
- Log.e(Constants.LOG_CATEGORY, "File Load Error, not found: ", e1);
- return result;
- }
-
- BufferedReader br = new BufferedReader(fr, 8 * 1024);
-
- try {
-
- // Read Marker
- if (!readMarker(br)) {
- break;
- }
-
- // Number of Questions
- int n = Integer.valueOf(br.readLine());
- if (!readMarker(br)) {
- break;
- }
-
- if (n <= 0) {
- return result;
- }
-
-
- for (int i = 0; i < n; i++) {
-
- String sNumber = readUntilMarker(br);
- number = Integer.valueOf(sNumber);
-
- String question = readUntilMarker(br);
- String option1 = readUntilMarker(br);
- String option2 = readUntilMarker(br);
- String option3 = readUntilMarker(br);
- String option4 = readUntilMarker(br);
-
- String sHasImage = readUntilMarker(br);
- boolean hasImage = "Y".equals(sHasImage);
-
- String image = null;
- if (hasImage) {
- File img = new File(dir, number + JPG);
- byte[] originalArray = IOUtil.loadBytes(img);
- String encodedString = Base64.encodeBytes(originalArray);
- image = encodedString;
- }
-
- String sAnswer = readUntilMarker(br);
- int answer = Integer.valueOf(sAnswer);
-
- String ip = readUntilMarker(br);
-
- String owner = null;
-
- // XXX We can't really use owner yet
- /*
- owner = readUntilMarker(br);
-
- */
- if (owner == null) {
- owner = TEACHER_NAME;
- }
-
- Question q = new Question(number, owner, ip, question, option1, option2,
- option3, option4, answer, image);
-
- result.add(q);
- }
-
- } catch (IOException e) {
- Log.e(Constants.LOG_CATEGORY, "JSON File Load Error: ", e);
- } finally {
- IOUtil.silentClose(br);
- }
-
- } while (false);
- }
-
- return result;
- }
+// USELESS: Previously used when the prepared questions came from local files
+
+// public Collection loadQuestions(String name) {
+// int number = 1;
+// Collection result = new ArrayList();
+// Log.d("QuestionsManager", "Importing Questions: " + name);
+//
+// File dir = new File(questionsDir, name);
+// File file = new File(dir, QUESTIONS_FILE);
+//
+// System.out.println("file.getAbsolutePath()="+file.getAbsolutePath());
+//
+// if (!file.exists()) {
+// Log.d("QuestionsManager", "JSON Questions file doesn't exist: " + file.getAbsolutePath());
+// file = new File(dir, dir.getName());
+// if (!file.exists()) {
+// Log.d("QuestionsManager", "CSV Questions file doesn't exist: " + file.getAbsolutePath());
+// return result;
+// } else {
+// Log.d("QuestionsManager", "CSV Questions file exists: " + file.getAbsolutePath());
+// }
+// }
+//
+// // XXX candidate for refactoring
+// if (file.getAbsolutePath().endsWith(IQ_MIME_EXT_CSV) == true) {
+// Log.d("QuestionsManager", "Load CSV Questions from: " + file.getAbsolutePath());
+// //
+// // Handle the .csv load
+// //
+// try {
+// CsvReader csvQuestions = new CsvReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
+// // CsvReader csvQuestions = new CsvReader(new InputStreamReader(new FileInputStream(file), "Shift_JIS"));
+// csvQuestions.readHeaders();
+//
+// while (csvQuestions.readRecord())
+// {
+// try {
+// String num = csvQuestions.get("num");
+// String question = csvQuestions.get("question");
+// String option1 = csvQuestions.get("choice1");
+// String option2 = csvQuestions.get("choice2");
+// String option3 = csvQuestions.get("choice3");
+// String option4 = csvQuestions.get("choice4");
+// String hasImage = csvQuestions.get("has_image");
+// String image = null;
+// Log.d("QuestionsManager", "Loading question: " + question + "(a) " + option1 + "(b)" + option2 + "(c)" + option3 + "(d)" + option4);
+// if (hasImage != null && hasImage.length() > 0) {
+// File img = new File(dir, number + JPG);
+// byte[] originalArray = IOUtil.loadBytes(img);
+// String encodedString = Base64.encodeBytes(originalArray);
+// image = encodedString;
+// }
+// int answer = Integer.valueOf(csvQuestions.get("answers"));
+// String owner = csvQuestions.get("owner_name");
+// if (owner == null || owner.length() == 0) {
+// owner= TEACHER_NAME;
+// }
+// String ip = csvQuestions.get("owner_IP");
+// if (ip == null || ip.length() == 0) {
+// ip = TEACHER_IP;
+// }
+// Question q = new Question(number, owner, ip, question, option1, option2, option3, option4, answer, image);
+// result.add(q);
+// number = number + 1;
+// } catch(IOException ioe) {
+// // XXX Log the error or do something
+// Log.e(Constants.LOG_CATEGORY, "CSV Load Error: ", ioe);
+// }
+// }
+// Log.d("QuestionsManager", "Total Number of Questions: " + (number - 1));
+// } catch(FileNotFoundException fnfe) {
+// // XXX Log the error or do something
+// Log.e(Constants.LOG_CATEGORY, "CSV Load Error, cannot find file: ", fnfe);
+// } catch(UnsupportedEncodingException uee) {
+// // XXX Log the error or do something
+// Log.e(Constants.LOG_CATEGORY, "CSV Load Error, unsupported encoding: ", uee);
+// } catch(IOException ioe) {
+// // XXX Log the error or do something
+// Log.e(Constants.LOG_CATEGORY, "CSV Load Error: ", ioe);
+// }
+// } else {
+// Log.d("QuestionsManager", "Load JSON Questions from: " + file.getAbsolutePath());
+// do {
+//
+// FileReader fr = null;
+// try {
+// fr = new FileReader(file);
+// } catch (FileNotFoundException e1) {
+// Log.e(Constants.LOG_CATEGORY, "File Load Error, not found: ", e1);
+// return result;
+// }
+//
+// BufferedReader br = new BufferedReader(fr, 8 * 1024);
+//
+// try {
+//
+// // Read Marker
+// if (!readMarker(br)) {
+// break;
+// }
+//
+// // Number of Questions
+// int n = Integer.valueOf(br.readLine());
+// if (!readMarker(br)) {
+// break;
+// }
+//
+// if (n <= 0) {
+// return result;
+// }
+//
+//
+// for (int i = 0; i < n; i++) {
+//
+// String sNumber = readUntilMarker(br);
+// number = Integer.valueOf(sNumber);
+//
+// String question = readUntilMarker(br);
+// String option1 = readUntilMarker(br);
+// String option2 = readUntilMarker(br);
+// String option3 = readUntilMarker(br);
+// String option4 = readUntilMarker(br);
+//
+// String sHasImage = readUntilMarker(br);
+// boolean hasImage = "Y".equals(sHasImage);
+//
+// String image = null;
+// if (hasImage) {
+// File img = new File(dir, number + JPG);
+// byte[] originalArray = IOUtil.loadBytes(img);
+// String encodedString = Base64.encodeBytes(originalArray);
+// image = encodedString;
+// }
+//
+// String sAnswer = readUntilMarker(br);
+// int answer = Integer.valueOf(sAnswer);
+//
+// String ip = readUntilMarker(br);
+//
+// String owner = null;
+//
+// // XXX We can't really use owner yet
+// /*
+// owner = readUntilMarker(br);
+//
+// */
+// if (owner == null) {
+// owner = TEACHER_NAME;
+// }
+//
+// Question q = new Question(number, owner, ip, question, option1, option2,
+// option3, option4, answer, image);
+//
+// result.add(q);
+// }
+//
+// } catch (IOException e) {
+// Log.e(Constants.LOG_CATEGORY, "JSON File Load Error: ", e);
+// } finally {
+// IOUtil.silentClose(br);
+// }
+//
+// } while (false);
+// }
+//
+// return result;
+// }
public boolean readMarker(BufferedReader br) throws IOException {
String s = br.readLine();
diff --git a/src/main/java/org/smilec/smile/bu/SmilePlugServerManager.java b/src/main/java/org/smilec/smile/bu/SmilePlugServerManager.java
index 99eddf0..52dac7d 100644
--- a/src/main/java/org/smilec/smile/bu/SmilePlugServerManager.java
+++ b/src/main/java/org/smilec/smile/bu/SmilePlugServerManager.java
@@ -15,6 +15,7 @@
**/
package org.smilec.smile.bu;
+import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
@@ -26,9 +27,13 @@
import org.json.JSONObject;
import org.smilec.smile.bu.exception.DataAccessException;
import org.smilec.smile.bu.json.CurrentMessageJSONParser;
+import org.smilec.smile.bu.json.IQSetJSONParser;
+import org.smilec.smile.bu.json.ResultsJSONParser;
import org.smilec.smile.domain.Board;
+import org.smilec.smile.domain.IQSet;
import org.smilec.smile.domain.LocalQuestionWrapper;
import org.smilec.smile.domain.Question;
+import org.smilec.smile.domain.Results;
import org.smilec.smile.domain.ServerQuestionWrapper;
import org.smilec.smile.util.HttpUtil;
import org.smilec.smile.util.IOUtil;
@@ -85,10 +90,12 @@ public void resetGame(String ip, Context context) throws NetworkErrorException {
}
- // XXX TODO: Add arguments to take Teacher Name, Session Name, and Group Name
+ /**
+ * Send the session ids (teacher name, session name, and group name) to smileplug server
+ */
public void createSession(String ip, String teacherName, String sessionTitle, String groupName, Context context) throws NetworkErrorException {
- String url = SmilePlugUtil.createUrl(ip, SmilePlugUtil.CREATE_SESSION);
+ String url = SmilePlugUtil.createUrl(ip, SmilePlugUtil.CREATE_SESSION_URL);
JSONObject jsonSessionValues = new JSONObject();
try {
@@ -104,6 +111,83 @@ public void createSession(String ip, String teacherName, String sessionTitle, St
put(ip,context,url,jsonSessionValues.toString());
}
+ /**
+ * @return a list of all iqsets available on smileplug server
+ */
+ public List getIQSets(String ip, Context context) throws NetworkErrorException {
+
+ String url = SmilePlugUtil.createUrl(ip, SmilePlugUtil.IQSETS_URL);
+
+ List iqsets = new ArrayList();
+
+ InputStream is = get(ip, context, url);
+
+ try {
+ String s = IOUtil.loadContent(is, "UTF-8");
+ iqsets = IQSetJSONParser.parseListOfIQSet(new JSONObject(s));
+
+ } catch (JSONException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } finally {
+ IOUtil.silentClose(is);
+ }
+
+ return iqsets;
+ }
+
+ /**
+ * This method is similar to this.getIQSets()
+ * but it just returns a String instead of a List of IQSet
+ * @param position position of the row in the list of IQSets
+ * @return the id of the iqset
+ */
+ public String getIdIQSetByPosition(String ip, Context context, int position) throws NetworkErrorException {
+
+ String id = new String();
+ String url = SmilePlugUtil.createUrl(ip, SmilePlugUtil.IQSETS_URL);
+ InputStream is = get(ip, context, url);
+
+ try {
+ String s = IOUtil.loadContent(is, "UTF-8");
+ id = IQSetJSONParser.getIdIQSetByPosition(new JSONObject(s), position);
+
+ } catch (JSONException e) { e.printStackTrace();
+ } catch (IOException e) { e.printStackTrace();
+ } finally { IOUtil.silentClose(is);
+ }
+ return id;
+ }
+
+ /**
+ * @return all the questions from a IQSet
+ */
+ public Collection getListOfQuestions(String ip, Context context, String idIQSet) throws NetworkErrorException {
+
+ Collection questions = new ArrayList();
+
+ String url = SmilePlugUtil.createUrl(ip, SmilePlugUtil.IQSET_URL+"/"+idIQSet);
+ InputStream is = get(ip, context, url);
+
+ try {
+ String s = IOUtil.loadContent(is, "UTF-8");
+ questions = IQSetJSONParser.parseIQSet(new JSONObject(s));
+
+ } catch (JSONException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } finally {
+ IOUtil.silentClose(is);
+ }
+ return questions;
+ }
+
public String currentMessageGame(String ip, Context context) throws NetworkErrorException {
String url = SmilePlugUtil.createUrl(ip, SmilePlugUtil.CURRENT_MESSAGE_URL);
diff --git a/src/main/java/org/smilec/smile/bu/json/IQSetJSONParser.java b/src/main/java/org/smilec/smile/bu/json/IQSetJSONParser.java
new file mode 100644
index 0000000..b89eaf9
--- /dev/null
+++ b/src/main/java/org/smilec/smile/bu/json/IQSetJSONParser.java
@@ -0,0 +1,105 @@
+package org.smilec.smile.bu.json;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.smilec.smile.domain.IQSet;
+import org.smilec.smile.domain.Question;
+
+public class IQSetJSONParser {
+
+ private static final String ALL_THE_IQSETS = "rows";
+ private static final String NUMBER_OF_IQSETS = "total_rows";
+ private static final String ID_OF_IQSET = "id";
+ private static final String KEY_OF_IQSET = "key";
+ private static final String VALUE_OF_IQSET = "value";
+
+ /**
+ * Used to parse the JSON request when we need to fill the ListView of all IQSet #UsingPreparedQuestions
+ *
+ */
+ public static final List parseListOfIQSet(JSONObject object) {
+
+ List iqsets = new ArrayList();
+
+ JSONArray rows = object.optJSONArray(ALL_THE_IQSETS);
+ int totalRows = object.optInt(NUMBER_OF_IQSETS);
+
+ for(int i=0; i parseIQSet(JSONObject object) {
+
+ Collection questions = new ArrayList();
+ JSONArray rows = object.optJSONArray("iqdata");
+
+ for(int i=0; i adapter;
+ //private File[] fileQuestionsList;
+ //private File fileQuestion;
+ //private ArrayAdapter adapter;
+
+ private List iqsets;
+ private IQSet iqset;
+ private IQSetListAdapter iqsetListAdapter;
private ListView lvListQuestions;
private Results results;
- private int item = 0;
+ private int currentPosition = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -119,6 +124,8 @@ protected void onResume() {
spinnerSeconds.setEnabled(false);
btClose.setOnClickListener(new CloseClickListenerUtil(this));
+
+
loadValuesTime();
@@ -219,9 +226,19 @@ private File[] getQuestions() throws DataAccessException {
private void loadQuestionsList() {
clearSelection();
- adapter = new FilesQuestionListAdapter(this, fileQuestionsList);
-
- lvListQuestions.setAdapter(adapter);
+ List iqsets = new ArrayList();
+ try {
+ iqsets = new SmilePlugServerManager().getIQSets(ip, UsePreparedQuestionsActivity.this);
+ } catch (NetworkErrorException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ //adapter = new FilesQuestionListAdapter(this, fileQuestionsList);
+ //lvListQuestions.setAdapter(adapter);
+ iqsetListAdapter = new IQSetListAdapter(UsePreparedQuestionsActivity.this, iqsets);
+ lvListQuestions.setAdapter(iqsetListAdapter);
+
lvListQuestions.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
lvListQuestions.setItemsCanFocus(false);
lvListQuestions.setOnItemClickListener(new ItemClickListener());
@@ -233,10 +250,10 @@ private class ItemClickListener implements OnItemClickListener {
public void onItemClick(AdapterView> arg0, View view, int position, long arg3) {
boolean itemChecked = lvListQuestions.isItemChecked(position);
- if (lvListQuestions.getCheckedItemPositions().size() > 1 && item != position) {
- lvListQuestions.setItemChecked(item, false);
+ if (lvListQuestions.getCheckedItemPositions().size() > 1 && currentPosition != position) {
+ lvListQuestions.setItemChecked(currentPosition, false);
}
- item = position;
+ currentPosition = position;
btOk.setEnabled(itemChecked);
cbQuestions.setClickable(itemChecked);
@@ -246,7 +263,8 @@ public void onItemClick(AdapterView> arg0, View view, int position, long arg3)
spinnerMinutes.setEnabled(false);
spinnerSeconds.setEnabled(false);
}
- fileQuestion = adapter.getItem(position);
+ //fileQuestion = adapter.getItem(position);
+ iqset = iqsetListAdapter.getItem(position);
}
}
@@ -262,7 +280,8 @@ private void clearSelection() {
public void onBackPressed() {
super.onBackPressed();
- if (fileQuestionsList.length == 0) {
+ //if (fileQuestionsList.length == 0) {
+ if (iqsets.size() == 0) {
Intent intent = new Intent(this, ChooseActivityFlowDialog.class);
intent.putExtra(GeneralActivity.PARAM_IP, ip);
intent.putExtra(GeneralActivity.PARAM_RESULTS, results);
@@ -273,9 +292,13 @@ public void onBackPressed() {
}
private class LoadBoardTask extends ProgressDialogAsyncTask {
+
+ private Context context;
public LoadBoardTask(Activity context) {
super(context);
+
+ this.context = context;
}
@Override
@@ -292,7 +315,7 @@ protected File[] doInBackground(Void... params) {
@Override
protected void onPostExecute(File[] fileQuestions) {
if (fileQuestions != null) {
- UsePreparedQuestionsActivity.this.fileQuestionsList = fileQuestions;
+ //UsePreparedQuestionsActivity.this.fileQuestionsList = fileQuestions;
UsePreparedQuestionsActivity.this.loadQuestionsList();
if (fileQuestions.length == 0) {
btOk.setEnabled(false);
@@ -316,13 +339,17 @@ public LoadTask(Activity context) {
this.context = context;
}
-
+
@Override
protected String doInBackground(Void... params) {
try {
Collection newQuestions = null;
- newQuestions = new QuestionsManager().loadQuestions(fileQuestion.getName());
-
+ //newQuestions = new QuestionsManager().loadQuestions(fileQuestion.getName());
+
+ String idCheckedIQSet = new SmilePlugServerManager().getIdIQSetByPosition(ip, context, currentPosition);
+
+ newQuestions = new SmilePlugServerManager().getListOfQuestions(ip, context, idCheckedIQSet);
+
new SmilePlugServerManager().startUsingPreparedQuestions(ip, context, newQuestions);
return "";
diff --git a/src/main/java/org/smilec/smile/ui/adapter/FilesQuestionListAdapter.java b/src/main/java/org/smilec/smile/ui/adapter/FilesQuestionListAdapter.java
index c1119c4..71d67bf 100644
--- a/src/main/java/org/smilec/smile/ui/adapter/FilesQuestionListAdapter.java
+++ b/src/main/java/org/smilec/smile/ui/adapter/FilesQuestionListAdapter.java
@@ -26,27 +26,30 @@
import android.widget.ArrayAdapter;
import android.widget.TextView;
-public class FilesQuestionListAdapter extends ArrayAdapter {
-
- public FilesQuestionListAdapter(Context context, File[] items) {
- super(context, 0, items);
- }
-
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
-
- final File fileQuestion = getItem(position);
-
- if (convertView == null) {
- Context context = getContext();
- LayoutInflater inflater = (LayoutInflater) context
- .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- convertView = inflater.inflate(R.layout.use_prepared_questions_item, parent, false);
- }
-
- final TextView tvFileName = (TextView) convertView.findViewById(R.id.tv_file_name);
- tvFileName.setText(String.valueOf(fileQuestion.getName()));
-
- return convertView;
- }
-}
+// This class was previously used to get lists of questions in local files
+// Replaced by IQSetListAdapter.java
+
+//public class FilesQuestionListAdapter extends ArrayAdapter {
+//
+// public FilesQuestionListAdapter(Context context, File[] items) {
+// super(context, 0, items);
+// }
+//
+// @Override
+// public View getView(int position, View convertView, ViewGroup parent) {
+//
+// final File fileQuestion = getItem(position);
+//
+// if (convertView == null) {
+// Context context = getContext();
+// LayoutInflater inflater = (LayoutInflater) context
+// .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+// convertView = inflater.inflate(R.layout.use_prepared_questions_item, parent, false);
+// }
+//
+// final TextView tvFileName = (TextView) convertView.findViewById(R.id.tv_file_name);
+// tvFileName.setText(String.valueOf(fileQuestion.getName()));
+//
+// return convertView;
+// }
+//}
diff --git a/src/main/java/org/smilec/smile/ui/adapter/IQSetListAdapter.java b/src/main/java/org/smilec/smile/ui/adapter/IQSetListAdapter.java
new file mode 100644
index 0000000..091629d
--- /dev/null
+++ b/src/main/java/org/smilec/smile/ui/adapter/IQSetListAdapter.java
@@ -0,0 +1,53 @@
+package org.smilec.smile.ui.adapter;
+
+import java.util.List;
+
+import org.smilec.smile.R;
+import org.smilec.smile.domain.IQSet;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.TextView;
+
+/*
+ * This class is only used to fill the ListView in use_prepared_questions_dialog.xml
+ * with the following values: http:///smile/iqsets
+ *
+ * */
+public class IQSetListAdapter extends ArrayAdapter {
+
+ // We load the list of iqsets to retrieve the values in getView(,,)
+ public IQSetListAdapter(Context context,List iqsets) {
+
+ super(context, 0, iqsets);
+ }
+
+ // This method will be executed for each row
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+
+ final IQSet iqset = getItem(position);
+
+ if (convertView == null) {
+ Context context = getContext();
+ LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ convertView = inflater.inflate(R.layout.use_prepared_questions_item, parent, false);
+ }
+
+ if (iqset != null) {
+ TextView tvSessionTitle = (TextView) convertView.findViewById(R.id.tv_file_name);
+ tvSessionTitle.setText(iqset.getSessionTitle());
+
+ TextView tvTeacherName = (TextView) convertView.findViewById(R.id.tv_teacher_name);
+ tvTeacherName.setText(iqset.getTeacherName());
+
+ TextView tvGroupName = (TextView) convertView.findViewById(R.id.tv_group_name);
+ tvGroupName.setText(String.valueOf(iqset.getGroupName()));
+ }
+
+ return convertView;
+ }
+}
diff --git a/src/main/java/org/smilec/smile/util/SmilePlugUtil.java b/src/main/java/org/smilec/smile/util/SmilePlugUtil.java
index 276eab1..1d7bfaf 100644
--- a/src/main/java/org/smilec/smile/util/SmilePlugUtil.java
+++ b/src/main/java/org/smilec/smile/util/SmilePlugUtil.java
@@ -33,7 +33,9 @@ public class SmilePlugUtil {
public static final String RESULTS_URL = "results";
public static final String RESET_URL = "reset";
public static final String CURRENT_MESSAGE_URL = "currentmessage";
- public static final String CREATE_SESSION = "createsession";
+ public static final String CREATE_SESSION_URL = "createsession";
+ public static final String IQSETS_URL = "iqsets";
+ public static final String IQSET_URL = "iqset";
public static final String JSON = "application/json";
public static final String FORM = "application/x-www-form-urlencoded";