From e6ca80aae016346c35e451537c260363585c47fe Mon Sep 17 00:00:00 2001 From: William Mora Date: Sat, 1 Nov 2014 19:32:03 -0300 Subject: [PATCH 01/53] config update --- .gitignore | 1 + build.gradle | 2 +- lib/build.gradle | 16 ++++++---------- sample/build.gradle | 10 ++++------ 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index b596590..498e4b8 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ .DS_Store /build *.iml +.navigation diff --git a/build.gradle b/build.gradle index 2e3fc3e..b75798f 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:0.13.2' + classpath 'com.android.tools.build:gradle:0.14.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/lib/build.gradle b/lib/build.gradle index d89559c..1fa402e 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -1,29 +1,25 @@ apply plugin: 'com.android.library' android { - compileSdkVersion 20 - buildToolsVersion "20.0.0" + compileSdkVersion 21 + buildToolsVersion "21.1.0" defaultConfig { applicationId "com.williammora.snackbar" minSdkVersion 15 - targetSdkVersion 20 - versionCode 5 - versionName "1.4.0" + targetSdkVersion 21 + versionCode 6 + versionName "2.0.0-SNAPSHOT" testInstrumentationRunner "android.test.InstrumentationTestRunner" testHandleProfiling true testFunctionalTest true } buildTypes { release { - runProguard false + minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } -dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) -} - apply from: 'maven-push.gradle' \ No newline at end of file diff --git a/sample/build.gradle b/sample/build.gradle index 69801d7..d19b009 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -1,19 +1,19 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 20 - buildToolsVersion "20.0.0" + compileSdkVersion 21 + buildToolsVersion "21.1.0" defaultConfig { applicationId "com.williammora.snackbar" minSdkVersion 15 - targetSdkVersion 20 + targetSdkVersion 21 versionCode 1 versionName "1.0" } buildTypes { release { - runProguard false + minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } @@ -21,7 +21,5 @@ android { } dependencies { - - compile fileTree(dir: 'libs', include: ['*.jar']) compile project(':lib') } From 0b53d35580a713c3c9509cf4980738eff559b851 Mon Sep 17 00:00:00 2001 From: William Mora Date: Sat, 1 Nov 2014 19:37:55 -0300 Subject: [PATCH 02/53] demo refactor --- sample/build.gradle | 2 +- sample/src/main/AndroidManifest.xml | 2 +- .../sample/snackbar/SnackbarSampleActivity.java | 2 +- sample/src/main/res/layout/activity_sample.xml | 2 +- sample/src/main/res/menu/sample.xml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) rename sample/src/main/java/com/{williammora => nispok}/sample/snackbar/SnackbarSampleActivity.java (99%) diff --git a/sample/build.gradle b/sample/build.gradle index d19b009..f0a5ce7 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -5,7 +5,7 @@ android { buildToolsVersion "21.1.0" defaultConfig { - applicationId "com.williammora.snackbar" + applicationId "com.nispok.snackbar" minSdkVersion 15 targetSdkVersion 21 versionCode 1 diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index 2266ce0..4870198 100644 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -1,6 +1,6 @@ + package="com.nispok.sample.snackbar" > + tools:context="com.nispok.sample.snackbar.SnackbarSampleActivity"> + tools:context="com.nispok.sample.snackbar.SnackbarSampleActivity" > Date: Sat, 1 Nov 2014 19:42:33 -0300 Subject: [PATCH 03/53] lib refactor --- lib/build.gradle | 2 +- .../snackbar/SnackbarTests.java | 2 +- lib/src/main/AndroidManifest.xml | 2 +- .../snackbar/Snackbar.java | 21 ++++++++++--------- .../snackbar/SnackbarLayout.java | 2 +- .../listeners/SwipeDismissTouchListener.java | 2 +- .../snackbar/SnackbarSampleActivity.java | 2 +- 7 files changed, 17 insertions(+), 16 deletions(-) rename lib/src/androidTest/java/com/{williammora => nispok}/snackbar/SnackbarTests.java (99%) rename lib/src/main/java/com/{williammora => nispok}/snackbar/Snackbar.java (93%) rename lib/src/main/java/com/{williammora => nispok}/snackbar/SnackbarLayout.java (97%) rename lib/src/main/java/com/{williammora => nispok}/snackbar/listeners/SwipeDismissTouchListener.java (99%) diff --git a/lib/build.gradle b/lib/build.gradle index 1fa402e..3312f7e 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -5,7 +5,7 @@ android { buildToolsVersion "21.1.0" defaultConfig { - applicationId "com.williammora.snackbar" + applicationId "com.nispok.snackbar" minSdkVersion 15 targetSdkVersion 21 versionCode 6 diff --git a/lib/src/androidTest/java/com/williammora/snackbar/SnackbarTests.java b/lib/src/androidTest/java/com/nispok/snackbar/SnackbarTests.java similarity index 99% rename from lib/src/androidTest/java/com/williammora/snackbar/SnackbarTests.java rename to lib/src/androidTest/java/com/nispok/snackbar/SnackbarTests.java index 9fe31c0..6d2629d 100644 --- a/lib/src/androidTest/java/com/williammora/snackbar/SnackbarTests.java +++ b/lib/src/androidTest/java/com/nispok/snackbar/SnackbarTests.java @@ -1,4 +1,4 @@ -package com.williammora.snackbar; +package com.nispok.snackbar; import android.content.Context; import android.graphics.Color; diff --git a/lib/src/main/AndroidManifest.xml b/lib/src/main/AndroidManifest.xml index 84f922b..6a38b46 100644 --- a/lib/src/main/AndroidManifest.xml +++ b/lib/src/main/AndroidManifest.xml @@ -1,4 +1,4 @@ - + diff --git a/lib/src/main/java/com/williammora/snackbar/Snackbar.java b/lib/src/main/java/com/nispok/snackbar/Snackbar.java similarity index 93% rename from lib/src/main/java/com/williammora/snackbar/Snackbar.java rename to lib/src/main/java/com/nispok/snackbar/Snackbar.java index d2e6149..baeaf4b 100644 --- a/lib/src/main/java/com/williammora/snackbar/Snackbar.java +++ b/lib/src/main/java/com/nispok/snackbar/Snackbar.java @@ -1,4 +1,4 @@ -package com.williammora.snackbar; +package com.nispok.snackbar; import android.app.Activity; import android.content.Context; @@ -13,7 +13,8 @@ import android.view.animation.AnimationUtils; import android.widget.FrameLayout; import android.widget.TextView; -import com.williammora.snackbar.listeners.SwipeDismissTouchListener; + +import com.nispok.snackbar.listeners.SwipeDismissTouchListener; /** * View that provides quick feedback about an operation in a small popup at the base of the screen @@ -200,7 +201,7 @@ public Snackbar animation(boolean withAnimation) { } /** - * Determines whether this {@link com.williammora.snackbar.Snackbar} can be swiped off from the screen + * Determines whether this {@link Snackbar} can be swiped off from the screen * * @param canSwipeToDismiss * @return @@ -442,7 +443,7 @@ public boolean shouldDismissOnActionClicked() { } /** - * Returns whether this {@link com.williammora.snackbar.Snackbar} is currently showing + * Returns whether this {@link Snackbar} is currently showing * * @return */ @@ -451,7 +452,7 @@ public boolean isShowing() { } /** - * Returns whether this {@link com.williammora.snackbar.Snackbar} has been dismissed + * Returns whether this {@link Snackbar} has been dismissed * * @return */ @@ -464,21 +465,21 @@ public interface ActionClickListener { } /** - * Interface used to notify of all {@link com.williammora.snackbar.Snackbar} display events. Useful if you want + * Interface used to notify of all {@link Snackbar} display events. Useful if you want * to move other views while the Snackbar is on screen. */ public interface EventListener { /** - * Called when a {@link com.williammora.snackbar.Snackbar} is about to enter the screen + * Called when a {@link Snackbar} is about to enter the screen * - * @param height {@link com.williammora.snackbar.Snackbar} height, in DP + * @param height {@link Snackbar} height, in DP */ public void onShow(int height); /** - * Called when a {@link com.williammora.snackbar.Snackbar} had just been dismissed + * Called when a {@link Snackbar} had just been dismissed * - * @param height {@link com.williammora.snackbar.Snackbar} height, in DP + * @param height {@link Snackbar} height, in DP */ public void onDismiss(int height); } diff --git a/lib/src/main/java/com/williammora/snackbar/SnackbarLayout.java b/lib/src/main/java/com/nispok/snackbar/SnackbarLayout.java similarity index 97% rename from lib/src/main/java/com/williammora/snackbar/SnackbarLayout.java rename to lib/src/main/java/com/nispok/snackbar/SnackbarLayout.java index fdc89d5..7c50913 100644 --- a/lib/src/main/java/com/williammora/snackbar/SnackbarLayout.java +++ b/lib/src/main/java/com/nispok/snackbar/SnackbarLayout.java @@ -1,4 +1,4 @@ -package com.williammora.snackbar; +package com.nispok.snackbar; import android.content.Context; import android.util.AttributeSet; diff --git a/lib/src/main/java/com/williammora/snackbar/listeners/SwipeDismissTouchListener.java b/lib/src/main/java/com/nispok/snackbar/listeners/SwipeDismissTouchListener.java similarity index 99% rename from lib/src/main/java/com/williammora/snackbar/listeners/SwipeDismissTouchListener.java rename to lib/src/main/java/com/nispok/snackbar/listeners/SwipeDismissTouchListener.java index b2c8c09..1dc94f0 100644 --- a/lib/src/main/java/com/williammora/snackbar/listeners/SwipeDismissTouchListener.java +++ b/lib/src/main/java/com/nispok/snackbar/listeners/SwipeDismissTouchListener.java @@ -1,4 +1,4 @@ -package com.williammora.snackbar.listeners; +package com.nispok.snackbar.listeners; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; diff --git a/sample/src/main/java/com/nispok/sample/snackbar/SnackbarSampleActivity.java b/sample/src/main/java/com/nispok/sample/snackbar/SnackbarSampleActivity.java index a222709..3d9d614 100644 --- a/sample/src/main/java/com/nispok/sample/snackbar/SnackbarSampleActivity.java +++ b/sample/src/main/java/com/nispok/sample/snackbar/SnackbarSampleActivity.java @@ -7,7 +7,7 @@ import android.view.View; import android.widget.Button; -import com.williammora.snackbar.Snackbar; +import com.nispok.snackbar.Snackbar; import java.lang.Override; From aa68a718c3aa462974653f3da688939cdeac28ca Mon Sep 17 00:00:00 2001 From: William Mora Date: Sat, 1 Nov 2014 20:23:07 -0300 Subject: [PATCH 04/53] sliding animations --- .../java/com/nispok/snackbar/Snackbar.java | 68 +++++++++++-------- lib/src/main/res/anim/snackbar_in.xml | 15 ++-- lib/src/main/res/anim/snackbar_out.xml | 10 +-- 3 files changed, 49 insertions(+), 44 deletions(-) diff --git a/lib/src/main/java/com/nispok/snackbar/Snackbar.java b/lib/src/main/java/com/nispok/snackbar/Snackbar.java index baeaf4b..5a76ac2 100644 --- a/lib/src/main/java/com/nispok/snackbar/Snackbar.java +++ b/lib/src/main/java/com/nispok/snackbar/Snackbar.java @@ -201,7 +201,7 @@ public Snackbar animation(boolean withAnimation) { } /** - * Determines whether this {@link Snackbar} can be swiped off from the screen + * Determines whether this {@link com.nispok.snackbar.Snackbar} can be swiped off from the screen * * @param canSwipeToDismiss * @return @@ -303,7 +303,7 @@ public boolean canDismiss(Object token) { @Override public void onDismiss(View view, Object token) { if (view != null) { - dismiss(); + finish(); } } })); @@ -333,22 +333,13 @@ public void show(Activity targetActivity) { mEventListener.onShow(mType.getHeight()); } - if (mAnimated) { - startSnackbarAnimation(); - } else { - postDelayed(new Runnable() { - @Override - public void run() { - dismiss(); - } - }, getDuration()); + if (!mAnimated) { + startTimer(); + return; } - } - private void startSnackbarAnimation() { - final Animation fadeOut = AnimationUtils.loadAnimation(getContext(), R.anim.snackbar_out); - fadeOut.setStartOffset(getDuration()); - fadeOut.setAnimationListener(new Animation.AnimationListener() { + Animation slideIn = AnimationUtils.loadAnimation(getContext(), R.anim.snackbar_in); + slideIn.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { @@ -359,7 +350,7 @@ public void onAnimationEnd(Animation animation) { post(new Runnable() { @Override public void run() { - dismiss(); + startTimer(); } }); } @@ -369,8 +360,27 @@ public void onAnimationRepeat(Animation animation) { } }); - Animation slideIn = AnimationUtils.loadAnimation(getContext(), R.anim.snackbar_in); - slideIn.setAnimationListener(new Animation.AnimationListener() { + startAnimation(slideIn); + } + + private void startTimer() { + postDelayed(new Runnable() { + @Override + public void run() { + dismiss(); + } + }, getDuration()); + } + + public void dismiss() { + + if (!mAnimated) { + finish(); + return; + } + + final Animation slideOut = AnimationUtils.loadAnimation(getContext(), R.anim.snackbar_out); + slideOut.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { @@ -381,7 +391,7 @@ public void onAnimationEnd(Animation animation) { post(new Runnable() { @Override public void run() { - startAnimation(fadeOut); + finish(); } }); } @@ -391,10 +401,10 @@ public void onAnimationRepeat(Animation animation) { } }); - startAnimation(slideIn); + startAnimation(slideOut); } - public void dismiss() { + private void finish() { clearAnimation(); ViewGroup parent = (ViewGroup) getParent(); if (parent != null) { @@ -443,7 +453,7 @@ public boolean shouldDismissOnActionClicked() { } /** - * Returns whether this {@link Snackbar} is currently showing + * Returns whether this {@link com.nispok.snackbar.Snackbar} is currently showing * * @return */ @@ -452,7 +462,7 @@ public boolean isShowing() { } /** - * Returns whether this {@link Snackbar} has been dismissed + * Returns whether this {@link com.nispok.snackbar.Snackbar} has been dismissed * * @return */ @@ -465,21 +475,21 @@ public interface ActionClickListener { } /** - * Interface used to notify of all {@link Snackbar} display events. Useful if you want + * Interface used to notify of all {@link com.nispok.snackbar.Snackbar} display events. Useful if you want * to move other views while the Snackbar is on screen. */ public interface EventListener { /** - * Called when a {@link Snackbar} is about to enter the screen + * Called when a {@link com.nispok.snackbar.Snackbar} is about to enter the screen * - * @param height {@link Snackbar} height, in DP + * @param height {@link com.nispok.snackbar.Snackbar} height, in DP */ public void onShow(int height); /** - * Called when a {@link Snackbar} had just been dismissed + * Called when a {@link com.nispok.snackbar.Snackbar} had just been dismissed * - * @param height {@link Snackbar} height, in DP + * @param height {@link com.nispok.snackbar.Snackbar} height, in DP */ public void onDismiss(int height); } diff --git a/lib/src/main/res/anim/snackbar_in.xml b/lib/src/main/res/anim/snackbar_in.xml index 74103a5..1980d91 100644 --- a/lib/src/main/res/anim/snackbar_in.xml +++ b/lib/src/main/res/anim/snackbar_in.xml @@ -1,12 +1,7 @@ - - - - \ No newline at end of file + \ No newline at end of file diff --git a/lib/src/main/res/anim/snackbar_out.xml b/lib/src/main/res/anim/snackbar_out.xml index 7f5c2e7..9dab587 100644 --- a/lib/src/main/res/anim/snackbar_out.xml +++ b/lib/src/main/res/anim/snackbar_out.xml @@ -1,7 +1,7 @@ - \ No newline at end of file + \ No newline at end of file From d726d3b40ff9f545838cf6e62d24e731e3e5f029 Mon Sep 17 00:00:00 2001 From: William Mora Date: Sat, 1 Nov 2014 21:42:53 -0300 Subject: [PATCH 05/53] removed custom layout for tablets --- .../java/com/nispok/snackbar/Snackbar.java | 55 ++++++------------- .../com/nispok/snackbar/SnackbarLayout.java | 49 ----------------- .../main/res/drawable/snackbar_background.xml | 6 -- lib/src/main/res/layout/snackbar.xml | 24 +++++--- lib/src/main/res/values-sw600dp/dimens.xml | 4 -- lib/src/main/res/values-sw600dp/styles.xml | 12 ---- lib/src/main/res/values/colors.xml | 4 -- lib/src/main/res/values/dimens.xml | 4 -- 8 files changed, 32 insertions(+), 126 deletions(-) delete mode 100644 lib/src/main/java/com/nispok/snackbar/SnackbarLayout.java delete mode 100644 lib/src/main/res/drawable/snackbar_background.xml delete mode 100644 lib/src/main/res/values-sw600dp/dimens.xml delete mode 100644 lib/src/main/res/values-sw600dp/styles.xml delete mode 100644 lib/src/main/res/values/colors.xml delete mode 100644 lib/src/main/res/values/dimens.xml diff --git a/lib/src/main/java/com/nispok/snackbar/Snackbar.java b/lib/src/main/java/com/nispok/snackbar/Snackbar.java index 5a76ac2..6e51f7e 100644 --- a/lib/src/main/java/com/nispok/snackbar/Snackbar.java +++ b/lib/src/main/java/com/nispok/snackbar/Snackbar.java @@ -3,7 +3,6 @@ import android.app.Activity; import android.content.Context; import android.graphics.Color; -import android.graphics.drawable.GradientDrawable; import android.text.TextUtils; import android.view.Gravity; import android.view.LayoutInflater; @@ -12,6 +11,7 @@ import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.FrameLayout; +import android.widget.RelativeLayout; import android.widget.TextView; import com.nispok.snackbar.listeners.SwipeDismissTouchListener; @@ -19,16 +19,11 @@ /** * View that provides quick feedback about an operation in a small popup at the base of the screen */ -public class Snackbar extends SnackbarLayout { +public class Snackbar extends RelativeLayout { private static int PHONE_MIN_HEIGHT_DP = 56; private static int PHONE_MAX_HEIGHT_DP = 80; - private static int TABLET_MIN_WIDTH_DP = 288; - private static int TABLET_MAX_WIDTH_DP = 568; - private static int TABLET_HEIGHT_DP = 48; - private static int TABLET_MARGIN_DP = 24; - public enum SnackbarType { SINGLE_LINE(PHONE_MIN_HEIGHT_DP, 1), MULTI_LINE(PHONE_MAX_HEIGHT_DP, 2); @@ -234,36 +229,19 @@ public Snackbar duration(long duration) { return this; } - private FrameLayout.LayoutParams init(Activity parent) { - SnackbarLayout layout = (SnackbarLayout) LayoutInflater.from(parent) + private void init(Activity parent) { + RelativeLayout layout = (RelativeLayout) LayoutInflater.from(parent) .inflate(R.layout.snackbar, this, true); + layout.setBackgroundColor(mColor); + float scale = getResources().getDisplayMetrics().density; + int height = (int) (mType.getHeight() * scale + 0.5f); - FrameLayout.LayoutParams params; - if (getResources().getConfiguration().smallestScreenWidthDp < 600) { - // Phone - layout.setMinimumHeight(dpToPx(PHONE_MIN_HEIGHT_DP, scale)); - layout.setMaxHeight(dpToPx(mType.getHeight(), scale)); - layout.setBackgroundColor(mColor); + RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, height); - params = new FrameLayout.LayoutParams( - FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT); - } else { - // Tablet/desktop - layout.setMinimumWidth(dpToPx(TABLET_MIN_WIDTH_DP, scale)); - layout.setMaxWidth(dpToPx(TABLET_MAX_WIDTH_DP, scale)); - layout.setBackgroundResource(R.drawable.snackbar_background); - GradientDrawable bg = (GradientDrawable) layout.getBackground(); - bg.setColor(mColor); - - params = new FrameLayout.LayoutParams( - FrameLayout.LayoutParams.WRAP_CONTENT, dpToPx(TABLET_HEIGHT_DP, scale)); - int margin = dpToPx(TABLET_MARGIN_DP, scale); - params.leftMargin = margin; - params.bottomMargin = margin; - } - params.gravity = Gravity.BOTTOM; + layout.setLayoutParams(params); TextView snackbarText = (TextView) layout.findViewById(R.id.snackbar_text); snackbarText.setText(mText); @@ -272,6 +250,7 @@ private FrameLayout.LayoutParams init(Activity parent) { TextView snackbarAction = (TextView) layout.findViewById(R.id.snackbar_action); if (!TextUtils.isEmpty(mActionLabel)) { + requestLayout(); snackbarAction.setText(mActionLabel); snackbarAction.setTextColor(mActionColor); snackbarAction.setOnClickListener(new OnClickListener() { @@ -309,11 +288,6 @@ public void onDismiss(View view, Object token) { })); } - return params; - } - - private static int dpToPx(int dp, float scale) { - return (int) (dp * scale + 0.5f); } /** @@ -323,8 +297,13 @@ private static int dpToPx(int dp, float scale) { * @param targetActivity */ public void show(Activity targetActivity) { - FrameLayout.LayoutParams params = init(targetActivity); + init(targetActivity); + ViewGroup root = (ViewGroup) targetActivity.findViewById(android.R.id.content); + FrameLayout.LayoutParams params = new FrameLayout.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); + params.gravity = Gravity.BOTTOM; + root.addView(this, params); mIsShowing = true; diff --git a/lib/src/main/java/com/nispok/snackbar/SnackbarLayout.java b/lib/src/main/java/com/nispok/snackbar/SnackbarLayout.java deleted file mode 100644 index 7c50913..0000000 --- a/lib/src/main/java/com/nispok/snackbar/SnackbarLayout.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.nispok.snackbar; - -import android.content.Context; -import android.util.AttributeSet; -import android.widget.LinearLayout; - -public class SnackbarLayout extends LinearLayout { - private int mMaxWidth = Integer.MAX_VALUE; - private int mMaxHeight = Integer.MAX_VALUE; - - public SnackbarLayout(Context context) { - super(context); - } - - public SnackbarLayout(Context context, AttributeSet attrs) { - this(context, attrs, 0); - } - - public SnackbarLayout(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - } - - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - // Adjust width as necessary - int width = MeasureSpec.getSize(widthMeasureSpec); - if (mMaxWidth < width) { - int mode = MeasureSpec.getMode(widthMeasureSpec); - widthMeasureSpec = MeasureSpec.makeMeasureSpec(mMaxWidth, mode); - } - // Adjust height as necessary - int height = MeasureSpec.getSize(heightMeasureSpec); - if (mMaxHeight < height) { - int mode = MeasureSpec.getMode(heightMeasureSpec); - heightMeasureSpec = MeasureSpec.makeMeasureSpec(mMaxHeight, mode); - } - super.onMeasure(widthMeasureSpec, heightMeasureSpec); - } - - public void setMaxWidth(int maxWidth) { - mMaxWidth = maxWidth; - requestLayout(); - } - - public void setMaxHeight(int maxHeight) { - mMaxHeight = maxHeight; - requestLayout(); - } -} diff --git a/lib/src/main/res/drawable/snackbar_background.xml b/lib/src/main/res/drawable/snackbar_background.xml deleted file mode 100644 index f75bee1..0000000 --- a/lib/src/main/res/drawable/snackbar_background.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/lib/src/main/res/layout/snackbar.xml b/lib/src/main/res/layout/snackbar.xml index 3ec2db8..639eb3b 100644 --- a/lib/src/main/res/layout/snackbar.xml +++ b/lib/src/main/res/layout/snackbar.xml @@ -1,20 +1,26 @@ - + + android:layout_alignParentRight="true" + android:layout_centerVertical="true" /> + android:layout_alignParentLeft="true" + android:layout_toLeftOf="@id/snackbar_action" + android:ellipsize="end" + android:textColor="@android:color/white" /> \ No newline at end of file diff --git a/lib/src/main/res/values-sw600dp/dimens.xml b/lib/src/main/res/values-sw600dp/dimens.xml deleted file mode 100644 index a7bf214..0000000 --- a/lib/src/main/res/values-sw600dp/dimens.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - 2dp - \ No newline at end of file diff --git a/lib/src/main/res/values-sw600dp/styles.xml b/lib/src/main/res/values-sw600dp/styles.xml deleted file mode 100644 index 0ca87d0..0000000 --- a/lib/src/main/res/values-sw600dp/styles.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/lib/src/main/res/values/colors.xml b/lib/src/main/res/values/colors.xml deleted file mode 100644 index ce3ce2e..0000000 --- a/lib/src/main/res/values/colors.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - #ff323232 - \ No newline at end of file diff --git a/lib/src/main/res/values/dimens.xml b/lib/src/main/res/values/dimens.xml deleted file mode 100644 index 8911744..0000000 --- a/lib/src/main/res/values/dimens.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - 0dp - \ No newline at end of file From 502ec5623210507d29478bdf222ca518f46058bb Mon Sep 17 00:00:00 2001 From: William Mora Date: Sat, 1 Nov 2014 22:09:22 -0300 Subject: [PATCH 06/53] Snackbar not swipeable by default --- lib/src/main/java/com/nispok/snackbar/Snackbar.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/nispok/snackbar/Snackbar.java b/lib/src/main/java/com/nispok/snackbar/Snackbar.java index 6e51f7e..72a8ee8 100644 --- a/lib/src/main/java/com/nispok/snackbar/Snackbar.java +++ b/lib/src/main/java/com/nispok/snackbar/Snackbar.java @@ -71,7 +71,7 @@ public long getDuration() { private boolean mShouldDismiss = true; private EventListener mEventListener; private boolean mIsShowing = false; - private boolean mCanSwipeToDismiss = true; + private boolean mCanSwipeToDismiss = false; private Snackbar(Context context) { super(context); From 15a2215ad1a5e3dbf958e1b5b46e130519097a8d Mon Sep 17 00:00:00 2001 From: William Mora Date: Sat, 1 Nov 2014 22:09:46 -0300 Subject: [PATCH 07/53] Travis update --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 47e6e17..fccb5c1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ android: - tools # The BuildTools version used by your project - - build-tools-20.0.0 + - build-tools-21.1.0 # The SDK version used to compile your project - android-20 From 70f717afdf1bd7120a81c93a00e17ce340d00a4e Mon Sep 17 00:00:00 2001 From: William Mora Date: Sat, 1 Nov 2014 22:10:12 -0300 Subject: [PATCH 08/53] Travis update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index de855a2..107d6f4 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Snackbar -[![Build Status](https://travis-ci.org/wmora/snackbar.svg?branch=master)](https://travis-ci.org/wmora/snackbar) +[![Build Status](https://travis-ci.org/nispok/snackbar.svg?branch=master)](https://travis-ci.org/nispok/snackbar) Library that implements Snackbars from Google's Material Design documentation. From 42f249941b687a73c020c11779a511a90cbedb28 Mon Sep 17 00:00:00 2001 From: William Mora Date: Sat, 1 Nov 2014 22:18:25 -0300 Subject: [PATCH 09/53] Travis update --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index fccb5c1..65de227 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,7 @@ android: - build-tools-21.1.0 # The SDK version used to compile your project - - android-20 + - android-21 # Specify at least one system image, # if you need to run emulator(s) during your tests From 4004a53ff426c99d51823b083efd5d0a588c9e09 Mon Sep 17 00:00:00 2001 From: William Mora Date: Sat, 1 Nov 2014 22:19:17 -0300 Subject: [PATCH 10/53] Travis update --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 65de227..211594e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: android env: matrix: - - ANDROID_TARGET=android-19 ANDROID_ABI=armeabi-v7a + - ANDROID_TARGET=android-21 ANDROID_ABI=armeabi-v7a branches: only: From 87d3e2484c43d5df6bc679c04bb5749b93d67342 Mon Sep 17 00:00:00 2001 From: William Mora Date: Sat, 1 Nov 2014 22:29:02 -0300 Subject: [PATCH 11/53] Travis update --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 211594e..2716146 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,8 +23,7 @@ android: # Specify at least one system image, # if you need to run emulator(s) during your tests - - sys-img-armeabi-v7a-android-19 - - sys-img-x86-android-17 + - sys-img-armeabi-v7a-android-21 # Emulator Management: Create, Start and Wait before_script: From f3ba1954d20aa9c4b449f51f5307d3305f4f36bb Mon Sep 17 00:00:00 2001 From: William Mora Date: Sat, 1 Nov 2014 23:01:42 -0300 Subject: [PATCH 12/53] default text colors may be changed through code or by overriding styles --- .../com/nispok/snackbar/SnackbarTests.java | 12 ++------ .../java/com/nispok/snackbar/Snackbar.java | 28 ++++++++++++------- lib/src/main/res/values/colors.xml | 6 ++++ lib/src/main/res/values/styles.xml | 2 ++ 4 files changed, 29 insertions(+), 19 deletions(-) create mode 100644 lib/src/main/res/values/colors.xml diff --git a/lib/src/androidTest/java/com/nispok/snackbar/SnackbarTests.java b/lib/src/androidTest/java/com/nispok/snackbar/SnackbarTests.java index 6d2629d..6353412 100644 --- a/lib/src/androidTest/java/com/nispok/snackbar/SnackbarTests.java +++ b/lib/src/androidTest/java/com/nispok/snackbar/SnackbarTests.java @@ -51,12 +51,6 @@ public void testSnackbarTextColorCanBeChanged() { assertEquals(Color.GREEN, mSnackbar.getTextColor()); } - public void testSnackbarActionColorShouldBeGreenByDefault() { - mSnackbar = Snackbar.with(mContext); - - assertEquals(Color.GREEN, mSnackbar.getActionColor()); - } - public void testSnackbarActionColorCanBeChanged() { mSnackbar = Snackbar.with(mContext).actionColor(Color.BLUE); @@ -107,11 +101,11 @@ public void testSnackbarWithCustomDurationOverrideSnackbarDuration() { assertEquals(1000l, mSnackbar.getDuration()); } - public void testSnackbarCanBeSetToDismissOnActionClicked() { + public void testSnackbarCanBeSetToNotDismissOnActionClicked() { mSnackbar = Snackbar.with(mContext) - .dismissOnActionClicked(true); + .dismissOnActionClicked(false); - assertTrue(mSnackbar.shouldDismissOnActionClicked()); + assertFalse(mSnackbar.shouldDismissOnActionClicked()); } public void testSnackbarShouldBeDismissedOnActionClickedByDefault() { diff --git a/lib/src/main/java/com/nispok/snackbar/Snackbar.java b/lib/src/main/java/com/nispok/snackbar/Snackbar.java index 72a8ee8..2427dee 100644 --- a/lib/src/main/java/com/nispok/snackbar/Snackbar.java +++ b/lib/src/main/java/com/nispok/snackbar/Snackbar.java @@ -2,7 +2,6 @@ import android.app.Activity; import android.content.Context; -import android.graphics.Color; import android.text.TextUtils; import android.view.Gravity; import android.view.LayoutInflater; @@ -21,11 +20,11 @@ */ public class Snackbar extends RelativeLayout { - private static int PHONE_MIN_HEIGHT_DP = 56; - private static int PHONE_MAX_HEIGHT_DP = 80; + private static int MIN_HEIGHT_DP = 56; + private static int MAX_HEIGHT_DP = 80; public enum SnackbarType { - SINGLE_LINE(PHONE_MIN_HEIGHT_DP, 1), MULTI_LINE(PHONE_MAX_HEIGHT_DP, 2); + SINGLE_LINE(MIN_HEIGHT_DP, 1), MULTI_LINE(MAX_HEIGHT_DP, 2); private int height; private int maxLines; @@ -61,10 +60,10 @@ public long getDuration() { private SnackbarType mType = SnackbarType.SINGLE_LINE; private SnackbarDuration mDuration = SnackbarDuration.LENGTH_LONG; private CharSequence mText; - private int mColor = 0xff323232; - private int mTextColor = Color.WHITE; + private int mColor = -1; + private int mTextColor = -1; private CharSequence mActionLabel; - private int mActionColor = Color.GREEN; + private int mActionColor = -1; private boolean mAnimated = true; private long mCustomDuration = -1; private ActionClickListener mActionClickListener; @@ -233,7 +232,8 @@ private void init(Activity parent) { RelativeLayout layout = (RelativeLayout) LayoutInflater.from(parent) .inflate(R.layout.snackbar, this, true); - layout.setBackgroundColor(mColor); + layout.setBackgroundColor(mColor != -1 ? mColor : + getResources().getColor(R.color.snackbar_background)); float scale = getResources().getDisplayMetrics().density; int height = (int) (mType.getHeight() * scale + 0.5f); @@ -245,14 +245,22 @@ private void init(Activity parent) { TextView snackbarText = (TextView) layout.findViewById(R.id.snackbar_text); snackbarText.setText(mText); - snackbarText.setTextColor(mTextColor); + + if (mTextColor != -1) { + snackbarText.setTextColor(mTextColor); + } + snackbarText.setMaxLines(mType.getMaxLines()); TextView snackbarAction = (TextView) layout.findViewById(R.id.snackbar_action); if (!TextUtils.isEmpty(mActionLabel)) { requestLayout(); snackbarAction.setText(mActionLabel); - snackbarAction.setTextColor(mActionColor); + + if (mActionColor != -1) { + snackbarAction.setTextColor(mActionColor); + } + snackbarAction.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { diff --git a/lib/src/main/res/values/colors.xml b/lib/src/main/res/values/colors.xml new file mode 100644 index 0000000..69c4389 --- /dev/null +++ b/lib/src/main/res/values/colors.xml @@ -0,0 +1,6 @@ + + + #ff323232 + #ffffffff + #ff00ff00 + \ No newline at end of file diff --git a/lib/src/main/res/values/styles.xml b/lib/src/main/res/values/styles.xml index 1e71014..cac3e60 100644 --- a/lib/src/main/res/values/styles.xml +++ b/lib/src/main/res/values/styles.xml @@ -7,9 +7,11 @@ 18dp 24dp 14sp + @color/snackbar_text \ No newline at end of file From 879fb22d8026a0b287c3b89d4f7bd6f3d5ec93b0 Mon Sep 17 00:00:00 2001 From: William Mora Date: Sat, 1 Nov 2014 23:16:12 -0300 Subject: [PATCH 13/53] demo update --- .../sample/snackbar/SnackbarSampleActivity.java | 14 +++++++------- sample/src/main/res/layout/activity_sample.xml | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sample/src/main/java/com/nispok/sample/snackbar/SnackbarSampleActivity.java b/sample/src/main/java/com/nispok/sample/snackbar/SnackbarSampleActivity.java index 3d9d614..cffa753 100644 --- a/sample/src/main/java/com/nispok/sample/snackbar/SnackbarSampleActivity.java +++ b/sample/src/main/java/com/nispok/sample/snackbar/SnackbarSampleActivity.java @@ -117,10 +117,10 @@ public void onDismiss(int height) { public void onClick(View v) { Snackbar.with(SnackbarSampleActivity.this) .text("Shorter message, different colors") - .textColor(Color.GREEN) - .color(Color.BLUE) + .textColor(Color.parseColor("#ff9d9d9c")) + .color(Color.parseColor("#ff914300")) .actionLabel("Action") - .actionColor(Color.RED) + .actionColor(Color.parseColor("#ff5a2900")) .actionListener(new Snackbar.ActionClickListener() { @Override public void onActionClicked() { @@ -132,13 +132,13 @@ public void onActionClicked() { } }); - Button unswipeableButton = (Button) findViewById(R.id.unswipeable); - unswipeableButton.setOnClickListener(new View.OnClickListener() { + Button swipeableButton = (Button) findViewById(R.id.swipeable); + swipeableButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Snackbar.with(SnackbarSampleActivity.this) - .text("Can't swipe this") - .swipeToDismiss(false) + .text("Swipe me off the screen") + .swipeToDismiss(true) .show(SnackbarSampleActivity.this); } }); diff --git a/sample/src/main/res/layout/activity_sample.xml b/sample/src/main/res/layout/activity_sample.xml index f31d6c3..3a9e895 100644 --- a/sample/src/main/res/layout/activity_sample.xml +++ b/sample/src/main/res/layout/activity_sample.xml @@ -56,7 +56,7 @@ android:text="Custom colors" />