Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
flavienlaurent committed Feb 2, 2014
0 parents commit 8c4451b
Show file tree
Hide file tree
Showing 38 changed files with 1,519 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Auto detect text files and perform LF normalization
* text=auto

# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union

# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.gradle
/local.properties
/.idea/workspace.xml
.DS_Store

.idea
*.iml
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
35 changes: 35 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android'

repositories {
mavenCentral()
}

android {
compileSdkVersion 19
buildToolsVersion "19.0.0"

defaultConfig {
minSdkVersion 17
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}

dependencies {
compile 'com.android.support:support-v4:13.0.0'
}
17 changes: 17 additions & 0 deletions app/proguard-rules.txt
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 E:/soft/android-studio/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# 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 *;
#}
32 changes: 32 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.flavienlaurent.spanimated" >

<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="19" />

<application
android:hardwareAccelerated="true"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.flavienlaurent.spanimated.MainActivity"
android:hardwareAccelerated="false"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.flavienlaurent.spanimated.ViewPagerActivity"
android:label="ViewPager"
android:theme="@style/AppTheme.ViewPagerTheme">
</activity>
</application>

</manifest>
Binary file added app/src/main/ic_launcher-web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 changes: 65 additions & 0 deletions app/src/main/java/com/flavienlaurent/spanimated/BubbleSpan.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.flavienlaurent.spanimated;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.text.style.ReplacementSpan;

import java.util.Random;

public class BubbleSpan extends ReplacementSpan {

private static final String TAG = "BubbleSpan";
private static final boolean DEBUG = false;
private Paint mPaint;

static Random random = new Random();
private int mWidth = -1;
private RectF mRectF = new RectF();

private int[] mColors = new int[20];

public BubbleSpan() {
initPaint();
initColors();
}

private void initPaint() {
mPaint = new Paint();
mPaint.setColor(Color.rgb(random.nextInt(255), random.nextInt(255), random.nextInt(255)));
mPaint.setAntiAlias(true);
}

private void initColors() {
for(int index = 0 ; index < mColors.length ; index++) {
mColors[index] = Color.rgb(random.nextInt(255), random.nextInt(255), random.nextInt(255));
}
}

@Override
public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) {
String word = extractText(text, start, end);
if(mWidth < 0) {
mWidth = (int) paint.measureText(word);
}
return mWidth;
}

@Override
public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) {
float charx = x;
for(int i = start ; i<end; i++) {
String charAt = extractText(text, i, i + 1);
float charWidth = paint.measureText(charAt);
mRectF.set(charx, top, charx += charWidth, bottom);
mPaint.setColor(mColors[i % mColors.length]);
canvas.drawOval(mRectF, mPaint);
}
canvas.drawText(text, start, end, x, y, paint);
}

private String extractText(CharSequence text, int start, int end) {
return text.subSequence(start, end).toString();
}
}
34 changes: 34 additions & 0 deletions app/src/main/java/com/flavienlaurent/spanimated/FrameSpan.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.flavienlaurent.spanimated;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.text.style.ReplacementSpan;

/**
*/
public class FrameSpan extends ReplacementSpan {

private final Paint mPaint;
private int mWidth;

public FrameSpan() {
mPaint = new Paint();
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setColor(Color.BLUE);
mPaint.setAntiAlias(true);
}

@Override
public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) {
//return text with relative to the Paint
mWidth = (int) paint.measureText(text.subSequence(start, end).toString());
return mWidth;
}

@Override
public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) {
//draw the frame with custom Paint
canvas.drawRect(x, top, x + mWidth, bottom, mPaint);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.flavienlaurent.spanimated;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.text.style.LineBackgroundSpan;

import java.util.Arrays;

/**
*
*/
public class LetterLineBackgroundSpan implements LineBackgroundSpan {

private static final char[] sV = {'a','e','i','o','u','y'};

private final Paint mCPaint;
private final Paint mVPaint;
private RectF mRectF = new RectF();

public LetterLineBackgroundSpan() {
mCPaint = new Paint();
mCPaint.setColor(Color.MAGENTA);
mCPaint.setAntiAlias(true);
mVPaint = new Paint();
mVPaint.setColor(Color.YELLOW);
mVPaint.setAntiAlias(true);
}

@Override
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) {
float charx = left;
for(int i = start ; i<end; i++) {
String charAt = extractText(text, i, i + 1);
float charWidth = p.measureText(charAt);
mRectF.set(charx, top, charx += charWidth, bottom);
if(Arrays.binarySearch(sV, charAt.charAt(0)) >= 0) {
c.drawRect(mRectF, mVPaint);
} else {
c.drawRect(mRectF, mCPaint);
}
}
}

private String extractText(CharSequence text, int start, int end) {
return text.subSequence(start, end).toString();
}
}
Loading

0 comments on commit 8c4451b

Please sign in to comment.