├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── drawable
│ │ │ │ ├── triangle.png
│ │ │ │ ├── textview_background.xml
│ │ │ │ ├── textview_background_bold.xml
│ │ │ │ ├── side_nav_bar.xml
│ │ │ │ ├── ic_menu_send.xml
│ │ │ │ ├── ic_menu_slideshow.xml
│ │ │ │ ├── ic_menu_gallery.xml
│ │ │ │ ├── ic_menu_manage.xml
│ │ │ │ ├── ic_menu_camera.xml
│ │ │ │ ├── ic_menu_share.xml
│ │ │ │ ├── spinner_background.xml
│ │ │ │ └── ic_launcher_background.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── values
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── styles.xml
│ │ │ │ └── strings.xml
│ │ │ ├── values-v21
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── menu
│ │ │ │ ├── navigation_drawer.xml
│ │ │ │ └── activity_navigation_drawer_drawer.xml
│ │ │ ├── layout-land
│ │ │ │ ├── spinner_layout.xml
│ │ │ │ ├── content_navigation_drawer.xml
│ │ │ │ ├── activity_navigation_drawer.xml
│ │ │ │ ├── app_bar_navigation_drawer.xml
│ │ │ │ ├── nav_header_navigation_drawer.xml
│ │ │ │ ├── fragment_exchange_rate.xml
│ │ │ │ ├── fragment_converter.xml
│ │ │ │ └── fragment_home.xml
│ │ │ ├── layout
│ │ │ │ ├── spinner_layout.xml
│ │ │ │ ├── content_navigation_drawer.xml
│ │ │ │ ├── activity_navigation_drawer.xml
│ │ │ │ ├── app_bar_navigation_drawer.xml
│ │ │ │ ├── nav_header_navigation_drawer.xml
│ │ │ │ ├── fragment_converter.xml
│ │ │ │ ├── fragment_exchange_rate.xml
│ │ │ │ ├── fragment_home.xml
│ │ │ │ └── fragment_radix.xml
│ │ │ ├── navigation
│ │ │ │ └── mobile_navigation.xml
│ │ │ └── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── example
│ │ │ │ └── calculatorbyleafee
│ │ │ │ ├── lib
│ │ │ │ ├── expression
│ │ │ │ │ ├── ErrorExpressionException.java
│ │ │ │ │ └── Expression.java
│ │ │ │ └── datastructure
│ │ │ │ │ ├── EmptyContainerException.java
│ │ │ │ │ ├── Lnode.java
│ │ │ │ │ ├── Lstack.java
│ │ │ │ │ └── Lqueue.java
│ │ │ │ ├── ui
│ │ │ │ ├── radix
│ │ │ │ │ ├── RadixModel.java
│ │ │ │ │ └── RadixFragment.java
│ │ │ │ ├── sharedTools
│ │ │ │ │ └── CustomAdapter.java
│ │ │ │ ├── exchangeRate
│ │ │ │ │ ├── ExchangeRateModel.java
│ │ │ │ │ └── ExchangeRateFragment.java
│ │ │ │ ├── home
│ │ │ │ │ └── HomeFragment.java
│ │ │ │ └── converter
│ │ │ │ │ ├── ConverterModel.java
│ │ │ │ │ └── ConverterFragment.java
│ │ │ │ └── MainCalc.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── calculatorbyleafee
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── calculatorbyleafee
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .idea
├── vcs.xml
├── misc.xml
├── dictionaries
│ └── leafee98.xml
├── runConfigurations.xml
├── gradle.xml
└── codeStyles
│ └── Project.xml
├── .gitignore
├── gradle.properties
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 | rootProject.name='CalculatorByLeafee'
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafee98/CalculatorByLeafee/master/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/drawable/triangle.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafee98/CalculatorByLeafee/master/app/src/main/res/drawable/triangle.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafee98/CalculatorByLeafee/master/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafee98/CalculatorByLeafee/master/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafee98/CalculatorByLeafee/master/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafee98/CalculatorByLeafee/master/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafee98/CalculatorByLeafee/master/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafee98/CalculatorByLeafee/master/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafee98/CalculatorByLeafee/master/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafee98/CalculatorByLeafee/master/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafee98/CalculatorByLeafee/master/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafee98/CalculatorByLeafee/master/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Sep 04 09:40:46 CST 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/textview_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/textview_background_bold.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/side_nav_bar.xml:
--------------------------------------------------------------------------------
1 |
3 |
9 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_menu_send.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 8dp
6 | 176dp
7 | 16dp
8 |
--------------------------------------------------------------------------------
/.idea/dictionaries/leafee98.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | calculatorbyleafee
5 | gibi
6 | kibi
7 | leafee
8 | lqueue
9 | mebi
10 | numa
11 | orginal
12 | scur
13 | tcur
14 | textview
15 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/calculatorbyleafee/lib/expression/ErrorExpressionException.java:
--------------------------------------------------------------------------------
1 | package com.example.calculatorbyleafee.lib.expression;
2 |
3 | public class ErrorExpressionException extends Exception {
4 | private static final long serialVersionUID = 6602273568241636585L;
5 | public ErrorExpressionException(String message) {
6 | super(message);
7 | }
8 | public ErrorExpressionException() {
9 | super();
10 | }
11 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/example/calculatorbyleafee/lib/datastructure/EmptyContainerException.java:
--------------------------------------------------------------------------------
1 | package com.example.calculatorbyleafee.lib.datastructure;
2 |
3 | public class EmptyContainerException extends Exception {
4 | private static final long serialVersionUID = 6202378284826546585L;
5 | public EmptyContainerException(String message) {
6 | super(message);
7 | }
8 | public EmptyContainerException() {
9 | super();
10 | }
11 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/example/calculatorbyleafee/lib/datastructure/Lnode.java:
--------------------------------------------------------------------------------
1 | package com.example.calculatorbyleafee.lib.datastructure;
2 |
3 | public class Lnode {
4 | public type item;
5 | public Lnode next;
6 |
7 | public Lnode(type item, Lnode next) {
8 | this.item = item;
9 | this.next = next;
10 | }
11 | public Lnode(type item) {
12 | this.item = item;
13 | this.next = null;
14 | }
15 |
16 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_menu_slideshow.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_menu_gallery.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/navigation_drawer.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
--------------------------------------------------------------------------------
/app/src/test/java/com/example/calculatorbyleafee/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.example.calculatorbyleafee;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_menu_manage.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/layout-land/spinner_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/spinner_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
14 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_menu_camera.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_menu_share.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/example/calculatorbyleafee/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.example.calculatorbyleafee;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.platform.app.InstrumentationRegistry;
6 | import androidx.test.ext.junit.runners.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24 |
25 | assertEquals("com.example.calculatorbyleafee", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/activity_navigation_drawer_drawer.xml:
--------------------------------------------------------------------------------
1 |
2 |
29 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/content_navigation_drawer.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/layout-land/content_navigation_drawer.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | CalculatorByLeafee
3 | NavigationDrawerActivity
4 | Open navigation drawer
5 | Close navigation drawer
6 | Android Studio
7 | android.studio@android.com
8 | Navigation header
9 | Settings
10 |
11 | Home
12 | Gallery
13 | Slideshow
14 | Tools
15 | Share
16 | Send
17 |
18 |
19 | Hello blank fragment
20 |
21 |
22 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_navigation_drawer.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
15 |
16 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/layout-land/activity_navigation_drawer.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
15 |
16 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/app_bar_navigation_drawer.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/spinner_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
-
6 |
7 |
8 |
9 |
14 |
17 |
18 |
19 | -
23 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/res/layout-land/app_bar_navigation_drawer.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/res/navigation/mobile_navigation.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
19 |
20 |
25 |
26 |
31 |
32 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 29
5 | buildToolsVersion "29.0.2"
6 | defaultConfig {
7 | applicationId "com.example.calculatorbyleafee"
8 | minSdkVersion 27
9 | targetSdkVersion 29
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | implementation fileTree(dir: 'libs', include: ['*.jar'])
24 | implementation 'androidx.appcompat:appcompat:1.0.2'
25 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
26 | implementation 'androidx.legacy:legacy-support-v4:1.0.0'
27 | implementation 'com.google.android.material:material:1.0.0'
28 | implementation 'androidx.navigation:navigation-fragment:2.0.0'
29 | implementation 'androidx.navigation:navigation-ui:2.0.0'
30 | implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
31 | testImplementation 'junit:junit:4.12'
32 | androidTestImplementation 'androidx.test:runner:1.2.0'
33 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/calculatorbyleafee/ui/radix/RadixModel.java:
--------------------------------------------------------------------------------
1 | package com.example.calculatorbyleafee.ui.radix;
2 |
3 | class RadixModel {
4 |
5 | private int value;
6 |
7 | RadixModel() {
8 | this.value = 0;
9 | }
10 |
11 | void setDec(String val) {
12 | if (val.equals("")) {
13 | this.value = 0;
14 | } else {
15 | this.value = Integer.parseInt(val);
16 | }
17 | }
18 |
19 | void setBin(String val) {
20 | if (val.equals("")) {
21 | this.value = 0;
22 | } else {
23 | this.value = Integer.parseInt(val, 2);
24 | }
25 | }
26 |
27 | void setOct(String val) {
28 | if (val.equals("")) {
29 | this.value = 0;
30 | } else {
31 | this.value = Integer.parseInt(val, 8);
32 | }
33 | }
34 |
35 | void setHex(String val) {
36 | if (val.equals("")) {
37 | this.value = 0;
38 | } else {
39 | this.value = Integer.parseInt(val, 16);
40 | }
41 | }
42 |
43 | String getBin() {
44 | return Integer.toBinaryString(this.value);
45 | }
46 |
47 | String getOct() {
48 | return Integer.toOctalString(this.value);
49 | }
50 |
51 | String getDec() {
52 | return Integer.toString(this.value);
53 | }
54 |
55 | String getHex() {
56 | return Integer.toHexString(this.value).toUpperCase();
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/calculatorbyleafee/ui/sharedTools/CustomAdapter.java:
--------------------------------------------------------------------------------
1 | package com.example.calculatorbyleafee.ui.sharedTools;
2 |
3 | import android.content.Context;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.BaseAdapter;
8 | import android.widget.TextView;
9 |
10 | import com.example.calculatorbyleafee.R;
11 |
12 | import java.util.List;
13 |
14 | /*
15 | * this class is used to adapt String into spinner_layout
16 | */
17 | public class CustomAdapter extends BaseAdapter {
18 |
19 | private List list;
20 | private Context context;
21 |
22 | public CustomAdapter(Context context, List list) {
23 | this.context = context;
24 | this.list = list;
25 | }
26 |
27 | @Override
28 | public int getCount() {
29 | return list.size();
30 | }
31 |
32 | @Override
33 | public Object getItem(int i) {
34 | return list.get(i);
35 | }
36 |
37 | @Override
38 | public long getItemId(int i) {
39 | return i;
40 | }
41 |
42 | @Override
43 | public View getView(int i, View view, ViewGroup viewGroup) {
44 | LayoutInflater inflater = LayoutInflater.from(context);
45 | view = inflater.inflate(R.layout.spinner_layout, viewGroup, false);
46 | TextView tv = view.findViewById(R.id.textViewOfSpinner);
47 | tv.setText(list.get(i));
48 | return tv;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/nav_header_navigation_drawer.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
22 |
23 |
29 |
30 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/app/src/main/res/layout-land/nav_header_navigation_drawer.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
22 |
23 |
29 |
30 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/calculatorbyleafee/MainCalc.java:
--------------------------------------------------------------------------------
1 | package com.example.calculatorbyleafee;
2 |
3 | import androidx.appcompat.app.AppCompatActivity;
4 | import androidx.appcompat.widget.Toolbar;
5 | import androidx.drawerlayout.widget.DrawerLayout;
6 | import androidx.navigation.NavController;
7 | import androidx.navigation.Navigation;
8 | import androidx.navigation.ui.AppBarConfiguration;
9 | import androidx.navigation.ui.NavigationUI;
10 |
11 | import android.os.Bundle;
12 | import android.view.Menu;
13 |
14 | import com.google.android.material.navigation.NavigationView;
15 |
16 | public class MainCalc extends AppCompatActivity {
17 |
18 | private AppBarConfiguration mAppBarConfiguration;
19 |
20 | @Override
21 | protected void onCreate(Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | setContentView(R.layout.activity_navigation_drawer);
24 |
25 | Toolbar toolbar = findViewById(R.id.toolbar);
26 | setSupportActionBar(toolbar);
27 | DrawerLayout drawer = findViewById(R.id.drawer_layout);
28 | NavigationView navigationView = findViewById(R.id.nav_view);
29 | // Passing each menu ID as a set of Ids because each
30 | // menu should be considered as top level destinations.
31 | mAppBarConfiguration = new AppBarConfiguration.Builder(
32 | R.id.nav_home, R.id.nav_converter, R.id.nav_radix,
33 | R.id.nav_exchangeRate)
34 | .setDrawerLayout(drawer)
35 | .build();
36 | NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
37 | NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
38 | NavigationUI.setupWithNavController(navigationView, navController);
39 |
40 | }
41 |
42 | @Override
43 | public boolean onCreateOptionsMenu(Menu menu) {
44 | // Inflate the menu; this adds items to the action bar if it is present.
45 | getMenuInflater().inflate(R.menu.navigation_drawer, menu);
46 | return true;
47 | }
48 |
49 | @Override
50 | public boolean onSupportNavigateUp() {
51 | NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
52 | return NavigationUI.navigateUp(navController, mAppBarConfiguration)
53 | || super.onSupportNavigateUp();
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/calculatorbyleafee/lib/datastructure/Lstack.java:
--------------------------------------------------------------------------------
1 | package com.example.calculatorbyleafee.lib.datastructure;
2 |
3 | public class Lstack {
4 | private Lnode _top;
5 |
6 | public Lstack() {
7 | this._top = null;
8 | }
9 | public void push(type item) {
10 | if (_top == null) {
11 | _top = new Lnode(item);
12 | } else {
13 | _top = new Lnode(item, _top);
14 | }
15 | }
16 | public type pop() throws EmptyContainerException {
17 | try {
18 | Lnode temp = _top;
19 | this._top = this._top.next;
20 | return temp.item;
21 | } catch (NullPointerException nu) {
22 | throw new EmptyContainerException();
23 | }
24 | }
25 | public type top() throws EmptyContainerException {
26 | try {
27 | return _top.item;
28 | } catch (NullPointerException nu) {
29 | throw new EmptyContainerException();
30 | }
31 | }
32 | public boolean isempty() {
33 | return _top == null;
34 | }
35 | public String toString(String op) {
36 | StringBuilder str = new StringBuilder();
37 | str.append('[');
38 | for (Lnode temp = this._top; temp != null; temp = temp.next) {
39 | str.append(temp.item);
40 | if (temp.next != null)
41 | str.append(op);
42 | }
43 | str.append(']');
44 | return str.toString();
45 | }
46 | public String toString() {
47 | return this.toString("/");
48 | }
49 |
50 | public static void main(String[] args) throws EmptyContainerException {
51 | Lstack st = new Lstack();
52 |
53 | st.push("abc");
54 | System.out.println("push 'abc'");
55 | System.out.println("stack's top is " + st.top());
56 | System.out.println(st);
57 |
58 |
59 | st.push("def");
60 | System.out.println("push 'def'");
61 | System.out.println("stack's top is " + st.top());
62 | System.out.println(st);
63 |
64 | System.out.println("pop, and get " + st.pop());
65 | System.out.println("stack's top is " + st.top());
66 | System.out.println(st);
67 |
68 | System.out.println("Now, the stack is" + (st.isempty() ? " " : " not ") + "empty, let we try to pop");
69 | System.out.println("pop, and get " + st.pop());
70 | System.out.println(st);
71 |
72 | System.out.println("Now, the stack is" + (st.isempty() ? " " : " not ") + "empty, let we try to pop");
73 | System.out.println("As it is empty, it will throw and EmptyContainer Exception");
74 | System.out.println("pop, and get " + st.pop());
75 | System.out.println("stack's top is " + st.top());
76 | System.out.println(st);
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/calculatorbyleafee/ui/exchangeRate/ExchangeRateModel.java:
--------------------------------------------------------------------------------
1 | package com.example.calculatorbyleafee.ui.exchangeRate;
2 |
3 |
4 | import android.util.Log;
5 |
6 | import org.json.JSONException;
7 | import org.json.JSONObject;
8 |
9 | import java.io.BufferedReader;
10 | import java.io.InputStreamReader;
11 | import java.net.HttpURLConnection;
12 | import java.net.URL;
13 |
14 | class ExchangeRateModel {
15 |
16 | static class GetRateException extends Exception {
17 |
18 | static final long serialVersionUID = 7834659287346191237L;
19 |
20 | GetRateException(String msg) {
21 | super(msg);
22 | }
23 |
24 | }
25 |
26 | static double getRate(String scur, String tcur) throws JSONException, GetRateException {
27 | if (scur.equals(tcur)) {
28 | return 1.0;
29 | } else {
30 | String jsonContent;
31 | try {
32 | String querySite = "http://haobaoshui.com:8008/exchangerate/v1/rate?scur=%s&tcur=%s";
33 | URL queryUrl = new URL(String.format(querySite, scur, tcur));
34 | HttpURLConnection connection = (HttpURLConnection) queryUrl.openConnection();
35 | connection.setRequestMethod("GET");
36 | connection.setConnectTimeout(5000);
37 | connection.setReadTimeout(3000);
38 |
39 | Log.w("ExchangeRateModel scur is", scur);
40 | Log.w("ExchangeRateModel tcur is", tcur);
41 | Log.w("ExchangeRateModel URL", String.format(querySite, scur, tcur));
42 |
43 | // DataOutputStream output = new DataOutputStream(connection.getOutputStream());
44 | // output.writeBytes(String.format("scur=%s&tcur=%s", scur, tcur));
45 | // output.flush();
46 |
47 | BufferedReader input = new BufferedReader(new InputStreamReader(connection.getInputStream()));
48 | StringBuilder stringbuilder = new StringBuilder();
49 | String line;
50 | while ((line = input.readLine()) != null) {
51 | stringbuilder.append(line);
52 | }
53 | jsonContent = stringbuilder.toString();
54 | } catch (Exception e) {
55 | e.printStackTrace();
56 | throw new GetRateException(e.getMessage());
57 | }
58 |
59 | return getRateFromJSON(jsonContent);
60 | }
61 | }
62 |
63 | private static double getRateFromJSON(String JSON) throws JSONException {
64 | Log.w("ExchangeRateModel jsonContent is", JSON);
65 | JSONObject jsonObject = new JSONObject(JSON);
66 | return jsonObject.getDouble("rate");
67 | }
68 |
69 | static String getTarget(String original, double rate) {
70 | double originalValue;
71 | try {
72 | originalValue = Double.parseDouble(original);
73 | return String.valueOf(originalValue * rate);
74 | } catch (NumberFormatException e) {
75 | e.printStackTrace();
76 | return "Number Format Error!";
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/calculatorbyleafee/lib/datastructure/Lqueue.java:
--------------------------------------------------------------------------------
1 | package com.example.calculatorbyleafee.lib.datastructure;
2 |
3 | public class Lqueue {
4 | private Lnode head;
5 | private Lnode tail;
6 |
7 | public Lqueue() {
8 | this.head = this.tail = null;
9 | }
10 | public void push(type item) {
11 | if (this.head == null) {
12 | this.head = this.tail = new Lnode(item);
13 | } else {
14 | this.tail.next = new Lnode(item);
15 | this.tail = this.tail.next;
16 | }
17 | }
18 | public type pop() throws EmptyContainerException {
19 | if (this.head == null)
20 | throw new EmptyContainerException();
21 |
22 | if (this.head == this.tail) {
23 | Lnode temp = this.head;
24 | this.head = this.tail = null;
25 | return temp.item;
26 | } else {
27 | Lnode temp = this.head;
28 | this.head = this.head.next;
29 | return temp.item;
30 | }
31 | }
32 | public type front() throws EmptyContainerException {
33 | try {
34 | return head.item;
35 | } catch (NullPointerException e) {
36 | throw new EmptyContainerException();
37 | }
38 | }
39 | public type back() throws EmptyContainerException {
40 | try {
41 | return tail.item;
42 | } catch (NullPointerException e) {
43 | throw new EmptyContainerException();
44 | }
45 | }
46 | public boolean isempty() {
47 | return this.head == null;
48 | }
49 | public String toString(String op) {
50 | StringBuilder str = new StringBuilder();
51 | str.append('[');
52 | for (Lnode temp = this.head; temp != null; temp = temp.next) {
53 | str.append(temp.item);
54 | if (temp.next != null) {
55 | str.append(op);
56 | }
57 | }
58 | str.append(']');
59 | return str.toString();
60 | }
61 | public String toString() {
62 | return this.toString("<-");
63 | }
64 |
65 | public static void main(String[] args) throws EmptyContainerException {
66 | Lqueue queue = new Lqueue();
67 |
68 | queue.push("abc");
69 | System.out.println("push abc");
70 | System.out.println("queue's front is " + queue.front());
71 | System.out.println("queue's back is " + queue.back());
72 | System.out.println(queue);
73 |
74 | queue.push("def");
75 | System.out.println("push def");
76 | System.out.println("queue's front is " + queue.front());
77 | System.out.println("queue's back is " + queue.back());
78 | System.out.println(queue);
79 |
80 | System.out.println("pop, and get " + queue.pop());
81 | System.out.println("queue's front is " + queue.front());
82 | System.out.println("queue's back is " + queue.back());
83 | System.out.println(queue);
84 |
85 | System.out.println("Now, the queue is" + (queue.isempty() ? " " : " not ") + "empty, let we try to pop");
86 | System.out.println("pop, and get " + queue.pop());
87 | System.out.println(queue);
88 |
89 | System.out.println("Now, the queue is" + (queue.isempty() ? " " : " not ") + "empty, let we try to pop");
90 | System.out.println("As it is empty, it should throw EmptyContainerException");
91 | System.out.println("pop, and get " + queue.pop());
92 | }
93 | }
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | xmlns:android
14 |
15 | ^$
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | xmlns:.*
25 |
26 | ^$
27 |
28 |
29 | BY_NAME
30 |
31 |
32 |
33 |
34 |
35 |
36 | .*:id
37 |
38 | http://schemas.android.com/apk/res/android
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | .*:name
48 |
49 | http://schemas.android.com/apk/res/android
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 | name
59 |
60 | ^$
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | style
70 |
71 | ^$
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 | .*
81 |
82 | ^$
83 |
84 |
85 | BY_NAME
86 |
87 |
88 |
89 |
90 |
91 |
92 | .*
93 |
94 | http://schemas.android.com/apk/res/android
95 |
96 |
97 | ANDROID_ATTRIBUTE_ORDER
98 |
99 |
100 |
101 |
102 |
103 |
104 | .*
105 |
106 | .*
107 |
108 |
109 | BY_NAME
110 |
111 |
112 |
113 |
114 |
115 |
116 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/calculatorbyleafee/ui/home/HomeFragment.java:
--------------------------------------------------------------------------------
1 | package com.example.calculatorbyleafee.ui.home;
2 |
3 | import android.os.Bundle;
4 | import android.util.Log;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.TextView;
9 |
10 | import androidx.annotation.NonNull;
11 | import androidx.fragment.app.Fragment;
12 |
13 | import com.example.calculatorbyleafee.R;
14 | import com.example.calculatorbyleafee.lib.expression.ErrorExpressionException;
15 | import com.example.calculatorbyleafee.lib.expression.Expression;
16 |
17 | import java.util.Arrays;
18 | import java.util.List;
19 | import java.util.Locale;
20 |
21 | public class HomeFragment extends Fragment {
22 |
23 | private View root;
24 |
25 | private static class InputHandler implements View.OnClickListener {
26 | private TextView textView;
27 | private StringBuilder expression = new StringBuilder();
28 |
29 | InputHandler(TextView textView) {
30 | this.textView = textView;
31 | }
32 |
33 | @Override
34 | public void onClick(View view) {
35 | switch (view.getId()) {
36 | case R.id.button_numPoint: expression.append('.'); break;
37 | case R.id.button_num0: expression.append('0'); break;
38 | case R.id.button_num1: expression.append('1'); break;
39 | case R.id.button_num2: expression.append('2'); break;
40 | case R.id.button_num3: expression.append('3'); break;
41 | case R.id.button_num4: expression.append('4'); break;
42 | case R.id.button_num5: expression.append('5'); break;
43 | case R.id.button_num6: expression.append('6'); break;
44 | case R.id.button_num7: expression.append('7'); break;
45 | case R.id.button_num8: expression.append('8'); break;
46 | case R.id.button_num9: expression.append('9'); break;
47 | case R.id.button_opPlus: expression.append('+'); break;
48 | case R.id.button_opMinus: expression.append('-'); break;
49 | case R.id.button_opMulti: expression.append('*'); break;
50 | case R.id.button_opDiv: expression.append('/'); break;
51 | case R.id.button_opPow: expression.append('^'); break;
52 | case R.id.button_opSin: expression.append("sin("); break;
53 | case R.id.button_opCos: expression.append("cos("); break;
54 | case R.id.button_opTan: expression.append("tan("); break;
55 | case R.id.button_opMod: expression.append("mod"); break;
56 | case R.id.button_opLeftParentheses: expression.append('('); break;
57 | case R.id.button_opRightParentheses: expression.append(')'); break;
58 |
59 | case R.id.button_clearAll:
60 | expression = new StringBuilder();
61 | break;
62 |
63 | case R.id.button_backspace:
64 | try {
65 | expression.deleteCharAt(expression.length() - 1);
66 | } catch (StringIndexOutOfBoundsException e) {
67 | Log.d("input expression",
68 | "backspace while expression zero length");
69 | }
70 | break;
71 | case R.id.button_opEqual:
72 | if (expression.toString().length() > 0) {
73 | try {
74 | expression = new StringBuilder(
75 | String.format(Locale.ENGLISH, "%.7f",
76 | Expression.calculate(expression.toString(), true)));
77 | } catch (ErrorExpressionException e) {
78 | String msg = e.getMessage();
79 | if (msg != null) {
80 | expression = new StringBuilder(msg);
81 | } else {
82 | expression = new StringBuilder("Unknown Error");
83 | }
84 | }
85 | }
86 | break;
87 | }
88 |
89 | textView.setText(expression.toString());
90 | }
91 | }
92 |
93 | public View onCreateView(@NonNull LayoutInflater inflater,
94 | ViewGroup container, Bundle savedInstanceState) {
95 | root = inflater.inflate(R.layout.fragment_home, container, false);
96 |
97 | // set onClick Listener
98 | List buttonsId = Arrays.asList(
99 | R.id.button_num0, R.id.button_num1, R.id.button_num2, R.id.button_num3,
100 | R.id.button_num4, R.id.button_num5, R.id.button_num6, R.id.button_num7,
101 | R.id.button_num8, R.id.button_num9, R.id.button_numPoint,
102 | R.id.button_opPlus, R.id.button_opMinus, R.id.button_opMulti, R.id.button_opDiv,
103 | R.id.button_opLeftParentheses, R.id.button_opRightParentheses,
104 | R.id.button_opPow, R.id.button_opMod, R.id.button_opEqual,
105 | R.id.button_opSin, R.id.button_opCos, R.id.button_opTan,
106 | R.id.button_clearAll, R.id.button_backspace
107 | );
108 |
109 | TextView expressionShower = root.findViewById(R.id.textView_expressionShower);
110 | InputHandler inputHandler =
111 | new InputHandler(expressionShower);
112 | for (int i = 0; i < buttonsId.size(); ++i) {
113 | (root.findViewById(buttonsId.get(i))).setOnClickListener(inputHandler);
114 | }
115 |
116 | if (savedInstanceState != null) {
117 | expressionShower.setText(savedInstanceState.getString("expression"));
118 | }
119 |
120 | return root;
121 | }
122 |
123 | @Override
124 | public void onSaveInstanceState(@NonNull Bundle outState) {
125 | super.onSaveInstanceState(outState);
126 | TextView tv = root.findViewById(R.id.textView_expressionShower);
127 | outState.putString("expression", tv.getText().toString());
128 | }
129 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/calculatorbyleafee/ui/converter/ConverterModel.java:
--------------------------------------------------------------------------------
1 | package com.example.calculatorbyleafee.ui.converter;
2 |
3 | import java.util.Arrays;
4 | import java.util.HashMap;
5 | import java.util.List;
6 | import java.util.Map;
7 |
8 | class ConverterModel {
9 |
10 | static Map> supportUnits;
11 |
12 | static {
13 | supportUnits = new HashMap<>();
14 | supportUnits.put("Types", Arrays.asList("Length", "Time", "Data", "Volume"));
15 |
16 | supportUnits.put("Volume", Arrays.asList("Milliliters", "Cubic centimeters",
17 | "Liters", "Cubic meters"));
18 | supportUnits.put("Length", Arrays.asList("nanometers", "microns", "millimeters", "centimeters",
19 | "meters", "kilometers", "inches", "yards", "miles", "nautical miles"));
20 | supportUnits.put("Time", Arrays.asList("microseconds", "milliseconds", "seconds", "minutes",
21 | "hours", "days", "weeks", "years"));
22 | supportUnits.put("Data", Arrays.asList("Bits", "Bytes", "KibiBits", "KibiBytes",
23 | "MebiBits", "MebiBytes", "GibiBits", "GibiBytes"));
24 | }
25 |
26 | static double convert(String ConvertType, String originalUnit, double original,
27 | String targetUnit) {
28 |
29 | double base = 0, target = 0;
30 | switch (ConvertType) {
31 | case "Volume":
32 | switch (originalUnit) {
33 | case "Milliliters":
34 | case "Cubic centimeters":
35 | base = original * 1;
36 | break;
37 | case "Liters":
38 | base = original * 1000;
39 | break;
40 | case "Cubic meters":
41 | base = original * 1000000;
42 | break;
43 | }
44 |
45 | switch (targetUnit) {
46 | case "Milliliters":
47 | case "Cubic centimeters":
48 | target = base / 1;
49 | break;
50 | case "Liters":
51 | target = base / 1000;
52 | break;
53 | case "Cubic meters":
54 | target = base / 1000000;
55 | break;
56 | }
57 | case "Length":
58 | switch (originalUnit) {
59 | case "nanometers":
60 | base = original * 1;
61 | break;
62 | case "microns":
63 | base = original * 1e3;
64 | break;
65 | case "millimeters":
66 | base = original * 1e6;
67 | break;
68 | case "centimeters":
69 | base = original * 1e7;
70 | break;
71 | case "meters":
72 | base = original * 1e9;
73 | break;
74 | case "kilometers":
75 | base = original * 1e12;
76 | break;
77 | case "inches":
78 | base = original * 1e7 * 2.54;
79 | break;
80 | case "yards":
81 | base = original * 1e7 * 2.54 * 36;
82 | break;
83 | case "miles":
84 | base = original * 1e7 * 2.54 * 36 * 1760;
85 | break;
86 | case "nautical miles":
87 | base = original * 1e12 * 1.852;
88 | break;
89 | }
90 |
91 | switch (targetUnit) {
92 | case "nanometers":
93 | target = base / 1;
94 | break;
95 | case "microns":
96 | target = base / 1e3;
97 | break;
98 | case "millimeters":
99 | target = base / 1e6;
100 | break;
101 | case "centimeters":
102 | target = base / 1e7;
103 | break;
104 | case "meters":
105 | target = base / 1e9;
106 | break;
107 | case "kilometers":
108 | target = base / 1e12;
109 | break;
110 | case "inches":
111 | target = base / 1e7 / 2.54;
112 | break;
113 | case "yards":
114 | target = base / 1e7 / 2.54 / 36;
115 | break;
116 | case "miles":
117 | target = base / 1e7 / 2.54 / 36 / 1760;
118 | break;
119 | case "nautical miles":
120 | target = base / 1e12 / 1.852;
121 | break;
122 | }
123 |
124 | break;
125 | case "Time":
126 | switch (originalUnit) {
127 | case "microseconds":
128 | base = original * 1;
129 | break;
130 | case "milliseconds":
131 | base = original * 1e3;
132 | break;
133 | case "seconds":
134 | base = original * 1e6;
135 | break;
136 | case "minutes":
137 | base = original * 1e6 * 60;
138 | break;
139 | case "hours":
140 | base = original * 1e6 * 3600;
141 | break;
142 | case "days":
143 | base = original * 1e6 * 3600 * 24;
144 | break;
145 | case "weeks":
146 | base = original * 1e6 * 3600 * 24 * 7;
147 | break;
148 | case "years":
149 | base = original * 1e6 * 3600 * 24 * 365;
150 | break;
151 | }
152 |
153 | switch (targetUnit) {
154 | case "microseconds":
155 | target = base / 1;
156 | break;
157 | case "milliseconds":
158 | target = base / 1e3;
159 | break;
160 | case "seconds":
161 | target = base / 1e6;
162 | break;
163 | case "minutes":
164 | target = base / 1e6 / 60;
165 | break;
166 | case "hours":
167 | target = base / 1e6 / 3600;
168 | break;
169 | case "days":
170 | target = base / 1e6 / 3600 / 24;
171 | break;
172 | case "weeks":
173 | target = base / 1e6 / 3600 / 24 / 7;
174 | break;
175 | case "years":
176 | target = base / 1e6 / 3600 / 24 / 365;
177 | break;
178 | }
179 | break;
180 | case "Data":
181 | // Units.put("Data", Arrays.asList("Bits", "Bytes", "KibiBits", "KibiBytes",
182 | // "MebiBits", "MebiBytes", "GibiBits", "GibiBytes"));
183 | switch (originalUnit) {
184 | case "Bits":
185 | base = original * 1;
186 | break;
187 | case "Bytes":
188 | base = original * 8;
189 | break;
190 | case "KibiBits":
191 | base = original * 1024;
192 | break;
193 | case "KibiBytes":
194 | base = original * 8 * 1024;
195 | break;
196 | case "MebiBits":
197 | base = original * 1024 * 1024;
198 | break;
199 | case "MebiBytes":
200 | base = original * 8 * 1024 * 1024;
201 | break;
202 | case "GibiBits":
203 | base = original * 1024 * 1024 * 1024;
204 | break;
205 | case "GibiBytes":
206 | base = original * 8 * 1024 * 1024 * 1024;
207 | break;
208 | }
209 |
210 |
211 | switch (targetUnit) {
212 | case "Bits":
213 | target = base / 1;
214 | break;
215 | case "Bytes":
216 | target = base / 8;
217 | break;
218 | case "KibiBits":
219 | target = base / 1024;
220 | break;
221 | case "KibiBytes":
222 | target = base / 8 / 1024;
223 | break;
224 | case "MebiBits":
225 | target = base / 1024 / 1024;
226 | break;
227 | case "MebiBytes":
228 | target = base / 8 / 1024 / 1024;
229 | break;
230 | case "GibiBits":
231 | target = base / 1024 / 1024 / 1024;
232 | break;
233 | case "GibiBytes":
234 | target = base / 8 / 1024 / 1024 / 1024;
235 | break;
236 | }
237 | break;
238 | }
239 |
240 | return target;
241 | }
242 | }
243 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_converter.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
10 |
11 |
16 |
17 |
26 |
27 |
33 |
34 |
35 |
41 |
42 |
51 |
52 |
63 |
64 |
65 |
71 |
72 |
81 |
82 |
93 |
94 |
95 |
100 |
101 |
106 |
107 |
114 |
115 |
123 |
124 |
125 |
130 |
131 |
138 |
139 |
146 |
147 |
154 |
155 |
156 |
161 |
162 |
169 |
170 |
177 |
178 |
185 |
186 |
187 |
188 |
193 |
194 |
201 |
202 |
209 |
210 |
217 |
218 |
219 |
220 |
225 |
226 |
233 |
234 |
241 |
242 |
243 |
244 |
245 |
246 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_exchange_rate.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
18 |
19 |
24 |
25 |
34 |
35 |
44 |
45 |
46 |
51 |
52 |
61 |
62 |
71 |
72 |
73 |
78 |
79 |
86 |
87 |
94 |
95 |
96 |
97 |
98 |
103 |
104 |
109 |
110 |
117 |
118 |
126 |
127 |
128 |
133 |
134 |
141 |
142 |
149 |
150 |
157 |
158 |
159 |
164 |
165 |
172 |
173 |
180 |
181 |
188 |
189 |
190 |
191 |
196 |
197 |
204 |
205 |
212 |
213 |
220 |
221 |
222 |
223 |
228 |
229 |
236 |
237 |
244 |
245 |
246 |
247 |
248 |
249 |
--------------------------------------------------------------------------------
/app/src/main/res/layout-land/fragment_exchange_rate.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
18 |
19 |
24 |
25 |
34 |
35 |
44 |
45 |
46 |
51 |
52 |
61 |
62 |
71 |
72 |
73 |
78 |
79 |
86 |
87 |
94 |
95 |
96 |
97 |
98 |
103 |
104 |
109 |
110 |
117 |
118 |
126 |
127 |
128 |
133 |
134 |
141 |
142 |
149 |
150 |
157 |
158 |
159 |
164 |
165 |
172 |
173 |
180 |
181 |
188 |
189 |
190 |
191 |
196 |
197 |
204 |
205 |
212 |
213 |
220 |
221 |
222 |
223 |
228 |
229 |
236 |
237 |
244 |
245 |
246 |
247 |
248 |
249 |
--------------------------------------------------------------------------------
/app/src/main/res/layout-land/fragment_converter.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
10 |
11 |
16 |
17 |
22 |
23 |
32 |
33 |
39 |
40 |
41 |
47 |
48 |
57 |
58 |
69 |
70 |
71 |
77 |
78 |
87 |
88 |
99 |
100 |
101 |
102 |
107 |
108 |
113 |
114 |
121 |
122 |
130 |
131 |
132 |
137 |
138 |
145 |
146 |
153 |
154 |
161 |
162 |
163 |
168 |
169 |
176 |
177 |
184 |
185 |
192 |
193 |
194 |
195 |
200 |
201 |
208 |
209 |
216 |
217 |
224 |
225 |
226 |
227 |
232 |
233 |
240 |
241 |
248 |
249 |
250 |
251 |
252 |
253 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/calculatorbyleafee/ui/converter/ConverterFragment.java:
--------------------------------------------------------------------------------
1 | package com.example.calculatorbyleafee.ui.converter;
2 |
3 | import android.os.Bundle;
4 | import android.util.Log;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.AdapterView;
9 | import android.widget.Button;
10 | import android.widget.Spinner;
11 | import android.widget.TextView;
12 | import androidx.annotation.NonNull;
13 | import androidx.annotation.Nullable;
14 | import androidx.fragment.app.Fragment;
15 |
16 | import com.example.calculatorbyleafee.R;
17 |
18 | import java.util.List;
19 |
20 | import com.example.calculatorbyleafee.ui.sharedTools.CustomAdapter;
21 |
22 | public class ConverterFragment extends Fragment {
23 | private View root;
24 | private Spinner spinnerType;
25 | private Spinner spinnerUnit1;
26 | private Spinner spinnerUnit2;
27 | private TextView textView1;
28 | private TextView textView2;
29 | private int activeView;
30 |
31 | private class ButtonListener implements Button.OnClickListener {
32 | @Override
33 | public void onClick(View view) {
34 | TextView activeTextView;
35 | activeTextView = (activeView == 1) ? textView1 : textView2;
36 |
37 | char appendChar = 0;
38 | String str = activeTextView.getText().toString();
39 | switch (view.getId()) {
40 | case R.id.button_backspace:
41 | if (str.length() > 1)
42 | str = str.substring(0, str.length() - 1);
43 | else if (str.length() == 1)
44 | str = "0";
45 | activeTextView.setText(str);
46 | break;
47 |
48 | case R.id.button_clearAll:
49 | activeTextView.setText("0");
50 | break;
51 |
52 | case R.id.button_numPoint:
53 | if (str.indexOf('.')== -1)
54 | appendChar = '.';
55 | break;
56 |
57 | case R.id.button_num0: appendChar = '0'; break;
58 | case R.id.button_num1: appendChar = '1'; break;
59 | case R.id.button_num2: appendChar = '2'; break;
60 | case R.id.button_num3: appendChar = '3'; break;
61 | case R.id.button_num4: appendChar = '4'; break;
62 | case R.id.button_num5: appendChar = '5'; break;
63 | case R.id.button_num6: appendChar = '6'; break;
64 | case R.id.button_num7: appendChar = '7'; break;
65 | case R.id.button_num8: appendChar = '8'; break;
66 | case R.id.button_num9: appendChar = '9'; break;
67 | }
68 |
69 | if (appendChar != 0) {
70 | if (str.equals("0") || str.equals("0.0"))
71 | str = "" + appendChar;
72 | else
73 | str += appendChar;
74 | activeTextView.setText(str);
75 | }
76 |
77 | doConvert();
78 | }
79 | }
80 |
81 | private void doConvert() {
82 | String type = spinnerType.getSelectedItem().toString();
83 | String unit1 = spinnerUnit1.getSelectedItem().toString();
84 | String unit2 = spinnerUnit2.getSelectedItem().toString();
85 | String str1 = textView1.getText().toString();
86 | String str2 = textView2.getText().toString();
87 | double num1 = 0, num2 = 0;
88 | try { num1 = Double.parseDouble(str1); }
89 | catch (NumberFormatException e) {
90 | if (e.getMessage() != null && !e.getMessage().equals("empty String")) throw e; }
91 | try { num2 = Double.parseDouble(str2); }
92 | catch (NumberFormatException e) {
93 | if (e.getMessage() != null && !e.getMessage().equals("empty String")) throw e; }
94 | double result;
95 | switch (activeView) {
96 | case 1:
97 | result = ConverterModel.convert(type, unit1, num1, unit2);
98 | textView2.setText(String.valueOf(result));
99 | break;
100 | case 2:
101 | result = ConverterModel.convert(type, unit2, num2, unit1);
102 | textView1.setText(String.valueOf(result));
103 | break;
104 | }
105 | }
106 |
107 | private class TextViewClickListener implements View.OnClickListener {
108 | @Override
109 | public void onClick(View v) {
110 | switchActive((v.getId() == R.id.textView_value1) ? 1 : 2);
111 | }
112 | }
113 |
114 | private void switchActive(int i) {
115 | activeView = i;
116 | if (activeView == 1) {
117 | textView1.setBackgroundResource(R.drawable.textview_background_bold);
118 | textView2.setBackgroundResource(R.drawable.textview_background);
119 | } else {
120 | textView1.setBackgroundResource(R.drawable.textview_background);
121 | textView2.setBackgroundResource(R.drawable.textview_background_bold);
122 | }
123 | }
124 |
125 | private void assignButtonOnClick() {
126 | ButtonListener buttonListener = new ButtonListener();
127 | int[] buttonIds= {
128 | R.id.button_clearAll, R.id.button_backspace,
129 | R.id.button_num0, R.id.button_num1, R.id.button_num2, R.id.button_num3,
130 | R.id.button_num4, R.id.button_num5, R.id.button_num6, R.id.button_num7,
131 | R.id.button_num8, R.id.button_num9, R.id.button_numPoint
132 | };
133 | for (int buttonId : buttonIds)
134 | root.findViewById(buttonId).setOnClickListener(buttonListener);
135 | }
136 |
137 | private void assignTextViewOnClick() {
138 | TextViewClickListener textViewListener = new TextViewClickListener();
139 | textView1.setClickable(true);
140 | textView2.setClickable(true);
141 | textView1.setOnClickListener(textViewListener);
142 | textView2.setOnClickListener(textViewListener);
143 | }
144 |
145 | private class SpinnerUnitOnItemSelectedListener implements AdapterView.OnItemSelectedListener {
146 | @Override
147 | public void onItemSelected(AdapterView> parent, View view, int position, long id) {
148 | Log.w("SpinnerUnitOnItemSelectedListener", "doConvert() in here");
149 | doConvert();
150 | }
151 |
152 | @Override
153 | public void onNothingSelected(AdapterView> parent) {
154 | // do nothing
155 | }
156 | }
157 |
158 | private class SpinnerTypeOnItemSelectedListener implements AdapterView.OnItemSelectedListener {
159 | @Override
160 | public void onItemSelected(AdapterView> parent, View view, int position, long id) {
161 | Log.w("SpinnerTypeOnItemSelectedListener", "type selected, reset unit's spinner adapter");
162 | String type = parent.getItemAtPosition(position).toString();
163 | CustomAdapter subAdapter = new CustomAdapter(getContext(), ConverterModel.supportUnits.get(type));
164 | spinnerUnit1.setAdapter(subAdapter);
165 | spinnerUnit2.setAdapter(subAdapter);
166 | }
167 |
168 | @Override
169 | public void onNothingSelected(AdapterView> parent) {
170 | Log.w("SpinnerTypeOnItemSelectedListener", "nothing selected");
171 | // do nothing
172 | }
173 | }
174 |
175 | private void assignSpinner() {
176 | Log.w("assignSpinner", "assigning spinner, set the type spinner adapter, and all spinner listener");
177 | List supportTypes = ConverterModel.supportUnits.get("Types");
178 | CustomAdapter typeAdapter = new CustomAdapter(getContext(), supportTypes);
179 |
180 | SpinnerTypeOnItemSelectedListener typeListener = new SpinnerTypeOnItemSelectedListener();
181 | SpinnerUnitOnItemSelectedListener unitListener = new SpinnerUnitOnItemSelectedListener();
182 | spinnerType.setAdapter(typeAdapter);
183 | spinnerType.setOnItemSelectedListener(typeListener);
184 | spinnerUnit1.setOnItemSelectedListener(unitListener);
185 | spinnerUnit2.setOnItemSelectedListener(unitListener);
186 | }
187 |
188 | @Override
189 | public void onSaveInstanceState(@NonNull Bundle outState) {
190 | super.onSaveInstanceState(outState);
191 |
192 | int spinnerTypePosition = spinnerType.getSelectedItemPosition();
193 | int spinner1 = spinnerUnit1.getSelectedItemPosition();
194 | int spinner2 = spinnerUnit2.getSelectedItemPosition();
195 | String str1 = textView1.getText().toString();
196 | String str2 = textView2.getText().toString();
197 |
198 | outState.putInt("activeView", activeView);
199 | outState.putInt("spinnerType", spinnerTypePosition);
200 | outState.putInt("spinnerUnit1", spinner1);
201 | outState.putInt("spinnerUnit2", spinner2);
202 | outState.putString("textView1", str1);
203 | outState.putString("textView2", str2);
204 |
205 | Log.w("Saving spinnerPosition", "saving the Unit1 is: " + outState.getInt("spinnerUnit1"));
206 | Log.w("Saving spinnerPosition", "saving the Unit2 is: " + outState.getInt("spinnerUnit2"));
207 | }
208 |
209 | @Nullable
210 | @Override
211 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
212 | super.onCreateView(inflater, container, savedInstanceState);
213 | root = inflater.inflate(R.layout.fragment_converter, container, false);
214 |
215 | spinnerType = root.findViewById(R.id.spinner_converter_type);
216 | spinnerUnit1 = root.findViewById(R.id.spinner_unit1);
217 | spinnerUnit2 = root.findViewById(R.id.spinner_unit2);
218 | textView1 = root.findViewById(R.id.textView_value1);
219 | textView2 = root.findViewById(R.id.textView_value2);
220 |
221 | this.assignButtonOnClick();
222 | this.assignTextViewOnClick();
223 | this.assignSpinner();
224 |
225 | if (savedInstanceState != null) {
226 | Log.w("spinnerPosition", "the Unit1 is: " + savedInstanceState.getInt("spinnerUnit1"));
227 | Log.w("spinnerPosition", "the Unit2 is: " + savedInstanceState.getInt("spinnerUnit2"));
228 | this.switchActive(savedInstanceState.getInt("activeView"));
229 | spinnerType.setSelection(savedInstanceState.getInt("spinnerType"));
230 | spinnerUnit1.setSelection(savedInstanceState.getInt("spinnerUnit1"));
231 | spinnerUnit2.setSelection(savedInstanceState.getInt("spinnerUnit2"));
232 | if (activeView == 1)
233 | textView1.setText(savedInstanceState.getString("textView1"));
234 | else
235 | textView2.setText(savedInstanceState.getString("textView2"));
236 | } else {
237 | textView1.setText("0");
238 | textView2.setText("0");
239 | this.switchActive(2);
240 | }
241 |
242 | return root;
243 | }
244 | }
245 |
--------------------------------------------------------------------------------
/app/src/main/res/layout-land/fragment_home.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
22 |
23 |
28 |
29 |
34 |
35 |
42 |
43 |
51 |
52 |
53 |
54 |
59 |
60 |
67 |
68 |
75 |
76 |
83 |
84 |
91 |
92 |
100 |
101 |
108 |
109 |
110 |
111 |
116 |
117 |
124 |
125 |
132 |
133 |
140 |
141 |
148 |
149 |
156 |
157 |
164 |
165 |
166 |
167 |
168 |
173 |
174 |
181 |
182 |
189 |
190 |
197 |
198 |
205 |
206 |
214 |
215 |
223 |
224 |
225 |
231 |
232 |
239 |
240 |
247 |
248 |
255 |
256 |
264 |
265 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/calculatorbyleafee/ui/radix/RadixFragment.java:
--------------------------------------------------------------------------------
1 | package com.example.calculatorbyleafee.ui.radix;
2 |
3 | import android.os.Bundle;
4 | import android.os.Parcel;
5 | import android.os.Parcelable;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.Button;
10 | import android.widget.TextView;
11 |
12 | import androidx.annotation.NonNull;
13 | import androidx.fragment.app.Fragment;
14 |
15 | import com.example.calculatorbyleafee.R;
16 |
17 | import java.util.ArrayList;
18 | import java.util.Arrays;
19 | import java.util.List;
20 |
21 | public class RadixFragment extends Fragment {
22 |
23 | private TextView textViewHex;
24 | private TextView textViewDec;
25 | private TextView textViewOct;
26 | private TextView textViewBin;
27 |
28 | private List