Skip to content

Commit

Permalink
Aggiunto scaricamento e passaggio domande a question tramite coda e s…
Browse files Browse the repository at this point in the history
…eparata classe questionnairelist
  • Loading branch information
raffysommy committed May 1, 2015
1 parent 9105a1c commit d94baa1
Show file tree
Hide file tree
Showing 12 changed files with 268 additions and 160 deletions.
4 changes: 2 additions & 2 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Testapp.iml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<module external.linked.project.id="Testapp" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="java-gradle" name="Java-Gradle">
<configuration>
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
<option name="BUILDABLE" value="false" />
</configuration>
</facet>
</component>
Expand All @@ -15,5 +16,4 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

</module>
8 changes: 4 additions & 4 deletions app/app.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="Testapp" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="Testapp" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
Expand All @@ -12,8 +12,9 @@
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugAndroidTest" />
<option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugAndroidTest" />
<option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugAndroidTestSources" />
<option name="TEST_SOURCE_GEN_TASK_NAME" value="generateDebugAndroidTestSources" />
<option name="ALLOW_USER_CONFIGURATION" value="false" />
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
Expand Down Expand Up @@ -89,5 +90,4 @@
<orderEntry type="library" exported="" name="support-v4-21.0.3" level="project" />
<orderEntry type="library" exported="" name="support-annotations-21.0.3" level="project" />
</component>
</module>

</module>
68 changes: 62 additions & 6 deletions app/src/main/java/com/example/raffaele/testapp/Query.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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<String> Risposteprob;
private String topic;
public static final Parcelable.Creator<Query> CREATOR= new Parcelable.Creator<Query>(){
@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
Expand All @@ -36,15 +51,21 @@ 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
*/
public Query(){
setid_domanda("");
setDomanda("");
setRisposta("");
setRispostarray("","","","");
setRispostarray("", "", "", "");
}
public Query(String domanda){
setid_domanda("");
Expand Down Expand Up @@ -117,9 +138,8 @@ public ArrayList<String> getRisposteprob() {
/**
* @param risposteprob Imposta le risposte probabili
*/
@SuppressWarnings({"unchecked"})
public void setRisposteprob(final ArrayList<String> risposteprob) {
Risposteprob = (ArrayList<String>) risposteprob.clone();
public void setRisposteprob(ArrayList<String> risposteprob) {
this.Risposteprob =risposteprob;
}

/**
Expand Down Expand Up @@ -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);
}
}
77 changes: 77 additions & 0 deletions app/src/main/java/com/example/raffaele/testapp/QueryList.java
Original file line number Diff line number Diff line change
@@ -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<Query> implements Parcelable {
private final String url = "https://k12-api.mybluemix.net/api/questionnaire/view"; //Url di connessione al backend
public static final Parcelable.Creator<QueryList> CREATOR= new Parcelable.Creator<QueryList>(){ //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<ja.length();i++){
jo=ja.getJSONObject(i);
this.add(new Query(jo.getString("id"), jo.getString("body"), jo.getString("answer"), jo.getString("fakeAnswer1"), jo.getString("fakeAnswer2"), jo.getString("fakeAnswer3"), jo.getString("topic")));
}
} catch (JSONException e) {
throw new NullPointerException("QuizNull");
}
}
/**
* @param in Parcel di ingresso
*/
private QueryList(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,QueryList.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);
}
}
50 changes: 37 additions & 13 deletions app/src/main/java/com/example/raffaele/testapp/Question.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@

import org.json.JSONObject;

import java.util.LinkedList;
import java.util.NoSuchElementException;
import java.util.Queue;

/**
* @author K12-Dev-Team
* @version 0.4
Expand All @@ -36,6 +40,7 @@ public class Question extends ActionBarActivity {
private final String api = "https://k12-api.mybluemix.net/api/question/random";
private final String apiDoc="https://k12-api.mybluemix.net/api/teacher/help";
private User utente;
private Queue<Query> queries;
private ArgumentList argumentList=new ArgumentList();
private ScoreManager scoreManager=null;
private final DrawableManager draw=new DrawableManager();
Expand All @@ -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));
Expand Down Expand Up @@ -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();
Expand All @@ -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;
}
Expand Down Expand Up @@ -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();
}
}

/**
Expand Down
28 changes: 15 additions & 13 deletions app/src/main/java/com/example/raffaele/testapp/Questionnaire.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Loading

0 comments on commit d94baa1

Please sign in to comment.