Skip to content

Commit

Permalink
Merge pull request #51 from jogrimst/cm-13.0
Browse files Browse the repository at this point in the history
#50 Personalize available operators
  • Loading branch information
literacyapp authored Jan 16, 2017
2 parents 98a8dbf + 5be7483 commit 3e8bcb1
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ android {
minSdkVersion 21
targetSdkVersion 23
versionCode 1000006
versionName "1.0.6-SNAPSHOT"
versionName "1.0.6"
setProperty("archivesBaseName", "$applicationId-$versionCode")
}

buildTypes {
Expand All @@ -30,4 +31,5 @@ dependencies {

compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'org.literacyapp:literacyapp-model:1.1.33'
}
10 changes: 10 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,15 @@
<action android:name="android.intent.action.CONFIGURATION_CHANGED" />
</intent-filter>
</service>

<receiver
android:name="com.android.calculator2.receiver.StudentUpdatedReceiver"
android:enabled="true"
android:exported="true">

<intent-filter>
<action android:name="literacyapp.intent.action.STUDENT_UPDATED" />
</intent-filter>
</receiver>
</application>
</manifest>
26 changes: 26 additions & 0 deletions app/src/main/java/com/android/calculator2/Calculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
Expand All @@ -43,6 +46,7 @@
import android.widget.FrameLayout;

import com.android.calculator2.CalculatorExpressionEvaluator.EvaluateCallback;
import com.android.calculator2.receiver.StudentUpdatedReceiver;
import com.android.calculator2.util.DigitLabelHelper;
import com.android.calculator2.util.PlayerUtil;
import com.android.calculator2.view.DisplayOverlay;
Expand All @@ -63,6 +67,9 @@
import com.xlythe.math.Persist;

import org.literacyapp.calculator.R;
import org.literacyapp.model.enums.content.NumeracySkill;

import java.util.Set;

import static com.android.calculator2.util.PlayerUtil.RAW_FILE_EQUALS;

Expand Down Expand Up @@ -160,6 +167,25 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_calculator);

// Personalize available operators
Button buttonOperatorMul = (Button) findViewById(R.id.op_mul);
Button buttonOperatorSub = (Button) findViewById(R.id.op_sub);
Button buttonOperatorAdd = (Button) findViewById(R.id.op_add);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
Set<String> numeracySkillSet = sharedPreferences.getStringSet(StudentUpdatedReceiver.PREF_STUDENT_NUMERACY_SKILLS, null);
Log.d(getClass().getName(), "numeracySkillSet: " + numeracySkillSet);
if (numeracySkillSet == null) {
buttonOperatorMul.setVisibility(View.INVISIBLE);
buttonOperatorSub.setVisibility(View.INVISIBLE);
} else {
if (!numeracySkillSet.contains(NumeracySkill.MULTIPLICATION.toString())) {
buttonOperatorMul.setVisibility(View.INVISIBLE);
}
if (!numeracySkillSet.contains(NumeracySkill.SUBTRACTION.toString())) {
buttonOperatorSub.setVisibility(View.INVISIBLE);
}
}

mX = getString(R.string.X);
mDisplayView = (DisplayOverlay) findViewById(R.id.display);
mFormulaEditText = (AdvancedDisplay) findViewById(R.id.formula);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.android.calculator2.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

public class StudentUpdatedReceiver extends BroadcastReceiver {

public static final String PREF_STUDENT_NUMBERS = "pref_student_numbers";
public static final String PREF_STUDENT_NUMERACY_SKILLS = "pref_student_numeracy_skills";

@Override
public void onReceive(Context context, Intent intent) {
Log.i(getClass().getName(), "onReceive");

// Customize the user interface to match the current Student's level

ArrayList<String> availableNumbers = intent.getStringArrayListExtra("availableNumbers");
Log.i(getClass().getName(), "availableNumbers: " + availableNumbers);

ArrayList<String> availableNumeracySkills = intent.getStringArrayListExtra("availableNumeracySkills");
Log.i(getClass().getName(), "availableNumeracySkills: " + availableNumeracySkills);

SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);

if (availableNumbers != null) {
Set<String> availableNumberSet = new HashSet<>();
for (String availableNumber : availableNumbers) {
availableNumberSet.add(availableNumber);
}
Log.i(getClass().getName(), "Storing availableNumbersSet: " + availableNumberSet);
sharedPreferences.edit().putStringSet(PREF_STUDENT_NUMBERS, availableNumberSet).commit();
}

if (availableNumeracySkills != null) {
Set<String> availableNumeracySkillSet = new HashSet<>();
for (String availableNumeracySkill : availableNumeracySkills) {
availableNumeracySkillSet.add(availableNumeracySkill);
}
Log.i(getClass().getName(), "Storing availableNumeracySkillSet: " + availableNumeracySkillSet);
sharedPreferences.edit().putStringSet(PREF_STUDENT_NUMERACY_SKILLS, availableNumeracySkillSet).commit();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.RemoteViews;

import com.android.calculator2.CalculatorExpressionTokenizer;
import com.android.calculator2.receiver.StudentUpdatedReceiver;
import com.android.calculator2.util.DigitLabelHelper;
import com.android.calculator2.util.PlayerUtil;
import com.xlythe.math.Base;
Expand All @@ -23,8 +26,10 @@

import org.javia.arity.SyntaxException;
import org.literacyapp.calculator.R;
import org.literacyapp.model.enums.content.NumeracySkill;

import java.text.DecimalFormatSymbols;
import java.util.Set;

import static com.android.calculator2.util.PlayerUtil.NUMBER_RAW_FILES;
import static com.android.calculator2.util.PlayerUtil.RAW_FILE_EQUALS;
Expand Down Expand Up @@ -302,6 +307,22 @@ private void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
remoteViews.setViewVisibility(R.id.clear, mClearText ? View.VISIBLE : View.GONE);
setOnClickListeners(context, appWidgetId, remoteViews);

// Personalize available operators
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
Set<String> numeracySkillSet = sharedPreferences.getStringSet(StudentUpdatedReceiver.PREF_STUDENT_NUMERACY_SKILLS, null);
Log.d(getClass().getName(), "numeracySkillSet: " + numeracySkillSet);
if (numeracySkillSet == null) {
remoteViews.setViewVisibility(R.id.mul, View.INVISIBLE);
remoteViews.setViewVisibility(R.id.minus, View.INVISIBLE);
} else {
if (!numeracySkillSet.contains(NumeracySkill.MULTIPLICATION.toString())) {
remoteViews.setViewVisibility(R.id.mul, View.INVISIBLE);
}
if (!numeracySkillSet.contains(NumeracySkill.SUBTRACTION.toString())) {
remoteViews.setViewVisibility(R.id.minus, View.INVISIBLE);
}
}

DigitLabelHelper.getInstance().getTextForDigits(context,
new DigitLabelHelper.DigitLabelHelperCallback() {
@Override
Expand Down
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ buildscript {

allprojects {
repositories {
mavenLocal()
jcenter()
mavenCentral()
maven {
url "http://archiva.educativo.eu:8081/repository/internal/"
}
}
}

0 comments on commit 3e8bcb1

Please sign in to comment.