├── app
├── .gitignore
├── src
│ └── main
│ │ ├── ic_launcher-web.png
│ │ ├── res
│ │ ├── drawable-nodpi
│ │ │ ├── pic1.png
│ │ │ ├── pic2.png
│ │ │ ├── pic3.png
│ │ │ ├── pic4.png
│ │ │ ├── pic5.png
│ │ │ └── pic1_small.png
│ │ ├── drawable-hdpi
│ │ │ └── ic_launcher.png
│ │ ├── drawable-mdpi
│ │ │ └── ic_launcher.png
│ │ ├── drawable-xhdpi
│ │ │ └── ic_launcher.png
│ │ ├── drawable-xxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── drawable-xxxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── layout
│ │ │ ├── activity_view_pager.xml
│ │ │ └── activity_main.xml
│ │ └── values
│ │ │ ├── colors.xml
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ │ ├── java
│ │ └── com
│ │ │ └── flavienlaurent
│ │ │ └── spanimated
│ │ │ ├── MutableBlurMaskFilterSpan.java
│ │ │ ├── FrameSpan.java
│ │ │ ├── StrikeSpan.java
│ │ │ ├── MutableForegroundColorSpan.java
│ │ │ ├── LetterLineBackgroundSpan.java
│ │ │ ├── BubbleSpan.java
│ │ │ ├── ViewPagerActivity.java
│ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
├── proguard-rules.txt
└── build.gradle
├── settings.gradle
├── sample.apk
├── .gitignore
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitattributes
├── README.md
├── gradle.properties
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/sample.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flavienlaurent/spans/HEAD/sample.apk
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | /.idea/workspace.xml
4 | .DS_Store
5 |
6 | .idea
7 | *.iml
--------------------------------------------------------------------------------
/app/src/main/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flavienlaurent/spans/HEAD/app/src/main/ic_launcher-web.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flavienlaurent/spans/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/drawable-nodpi/pic1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flavienlaurent/spans/HEAD/app/src/main/res/drawable-nodpi/pic1.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-nodpi/pic2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flavienlaurent/spans/HEAD/app/src/main/res/drawable-nodpi/pic2.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-nodpi/pic3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flavienlaurent/spans/HEAD/app/src/main/res/drawable-nodpi/pic3.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-nodpi/pic4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flavienlaurent/spans/HEAD/app/src/main/res/drawable-nodpi/pic4.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-nodpi/pic5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flavienlaurent/spans/HEAD/app/src/main/res/drawable-nodpi/pic5.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flavienlaurent/spans/HEAD/app/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flavienlaurent/spans/HEAD/app/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-nodpi/pic1_small.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flavienlaurent/spans/HEAD/app/src/main/res/drawable-nodpi/pic1_small.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flavienlaurent/spans/HEAD/app/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flavienlaurent/spans/HEAD/app/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flavienlaurent/spans/HEAD/app/src/main/res/drawable-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Apr 10 15:27:10 PDT 2013
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=http\://services.gradle.org/distributions/gradle-1.9-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_view_pager.xml:
--------------------------------------------------------------------------------
1 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #000000
4 | #96C13E
5 | #681300
6 | #68009E
7 | #003D4E
8 | #0094FF
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | spans
5 | Frankfurter strip steak sirloin kielbasa drumstick tongue chicken, rump cow shoulder ribeye kevin ground round flank. Ham pork chop rump, kevin bresaola short ribs leberkas Im gonna be Animated!. Spare ribs tail short ribs jerky flank. Ground round chuck cow shank t-bone venison pork belly ball tip fatback tri-tip prosciutto biltong rump tail.
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 | *.sln merge=union
7 | *.csproj merge=union
8 | *.vbproj merge=union
9 | *.fsproj merge=union
10 | *.dbproj merge=union
11 |
12 | # Standard to msysgit
13 | *.doc diff=astextplain
14 | *.DOC diff=astextplain
15 | *.docx diff=astextplain
16 | *.DOCX diff=astextplain
17 | *.dot diff=astextplain
18 | *.DOT diff=astextplain
19 | *.pdf diff=astextplain
20 | *.PDF diff=astextplain
21 | *.rtf diff=astextplain
22 | *.RTF diff=astextplain
23 |
--------------------------------------------------------------------------------
/app/proguard-rules.txt:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in E:/soft/android-studio/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the ProGuard
5 | # include property in project.properties.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | mavenCentral()
4 | }
5 | dependencies {
6 | classpath 'com.android.tools.build:gradle:0.7.+'
7 | }
8 | }
9 | apply plugin: 'android'
10 |
11 | repositories {
12 | mavenCentral()
13 | }
14 |
15 | android {
16 | compileSdkVersion 19
17 | buildToolsVersion "19.0.0"
18 |
19 | defaultConfig {
20 | minSdkVersion 17
21 | targetSdkVersion 19
22 | versionCode 1
23 | versionName "1.0"
24 | }
25 | buildTypes {
26 | release {
27 | runProguard false
28 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
29 | }
30 | }
31 | }
32 |
33 | dependencies {
34 | compile 'com.android.support:support-v4:13.0.0'
35 | }
36 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Spans
2 | ==================
3 |
4 | http://flavienlaurent.com/blog/2014/01/31/spans/
5 |
6 | License
7 | -----------
8 |
9 | Copyright 2013 Flavien Laurent
10 |
11 | Licensed under the Apache License, Version 2.0 (the "License");
12 | you may not use this file except in compliance with the License.
13 | You may obtain a copy of the License at
14 |
15 | http://www.apache.org/licenses/LICENSE-2.0
16 |
17 | Unless required by applicable law or agreed to in writing, software
18 | distributed under the License is distributed on an "AS IS" BASIS,
19 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 | See the License for the specific language governing permissions and
21 | limitations under the License.
22 |
23 | [1]: https://raw.github.com/flavienlaurent/NotBoringActionBar/master/graphics/notboringab.gif
24 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Settings specified in this file will override any Gradle settings
5 | # configured through the IDE.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
12 |
13 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/flavienlaurent/spanimated/MutableBlurMaskFilterSpan.java:
--------------------------------------------------------------------------------
1 | package com.flavienlaurent.spanimated;
2 |
3 | import android.graphics.BlurMaskFilter;
4 | import android.graphics.MaskFilter;
5 | import android.text.TextPaint;
6 | import android.text.style.CharacterStyle;
7 | import android.text.style.UpdateAppearance;
8 |
9 | public class MutableBlurMaskFilterSpan extends CharacterStyle implements UpdateAppearance {
10 |
11 | private static final String TAG = "MutableBlurMaskFilterSpan";
12 | private float mRadius;
13 | private MaskFilter mFilter;
14 |
15 | public MutableBlurMaskFilterSpan(float radius) {
16 | mRadius = radius;
17 | }
18 |
19 | public void setRadius(float radius) {
20 | mRadius = radius;
21 | mFilter = new BlurMaskFilter(mRadius, BlurMaskFilter.Blur.NORMAL);
22 | }
23 |
24 | public float getRadius() {
25 | return mRadius;
26 | }
27 |
28 | public MaskFilter getFilter() {
29 | return mFilter;
30 | }
31 |
32 | @Override
33 | public void updateDrawState(TextPaint ds) {
34 | ds.setMaskFilter(mFilter);
35 | }
36 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/flavienlaurent/spanimated/FrameSpan.java:
--------------------------------------------------------------------------------
1 | package com.flavienlaurent.spanimated;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Color;
5 | import android.graphics.Paint;
6 | import android.text.style.ReplacementSpan;
7 |
8 | /**
9 | */
10 | public class FrameSpan extends ReplacementSpan {
11 |
12 | private final Paint mPaint;
13 | private int mWidth;
14 |
15 | public FrameSpan() {
16 | mPaint = new Paint();
17 | mPaint.setStyle(Paint.Style.STROKE);
18 | mPaint.setColor(Color.BLUE);
19 | mPaint.setAntiAlias(true);
20 | }
21 |
22 | @Override
23 | public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) {
24 | //return text with relative to the Paint
25 | mWidth = (int) paint.measureText(text, start, end);
26 | return mWidth;
27 | }
28 |
29 | @Override
30 | public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) {
31 | //draw the frame with custom Paint
32 | canvas.drawRect(x, top, x + mWidth, bottom, mPaint);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
8 |
9 |
15 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/java/com/flavienlaurent/spanimated/StrikeSpan.java:
--------------------------------------------------------------------------------
1 | package com.flavienlaurent.spanimated;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Color;
5 | import android.graphics.Paint;
6 | import android.graphics.RectF;
7 | import android.text.style.ReplacementSpan;
8 |
9 | /**
10 | */
11 | public class StrikeSpan extends ReplacementSpan {
12 |
13 | private final Paint mPaint;
14 | private int mWidth;
15 |
16 | public StrikeSpan(int strokeWidth) {
17 | mPaint = new Paint();
18 | mPaint.setStyle(Paint.Style.STROKE);
19 | mPaint.setColor(Color.BLUE);
20 | mPaint.setAntiAlias(true);
21 | mPaint.setStrokeWidth(strokeWidth);
22 | }
23 |
24 | @Override
25 | public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) {
26 | mWidth = (int) paint.measureText(text, start, end);
27 | return mWidth;
28 | }
29 |
30 | @Override
31 | public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) {
32 | float centerY = (top + bottom) * 0.5f;
33 | canvas.drawText(text, start, end, x, y, paint);
34 | canvas.drawLine(x, centerY, x + mWidth, centerY, mPaint);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/app/src/main/java/com/flavienlaurent/spanimated/MutableForegroundColorSpan.java:
--------------------------------------------------------------------------------
1 | package com.flavienlaurent.spanimated;
2 |
3 | import android.graphics.Color;
4 | import android.os.Parcel;
5 | import android.text.TextPaint;
6 | import android.text.style.ForegroundColorSpan;
7 |
8 | public class MutableForegroundColorSpan extends ForegroundColorSpan {
9 |
10 | private int mAlpha = 255;
11 | private int mForegroundColor;
12 |
13 | public MutableForegroundColorSpan(int alpha, int color) {
14 | super(color);
15 | mAlpha = alpha;
16 | mForegroundColor = color;
17 | }
18 |
19 | public MutableForegroundColorSpan(Parcel src) {
20 | super(src);
21 | mForegroundColor = src.readInt();
22 | mAlpha = src.readInt();
23 | }
24 |
25 | public void writeToParcel(Parcel dest, int flags) {
26 | super.writeToParcel(dest, flags);
27 | dest.writeInt(mForegroundColor);
28 | dest.writeFloat(mAlpha);
29 | }
30 |
31 | @Override
32 | public void updateDrawState(TextPaint ds) {
33 | ds.setColor(getForegroundColor());
34 | }
35 |
36 | /**
37 | * @param alpha from 0 to 255
38 | */
39 | public void setAlpha(int alpha) {
40 | mAlpha = alpha;
41 | }
42 |
43 | public void setForegroundColor(int foregroundColor) {
44 | mForegroundColor = foregroundColor;
45 | }
46 |
47 | public float getAlpha() {
48 | return mAlpha;
49 | }
50 |
51 | @Override
52 | public int getForegroundColor() {
53 | return Color.argb(mAlpha, Color.red(mForegroundColor), Color.green(mForegroundColor), Color.blue(mForegroundColor));
54 | }
55 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/flavienlaurent/spanimated/LetterLineBackgroundSpan.java:
--------------------------------------------------------------------------------
1 | package com.flavienlaurent.spanimated;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Color;
5 | import android.graphics.Paint;
6 | import android.graphics.RectF;
7 | import android.text.style.LineBackgroundSpan;
8 |
9 | import java.util.Arrays;
10 |
11 | /**
12 | *
13 | */
14 | public class LetterLineBackgroundSpan implements LineBackgroundSpan {
15 |
16 | private static final char[] sV = {'a','e','i','o','u','y'};
17 |
18 | private final Paint mCPaint;
19 | private final Paint mVPaint;
20 | private RectF mRectF = new RectF();
21 |
22 | public LetterLineBackgroundSpan() {
23 | mCPaint = new Paint();
24 | mCPaint.setColor(Color.MAGENTA);
25 | mCPaint.setAntiAlias(true);
26 | mVPaint = new Paint();
27 | mVPaint.setColor(Color.YELLOW);
28 | mVPaint.setAntiAlias(true);
29 | }
30 |
31 | @Override
32 | public void drawBackground(Canvas c, Paint p, int left, int right, int top, int baseline, int bottom, CharSequence text, int start, int end, int lnum) {
33 | float charx = left;
34 | for(int i = start ; i= 0) {
39 | c.drawRect(mRectF, mVPaint);
40 | } else {
41 | c.drawRect(mRectF, mCPaint);
42 | }
43 | }
44 | }
45 |
46 | private String extractText(CharSequence text, int start, int end) {
47 | return text.subSequence(start, end).toString();
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/app/src/main/java/com/flavienlaurent/spanimated/BubbleSpan.java:
--------------------------------------------------------------------------------
1 | package com.flavienlaurent.spanimated;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Color;
5 | import android.graphics.Paint;
6 | import android.graphics.RectF;
7 | import android.text.style.ReplacementSpan;
8 |
9 | import java.util.Random;
10 |
11 | public class BubbleSpan extends ReplacementSpan {
12 |
13 | private static final String TAG = "BubbleSpan";
14 | private static final boolean DEBUG = false;
15 | private Paint mPaint;
16 |
17 | static Random random = new Random();
18 | private int mWidth = -1;
19 | private RectF mRectF = new RectF();
20 |
21 | private int[] mColors = new int[20];
22 |
23 | public BubbleSpan() {
24 | initPaint();
25 | initColors();
26 | }
27 |
28 | private void initPaint() {
29 | mPaint = new Paint();
30 | mPaint.setColor(Color.rgb(random.nextInt(255), random.nextInt(255), random.nextInt(255)));
31 | mPaint.setAntiAlias(true);
32 | }
33 |
34 | private void initColors() {
35 | for(int index = 0 ; index < mColors.length ; index++) {
36 | mColors[index] = Color.rgb(random.nextInt(255), random.nextInt(255), random.nextInt(255));
37 | }
38 | }
39 |
40 | @Override
41 | public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) {
42 | //return text with relative to the Paint
43 | mWidth = (int) paint.measureText(text, start, end);
44 | return mWidth;
45 | }
46 |
47 | @Override
48 | public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) {
49 | float charx = x;
50 | for(int i = start ; iNUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
11 |
12 |
21 |
22 |
27 |
28 |
33 |
34 |
39 |
40 |
43 |
44 |
49 |
50 |
56 |
57 |
58 |
59 |
64 |
65 |
70 |
71 |
76 |
77 |
82 |
83 |
88 |
89 |
94 |
95 |
96 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/app/src/main/java/com/flavienlaurent/spanimated/ViewPagerActivity.java:
--------------------------------------------------------------------------------
1 | package com.flavienlaurent.spanimated;
2 |
3 | import android.animation.ArgbEvaluator;
4 | import android.app.Activity;
5 | import android.content.res.Resources;
6 | import android.graphics.Color;
7 | import android.os.Bundle;
8 | import android.support.v4.view.PagerAdapter;
9 | import android.support.v4.view.ViewPager;
10 | import android.text.SpannableString;
11 | import android.text.Spanned;
12 | import android.util.Log;
13 | import android.view.View;
14 | import android.view.ViewGroup;
15 | import android.widget.ImageView;
16 |
17 | public class ViewPagerActivity extends Activity {
18 |
19 | private static final String TAG = "ViewPagerActivity";
20 | private static final boolean DEBUG = true;
21 | private static int[] sPics = {R.drawable.pic1, R.drawable.pic2, R.drawable.pic3, R.drawable.pic4, R.drawable.pic5};
22 | private static String[] sPicNames = {"It's green!", "DarkRed this one", "Vioolet", "Dark aqua blue", "BLUE"};
23 | private static int[] sPicColors;
24 |
25 | private ViewPager mViewPager;
26 | private SpannableString[] mSpannableTitles;
27 | private MutableForegroundColorSpan mMutableSpan;
28 |
29 | @Override
30 | protected void onCreate(Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 |
33 | Resources resources = getResources();
34 | sPicColors = new int[] {resources.getColor(R.color.color1), resources.getColor(R.color.color2), resources.getColor(R.color.color3), resources.getColor(R.color.color4), resources.getColor(R.color.color5)};
35 |
36 | setContentView(R.layout.activity_view_pager);
37 |
38 | mViewPager = (ViewPager) findViewById(R.id.viewpager);
39 | mViewPager.setAdapter(new ImagePagerAdapter());
40 |
41 | mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
42 |
43 | private int mCurrentSelected;
44 | private int mNextSelected;
45 |
46 | @Override
47 | public void onPageSelected(int position) {
48 | if(DEBUG) Log.d(TAG, "onPageSelected:" + position);
49 | mCurrentSelected = position;
50 | mNextSelected = position;
51 | }
52 |
53 | @Override
54 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
55 | if(DEBUG) Log.d(TAG, "positionOffset:" + positionOffset);
56 | if(DEBUG) Log.d(TAG, "positionOffsetPixels:" + positionOffsetPixels);
57 |
58 | //http://stackoverflow.com/a/14111712/1785133
59 | if (positionOffset > 0.5) {
60 | // Closer to next screen than to current
61 | if (position + 1 != mNextSelected) {
62 | mNextSelected = position + 1;
63 | }
64 | } else {
65 | // Closer to current screen than to next
66 | if (position != mNextSelected) {
67 | mNextSelected = position;
68 | }
69 | }
70 |
71 | if(DEBUG) Log.d(TAG, "mCurrentSelected:" + mCurrentSelected);
72 | if(DEBUG) Log.d(TAG, "mNextSelected:" + mNextSelected);
73 |
74 | float positionOffsetCalc = Math.round(positionOffset * 100.0f) / 100.0f;
75 | if(positionOffsetCalc < 0.50) {
76 | positionOffsetCalc = 1 - positionOffsetCalc;
77 | } else if(positionOffsetCalc == 0.50) {
78 | positionOffsetCalc = 0;
79 | }
80 |
81 | if(DEBUG) Log.d(TAG, "positionOffsetCalc:" + positionOffsetCalc);
82 | mMutableSpan.setAlpha((int) (510 * positionOffsetCalc)); // 255 * 2
83 | mMutableSpan.setForegroundColor(sPicColors[mNextSelected]);
84 |
85 | updateTitle(mNextSelected);
86 | }
87 |
88 | @Override
89 | public void onPageScrollStateChanged(int state) {
90 | }
91 | });
92 |
93 | mMutableSpan = new MutableForegroundColorSpan(255, sPicColors[0]);
94 |
95 | initSpannableTitles();
96 |
97 | updateTitle(mViewPager.getCurrentItem());
98 | }
99 |
100 | private void initSpannableTitles() {
101 | mSpannableTitles = new SpannableString[sPicNames.length];
102 | int index = 0;
103 | for(String picName : sPicNames) {
104 | mSpannableTitles[index++] = new SpannableString(picName);
105 | }
106 | }
107 |
108 | private void updateTitle(int position) {
109 | SpannableString mSpannableTitle = mSpannableTitles[position];
110 | mSpannableTitle.setSpan(mMutableSpan, 0, mSpannableTitle.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
111 | setTitle(mSpannableTitle);
112 | }
113 |
114 | private class ImagePagerAdapter extends PagerAdapter {
115 |
116 | @Override
117 | public int getCount() {
118 | return sPics.length;
119 | }
120 |
121 | @Override
122 | public Object instantiateItem(ViewGroup viewGroup, int position) {
123 | ImageView view = new ImageView(ViewPagerActivity.this);
124 | view.setImageResource(sPics[position]);
125 | viewGroup.addView(view, 0);
126 | return view;
127 | }
128 |
129 | @Override
130 | public void destroyItem(ViewGroup collection, int position, Object view) {
131 | ((ViewPager) collection).removeView((ImageView) view);
132 | }
133 |
134 | @Override
135 | public boolean isViewFromObject(View view, Object object) {
136 | return view == ((ImageView) object);
137 | }
138 |
139 | }
140 | }
141 |
--------------------------------------------------------------------------------
/app/src/main/java/com/flavienlaurent/spanimated/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.flavienlaurent.spanimated;
2 |
3 | import android.animation.Animator;
4 | import android.animation.AnimatorListenerAdapter;
5 | import android.animation.ArgbEvaluator;
6 | import android.animation.ObjectAnimator;
7 | import android.animation.ValueAnimator;
8 | import android.app.Activity;
9 | import android.content.Intent;
10 | import android.graphics.BlurMaskFilter;
11 | import android.graphics.Color;
12 | import android.graphics.EmbossMaskFilter;
13 | import android.graphics.Typeface;
14 | import android.os.Bundle;
15 | import android.text.Layout;
16 | import android.text.SpannableString;
17 | import android.text.Spanned;
18 | import android.text.style.AbsoluteSizeSpan;
19 | import android.text.style.AlignmentSpan;
20 | import android.text.style.BackgroundColorSpan;
21 | import android.text.style.BulletSpan;
22 | import android.text.style.ForegroundColorSpan;
23 | import android.text.style.ImageSpan;
24 | import android.text.style.LocaleSpan;
25 | import android.text.style.MaskFilterSpan;
26 | import android.text.style.QuoteSpan;
27 | import android.text.style.RelativeSizeSpan;
28 | import android.text.style.ScaleXSpan;
29 | import android.text.style.StrikethroughSpan;
30 | import android.text.style.StyleSpan;
31 | import android.text.style.SubscriptSpan;
32 | import android.text.style.SuperscriptSpan;
33 | import android.text.style.TextAppearanceSpan;
34 | import android.text.style.TypefaceSpan;
35 | import android.text.style.UnderlineSpan;
36 | import android.util.Log;
37 | import android.util.Property;
38 | import android.view.View;
39 | import android.view.animation.AccelerateDecelerateInterpolator;
40 | import android.view.animation.LinearInterpolator;
41 | import android.widget.ArrayAdapter;
42 | import android.widget.Button;
43 | import android.widget.Spinner;
44 | import android.widget.TextView;
45 |
46 | import java.util.ArrayList;
47 | import java.util.Collections;
48 | import java.util.HashSet;
49 | import java.util.Locale;
50 |
51 | public class MainActivity extends Activity {
52 |
53 | private static String ANIMATED_WORD = "Im gonna be Animated!";
54 |
55 | private TextView mText;
56 | private Button mBtnAnimateColor;
57 | private Button mBtnReset;
58 | private Button mBtnDraw1;
59 | private Button mBtnDraw2;
60 | private Button mBtnDraw3;
61 | private Button mBtnAnimateTypeWriter;
62 | private Button mBtnViewPager;
63 | private Button mBtnAnimateAb1;
64 | private Button mBtnAnimateAb2;
65 | private Button mBtnSpanIt;
66 | private Spinner mSpinner;
67 |
68 | private int mTextColor;
69 |
70 | private String mBaconIpsum;
71 | private CharSequence mActionBarTitle;
72 |
73 | private SpannableString mBaconIpsumSpannableString;
74 | private SpannableString mActionBarTitleSpannableString;
75 | private AccelerateDecelerateInterpolator mSmoothInterpolator;
76 | private LinearInterpolator mTypeWriterInterpolator;
77 |
78 | private HashSet