Skip to content

Commit

Permalink
added some javadoc and code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
gturedi committed Mar 21, 2017
1 parent c62309a commit b948231
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 28 deletions.
11 changes: 11 additions & 0 deletions app/src/main/res/anim/in.xml
@@ -0,0 +1,11 @@
<set xmlns:android="http://schemas.android.com/apk/res/android"
>

<alpha
android:duration="1000"
android:fromAlpha="0"
android:interpolator="@android:anim/accelerate_interpolator"
android:toAlpha="1"
/>

</set>
11 changes: 11 additions & 0 deletions app/src/main/res/anim/out.xml
@@ -0,0 +1,11 @@
<set xmlns:android="http://schemas.android.com/apk/res/android"
>

<alpha
android:duration="1000"
android:fromAlpha="1"
android:interpolator="@android:anim/accelerate_interpolator"
android:toAlpha="0"
/>

</set>
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -4,7 +4,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:2.3.0-rc1'
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.jakewharton:butterknife-gradle-plugin:8.5.1'
}
}
Expand Down
1 change: 1 addition & 0 deletions gradle/quality/pmdRuleSet.xml
Expand Up @@ -10,6 +10,7 @@
<exclude name="AtLeastOneConstructor"/>
<exclude name="OnlyOneReturn"/>
<exclude name="AvoidLiteralsInIfCondition"/>
<exclude name="DataflowAnomalyAnalysis"/>
</rule>
<rule ref="rulesets/java/controversial.xml/AvoidLiteralsInIfCondition">
<properties>
Expand Down
Empty file modified gradlew 100644 → 100755
Empty file.
63 changes: 36 additions & 27 deletions library/src/main/java/com/gturedi/views/StatefulLayout.java
Expand Up @@ -3,15 +3,18 @@
import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.AnimRes;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.*;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

/**
* Android layout to show most common state templates like loading, empty, error etc. To do that all you need to is
Expand All @@ -26,9 +29,21 @@ public class StatefulLayout
private static final int DEFAULT_IN_ANIM = android.R.anim.fade_in;
private static final int DEFAULT_OUT_ANIM = android.R.anim.fade_out;

/**
* Indicates whether to place the animation on state changes
*/
private boolean animationEnabled;
/**
* Animation started begin of state change
*/
private Animation inAnimation;
/**
* Animation started end of state change
*/
private Animation outAnimation;
/**
* to synchronize transition animations when animation duration shorter then request of state change
*/
private int animCounter;

private View content;
Expand All @@ -42,12 +57,12 @@ public StatefulLayout(Context context) {
this(context, null);
}

public StatefulLayout(Context context, @Nullable AttributeSet attrs) {
public StatefulLayout(Context context, AttributeSet attrs) {
super(context, attrs, 0);
TypedArray array = context.getTheme().obtainStyledAttributes(attrs, R.styleable.stfStatefulLayout, 0, 0);
animationEnabled = array.getBoolean(R.styleable.stfStatefulLayout_stfAnimationEnabled, DEFAULT_ANIM_ENABLED);
inAnimation = loadAnimation(array.getResourceId(R.styleable.stfStatefulLayout_stfInAnimation, DEFAULT_IN_ANIM));
outAnimation = loadAnimation(array.getResourceId(R.styleable.stfStatefulLayout_stfOutAnimation, DEFAULT_OUT_ANIM));
inAnimation = anim(array.getResourceId(R.styleable.stfStatefulLayout_stfInAnimation, DEFAULT_IN_ANIM));
outAnimation = anim(array.getResourceId(R.styleable.stfStatefulLayout_stfOutAnimation, DEFAULT_OUT_ANIM));
array.recycle();
}

Expand All @@ -68,7 +83,7 @@ public void setInAnimation(Animation animation) {
}

public void setInAnimation(@AnimRes int anim) {
inAnimation = loadAnimation(anim);
inAnimation = anim(anim);
}

public Animation getOutAnimation() {
Expand All @@ -80,7 +95,7 @@ public void setOutAnimation(Animation animation) {
}

public void setOutAnimation(@AnimRes int anim) {
outAnimation = loadAnimation(anim);
outAnimation = anim(anim);
}

@Override
Expand All @@ -101,24 +116,21 @@ protected void onFinishInflate() {
// content //

public void showContent() {
stContainer.clearAnimation();
content.clearAnimation();

if (isAnimationEnabled()) {
stContainer.clearAnimation();
content.clearAnimation();
final int animCounterCopy = ++animCounter;
if (stContainer.getVisibility() == VISIBLE) {
Animation outAnim = outAnimation;
outAnim.setAnimationListener(new CustomAnimationListener() {
outAnimation.setAnimationListener(new CustomAnimationListener() {
@Override
public void onAnimationEnd(Animation animation) {
if(animCounter != animCounterCopy)
return;
if (animCounter != animCounterCopy) return;
stContainer.setVisibility(GONE);
content.setVisibility(VISIBLE);
content.startAnimation(inAnimation);
}
});
stContainer.startAnimation(outAnim);
stContainer.startAnimation(outAnimation);
}
} else {
stContainer.setVisibility(GONE);
Expand Down Expand Up @@ -221,28 +233,24 @@ public void showLocationOff(String message, OnClickListener clickListener) {
* @see com.gturedi.views.CustomStateOptions
*/
public void showCustom(final CustomStateOptions options) {
stContainer.clearAnimation();
content.clearAnimation();

if (isAnimationEnabled()) {
stContainer.clearAnimation();
content.clearAnimation();
final int animCounterCopy = ++animCounter;
if (stContainer.getVisibility() == GONE) {
Animation outAnim = outAnimation;
outAnim.setAnimationListener(new CustomAnimationListener() {
outAnimation.setAnimationListener(new CustomAnimationListener() {
@Override
public void onAnimationEnd(Animation animation) {
if (animCounterCopy != animCounter)
return;
if (animCounterCopy != animCounter) return;
content.setVisibility(GONE);
stContainer.setVisibility(VISIBLE);
stContainer.startAnimation(inAnimation);
}
});
content.startAnimation(outAnim);
content.startAnimation(outAnimation);
state(options);
} else {
Animation outAnim = outAnimation;
outAnim.setAnimationListener(new CustomAnimationListener() {
outAnimation.setAnimationListener(new CustomAnimationListener() {
@Override
public void onAnimationEnd(Animation animation) {
if (animCounterCopy != animCounter)
Expand All @@ -251,7 +259,7 @@ public void onAnimationEnd(Animation animation) {
stContainer.startAnimation(inAnimation);
}
});
stContainer.startAnimation(outAnim);
stContainer.startAnimation(outAnimation);
}
} else {
content.setVisibility(GONE);
Expand Down Expand Up @@ -299,7 +307,8 @@ private String str(@StringRes int resId) {
return getContext().getString(resId);
}

private Animation loadAnimation(@AnimRes int resId) {
private Animation anim(@AnimRes int resId) {
return AnimationUtils.loadAnimation(getContext(), resId);
}

}

0 comments on commit b948231

Please sign in to comment.