diff --git a/res/layout-large-land/iqset_details.xml b/res/layout-large-land/iqset_details.xml new file mode 100644 index 0000000..93482d0 --- /dev/null +++ b/res/layout-large-land/iqset_details.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + diff --git a/res/layout-large-land/preview_iqset_item.xml b/res/layout-large-land/preview_iqset_item.xml new file mode 100644 index 0000000..2699558 --- /dev/null +++ b/res/layout-large-land/preview_iqset_item.xml @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/layout-large-land/questions_item.xml b/res/layout-large-land/questions_item.xml index 9c1385d..e9147ae 100644 --- a/res/layout-large-land/questions_item.xml +++ b/res/layout-large-land/questions_item.xml @@ -1,7 +1,6 @@ + + + android:textColor="@color/pink" /> - + Complete Question QUESTION + IQSET Students diff --git a/src/main/java/org/smilec/smile/domain/IQSet.java b/src/main/java/org/smilec/smile/domain/IQSet.java index 9ccf1a4..bcaca01 100644 --- a/src/main/java/org/smilec/smile/domain/IQSet.java +++ b/src/main/java/org/smilec/smile/domain/IQSet.java @@ -3,6 +3,7 @@ import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.Collection; import java.util.Date; import java.util.Locale; @@ -15,6 +16,7 @@ public class IQSet { private String sessionTitle; private String teacherName; private String groupName; + private Collection questions; public IQSet() { } @@ -80,4 +82,11 @@ public String getGroupName() { public void setGroupName(String groupName) { this.groupName = groupName; } + + public Collection getQuestions() { + return questions; + } + public void setQuestions(Collection questions) { + this.questions = questions; + } } diff --git a/src/main/java/org/smilec/smile/ui/UsePreparedQuestionsActivity.java b/src/main/java/org/smilec/smile/ui/UsePreparedQuestionsActivity.java index 3ef316b..cf454fc 100644 --- a/src/main/java/org/smilec/smile/ui/UsePreparedQuestionsActivity.java +++ b/src/main/java/org/smilec/smile/ui/UsePreparedQuestionsActivity.java @@ -18,6 +18,7 @@ import java.io.File; import java.util.ArrayList; import java.util.Collection; +import java.util.Comparator; import java.util.List; import org.smilec.smile.R; @@ -29,6 +30,7 @@ import org.smilec.smile.domain.Question; import org.smilec.smile.domain.Results; import org.smilec.smile.ui.adapter.IQSetListAdapter; +import org.smilec.smile.ui.adapter.QuestionListAdapter; import org.smilec.smile.util.ActivityUtil; import org.smilec.smile.util.CloseClickListenerUtil; import org.smilec.smile.util.DialogUtil; @@ -72,9 +74,11 @@ public class UsePreparedQuestionsActivity extends ListActivity { private String ip; private String status; - private List iqsets; +// private List iqsets; private IQSet iqset; private IQSetListAdapter iqsetListAdapter; + +// private ArrayAdapter previewIQSetAdapter; private ListView lvListQuestions; private Results results; @@ -154,35 +158,41 @@ private void loadValuesTime() { spinnerSeconds.setAdapter(adapterSeconds); } + /** + * Listener on the button to load iqsets + */ private class LoadButtonListener implements OnClickListener { @Override public void onClick(View v) { - if (status != null) { - Log.d("SMILE Teacher", "Status = " + status); - if (!status.equals("") && !status.equals("START_MAKE")) { - AlertDialog.Builder builder = new AlertDialog.Builder( - UsePreparedQuestionsActivity.this); - builder.setMessage(R.string.game_running).setCancelable(false) + + if (status != null && !status.equals("") && !status.equals("START_MAKE")) { + + Log.d("SMILE Teacher", "Status = " + status); + + AlertDialog.Builder builder = new AlertDialog.Builder(UsePreparedQuestionsActivity.this); + + builder.setMessage(R.string.game_running).setCancelable(false) .setNeutralButton("Ok", new DialogInterface.OnClickListener() { - @Override + + @Override public void onClick(DialogInterface dialog, int id) { new LoadTask(UsePreparedQuestionsActivity.this).execute(); } }); AlertDialog alert = builder.create(); alert.show(); - } else { - new LoadTask(UsePreparedQuestionsActivity.this).execute(); - } + } else { new LoadTask(UsePreparedQuestionsActivity.this).execute(); } ActivityUtil.showLongToast(UsePreparedQuestionsActivity.this, R.string.toast_starting); } - } + /** + * Listener on the checkbox enable/disable timer + */ private class CbQuestionsButtonListener implements OnClickListener { @Override @@ -199,34 +209,20 @@ public void onClick(View v) { } } - private void openGeneralActivity() { - Intent intent = new Intent(this, GeneralActivity.class); - intent.putExtra(GeneralActivity.PARAM_IP, ip); - intent.putExtra(GeneralActivity.PARAM_RESULTS, results); - intent.putExtra(GeneralActivity.PARAM_STATUS, status); - intent.putExtra(GeneralActivity.PARAM_HOURS, spinnerHours.getSelectedItem().toString()); - intent.putExtra(GeneralActivity.PARAM_MINUTES, spinnerMinutes.getSelectedItem().toString()); - intent.putExtra(GeneralActivity.PARAM_SECONDS, spinnerSeconds.getSelectedItem().toString()); - startActivity(intent); - - ActivityUtil.showLongToast(this, R.string.toast_starting); - - this.finish(); - } - + private File[] getQuestions() throws DataAccessException { return new QuestionsManager().getSavedQuestions(); } - private void loadQuestionsList() { + private void loadIQSets() { clearSelection(); List iqsets = new ArrayList(); - try { - iqsets = new SmilePlugServerManager().getIQSets(ip, UsePreparedQuestionsActivity.this); - } catch (NetworkErrorException e) { - e.printStackTrace(); - } + + try + { iqsets = new SmilePlugServerManager().getIQSets(ip, UsePreparedQuestionsActivity.this); } + catch (NetworkErrorException e) + { e.printStackTrace(); } iqsetListAdapter = new IQSetListAdapter(UsePreparedQuestionsActivity.this, iqsets,ip); lvListQuestions.setAdapter(iqsetListAdapter); @@ -295,24 +291,18 @@ protected File[] doInBackground(Void... params) { return null; } - /* - * File[] fileQuestions contains the 4 preloaded local files, but this is not used anymore - * and it is replaced by the iqsets - */ @Override protected void onPostExecute(File[] fileQuestions) { boolean iqsetsExist = false; - try { - iqsetsExist = new SmilePlugServerManager().iqsetsExist(ip, context); - } catch (NetworkErrorException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + try + {iqsetsExist = new SmilePlugServerManager().iqsetsExist(ip, context); } + catch (NetworkErrorException e) + { e.printStackTrace(); } if (iqsetsExist) { - UsePreparedQuestionsActivity.this.loadQuestionsList(); + UsePreparedQuestionsActivity.this.loadIQSets(); } else { btOk.setEnabled(false); @@ -362,4 +352,19 @@ protected void onPostExecute(String message) { } } } + + private void openGeneralActivity() { + Intent intent = new Intent(this, GeneralActivity.class); + intent.putExtra(GeneralActivity.PARAM_IP, ip); + intent.putExtra(GeneralActivity.PARAM_RESULTS, results); + intent.putExtra(GeneralActivity.PARAM_STATUS, status); + intent.putExtra(GeneralActivity.PARAM_HOURS, spinnerHours.getSelectedItem().toString()); + intent.putExtra(GeneralActivity.PARAM_MINUTES, spinnerMinutes.getSelectedItem().toString()); + intent.putExtra(GeneralActivity.PARAM_SECONDS, spinnerSeconds.getSelectedItem().toString()); + startActivity(intent); + + ActivityUtil.showLongToast(this, R.string.toast_starting); + + this.finish(); + } } \ No newline at end of file diff --git a/src/main/java/org/smilec/smile/ui/adapter/IQSetListAdapter.java b/src/main/java/org/smilec/smile/ui/adapter/IQSetListAdapter.java index ee1f3c3..d7210f4 100644 --- a/src/main/java/org/smilec/smile/ui/adapter/IQSetListAdapter.java +++ b/src/main/java/org/smilec/smile/ui/adapter/IQSetListAdapter.java @@ -1,18 +1,37 @@ package org.smilec.smile.ui.adapter; +import java.util.Collection; import java.util.List; import org.smilec.smile.R; +import org.smilec.smile.bu.Constants; import org.smilec.smile.bu.SmilePlugServerManager; +import org.smilec.smile.domain.CurrentMessageStatus; import org.smilec.smile.domain.IQSet; +import org.smilec.smile.domain.Question; +import org.smilec.smile.ui.GeneralActivity; +import org.smilec.smile.util.ActivityUtil; +import org.smilec.smile.util.CloseClickListenerUtil; +import org.smilec.smile.util.ImageLoader; import android.accounts.NetworkErrorException; +import android.app.Dialog; import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.view.Display; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.View.OnClickListener; import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.ImageButton; +import android.widget.ImageView; +import android.widget.ListView; import android.widget.TextView; +import android.widget.Toast; +import android.widget.LinearLayout.LayoutParams; /* * This class is only used to fill the ListView in use_prepared_questions_dialog.xml @@ -21,12 +40,14 @@ * */ public class IQSetListAdapter extends ArrayAdapter { + private Context context; private String ip; // We load the list of iqsets to retrieve the values in getView(,,) public IQSetListAdapter(Context context,List iqsets, String ip) { super(context, 0, iqsets); + this.context = context; this.ip = ip; } @@ -55,20 +76,71 @@ public View getView(int position, View convertView, ViewGroup parent) { TextView tvDate = (TextView) convertView.findViewById(R.id.tv_date); tvDate.setText(String.valueOf(iqset.getDate())); + // Here we get the list of questions... String idIQSet; int size = 0; + Collection questionsOfIQSet = null; try { idIQSet = new SmilePlugServerManager().getIdIQSetByPosition(ip, getContext(), position); - size = new SmilePlugServerManager().getListOfQuestions(ip, getContext(), idIQSet).size(); + questionsOfIQSet = new SmilePlugServerManager().getListOfQuestions(ip, getContext(), idIQSet); + size = questionsOfIQSet.size(); } catch (NetworkErrorException e) { e.printStackTrace(); } + // ...to count the number of questions TextView tvSize = (TextView) convertView.findViewById(R.id.tv_size); - if(size < 10) tvSize.setText("0"+String.valueOf(size)); - else tvSize.setText(String.valueOf(size)); + if(size < 10) tvSize.setText("0"+String.valueOf(questionsOfIQSet.size())); + else tvSize.setText(String.valueOf(questionsOfIQSet.size())); + + // ...and get values for the preview if listener is called + ImageView ivDetails = (ImageView) convertView.findViewById(R.id.iv_details); + iqset.setQuestions(questionsOfIQSet); + ivDetails.setOnClickListener(new OpenIQSetDetailsListener(iqset)); } return convertView; } + + /** + * Listener called to display the preview of an IQSet + */ + private class OpenIQSetDetailsListener implements OnClickListener { + + private IQSet iqsetToPreview; + + public OpenIQSetDetailsListener(IQSet iqset) { + this.iqsetToPreview = iqset; + } + + @Override + public void onClick(View v) { + + // Preparing "Details" view + Dialog detailsDialog = new Dialog(context, R.style.Dialog); + detailsDialog.setContentView(R.layout.iqset_details); + Display displaySize = ActivityUtil.getDisplaySize(getContext()); + detailsDialog.getWindow().setLayout(displaySize.getWidth(), displaySize.getHeight()); + detailsDialog.show(); + + // Preparing the values in the "Details" view + loadDetailOfIQSet(detailsDialog, iqsetToPreview); + } + } + +/** + * Preparing the Dialog to show a preview of IQSet + */ +private void loadDetailOfIQSet(final Dialog detailsDialog, IQSet iqsetToPreview) { + + ImageButton btClose = (ImageButton) detailsDialog.findViewById(R.id.bt_close); + btClose.setOnClickListener(new CloseClickListenerUtil(detailsDialog)); + + TextView tvTitle = (TextView) detailsDialog.findViewById(R.id.tv_title); + tvTitle.setText(iqsetToPreview.getSessionTitle()); + + ListView lvQuestionsPreviewed = (ListView) detailsDialog.findViewById(R.id.lv_questions_preview); + ArrayAdapter data = new IQSetPreviewAdapter(context, (List) iqsetToPreview.getQuestions()); + lvQuestionsPreviewed.setAdapter(data); + } } diff --git a/src/main/java/org/smilec/smile/ui/adapter/IQSetPreviewAdapter.java b/src/main/java/org/smilec/smile/ui/adapter/IQSetPreviewAdapter.java new file mode 100644 index 0000000..e3fd175 --- /dev/null +++ b/src/main/java/org/smilec/smile/ui/adapter/IQSetPreviewAdapter.java @@ -0,0 +1,103 @@ +/** +Copyright 2012-2013 SMILE Consortium, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +**/ +package org.smilec.smile.ui.adapter; + +import java.util.List; + +import org.smilec.smile.R; +import org.smilec.smile.bu.Constants; +import org.smilec.smile.bu.SmilePlugServerManager; +import org.smilec.smile.domain.CurrentMessageStatus; +import org.smilec.smile.domain.Question; +import org.smilec.smile.domain.Results; +import org.smilec.smile.ui.GeneralActivity; +import org.smilec.smile.ui.widget.checkbox.InertCheckBox; +import org.smilec.smile.util.ActivityUtil; +import org.smilec.smile.util.CloseClickListenerUtil; +import org.smilec.smile.util.ImageLoader; + +import android.accounts.NetworkErrorException; +import android.app.Dialog; +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.view.Display; +import android.view.LayoutInflater; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.ImageButton; +import android.widget.ImageView; +import android.widget.LinearLayout.LayoutParams; +import android.widget.RatingBar; +import android.widget.TextView; +import android.widget.Toast; + +public class IQSetPreviewAdapter extends ArrayAdapter { + + private Context context; + + public IQSetPreviewAdapter(Context context, List items) { + super(context, android.R.layout.simple_list_item_multiple_choice, items); + + this.context = context; + } + + // For each position (<=> question in the session), we prepare the row + @Override + public View getView(int position, View convertView, ViewGroup parent) { + + final Question question = super.getItem(position); + + if (convertView == null) { + Context context = getContext(); + LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + convertView = inflater.inflate(R.layout.preview_iqset_item, parent, false); + } + + TextView tvQuestion = (TextView) convertView.findViewById(R.id.tv_question); + if (!question.getQuestion().equals("")) { tvQuestion.setText(question.getQuestion()); } + else { tvQuestion.setVisibility(View.GONE); } + + TextView tva1 = (TextView) convertView.findViewById(R.id.tv_alternative1); + if (!question.getOption1().equals("")) + { tva1.setText(context.getString(R.string.alternative1) + " " + question.getOption1()); } + else + { tva1.setVisibility(View.GONE); } + + TextView tva2 = (TextView) convertView.findViewById(R.id.tv_alternative2); + if (!question.getOption1().equals("")) + { tva2.setText(context.getString(R.string.alternative2) + " " + question.getOption2()); } + else + { tva2.setVisibility(View.GONE); } + + TextView tva3 = (TextView) convertView.findViewById(R.id.tv_alternative3); + if (!question.getOption1().equals("")) + { tva3.setText(context.getString(R.string.alternative3) + " " + question.getOption3()); } + else + { tva3.setVisibility(View.GONE); } + + TextView tva4 = (TextView) convertView.findViewById(R.id.tv_alternative4); + if (!question.getOption1().equals("")) + { tva4.setText(context.getString(R.string.alternative4) + " " + question.getOption4()); } + else + { tva4.setVisibility(View.GONE); } + + return convertView; + } +} diff --git a/src/main/java/org/smilec/smile/ui/adapter/QuestionListAdapter.java b/src/main/java/org/smilec/smile/ui/adapter/QuestionListAdapter.java index 47649dc..749d916 100644 --- a/src/main/java/org/smilec/smile/ui/adapter/QuestionListAdapter.java +++ b/src/main/java/org/smilec/smile/ui/adapter/QuestionListAdapter.java @@ -15,38 +15,25 @@ **/ package org.smilec.smile.ui.adapter; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; import java.util.List; import org.smilec.smile.R; import org.smilec.smile.bu.Constants; -import org.smilec.smile.bu.QuestionsManager; import org.smilec.smile.bu.SmilePlugServerManager; import org.smilec.smile.domain.CurrentMessageStatus; import org.smilec.smile.domain.Question; import org.smilec.smile.domain.Results; import org.smilec.smile.ui.GeneralActivity; -import org.smilec.smile.ui.fragment.QuestionsFragment; import org.smilec.smile.ui.widget.checkbox.InertCheckBox; import org.smilec.smile.util.ActivityUtil; import org.smilec.smile.util.CloseClickListenerUtil; import org.smilec.smile.util.ImageLoader; import android.accounts.NetworkErrorException; -import android.app.Activity; -import android.app.AlertDialog; import android.app.Dialog; import android.content.Context; -import android.content.DialogInterface; import android.graphics.Bitmap; import android.graphics.BitmapFactory; -import android.util.Log; import android.view.Display; import android.view.LayoutInflater; import android.view.View; @@ -56,10 +43,10 @@ import android.widget.Button; import android.widget.ImageButton; import android.widget.ImageView; -import android.widget.Toast; import android.widget.LinearLayout.LayoutParams; import android.widget.RatingBar; import android.widget.TextView; +import android.widget.Toast; public class QuestionListAdapter extends ArrayAdapter { diff --git a/src/main/java/org/smilec/smile/ui/fragment/QuestionsFragment.java b/src/main/java/org/smilec/smile/ui/fragment/QuestionsFragment.java index a762482..dce83af 100644 --- a/src/main/java/org/smilec/smile/ui/fragment/QuestionsFragment.java +++ b/src/main/java/org/smilec/smile/ui/fragment/QuestionsFragment.java @@ -15,15 +15,9 @@ **/ package org.smilec.smile.ui.fragment; -import java.io.BufferedReader; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.ObjectInputStream.GetField; import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; @@ -34,10 +28,8 @@ import org.smilec.smile.R; import org.smilec.smile.bu.BoardManager; import org.smilec.smile.bu.Constants; -import org.smilec.smile.bu.QuestionsManager; import org.smilec.smile.bu.SmilePlugServerManager; import org.smilec.smile.bu.exception.DataAccessException; -import org.smilec.smile.bu.json.CurrentMessageJSONParser; import org.smilec.smile.domain.Board; import org.smilec.smile.domain.Question; import org.smilec.smile.domain.Results; @@ -47,7 +39,6 @@ import org.smilec.smile.util.CloseClickListenerUtil; import org.smilec.smile.util.SendEmailAsyncTask; -import android.R.bool; import android.accounts.NetworkErrorException; import android.app.Activity; import android.app.Dialog; @@ -69,7 +60,6 @@ import android.widget.ImageButton; import android.widget.ListView; import android.widget.TextView; -import android.widget.Toast; public class QuestionsFragment extends AbstractFragment {