diff --git a/app/build.gradle b/app/build.gradle index 7a76ce0..dc2d10f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,26 +1,24 @@ -apply plugin: 'android' +apply plugin: 'com.android.application' android { - compileSdkVersion 19 - buildToolsVersion "19.0.3" + compileSdkVersion parent.ext.compileSdkVersion + buildToolsVersion parent.ext.buildToolsVersion defaultConfig { - minSdkVersion 11 - targetSdkVersion 19 - versionCode 1 - versionName "1.0" + minSdkVersion parent.ext.minSdkVersion + targetSdkVersion parent.ext.targetSdkVersion + versionName parent.ext.versionName + versionCode parent.ext.versionCode } buildTypes { release { - runProguard false + minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' } } } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:appcompat-v7:19.1.0' - compile 'com.android.support:support-v4:19.1.0' - compile 'com.nineoldandroids:library:2.4.0' + compile 'com.android.support:appcompat-v7:22.+' + compile project(':lib') } diff --git a/app/src/main/res/layout/fragment_main.xml b/app/src/main/res/layout/fragment_main.xml index f501774..77c8617 100644 --- a/app/src/main/res/layout/fragment_main.xml +++ b/app/src/main/res/layout/fragment_main.xml @@ -4,13 +4,13 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical" android:layout_width="match_parent" - android:layout_height="match_parent"> + android:layout_height="match_parent" + android:paddingLeft="@dimen/activity_horizontal_margin" + android:paddingRight="@dimen/activity_horizontal_margin"> - + android:layout_height="wrap_content"> - + - @@ -39,12 +38,11 @@ android:singleLine="true" android:imeOptions="actionDone" /> - + - @@ -56,6 +54,6 @@ android:singleLine="true" android:imeOptions="actionDone" /> - + \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 4fb091e..766ab99 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -5,11 +5,4 @@ - - - diff --git a/build.gradle b/build.gradle index 80eec1a..e700def 100644 --- a/build.gradle +++ b/build.gradle @@ -5,10 +5,26 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:0.9.+' + classpath 'com.android.tools.build:gradle:1.1.0' } } + +ext { + versionMajor = 1 + versionMinor = 1 + versionPatch = 0 + + versionCode = versionMajor * 1000 + versionMinor * 100 + versionPatch + versionName = versionMajor + "." + versionMinor + "." + versionPatch + + minSdkVersion = 14 + targetSdkVersion = 22 + compileSdkVersion = 22 + buildToolsVersion = '22.0.0' + +} + allprojects { repositories { mavenCentral() diff --git a/lib/.gitignore b/lib/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/lib/.gitignore @@ -0,0 +1 @@ +/build diff --git a/lib/build.gradle b/lib/build.gradle new file mode 100644 index 0000000..c01cbed --- /dev/null +++ b/lib/build.gradle @@ -0,0 +1,23 @@ +apply plugin: 'com.android.library' + +android { + compileSdkVersion parent.ext.compileSdkVersion + buildToolsVersion parent.ext.buildToolsVersion + + defaultConfig { + minSdkVersion parent.ext.minSdkVersion + targetSdkVersion parent.ext.targetSdkVersion + versionName parent.ext.versionName + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile 'com.android.support:support-v4:22.+' + compile 'com.nineoldandroids:library:2.4.0' +} diff --git a/lib/proguard-rules.pro b/lib/proguard-rules.pro new file mode 100644 index 0000000..28df15b --- /dev/null +++ b/lib/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /Users/jesus/Library/Android/sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/lib/src/androidTest/java/com/example/jesus/lib/ApplicationTest.java b/lib/src/androidTest/java/com/example/jesus/lib/ApplicationTest.java new file mode 100644 index 0000000..9147369 --- /dev/null +++ b/lib/src/androidTest/java/com/example/jesus/lib/ApplicationTest.java @@ -0,0 +1,13 @@ +package com.example.jesus.lib; + +import android.app.Application; +import android.test.ApplicationTestCase; + +/** + * Testing Fundamentals + */ +public class ApplicationTest extends ApplicationTestCase { + public ApplicationTest() { + super(Application.class); + } +} \ No newline at end of file diff --git a/lib/src/main/AndroidManifest.xml b/lib/src/main/AndroidManifest.xml new file mode 100644 index 0000000..1d3b137 --- /dev/null +++ b/lib/src/main/AndroidManifest.xml @@ -0,0 +1,8 @@ + + + + + + + diff --git a/app/src/main/java/com/jesusm/floatinglabelpass/app/ui/activities/customviews/CheckStrenghtLabelLayout.java b/lib/src/main/java/com/example/jesus/lib/CheckStrenghtLabelLayout.java similarity index 93% rename from app/src/main/java/com/jesusm/floatinglabelpass/app/ui/activities/customviews/CheckStrenghtLabelLayout.java rename to lib/src/main/java/com/example/jesus/lib/CheckStrenghtLabelLayout.java index cb01466..8e50149 100644 --- a/app/src/main/java/com/jesusm/floatinglabelpass/app/ui/activities/customviews/CheckStrenghtLabelLayout.java +++ b/lib/src/main/java/com/example/jesus/lib/CheckStrenghtLabelLayout.java @@ -1,20 +1,17 @@ -package com.jesusm.floatinglabelpass.app.ui.activities.customviews; +package com.example.jesus.lib; import android.content.Context; import android.graphics.Bitmap; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; +import android.support.v4.content.res.ResourcesCompat; import android.text.InputType; import android.util.AttributeSet; import android.widget.EditText; -import com.jesusm.floatinglabelpass.app.R; import com.nineoldandroids.animation.ArgbEvaluator; import com.nineoldandroids.animation.ValueAnimator; -/** - * Created by Jesus on 05/05/14. - */ public abstract class CheckStrenghtLabelLayout extends FloatLabelLayout { private static final long LABEL_COLOR_CHANGE_ANIMATION_TIME = 333L; @@ -67,7 +64,7 @@ private void checkDrawAcceptIcon() { private void initAcceptDrawableCompound() { // Read your drawable from somewhere - Drawable dr = getResources().getDrawable(R.drawable.ic_action_navigation_accept); + Drawable dr = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_action_navigation_accept, null); Bitmap bitmap = ((BitmapDrawable) dr).getBitmap(); // Scale it to the label size int acceptDrawableSize = (int) getLabel().getTextSize(); diff --git a/app/src/main/java/com/jesusm/floatinglabelpass/app/ui/activities/customviews/FloatLabelLayout.java b/lib/src/main/java/com/example/jesus/lib/FloatLabelLayout.java similarity index 85% rename from app/src/main/java/com/jesusm/floatinglabelpass/app/ui/activities/customviews/FloatLabelLayout.java rename to lib/src/main/java/com/example/jesus/lib/FloatLabelLayout.java index 2aa7fbd..9c566e1 100644 --- a/app/src/main/java/com/jesusm/floatinglabelpass/app/ui/activities/customviews/FloatLabelLayout.java +++ b/lib/src/main/java/com/example/jesus/lib/FloatLabelLayout.java @@ -1,4 +1,4 @@ -package com.jesusm.floatinglabelpass.app.ui.activities.customviews;/* +package com.example.jesus.lib;/* * Copyright (C) 2014 Chris Banes * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,19 +17,18 @@ import android.content.Context; import android.content.res.TypedArray; import android.graphics.Color; +import android.support.annotation.NonNull; import android.text.Editable; import android.text.TextUtils; import android.text.TextWatcher; import android.util.AttributeSet; import android.util.TypedValue; -import android.view.Gravity; import android.view.View; import android.view.ViewGroup; import android.widget.EditText; -import android.widget.FrameLayout; +import android.widget.LinearLayout; import android.widget.TextView; -import com.jesusm.floatinglabelpass.app.R; import com.nineoldandroids.animation.Animator; import com.nineoldandroids.animation.AnimatorSet; import com.nineoldandroids.animation.ObjectAnimator; @@ -42,17 +41,15 @@ * @see Matt D. Smith on Dribble * @see Brad Frost's blog post */ -public class FloatLabelLayout extends FrameLayout { +public class FloatLabelLayout extends LinearLayout { - - private static final float DEFAULT_PADDING_LEFT_RIGHT_DP = 12f; - private static final long ANIMATION_DURATION = 150; + private static final int DEFAULT_PADDING_TOP_BOTTOM_DP = 8; + private static final long ANIMATION_DURATION = 100; private int mLabelColor = Color.GRAY; private EditText mEditText; private TextView mLabel; - public FloatLabelLayout(Context context) { this(context, null); } @@ -63,46 +60,42 @@ public FloatLabelLayout(Context context, AttributeSet attrs) { public FloatLabelLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); + setOrientation(VERTICAL); final TypedArray a = context .obtainStyledAttributes(attrs, R.styleable.FloatLabelLayout); - final int sidePadding = a.getDimensionPixelSize( - R.styleable.FloatLabelLayout_floatLabelSidePadding, - dipsToPix(DEFAULT_PADDING_LEFT_RIGHT_DP)); mLabel = new TextView(context); - mLabel.setPadding(sidePadding, 0, sidePadding, 0); - mLabel.setVisibility(INVISIBLE); + initLabelAppearance(context, a); + mLabelColor = mLabel.getCurrentTextColor(); + addView(mLabel, 0, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); + + a.recycle(); + } + private void initLabelAppearance(Context context, TypedArray a) { + mLabel.setVisibility(INVISIBLE); + mLabel.setPadding(0, dipsToPix(DEFAULT_PADDING_TOP_BOTTOM_DP), 0, 0); mLabel.setTextAppearance(context, a.getResourceId(R.styleable.FloatLabelLayout_floatLabelTextAppearance, - android.R.style.TextAppearance_Small) + R.style.PasswordFloatingLabelLayout_DefaultStyle) ); - mLabelColor = mLabel.getCurrentTextColor(); - - - addView(mLabel, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); - - - a.recycle(); } @Override - public final void addView(View child, int index, ViewGroup.LayoutParams params) { + public final void addView(@NonNull View child, int index, ViewGroup.LayoutParams params) { if (child instanceof EditText) { // If we already have an EditText, throw an exception if (mEditText != null) { throw new IllegalArgumentException("We already have an EditText, can only have one"); } - - // Update the layout params so that the EditText is at the bottom, with enough top - // margin to show the label - final LayoutParams lp = new LayoutParams(params); - lp.gravity = Gravity.BOTTOM; - lp.topMargin = (int) mLabel.getTextSize(); - params = lp; - + child.setPadding(child.getPaddingLeft(), dipsToPix(DEFAULT_PADDING_TOP_BOTTOM_DP), + child.getPaddingRight(), dipsToPix(DEFAULT_PADDING_TOP_BOTTOM_DP)); + if (mLabel != null) { + mLabel.setPadding(child.getPaddingLeft(), mLabel.getPaddingTop(), + child.getPaddingRight(), mLabel.getPaddingBottom()); + } setEditText((EditText) child); } @@ -199,7 +192,7 @@ public TextView getLabel() { */ private void showLabel() { ObjectAnimator alpha = ObjectAnimator.ofFloat(mLabel, "alpha", 0f, 1f); - ObjectAnimator translationY = ObjectAnimator.ofFloat(mLabel, "translationY", mLabel.getHeight(), 0f); + ObjectAnimator translationY = ObjectAnimator.ofFloat(mLabel, "translationY", mLabel.getHeight() / 2, 0f); AnimatorSet animatorSet = new AnimatorSet(); animatorSet.setDuration(ANIMATION_DURATION); animatorSet.playTogether(alpha, translationY); @@ -226,10 +219,8 @@ public void onAnimationRepeat(Animator animation) { }); animatorSet.start(); - } - /** * Hide the label using an animation */ @@ -237,7 +228,7 @@ private void hideLabel() { ViewHelper.setAlpha(mLabel, 1f); ViewHelper.setTranslationY(mLabel, 0f); ObjectAnimator alpha = ObjectAnimator.ofFloat(mLabel, "alpha", 0f); - ObjectAnimator translationY = ObjectAnimator.ofFloat(mLabel, "translationY", mLabel.getHeight()); + ObjectAnimator translationY = ObjectAnimator.ofFloat(mLabel, "translationY", mLabel.getHeight() / 2); AnimatorSet animatorSet = new AnimatorSet(); animatorSet.addListener(new com.nineoldandroids.animation.Animator.AnimatorListener() { @Override @@ -247,7 +238,7 @@ public void onAnimationStart(com.nineoldandroids.animation.Animator animation) { @Override public void onAnimationEnd(com.nineoldandroids.animation.Animator animation) { - mLabel.setVisibility(View.GONE); + mLabel.setVisibility(View.INVISIBLE); } @Override diff --git a/app/src/main/java/com/jesusm/floatinglabelpass/app/ui/activities/customviews/MailLabelLayoutCheck.java b/lib/src/main/java/com/example/jesus/lib/MailLabelLayoutCheck.java similarity index 88% rename from app/src/main/java/com/jesusm/floatinglabelpass/app/ui/activities/customviews/MailLabelLayoutCheck.java rename to lib/src/main/java/com/example/jesus/lib/MailLabelLayoutCheck.java index dc82114..a93d7e3 100644 --- a/app/src/main/java/com/jesusm/floatinglabelpass/app/ui/activities/customviews/MailLabelLayoutCheck.java +++ b/lib/src/main/java/com/example/jesus/lib/MailLabelLayoutCheck.java @@ -1,15 +1,10 @@ -package com.jesusm.floatinglabelpass.app.ui.activities.customviews; +package com.example.jesus.lib; import android.content.Context; import android.text.InputType; import android.text.TextUtils; import android.util.AttributeSet; -import com.jesusm.floatinglabelpass.app.R; - -/** - * Created by Jesus on 05/05/14. - */ public class MailLabelLayoutCheck extends CheckStrenghtLabelLayout { private boolean valid = false; @@ -30,7 +25,7 @@ public MailLabelLayoutCheck(Context context, AttributeSet attrs, int defStyle) { int getColorFromCriteria(String target) { valid = isValidEmail(target); return valid ? getResources().getColor(R.color.float_label_password_good) : - getResources().getColor(R.color.float_label_password_bad); + getResources().getColor(R.color.float_label_password_error); } @Override diff --git a/app/src/main/java/com/jesusm/floatinglabelpass/app/ui/activities/customviews/PasswordFloatLabelLayoutCheck.java b/lib/src/main/java/com/example/jesus/lib/PasswordFloatLabelLayoutCheck.java similarity index 82% rename from app/src/main/java/com/jesusm/floatinglabelpass/app/ui/activities/customviews/PasswordFloatLabelLayoutCheck.java rename to lib/src/main/java/com/example/jesus/lib/PasswordFloatLabelLayoutCheck.java index f610cc3..327817a 100644 --- a/app/src/main/java/com/jesusm/floatinglabelpass/app/ui/activities/customviews/PasswordFloatLabelLayoutCheck.java +++ b/lib/src/main/java/com/example/jesus/lib/PasswordFloatLabelLayoutCheck.java @@ -1,17 +1,11 @@ -package com.jesusm.floatinglabelpass.app.ui.activities.customviews; +package com.example.jesus.lib; import android.content.Context; import android.text.InputType; import android.util.AttributeSet; -import com.jesusm.floatinglabelpass.app.R; - -/** - * Created by Jesus on 03/05/14. - */ public class PasswordFloatLabelLayoutCheck extends CheckStrenghtLabelLayout { - private int passLength = 0; private boolean showLabelIcon = false; public PasswordFloatLabelLayoutCheck(Context context) { @@ -30,10 +24,10 @@ public PasswordFloatLabelLayoutCheck(Context context, AttributeSet attrs, int de @Override int getColorFromCriteria(String text) { - passLength = getEditText().getText().toString().length(); + int passLength = getEditText().getText().toString().length(); if (passLength < 3) { showLabelIcon = false; - return getResources().getColor(R.color.float_label_password_bad); + return getResources().getColor(R.color.float_label_password_error); } else if (passLength < 6) { showLabelIcon = false; return getResources().getColor(R.color.float_label_password_regular); diff --git a/app/src/main/java/com/jesusm/floatinglabelpass/app/ui/activities/customviews/SimpleLabelLayoutCheck.java b/lib/src/main/java/com/example/jesus/lib/SimpleLabelLayoutCheck.java similarity index 84% rename from app/src/main/java/com/jesusm/floatinglabelpass/app/ui/activities/customviews/SimpleLabelLayoutCheck.java rename to lib/src/main/java/com/example/jesus/lib/SimpleLabelLayoutCheck.java index 0bb3c13..60b40ee 100644 --- a/app/src/main/java/com/jesusm/floatinglabelpass/app/ui/activities/customviews/SimpleLabelLayoutCheck.java +++ b/lib/src/main/java/com/example/jesus/lib/SimpleLabelLayoutCheck.java @@ -1,14 +1,9 @@ -package com.jesusm.floatinglabelpass.app.ui.activities.customviews; +package com.example.jesus.lib; import android.content.Context; import android.text.InputType; import android.util.AttributeSet; -import com.jesusm.floatinglabelpass.app.R; - -/** - * Created by Jesus on 05/05/14. - */ public class SimpleLabelLayoutCheck extends CheckStrenghtLabelLayout { private int color = getResources().getColor(R.color.float_label); diff --git a/lib/src/main/res/drawable-hdpi/ic_action_navigation_accept.png b/lib/src/main/res/drawable-hdpi/ic_action_navigation_accept.png new file mode 100644 index 0000000..432e2a9 Binary files /dev/null and b/lib/src/main/res/drawable-hdpi/ic_action_navigation_accept.png differ diff --git a/lib/src/main/res/drawable-mdpi/ic_action_navigation_accept.png b/lib/src/main/res/drawable-mdpi/ic_action_navigation_accept.png new file mode 100755 index 0000000..fa97042 Binary files /dev/null and b/lib/src/main/res/drawable-mdpi/ic_action_navigation_accept.png differ diff --git a/lib/src/main/res/drawable-xhdpi/ic_action_navigation_accept.png b/lib/src/main/res/drawable-xhdpi/ic_action_navigation_accept.png new file mode 100644 index 0000000..8f4a592 Binary files /dev/null and b/lib/src/main/res/drawable-xhdpi/ic_action_navigation_accept.png differ diff --git a/lib/src/main/res/drawable-xxhdpi/ic_action_navigation_accept.png b/lib/src/main/res/drawable-xxhdpi/ic_action_navigation_accept.png new file mode 100644 index 0000000..3597c41 Binary files /dev/null and b/lib/src/main/res/drawable-xxhdpi/ic_action_navigation_accept.png differ diff --git a/app/src/main/res/values/attrs.xml b/lib/src/main/res/values/attrs.xml similarity index 99% rename from app/src/main/res/values/attrs.xml rename to lib/src/main/res/values/attrs.xml index 746319e..9825fa9 100644 --- a/app/src/main/res/values/attrs.xml +++ b/lib/src/main/res/values/attrs.xml @@ -9,4 +9,5 @@ + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/lib/src/main/res/values/colors.xml similarity index 65% rename from app/src/main/res/values/colors.xml rename to lib/src/main/res/values/colors.xml index f89b861..402c6eb 100644 --- a/app/src/main/res/values/colors.xml +++ b/lib/src/main/res/values/colors.xml @@ -1,7 +1,8 @@ #ff007ef0 - #ffac0005 + #ffac0005 #fff0b31a #ff1ca71c + #5d000000 \ No newline at end of file diff --git a/lib/src/main/res/values/strings.xml b/lib/src/main/res/values/strings.xml new file mode 100644 index 0000000..d8b1ac9 --- /dev/null +++ b/lib/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + lib + diff --git a/lib/src/main/res/values/styles.xml b/lib/src/main/res/values/styles.xml new file mode 100644 index 0000000..2cb078b --- /dev/null +++ b/lib/src/main/res/values/styles.xml @@ -0,0 +1,16 @@ + + + + + + + + diff --git a/settings.gradle b/settings.gradle index e7b4def..3cbe249 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':app' +include ':app', ':lib'