Skip to content

Commit

Permalink
Merge pull request #38 from mplekunov/Version_In_Progress
Browse files Browse the repository at this point in the history
Version 3.0
  • Loading branch information
mplekunov authored Jun 8, 2022
2 parents a8fd4df + fe09d9c commit 24ddf82
Show file tree
Hide file tree
Showing 42 changed files with 1,482 additions and 555 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
.cxx
local.properties
/app/release/
/app/CalculatorApp/
29 changes: 28 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ android {
productFlavors {
CalculatorApp {
dimension 'CalculatorApp'
versionCode 2
versionName '2.1'
versionCode 3
versionName '3.0'
}
}
}
Expand All @@ -53,7 +53,7 @@ dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.6.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'

// Nav Bar
implementation("androidx.navigation:navigation-fragment-ktx:2.4.2")
Expand All @@ -68,6 +68,9 @@ dependencies {
implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:2.4.1"
implementation 'androidx.legacy:legacy-support-v4:1.0.0'

implementation 'androidx.preference:preference-ktx:1.2.0'
implementation 'androidx.preference:preference:1.2.0'

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'

Expand Down
6 changes: 3 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:label="Calculator"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Calculator">
android:theme="@style/Theme.Calculator.DayNight">

<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Expand Down
76 changes: 60 additions & 16 deletions app/src/main/java/com/example/calculator/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,26 +1,70 @@
package com.example.calculator

import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.os.PersistableBundle
import android.view.View
import android.util.TypedValue
import android.view.Menu
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.NavController
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.setupActionBarWithNavController
import androidx.core.content.ContextCompat
import androidx.navigation.findNavController
import androidx.preference.PreferenceManager
import com.example.calculator.model.settings.SettingsManager

class MainActivity : AppCompatActivity(R.layout.activity_main) {
private lateinit var navController: NavController
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
super.onCreate(savedInstanceState, persistentState)
loadDefaultSettings()
setSupportActionBar(findViewById(R.id.toolbar))
}

private fun loadDefaultSettings() {
val settingsManager = SettingsManager(this)

val typedValue = TypedValue()
theme.resolveAttribute(com.google.android.material.R.attr.colorOnPrimary, typedValue, true)

// settingsManager.setColor(R.string.saved_input_font_color_key, ContextCompat.getColor(this, typedValue.resourceId))
settingsManager.setColor(R.string.saved_output_font_color_key, ContextCompat.getColor(this, typedValue.resourceId))

settingsManager.setColor(R.string.saved_number_button_color_key, ContextCompat.getColor(this, typedValue.resourceId))
settingsManager.setColor(R.string.saved_function_button_color_key, resources.getColor(R.color.calc_function_button, theme))
settingsManager.setColor(R.string.saved_operator_button_color_key, resources.getColor(R.color.calc_operation_button, theme))

settingsManager.setColor(R.string.saved_clear_button_color_key, resources.getColor(R.color.calc_clear_button, theme))
settingsManager.setColor(R.string.saved_clear_all_button_color_key, resources.getColor(R.color.calc_clear_all_button, theme))

// val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
// navController = navHostFragment.navController
//
// setupActionBarWithNavController(navController)
settingsManager.setColor(R.string.saved_disabled_button_color_key, resources.getColor(R.color.calc_disabled_button, theme))
settingsManager.setColor(R.string.saved_highlighting_color_key, resources.getColor(R.color.highlighted_text, theme))

// settingsManager.setString(R.string.saved_input_font_size_key, "35")
// settingsManager.setString(R.string.saved_output_font_size_key, "20")
}


override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.menu, menu)
return true
}

// override fun onSupportNavigateUp(): Boolean {
// return navController.navigateUp() || super.onSupportNavigateUp()
// }
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when(item.itemId) {
R.id.settings_item -> {
findNavController(R.id.nav_host_fragment).navigate(R.id.action_calculatorFragment_to_settingsFragment)
true
}
R.id.about_item -> {
val intent = Intent(Intent.ACTION_VIEW)
intent.data = Uri.parse("https://github.com/mplekunov/CalculatorApp")

startActivity(intent)
true
}
else -> super.onOptionsItemSelected(item)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.example.calculator.converter

import androidx.core.graphics.*

object ColorConverter {
fun toHexColor(color: Int): String {
var alpha = color.alpha.toString(16)
if (alpha.length == 1)
alpha = "0$alpha"

var red = color.red.toString(16)
if (red.length == 1)
red = "0$red"

var green = color.green.toString(16)
if (green.length == 1)
green = "0$green"

var blue = color.blue.toString(16)
if (blue.length == 1)
blue = "0$blue"

return "#$alpha$red$green$blue"
}

fun toIntColor(color: String): Int {
return color.toColorInt()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ object TokenFormatter {
*/
fun convertTokenToString(token: Token?, removeTrailingZeroes: Boolean): String {
if (token == null || token.isEmpty())
return " 0 "
return " 0"
return if (token.type == TokenTypes.Number) {
return when (token) {
NumberParser.parse(NumberKind.INFINITY) -> " $token"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,15 @@ class Expression {
*/
private fun processMinusSign(token: Token, index: Int) : Boolean {
val leftParenthesis = OperatorParser.parse(OperatorKind.LEFT_BRACKET)
val rightParenthesis = OperatorParser.parse(OperatorKind.RIGHT_BRACKET)

// Minus sign can be in the beginning of an expression
if (_expression.isEmpty())
return _expression.add(OperatorParser.parse(OperatorKind.SUBTRACTION))

// Minus sign can be after left parenthesis
return if (_expression.last().type == TokenTypes.Operator) {
if (_expression.last() == leftParenthesis)
if (_expression.last() == leftParenthesis || _expression.last() == rightParenthesis)
_expression.add(OperatorParser.parse(OperatorKind.SUBTRACTION))
else {
_expression.add(OperatorParser.parse(OperatorKind.LEFT_BRACKET)) &&
Expand Down
Loading

0 comments on commit 24ddf82

Please sign in to comment.