Skip to content

Commit 164d328

Browse files
committed
Initial Commit
0 parents  commit 164d328

File tree

9 files changed

+241
-0
lines changed

9 files changed

+241
-0
lines changed

.gitignore

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Eclipse
2+
.project
3+
.classpath
4+
.settings
5+
.checkstyle
6+
7+
# IntelliJ IDEA
8+
.idea
9+
*.iml
10+
*.ipr
11+
*.iws
12+
classes
13+
gen-external-apklibs
14+
15+
# Gradle
16+
gradle/
17+
.gradle
18+
build
19+
gradlew
20+
gradlew.bat
21+
22+
# Maven
23+
target
24+
release.properties
25+
pom.xml.*
26+
27+
# Ant
28+
bin
29+
gen
30+
build.xml
31+
ant.properties
32+
local.properties
33+
proguard.cfg
34+
proguard-project.txt
35+
36+
# Other
37+
.DS_Store
38+
tmp

README.md

Whitespace-only changes.

build.gradle

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
buildscript {
2+
repositories {
3+
mavenCentral()
4+
}
5+
6+
dependencies {
7+
classpath 'com.android.tools.build:gradle:0.6.+'
8+
}
9+
}
10+
11+
allprojects {
12+
group = 'com.wrapp.android'
13+
version = '1.0.0'
14+
15+
repositories {
16+
mavenCentral()
17+
}
18+
19+
tasks.withType(Compile) {
20+
options.encoding = "UTF-8"
21+
}
22+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="100" android:versionName="1.0.0" package="com.wrapp.android">
3+
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="17"/>
4+
<application/>
5+
</manifest>

floatlabelededittext/build.gradle

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
apply plugin: 'android-library'
2+
3+
dependencies {
4+
compile 'com.android.support:support-v4:18.0.+'
5+
}
6+
7+
dependencies {
8+
compile 'com.nineoldandroids:library:2.4.0'
9+
}
10+
11+
android {
12+
compileSdkVersion 14
13+
buildToolsVersion '17.0.0'
14+
15+
sourceSets {
16+
main {
17+
manifest.srcFile 'AndroidManifest.xml'
18+
java.srcDirs = ['src']
19+
res.srcDirs = ['res']
20+
}
21+
}
22+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- ~ Copyright (c) 2012 Bohemian Wrappsody AB. -->
3+
4+
<merge xmlns:android="http://schemas.android.com/apk/res/android"
5+
android:layout_width="wrap_content"
6+
android:layout_height="wrap_content"
7+
android:orientation="vertical">
8+
9+
<TextView
10+
android:paddingLeft="13dp"
11+
android:id="@+id/FloatLabeledEditTextHint"
12+
android:layout_height="wrap_content"
13+
android:layout_width="match_parent"
14+
android:text="Hint"
15+
android:textStyle="bold"/>
16+
17+
<EditText
18+
android:layout_height="wrap_content"
19+
android:layout_width="match_parent"
20+
android:layout_marginTop="-6dp"
21+
android:id="@+id/FloatLabeledEditTextEditText"/>
22+
23+
</merge>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<resources>
2+
<declare-styleable name="FloatLabeledEditText">
3+
<attr name="floatingHint" format="string"/>
4+
</declare-styleable>
5+
</resources>
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
package com.wrapp.android.views;
2+
3+
import android.content.Context;
4+
import android.content.res.TypedArray;
5+
import android.text.Editable;
6+
import android.text.TextWatcher;
7+
import android.util.AttributeSet;
8+
import android.view.LayoutInflater;
9+
import android.view.View;
10+
import android.widget.EditText;
11+
import android.widget.LinearLayout;
12+
import android.widget.TextView;
13+
14+
import com.nineoldandroids.animation.Animator;
15+
import com.nineoldandroids.animation.AnimatorListenerAdapter;
16+
import com.nineoldandroids.animation.AnimatorSet;
17+
import com.nineoldandroids.animation.ObjectAnimator;
18+
import com.wrapp.android.R;
19+
20+
public class FloatLabeledEditText extends LinearLayout {
21+
22+
private String hint;
23+
24+
private TextView hintTextView;
25+
private EditText editText;
26+
27+
public FloatLabeledEditText(Context context) {
28+
this(context, null);
29+
initialize();
30+
}
31+
32+
public FloatLabeledEditText(Context context, AttributeSet attrs) {
33+
this(context, attrs, 0);
34+
}
35+
36+
public FloatLabeledEditText(Context context, AttributeSet attrs, int defStyle) {
37+
super(context, attrs, defStyle);
38+
39+
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.FloatLabeledEditText);
40+
try {
41+
hint = a.getString(R.styleable.FloatLabeledEditText_floatingHint);
42+
} finally {
43+
a.recycle();
44+
}
45+
46+
initialize();
47+
}
48+
49+
private void initialize() {
50+
setOrientation(VERTICAL);
51+
52+
View view = LayoutInflater.from(getContext()).inflate(R.layout.float_labeled_edit_text, this);
53+
54+
hintTextView = (TextView) view.findViewById(R.id.FloatLabeledEditTextHint);
55+
editText = (EditText) view.findViewById(R.id.FloatLabeledEditTextEditText);
56+
57+
if (hint != null) {
58+
setHint(hint);
59+
}
60+
61+
hintTextView.setVisibility(View.INVISIBLE);
62+
editText.addTextChangedListener(onTextChanged);
63+
}
64+
65+
private TextWatcher onTextChanged = new TextWatcher() {
66+
@Override
67+
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
68+
}
69+
70+
@Override
71+
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
72+
}
73+
74+
@Override
75+
public void afterTextChanged(Editable editable) {
76+
setShowHint(editable.length() != 0);
77+
}
78+
};
79+
80+
private void setShowHint(final boolean show) {
81+
AnimatorSet animation = null;
82+
if ((hintTextView.getVisibility() == VISIBLE) && !show) {
83+
animation = new AnimatorSet();
84+
ObjectAnimator move = ObjectAnimator.ofFloat(hintTextView, "translationY", 0, hintTextView.getHeight() / 8);
85+
ObjectAnimator fade = ObjectAnimator.ofFloat(hintTextView, "alpha", 1, 0);
86+
animation.playTogether(move, fade);
87+
} else if ((hintTextView.getVisibility() != VISIBLE) && show) {
88+
animation = new AnimatorSet();
89+
ObjectAnimator move = ObjectAnimator.ofFloat(hintTextView, "translationY", hintTextView.getHeight() / 8, 0);
90+
ObjectAnimator fade = ObjectAnimator.ofFloat(hintTextView, "alpha", 0, 1);
91+
animation.playTogether(move, fade);
92+
}
93+
94+
if (animation != null) {
95+
animation.addListener(new AnimatorListenerAdapter() {
96+
@Override
97+
public void onAnimationStart(Animator animation) {
98+
super.onAnimationStart(animation);
99+
hintTextView.setVisibility(VISIBLE);
100+
}
101+
102+
@Override
103+
public void onAnimationEnd(Animator animation) {
104+
super.onAnimationEnd(animation);
105+
hintTextView.setVisibility(show ? VISIBLE : INVISIBLE);
106+
}
107+
});
108+
animation.start();
109+
}
110+
}
111+
112+
private void setHint(String hint) {
113+
this.hint = hint;
114+
editText.setHint(hint);
115+
hintTextView.setText(hint);
116+
}
117+
118+
public Editable getText() {
119+
return editText.getText();
120+
}
121+
122+
public void setText(CharSequence text) {
123+
editText.setText(text);
124+
}
125+
}

settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include 'floatlabelededittext'

0 commit comments

Comments
 (0)