Skip to content

Latest commit

 

History

History
166 lines (125 loc) · 4.82 KB

File metadata and controls

166 lines (125 loc) · 4.82 KB

Android Calculator

An Android calculator application implementing basic and scientific mathematical operations with custom expression parsing.

Features

  • Basic arithmetic operations (addition, subtraction, multiplication, division)
  • Scientific functions (trigonometric, logarithmic, exponential)
  • Expression parsing with operator precedence and parentheses
  • Multiple numbering system support (international, Arabic-Indic, etc.)
  • Calculation history with persistent storage
  • Theme configuration (light, dark, AMOLED)
  • Precision control for decimal output
  • Scientific notation support
  • Quick Settings tile integration

Screenshots

Here are a few screens to give you a quick feel for the app:

Calculator Screenshot 1 Calculator Screenshot 2 Calculator Screenshot 3

Calculator Screenshot 4 Calculator Screenshot 5 Calculator Screenshot 6

Technical Details

Technology Stack

  • Language: Kotlin
  • Platform: Android (API 21-34)
  • Build System: Gradle with Kotlin DSL
  • UI: Android Views with View Binding
  • Architecture: Activity-based with service components

Core Components

Calculator Engine (calculator/Calculator.kt)

  • Mathematical expression evaluation using BigDecimal for precision
  • Supports trigonometric, logarithmic, and exponential functions
  • Handles special cases (division by zero, domain errors, syntax errors)

Expression Parser (calculator/parser/Expression.kt)

  • Converts user input into evaluable mathematical expressions
  • Handles symbol substitution (× → *, ÷ → /)
  • Manages operator precedence and parentheses
  • Formats percentage calculations

History Management (history/History.kt)

  • JSON-based storage using Gson
  • Persistent calculation records with timestamps
  • Configurable history limits

Project Structure

app/src/main/
├── java/com/android/calculator/
│   ├── activities/           # Activity classes (MainActivity, SettingsActivity, AboutActivity)
│   ├── calculator/           # Core calculation logic
│   │   ├── Calculator.kt     # Mathematical operations implementation
│   │   └── parser/           # Expression parsing utilities
│   ├── history/              # Calculation history management
│   ├── services/             # Background services (Quick Settings tile)
│   └── util/                 # Utility classes (theme, preferences, scientific mode)
└── res/                      # Android resources (layouts, values, drawables)

Building the Project

Prerequisites

  • Android Studio Hedgehog (2023.1.1) or later
  • JDK 8 or higher
  • Android SDK with API 34
  • Gradle 8.0+

Build Commands

Clone the repository and build using the Gradle wrapper.

Windows (PowerShell/CMD):

REM Clone repository
git clone https://github.com/HRG-OFFICIAL/Android-Calculator.git
cd Android-Calculator

REM Build debug APK
gradlew.bat assembleDebug

REM Install on connected device
gradlew.bat installDebug

REM Run unit tests
gradlew.bat testDebugUnitTest

REM Run instrumented tests
gradlew.bat connectedAndroidTest

macOS/Linux (bash/zsh):

# Clone repository
git clone https://github.com/HRG-OFFICIAL/Android-Calculator.git
cd Android-Calculator

# Build debug APK
./gradlew assembleDebug

# Install on connected device
./gradlew installDebug

# Run unit tests
./gradlew testDebugUnitTest

# Run instrumented tests
./gradlew connectedAndroidTest

Configuration

Supported Operations

  • Arithmetic: +, -, ×, ÷
  • Exponentiation: ^, E (scientific notation)
  • Functions: sin, cos, tan, ln, log, log₂, , !
  • Constants: π, e
  • Parentheses for precedence control

Precision Settings

  • Configurable decimal places (0-15)
  • Scientific notation toggle
  • Rounding mode: HALF_UP

Testing

Unit tests are located in app/src/test/java/ and cover:

  • Expression parsing
  • Mathematical operations
  • Edge cases (division by zero, invalid operations)

Run tests:

./gradlew test

Permissions

  • VIBRATE: Haptic feedback on button presses
  • SYSTEM_ALERT_WINDOW: Display overlay for quick access
  • USE_FULL_SCREEN_INTENT: Quick Settings tile functionality

Support

If you find this project useful and would like to support its development, you can:

  • Star this repository
  • Report bugs or suggest features
  • Buy me a coffee to support continued development

License

This project is licensed under the MIT License - see LICENSE file for details.