├── .gitignore ├── FloatLabel ├── .settings │ └── org.eclipse.jdt.core.prefs ├── AndroidManifest.xml ├── build.gradle ├── gradle.properties ├── libs │ └── android-support-v4.jar ├── proguard-project.txt ├── project.properties ├── res │ ├── layout │ │ └── float_label.xml │ └── values │ │ ├── attrs.xml │ │ ├── ids.xml │ │ └── strings.xml └── src │ └── com │ └── iangclifton │ └── android │ └── floatlabel │ └── FloatLabel.java ├── FloatLabelExample ├── .settings │ └── org.eclipse.jdt.core.prefs ├── AndroidManifest.xml ├── build.gradle ├── ic_launcher-web.png ├── libs │ └── android-support-v4.jar ├── proguard-project.txt ├── project.properties ├── res │ ├── drawable-hdpi │ │ ├── custom_hint_color.xml │ │ ├── ic_action_github.png │ │ └── ic_launcher.png │ ├── drawable-mdpi │ │ ├── ic_action_github.png │ │ └── ic_launcher.png │ ├── drawable-xhdpi │ │ ├── ic_action_github.png │ │ └── ic_launcher.png │ ├── drawable-xxhdpi │ │ ├── ic_action_github.png │ │ └── ic_launcher.png │ ├── layout │ │ ├── activity_about.xml │ │ ├── activity_main.xml │ │ └── custom_float_label.xml │ ├── menu │ │ ├── about.xml │ │ └── main.xml │ ├── values-sw600dp │ │ └── dimens.xml │ ├── values-sw720dp-land │ │ └── dimens.xml │ ├── values-w820dp │ │ └── dimens.xml │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml └── src │ └── com │ └── iangclifton │ └── android │ └── floatlabelexample │ ├── AboutActivity.java │ └── MainActivity.java ├── LICENSE ├── README.md ├── build.gradle ├── changelog.md ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ ├── gradle-wrapper.properties │ └── gradle-wrapper.properties~ ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # files for the dex VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # generated files 12 | bin/ 13 | gen/ 14 | build/ 15 | 16 | # Local configuration file (sdk path, etc) 17 | local.properties 18 | 19 | # Eclipse project files 20 | .classpath 21 | .project 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Intellij project files 27 | .gradle 28 | *.iml 29 | *.ipr 30 | *.iws 31 | .idea/ 32 | -------------------------------------------------------------------------------- /FloatLabel/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 3 | org.eclipse.jdt.core.compiler.compliance=1.6 4 | org.eclipse.jdt.core.compiler.source=1.6 5 | -------------------------------------------------------------------------------- /FloatLabel/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 8 | 9 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /FloatLabel/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | dependencies { 4 | //compile fileTree(dir: 'libs', include: '*.jar') 5 | // compile 'com.android.support:support-v13:13.0.0' 6 | } 7 | 8 | android { 9 | compileSdkVersion 19 10 | buildToolsVersion "19.1.0" 11 | 12 | sourceSets { 13 | main { 14 | manifest.srcFile 'AndroidManifest.xml' 15 | java.srcDirs = ['src'] 16 | resources.srcDirs = ['src'] 17 | aidl.srcDirs = ['src'] 18 | renderscript.srcDirs = ['src'] 19 | res.srcDirs = ['res'] 20 | assets.srcDirs = ['assets'] 21 | } 22 | 23 | // Move the tests to tests/java, tests/res, etc... 24 | instrumentTest.setRoot('tests') 25 | 26 | // Move the build types to build-types/ 27 | // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ... 28 | // This moves them out of them default location under src//... which would 29 | // conflict with src/ being used by the main source set. 30 | // Adding new build types or product flavors should be accompanied 31 | // by a similar customization. 32 | debug.setRoot('build-types/debug') 33 | release.setRoot('build-types/release') 34 | } 35 | } 36 | 37 | apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle' 38 | -------------------------------------------------------------------------------- /FloatLabel/gradle.properties: -------------------------------------------------------------------------------- 1 | POM_NAME=Android Float Label 2 | POM_ARTIFACT_ID=floatlabel 3 | POM_PACKAGING=aar 4 | -------------------------------------------------------------------------------- /FloatLabel/libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IanGClifton/AndroidFloatLabel/b0a39c26f010f17d5f3648331e9784a41e025c0d/FloatLabel/libs/android-support-v4.jar -------------------------------------------------------------------------------- /FloatLabel/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /FloatLabel/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-19 15 | android.library=true 16 | -------------------------------------------------------------------------------- /FloatLabel/res/layout/float_label.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 13 | 14 | 15 | 21 | 22 | -------------------------------------------------------------------------------- /FloatLabel/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /FloatLabel/res/values/ids.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /FloatLabel/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Float Label 4 | 5 | 6 | -------------------------------------------------------------------------------- /FloatLabel/src/com/iangclifton/android/floatlabel/FloatLabel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Ian G. Clifton 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.iangclifton.android.floatlabel; 17 | 18 | import android.annotation.TargetApi; 19 | import android.content.Context; 20 | import android.content.res.ColorStateList; 21 | import android.content.res.TypedArray; 22 | import android.os.Build; 23 | import android.os.Bundle; 24 | import android.os.Parcelable; 25 | import android.text.Editable; 26 | import android.text.InputType; 27 | import android.text.TextWatcher; 28 | import android.util.AttributeSet; 29 | import android.view.Gravity; 30 | import android.view.View; 31 | import android.widget.EditText; 32 | import android.widget.FrameLayout; 33 | import android.widget.TextView; 34 | 35 | /** 36 | * A ViewGroup that consists of an EditText and a TextView as the label.
37 | *
38 | * When the EditText is empty, its hint is displayed. When it is nonempty, the 39 | * TextView label is displayed.
40 | *
41 | * You can set the label programmatically with either 42 | * {@link #setLabel(CharSequence)} or {@link #setLabel(int)}. 43 | * 44 | * @author Ian G. Clifton 45 | * @see Float 47 | * label inspiration on Dribbble 48 | */ 49 | public class FloatLabel extends FrameLayout { 50 | 51 | private static final String SAVE_STATE_KEY_EDIT_TEXT = "saveStateEditText"; 52 | private static final String SAVE_STATE_KEY_LABEL = "saveStateLabel"; 53 | private static final String SAVE_STATE_PARENT = "saveStateParent"; 54 | private static final String SAVE_STATE_TAG = "saveStateTag"; 55 | private static final String SAVE_STATE_KEY_FOCUS = "saveStateFocus"; 56 | 57 | /** 58 | * Reference to the EditText 59 | */ 60 | private EditText mEditText; 61 | 62 | /** 63 | * When init is complete, child views can no longer be added 64 | */ 65 | private boolean mInitComplete = false; 66 | 67 | /** 68 | * Reference to the TextView used as the label 69 | */ 70 | private TextView mLabel; 71 | 72 | /** 73 | * LabelAnimator that animates the appearance and disappearance of the label TextView 74 | */ 75 | private LabelAnimator mLabelAnimator = new DefaultLabelAnimator(); 76 | 77 | /** 78 | * True if the TextView label is showing (alpha 1f) 79 | */ 80 | private boolean mLabelShowing; 81 | 82 | /** 83 | * Holds saved state if any is waiting to be restored 84 | */ 85 | private Bundle mSavedState; 86 | 87 | /** 88 | * True when any setTextWithoutAnimation method is called and then immediately turned false 89 | * once the text update has finished. 90 | */ 91 | private boolean mSkipAnimation = false; 92 | 93 | /** 94 | * Interface for providing custom animations to the label TextView. 95 | */ 96 | public interface LabelAnimator { 97 | 98 | /** 99 | * Called when the label should become visible 100 | * 101 | * @param label TextView to animate to visible 102 | */ 103 | public void onDisplayLabel(View label); 104 | 105 | /** 106 | * Called when the label should become invisible 107 | * 108 | * @param label TextView to animate to invisible 109 | */ 110 | public void onHideLabel(View label); 111 | } 112 | 113 | public FloatLabel(Context context) { 114 | this(context, null, 0); 115 | } 116 | 117 | public FloatLabel(Context context, AttributeSet attrs) { 118 | this(context, attrs, 0); 119 | } 120 | 121 | public FloatLabel(Context context, AttributeSet attrs, int defStyle) { 122 | super(context, attrs, defStyle); 123 | init(context, attrs, defStyle); 124 | } 125 | 126 | @Override 127 | public void addView(View child) { 128 | if (mInitComplete) { 129 | throw new UnsupportedOperationException("You cannot add child views to a FloatLabel"); 130 | } else { 131 | super.addView(child); 132 | } 133 | } 134 | 135 | @Override 136 | public void addView(View child, int index) { 137 | if (mInitComplete) { 138 | throw new UnsupportedOperationException("You cannot add child views to a FloatLabel"); 139 | } else { 140 | super.addView(child, index); 141 | } 142 | } 143 | 144 | @Override 145 | public void addView(View child, int index, android.view.ViewGroup.LayoutParams params) { 146 | if (mInitComplete) { 147 | throw new UnsupportedOperationException("You cannot add child views to a FloatLabel"); 148 | } else { 149 | super.addView(child, index, params); 150 | } 151 | } 152 | 153 | @Override 154 | public void addView(View child, int width, int height) { 155 | if (mInitComplete) { 156 | throw new UnsupportedOperationException("You cannot add child views to a FloatLabel"); 157 | } else { 158 | super.addView(child, width, height); 159 | } 160 | } 161 | 162 | @Override 163 | public void addView(View child, android.view.ViewGroup.LayoutParams params) { 164 | if (mInitComplete) { 165 | throw new UnsupportedOperationException("You cannot add child views to a FloatLabel"); 166 | } else { 167 | super.addView(child, params); 168 | } 169 | } 170 | 171 | /** 172 | * Returns the EditText portion of this View 173 | * 174 | * @return the EditText portion of this View 175 | */ 176 | public EditText getEditText() { 177 | return mEditText; 178 | } 179 | 180 | /** 181 | * Returns the label portion of this View 182 | * 183 | * @return the label portion of this View 184 | */ 185 | public TextView getLabel() { 186 | return mLabel; 187 | } 188 | 189 | /** 190 | * Sets the text to be displayed above the EditText if the EditText is 191 | * nonempty or as the EditText hint if it is empty 192 | * 193 | * @param resid 194 | * int String resource ID 195 | */ 196 | public void setLabel(int resid) { 197 | setLabel(getContext().getString(resid)); 198 | } 199 | 200 | /** 201 | * Sets the text to be displayed above the EditText if the EditText is 202 | * nonempty or as the EditText hint if it is empty 203 | * 204 | * @param hint 205 | * CharSequence to set as the label 206 | */ 207 | public void setLabel(CharSequence hint) { 208 | mEditText.setHint(hint); 209 | mLabel.setText(hint); 210 | } 211 | 212 | /** 213 | * Specifies a new LabelAnimator to handle calls to show/hide the label 214 | * 215 | * @param labelAnimator LabelAnimator to use; null causes use of the default LabelAnimator 216 | */ 217 | public void setLabelAnimator(LabelAnimator labelAnimator) { 218 | if (labelAnimator == null) { 219 | mLabelAnimator = new DefaultLabelAnimator(); 220 | } else { 221 | mLabelAnimator = labelAnimator; 222 | } 223 | } 224 | 225 | /** 226 | * Sets the EditText's text with animation 227 | * 228 | * @param resid int String resource ID 229 | */ 230 | public void setText(int resid) { 231 | mEditText.setText(resid); 232 | } 233 | 234 | /** 235 | * Sets the EditText's text with label animation 236 | * 237 | * @param text char[] text 238 | * @param start int start of char array to use 239 | * @param len int characters to use from the array 240 | */ 241 | public void setText(char[] text, int start, int len) { 242 | mEditText.setText(text, start, len); 243 | } 244 | 245 | /** 246 | * Sets the EditText's text with label animation 247 | * 248 | * @param resid int String resource ID 249 | * @param type TextView.BufferType 250 | */ 251 | public void setText(int resid, TextView.BufferType type) { 252 | mEditText.setText(resid, type); 253 | } 254 | 255 | /** 256 | * Sets the EditText's text with label animation 257 | * 258 | * @param text CharSequence to set 259 | */ 260 | public void setText(CharSequence text) { 261 | mEditText.setText(text); 262 | } 263 | 264 | /** 265 | * Sets the EditText's text with label animation 266 | * 267 | * @param text CharSequence to set 268 | * @param type TextView.BufferType 269 | */ 270 | public void setText(CharSequence text, TextView.BufferType type) { 271 | mEditText.setText(text, type); 272 | } 273 | 274 | /** 275 | * Sets the EditText's text without animating the label 276 | * 277 | * @param resid int String resource ID 278 | */ 279 | public void setTextWithoutAnimation(int resid) { 280 | mSkipAnimation = true; 281 | mEditText.setText(resid); 282 | } 283 | 284 | /** 285 | * Sets the EditText's text without animating the label 286 | * 287 | * @param text char[] text 288 | * @param start int start of char array to use 289 | * @param len int characters to use from the array 290 | */ 291 | public void setTextWithoutAnimation(char[] text, int start, int len) { 292 | mSkipAnimation = true; 293 | mEditText.setText(text, start, len); 294 | } 295 | 296 | /** 297 | * Sets the EditText's text without animating the label 298 | * 299 | * @param resid int String resource ID 300 | * @param type TextView.BufferType 301 | */ 302 | public void setTextWithoutAnimation(int resid, TextView.BufferType type) { 303 | mSkipAnimation = true; 304 | mEditText.setText(resid, type); 305 | } 306 | 307 | /** 308 | * Sets the EditText's text without animating the label 309 | * 310 | * @param text CharSequence to set 311 | */ 312 | public void setTextWithoutAnimation(CharSequence text) { 313 | mSkipAnimation = true; 314 | mEditText.setText(text); 315 | } 316 | 317 | /** 318 | * Sets the EditText's text without animating the label 319 | * 320 | * @param text CharSequence to set 321 | * @param type TextView.BufferType 322 | */ 323 | public void setTextWithoutAnimation(CharSequence text, TextView.BufferType type) { 324 | mSkipAnimation = true; 325 | mEditText.setText(text, type); 326 | } 327 | 328 | @Override 329 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { 330 | final int childLeft = getPaddingLeft(); 331 | final int childRight = right - left - getPaddingRight(); 332 | 333 | int childTop = getPaddingTop(); 334 | final int childBottom = bottom - top - getPaddingBottom(); 335 | 336 | layoutChild(mLabel, childLeft, childTop, childRight, childBottom); 337 | layoutChild(mEditText, childLeft, childTop + mLabel.getMeasuredHeight() , childRight, childBottom); 338 | } 339 | 340 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) 341 | private void layoutChild(View child, int parentLeft, int parentTop, int parentRight, int parentBottom) { 342 | if (child.getVisibility() != GONE) { 343 | final LayoutParams lp = (LayoutParams) child.getLayoutParams(); 344 | 345 | final int width = child.getMeasuredWidth(); 346 | final int height = child.getMeasuredHeight(); 347 | 348 | int childLeft; 349 | final int childTop = parentTop + lp.topMargin; 350 | 351 | int gravity = lp.gravity; 352 | if (gravity == -1) { 353 | gravity = Gravity.TOP | Gravity.START; 354 | } 355 | 356 | final int layoutDirection; 357 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { 358 | layoutDirection = LAYOUT_DIRECTION_LTR; 359 | } else { 360 | layoutDirection = getLayoutDirection(); 361 | } 362 | 363 | final int absoluteGravity = Gravity.getAbsoluteGravity(gravity, layoutDirection); 364 | 365 | switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { 366 | case Gravity.CENTER_HORIZONTAL: 367 | childLeft = parentLeft + (parentRight - parentLeft - width) / 2 + lp.leftMargin - lp.rightMargin; 368 | break; 369 | case Gravity.END: 370 | childLeft = parentRight - width - lp.rightMargin; 371 | break; 372 | case Gravity.START: 373 | default: 374 | childLeft = parentLeft + lp.leftMargin; 375 | } 376 | 377 | child.layout(childLeft, childTop, childLeft + width, childTop + height); 378 | } 379 | } 380 | 381 | @Override 382 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 383 | // Restore any state that's been pending before measuring 384 | if (mSavedState != null) { 385 | Parcelable childState = mSavedState.getParcelable(SAVE_STATE_KEY_EDIT_TEXT); 386 | mEditText.onRestoreInstanceState(childState); 387 | childState = mSavedState.getParcelable(SAVE_STATE_KEY_LABEL); 388 | mLabel.onRestoreInstanceState(childState); 389 | if (mSavedState.getBoolean(SAVE_STATE_KEY_FOCUS, false)) { 390 | mEditText.requestFocus(); 391 | } 392 | mSavedState = null; 393 | } 394 | measureChild(mEditText, widthMeasureSpec, heightMeasureSpec); 395 | measureChild(mLabel, widthMeasureSpec, heightMeasureSpec); 396 | setMeasuredDimension(measureWidth(widthMeasureSpec), measureHeight(heightMeasureSpec)); 397 | } 398 | 399 | @Override 400 | protected void onRestoreInstanceState(Parcelable state) { 401 | if (state instanceof Bundle) { 402 | final Bundle savedState = (Bundle) state; 403 | if (savedState.getBoolean(SAVE_STATE_TAG, false)) { 404 | // Save our state for later since children will have theirs restored after this 405 | // and having more than one FloatLabel in an Activity or Fragment means you have 406 | // multiple views of the same ID 407 | mSavedState = savedState; 408 | super.onRestoreInstanceState(savedState.getParcelable(SAVE_STATE_PARENT)); 409 | return; 410 | } 411 | } 412 | 413 | super.onRestoreInstanceState(state); 414 | } 415 | 416 | @Override 417 | protected Parcelable onSaveInstanceState() { 418 | final Parcelable superState = super.onSaveInstanceState(); 419 | final Bundle saveState = new Bundle(); 420 | saveState.putParcelable(SAVE_STATE_KEY_EDIT_TEXT, mEditText.onSaveInstanceState()); 421 | saveState.putParcelable(SAVE_STATE_KEY_LABEL, mLabel.onSaveInstanceState()); 422 | saveState.putBoolean(SAVE_STATE_KEY_FOCUS, mEditText.isFocused()); 423 | saveState.putBoolean(SAVE_STATE_TAG, true); 424 | saveState.putParcelable(SAVE_STATE_PARENT, superState); 425 | 426 | return saveState; 427 | } 428 | 429 | private int measureHeight(int heightMeasureSpec) { 430 | int specMode = MeasureSpec.getMode(heightMeasureSpec); 431 | int specSize = MeasureSpec.getSize(heightMeasureSpec); 432 | 433 | int result = 0; 434 | if (specMode == MeasureSpec.EXACTLY) { 435 | result = specSize; 436 | } else { 437 | result = mEditText.getMeasuredHeight() + mLabel.getMeasuredHeight(); 438 | result += getPaddingTop() + getPaddingBottom(); 439 | result = Math.max(result, getSuggestedMinimumHeight()); 440 | 441 | if (specMode == MeasureSpec.AT_MOST) { 442 | result = Math.min(result, specSize); 443 | } 444 | } 445 | 446 | return result; 447 | } 448 | 449 | private int measureWidth(int widthMeasureSpec) { 450 | int specMode = MeasureSpec.getMode(widthMeasureSpec); 451 | int specSize = MeasureSpec.getSize(widthMeasureSpec); 452 | 453 | int result = 0; 454 | if (specMode == MeasureSpec.EXACTLY) { 455 | result = specSize; 456 | } else { 457 | result = Math.max(mEditText.getMeasuredWidth(), mLabel.getMeasuredWidth()); 458 | result = Math.max(result, getSuggestedMinimumWidth()); 459 | result += getPaddingLeft() + getPaddingRight(); 460 | if (specMode == MeasureSpec.AT_MOST) { 461 | result = Math.min(result, specSize); 462 | } 463 | } 464 | 465 | return result; 466 | } 467 | 468 | /** 469 | * Initializes the view's default values and values from attrs, if not null 470 | * 471 | * @param context Context to access styled attributes 472 | * @param attrs AttributeSet from constructor or null 473 | * @param defStyle int resource ID of style to use for defaults 474 | */ 475 | private void init(Context context, AttributeSet attrs, int defStyle) { 476 | // Load custom attributes 477 | final int layout; 478 | int editTextId = R.id.edit_text; 479 | int floatLabelId = R.id.float_label; 480 | final CharSequence text; 481 | final CharSequence hint; 482 | final ColorStateList hintColor; 483 | final int floatLabelColor; 484 | final int imeOptions; 485 | final int inputType; 486 | final int nextFocusDownId; 487 | final int nextFocusForwardId; 488 | final int nextFocusLeftId; 489 | final int nextFocusRightId; 490 | final int nextFocusUpId; 491 | 492 | if (attrs == null) { 493 | layout = R.layout.float_label; 494 | text = null; 495 | hint = null; 496 | hintColor = null; 497 | floatLabelColor = 0; 498 | imeOptions = 0; 499 | inputType = 0; 500 | nextFocusDownId = NO_ID; 501 | nextFocusForwardId = NO_ID; 502 | nextFocusLeftId = NO_ID; 503 | nextFocusRightId = NO_ID; 504 | nextFocusUpId = NO_ID; 505 | } else { 506 | final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FloatLabel, defStyle, 0); 507 | 508 | // Main attributes 509 | layout = a.getResourceId(R.styleable.FloatLabel_android_layout, R.layout.float_label); 510 | editTextId = a.getResourceId(R.styleable.FloatLabel_editTextId, R.id.edit_text); 511 | floatLabelId = a.getResourceId(R.styleable.FloatLabel_labelId, R.id.float_label); 512 | text = a.getText(R.styleable.FloatLabel_android_text); 513 | hint = a.getText(R.styleable.FloatLabel_android_hint); 514 | hintColor = a.getColorStateList(R.styleable.FloatLabel_android_textColorHint); 515 | floatLabelColor = a.getColor(R.styleable.FloatLabel_floatLabelColor, 0); 516 | imeOptions = a.getInt(R.styleable.FloatLabel_android_imeOptions, 0); 517 | inputType = a.getInt(R.styleable.FloatLabel_android_inputType, InputType.TYPE_CLASS_TEXT); 518 | 519 | // Next focus views 520 | nextFocusDownId = a.getResourceId(R.styleable.FloatLabel_android_nextFocusDown, NO_ID); 521 | nextFocusForwardId = a.getResourceId(R.styleable.FloatLabel_android_nextFocusForward, NO_ID); 522 | nextFocusLeftId = a.getResourceId(R.styleable.FloatLabel_android_nextFocusLeft, NO_ID); 523 | nextFocusRightId = a.getResourceId(R.styleable.FloatLabel_android_nextFocusRight, NO_ID); 524 | nextFocusUpId = a.getResourceId(R.styleable.FloatLabel_android_nextFocusUp, NO_ID); 525 | 526 | // Done with TypedArray 527 | a.recycle(); 528 | } 529 | 530 | inflate(context, layout, this); 531 | mEditText = (EditText) findViewById(editTextId); 532 | if (mEditText == null) { 533 | // fallback to default value 534 | mEditText = (EditText) findViewById(R.id.edit_text); 535 | } 536 | if (mEditText == null) { 537 | throw new RuntimeException( 538 | "Your layout must have an EditText whose ID is @id/edit_text"); 539 | } 540 | if (editTextId != R.id.edit_text) { 541 | mEditText.setId(editTextId); 542 | } 543 | mEditText.setHint(hint); 544 | mEditText.setText(text); 545 | if (hintColor != null) { 546 | mEditText.setHintTextColor(hintColor); 547 | } 548 | if (imeOptions != 0) { 549 | mEditText.setImeOptions(imeOptions); 550 | } 551 | if (inputType != 0) { 552 | mEditText.setInputType(inputType); 553 | } 554 | // Set all next focus views 555 | mEditText.setNextFocusDownId(nextFocusDownId); 556 | mEditText.setNextFocusForwardId(nextFocusForwardId); 557 | mEditText.setNextFocusLeftId(nextFocusLeftId); 558 | mEditText.setNextFocusRightId(nextFocusRightId); 559 | mEditText.setNextFocusUpId(nextFocusUpId); 560 | 561 | // Set up the label view 562 | mLabel = (TextView) findViewById(floatLabelId); 563 | if (mLabel == null) { 564 | // fallback to default value 565 | mLabel = (TextView) findViewById(R.id.float_label); 566 | } 567 | if (mLabel == null) { 568 | throw new RuntimeException( 569 | "Your layout must have a TextView whose ID is @id/float_label"); 570 | } 571 | if (floatLabelId != R.id.float_label) { 572 | mLabel.setId(floatLabelId); 573 | } 574 | mLabel.setText(mEditText.getHint()); 575 | if (floatLabelColor != 0) 576 | mLabel.setTextColor(floatLabelColor); 577 | 578 | // Listen to EditText to know when it is empty or nonempty 579 | mEditText.addTextChangedListener(new EditTextWatcher()); 580 | 581 | // Check current state of EditText 582 | if (mEditText.getText().length() == 0) { 583 | mLabel.setAlpha(0); 584 | mLabelShowing = false; 585 | } else { 586 | mLabel.setVisibility(View.VISIBLE); 587 | mLabelShowing = true; 588 | } 589 | 590 | // Mark init as complete to prevent accidentally breaking the view by 591 | // adding children 592 | mInitComplete = true; 593 | } 594 | 595 | /** 596 | * LabelAnimator that uses the traditional float label Y shift and fade. 597 | * 598 | * @author Ian G. Clifton 599 | */ 600 | private static class DefaultLabelAnimator implements LabelAnimator { 601 | 602 | @Override 603 | public void onDisplayLabel(View label) { 604 | final float offset = label.getHeight() / 2; 605 | final float currentY = label.getY(); 606 | if (currentY != offset) { 607 | label.setY(offset); 608 | } 609 | label.animate().alpha(1).y(0); 610 | } 611 | 612 | @Override 613 | public void onHideLabel(View label) { 614 | final float offset = label.getHeight() / 2; 615 | final float currentY = label.getY(); 616 | if (currentY != 0) { 617 | label.setY(0); 618 | } 619 | label.animate().alpha(0).y(offset); 620 | } 621 | } 622 | /** 623 | * TextWatcher that notifies FloatLabel when the EditText changes between 624 | * having text and not having text or vice versa. 625 | * 626 | * @author Ian G. Clifton 627 | */ 628 | private class EditTextWatcher implements TextWatcher { 629 | @Override 630 | public void afterTextChanged(Editable s) { 631 | if (mSkipAnimation) { 632 | mSkipAnimation = false; 633 | if (s.length() == 0) { 634 | // TextView label should be gone 635 | if (mLabelShowing) { 636 | mLabel.setAlpha(0); 637 | mLabelShowing = false; 638 | } 639 | } else if (!mLabelShowing) { 640 | // TextView label should be visible 641 | mLabel.setAlpha(1); 642 | mLabel.setY(0); 643 | mLabelShowing = true; 644 | } 645 | return; 646 | } 647 | if (s.length() == 0) { 648 | // Text is empty; TextView label should be invisible 649 | if (mLabelShowing) { 650 | mLabelAnimator.onHideLabel(mLabel); 651 | mLabelShowing = false; 652 | } 653 | } else if (!mLabelShowing) { 654 | // Text is nonempty; TextView label should be visible 655 | mLabelShowing = true; 656 | mLabelAnimator.onDisplayLabel(mLabel); 657 | } 658 | } 659 | 660 | @Override 661 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { 662 | // Ignored 663 | } 664 | 665 | @Override 666 | public void onTextChanged(CharSequence s, int start, int before, int count) { 667 | // Ignored 668 | } 669 | } 670 | } 671 | -------------------------------------------------------------------------------- /FloatLabelExample/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 3 | org.eclipse.jdt.core.compiler.compliance=1.6 4 | org.eclipse.jdt.core.compiler.source=1.6 5 | -------------------------------------------------------------------------------- /FloatLabelExample/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 16 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 29 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /FloatLabelExample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | dependencies { 4 | compile 'com.android.support:support-v4:21.0.3' 5 | // Use the below dependency if you will have the library locally available 6 | compile project(':FloatLabel') 7 | // Comment out the above dependency and use the one below for the AAR in Maven Central 8 | // compile 'com.iangclifton.android:floatlabel:1.0.4' 9 | } 10 | 11 | android { 12 | compileSdkVersion 21 13 | buildToolsVersion "19.1.0" 14 | 15 | sourceSets { 16 | main { 17 | manifest.srcFile 'AndroidManifest.xml' 18 | java.srcDirs = ['src'] 19 | resources.srcDirs = ['src'] 20 | aidl.srcDirs = ['src'] 21 | renderscript.srcDirs = ['src'] 22 | res.srcDirs = ['res'] 23 | assets.srcDirs = ['assets'] 24 | } 25 | 26 | // Move the tests to tests/java, tests/res, etc... 27 | instrumentTest.setRoot('tests') 28 | 29 | // Move the build types to build-types/ 30 | // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ... 31 | // This moves them out of them default location under src//... which would 32 | // conflict with src/ being used by the main source set. 33 | // Adding new build types or product flavors should be accompanied 34 | // by a similar customization. 35 | debug.setRoot('build-types/debug') 36 | release.setRoot('build-types/release') 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /FloatLabelExample/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IanGClifton/AndroidFloatLabel/b0a39c26f010f17d5f3648331e9784a41e025c0d/FloatLabelExample/ic_launcher-web.png -------------------------------------------------------------------------------- /FloatLabelExample/libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IanGClifton/AndroidFloatLabel/b0a39c26f010f17d5f3648331e9784a41e025c0d/FloatLabelExample/libs/android-support-v4.jar -------------------------------------------------------------------------------- /FloatLabelExample/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /FloatLabelExample/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-19 15 | android.library.reference.1=../FloatLabel 16 | -------------------------------------------------------------------------------- /FloatLabelExample/res/drawable-hdpi/custom_hint_color.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /FloatLabelExample/res/drawable-hdpi/ic_action_github.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IanGClifton/AndroidFloatLabel/b0a39c26f010f17d5f3648331e9784a41e025c0d/FloatLabelExample/res/drawable-hdpi/ic_action_github.png -------------------------------------------------------------------------------- /FloatLabelExample/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IanGClifton/AndroidFloatLabel/b0a39c26f010f17d5f3648331e9784a41e025c0d/FloatLabelExample/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /FloatLabelExample/res/drawable-mdpi/ic_action_github.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IanGClifton/AndroidFloatLabel/b0a39c26f010f17d5f3648331e9784a41e025c0d/FloatLabelExample/res/drawable-mdpi/ic_action_github.png -------------------------------------------------------------------------------- /FloatLabelExample/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IanGClifton/AndroidFloatLabel/b0a39c26f010f17d5f3648331e9784a41e025c0d/FloatLabelExample/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /FloatLabelExample/res/drawable-xhdpi/ic_action_github.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IanGClifton/AndroidFloatLabel/b0a39c26f010f17d5f3648331e9784a41e025c0d/FloatLabelExample/res/drawable-xhdpi/ic_action_github.png -------------------------------------------------------------------------------- /FloatLabelExample/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IanGClifton/AndroidFloatLabel/b0a39c26f010f17d5f3648331e9784a41e025c0d/FloatLabelExample/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /FloatLabelExample/res/drawable-xxhdpi/ic_action_github.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IanGClifton/AndroidFloatLabel/b0a39c26f010f17d5f3648331e9784a41e025c0d/FloatLabelExample/res/drawable-xxhdpi/ic_action_github.png -------------------------------------------------------------------------------- /FloatLabelExample/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IanGClifton/AndroidFloatLabel/b0a39c26f010f17d5f3648331e9784a41e025c0d/FloatLabelExample/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /FloatLabelExample/res/layout/activity_about.xml: -------------------------------------------------------------------------------- 1 | 10 | 11 | 18 | 19 | 27 | 28 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /FloatLabelExample/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 16 | 17 | 23 | 24 | 29 | 30 | 36 | 37 | 43 | 44 | 51 | 52 | 58 | 59 | 66 | 67 | 73 | 74 | 81 | 82 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /FloatLabelExample/res/layout/custom_float_label.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 12 | 13 | 18 | 19 | -------------------------------------------------------------------------------- /FloatLabelExample/res/menu/about.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /FloatLabelExample/res/menu/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /FloatLabelExample/res/values-sw600dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /FloatLabelExample/res/values-sw720dp-land/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 128dp 8 | 9 | 10 | -------------------------------------------------------------------------------- /FloatLabelExample/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /FloatLabelExample/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FF0000 4 | -------------------------------------------------------------------------------- /FloatLabelExample/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16dp 5 | 16dp 6 | 8dp 7 | 16dp 8 | 9 | 10 | -------------------------------------------------------------------------------- /FloatLabelExample/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Float Label Example 5 | Toggle Theme 6 | Example Label 7 | Prefilled 8 | Custom Layout 9 | Custom Hint Color 10 | Default Settings 11 | Custom Animations 12 | Custom FloatLabel Color 13 | Input type Password 14 | 15 | About Float Label 16 | This application demonstrates the Android Float Label library by Ian G. Clifton. Complete source code is available on GitHub and the SDK is also in Maven Central for easy use. 17 | GitHub 18 | About 19 | For some bizarre reason, you do not have a browser on your device. What is wrong with you? 20 | 21 | 22 | -------------------------------------------------------------------------------- /FloatLabelExample/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | -------------------------------------------------------------------------------- /FloatLabelExample/src/com/iangclifton/android/floatlabelexample/AboutActivity.java: -------------------------------------------------------------------------------- 1 | package com.iangclifton.android.floatlabelexample; 2 | 3 | import android.app.Activity; 4 | import android.content.ActivityNotFoundException; 5 | import android.content.Intent; 6 | import android.net.Uri; 7 | import android.os.Bundle; 8 | import android.view.Menu; 9 | import android.view.MenuItem; 10 | import android.widget.Toast; 11 | 12 | /** 13 | * Simple Activity that displays info about the app and has an ActionBar button for GitHub. 14 | * 15 | * @author Ian G. Clifton 16 | */ 17 | public class AboutActivity extends Activity { 18 | 19 | private static final String GITHUB_URL = "https://github.com/IanGClifton/AndroidFloatLabel"; 20 | 21 | @Override 22 | protected void onCreate(Bundle savedInstanceState) { 23 | super.onCreate(savedInstanceState); 24 | setContentView(R.layout.activity_about); 25 | } 26 | 27 | 28 | @Override 29 | public boolean onCreateOptionsMenu(Menu menu) { 30 | // Inflate the menu; this adds items to the action bar if it is present. 31 | getMenuInflater().inflate(R.menu.about, menu); 32 | return true; 33 | } 34 | 35 | @Override 36 | public boolean onOptionsItemSelected(MenuItem item) { 37 | final int id = item.getItemId(); 38 | switch (id) { 39 | case R.id.action_github: 40 | Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(GITHUB_URL)); 41 | try { 42 | startActivity(browserIntent); 43 | } catch (ActivityNotFoundException e) { 44 | Toast.makeText(this, R.string.no_browser, Toast.LENGTH_SHORT).show(); 45 | } 46 | return true; 47 | } 48 | return super.onOptionsItemSelected(item); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /FloatLabelExample/src/com/iangclifton/android/floatlabelexample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.iangclifton.android.floatlabelexample; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.view.Menu; 7 | import android.view.MenuItem; 8 | import android.view.View; 9 | 10 | import com.iangclifton.android.floatlabel.FloatLabel; 11 | 12 | public class MainActivity extends Activity { 13 | 14 | private int mTheme = android.R.style.Theme_Holo_Light_DarkActionBar; 15 | private static final String BUNDLE_KEY_THEME = MainActivity.class.getPackage() + ".theme"; 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | if (savedInstanceState != null) { 21 | mTheme = savedInstanceState.getInt(BUNDLE_KEY_THEME, mTheme); 22 | } 23 | setTheme(mTheme); 24 | setContentView(R.layout.activity_main); 25 | 26 | // This is how you add a custom animator 27 | final FloatLabel floatLabel = (FloatLabel) findViewById(R.id.float_label_custom_animation_1); 28 | floatLabel.setLabelAnimator(new CustomLabelAnimator()); 29 | } 30 | 31 | 32 | @Override 33 | public boolean onCreateOptionsMenu(Menu menu) { 34 | // Inflate the menu; this adds items to the action bar if it is present. 35 | getMenuInflater().inflate(R.menu.main, menu); 36 | return true; 37 | } 38 | 39 | @Override 40 | public boolean onOptionsItemSelected(MenuItem item) { 41 | final int id = item.getItemId(); 42 | switch (id) { 43 | case R.id.action_toggle_theme: 44 | if (mTheme == android.R.style.Theme_Holo_Light_DarkActionBar) { 45 | mTheme = android.R.style.Theme_Holo; 46 | } else { 47 | mTheme = android.R.style.Theme_Holo_Light_DarkActionBar; 48 | } 49 | recreate(); 50 | return true; 51 | case R.id.action_about: 52 | startActivity(new Intent(this, AboutActivity.class)); 53 | return true; 54 | } 55 | return super.onOptionsItemSelected(item); 56 | } 57 | 58 | @Override 59 | protected void onSaveInstanceState(Bundle outState) { 60 | super.onSaveInstanceState(outState); 61 | outState.putInt(BUNDLE_KEY_THEME, mTheme); 62 | } 63 | 64 | /** 65 | * LabelAnimator that uses a custom X shift and fade. 66 | * 67 | * @author Ian G. Clifton 68 | */ 69 | private static class CustomLabelAnimator implements FloatLabel.LabelAnimator { 70 | /*package*/ static final float SCALE_X_SHOWN = 1f; 71 | /*package*/ static final float SCALE_X_HIDDEN = 2f; 72 | /*package*/ static final float SCALE_Y_SHOWN = 1f; 73 | /*package*/ static final float SCALE_Y_HIDDEN = 0f; 74 | 75 | @Override 76 | public void onDisplayLabel(View label) { 77 | final float shift = label.getWidth() / 2; 78 | label.setScaleX(SCALE_X_HIDDEN); 79 | label.setScaleY(SCALE_Y_HIDDEN); 80 | label.setX(shift); 81 | label.animate().alpha(1).scaleX(SCALE_X_SHOWN).scaleY(SCALE_Y_SHOWN).x(0f); 82 | } 83 | 84 | @Override 85 | public void onHideLabel(View label) { 86 | final float shift = label.getWidth() / 2; 87 | label.setScaleX(SCALE_X_SHOWN); 88 | label.setScaleY(SCALE_Y_SHOWN); 89 | label.setX(0f); 90 | label.animate().alpha(0).scaleX(SCALE_X_HIDDEN).scaleY(SCALE_Y_HIDDEN).x(shift); 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | AndroidFloatLabel 2 | ================= 3 | 4 | This repository contains an Android library project for Android 4.0+ with a custom view that implements the Float Label pattern (http://dribbble.com/shots/1254439--GIF-Float-Label-Form-Interaction) and an example project using the Float Label library. The custom View, FloatLabel, basically consists of two pieces: the EditText and the label (a TextView). 5 | 6 | Quick Overview 7 | -------------- 8 | 9 | - [YouTube demo](http://www.youtube.com/watch?v=9VoVxw8aAx0) 10 | - [Google Play example app](https://play.google.com/store/apps/details?id=com.iangclifton.android.floatlabelexample) 11 | 12 | Getting Started 13 | --------------- 14 | 15 | Download the source to use it as a library project or use it directly from Maven Central in your dependencies. For example: 16 | 17 | dependencies { 18 | compile 'com.iangclifton.android:floatlabel:1.0.4' 19 | } 20 | 21 | For most use, you can simply use the custom view in your XML layout, specifying a label to use as both the EditText hint and the label TextView with the android:hint property. Example: 22 | 23 | 28 | 29 | You can also dynamically set the label with floatLabel.setLabel("Custom Label") or floatLabel.setLabel(R.string.custom_label). You can dynamically set the text of the EditText with floatLabel.setText(). All the typical setText variations are supported. If you want to set the text without an animation (such as if you're programmatically preparing views in onCreate), use floatLabel.setTextWithoutAnimation() (again, all the usual variations are supported). 30 | 31 | If you need a reference to the EditText, you can call floatLabel.getEditText(). 32 | 33 | Custom Layout 34 | ------------- 35 | 36 | If you want to specify a custom layout to use, you can do something like this: 37 | 38 | 44 | 45 | Your custom layout should include a label TextView (id/float_label) and an EditText (id/edit_text). The custom layouts are extremely limited because the FloatLabel simply lays out the label and the EditText and ignores all other views. This is very efficient but also prevents you from creating a much more complex layout. Here's an example: 46 | 47 | 48 | 49 | 56 | 61 | 62 | 63 | Custom Animation 64 | ---------------- 65 | 66 | You can override the animations used to show and hide the label by implementing a FloatLabel.LabelAnimator and calling floatLabel.setLabelAnimator(new MyLabelAnimator());. Note that you should use the alpha property of the label to show and hide it rather than the View.setVisibility(int) method. Example: 67 | 68 | private static class CustomLabelAnimator implements FloatLabel.LabelAnimator { 69 | /*package*/ static final float SCALE_X_SHOWN = 1f; 70 | /*package*/ static final float SCALE_X_HIDDEN = 2f; 71 | /*package*/ static final float SCALE_Y_SHOWN = 1f; 72 | /*package*/ static final float SCALE_Y_HIDDEN = 0f; 73 | 74 | @Override 75 | public void onDisplayLabel(View label) { 76 | final float shift = label.getWidth() / 2; 77 | label.setScaleX(SCALE_X_HIDDEN); 78 | label.setScaleY(SCALE_Y_HIDDEN); 79 | label.setX(shift); 80 | label.animate().alpha(1).scaleX(SCALE_X_SHOWN).scaleY(SCALE_Y_SHOWN).x(0f); 81 | } 82 | 83 | @Override 84 | public void onHideLabel(View label) { 85 | final float shift = label.getWidth() / 2; 86 | label.setScaleX(SCALE_X_SHOWN); 87 | label.setScaleY(SCALE_Y_SHOWN); 88 | label.setX(0f); 89 | label.animate().alpha(0).scaleX(SCALE_X_HIDDEN).scaleY(SCALE_Y_HIDDEN).x(shift); 90 | } 91 | } 92 | 93 | 94 | Related Projects 95 | ---------------- 96 | 97 | * [Fork of Float Label for Android 2.3+](https://github.com/edouardouvrard/AndroidFloatLabel-API9) 98 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | buildscript { 3 | repositories { 4 | mavenCentral() 5 | } 6 | dependencies { 7 | classpath 'com.android.tools.build:gradle:1.1.0' 8 | } 9 | } 10 | 11 | def isReleaseBuild() { 12 | return version.contains("SNAPSHOT") == false 13 | } 14 | 15 | allprojects { 16 | version = VERSION_NAME 17 | group = GROUP 18 | 19 | repositories { 20 | mavenCentral() 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /changelog.md: -------------------------------------------------------------------------------- 1 | v1.0.4 2 | ====== 3 | 4 | - Added setText methods to quickly set the EditText text 5 | - Added setTextWithoutAnimation methods to set the EditText without triggering the label animation 6 | 7 | v1.0.3 8 | ====== 9 | 10 | - Removed app icon that was conflicting with some apps 11 | - Removed allowBackup tag 12 | - Added support for imeOptions attributes 13 | - Added support for custom IDs 14 | 15 | 16 | v1.0.2 17 | ====== 18 | 19 | - Fixed focus retention on configuration change 20 | - Better RTL support 21 | - Removed theme from manifest 22 | - Added AboutActivity to sample project 23 | - Partial support for nextFocus* attributes 24 | 25 | 26 | v1.0.1 27 | ====== 28 | 29 | - Support for additional attributes (floatLabelColor, inputType) 30 | 31 | 32 | v1.0.0 33 | ====== 34 | 35 | Initial release 36 | 37 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | VERSION_NAME=1.0.4 2 | VERSION_CODE=5 3 | GROUP=com.iangclifton.android 4 | 5 | POM_DESCRIPTION=Android library for float label custom view 6 | POM_URL=https://github.com/IanGClifton/AndroidFloatLabel 7 | POM_SCM_URL=https://github.com/IanGClifton/AndroidFloatLabel 8 | POM_SCM_CONNECTION=scm:git@github.com:IanGClifton/AndroidFloatLabel.git 9 | POM_SCM_DEV_CONNECTION=scm:git@github.com:IanGClifton/AndroidFloatLabel.git 10 | POM_LICENCE_NAME=The Apache Software License, Version 2.0 11 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt 12 | POM_LICENCE_DIST=repo 13 | POM_DEVELOPER_ID=iangclifton 14 | POM_DEVELOPER_NAME=Ian G. Clifton 15 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IanGClifton/AndroidFloatLabel/b0a39c26f010f17d5f3648331e9784a41e025c0d/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Mar 08 20:13:57 PDT 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties~: -------------------------------------------------------------------------------- 1 | #Wed Apr 10 15:27:10 PDT 2013 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=http\://services.gradle.org/distributions/gradle-1.6-bin.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':FloatLabelExample' 2 | include ':FloatLabel' 3 | --------------------------------------------------------------------------------