Skip to content
This repository was archived by the owner on Feb 8, 2022. It is now read-only.

Commit 7add9bf

Browse files
author
florent champigny
committed
1.0.6 hasfocus
1 parent 93f9748 commit 7add9bf

File tree

7 files changed

+63
-27
lines changed

7 files changed

+63
-27
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ compile 'com.github.florent37:materialtextfield:1.0.5'
6464

6565
#Log
6666

67+
1.0.6
68+
- support focusability
69+
- added `app:mtf_hasFocus="false"`
70+
6771
1.0.3
6872

6973
- removed some dependencies

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ext {
1919
sdk = 23
2020
buildTools = "23.0.3"
2121
minSdk = 10
22-
libraryVersion = "1.0.5"
22+
libraryVersion = "1.0.6"
2323
supportVersion = "23.4.0"
2424
}
2525

materialtextfield/materialtextfield.iml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<module external.linked.project.id=":materialtextfield" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="com.github.florent37" external.system.module.version="1.0.5" type="JAVA_MODULE" version="4">
2+
<module external.linked.project.id=":materialtextfield" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="com.github.florent37" external.system.module.version="1.0.6" type="JAVA_MODULE" version="4">
33
<component name="FacetManager">
44
<facet type="android-gradle" name="Android-Gradle">
55
<configuration>
@@ -65,14 +65,6 @@
6565
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
6666
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
6767
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
68-
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
69-
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
70-
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
71-
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
72-
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
73-
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
74-
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
75-
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
7668
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
7769
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
7870
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
@@ -81,9 +73,16 @@
8173
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
8274
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
8375
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
76+
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
77+
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
78+
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
79+
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
80+
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
81+
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
82+
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
83+
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
8484
<excludeFolder url="file://$MODULE_DIR$/build/docs" />
8585
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/annotations" />
86-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
8786
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
8887
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
8988
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
@@ -99,7 +98,6 @@
9998
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
10099
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
101100
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
102-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
103101
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
104102
<excludeFolder url="file://$MODULE_DIR$/build/libs" />
105103
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />

materialtextfield/src/main/java/com/github/florent37/materialtextfield/MaterialTextField.java

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
*/
2121
public class MaterialTextField extends FrameLayout {
2222

23-
2423
protected TextView label;
2524
protected View card;
2625
protected ImageView image;
@@ -35,6 +34,7 @@ public class MaterialTextField extends FrameLayout {
3534
protected int labelColor = -1;
3635
protected int imageDrawableId = -1;
3736
protected int cardCollapsedHeight = -1;
37+
protected boolean hasFocus = false;
3838

3939
protected float reducedScale = 0.2f;
4040

@@ -44,7 +44,7 @@ public MaterialTextField(Context context) {
4444

4545
public MaterialTextField(Context context, AttributeSet attrs) {
4646
super(context, attrs);
47-
handleAttributes(context,attrs);
47+
handleAttributes(context, attrs);
4848
}
4949

5050
public MaterialTextField(Context context, AttributeSet attrs, int defStyleAttr) {
@@ -93,7 +93,6 @@ public void onAnimationUpdate(View view) {
9393
.scaleY(reducedScale)
9494
.setDuration(ANIMATION_DURATION);
9595

96-
9796
if (OPEN_KEYBOARD_ON_FOCUS) {
9897
((InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
9998
}
@@ -127,7 +126,9 @@ public void expand() {
127126
.scaleY(1f)
128127
.setDuration(ANIMATION_DURATION);
129128

130-
editText.requestFocus();
129+
if (editText != null) {
130+
editText.requestFocus();
131+
}
131132
if (OPEN_KEYBOARD_ON_FOCUS) {
132133
((InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
133134
}
@@ -160,6 +161,33 @@ public boolean isExpanded() {
160161
return expanded;
161162
}
162163

164+
public void setHasFocus(boolean hasFocus) {
165+
this.hasFocus = hasFocus;
166+
final InputMethodManager inputMethodManager = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
167+
if (hasFocus) {
168+
expand();
169+
editText.postDelayed(new Runnable() {
170+
public void run() {
171+
editText.requestFocusFromTouch();
172+
inputMethodManager.showSoftInput(editText, 0);
173+
}
174+
}, 300);
175+
} else {
176+
reduce();
177+
}
178+
}
179+
180+
@Override
181+
public void requestChildFocus(View child, View focused) {
182+
super.requestChildFocus(child, focused);
183+
184+
if (focused != null) {
185+
setHasFocus(true);
186+
} else {
187+
setHasFocus(false);
188+
}
189+
}
190+
163191
protected void handleAttributes(Context context, AttributeSet attrs) {
164192
try {
165193
TypedArray styledAttrs = context.obtainStyledAttributes(attrs, R.styleable.MaterialTextField);
@@ -179,6 +207,9 @@ protected void handleAttributes(Context context, AttributeSet attrs) {
179207
{
180208
cardCollapsedHeight = styledAttrs.getDimensionPixelOffset(R.styleable.MaterialTextField_mtf_cardCollapsedHeight, context.getResources().getDimensionPixelOffset(R.dimen.mtf_cardHeight_initial));
181209
}
210+
{
211+
hasFocus = styledAttrs.getBoolean(R.styleable.MaterialTextField_mtf_hasFocus, false);
212+
}
182213

183214
styledAttrs.recycle();
184215
} catch (Exception e) {
@@ -245,6 +276,7 @@ public void onClick(View v) {
245276
}
246277
});
247278

279+
setHasFocus(hasFocus);
248280
}
249281

250282
protected void customizeFromAttributes() {

materialtextfield/src/main/res/values/attrs.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<attr name="mtf_cardCollapsedHeight" format="dimension"/>
55
<attr name="mtf_labelColor" format="color"/>
66
<attr name="mtf_image" format="reference"/>
7+
<attr name="mtf_hasFocus" format="boolean"/>
78
<attr name="mtf_animationDuration" format="integer"/>
89
<attr name="mtf_openKeyboardOnFocus" format="boolean"/>
910
</declare-styleable>

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2-
xmlns:tools="http://schemas.android.com/tools"
3-
android:layout_width="match_parent"
4-
android:layout_height="match_parent"
5-
xmlns:app="http://schemas.android.com/apk/res-auto"
6-
android:orientation="vertical"
7-
android:background="#4644aa">
2+
xmlns:app="http://schemas.android.com/apk/res-auto"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
android:background="#4644aa"
6+
android:orientation="vertical">
87

98
<android.support.v7.widget.Toolbar
109
android:id="@+id/toolbar"
11-
android:background="#3FFF"
1210
android:layout_width="match_parent"
13-
android:layout_height="wrap_content" />
11+
android:layout_height="wrap_content"
12+
android:background="#3FFF"/>
1413

1514
<com.github.florent37.materialtextfield.MaterialTextField
1615
android:layout_width="300dp"
17-
android:layout_gravity="center_horizontal"
1816
android:layout_height="wrap_content"
17+
android:layout_gravity="center_horizontal"
1918
android:layout_marginLeft="4dp"
2019
android:layout_marginRight="4dp"
2120
android:layout_marginTop="20dp"
2221
app:mtf_cardCollapsedHeight="4dp"
22+
app:mtf_hasFocus="false"
2323
app:mtf_image="@drawable/ic_mail_grey600_24dp"
2424
>
2525

@@ -33,8 +33,9 @@
3333
<EditText
3434
android:layout_width="match_parent"
3535
android:layout_height="wrap_content"
36-
android:textColor="#333"
3736
android:hint="Email"
37+
android:singleLine="true"
38+
android:textColor="#333"
3839
android:textColorHint="#666"
3940
android:textSize="15sp" />
4041

sample/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<resources>
2-
<string name="app_name">Sample</string>
2+
<string name="app_name">MaterialTextField</string>
33

44
<string name="hello_world">Hello world!</string>
55
<string name="action_settings">Settings</string>

0 commit comments

Comments
 (0)