-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from mitchhentges/title-feedback
Title feedback animation
- Loading branch information
Showing
7 changed files
with
66 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
app/src/main/java/ca/mitchhentges/positionmock/TitleBarAnimator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package ca.mitchhentges.positionmock; | ||
|
||
import android.animation.ValueAnimator; | ||
import android.graphics.Color; | ||
import android.graphics.drawable.ColorDrawable; | ||
import android.support.v7.app.ActionBarActivity; | ||
import android.util.Log; | ||
|
||
/** | ||
* @author cacti | ||
* @since 12/1/2015 | ||
*/ | ||
public class TitleBarAnimator { | ||
|
||
private final ActionBarActivity activity; | ||
|
||
public TitleBarAnimator(ActionBarActivity activity) { | ||
this.activity = activity; | ||
} | ||
|
||
public void animateTitleBar() { | ||
// Initial colors of each system bar. | ||
final int toolbarColor = activity.getResources().getColor(R.color.toolbar_color); | ||
final int toolbarToColor = activity.getResources().getColor(R.color.toolbar_to_color); | ||
|
||
ValueAnimator anim = ValueAnimator.ofFloat(0, 1); | ||
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { | ||
@Override | ||
public void onAnimationUpdate(ValueAnimator animation) { | ||
float position = animation.getAnimatedFraction(); | ||
|
||
if (position > 0.5) { | ||
position = Math.abs(position - 1); | ||
} | ||
|
||
int blended = blendColors(toolbarColor, toolbarToColor, position * 2); | ||
ColorDrawable background = new ColorDrawable(blended); | ||
activity.getSupportActionBar().setBackgroundDrawable(background); | ||
} | ||
}); | ||
anim.setDuration(500).start(); | ||
} | ||
|
||
private int blendColors(int from, int to, float ratio) { | ||
final float inverseRatio = 1f - ratio; | ||
|
||
final float r = Color.red(to) * ratio + Color.red(from) * inverseRatio; | ||
final float g = Color.green(to) * ratio + Color.green(from) * inverseRatio; | ||
final float b = Color.blue(to) * ratio + Color.blue(from) * inverseRatio; | ||
|
||
return Color.rgb((int) r, (int) g, (int) b); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<color name="toolbar_color">#212121</color> | ||
<color name="toolbar_to_color">#45B223</color> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,5 +19,5 @@ allprojects { | |
} | ||
|
||
task wrapper(type: Wrapper) { | ||
gradleVersion = '2.5' | ||
gradleVersion = '2.9' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Fri Aug 07 20:19:40 PDT 2015 | ||
#Tue Dec 01 21:54:51 PST 2015 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.9-bin.zip |