Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ android {
dependencies {

implementation project(path: ':photocropping')
implementation project(path: ':maskededittext')

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.1'
Expand Down
7 changes: 0 additions & 7 deletions app/src/main/java/com/hipo/macaron/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package com.hipo.macaron

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.hipo.macaron.imagecropdemo.ImageCropMainActivity
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -13,10 +11,5 @@ class MainActivity : AppCompatActivity() {
}

private fun initUi() {
mainPhotoCropDemoButton.setOnClickListener { onImageCropButtonClick() }
}

private fun onImageCropButtonClick() {
startActivity(ImageCropMainActivity.newIntent(this))
}
}
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_android.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M17.6,11.48 L19.44,8.3a0.63,0.63 0,0 0,-1.09 -0.63l-1.88,3.24a11.43,11.43 0,0 0,-8.94 0L5.65,7.67a0.63,0.63 0,0 0,-1.09 0.63L6.4,11.48A10.81,10.81 0,0 0,1 20L23,20A10.81,10.81 0,0 0,17.6 11.48ZM7,17.25A1.25,1.25 0,1 1,8.25 16,1.25 1.25,0 0,1 7,17.25ZM17,17.25A1.25,1.25 0,1 1,18.25 16,1.25 1.25,0 0,1 17,17.25Z"
android:fillColor="#FF000000"/>
</vector>
92 changes: 80 additions & 12 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,87 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
android:background="@color/white">

<Button
android:id="@+id/mainPhotoCropDemoButton"
android:layout_width="wrap_content"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Demo Photo Cropping"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
android:orientation="vertical">

</androidx.constraintlayout.widget.ConstraintLayout>
<com.hipo.maskededittext.MaskedTextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Date"
android:theme="@style/MaskedInputTextLayoutTheme"
app:error="Error Text"
app:helper="Helper Text"
app:maskType="date" />

<com.hipo.maskededittext.MaskedTextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_40"
android:hint="Currency"
android:theme="@style/MaskedInputTextLayoutTheme.Currency"
app:maskType="currency" />

<com.hipo.maskededittext.MaskedTextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_40"
android:hint="Credit Card"
android:theme="@style/MaskedInputTextLayoutTheme"
app:maskType="credit_card" />

<com.hipo.maskededittext.MaskedTextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_40"
android:hint="Date No Day"
android:theme="@style/MaskedInputTextLayoutTheme"
app:maskType="date_mm_yyyy" />

<com.hipo.maskededittext.MaskedTextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_40"
android:hint="Iban"
android:theme="@style/MaskedInputTextLayoutTheme"
app:maskType="iban" />

<com.hipo.maskededittext.MaskedTextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_40"
android:hint="Phone"
android:theme="@style/MaskedInputTextLayoutTheme"
app:maskType="phone" />

<com.hipo.maskededittext.MaskedTextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_40"
android:hint="SSN"
android:theme="@style/MaskedInputTextLayoutTheme"
app:maskType="ssn" />

<com.hipo.maskededittext.MaskedTextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_40"
android:hint="TC"
android:theme="@style/MaskedInputTextLayoutTheme"
app:maskType="tc_id" />

<com.hipo.maskededittext.MaskedTextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_40"
android:hint="Static Text"
android:theme="@style/MaskedInputTextLayoutTheme"
app:maskType="static_text" />

</LinearLayout>
</ScrollView>
16 changes: 0 additions & 16 deletions app/src/main/res/values-night/themes.xml

This file was deleted.

3 changes: 3 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>

<color name="gray_300">#8F929E</color>
<color name="red_300">#E54360</color>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.Macaron" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<style name="Theme.Macaron" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.4.0"
ext.kotlin_version = "1.5.20"
repositories {
google()
jcenter()
Expand Down
16 changes: 13 additions & 3 deletions maskededittext/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,25 @@ android {
lintOptions {
abortOnError false
}

buildFeatures {
viewBinding true
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.core:core-ktx:1.6.0'
implementation "androidx.constraintlayout:constraintlayout:2.0.4"
implementation 'com.google.android.material:material:1.4.0'

def lifecycle = "2.3.1"

implementation 'com.google.android.material:material:1.0.0'
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle"
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle"
}

tasks.withType(Javadoc).all { enabled = false }
Expand Down
2 changes: 1 addition & 1 deletion maskededittext/library.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
artifact=maskededittext
libraryName=com.hipo.maskededittext
libraryVersion=1.2.10
libraryVersion=1.2.15
libraryDescription=Masked edit text to format phone number, date, ssn and custom types.
3 changes: 1 addition & 2 deletions maskededittext/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hipo.maskededittext" />
<manifest package="com.hipo.maskededittext" />
123 changes: 100 additions & 23 deletions maskededittext/src/main/java/com/hipo/maskededittext/Mask.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
package com.hipo.maskededittext

import com.hipo.maskededittext.masks.*
import com.hipo.maskededittext.masks.CreditCardMask
import com.hipo.maskededittext.masks.CurrencyMask
import com.hipo.maskededittext.masks.CustomMask
import com.hipo.maskededittext.masks.DateMask
import com.hipo.maskededittext.masks.DateMonthYearMask
import com.hipo.maskededittext.masks.IBANMask
import com.hipo.maskededittext.masks.PhoneMask
import com.hipo.maskededittext.masks.SSNMask
import com.hipo.maskededittext.masks.StaticTextMask
import com.hipo.maskededittext.masks.TCIdMask
import com.hipo.maskededittext.masks.UnselectedMask
import com.hipo.maskededittext.model.CurrencyMaskerSettings
import com.hipo.maskededittext.utils.extensions.specialChars


abstract class Mask {
abstract val maskPattern: String
Expand All @@ -10,46 +23,110 @@ abstract class Mask {
abstract fun isValidToParse(maskedText: String): Boolean
abstract fun filterMaskedText(maskedText: String): String

fun calculateUpcomingMaskDistance(start: Int): Int {
if (start == 0) {
return 0
}
var index = start
with(this) {
while (index in maskPattern.indices && specialChars.contains(maskPattern[index])) {
index++
}
}
return index
}

fun calculateCurrentMaskDistance(start: Int): Int {
if (start == 0) {
return 0
}
var index = start
with(this) {
while (index in maskPattern.indices && specialChars.contains(maskPattern[index])) {
index--
}
}
return index
}

// Enum class order must be the same as attrs.xml order
enum class Type : MaskCreator {
DATE {
override fun create(maskPattern: String?, returnPattern: String?): Mask =
DateMask()
override fun create(
maskPattern: String?,
returnPattern: String?,
currencyMaskerSettings: CurrencyMaskerSettings?
): Mask = DateMask()
},
PHONE {
override fun create(maskPattern: String?, returnPattern: String?): Mask =
PhoneMask()
override fun create(
maskPattern: String?,
returnPattern: String?,
currencyMaskerSettings: CurrencyMaskerSettings?
): Mask = PhoneMask()
},
SSN {
override fun create(maskPattern: String?, returnPattern: String?): Mask =
SSNMask()
override fun create(
maskPattern: String?,
returnPattern: String?,
currencyMaskerSettings: CurrencyMaskerSettings?
): Mask = SSNMask()
},
CURRENCY {
override fun create(maskPattern: String?, returnPattern: String?): Mask =
CurrencyMask(maskPattern.orEmpty())
override fun create(
maskPattern: String?,
returnPattern: String?,
currencyMaskerSettings: CurrencyMaskerSettings?
): Mask = CurrencyMask(maskPattern.orEmpty(), currencyMaskerSettings)
},
CUSTOM {
override fun create(maskPattern: String?, returnPattern: String?): Mask =
CustomMask(
maskPattern.orEmpty(),
returnPattern.orEmpty()
)
override fun create(
maskPattern: String?,
returnPattern: String?,
currencyMaskerSettings: CurrencyMaskerSettings?
): Mask = CustomMask(maskPattern.orEmpty(), returnPattern.orEmpty())
},
STATIC_TEXT {
override fun create(maskPattern: String?, returnPattern: String?) =
StaticTextMask(maskPattern!!)
override fun create(
maskPattern: String?,
returnPattern: String?,
currencyMaskerSettings: CurrencyMaskerSettings?
): Mask = StaticTextMask(maskPattern!!)
},
CREDIT_CARD {
override fun create(maskPattern: String?, returnPattern: String?) =
CreditCardMask()
override fun create(
maskPattern: String?,
returnPattern: String?,
currencyMaskerSettings: CurrencyMaskerSettings?
): Mask = CreditCardMask()
},
DATE_MONTH_YEAR {
override fun create(maskPattern: String?, returnPattern: String?) =
DateMonthYearMask()
override fun create(
maskPattern: String?,
returnPattern: String?,
currencyMaskerSettings: CurrencyMaskerSettings?
): Mask = DateMonthYearMask()
},
IBAN {
override fun create(
maskPattern: String?,
returnPattern: String?,
currencyMaskerSettings: CurrencyMaskerSettings?
): Mask = IBANMask()
},
TC_ID {
override fun create(
maskPattern: String?,
returnPattern: String?,
currencyMaskerSettings: CurrencyMaskerSettings?
): Mask = TCIdMask()
},
UNSELECTED {
override fun create(maskPattern: String?, returnPattern: String?): Mask =
UnselectedMask()
}
override fun create(
maskPattern: String?,
returnPattern: String?,
currencyMaskerSettings: CurrencyMaskerSettings?
): Mask = UnselectedMask()
},
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package com.hipo.maskededittext

import com.hipo.maskededittext.model.CurrencyMaskerSettings

interface MaskCreator {
fun create(maskPattern: String? = null, returnPattern: String? = null): Mask
fun create(
maskPattern: String? = null,
returnPattern: String? = null,
currencyMaskerSettings: CurrencyMaskerSettings? = null
): Mask
}
Loading