From c758c010c6f39f92cf5c5dd7f12b698e7560cabf Mon Sep 17 00:00:00 2001 From: arch10 Date: Tue, 16 Apr 2019 01:13:27 +0530 Subject: [PATCH 1/4] code optimisation --- .../arch1/testapplication/Evaluate.java | 13 ++++- .../arch1/testapplication/MainActivity.java | 56 ++----------------- 2 files changed, 14 insertions(+), 55 deletions(-) diff --git a/app/src/main/java/com/example/arch1/testapplication/Evaluate.java b/app/src/main/java/com/example/arch1/testapplication/Evaluate.java index 2e8bb8f..e60fb56 100644 --- a/app/src/main/java/com/example/arch1/testapplication/Evaluate.java +++ b/app/src/main/java/com/example/arch1/testapplication/Evaluate.java @@ -111,7 +111,7 @@ public static String tryBalancingBrackets(String equ) { } //adds thousand separator - private static String formatString(String str) { + static String formatString(String str) { int index = str.indexOf('.'); if(index == -1) index = str.length(); @@ -130,7 +130,7 @@ private static String formatString(String str) { } //checks if the string provided is a number - private static boolean isNumber(String string) { + static boolean isNumber(String string) { return Pattern.matches("-?\\d+(\\.\\d+)?", string); } @@ -248,7 +248,7 @@ private boolean canBeLastChar(char c) { } //checks if the given char is a number or a constant - private boolean isNumber(char c) { + static boolean isNumber(char c) { switch (c) { case '1': case '2': @@ -934,4 +934,11 @@ private String getValue(Stack token) throws Exception{ return null; } + static boolean isAnError(String string) { + return (string.equals("Invalid Expression") || + string.equals("Domain error") || + string.equals("Cannot divide by 0") || + string.equals("Number too large")); + } + } diff --git a/app/src/main/java/com/example/arch1/testapplication/MainActivity.java b/app/src/main/java/com/example/arch1/testapplication/MainActivity.java index a7a1d76..a32c3b8 100644 --- a/app/src/main/java/com/example/arch1/testapplication/MainActivity.java +++ b/app/src/main/java/com/example/arch1/testapplication/MainActivity.java @@ -29,7 +29,10 @@ import com.getkeepsafe.taptargetview.TapTargetSequence; import java.util.Stack; -import java.util.regex.Pattern; + +import static com.example.arch1.testapplication.Evaluate.formatString; +import static com.example.arch1.testapplication.Evaluate.isAnError; +import static com.example.arch1.testapplication.Evaluate.isNumber; public class MainActivity extends AppCompatActivity implements View.OnClickListener, TextWatcher { @@ -131,15 +134,6 @@ public boolean onLongClick(View v) { } - private boolean isAnError(String string) { - if (string.equals("Invalid Expression") || - string.equals("Domain error") || - string.equals("Cannot divide by 0") || - string.equals("Number too large")) - return true; - return false; - } - @Override public void onClick(View v) { int id = v.getId(); @@ -1330,25 +1324,6 @@ private boolean isOperator(char c) { return false; } - //adds number formatter (,) to the number string - private String formatString(String str) { - int index = str.indexOf('.'); - if (index == -1) - index = str.length(); - int temp = 0; - for (int i = index - 1; i > 0; i--) { - temp++; - - if (temp % 3 == 0) { - temp = 0; - if (i == 1 && str.charAt(0) == '-') - break; - str = str.substring(0, i) + "," + str.substring(i); - } - } - return str; - } - //adds number formatter (,) to the equation private String formatEquation(String equation) { Stack stack = new Stack<>(); @@ -1417,29 +1392,6 @@ public boolean onPrepareOptionsMenu(Menu menu) { return super.onPrepareOptionsMenu(menu); } - private static boolean isNumber(String string) { - return Pattern.matches("-?\\d+(\\.\\d+)?", string); - } - - private boolean isNumber(char c) { - switch (c) { - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case '0': - case 'e': - case '\u03c0': - return true; - } - return false; - } - @Override protected void onStop() { super.onStop(); From 8a678722a1afddb387ed690f1d455c4e266da225 Mon Sep 17 00:00:00 2001 From: arch10 Date: Wed, 17 Apr 2019 03:01:12 +0530 Subject: [PATCH 2/4] Update theme_layout.xml --- app/src/main/res/layout/theme_item_layout.xml | 49 ---------- app/src/main/res/layout/theme_layout.xml | 91 +++++++++++++++++++ 2 files changed, 91 insertions(+), 49 deletions(-) delete mode 100644 app/src/main/res/layout/theme_item_layout.xml create mode 100644 app/src/main/res/layout/theme_layout.xml diff --git a/app/src/main/res/layout/theme_item_layout.xml b/app/src/main/res/layout/theme_item_layout.xml deleted file mode 100644 index 9225379..0000000 --- a/app/src/main/res/layout/theme_item_layout.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/theme_layout.xml b/app/src/main/res/layout/theme_layout.xml new file mode 100644 index 0000000..f77707c --- /dev/null +++ b/app/src/main/res/layout/theme_layout.xml @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 31cd090169ec66c739c2e464ab3a655f52b44829 Mon Sep 17 00:00:00 2001 From: arch10 Date: Mon, 22 Apr 2019 01:39:54 +0530 Subject: [PATCH 3/4] theme layout changed --- .../arch1/testapplication/ThemeActivity.java | 139 +++--- app/src/main/res/layout/theme_layout.xml | 22 +- app/src/main/res/layout/theme_switcher.xml | 416 ++++++++++++++++++ 3 files changed, 496 insertions(+), 81 deletions(-) create mode 100644 app/src/main/res/layout/theme_switcher.xml diff --git a/app/src/main/java/com/example/arch1/testapplication/ThemeActivity.java b/app/src/main/java/com/example/arch1/testapplication/ThemeActivity.java index 0dfde23..5f80469 100644 --- a/app/src/main/java/com/example/arch1/testapplication/ThemeActivity.java +++ b/app/src/main/java/com/example/arch1/testapplication/ThemeActivity.java @@ -6,15 +6,16 @@ import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; + import android.util.TypedValue; import android.view.View; -import android.widget.RadioGroup; -import android.widget.Toast; +import android.widget.LinearLayout; -public class ThemeActivity extends AppCompatActivity { +public class ThemeActivity extends AppCompatActivity implements View.OnClickListener { - private RadioGroup themeGroup; private AppPreferences preferences; + private View themeSwitcher; + private LinearLayout classic, orange, green, blue, red, lightGreen, purple, pink, materialLight, materialDark; @Override protected void onCreate(Bundle savedInstanceState) { @@ -22,7 +23,30 @@ protected void onCreate(Bundle savedInstanceState) { setTheme(Theme.getTheme(preferences.getStringPreference(AppPreferences.APP_THEME))); super.onCreate(savedInstanceState); - setContentView(R.layout.activity_theme); + setContentView(R.layout.theme_layout); + + themeSwitcher = findViewById(R.id.theme_switcher); + classic = themeSwitcher.findViewById(R.id.theme_classic); + orange = themeSwitcher.findViewById(R.id.theme_orange); + green = themeSwitcher.findViewById(R.id.theme_green); + blue = themeSwitcher.findViewById(R.id.theme_blue); + red = themeSwitcher.findViewById(R.id.theme_red); + lightGreen = themeSwitcher.findViewById(R.id.theme_lightgreen); + purple = themeSwitcher.findViewById(R.id.theme_purple); + pink = themeSwitcher.findViewById(R.id.theme_pink); + materialLight = themeSwitcher.findViewById(R.id.theme_material_light); + materialDark = themeSwitcher.findViewById(R.id.theme_material_dark); + + classic.setOnClickListener(this); + orange.setOnClickListener(this); + green.setOnClickListener(this); + blue.setOnClickListener(this); + red.setOnClickListener(this); + lightGreen.setOnClickListener(this); + purple.setOnClickListener(this); + pink.setOnClickListener(this); + materialLight.setOnClickListener(this); + materialDark.setOnClickListener(this); String themeName = preferences.getStringPreference(AppPreferences.APP_THEME); @@ -30,15 +54,15 @@ protected void onCreate(Bundle savedInstanceState) { setSupportActionBar(toolbar); TypedValue typedValue = new TypedValue(); - TypedArray a = obtainStyledAttributes(typedValue.data, new int[] { R.attr.colorPrimary }); + TypedArray a = obtainStyledAttributes(typedValue.data, new int[]{R.attr.colorPrimary}); int color = a.getColor(0, 0); a.recycle(); - if(themeName.equals(Theme.DEFAULT)) { + if (themeName.equals(Theme.DEFAULT)) { color = getResources().getColor(R.color.colorMaterialSteelGrey); toolbar.setTitleTextColor(getResources().getColor(R.color.colorWhite)); toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp); - } else if(themeName.equals(Theme.MATERIAL_LIGHT)) { + } else if (themeName.equals(Theme.MATERIAL_LIGHT)) { toolbar.setTitleTextColor(getResources().getColor(R.color.gray)); toolbar.setNavigationIcon(R.drawable.ic_arrow_back_black_24dp); } else { @@ -56,96 +80,59 @@ public void onClick(View v) { } }); - themeGroup = findViewById(R.id.rg_theme_group); - checkSelectedTheme(); - - themeGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(RadioGroup group, int checkedId) { - switch (checkedId) { - case R.id.rb_theme_green: - changeTheme(Theme.GREEN); - break; - case R.id.rb_theme_orange: - changeTheme(Theme.ORANGE); - break; - case R.id.rb_theme_blue: - changeTheme(Theme.BLUE); - break; - case R.id.rb_theme_red: - changeTheme(Theme.RED); - break; - case R.id.rb_theme_lightgreen: - changeTheme(Theme.LIGHT_GREEN); - break; - case R.id.rb_theme_pink: - changeTheme(Theme.PINK); - break; - case R.id.rb_theme_purple: - changeTheme(Theme.PURPLE); - break; - case R.id.rb_theme_material2: - changeTheme(Theme.MATERIAL_LIGHT); - break; - case R.id.rb_theme_material_dark: - changeTheme(Theme.MATERIAL_DARK); - break; - case R.id.rb_theme_default: - changeTheme(Theme.DEFAULT); - } - } - }); - } private void changeTheme(String themeName) { + String currTheme = preferences.getStringPreference(AppPreferences.APP_THEME); + if(currTheme.equals(themeName)) + return; Theme.changeTheme(themeName, preferences); Intent intent[] = new Intent[3]; intent[2] = new Intent(this, ThemeActivity.class); intent[1] = new Intent(this, SettingsActivity.class); intent[0] = new Intent(this, MainActivity.class); startActivities(intent); - overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out); + overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); finish(); } - private void checkSelectedTheme() { - String themeName = preferences.getStringPreference(AppPreferences.APP_THEME); - - switch (themeName) { - case Theme.GREEN : - themeGroup.check(R.id.rb_theme_green); + @Override + public void onClick(View v) { + int id = v.getId(); + switch (id) { + case R.id.theme_classic: + changeTheme(Theme.DEFAULT); break; - case Theme.ORANGE : - themeGroup.check(R.id.rb_theme_orange); + case R.id.theme_orange: + changeTheme(Theme.ORANGE); break; - case Theme.BLUE : - themeGroup.check(R.id.rb_theme_blue); + case R.id.theme_green: + changeTheme(Theme.GREEN); break; - case Theme.RED : - themeGroup.check(R.id.rb_theme_red); + case R.id.theme_blue: + changeTheme(Theme.BLUE); break; - case Theme.LIGHT_GREEN : - themeGroup.check(R.id.rb_theme_lightgreen); + case R.id.theme_red: + changeTheme(Theme.RED); break; - case Theme.PINK : - themeGroup.check(R.id.rb_theme_pink); + case R.id.theme_lightgreen: + changeTheme(Theme.LIGHT_GREEN); break; - case Theme.PURPLE : - themeGroup.check(R.id.rb_theme_purple); + case R.id.theme_pink: + changeTheme(Theme.PINK); break; - case Theme.MATERIAL_LIGHT : - themeGroup.check(R.id.rb_theme_material2); + case R.id.theme_purple: + changeTheme(Theme.PURPLE); break; - case Theme.MATERIAL_DARK : - themeGroup.check(R.id.rb_theme_material_dark); + case R.id.theme_material_light: + changeTheme(Theme.MATERIAL_LIGHT); break; - case Theme.DEFAULT : - themeGroup.check(R.id.rb_theme_default); + case R.id.theme_material_dark: + changeTheme(Theme.MATERIAL_DARK); + break; + default: + changeTheme(Theme.MATERIAL_LIGHT); break; - default : - themeGroup.check(R.id.rb_theme_material2); } } - } diff --git a/app/src/main/res/layout/theme_layout.xml b/app/src/main/res/layout/theme_layout.xml index f77707c..59176d3 100644 --- a/app/src/main/res/layout/theme_layout.xml +++ b/app/src/main/res/layout/theme_layout.xml @@ -1,7 +1,6 @@ @@ -10,7 +9,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" - app:layout_constraintGuide_percent="0.40" /> + app:layout_constraintGuide_percent="0.4" /> @@ -28,10 +28,8 @@ android:id="@+id/frameLayout" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginTop="8dp" - android:layout_marginBottom="8dp" + android:layout_marginTop="16dp" android:background="@color/gray" - app:layout_constraintBottom_toTopOf="@id/textView3" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/toolbar"> @@ -78,6 +76,20 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From c64846bc79429b7ac25c82fc9de581de1bc34e06 Mon Sep 17 00:00:00 2001 From: arch10 Date: Mon, 22 Apr 2019 01:50:00 +0530 Subject: [PATCH 4/4] code format and version update to 1.9.3 --- app/build.gradle | 4 +- .../arch1/testapplication/AboutActivity.java | 7 +- .../CalculatorPadViewPager.java | 2 + .../arch1/testapplication/Evaluate.java | 60 ++++++++--------- .../GeneralSettingsActivity.java | 18 +++-- .../testapplication/HistoryActivity.java | 16 +++-- .../arch1/testapplication/HistoryAdapter.java | 2 + .../arch1/testapplication/ListAdapter.java | 24 +++---- .../arch1/testapplication/MainActivity.java | 10 +-- .../example/arch1/testapplication/Theme.java | 66 +++++++++---------- .../arch1/testapplication/ThemeActivity.java | 2 +- 11 files changed, 113 insertions(+), 98 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 4d46027..fca8c91 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,8 +7,8 @@ android { applicationId "com.gigaworks.tech.calculator" minSdkVersion 21 targetSdkVersion 28 - versionCode 24 - versionName "1.9.2" + versionCode 25 + versionName "1.9.3" buildConfigField "java.util.Date", "buildTime", "new java.util.Date(" + System.currentTimeMillis() + "L)" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/app/src/main/java/com/example/arch1/testapplication/AboutActivity.java b/app/src/main/java/com/example/arch1/testapplication/AboutActivity.java index 4e10ae4..2da379c 100644 --- a/app/src/main/java/com/example/arch1/testapplication/AboutActivity.java +++ b/app/src/main/java/com/example/arch1/testapplication/AboutActivity.java @@ -4,6 +4,7 @@ import android.content.res.TypedArray; import android.net.Uri; import android.os.Bundle; + import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; import androidx.browser.customtabs.CustomTabsIntent; @@ -46,15 +47,15 @@ protected void onCreate(Bundle savedInstanceState) { context = this; TypedValue typedValue = new TypedValue(); - TypedArray a = obtainStyledAttributes(typedValue.data, new int[] { R.attr.colorPrimary }); + TypedArray a = obtainStyledAttributes(typedValue.data, new int[]{R.attr.colorPrimary}); color = a.getColor(0, 0); a.recycle(); - if(themeName.equals(Theme.DEFAULT)) { + if (themeName.equals(Theme.DEFAULT)) { color = getResources().getColor(R.color.colorMaterialSteelGrey); toolbar.setTitleTextColor(getResources().getColor(R.color.colorWhite)); toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp); - } else if(themeName.equals(Theme.MATERIAL_LIGHT)) { + } else if (themeName.equals(Theme.MATERIAL_LIGHT)) { toolbar.setTitleTextColor(getResources().getColor(R.color.gray)); toolbar.setNavigationIcon(R.drawable.ic_arrow_back_black_24dp); } else { diff --git a/app/src/main/java/com/example/arch1/testapplication/CalculatorPadViewPager.java b/app/src/main/java/com/example/arch1/testapplication/CalculatorPadViewPager.java index 271e659..66c1831 100644 --- a/app/src/main/java/com/example/arch1/testapplication/CalculatorPadViewPager.java +++ b/app/src/main/java/com/example/arch1/testapplication/CalculatorPadViewPager.java @@ -17,8 +17,10 @@ */ import android.content.Context; + import androidx.viewpager.widget.PagerAdapter; import androidx.viewpager.widget.ViewPager; + import android.util.AttributeSet; import android.view.View; import android.view.ViewGroup; diff --git a/app/src/main/java/com/example/arch1/testapplication/Evaluate.java b/app/src/main/java/com/example/arch1/testapplication/Evaluate.java index e60fb56..5e65acf 100644 --- a/app/src/main/java/com/example/arch1/testapplication/Evaluate.java +++ b/app/src/main/java/com/example/arch1/testapplication/Evaluate.java @@ -22,12 +22,12 @@ public static String calculateResult(String equ, Boolean enableNumberFormatter, if (!equ.equals("")) { equ = equ.replace("รท", "/"); equ = equ.replace("\u00d7", "*"); - equ = equ.replace(",",""); + equ = equ.replace(",", ""); String ans = new Evaluate().getAnswer(equ); if (ans.equals("-0")) ans = "0"; - if(enableNumberFormatter) + if (enableNumberFormatter) return formatString(ans); return ans; } @@ -56,9 +56,9 @@ public static String tryBalancingBrackets(String equ) { int a = 0, b = 0; //if (-) appears in the end, remove it - if(tempEqu.endsWith("-")) { - tempEqu = tempEqu.substring(0,tempEqu.length()-1); - if(balancedParenthesis(tempEqu)) { + if (tempEqu.endsWith("-")) { + tempEqu = tempEqu.substring(0, tempEqu.length() - 1); + if (balancedParenthesis(tempEqu)) { return tempEqu; } } @@ -113,17 +113,17 @@ public static String tryBalancingBrackets(String equ) { //adds thousand separator static String formatString(String str) { int index = str.indexOf('.'); - if(index == -1) + if (index == -1) index = str.length(); int temp = 0; - for(int i = index-1; i>0; i--){ + for (int i = index - 1; i > 0; i--) { temp++; - if(temp%3 == 0){ + if (temp % 3 == 0) { temp = 0; - if(i==1 && str.charAt(0) == '-') + if (i == 1 && str.charAt(0) == '-') break; - str = str.substring(0,i)+","+str.substring(i); + str = str.substring(0, i) + "," + str.substring(i); } } return str; @@ -146,12 +146,12 @@ private boolean isRoot(String string) { public static String roundMyAnswer(String ans) { String precision = preferences.getStringPreference(AppPreferences.APP_ANSWER_PRECISION); - BigDecimal num = new BigDecimal(ans); + BigDecimal num = new BigDecimal(ans); num = num.setScale(getPrecision(precision), RoundingMode.HALF_UP); num = num.stripTrailingZeros(); - if(num.compareTo(new BigDecimal("0")) == 0) + if (num.compareTo(new BigDecimal("0")) == 0) return "0"; return num.toPlainString(); } @@ -206,7 +206,7 @@ private Double solveRoot(Stack gg) { //returns factorial of a number private static BigInteger factorial(int n) { BigInteger offset = new BigInteger("1"); - if(n < 0){ + if (n < 0) { offset = new BigInteger("-1"); n = -n; } @@ -273,8 +273,8 @@ private String getAnswer(String equation) { equation = equation.replaceAll("e", Math.E + ""); equation = equation.replaceAll("\u03c0", "" + Math.PI); equation = equation.replaceAll("-", "+-"); - equation = equation.replaceAll("\\^\\+-","^-"); - equation = equation.replaceAll("\\(\\+-","(-"); + equation = equation.replaceAll("\\^\\+-", "^-"); + equation = equation.replaceAll("\\(\\+-", "(-"); equation = equation.replaceAll("(\\*\\+)", "*"); equation = equation.replaceAll("(\\/\\+)", "/"); equation = equation.replaceAll("(\\+\\+)", "+"); @@ -283,8 +283,8 @@ private String getAnswer(String equation) { equation = equation.replaceAll("\\-\\)", ")"); equation = equation.replaceAll("\\/\\)", ")"); equation = equation.replaceAll("\\*\\)", ")"); - equation = equation.replaceAll("\\.\\)",")"); - equation = equation.replaceAll("\\^\\)",")"); + equation = equation.replaceAll("\\.\\)", ")"); + equation = equation.replaceAll("\\^\\)", ")"); char c = equation.charAt(equation.length() - 1); @@ -367,7 +367,7 @@ private String getAnswer(String equation) { //solves sub-equations without brackets //this is the method where actual calculations happen - private String getValue(Stack token) throws Exception{ + private String getValue(Stack token) throws Exception { String temp; Stack stack = new Stack<>(); Stack workingStack = token; @@ -733,30 +733,30 @@ private String getValue(Stack token) throws Exception{ case "%": num1 = Double.parseDouble(stack.pop()); - if(stack.size() >=2 && (stack.peek().equals("+") || stack.peek().equals("-"))) { + if (stack.size() >= 2 && (stack.peek().equals("+") || stack.peek().equals("-"))) { String op = stack.pop(); Stack tempStack = new Stack<>(); - while (!stack.empty()){ + while (!stack.empty()) { tempStack.push(stack.pop()); } String tempAns = getValue(tempStack); - if(tempAns == null) { + if (tempAns == null) { errMsg = "Invalid Expression"; return null; } Double num = Double.parseDouble(tempAns); - num1 = ((num1/100) * num); + num1 = ((num1 / 100) * num); - if(op.equals("+")){ - num+=num1; - } else if(op.equals("-")) { - num-=num1; + if (op.equals("+")) { + num += num1; + } else if (op.equals("-")) { + num -= num1; } - stack.push(num+""); + stack.push(num + ""); break; } num1 = num1 / 100; @@ -768,7 +768,7 @@ private String getValue(Stack token) throws Exception{ return null; } int a = Integer.parseInt(stack.pop()); - if(a > 50){ + if (a > 50) { errMsg = "Number too large"; return null; } @@ -839,7 +839,7 @@ private String getValue(Stack token) throws Exception{ return null; } - num1 = num1.divide(num2,15,RoundingMode.HALF_UP); + num1 = num1.divide(num2, 15, RoundingMode.HALF_UP); val1 = num1.toPlainString(); stack.push(val1); } else { @@ -935,7 +935,7 @@ private String getValue(Stack token) throws Exception{ } static boolean isAnError(String string) { - return (string.equals("Invalid Expression") || + return (string.equals("Invalid Expression") || string.equals("Domain error") || string.equals("Cannot divide by 0") || string.equals("Number too large")); diff --git a/app/src/main/java/com/example/arch1/testapplication/GeneralSettingsActivity.java b/app/src/main/java/com/example/arch1/testapplication/GeneralSettingsActivity.java index 9d0668a..933d798 100644 --- a/app/src/main/java/com/example/arch1/testapplication/GeneralSettingsActivity.java +++ b/app/src/main/java/com/example/arch1/testapplication/GeneralSettingsActivity.java @@ -1,10 +1,14 @@ package com.example.arch1.testapplication; import android.content.res.TypedArray; + import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; + import android.os.Bundle; + import androidx.appcompat.widget.Toolbar; + import android.util.TypedValue; import android.view.View; import android.widget.CompoundButton; @@ -30,15 +34,15 @@ protected void onCreate(Bundle savedInstanceState) { String themeName = preferences.getStringPreference(AppPreferences.APP_THEME); TypedValue typedValue = new TypedValue(); - TypedArray a = obtainStyledAttributes(typedValue.data, new int[] { R.attr.colorPrimary }); + TypedArray a = obtainStyledAttributes(typedValue.data, new int[]{R.attr.colorPrimary}); int color = a.getColor(0, 0); a.recycle(); - if(themeName.equals(Theme.DEFAULT)) { + if (themeName.equals(Theme.DEFAULT)) { color = getResources().getColor(R.color.colorMaterialSteelGrey); toolbar.setTitleTextColor(getResources().getColor(R.color.colorWhite)); toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp); - } else if(themeName.equals(Theme.MATERIAL_LIGHT)) { + } else if (themeName.equals(Theme.MATERIAL_LIGHT)) { toolbar.setTitleTextColor(getResources().getColor(R.color.gray)); toolbar.setNavigationIcon(R.drawable.ic_arrow_back_black_24dp); } else { @@ -68,14 +72,14 @@ public void onClick(View v) { numberFormatterSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - preferences.setBooleanPreference(AppPreferences.APP_NUMBER_FORMATTER,isChecked); + preferences.setBooleanPreference(AppPreferences.APP_NUMBER_FORMATTER, isChecked); } }); smartCalculationSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if(!isChecked){ + if (!isChecked) { //show warning AlertDialog.Builder builder = new AlertDialog.Builder(GeneralSettingsActivity.this); builder.setTitle("Warning") @@ -83,10 +87,10 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { " will no longer be able to auto-complete or auto-correct " + "your equations. We recommend to enable this feature for faster and " + "easy usage of Calculator Plus.") - .setPositiveButton("Ok",null); + .setPositiveButton("Ok", null); builder.show(); } - preferences.setBooleanPreference(AppPreferences.APP_SMART_CALCULATIONS,isChecked); + preferences.setBooleanPreference(AppPreferences.APP_SMART_CALCULATIONS, isChecked); } }); diff --git a/app/src/main/java/com/example/arch1/testapplication/HistoryActivity.java b/app/src/main/java/com/example/arch1/testapplication/HistoryActivity.java index e8bd8b9..6c9cdf7 100644 --- a/app/src/main/java/com/example/arch1/testapplication/HistoryActivity.java +++ b/app/src/main/java/com/example/arch1/testapplication/HistoryActivity.java @@ -2,11 +2,15 @@ import android.content.Intent; import android.content.res.TypedArray; + import androidx.appcompat.app.AppCompatActivity; + import android.os.Bundle; + import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import androidx.appcompat.widget.Toolbar; + import android.util.TypedValue; import android.view.Menu; import android.view.MenuItem; @@ -40,15 +44,15 @@ protected void onCreate(Bundle savedInstanceState) { setSupportActionBar(toolbar); TypedValue typedValue = new TypedValue(); - TypedArray a = obtainStyledAttributes(typedValue.data, new int[] { R.attr.colorPrimary }); + TypedArray a = obtainStyledAttributes(typedValue.data, new int[]{R.attr.colorPrimary}); int color = a.getColor(0, 0); a.recycle(); - if(themeName.equals(Theme.DEFAULT)) { + if (themeName.equals(Theme.DEFAULT)) { color = getResources().getColor(R.color.colorMaterialSteelGrey); toolbar.setTitleTextColor(getResources().getColor(R.color.colorWhite)); toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp); - } else if(themeName.equals(Theme.MATERIAL_LIGHT)) { + } else if (themeName.equals(Theme.MATERIAL_LIGHT)) { toolbar.setTitleTextColor(getResources().getColor(R.color.gray)); toolbar.setNavigationIcon(R.drawable.ic_arrow_back_black_24dp); } else { @@ -112,7 +116,7 @@ public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.history_menu, menu); delItem = menu.getItem(0); - if(mAdapter.getItemCount() == 0){ + if (mAdapter.getItemCount() == 0) { menu.getItem(0).setVisible(false); } @@ -131,11 +135,11 @@ public boolean onOptionsItemSelected(MenuItem item) { } private void checkHistoryStatus() { - if(mAdapter.getItemCount() == 0){ + if (mAdapter.getItemCount() == 0) { recyclerView.setVisibility(View.GONE); noHistoryLayout.setVisibility(View.VISIBLE); - if(delItem!=null){ + if (delItem != null) { delItem.setVisible(false); } } diff --git a/app/src/main/java/com/example/arch1/testapplication/HistoryAdapter.java b/app/src/main/java/com/example/arch1/testapplication/HistoryAdapter.java index fd454f3..8be52ff 100644 --- a/app/src/main/java/com/example/arch1/testapplication/HistoryAdapter.java +++ b/app/src/main/java/com/example/arch1/testapplication/HistoryAdapter.java @@ -1,8 +1,10 @@ package com.example.arch1.testapplication; import android.content.Context; + import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; + import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/app/src/main/java/com/example/arch1/testapplication/ListAdapter.java b/app/src/main/java/com/example/arch1/testapplication/ListAdapter.java index 8eede5b..689e405 100644 --- a/app/src/main/java/com/example/arch1/testapplication/ListAdapter.java +++ b/app/src/main/java/com/example/arch1/testapplication/ListAdapter.java @@ -1,9 +1,11 @@ package com.example.arch1.testapplication; import android.content.Context; + import androidx.annotation.NonNull; import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.RecyclerView; + import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -86,27 +88,27 @@ private int getColor() { String theme = preferences.getStringPreference(AppPreferences.APP_THEME); switch (theme) { - case Theme.GREEN : + case Theme.GREEN: return R.color.colorMaterialGreen; - case Theme.ORANGE : + case Theme.ORANGE: return R.color.colorMaterialOrange; - case Theme.BLUE : + case Theme.BLUE: return R.color.colorMaterialBlue; - case Theme.RED : + case Theme.RED: return R.color.colorMaterialRed; - case Theme.LIGHT_GREEN : + case Theme.LIGHT_GREEN: return R.color.colorMaterialLGreen; - case Theme.PINK : + case Theme.PINK: return R.color.colorMaterialPink; - case Theme.PURPLE : + case Theme.PURPLE: return R.color.colorMaterialPurple; - case Theme.MATERIAL_LIGHT : + case Theme.MATERIAL_LIGHT: return R.color.colorMaterialBlue; - case Theme.MATERIAL_DARK : + case Theme.MATERIAL_DARK: return R.color.colorMaterialBlue; - case Theme.DEFAULT : + case Theme.DEFAULT: return R.color.colorMaterialSteelGrey; - default : + default: return R.color.colorMaterialBlue; } } diff --git a/app/src/main/java/com/example/arch1/testapplication/MainActivity.java b/app/src/main/java/com/example/arch1/testapplication/MainActivity.java index d6706aa..89af8cc 100644 --- a/app/src/main/java/com/example/arch1/testapplication/MainActivity.java +++ b/app/src/main/java/com/example/arch1/testapplication/MainActivity.java @@ -887,13 +887,13 @@ public void onClick(View v) { break; case R.id.mr: String memory = preferences.getStringPreference(AppPreferences.APP_MEMORY_VALUE); - if(!isEquationEmpty()) { + if (!isEquationEmpty()) { c = equ.charAt(equ.length() - 1); - if(equ.endsWith("%") || equ.endsWith(")") || equ.endsWith("e") || equ.endsWith("!") || equ.endsWith(piSymbol)) { + if (equ.endsWith("%") || equ.endsWith(")") || equ.endsWith("e") || equ.endsWith("!") || equ.endsWith(piSymbol)) { add(mulSymbol + memory); break; } - if(!isNumber(c)) { + if (!isNumber(c)) { add(memory); break; } @@ -903,7 +903,7 @@ public void onClick(View v) { break; case R.id.mplus: if (!result.getText().toString().isEmpty()) { - if(!preferences.getStringPreference(AppPreferences.APP_MEMORY_VALUE).equals("")) { + if (!preferences.getStringPreference(AppPreferences.APP_MEMORY_VALUE).equals("")) { Double init = Double.parseDouble(preferences.getStringPreference(AppPreferences.APP_MEMORY_VALUE)); Double res = Double.parseDouble(result.getText().toString()); res = init + res; @@ -913,7 +913,7 @@ public void onClick(View v) { break; case R.id.mminus: if (!result.getText().toString().isEmpty()) { - if(!preferences.getStringPreference(AppPreferences.APP_MEMORY_VALUE).equals("")) { + if (!preferences.getStringPreference(AppPreferences.APP_MEMORY_VALUE).equals("")) { Double init = Double.parseDouble(preferences.getStringPreference(AppPreferences.APP_MEMORY_VALUE)); Double res = Double.parseDouble(result.getText().toString()); res = init - res; diff --git a/app/src/main/java/com/example/arch1/testapplication/Theme.java b/app/src/main/java/com/example/arch1/testapplication/Theme.java index 152b8fb..2336522 100644 --- a/app/src/main/java/com/example/arch1/testapplication/Theme.java +++ b/app/src/main/java/com/example/arch1/testapplication/Theme.java @@ -16,64 +16,64 @@ class Theme { static int getTheme(String themeName) { switch (themeName) { - case GREEN : + case GREEN: return R.style.GreenAppTheme; - case ORANGE : + case ORANGE: return R.style.AppTheme; - case BLUE : + case BLUE: return R.style.BlueAppTheme; - case RED : + case RED: return R.style.RedAppTheme; - case LIGHT_GREEN : + case LIGHT_GREEN: return R.style.LightGreenAppTheme; - case PINK : + case PINK: return R.style.PinkAppTheme; - case PURPLE : + case PURPLE: return R.style.PurpleAppTheme; - case MATERIAL_LIGHT : + case MATERIAL_LIGHT: return R.style.MaterialLight; - case MATERIAL_DARK : + case MATERIAL_DARK: return R.style.MaterialDark; - case DEFAULT : + case DEFAULT: return R.style.DefAppTheme; - default : + default: return R.style.MaterialLight; } } static void changeTheme(String themeName, AppPreferences preferences) { switch (themeName) { - case GREEN : + case GREEN: preferences.setStringPreference(AppPreferences.APP_THEME, GREEN); break; - case ORANGE : + case ORANGE: preferences.setStringPreference(AppPreferences.APP_THEME, ORANGE); break; - case BLUE : + case BLUE: preferences.setStringPreference(AppPreferences.APP_THEME, BLUE); break; - case RED : + case RED: preferences.setStringPreference(AppPreferences.APP_THEME, RED); break; - case LIGHT_GREEN : + case LIGHT_GREEN: preferences.setStringPreference(AppPreferences.APP_THEME, LIGHT_GREEN); break; - case PINK : + case PINK: preferences.setStringPreference(AppPreferences.APP_THEME, PINK); break; - case PURPLE : + case PURPLE: preferences.setStringPreference(AppPreferences.APP_THEME, PURPLE); break; - case MATERIAL_LIGHT : + case MATERIAL_LIGHT: preferences.setStringPreference(AppPreferences.APP_THEME, MATERIAL_LIGHT); break; - case MATERIAL_DARK : + case MATERIAL_DARK: preferences.setStringPreference(AppPreferences.APP_THEME, MATERIAL_DARK); break; - case DEFAULT : + case DEFAULT: preferences.setStringPreference(AppPreferences.APP_THEME, DEFAULT); break; - default : + default: preferences.setStringPreference(AppPreferences.APP_THEME, MATERIAL_LIGHT); } } @@ -84,37 +84,37 @@ static ListData getThemeData(String themeName) { data.setImg(R.drawable.ic_outline_color_lens_24px); switch (themeName) { - case GREEN : + case GREEN: data.setBody("Green"); break; - case ORANGE : + case ORANGE: data.setBody("Orange"); break; - case BLUE : + case BLUE: data.setBody("Blue"); break; - case RED : + case RED: data.setBody("Red"); break; - case LIGHT_GREEN : + case LIGHT_GREEN: data.setBody("Light Green"); break; - case PINK : + case PINK: data.setBody("Pink"); break; - case PURPLE : + case PURPLE: data.setBody("Purple"); break; - case MATERIAL_LIGHT : + case MATERIAL_LIGHT: data.setBody("Material Light"); break; - case MATERIAL_DARK : + case MATERIAL_DARK: data.setBody("Material Dark"); break; - case DEFAULT : + case DEFAULT: data.setBody("Classic"); break; - default : + default: data.setBody("Material Light"); } diff --git a/app/src/main/java/com/example/arch1/testapplication/ThemeActivity.java b/app/src/main/java/com/example/arch1/testapplication/ThemeActivity.java index 5f80469..57dfd63 100644 --- a/app/src/main/java/com/example/arch1/testapplication/ThemeActivity.java +++ b/app/src/main/java/com/example/arch1/testapplication/ThemeActivity.java @@ -84,7 +84,7 @@ public void onClick(View v) { private void changeTheme(String themeName) { String currTheme = preferences.getStringPreference(AppPreferences.APP_THEME); - if(currTheme.equals(themeName)) + if (currTheme.equals(themeName)) return; Theme.changeTheme(themeName, preferences); Intent intent[] = new Intent[3];