Skip to content

Commit

Permalink
Merge pull request #108 from chrqls/dev
Browse files Browse the repository at this point in the history
[#14] Teacher can change the limit of percent to succeed
  • Loading branch information
chrqls committed Jan 4, 2014
2 parents 5b81e6d + d15f013 commit 0158483
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 33 deletions.
21 changes: 11 additions & 10 deletions res/layout-large-land/students.xml
Original file line number Diff line number Diff line change
Expand Up @@ -261,16 +261,6 @@
<!-- android:layout_marginTop="10dip" -->
<!-- android:layout_below="@+id/tv_top_scorers_top" /> -->

<!-- <RatingBar -->
<!-- android:id="@+id/rb_ratingbar" -->
<!-- style="?android:attr/ratingBarStyleSmall" -->
<!-- android:layout_width="wrap_content" -->
<!-- android:layout_height="wrap_content" -->
<!-- android:layout_marginLeft="10dip" -->
<!-- android:layout_marginBottom="5dip" -->
<!-- android:numStars="5" -->
<!-- android:layout_below="@+id/tv_top_scorers_rating" /> -->

<TextView
android:id="@+id/tv_percent_completed"
android:layout_width="wrap_content"
Expand All @@ -292,6 +282,17 @@
android:layout_marginTop="10dip"
android:layout_below="@+id/tv_percent_completed"
android:layout_alignLeft="@+id/tv_percent_completed" />

<Spinner
android:id="@+id/sp_limit_to_succeed"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:prompt="@string/limit_to_succeed"
android:layout_marginLeft="10dip"
android:layout_marginBottom="3dip"
android:layout_toRightOf="@+id/tv_percent_correct"
android:layout_above="@+id/view_separator_below"
android:layout_below="@+id/tv_percent_completed"/>

<View
android:id="@+id/view_separator_below"
Expand Down
12 changes: 12 additions & 0 deletions res/values/percent_correct_array.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="percent_correct">
<item>50</item>
<item>60</item>
<item>70</item>
<item>75</item>
<item>80</item>
<item>90</item>
<item>100</item>
</string-array>
</resources>
3 changes: 2 additions & 1 deletion res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<string name="rating_table">Highest\nRating</string>
<string name="students_completed">completed</string>
<string name="students_correct">correct</string>
<string name="limit_to_succeed">Percent limit to succeed</string>

<string name="send_report">Send a report</string>
<string name="send_report_body">Please leave your report:</string>
Expand All @@ -66,7 +67,7 @@
<string name="top_scores">TOP SCORER</string>

<string name="about">About</string>
<string name="about_text">SMILE Teacher App 0.9.8b1: The activity management application for teachers,
<string name="about_text">SMILE Teacher App 0.9.9b1: The activity management application for teachers,
called the SMILE Teacher, serves to manage and
save data from the activity via an ad-hoc network. It is a
Graphic User Interface-based application that can be
Expand Down
12 changes: 3 additions & 9 deletions src/main/java/org/smilec/smile/bu/SmilePlugServerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,10 @@ public List<IQSet> getIQSets(String ip, Context context) throws NetworkErrorExce
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);
}
catch (JSONException e) { e.printStackTrace(); }
catch (IOException e) { e.printStackTrace(); }
finally { IOUtil.silentClose(is); }

return iqsets;
}
Expand Down
33 changes: 30 additions & 3 deletions src/main/java/org/smilec/smile/ui/GeneralActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,13 @@
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TableLayout;
import android.widget.TextView;

Expand Down Expand Up @@ -127,7 +131,7 @@ public void onCreate(Bundle savedInstanceState) {
tvTime = (TextView) findViewById(R.id.tv_time);
tvRemaining = (TextView) findViewById(R.id.tv_remaining_time);
tvStatus = (TextView) findViewById(R.id.tv_status);

if (savedInstanceState != null) {
Board tmp = (Board) savedInstanceState.getSerializable(PARAM_BOARD);

Expand Down Expand Up @@ -245,7 +249,7 @@ private void updateCurrentFragment(Board newBoard) {
@Override
protected void onResume() {
super.onResume();

btSolve.setOnClickListener(new SolveButtonListener());
btResults.setOnClickListener(new ResultsButtonListener());

Expand Down Expand Up @@ -611,6 +615,30 @@ private void showResults() {
.findViewById(R.id.rl_top_scorers);
rlTopScorersContainer.setVisibility(View.VISIBLE);


Spinner spLimitToSucceed = (Spinner) findViewById(R.id.sp_limit_to_succeed);
ArrayAdapter<?> adapterLimit = ArrayAdapter.createFromResource(this, R.array.percent_correct, android.R.layout.simple_spinner_item);
adapterLimit.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spLimitToSucceed.setAdapter(adapterLimit);

// Initialize the spinner to 70%
spLimitToSucceed.setSelection(2);

// If the teacher clicks on the spinner to set a different limit to succeed
spLimitToSucceed.setOnItemSelectedListener(new OnItemSelectedListener() {

@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {

String[] bases = getResources().getStringArray(R.array.percent_correct);
((StudentsFragment)activeFragment).updatePercentCorrect(Integer.parseInt(bases[position]));
}

@Override
public void onNothingSelected(AdapterView<?> arg0) { }
});

// If the teacher clicks on "Send results" button
Button btSendResults = (Button) GeneralActivity.this.findViewById(R.id.bt_send_results);
btSendResults.setVisibility(View.VISIBLE);
btSendResults.setOnClickListener(new OnClickListener() {
Expand All @@ -619,7 +647,6 @@ private void showResults() {
public void onClick(View v) {
SendEmailResultsUtil.send(board, ip, GeneralActivity.this);
}

});
}

Expand Down
25 changes: 15 additions & 10 deletions src/main/java/org/smilec/smile/ui/fragment/StudentsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import android.widget.ListView;
import android.widget.RatingBar;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;

public class StudentsFragment extends AbstractFragment {
Expand All @@ -66,6 +67,8 @@ public class StudentsFragment extends AbstractFragment {
private Results results;

private boolean run;

private int limitToSucceed;

private String ip;

Expand Down Expand Up @@ -106,9 +109,7 @@ public void onResume() {
super.onResume();

ip = getActivity().getIntent().getStringExtra(GeneralActivity.PARAM_IP);
results = (Results) getActivity().getIntent().getSerializableExtra(
GeneralActivity.PARAM_RESULTS);

results = (Results) getActivity().getIntent().getSerializableExtra(GeneralActivity.PARAM_RESULTS);
adapter = new StudentListAdapter(getActivity(), students);

ListView lvListStudents = (ListView) getActivity().findViewById(R.id.lv_students);
Expand Down Expand Up @@ -190,7 +191,7 @@ public void run() {
tvAnswers.setText(getString(R.string.answers) + ": " + countAnswers);

if (results != null) {
setTopScorersArea(results, board);
setTopScorersArea(results);
}
}

Expand Down Expand Up @@ -296,7 +297,7 @@ private String getPercentCorrect() {
}
}
// if the student has 70+% of correct answers, we count it
nbStudentOver70 += nbQuestionsCorrect*100/questions.size() >= 70 ? 1:0;
nbStudentOver70 += nbQuestionsCorrect*100/questions.size() >= this.limitToSucceed ? 1:0;
}

float percent = !students.isEmpty()? (float) (nbStudentOver70/students.size())*100 : 0;
Expand All @@ -306,8 +307,16 @@ private String getPercentCorrect() {
" ("+ String.format("%.0f", nbStudentOver70)+"/"+students.size() +")";
return s;
}

public void updatePercentCorrect(int limitToSucceed) {

this.limitToSucceed = limitToSucceed;
TextView tvPercentCorrect = (TextView) getActivity().findViewById(R.id.tv_percent_correct);
tvPercentCorrect.setText(this.getPercentCorrect());
tvPercentCorrect.setVisibility(View.VISIBLE);
}

private void setTopScorersArea(Results results, Board board) {
private void setTopScorersArea(Results results) {
try {
TextView tvTopScorersTop = (TextView) getActivity().findViewById(
R.id.tv_top_scorers_top);
Expand All @@ -327,10 +336,6 @@ private void setTopScorersArea(Results results, Board board) {
//TextView tvTopScorersRating = (TextView) getActivity().findViewById(R.id.tv_top_scorers_rating);
//tvTopScorersRating.setText(getString(R.string.rating) + ": " + results.getWinnerRating());

// Seems useless >> issues 14
//final RatingBar rbRatingBar = (RatingBar) getActivity().findViewById(R.id.rb_ratingbar);
//rbRatingBar.setRating(results.getWinnerRating());

} catch (JSONException e) {
new SendEmailAsyncTask(e.getMessage(),JSONException.class.getName(),StudentsFragment.class.getName()).execute();
Log.e("StudentsFragment", "Error: " + e);
Expand Down

0 comments on commit 0158483

Please sign in to comment.