diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index 2cbb09b..3068cd4 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -6,6 +6,7 @@
+
-
-
+
\ No newline at end of file
diff --git a/Testapp.iml b/Testapp.iml
index 0bb6048..7b5baab 100644
--- a/Testapp.iml
+++ b/Testapp.iml
@@ -1,9 +1,10 @@
-
+
+
@@ -15,5 +16,4 @@
-
-
+
\ No newline at end of file
diff --git a/app/app.iml b/app/app.iml
index 51d3395..b059125 100644
--- a/app/app.iml
+++ b/app/app.iml
@@ -1,5 +1,5 @@
-
+
@@ -12,8 +12,9 @@
-
+
+
@@ -89,5 +90,4 @@
-
-
+
\ No newline at end of file
diff --git a/app/src/main/java/com/example/raffaele/testapp/Query.java b/app/src/main/java/com/example/raffaele/testapp/Query.java
index afc181f..84084a6 100644
--- a/app/src/main/java/com/example/raffaele/testapp/Query.java
+++ b/app/src/main/java/com/example/raffaele/testapp/Query.java
@@ -1,5 +1,9 @@
package com.example.raffaele.testapp;
+import android.os.Parcel;
+import android.os.Parcelable;
+import android.util.Log;
+
import java.util.ArrayList;
import java.util.Collections;
@@ -12,13 +16,24 @@
* @author K12-Dev-Team
* @version 0.1
*/
-public class Query {
+public class Query implements Parcelable {
private String id_domanda;
private String Domanda;
private String Risposta;
private ArrayList Risposteprob;
private String topic;
+ public static final Parcelable.Creator CREATOR= new Parcelable.Creator(){
+ @Override
+ public Query createFromParcel(Parcel in){
+ return new Query(in);
+ }
+
+ @Override
+ public Query[] newArray(int size) {
+ return new Query[size];
+ }
+ };
/**
* Costruttore della classe Domanda
* @param id_domanda Id della domanda
@@ -36,7 +51,13 @@ public Query(final String id_domanda,final String domanda,final String risposta,
setRispostarray(rispostaf1, rispostaf2, rispostaf3, risposta);
setTopic(topic);
}
-
+ /**
+ *
+ * @param in oggetto parceable da convertire
+ */
+ private Query(Parcel in ){
+ readFromParcel(in);
+ }
/**
* Costruttore Vuoto
*/
@@ -44,7 +65,7 @@ public Query(){
setid_domanda("");
setDomanda("");
setRisposta("");
- setRispostarray("","","","");
+ setRispostarray("", "", "", "");
}
public Query(String domanda){
setid_domanda("");
@@ -117,9 +138,8 @@ public ArrayList getRisposteprob() {
/**
* @param risposteprob Imposta le risposte probabili
*/
- @SuppressWarnings({"unchecked"})
- public void setRisposteprob(final ArrayList risposteprob) {
- Risposteprob = (ArrayList) risposteprob.clone();
+ public void setRisposteprob(ArrayList risposteprob) {
+ this.Risposteprob =risposteprob;
}
/**
@@ -157,4 +177,40 @@ private void setTopic(String topic) {
public void RandomQuery(){
Collections.shuffle(this.Risposteprob);
}
+
+ /**
+ * Metodo di default dell'interfaccia parcel
+ * @return 0
+ */
+
+ /**
+ *
+ * @param in Riceve in ingresso una domanda parcellizzata e imposta i membri privati con i parametri del parcel attraverso il readString
+ */
+ private void readFromParcel(Parcel in) {
+ setid_domanda(in.readString());
+ setDomanda(in.readString());
+ setRisposta(in.readString());
+ setRisposteprob(in.createStringArrayList());
+ //Log.d("TeacherQuestionresult", Risposteprob.get(3));
+ setTopic(in.readString());
+ }
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ /**
+ * Metodo di scrittura del parcel
+ * @param dest Parcel di destinazione
+ * @param flags (optional)
+ */
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeString(id_domanda);
+ dest.writeString(Domanda);
+ dest.writeString(Risposta);
+ dest.writeStringList(Risposteprob);
+ dest.writeString(topic);
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/raffaele/testapp/QueryList.java b/app/src/main/java/com/example/raffaele/testapp/QueryList.java
new file mode 100644
index 0000000..77c645b
--- /dev/null
+++ b/app/src/main/java/com/example/raffaele/testapp/QueryList.java
@@ -0,0 +1,77 @@
+package com.example.raffaele.testapp;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+import android.util.Log;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.util.LinkedList;
+
+/**
+ * Created by K12-Dev-Team on 29/04/2015.
+ */
+public class QueryList extends LinkedList implements Parcelable {
+ private final String url = "https://k12-api.mybluemix.net/api/questionnaire/view"; //Url di connessione al backend
+ public static final Parcelable.Creator CREATOR= new Parcelable.Creator(){ //creatore dell'argumentlist
+ @Override
+ public QueryList createFromParcel(Parcel in){
+ return new QueryList(in);
+ }
+
+ @Override
+ public QueryList[] newArray(int size) {return new QueryList[0];
+ }
+ };
+ private String idquiz;
+
+ public QueryList(String idquiz){
+ this.idquiz=idquiz;
+ }
+ public void getHTTP(String token) throws NullPointerException {
+ this.clear(); //pulisce la lista per sicurezza
+ HTMLRequest htmlRequest =new HTMLRequest(url, "access_token=" + token+"&id="+idquiz); //richiesta con token
+ String result=htmlRequest.getHTMLThread();
+ Log.d("QueryList", idquiz); //loggo per scopi di debug
+ Log.d("TeacherQuestionresult", result);
+ try{
+ JSONObject jo= new JSONObject(result); //elaboro l'array di json e aggiungo gli elementi alla lista
+ if(jo.has("success")&&!jo.getBoolean("success")){
+ throw new NullPointerException("QuizNull");
+ }
+ JSONArray ja=jo.getJSONArray("questions");
+ for(int i=0;i queries;
private ArgumentList argumentList=new ArgumentList();
private ScoreManager scoreManager=null;
private final DrawableManager draw=new DrawableManager();
@@ -61,8 +66,11 @@ protected void onCreate(Bundle savedInstanceState) {
Intent i = getIntent();
Bundle extras=i.getExtras();
this.utente = extras.getParcelable("utentec");
- if(extras.getParcelable("argomenti")!=null)
+ if(i.hasExtra("argomenti"))
this.argumentList=extras.getParcelable("argomenti");
+ if(i.hasExtra("quiz")){
+ queries= extras.getParcelable("quiz");
+ }
this.token = this.utente.getAccessToken();
setContentView(R.layout.activity_question);
toastview=getLayoutInflater().inflate(R.layout.toastlayout, (ViewGroup)findViewById(R.id.toastlayout));
@@ -125,6 +133,9 @@ public void impostafont(){
/**
* Recupera la domanda dal backend
* @return Domanda dal backend
+ * @throws NullPointerException Null Query
+ * @see NullPointerException
+ * @see HTMLRequest
*/
public Query request_data() {
Query Domand = new Query();
@@ -133,16 +144,12 @@ public Query request_data() {
HTMLRequest htmlRequest = new HTMLRequest(this.api, "access_token=" + this.token +"&topics="+this.argumentList.toString());
try {
result = htmlRequest.getHTMLThread();
- if(result!=null) {
- jo = new JSONObject(result);
- Domand = new Query(jo.getString("id"), jo.getString("body"), jo.getString("answer"), jo.getString("fakeAnswer1"), jo.getString("fakeAnswer2"), jo.getString("fakeAnswer3"), jo.getString("topic"));
- Log.d("id", jo.getString("id"));
- Log.d("topic", jo.getString("topic"));
- } else{
- Domand=new Query("There are not more question");
- }
+ jo = new JSONObject(result);
+ Domand = new Query(jo.getString("id"), jo.getString("body"), jo.getString("answer"), jo.getString("fakeAnswer1"), jo.getString("fakeAnswer2"), jo.getString("fakeAnswer3"), jo.getString("topic"));
+ Log.d("id", jo.getString("id"));
+ Log.d("topic", jo.getString("topic"));
} catch (Exception e) {
- e.printStackTrace();
+ throw new NullPointerException("NullQuery");
}
return Domand;
}
@@ -206,9 +213,26 @@ public boolean onOptionsItemSelected(MenuItem item) {
* Procedura di cambio domanda
*/
public void cambiadomanda(){
- this.Domanda = new Query(request_data());
- this.Domanda.RandomQuery();
- impostabottoni();
+ try {
+ if (queries != null) {
+ this.Domanda = queries.remove();
+ }
+ else {
+ this.Domanda = new Query(request_data());
+ }
+ this.Domanda.RandomQuery();
+ }
+ catch (NoSuchElementException e) {
+ this.Domanda=new Query("Quiz Completed! Good Job :)");
+ Log.d("QuestionHandler","QuizCompleted");
+ }
+ catch (NullPointerException e){
+ this.Domanda=new Query("There are not more question");
+ Log.d("QuestionHandler","NoMoreQuestion");
+ }
+ finally {
+ impostabottoni();
+ }
}
/**
diff --git a/app/src/main/java/com/example/raffaele/testapp/Questionnaire.java b/app/src/main/java/com/example/raffaele/testapp/Questionnaire.java
index 8e99b28..849280e 100644
--- a/app/src/main/java/com/example/raffaele/testapp/Questionnaire.java
+++ b/app/src/main/java/com/example/raffaele/testapp/Questionnaire.java
@@ -1,29 +1,31 @@
package com.example.raffaele.testapp;
/**
- * Created by Muscetti on 25/04/2015.
+ * Created by K12-Dev-Team on 25/04/2015.
*/
public class Questionnaire {
- private String Name;
- private String Description;
- public String getName() {
- return Name;
+ private String id;
+ private String name;
+
+ public String getId() {
+ return id;
}
- public void setName(String name) {
- Name = name;
+ public void setId(String id) {
+ this.id = id;
}
- public String getDescription() {
- return Description;
+ public String getname() {
+ return name;
}
- public void setDescription(String description) {
- Description = description;
+ public void setname(String name) {
+ this.name = name;
}
- public Questionnaire(String name) {
- Name = name;
+ public Questionnaire(String id,String name) {
+ this.name = name;
+ this.id=id;
}
}
diff --git a/app/src/main/java/com/example/raffaele/testapp/QuestionnaireList.java b/app/src/main/java/com/example/raffaele/testapp/QuestionnaireList.java
new file mode 100644
index 0000000..8b9cdfc
--- /dev/null
+++ b/app/src/main/java/com/example/raffaele/testapp/QuestionnaireList.java
@@ -0,0 +1,33 @@
+package com.example.raffaele.testapp;
+
+import android.util.Log;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.util.ArrayList;
+
+/**
+ *
+ * Created by K12-Dev-Team on 02/05/2015.
+ */
+public class QuestionnaireList extends ArrayList {
+ private final String url = "http://k12-api.mybluemix.net/api/questionnaire/list";
+ public void getHttp(String token) { //metodo di richiesta al backend
+ this.clear(); //pulisce la lista per sicurezza
+ HTMLRequest htmlRequest = new HTMLRequest(url, "access_token=" + token); //richiesta con token
+ String result = htmlRequest.getHTMLThread();
+ Log.d("token", token); //loggo il token per scopi di debug
+ try {
+ JSONArray ja = new JSONArray(result); //elaboro l'array di json e aggiungo gli elementi alla lista
+ JSONObject jo;
+ for (int i = 0; i < ja.length(); i++) {
+ jo = ja.getJSONObject(i);
+ this.add(new Questionnaire(jo.getString("id"), jo.getString("name")));
+ }
+ } catch (JSONException e) {
+ e.printStackTrace(); //in caso di eccezzioni stampo la lista chiamate (Le eccezzioni json non sono recuperabili ma non impediscono il continuo dell'esecuzione)
+ }
+ }
+}
diff --git a/app/src/main/java/com/example/raffaele/testapp/TeacherQuestion.java b/app/src/main/java/com/example/raffaele/testapp/TeacherQuestion.java
index 250b844..45dc560 100644
--- a/app/src/main/java/com/example/raffaele/testapp/TeacherQuestion.java
+++ b/app/src/main/java/com/example/raffaele/testapp/TeacherQuestion.java
@@ -3,8 +3,6 @@
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
-import android.os.Parcelable;
-import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
@@ -12,27 +10,20 @@
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
-import android.widget.AdapterView;
import android.widget.ArrayAdapter;
-import android.widget.CheckBox;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-
import java.util.ArrayList;
public class TeacherQuestion extends Activity {
- private final String url = "http://k12-api.mybluemix.net/api/questionnaire/list";
- private ArrayList listaquestionari = new ArrayList();
+ private QuestionnaireList listaquestionari = new QuestionnaireList();
private User utente;
- private String token = "";
+ private static String token;
private AdapterCustom dataAdapter = null;
-
+ private QueryList teacherQuestionList=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -40,7 +31,8 @@ protected void onCreate(Bundle savedInstanceState) {
Intent i = getIntent();
Bundle extras=i.getExtras();
this.utente = extras.getParcelable("utentec"); //riceve da welcome l'utente
- this.getHttp(this.utente.getAccessToken());
+ token=this.utente.getAccessToken();
+ this.listaquestionari.getHttp(token);
displayListView();
}
@@ -67,39 +59,32 @@ public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}
-
- public void getHttp(String token) { //metodo di richiesta al backend
- listaquestionari.clear(); //pulisce la lista per sicurezza
- HTMLRequest htmlRequest = new HTMLRequest(url, "access_token=" + token); //richiesta con token
- String result = htmlRequest.getHTMLThread();
- Log.d("token", token); //loggo il token per scopi di debug
+ public void onQuizSelect(View view){
+ String quiz=((TextView)view).getHint().toString();
+ teacherQuestionList =new QueryList(quiz);
try {
- JSONArray ja = new JSONArray(result); //elaboro l'array di json e aggiungo gli elementi alla lista
- JSONObject jo;
- for (int i = 0; i < ja.length(); i++) {
- jo = ja.getJSONObject(i);
- listaquestionari.add(new Questionnaire(jo.getString("name")));
- }
- } catch (JSONException e) {
- e.printStackTrace(); //in caso di eccezzioni stampo la lista chiamate (Le eccezzioni json non sono recuperabili ma non impediscono il continuo dell'esecuzione)
+ teacherQuestionList.getHTTP(token);
+ Toast.makeText(getApplicationContext(), "Selected: " + ((TextView)view).getText().toString(), Toast.LENGTH_LONG).show();
+ Intent i=new Intent(this,Question.class);
+ Bundle extras=new Bundle();
+ extras.putParcelable("utentec", this.utente);
+ extras.putParcelable("quiz",this.teacherQuestionList);
+ extras.putString("idquiz", quiz);
+ i.putExtras(extras);
+ startActivity(i);
+ } catch (NullPointerException e) {
+ Toast.makeText(getApplicationContext(), "No question available for this quiz!", Toast.LENGTH_LONG).show();
}
}
+
+
private void displayListView() {
//Array list di Argomenti
dataAdapter = new AdapterCustom(this,R.layout.list_item1, listaquestionari);
ListView listView = (ListView) findViewById(R.id.listView2);
// Assegna l'adapter alla listview
listView.setAdapter(dataAdapter);
-
- listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- public void onItemClick(AdapterView> parent, View view, int pos, long id) {
- // Mostra una toast quando checka
- Questionnaire questlist = (Questionnaire) parent.getItemAtPosition(pos);
- Toast.makeText(getApplicationContext(), "Selected: " + questlist.getName(), Toast.LENGTH_LONG).show();
- }
- });
-
}
/**
@@ -129,12 +114,13 @@ public View getView(int position, View convertView, ViewGroup parent) {
textcheck = (TextCheck) convertView.getTag();
}
Questionnaire listquest = listaquestionari.get(position); //ritorna la posizione dell' elemento selezionato
- textcheck.code.setText(listquest.getName());
+ textcheck.code.setText(listquest.getname());
+ textcheck.code.setHint(listquest.getId());
return convertView;
}
- private ArrayList listaquestionari = null;
+ private QuestionnaireList listaquestionari = null;
/**
* @param context Context dell'applicazione
@@ -143,7 +129,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
*/
public AdapterCustom(Context context, int textViewResourceId, ArrayList questList) {
super(context, textViewResourceId, questList); //costruttore della superclasse
- listaquestionari = new ArrayList();
+ listaquestionari = new QuestionnaireList();
listaquestionari.addAll(questList); //aggiunta degli elementi alla arraylist
}
diff --git a/app/src/main/java/com/example/raffaele/testapp/TeacherQuestionList.java b/app/src/main/java/com/example/raffaele/testapp/TeacherQuestionList.java
deleted file mode 100644
index d60141f..0000000
--- a/app/src/main/java/com/example/raffaele/testapp/TeacherQuestionList.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package com.example.raffaele.testapp;
-
-import android.os.Parcel;
-import android.os.Parcelable;
-
-import java.util.ArrayList;
-
-/**
- * Created by Filippo on 29/04/2015.
- */
-public class TeacherQuestionList extends ArrayList implements Parcelable {
- public static final Parcelable.Creator CREATOR= new Parcelable.Creator(){ //creatore dell'argumentlist
- @Override
- public TeacherQuestionList createFromParcel(Parcel in){
- return new TeacherQuestionList(in);
- }
-
- @Override
- public TeacherQuestionList[] newArray(int size) {return new TeacherQuestionList[0];
- }
- };
- public TeacherQuestionList(){
- super();
- } //costruttore vuoto
-
- /**
- * @param in Parcel di ingresso
- */
- private TeacherQuestionList(Parcel in ){
- readFromParcel(in);
- } //Costruttore della parceable
-
- /**
- * @param in Parcel di ingresso
- */
- public void readFromParcel(Parcel in){
- this.clear(); //pulisce la lista per sicurezza
- in.readList(this,TeacherQuestionList.class.getClassLoader()); //riempie la lista con gli elementi dal parceable
- }
-
- @Override
- public int describeContents() {
- return 0;
- }
-
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- dest.writeList(this);
- }
-}
diff --git a/app/src/main/java/com/example/raffaele/testapp/Welcome_student.java b/app/src/main/java/com/example/raffaele/testapp/Welcome_student.java
index d67f145..be86d40 100644
--- a/app/src/main/java/com/example/raffaele/testapp/Welcome_student.java
+++ b/app/src/main/java/com/example/raffaele/testapp/Welcome_student.java
@@ -26,6 +26,7 @@ public class Welcome_student extends ActionBarActivity {
private User utente;
private ArgumentList argumentList;
private static final int MSG_SAVE_SCORE_REQUEST = 1;
+ private AlertDialog alertDialog;
/**
* Creatore della vista
@@ -102,31 +103,12 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
*/
public void opendialog(View view){
LayoutInflater linf = LayoutInflater.from(this);
- final View inflator =linf.inflate(R.layout.dialog_question_select,null);
- AlertDialog.Builder alertDialogBuilder=new AlertDialog.Builder(this);
+ final View inflator =linf.inflate(R.layout.dialog_question_select, null);
+ AlertDialog.Builder alertDialogBuilder;
+ alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setTitle("Select the type of Question");
alertDialogBuilder.setView(inflator);
- /*alertDialogBuilder
- .setPositiveButton("Submit", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int id) {
- String question = editText.getText().toString().trim();
- HTMLRequest htmlRequest = new HTMLRequest(apiDoc, "idquestion=" + id_question + "&question=" + question + "&user" + utente.getUsername() + "&access_token" + utente.getAccessToken());
- if (Boolean.valueOf(htmlRequest.getHTMLThread())) {
- Toast.makeText(getApplicationContext(), "Question Sent", Toast.LENGTH_SHORT).show();
- } else {
- Toast.makeText(getApplicationContext(), "Error: Question not Sent", Toast.LENGTH_SHORT).show();
- }
- dialog.dismiss();
- }
- })
- .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- dialog.dismiss();
- }
- });
- */
- AlertDialog alertDialog = alertDialogBuilder.create();
+ alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
//richiamo view Question
@@ -158,21 +140,18 @@ public void toChat(View v) {
public void toArgument(View v) {
Intent i = new Intent(this, Argument_Page.class);
Bundle extras=new Bundle();
- //passo l'oggetto user alla prossima view
- /*if(argumentList!=null){
- extras.putParcelable("argomenti",this.argumentList);
- }
- */
extras.putParcelable("utentec",this.utente);
i.putExtras(extras);
+ alertDialog.dismiss();
startActivity(i);
}
public void TeacherQuestion (View v) {
Intent i = new Intent(this, TeacherQuestion.class);
Bundle extras=new Bundle();
- extras.putParcelable("utentec",this.utente);
+ extras.putParcelable("utentec", this.utente);
i.putExtras(extras);
+ alertDialog.dismiss();
startActivity(i);
}
diff --git a/app/src/main/res/layout/list_item1.xml b/app/src/main/res/layout/list_item1.xml
index c15ea88..0705d9b 100644
--- a/app/src/main/res/layout/list_item1.xml
+++ b/app/src/main/res/layout/list_item1.xml
@@ -10,5 +10,6 @@
android:layout_height="wrap_content"
android:text="TextView"
android:clickable="true"
- android:textSize="30sp" />
+ android:textSize="30sp"
+ android:onClick="onQuizSelect" />