Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions app/src/main/java/com/irozon/sneakersample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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;
}
}
}
6 changes: 6 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@
android:layout_height="wrap_content"
android:text="Show Warning" />

<Button
android:id="@+id/btShowUpdating"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Show Updating" />

</LinearLayout>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion sneaker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.library'

android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
buildToolsVersion '26.0.2'

defaultConfig {
minSdkVersion 14
Expand Down
107 changes: 86 additions & 21 deletions sneaker/src/main/java/com/irozon/sneaker/Sneaker.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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 {
Expand All @@ -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;
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -550,15 +599,17 @@ 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);
handler.postDelayed(new Runnable() {
@Override
public void run() {
getLayout().startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.popup_hide));


viewGroup.removeView(getLayout());
}
}, mDuration);
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions sneaker/src/main/res/anim/update.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate

android:duration="800"
android:fromDegrees="0"
android:pivotX="45%"
android:pivotY="45%"
android:repeatCount="-1"
android:repeatMode="restart"
android:toDegrees="360"

/>
</set>
9 changes: 9 additions & 0 deletions sneaker/src/main/res/drawable/ic_update.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FFFFFF"
android:pathData="m10.89736,2.83499c0.86459,0.00107 1.69054,0.14824 2.47276,0.39408l-0.61907,1.05254l4.3944,0l-1.09888,-1.87081l-1.09804,-1.87025l-0.57802,0.9855c-1.0833,-0.38934 -2.25113,-0.60723 -3.47236,-0.60723c-5.62124,0 -10.17743,4.47918 -10.17743,10.00503c0,2.29341 0.79348,4.40055 2.11401,6.0888l1.54753,-1.16803c-1.06801,-1.36434 -1.71015,-3.06684 -1.71364,-4.92022c0.00778,-4.46758 3.68462,-8.08256 8.22873,-8.08941l0,0zm8.06449,2.00216l-1.54753,1.16859c1.06774,1.36382 1.70989,3.06525 1.71283,4.91918c-0.00778,4.46754 -3.68462,8.082 -8.229,8.08936c-0.80529,-0.00102 -1.57571,-0.12974 -2.31016,-0.34501l0.58257,-0.99028l-4.39438,0l1.09807,1.86978l1.09886,1.87236l0.61263,-1.04512c1.03902,0.35557 2.15102,0.55394 3.31241,0.55446c5.62205,-0.00103 10.17746,-4.48021 10.17878,-10.00607c-0.00132,-2.29341 -0.79537,-4.40003 -2.11508,-6.08725l0,0z" />
</vector>
Loading