From a5bece6bf0d3729ab4de0aee26200b75b2b71e9c Mon Sep 17 00:00:00 2001 From: Jo Grimstad Date: Mon, 16 Jan 2017 21:13:36 +0300 Subject: [PATCH 1/2] #50 Personalize available operators - app --- app/build.gradle | 2 + app/src/main/AndroidManifest.xml | 10 +++++ .../com/android/calculator2/Calculator.java | 26 +++++++++++ .../receiver/StudentUpdatedReceiver.java | 44 ++++++++++++++++--- build.gradle | 5 +++ 5 files changed, 82 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 88ed97104..8ed393ba5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,6 +10,7 @@ android { targetSdkVersion 23 versionCode 1000006 versionName "1.0.6-SNAPSHOT" + setProperty("archivesBaseName", "$applicationId-$versionCode") } buildTypes { @@ -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' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8030a5f42..8d3c3c20b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -93,5 +93,15 @@ + + + + + + + diff --git a/app/src/main/java/com/android/calculator2/Calculator.java b/app/src/main/java/com/android/calculator2/Calculator.java index 2511d0de4..892b10253 100644 --- a/app/src/main/java/com/android/calculator2/Calculator.java +++ b/app/src/main/java/com/android/calculator2/Calculator.java @@ -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; @@ -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; @@ -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; @@ -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 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); diff --git a/app/src/main/java/com/android/calculator2/receiver/StudentUpdatedReceiver.java b/app/src/main/java/com/android/calculator2/receiver/StudentUpdatedReceiver.java index 788bbc6fa..49749bed8 100644 --- a/app/src/main/java/com/android/calculator2/receiver/StudentUpdatedReceiver.java +++ b/app/src/main/java/com/android/calculator2/receiver/StudentUpdatedReceiver.java @@ -3,15 +3,49 @@ 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 StudentUpdatedReceiver() { - } + + 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) { - // TODO: This method is called when the BroadcastReceiver is receiving - // an Intent broadcast. - throw new UnsupportedOperationException("Not yet implemented"); + Log.i(getClass().getName(), "onReceive"); + + // Customize the user interface to match the current Student's level + + ArrayList availableNumbers = intent.getStringArrayListExtra("availableNumbers"); + Log.i(getClass().getName(), "availableNumbers: " + availableNumbers); + + ArrayList availableNumeracySkills = intent.getStringArrayListExtra("availableNumeracySkills"); + Log.i(getClass().getName(), "availableNumeracySkills: " + availableNumeracySkills); + + SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); + + if (availableNumbers != null) { + Set 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 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(); + } } } diff --git a/build.gradle b/build.gradle index b3e1f0218..b1b3f0c94 100644 --- a/build.gradle +++ b/build.gradle @@ -10,6 +10,11 @@ buildscript { allprojects { repositories { + mavenLocal() jcenter() + mavenCentral() + maven { + url "http://archiva.educativo.eu:8081/repository/internal/" + } } } From 5be748341a84be85c4d5455aca653a96db66d49e Mon Sep 17 00:00:00 2001 From: Jo Grimstad Date: Mon, 16 Jan 2017 21:36:14 +0300 Subject: [PATCH 2/2] #50 Personalize available operators - widget --- app/build.gradle | 2 +- .../calculator2/widget/CalculatorWidget.java | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 8ed393ba5..cb3ccdb3a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,7 +9,7 @@ android { minSdkVersion 21 targetSdkVersion 23 versionCode 1000006 - versionName "1.0.6-SNAPSHOT" + versionName "1.0.6" setProperty("archivesBaseName", "$applicationId-$versionCode") } diff --git a/app/src/main/java/com/android/calculator2/widget/CalculatorWidget.java b/app/src/main/java/com/android/calculator2/widget/CalculatorWidget.java index 2ecd216e2..f839e35ea 100644 --- a/app/src/main/java/com/android/calculator2/widget/CalculatorWidget.java +++ b/app/src/main/java/com/android/calculator2/widget/CalculatorWidget.java @@ -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; @@ -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; @@ -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 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