diff --git a/app/build.gradle b/app/build.gradle
index f247b19..4dc402b 100755
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
android {
compileSdkVersion 25
- buildToolsVersion "25.0.3"
+ buildToolsVersion '26.0.2'
defaultConfig {
applicationId "com.irozon.sneakersample"
minSdkVersion 19
diff --git a/app/src/main/java/com/irozon/sneakersample/MainActivity.java b/app/src/main/java/com/irozon/sneakersample/MainActivity.java
index 8e60b07..1a6684d 100755
--- a/app/src/main/java/com/irozon/sneakersample/MainActivity.java
+++ b/app/src/main/java/com/irozon/sneakersample/MainActivity.java
@@ -10,9 +10,10 @@
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
- Button btShowError;
- Button btShowSuccess;
- Button btShowWarning;
+ private Button btShowError;
+ private Button btShowSuccess;
+ private Button btShowWarning;
+ private Button btShowUpdating;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -22,10 +23,12 @@ protected void onCreate(Bundle savedInstanceState) {
btShowError = (Button) findViewById(R.id.btShowError);
btShowSuccess = (Button) findViewById(R.id.btShowSuccess);
btShowWarning = (Button) findViewById(R.id.btShowWarning);
+ btShowUpdating = (Button) findViewById(R.id.btShowUpdating);
btShowError.setOnClickListener(this);
btShowSuccess.setOnClickListener(this);
btShowWarning.setOnClickListener(this);
+ btShowUpdating.setOnClickListener(this);
}
@Override
@@ -50,6 +53,10 @@ public void onClick(View v) {
.setMessage("This is the warning message")
.sneakWarning();
break;
+ case R.id.btShowUpdating:
+ Sneaker.with(this)
+ .sneakUpdate();
+ break;
}
}
}
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index dcfe8ef..aeed49f 100755
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -27,4 +27,10 @@
android:layout_height="wrap_content"
android:text="Show Warning" />
+
+
diff --git a/build.gradle b/build.gradle
index 8a2f96e..e747a9a 100755
--- a/build.gradle
+++ b/build.gradle
@@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
- classpath 'com.android.tools.build:gradle:3.0.0-alpha6'
+ classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 53af44d..044f2a9 100755
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Sat Jul 15 19:22:33 EDT 2017
+#Sun Nov 05 22:27:35 GMT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-milestone-1-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
diff --git a/sneaker/build.gradle b/sneaker/build.gradle
index e7b14ed..c12956f 100755
--- a/sneaker/build.gradle
+++ b/sneaker/build.gradle
@@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
android {
compileSdkVersion 25
- buildToolsVersion "25.0.3"
+ buildToolsVersion '26.0.2'
defaultConfig {
minSdkVersion 14
diff --git a/sneaker/src/main/java/com/irozon/sneaker/Sneaker.java b/sneaker/src/main/java/com/irozon/sneaker/Sneaker.java
index 8c1f26e..765b0b9 100755
--- a/sneaker/src/main/java/com/irozon/sneaker/Sneaker.java
+++ b/sneaker/src/main/java/com/irozon/sneaker/Sneaker.java
@@ -1,5 +1,7 @@
package com.irozon.sneaker;
+import android.animation.ArgbEvaluator;
+import android.animation.ValueAnimator;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
@@ -8,6 +10,7 @@
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Handler;
+import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.AppCompatImageView;
import android.view.Gravity;
@@ -132,7 +135,7 @@ private static View getLayout() {
* @param title string value of title
* @return
*/
- public Sneaker setTitle(String title) {
+ public Sneaker setTitle(@NonNull String title) {
mTitle = title;
return this;
}
@@ -144,7 +147,7 @@ public Sneaker setTitle(String title) {
* @param color Color resource for title text
* @return
*/
- public Sneaker setTitle(String title, int color) {
+ public Sneaker setTitle(@NonNull String title, @NonNull int color) {
mTitle = title;
if (getContext() != null) {
try {
@@ -162,7 +165,7 @@ public Sneaker setTitle(String title, int color) {
* @param message String value of message
* @return
*/
- public Sneaker setMessage(String message) {
+ public Sneaker setMessage(@NonNull String message) {
mMessage = message;
return this;
}
@@ -174,7 +177,7 @@ public Sneaker setMessage(String message) {
* @param color Color resource for message text
* @return
*/
- public Sneaker setMessage(String message, int color) {
+ public Sneaker setMessage(@NonNull String message, @NonNull int color) {
mMessage = message;
if (getContext() != null) {
try {
@@ -217,8 +220,7 @@ public Sneaker setIcon(Drawable icon) {
* @param isCircular If icon is round or not
* @return
*/
- public Sneaker setIcon(int icon, boolean isCircular) {
- mIconDrawable = null;
+ public Sneaker setIcon(@NonNull int icon, @NonNull boolean isCircular) {
mIcon = icon;
mIsCircular = isCircular;
return this;
@@ -238,7 +240,7 @@ public Sneaker setIcon(Drawable icon, boolean isCircular) {
return this;
}
- public Sneaker setIcon(int icon, int tintColor) {
+ public Sneaker setIcon(@NonNull int icon, @NonNull int tintColor) {
mIconDrawable = null;
mIcon = icon;
if (getContext() != null) {
@@ -272,7 +274,7 @@ public Sneaker setIcon(Drawable icon, int tintColor) {
* @param isCircular If icon is round or not
* @return
*/
- public Sneaker setIcon(int icon, int tintColor, boolean isCircular) {
+ public Sneaker setIcon(@NonNull int icon, @NonNull int tintColor, @NonNull boolean isCircular) {
mIconDrawable = null;
mIcon = icon;
mIsCircular = isCircular;
@@ -294,7 +296,7 @@ public Sneaker setIcon(int icon, int tintColor, boolean isCircular) {
* @param isCircular If icon is round or not
* @return
*/
- public Sneaker setIcon(Drawable icon, int tintColor, boolean isCircular) {
+ public Sneaker setIcon(@NonNull Drawable icon, @NonNull int tintColor, boolean isCircular) {
mIcon = DEFAULT_VALUE;
mIconDrawable = icon;
mIsCircular = isCircular;
@@ -324,7 +326,7 @@ public Sneaker setIconSize(int size) {
* @param autoHide
* @return
*/
- public Sneaker autoHide(boolean autoHide) {
+ public Sneaker autoHide(@NonNull boolean autoHide) {
mAutoHide = autoHide;
return this;
}
@@ -335,7 +337,7 @@ public Sneaker autoHide(boolean autoHide) {
* @param height Height value for sneaker
* @return
*/
- public Sneaker setHeight(int height) {
+ public Sneaker setHeight(@NonNull int height) {
mHeight = height;
return this;
}
@@ -347,7 +349,7 @@ public Sneaker setHeight(int height) {
* @param duration
* @return
*/
- public Sneaker setDuration(int duration) {
+ public Sneaker setDuration(@NonNull int duration) {
mDuration = duration;
return this;
}
@@ -358,27 +360,53 @@ public Sneaker setDuration(int duration) {
* @param listener
* @return
*/
- public Sneaker setOnSneakerClickListener(OnSneakerClickListener listener) {
+ public Sneaker setOnSneakerClickListener(@NonNull OnSneakerClickListener listener) {
mListener = listener;
return this;
}
/**
* Set font for title and message
+ *
* @param typeface
* @return
*/
- public Sneaker setTypeface(Typeface typeface) {
+ public Sneaker setTypeface(@NonNull Typeface typeface) {
mTypeFace = typeface;
return this;
}
+ public void changeColour(Color color) {
+ if (isShowing()) {
+ ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), mBackgroundColor, color);
+ final LinearLayout layout = layoutWeakReference.get();
+ colorAnimation.setDuration(250); // milliseconds
+ colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
+
+ @Override
+ public void onAnimationUpdate(ValueAnimator animator) {
+ layout.setBackgroundColor((int) animator.getAnimatedValue());
+ }
+
+ });
+ }
+ }
+
+ /**
+ * Whether Sneaker is currently showing
+ *
+ * @return True: Sneaker is showing, False: Sneaker is gone
+ */
+ public boolean isShowing() {
+ return layoutWeakReference != null;
+ }
+
/**
* Shows sneaker with custom color
*
* @param backgroundColor Color resource for sneaker background color
*/
- public void sneak(int backgroundColor) {
+ public void sneak(@NonNull int backgroundColor) {
if (getContext() != null) {
try {
mBackgroundColor = ContextCompat.getColor(getContext(), backgroundColor);
@@ -420,6 +448,24 @@ public Sneaker sneakError() {
return null;
}
+ /**
+ * Shows updating sneaker with fixed icon, background color and icon color.
+ * Icons, background and text colors for this are not customizable
+ */
+ public Sneaker sneakUpdate() {
+ mBackgroundColor = Color.parseColor("#f99922");
+ mTitleColor = Color.parseColor("#FFFFFF");
+ mTitle = "Updating...";
+ mMessageColor = Color.parseColor("#FFFFFF");
+ mIconColorFilterColor = Color.parseColor("#FFFFFF");
+ mAutoHide = false;
+ mIcon = R.drawable.ic_update;
+
+ if (getContext() != null)
+ sneakView();
+ return null;
+ }
+
/**
* Shows success sneaker with fixed icon, background color and icon color.
* Icons, background and text colors for this are not customizable
@@ -440,7 +486,6 @@ public Sneaker sneakSuccess() {
* Creates the view and sneaks in
*/
private void sneakView() {
-
// Main layout
LinearLayout layout = new LinearLayout(getContext());
layoutWeakReference = new WeakReference<>(layout);
@@ -464,8 +509,7 @@ private void sneakView() {
AppCompatImageView ivIcon = new AppCompatImageView(getContext());
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(convertToDp(mIconSize), convertToDp(mIconSize));
ivIcon.setLayoutParams(lp);
-
- if(mIcon == DEFAULT_VALUE) {
+ if (mIcon == DEFAULT_VALUE) {
ivIcon.setImageDrawable(mIconDrawable);
} else {
ivIcon.setImageResource(mIcon);
@@ -475,12 +519,17 @@ private void sneakView() {
ivIcon.setColorFilter(mIconColorFilterColor);
}
layout.addView(ivIcon);
+ //-- Start Updating Animation
+ if (mIcon == R.drawable.ic_update) {
+ ivIcon.startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.update));
+
+ }
} else {
RoundedImageView ivIcon = new RoundedImageView(getContext());
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(convertToDp(mIconSize), convertToDp(mIconSize));
ivIcon.setLayoutParams(lp);
- if(mIcon == DEFAULT_VALUE) {
+ if (mIcon == DEFAULT_VALUE) {
ivIcon.setImageDrawable(mIconDrawable);
} else {
ivIcon.setImageResource(mIcon);
@@ -550,8 +599,8 @@ private void sneakView() {
layout.setOnClickListener(this);
viewGroup.addView(layout);
-
layout.startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.popup_show));
+ //-- Setup Hide Handler
if (mAutoHide) {
Handler handler = new Handler();
handler.removeCallbacks(null);
@@ -559,6 +608,8 @@ private void sneakView() {
@Override
public void run() {
getLayout().startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.popup_hide));
+
+
viewGroup.removeView(getLayout());
}
}, mDuration);
@@ -587,7 +638,7 @@ public void getExistingOverlayInViewAndRemove(ViewGroup parent) {
/**
* Returns status bar height.
*
- * @return
+ * @return Height of status bar
*/
private int getStatusBarHeight() {
Rect rectangle = new Rect();
@@ -600,6 +651,20 @@ private int getStatusBarHeight() {
return statusBarHeight;
}
+ /**
+ * Gets height of the title bar
+ *
+ * @return Height of title bar
+ */
+ private int getTitleBarHeight() {
+ Rect rectangle = new Rect();
+ Window window = ((Activity) getContext()).getWindow();
+ window.getDecorView().getWindowVisibleDisplayFrame(rectangle);
+ int statusBarHeight = rectangle.top;
+ int contentViewTop = window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
+ return contentViewTop - statusBarHeight;
+ }
+
private int convertToDp(float sizeInDp) {
float scale = getContext().getResources().getDisplayMetrics().density;
return (int) (sizeInDp * scale + 0.5f);
diff --git a/sneaker/src/main/res/anim/update.xml b/sneaker/src/main/res/anim/update.xml
new file mode 100644
index 0000000..e1e83d7
--- /dev/null
+++ b/sneaker/src/main/res/anim/update.xml
@@ -0,0 +1,14 @@
+
+
+
+
\ No newline at end of file
diff --git a/sneaker/src/main/res/drawable/ic_update.xml b/sneaker/src/main/res/drawable/ic_update.xml
new file mode 100644
index 0000000..ec9d640
--- /dev/null
+++ b/sneaker/src/main/res/drawable/ic_update.xml
@@ -0,0 +1,9 @@
+
+
+
diff --git a/sneaker/src/main/res/drawable/ic_warning.xml b/sneaker/src/main/res/drawable/ic_warning.xml
index 35e1310..9a9d8a4 100755
--- a/sneaker/src/main/res/drawable/ic_warning.xml
+++ b/sneaker/src/main/res/drawable/ic_warning.xml
@@ -1,9 +1,9 @@
+ android:viewportHeight="24.0"
+ android:viewportWidth="24.0">
+ android:fillColor="#FFFFFF"
+ android:pathData="M1,21h22L12,2 1,21zM13,18h-2v-2h2v2zM13,14h-2v-4h2v4z" />