-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit eba12e3
Showing
28 changed files
with
759 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
.DS_Store | ||
/build | ||
|
||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm | ||
|
||
## Directory-based project format | ||
.idea/ | ||
# if you remove the above rule, at least ignore user-specific stuff: | ||
# .idea/workspace.xml | ||
# .idea/tasks.xml | ||
# and these sensitive or high-churn files: | ||
# .idea/dataSources.ids | ||
# .idea/dataSources.xml | ||
# .idea/sqlDataSources.xml | ||
# .idea/dynamic.xml | ||
|
||
## File-based project format | ||
*.ipr | ||
*.iml | ||
*.iws | ||
|
||
## Additional for IntelliJ | ||
out/ | ||
|
||
# generated by mpeltonen/sbt-idea plugin | ||
.idea_modules/ | ||
|
||
# generated by JIRA plugin | ||
atlassian-ide-plugin.xml | ||
|
||
# generated by Crashlytics plugin (for Android Studio and Intellij) | ||
com_crashlytics_export_strings.xml |
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 @@ | ||
/build |
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,24 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 20 | ||
buildToolsVersion "20.0.0" | ||
|
||
defaultConfig { | ||
applicationId "interactivelabs.shinetextview" | ||
minSdkVersion 14 | ||
targetSdkVersion 20 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
buildTypes { | ||
release { | ||
runProguard false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
} |
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,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in /Applications/Android Studio.app/sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |
13 changes: 13 additions & 0 deletions
13
app/src/androidTest/java/interactivelabs/shinetextview/ApplicationTest.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,13 @@ | ||
package interactivelabs.shinetextview; | ||
|
||
import android.app.Application; | ||
import android.test.ApplicationTestCase; | ||
|
||
/** | ||
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a> | ||
*/ | ||
public class ApplicationTest extends ApplicationTestCase<Application> { | ||
public ApplicationTest() { | ||
super(Application.class); | ||
} | ||
} |
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,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="interactivelabs.shinetextview" > | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@drawable/ic_launcher" | ||
android:label="@string/app_name" | ||
android:theme="@style/AppTheme" > | ||
<activity | ||
android:name="com.shine.android.MainActivity" | ||
android:label="@string/app_name" > | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
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,92 @@ | ||
package com.shine.android; | ||
|
||
import android.animation.Animator; | ||
import android.animation.AnimatorListenerAdapter; | ||
import android.animation.ValueAnimator; | ||
import android.os.Build; | ||
import android.view.View; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Shine { | ||
private static final String TAG = Shine.class.getSimpleName(); | ||
private ValueAnimator animator; | ||
private long duration; | ||
private long startDelay; | ||
private List<String> shineList = new ArrayList<String>(); | ||
|
||
public Shine(long duration, long startDelay, List<String> shineList) { | ||
this.duration = duration; | ||
this.startDelay = startDelay; | ||
this.shineList = shineList; | ||
} | ||
|
||
public boolean isAnimating() { | ||
return animator != null && animator.isRunning(); | ||
} | ||
|
||
public <V extends View & ShineViewBase> void start(final V shineView) { | ||
|
||
if (isAnimating()) { | ||
return; | ||
} | ||
|
||
final Runnable animate = new Runnable() { | ||
@Override | ||
public void run() { | ||
shineView.setShine(true); | ||
shineView.setShineList(shineList); | ||
animator = ValueAnimator.ofFloat(0.0f, 2.0f); | ||
animator.setDuration(duration); | ||
animator.setStartDelay(startDelay); | ||
animator.setRepeatCount(ValueAnimator.INFINITE); | ||
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { | ||
@Override | ||
public void onAnimationUpdate(ValueAnimator animator) { | ||
Float percent = (Float) animator.getAnimatedValue(); | ||
shineView.setShinePercent(percent); | ||
shineView.invalidate(); | ||
} | ||
}); | ||
animator.addListener(new AnimatorListenerAdapter() { | ||
|
||
@Override | ||
public void onAnimationEnd(Animator animation) { | ||
shineView.setShine(false); | ||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { | ||
shineView.postInvalidate(); | ||
} else { | ||
shineView.postInvalidateOnAnimation(); | ||
} | ||
|
||
animator = null; | ||
} | ||
|
||
@Override | ||
public void onAnimationRepeat(Animator animation) { | ||
shineView.toggle(); | ||
} | ||
}); | ||
animator.start(); | ||
} | ||
}; | ||
|
||
if (!shineView.isSetUp()) { | ||
shineView.setAnimationSetupCallback(new ShineViewHelper.AnimationSetupCallback() { | ||
@Override | ||
public void onSetupAnimation(final View target) { | ||
animate.run(); | ||
} | ||
}); | ||
} else { | ||
animate.run(); | ||
} | ||
} | ||
|
||
public void cancel() { | ||
if (animator != null) { | ||
animator.cancel(); | ||
} | ||
} | ||
} |
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,76 @@ | ||
package com.shine.android; | ||
|
||
import android.content.Context; | ||
import android.graphics.Canvas; | ||
import android.text.SpannableString; | ||
import android.util.AttributeSet; | ||
import android.widget.TextView; | ||
|
||
import java.util.List; | ||
|
||
public class ShineTextView extends TextView implements ShineViewBase { | ||
|
||
private ShineViewHelper mShineViewHelper; | ||
|
||
public ShineTextView(Context context) { | ||
super(context); | ||
mShineViewHelper = new ShineViewHelper(this); | ||
} | ||
|
||
public ShineTextView(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
mShineViewHelper = new ShineViewHelper(this); | ||
} | ||
|
||
public ShineTextView(Context context, AttributeSet attrs, int defStyle) { | ||
super(context, attrs, defStyle); | ||
mShineViewHelper = new ShineViewHelper(this); | ||
} | ||
|
||
@Override | ||
protected void onDraw(Canvas canvas) { | ||
if (mShineViewHelper != null) { | ||
SpannableString spannableString = mShineViewHelper.onDraw(getCurrentTextColor()); | ||
setText(spannableString); | ||
} | ||
super.onDraw(canvas); | ||
} | ||
|
||
@Override | ||
public void setAnimationSetupCallback(ShineViewHelper.AnimationSetupCallback callback) { | ||
mShineViewHelper.setAnimationSetupCallback(callback); | ||
} | ||
|
||
@Override | ||
public boolean isSetUp() { | ||
return mShineViewHelper.isSetUp(); | ||
} | ||
|
||
@Override | ||
public void setShine(boolean isShining) { | ||
mShineViewHelper.setShine(isShining); | ||
} | ||
|
||
@Override | ||
public void setShinePercent(float percent) { | ||
mShineViewHelper.setShinePercent(percent); | ||
} | ||
|
||
@Override | ||
public void setShineList(List<String> shineList) { | ||
mShineViewHelper.setShineList(shineList); | ||
} | ||
|
||
@Override | ||
public void toggle() { | ||
mShineViewHelper.toggle(); | ||
} | ||
|
||
@Override | ||
protected void onSizeChanged(int w, int h, int oldw, int oldh) { | ||
super.onSizeChanged(w, h, oldw, oldh); | ||
if (mShineViewHelper != null) { | ||
mShineViewHelper.onSizeChanged(); | ||
} | ||
} | ||
} |
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,17 @@ | ||
package com.shine.android; | ||
|
||
import java.util.List; | ||
|
||
public interface ShineViewBase { | ||
public void setAnimationSetupCallback(ShineViewHelper.AnimationSetupCallback callback); | ||
|
||
public boolean isSetUp(); | ||
|
||
public void setShine(boolean isShining); | ||
|
||
public void setShinePercent(float percent); | ||
|
||
public void setShineList(List<String> shineList); | ||
|
||
public void toggle(); | ||
} |
Oops, something went wrong.