Skip to content

Commit

Permalink
Merge pull request #19 from gzeinnumer/open-pull
Browse files Browse the repository at this point in the history
Open pull
  • Loading branch information
gzeinnumer authored Feb 3, 2021
2 parents 06e7e7c + 5913794 commit 093edc0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 182 deletions.
137 changes: 6 additions & 131 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
</h1>

<p align="center">
<a><img src="https://img.shields.io/badge/Version-4.0.0-brightgreen.svg?style=flat"></a>
<a><img src="https://img.shields.io/badge/Version-4.0.1-brightgreen.svg?style=flat"></a>
<a><img src="https://img.shields.io/badge/ID-gzeinnumer-blue.svg?style=flat"></a>
<a><img src="https://img.shields.io/badge/Java-Suport-green?logo=java&style=flat"></a>
<a><img src="https://img.shields.io/badge/Koltin-Suport-green?logo=kotlin&style=flat"></a>
<a><img src="https://img.shields.io/badge/Kotlin-Suport-green?logo=kotlin&style=flat"></a>
<a href="https://github.com/gzeinnumer"><img src="https://img.shields.io/github/followers/gzeinnumer?label=follow&style=social"></a>
<br>
<p>Simple way to convert 1000000 to 1,000,000 .</p>
Expand Down Expand Up @@ -61,29 +61,11 @@ dependencies {

**Note** `RP 123,456,789.111` To Remove `Prefix` `RP` and symbol `,` you can use this :
```java
String str = editText.getText().toString();
textView.setText(StringTools.trimCommaOfString(str, "RP "));
//or -> without prefix
textView.setText(StringTools.trimCommaOfString(str);
```
```kotlin
val str = editText.text;
textView.text = StringTools.trimCommaOfString(str, "RP ")
//or -> without prefix
textView.text = StringTools.trimCommaOfString(str)
StringTools.trimCommaOfString(str, "RP ");
```

Here is the `xml` view that i use for **Sample 1-4**
```xml
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal" />
```
#
* **Sample 1** -> Simple `TextWacher`
> **Java**
```java
editText.addTextChangedListener(new CurrencyConverter(editText));

Expand All @@ -98,22 +80,9 @@ button.setOnClickListener(new View.OnClickListener() {
}
});
```
> **Kotlin**
```kotlin
editText.addTextChangedListener(CurrencyConverter(editText))

button.setOnClickListener {
val str: String = editText.text.toString()
Log.d(TAG, "onClick: " + StringTools.trimCommaOfString(str))
Log.d(TAG, "onClick: "+editText.text.toString())

textView.text = StringTools.trimCommaOfString(str)
}
```

#
* **Sample 2** -> Simple `TextWacher` With `CallBack`
> **Java**
```java
editText.addTextChangedListener(new CurrencyConverter(editText, new CurrencyConverter.StringCallBack() {
@Override
Expand All @@ -125,23 +94,9 @@ editText.addTextChangedListener(new CurrencyConverter(editText, new CurrencyConv
}
}));
```
> **Kotlin**
```kotlin
editText.addTextChangedListener(
CurrencyConverter(editText,
StringCallBack { value ->
Log.d(TAG, "realString: $value")
Log.d(TAG, "realString: "+editText.text)

textView.text = StringTools.trimCommaOfString(str)
}
)
)
```

#
* **Sample 3** -> Simple `TextWacher` With `Prefix`
> **Java**
```java
editText.addTextChangedListener(new CurrencyConverter(editText, "RP "));

Expand All @@ -156,22 +111,9 @@ button.setOnClickListener(new View.OnClickListener() {
}
});
```
> **Kotlin**
```kotlin
editText.addTextChangedListener(CurrencyConverter(editText, "RP "))

button.setOnClickListener {
val str: String = editText.text.toString()
Log.d(TAG, "onClick: " + StringTools.trimCommaOfString(str))
Log.d(TAG, "onClick: "+editText.text.toString())

textView.text = StringTools.trimCommaOfString(str)
}
```

#
* **Sample 4** -> Simple `TextWacher` With `Prefix` And `CallBack`
> **Java**
```java
editText.addTextChangedListener(new CurrencyConverter(editText, "RP " ,new CurrencyConverter.StringCallBack() {
@Override
Expand All @@ -183,20 +125,6 @@ editText.addTextChangedListener(new CurrencyConverter(editText, "RP " ,new Curre
}
}));
```
> **Kotlin**
```kotlin
editText.addTextChangedListener(
CurrencyConverter(editText,
"RP ",
StringCallBack { value ->
Log.d(TAG, "realString: $value")
Log.d(TAG, "realString: "+editText.text)

textView.text = StringTools.trimCommaOfString(str)
}
)
)
```

Preview For **Sample 1-4**:
|<img src="https://github.com/gzeinnumer/MyLibCurrencyConverter/blob/master/preview/example1.jpg" width="400"/>|<img src="https://github.com/gzeinnumer/MyLibCurrencyConverter/blob/master/preview/example2.jpg" width="400"/>|
Expand Down Expand Up @@ -245,6 +173,7 @@ Preview :
<com.gzeinnumer.mylibcurrencyconverter.utils.CurrencyEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
app:prefix="RP " />

</com.google.android.material.textfield.TextInputLayout>
Expand All @@ -260,62 +189,6 @@ Preview :
|<img src="https://github.com/gzeinnumer/MyLibCurrencyConverter/blob/master/preview/example5.jpg" width="400"/>|<img src="https://github.com/gzeinnumer/MyLibCurrencyConverter/blob/master/preview/example10.jpg" width="400"/>|
|---|---|

#
* **Sample 3** -> Use Material Design With Simple Code
XML
```xml
//OutlinedBox
<com.gzeinnumer.mylibcurrencyconverter.utils.CurrencyEditTextOutlinedBox
android:id="@+id/ed_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hint="Dalam Jumlah Rupiah"
app:prefix="RP "/>

//FilledBox
<com.gzeinnumer.mylibcurrencyconverter.utils.CurrencyEditTextFilledBox
android:id="@+id/ed_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hint="Dalam Jumlah Rupiah"
app:prefix="RP " />
```
Custom your view
```xml
app:hint="Dalam Jumlah Rupiah" // for Hint of EditText
app:maxLength="20" // for Max Character in EditText include Prefix and Comma
app:prefix="RP " // for Prefix Example -> RP 1.000.000
app:textSize="12sp" // for TextSize on input
```
Remove `Prefix` and symbol `,` and get `real value`
```java
//OutlinedBox
CurrencyEditTextOutlinedBox ed1 = findViewById(R.id.ed_1);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

textView.setText(ed1.getText());
textView.setText(StringTools.trimCommaOfString(ed1.getText(), "RP "));
}
});

//FilledBox
CurrencyEditTextFilledBox ed1 = findViewById(R.id.ed_2);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

textView.setText(ed1.getText());
textView.setText(StringTools.trimCommaOfString(ed1.getText(), "RP "));
}
});
```

**Preview** :
|<img src="https://github.com/gzeinnumer/MyLibCurrencyConverter/blob/master/preview/example6.jpg" width="400"/>|<img src="https://github.com/gzeinnumer/MyLibCurrencyConverter/blob/master/preview/example11.jpg" width="400"/>|
|---|---|

---

**FullCode [MainActivity](https://github.com/gzeinnumer/MyLibCurrencyConverter/blob/master/app/src/main/java/com/gzeinnumer/mylibcurrencyconverter/MainActivity.java) & [XML](https://github.com/gzeinnumer/MyLibCurrencyConverter/blob/master/app/src/main/res/layout/activity_main.xml)**
Expand All @@ -327,6 +200,8 @@ button.setOnClickListener(new View.OnClickListener() {
### Version
- **4.0.0**
- First Release
- **4.0.1**
- Take Out Useless Method

---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package com.gzeinnumer.mylibcurrencyconverter;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

//import com.gzeinnumer.mylibcurrencyconverter.utils.CurrencyConvertera;
import androidx.appcompat.app.AppCompatActivity;

import com.gzeinnumer.mylibcurrencyconverter.utils.CurrencyConverter;
import com.gzeinnumer.mylibcurrencyconverter.utils.CurrencyEditTextFilledBox;
import com.gzeinnumer.mylibcurrencyconverter.utils.CurrencyEditTextOutlinedBox;
import com.gzeinnumer.mylibcurrencyconverter.utils.StringTools;

//import com.gzeinnumer.mylibcurrencyconverter.utils.CurrencyConvertera;

public class MainActivity extends AppCompatActivity {

private static final String TAG = "MainActivity";
Expand All @@ -33,10 +32,8 @@ protected void onCreate(Bundle savedInstanceState) {
textView = findViewById(R.id.textView);

sample1();
// sample2();
// sample3();
sample4();
sample5();
sample2();
sample3();
}

private void sample1() {
Expand Down Expand Up @@ -70,32 +67,4 @@ public void realString(String value) {
}
}));
}

private void sample4() {
CurrencyEditTextOutlinedBox ed1 = findViewById(R.id.ed_1);

button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

// textView.setText(ed1.getText());
textView.setText(StringTools.trimCommaOfString(ed1.getText(), "RP "));
}
});

}

private void sample5() {
CurrencyEditTextFilledBox ed1 = findViewById(R.id.ed_2);

button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

textView.setText(ed1.getText());
textView.setText(StringTools.trimCommaOfString(ed1.getText(), "RP "));
}
});

}
}
14 changes: 0 additions & 14 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,4 @@

</com.google.android.material.textfield.TextInputLayout>

<com.gzeinnumer.mylibcurrencyconverter.utils.CurrencyEditTextOutlinedBox
android:id="@+id/ed_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hint="Dalam Jumlah Rupiah"
app:prefix="RP " />

<com.gzeinnumer.mylibcurrencyconverter.utils.CurrencyEditTextFilledBox
android:id="@+id/ed_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hint="Dalam Jumlah Rupiah"
app:prefix="RP " />

</LinearLayout>

0 comments on commit 093edc0

Please sign in to comment.