Skip to content

Commit 537fedf

Browse files
committed
add support of the dark theme
1 parent ff281e3 commit 537fedf

34 files changed

Lines changed: 284 additions & 74 deletions

app/build.gradle

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
apply plugin: 'com.android.application'
22
apply plugin: 'kotlin-android'
33
apply plugin: 'kotlin-android-extensions'
4+
apply plugin: 'kotlin-kapt'
45

56
android {
6-
compileSdkVersion 29
7+
compileSdkVersion 30
78
defaultConfig {
89
applicationId "com.omarshehe.forminputs"
910
minSdkVersion 16
10-
targetSdkVersion 29
11+
targetSdkVersion 30
1112
versionCode 1
1213
versionName "1.0.3"
1314
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -18,19 +19,19 @@ android {
1819
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
1920
}
2021
}
21-
// buildFeatures.viewBinding
22-
android {
23-
viewBinding.enabled = true
22+
23+
buildFeatures{
24+
dataBinding=true
2425
}
2526
}
2627

2728
dependencies {
2829
implementation fileTree(dir: 'libs', include: ['*.jar'])
2930
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
3031
implementation 'androidx.appcompat:appcompat:1.2.0'
31-
implementation 'androidx.core:core-ktx:1.3.1'
32-
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
33-
testImplementation 'junit:junit:4.13'
32+
implementation 'androidx.core:core-ktx:1.3.2'
33+
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
34+
testImplementation 'junit:junit:4.13.1'
3435
androidTestImplementation 'androidx.test:runner:1.3.0'
3536
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
3637
implementation 'com.google.android.material:material:1.2.1'

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
package="com.omarshehe.forminputs">
44

55
<application
6+
android:name=".Application"
67
android:allowBackup="true"
78
android:icon="@mipmap/ic_launcher"
89
android:label="@string/app_name"
910
android:roundIcon="@mipmap/ic_launcher_round"
1011
android:supportsRtl="true"
11-
android:theme="@style/AppTheme">
12+
android:theme="@style/AppTheme"
13+
android:fullBackupContent="true">
1214
<activity android:name=".MaterialView"
1315
android:theme="@style/MaterialComponentsStyle"/>
1416
<activity
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.omarshehe.forminputs
2+
3+
import android.app.Application
4+
import androidx.appcompat.app.AppCompatDelegate
5+
import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
6+
7+
8+
class Application : Application() {
9+
override fun onCreate() {
10+
super.onCreate()
11+
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM)
12+
}
13+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.omarshehe.forminputs
2+
3+
import android.view.Menu
4+
import android.view.MenuItem
5+
import androidx.appcompat.app.AppCompatActivity
6+
import androidx.appcompat.app.AppCompatDelegate
7+
import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO
8+
import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES
9+
10+
open class BaseActivity : AppCompatActivity() {
11+
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
12+
menuInflater.inflate(R.menu.main_menu, menu)
13+
return true
14+
}
15+
16+
override fun onOptionsItemSelected(item: MenuItem): Boolean {
17+
when (item.itemId) {
18+
R.id.action_dark -> AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES)
19+
R.id.action_light -> AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO)
20+
}
21+
return super.onOptionsItemSelected(item)
22+
}
23+
}

app/src/main/java/com/omarshehe/forminputs/MainActivity.kt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,24 @@ import android.content.Intent
44
import android.os.Bundle
55
import android.os.Handler
66
import android.widget.Toast
7-
import androidx.appcompat.app.AppCompatActivity
7+
import com.omarshehe.forminputkotlin.interfaces.OnTextChangeListener
88
import com.omarshehe.forminputkotlin.interfaces.SpinnerSelectionListener
99
import kotlinx.android.synthetic.main.activity_main.*
1010

11-
class MainActivity : AppCompatActivity() {
11+
class MainActivity : BaseActivity() {
1212

1313
override fun onCreate(savedInstanceState: Bundle?) {
1414
super.onCreate(savedInstanceState)
1515
setContentView(R.layout.activity_main)
1616

17-
1817
// set view to confirm the value
1918
confirmPassword.setViewToConfirm(password)
2019
confirmEmail.setViewToConfirm(email)
2120
confirmPin.setViewToConfirm(pin)
2221

2322
pin.setValues("1","2","3","4")
2423

25-
// startActivity(Intent(this, MaterialView::class.java))
24+
//startActivity(Intent(this, MaterialView::class.java))
2625
btnSubmit.setOnClickListener {
2726
if (gender.noError(mainView) &&
2827
country.noError(mainView) &&
@@ -40,7 +39,7 @@ class MainActivity : AppCompatActivity() {
4039
confirmPin.noError(mainView)) {
4140

4241
btnSubmit.showLoading(true)
43-
Handler().postDelayed({
42+
Handler(mainLooper).postDelayed({
4443
btnSubmit.showLoading(false)
4544
startActivity(Intent(this, Programmatically::class.java))
4645
}, 1000)
@@ -53,5 +52,12 @@ class MainActivity : AppCompatActivity() {
5352
}
5453
})
5554

55+
fullName.setOnTextChangeListener(object :OnTextChangeListener{
56+
override fun onTextChange(value: String) {
57+
Toast.makeText(baseContext,value,Toast.LENGTH_LONG).show()
58+
}
59+
60+
})
61+
5662
}
5763
}

app/src/main/java/com/omarshehe/forminputs/MaterialView.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class MaterialView : AppCompatActivity() {
1717
btnSubmit.setOnClickListener {
1818
if(txtFullName.noError(mainView) && txtEmail.noError(mainView) && txtPhoneNumber.noError(mainView)){
1919
btnSubmit.showLoading(true)
20-
Handler().postDelayed({
20+
Handler(mainLooper).postDelayed({
2121
btnSubmit.showLoading(false)
2222
}, 1000)
2323
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
2+
<item android:state_enabled="true"
3+
android:state_pressed="true"
4+
android:alpha="@dimen/hint_pressed_alpha_material_dark"
5+
android:color="@color/foreground_material_dark" />
6+
<item android:alpha="@dimen/hint_alpha_material_dark"
7+
android:color="@color/foreground_material_dark" />
8+
</selector>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:shape="rectangle">
4+
<corners android:radius="3dp" />
5+
<solid android:color="#272727" />
6+
<stroke
7+
android:width="0.8dp"
8+
android:color="#FFFFFF" />
9+
<padding
10+
android:bottom="1dp"
11+
android:left="1dp"
12+
android:right="1dp"
13+
android:top="1dp" />
14+
</shape>

app/src/main/res/layout/activity_main.xml

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
android:id="@+id/mainView"
66
android:layout_width="match_parent"
77
android:layout_height="match_parent"
8-
android:background="#F1F1F1"
98
android:orientation="vertical"
109
tools:context=".MainActivity">
1110

@@ -22,18 +21,22 @@
2221
android:id="@+id/gender"
2322
android:layout_width="match_parent"
2423
android:layout_height="wrap_content"
24+
app:form_textColor="@color/input_text_color"
25+
app:form_textColorLabel="@color/input_text_color"
2526
app:form_array="@array/array_gender"
2627
app:form_hint="Select gender"
2728
app:form_label="Gender"
2829
app:form_showLabel="false"
29-
app:form_textColor="@color/colorGrey" />
30+
/>
3031

3132

3233
<com.omarshehe.forminputkotlin.FormInputAutoComplete
3334
android:id="@+id/country"
3435
android:layout_width="match_parent"
3536
android:layout_height="wrap_content"
3637
android:layout_marginTop="16dp"
38+
app:form_textColor="@color/input_text_color"
39+
app:form_textColorLabel="@color/input_text_color"
3740
app:form_array="@array/array_country"
3841
app:form_height="@dimen/formInputInput_box_height"
3942
app:form_hint="Your country"
@@ -47,6 +50,8 @@
4750
android:layout_width="match_parent"
4851
android:layout_height="wrap_content"
4952
android:layout_marginTop="16dp"
53+
app:form_textColor="@color/input_text_color"
54+
app:form_textColorLabel="@color/input_text_color"
5055
app:form_hint="Your portfolio"
5156
app:form_inputType="url"
5257
app:form_label="Portfolio" />
@@ -56,6 +61,8 @@
5661
android:layout_width="match_parent"
5762
android:layout_height="wrap_content"
5863
android:layout_marginTop="16dp"
64+
app:form_textColor="@color/input_text_color"
65+
app:form_textColorLabel="@color/input_text_color"
5966
app:form_hint="Your full name"
6067
app:form_inputType="text"
6168
app:form_label="Full Name" />
@@ -66,6 +73,8 @@
6673
android:layout_width="match_parent"
6774
android:layout_height="wrap_content"
6875
android:layout_marginTop="16dp"
76+
app:form_textColor="@color/input_text_color"
77+
app:form_textColorLabel="@color/input_text_color"
6978
app:form_array="@array/array_currency"
7079
app:form_hint="Enter Price"
7180
app:form_inputType="number"
@@ -76,6 +85,8 @@
7685
android:layout_width="match_parent"
7786
android:layout_height="wrap_content"
7887
android:layout_marginTop="16dp"
88+
app:form_textColor="@color/input_text_color"
89+
app:form_textColorLabel="@color/input_text_color"
7990
app:form_hint="Your phone number"
8091
app:form_inputType="phoneNumber"
8192
app:form_isMandatory="false"
@@ -86,6 +97,8 @@
8697
android:layout_width="match_parent"
8798
android:layout_height="wrap_content"
8899
android:layout_marginTop="16dp"
100+
app:form_textColor="@color/input_text_color"
101+
app:form_textColorLabel="@color/input_text_color"
89102
app:form_hint="Your ID number"
90103
app:form_inputType="number"
91104
app:form_isMandatory="false"
@@ -97,6 +110,8 @@
97110
android:layout_width="match_parent"
98111
android:layout_height="wrap_content"
99112
android:layout_marginTop="16dp"
113+
app:form_textColor="@color/input_text_color"
114+
app:form_textColorLabel="@color/input_text_color"
100115
app:form_height="130dp"
101116
app:form_hint="About you"
102117
app:form_label="About you"
@@ -108,6 +123,8 @@
108123
android:layout_width="match_parent"
109124
android:layout_height="wrap_content"
110125
android:layout_marginTop="16dp"
126+
app:form_textColor="@color/input_text_color"
127+
app:form_textColorLabel="@color/input_text_color"
111128
app:form_hint="Your email address"
112129
app:form_inputType="email"
113130
app:form_label="Email" />
@@ -118,6 +135,8 @@
118135
android:layout_height="wrap_content"
119136
android:layout_marginTop="16dp"
120137
android:inputType="textAutoCorrect"
138+
app:form_textColor="@color/input_text_color"
139+
app:form_textColorLabel="@color/input_text_color"
121140
app:form_hint="Confirm email address"
122141
app:form_inputType="email"
123142
app:form_label="Confirm email" />
@@ -127,6 +146,8 @@
127146
android:layout_width="match_parent"
128147
android:layout_height="wrap_content"
129148
android:layout_marginTop="16dp"
149+
app:form_textColor="@color/input_text_color"
150+
app:form_textColorLabel="@color/input_text_color"
130151
app:form_hint="Your password"
131152
app:form_label="Password"
132153
app:form_showPassStrength="true"
@@ -137,6 +158,8 @@
137158
android:layout_width="match_parent"
138159
android:layout_height="wrap_content"
139160
android:layout_marginTop="16dp"
161+
app:form_textColor="@color/input_text_color"
162+
app:form_textColorLabel="@color/input_text_color"
140163
app:form_hint="Confirm your password"
141164
app:form_label="Confirm Password"
142165
app:form_showPassStrength="false" />
@@ -146,6 +169,8 @@
146169
android:layout_width="wrap_content"
147170
android:layout_height="wrap_content"
148171
android:layout_marginTop="16dp"
172+
app:form_textColor="@color/input_text_color"
173+
app:form_textColorLabel="@color/input_text_color"
149174
app:form_label="Pin"
150175
app:form_hint="0"/>
151176

@@ -154,6 +179,8 @@
154179
android:layout_width="wrap_content"
155180
android:layout_height="wrap_content"
156181
android:layout_marginTop="16dp"
182+
app:form_textColor="@color/input_text_color"
183+
app:form_textColorLabel="@color/input_text_color"
157184
app:form_label="Conform Pin"
158185
app:form_hint="0"
159186
app:form_inputType="number"/>
@@ -169,7 +196,7 @@
169196
android:textColor="@color/white"
170197
app:backgroundTint="@color/colorPrimary"
171198
app:cornerRadius="35dp"
172-
app:form_progressColor="@color/colorPink"
199+
app:form_progressColor="@color/colorAccent"
173200
app:form_showProgress="true"
174201
app:form_valueOnLoad="Please, wait.." />
175202
</LinearLayout>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<menu xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto">
4+
<item
5+
android:id="@+id/action_dark"
6+
android:orderInCategory="100"
7+
android:title="@string/dark"
8+
app:showAsAction="ifRoom" />
9+
<item
10+
android:id="@+id/action_light"
11+
android:orderInCategory="200"
12+
android:title="@string/light"
13+
app:showAsAction="ifRoom"/>
14+
</menu>

0 commit comments

Comments
 (0)