Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6_2_X][TIMOB-24639] Android: Implement animated hintText via TextInputLayout #9267

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions android/dependency.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@
"media":["filesystem"],
"network":["xml"],
"platform":[],
"ui":["filesystem","media","appcompat","cardview","design"],
"ui":["appcompat","cardview","design","filesystem","media"],
"utils":[],
"xml":[]
},
"required": ["analytics","android","app","ui","locale","network"],
"libraries":
{
"android":["jaxen-1.1.1.jar","ti-commons-codec-1.3.jar","kroll-common.jar","titanium.jar","filesystem.jar","android-support-multidex.jar"],
"xml":["jaxen-1.1.1.jar"],
"ui":["nineoldandroids-appc-2.4.0.jar"],
"appcompat":["android-support-v4.jar", "android-support-v7-appcompat.jar", "android-support-animated-vector-drawable.jar", "android-support-annotations.jar", "android-support-compat.jar", "android-support-core-ui.jar", "android-support-core-utils.jar", "android-support-fragment.jar", "android-support-media-compat.jar", "android-support-vector-drawable.jar", "android-support-transition.jar", "android-support-v7-recyclerview.jar"],
"cardview":["android-support-v7-cardview.jar"],
"design":["android-support-design.jar"],
"android":["jaxen-1.1.1.jar","ti-commons-codec-1.3.jar","kroll-common.jar","titanium.jar","filesystem.jar","android-support-multidex.jar"],
"xml":["jaxen-1.1.1.jar"],
"ui":["nineoldandroids-appc-2.4.0.jar"],
"analytics":["aps-analytics.jar"]
},
"runtimes":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
TiC.PROPERTY_HINT_TEXT,
TiC.PROPERTY_HINT_TEXT_ID,
TiC.PROPERTY_HINT_TEXT_COLOR,
TiC.PROPERTY_HINT_TYPE,
TiC.PROPERTY_INPUT_TYPE,
TiC.PROPERTY_KEYBOARD_TYPE,
TiC.PROPERTY_MAX_LENGTH,
Expand All @@ -59,6 +60,7 @@ public TextFieldProxy()
defaultValues.put(TiC.PROPERTY_VALUE, "");
defaultValues.put(TiC.PROPERTY_MAX_LENGTH, -1);
defaultValues.put(TiC.PROPERTY_FULLSCREEN, true);
defaultValues.put(TiC.PROPERTY_HINT_TYPE, UIModule.HINT_TYPE_STATIC);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ public class UIModule extends KrollModule implements Handler.Callback
@Kroll.constant public static final int INPUT_TYPE_CLASS_NUMBER = InputType.TYPE_CLASS_NUMBER;
@Kroll.constant public static final int INPUT_TYPE_CLASS_TEXT = InputType.TYPE_CLASS_TEXT;

@Kroll.constant public static final int HINT_TYPE_STATIC = 0;
@Kroll.constant public static final int HINT_TYPE_ANIMATED = 1;

@Kroll.constant public static final int HIDDEN_BEHAVIOR_GONE = View.GONE;
@Kroll.constant public static final int HIDDEN_BEHAVIOR_INVISIBLE = View.INVISIBLE;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@
import org.appcelerator.titanium.view.TiUIView;

import ti.modules.titanium.ui.AttributedStringProxy;
import ti.modules.titanium.ui.UIModule;

import android.content.Context;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.os.Build;
import android.os.Bundle;
import android.support.design.widget.TextInputLayout;
import android.text.Editable;
import android.text.InputFilter;
import android.text.InputType;
Expand All @@ -45,6 +48,7 @@
import android.view.inputmethod.InputMethodManager;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;

Expand Down Expand Up @@ -88,6 +92,7 @@ public class TiUIText extends TiUIView
private boolean disableChangeEvent = false;

protected TiUIEditText tv;
protected TextInputLayout textInputLayout;

public TiUIText(final TiViewProxy proxy, boolean field)
{
Expand Down Expand Up @@ -130,7 +135,10 @@ public void onLayoutChange(View v, int left, int top, int right, int bottom, int
} else {
tv.setGravity(Gravity.TOP | Gravity.LEFT);
}
setNativeView(tv);

textInputLayout = new TextInputLayout(proxy.getActivity());
textInputLayout.addView(tv, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
setNativeView(textInputLayout);
}

@Override
Expand Down Expand Up @@ -159,7 +167,15 @@ public void processProperties(KrollDict d)
}

if (d.containsKey(TiC.PROPERTY_HINT_TEXT)) {
tv.setHint(d.getString(TiC.PROPERTY_HINT_TEXT));
String hintText = d.getString(TiC.PROPERTY_HINT_TEXT);
if (hintText != null) {
int type = TiConvert.toInt(d.get(TiC.PROPERTY_HINT_TYPE), UIModule.HINT_TYPE_STATIC);
if (type == UIModule.HINT_TYPE_STATIC) {
tv.setHint(hintText);
} else if (type == UIModule.HINT_TYPE_ANIMATED) {
textInputLayout.setHint(hintText);
}
}
}

if (d.containsKey(TiC.PROPERTY_HINT_TEXT_COLOR)) {
Expand Down Expand Up @@ -285,6 +301,18 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
tv.setHint(TiConvert.toString(newValue));
} else if (key.equals(TiC.PROPERTY_HINT_TEXT_COLOR)) {
tv.setHintTextColor(TiConvert.toColor((String) newValue));
} else if (key.equals(TiC.PROPERTY_HINT_TYPE)) {
String hintText = TiConvert.toString(proxy.getProperty(TiC.PROPERTY_HINT_TEXT));
if (hintText != null) {
int type = TiConvert.toInt(newValue);
if (type == UIModule.HINT_TYPE_STATIC) {
textInputLayout.setHint("");
tv.setHint(hintText);
} else if (type == UIModule.HINT_TYPE_ANIMATED) {
tv.setHint("");
textInputLayout.setHint(hintText);
}
}
} else if (key.equals(TiC.PROPERTY_ELLIPSIZE)) {
if (TiConvert.toBoolean(newValue)) {
tv.setEllipsize(TruncateAt.END);
Expand Down
5 changes: 5 additions & 0 deletions android/titanium/src/java/org/appcelerator/titanium/TiC.java
Original file line number Diff line number Diff line change
Expand Up @@ -1577,6 +1577,11 @@ public class TiC
*/
public static final String PROPERTY_HINT_TEXT_COLOR = "hintTextColor";

/**
* @module.api
*/
public static final String PROPERTY_HINT_TYPE = "hintType";

/**
* @module.api
*/
Expand Down
10 changes: 10 additions & 0 deletions apidoc/Titanium/UI/TextField.yml
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,16 @@ properties:
type: String
since: "6.2.0"

- name: hintType
summary: Hint type to display on the text field.
platforms: [android]
since: {android: "6.2.0"}
description: |
Setting this to <Titanium.UI.HINT_TYPE_ANIMATED> will use the animated TextInputLayout on Android.
type: Number
constants: [Titanium.UI.HINT_TYPE_*]
default: <Titanium.UI.HINT_TYPE_STATIC>

- name: inputType
summary: Input type to accept in the text field. Also influences the Keyboard type to display.
description: |
Expand Down
18 changes: 18 additions & 0 deletions apidoc/Titanium/UI/UI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,24 @@ properties:
type: Number
permission: read-only
platforms: [iphone, ipad]

- name: HINT_TYPE_STATIC
deprecated:
since: "6.2.0"
summary: |
Use when creating a TextField to specify the hintType as static.
type: Number
permission: read-only
platforms: [android]

- name: HINT_TYPE_ANIMATED
deprecated:
since: "6.2.0"
summary: |
Use when creating a TextField to specify the hintType as animated.
type: Number
permission: read-only
platforms: [android]

- name: TEXT_ELLIPSIZE_TRUNCATE_WORD_WRAP
summary: Add ellipses at word boundaries, unless the word itself doesn't fit on a single line.
Expand Down