Skip to content

Commit

Permalink
Merge pull request #20 from arch10/beta
Browse files Browse the repository at this point in the history
New Theme page
  • Loading branch information
arch10 authored Apr 21, 2019
2 parents a519058 + c64846b commit 256f4ae
Show file tree
Hide file tree
Showing 14 changed files with 707 additions and 276 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
71 changes: 39 additions & 32 deletions app/src/main/java/com/example/arch1/testapplication/Evaluate.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -111,26 +111,26 @@ 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)
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;
}

//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);
}

Expand All @@ -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();
}
Expand Down Expand Up @@ -206,7 +206,7 @@ private Double solveRoot(Stack<String> 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;
}
Expand Down Expand Up @@ -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':
Expand All @@ -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("(\\+\\+)", "+");
Expand All @@ -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);

Expand Down Expand Up @@ -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<String> token) throws Exception{
private String getValue(Stack<String> token) throws Exception {
String temp;
Stack<String> stack = new Stack<>();
Stack<String> workingStack = token;
Expand Down Expand Up @@ -733,30 +733,30 @@ private String getValue(Stack<String> 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<String> 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;
Expand All @@ -768,7 +768,7 @@ private String getValue(Stack<String> token) throws Exception{
return null;
}
int a = Integer.parseInt(stack.pop());
if(a > 50){
if (a > 50) {
errMsg = "Number too large";
return null;
}
Expand Down Expand Up @@ -839,7 +839,7 @@ private String getValue(Stack<String> 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 {
Expand Down Expand Up @@ -934,4 +934,11 @@ private String getValue(Stack<String> 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"));
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -68,25 +72,25 @@ 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")
.setMessage("This action will disable smart calculations. Calculator Plus" +
" 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);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Loading

0 comments on commit 256f4ae

Please sign in to comment.