-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3a81740
Showing
33 changed files
with
1,570 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx | ||
local.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
plugins { | ||
id 'com.android.application' | ||
} | ||
|
||
android { | ||
compileSdk 30 | ||
buildToolsVersion "30.0.2" | ||
|
||
defaultConfig { | ||
applicationId "com.eurokonverter" | ||
minSdk 21 | ||
targetSdk 30 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
setProperty("archivesBaseName", "$applicationId-$versionName") | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled true | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
implementation 'androidx.appcompat:appcompat:1.2.0' | ||
implementation 'com.google.android.material:material:1.4.0' | ||
implementation 'androidx.gridlayout:gridlayout:1.0.0' | ||
implementation "androidx.cardview:cardview:1.0.0" | ||
|
||
testImplementation 'junit:junit:4.+' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.3' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.eurokonverter"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.EuroKonverter"> | ||
<activity | ||
android:name=".MainActivity" | ||
android:exported="true" | ||
android:screenOrientation="portrait" | ||
> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,218 @@ | ||
package com.eurokonverter; | ||
|
||
import android.graphics.Color; | ||
import android.os.Bundle; | ||
import android.text.Selection; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.LinearLayout; | ||
import android.widget.TextView; | ||
|
||
import androidx.appcompat.app.AppCompatActivity; | ||
|
||
import com.eurokonverter.util.CustomScrollingMovementMethod; | ||
|
||
import java.util.Locale; | ||
|
||
/** | ||
* | ||
*/ | ||
public class MainActivity extends AppCompatActivity { | ||
|
||
private final double CONVERSION_RATE = 7.53450; | ||
|
||
private LinearLayout selectedView; | ||
private TextView inputView; | ||
private TextView outputView; | ||
|
||
/** | ||
* | ||
* @param textView | ||
*/ | ||
private void scrollToEnd(TextView textView) { | ||
|
||
textView.append(""); | ||
Selection.setSelection(textView.getEditableText(), textView.length()); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
private void setInputViewScrolling(int id) { | ||
|
||
LinearLayout view = findViewById(id); | ||
if (view == null) { | ||
return; | ||
} | ||
|
||
TextView inputView = (TextView) view.getChildAt(view.getChildCount() - 1); | ||
if (inputView == null) { | ||
return; | ||
} | ||
|
||
inputView.setMovementMethod(new CustomScrollingMovementMethod(this)); | ||
scrollToEnd(inputView); | ||
} | ||
/** | ||
* | ||
* @param layoutId | ||
*/ | ||
private void setSelectedView(int layoutId) { | ||
|
||
LinearLayout hrk = findViewById(R.id.linearLayoutHRK); | ||
LinearLayout eur = findViewById(R.id.linearLayoutEUR); | ||
|
||
if (hrk == null || eur == null) { | ||
return; | ||
} | ||
|
||
if (layoutId == R.id.linearLayoutHRK) { | ||
eur.setBackgroundColor(Color.TRANSPARENT); | ||
hrk.setBackgroundColor(getResources().getColor(R.color.design_default_color_secondary)); | ||
|
||
inputView = (TextView) hrk.getChildAt(hrk.getChildCount() - 1); | ||
outputView = (TextView) eur.getChildAt(eur.getChildCount() - 1); | ||
selectedView = hrk; | ||
} else { | ||
hrk.setBackgroundColor(Color.TRANSPARENT); | ||
eur.setBackgroundColor(getResources().getColor(R.color.design_default_color_secondary)); | ||
|
||
inputView = (TextView) eur.getChildAt(eur.getChildCount() - 1); | ||
outputView = (TextView) hrk.getChildAt(hrk.getChildCount() - 1); | ||
selectedView = eur; | ||
} | ||
} | ||
|
||
/** | ||
* | ||
* @param textView | ||
* @return | ||
*/ | ||
private double getDouble(TextView textView) { | ||
|
||
String string = textView.getText().toString().replaceAll("\\.", "").replaceAll(",", "."); | ||
return Double.parseDouble(string); | ||
} | ||
|
||
/** | ||
* | ||
* @param textView | ||
* @param value | ||
*/ | ||
private void setDouble(TextView textView, double value) { | ||
|
||
if (value == 0) { | ||
textView.setText("0"); | ||
return; | ||
} | ||
|
||
textView.setText(String.format(Locale.GERMANY, "%,.2f", value)); | ||
} | ||
|
||
/** | ||
* | ||
* @param textView | ||
* @param value | ||
*/ | ||
private void setDoubleNoDecimals(TextView textView, double value) { | ||
|
||
if (value == 0) { | ||
textView.setText("0"); | ||
return; | ||
} | ||
|
||
String string = String.format(Locale.GERMANY, "%,.2f", value); | ||
|
||
while (string.endsWith("0")) { | ||
string = string.substring(0, string.length() - 1); | ||
} | ||
|
||
if (string.endsWith(",")) { | ||
string = string.substring(0, string.length() - 1); | ||
} | ||
|
||
textView.setText(string); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
private void convert() { | ||
|
||
double value = getDouble(inputView); | ||
if (selectedView.getId() == R.id.linearLayoutHRK) { | ||
value /= CONVERSION_RATE; | ||
} else { | ||
value *= CONVERSION_RATE; | ||
} | ||
|
||
setDouble(outputView, value); | ||
scrollToEnd(outputView); | ||
} | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
setInputViewScrolling(R.id.linearLayoutHRK); | ||
setInputViewScrolling(R.id.linearLayoutEUR); | ||
|
||
setSelectedView(R.id.linearLayoutHRK); | ||
} | ||
|
||
/** | ||
* | ||
* @param view | ||
*/ | ||
public void onCurrencySelected(View view) { | ||
setSelectedView(view.getId()); | ||
} | ||
|
||
/** | ||
* | ||
* @param view | ||
*/ | ||
public void onKeyPressed(View view) { | ||
|
||
if (selectedView == null || inputView == null) { | ||
return; | ||
} | ||
|
||
char key = ((Button) view).getText().toString().charAt(0); | ||
if (key == 'C') { | ||
inputView.setText("0"); | ||
} else if (key == 8592) { | ||
|
||
int length = inputView.length(); | ||
if (length > 1) { | ||
inputView.setText(inputView.getText().subSequence(0, length - 1)); | ||
} else { | ||
inputView.setText("0"); | ||
} | ||
} else if (key == ',') { | ||
if (!inputView.getText().toString().contains(",")) { | ||
inputView.append("" + key); | ||
} | ||
} else { | ||
|
||
String text = inputView.getText().toString(); | ||
if (text.contains(",") && text.indexOf(',') == text.length() - 3) { | ||
return; | ||
} | ||
|
||
if (inputView.length() == 1 && text.charAt(0) == '0') { | ||
inputView.setText("" + key); | ||
} else { | ||
inputView.append("" + key); | ||
} | ||
} | ||
|
||
if (!inputView.getText().toString().contains(",")) { | ||
setDoubleNoDecimals(inputView, getDouble(inputView)); | ||
} | ||
|
||
scrollToEnd(inputView); | ||
convert(); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
app/src/main/java/com/eurokonverter/util/CustomScrollingMovementMethod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.eurokonverter.util; | ||
|
||
import android.text.Spannable; | ||
import android.text.method.ScrollingMovementMethod; | ||
import android.view.GestureDetector; | ||
import android.view.MotionEvent; | ||
import android.view.View; | ||
import android.widget.TextView; | ||
|
||
import com.eurokonverter.MainActivity; | ||
|
||
/** | ||
* | ||
*/ | ||
public class CustomScrollingMovementMethod extends ScrollingMovementMethod { | ||
|
||
private TextView textView; | ||
private final GestureDetector gestureDetector; | ||
|
||
/** | ||
* | ||
* @param activity | ||
*/ | ||
public CustomScrollingMovementMethod(MainActivity activity) { | ||
|
||
gestureDetector = new GestureDetector(activity, new GestureDetector.SimpleOnGestureListener() { | ||
@Override | ||
public boolean onSingleTapUp(MotionEvent e) { | ||
activity.onCurrencySelected((View) textView.getParent()); | ||
return super.onSingleTapUp(e); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) { | ||
|
||
textView = widget; | ||
gestureDetector.onTouchEvent(event); | ||
return super.onTouchEvent(widget, buffer, event); | ||
} | ||
} |
Oops, something went wrong.