Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ apply plugin: 'com.android.application'
group = 'com.github.rafakob'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
compileSdkVersion rootProject.ext.CompileSdk
buildToolsVersion rootProject.ext.BuildTools

defaultConfig {
applicationId "com.rafakob.example.drawme"
minSdkVersion 10
targetSdkVersion 23
minSdkVersion rootProject.ext.MinSdk
targetSdkVersion rootProject.ext.TargetSdk
versionCode 1
versionName "1.0.0"
}
Expand All @@ -24,7 +24,7 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile "com.android.support:appcompat-v7:$rootProject.ext.SupportLibrary"

compile project(':library')
}
12 changes: 10 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,23 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-rc1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
classpath 'com.android.tools.build:gradle:2.3.2'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
}
}

allprojects {
repositories {
jcenter()
}

rootProject.ext {
BuildTools = "25.0.2"
MinSdk = 10
TargetSdk = 25
CompileSdk = 25
SupportLibrary = "25.3.1"
}
}

task clean(type: Delete) {
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Dec 28 10:00:20 PST 2015
#Thu Jun 08 19:35:26 PST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-all.zip
11 changes: 6 additions & 5 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ def versionMinor = 1
def versionPatch = 6

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
compileSdkVersion rootProject.ext.CompileSdk
buildToolsVersion rootProject.ext.BuildTools

defaultConfig {
minSdkVersion 10
targetSdkVersion 23
minSdkVersion rootProject.ext.MinSdk
targetSdkVersion rootProject.ext.TargetSdk
versionCode versionMajor * 1000000 + versionMinor * 1000 + versionPatch
versionName "${versionMajor}.${versionMinor}.${versionPatch}"
}

buildTypes {
release {
minifyEnabled false
Expand All @@ -26,7 +27,7 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile "com.android.support:appcompat-v7:$rootProject.ext.SupportLibrary"
}

// build a jar with source files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.AttrRes;
import android.support.annotation.ColorInt;
import android.support.annotation.FloatRange;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.text.TextUtils;
import android.util.AttributeSet;
Expand Down Expand Up @@ -38,7 +41,7 @@ public DrawMeShapeText(Context context, View view, AttributeSet attrs, @AttrRes

protected void obtainTextAttributes(TypedArray a) {
font = a.getString(R.styleable.DrawMeText_dm_font);
textColor = a.getColor(R.styleable.DrawMeText_dm_textColor, ((TextView) mView).getTextColors().getDefaultColor());
textColor = a.getColor(R.styleable.DrawMeText_dm_textColor, getTitleColor(backColor));
textColorPressed = a.getColor(R.styleable.DrawMeText_dm_textColorPressed, textColor);
textColorDisabled = a.getColor(R.styleable.DrawMeText_dm_textColorDisabled, textColor);

Expand Down Expand Up @@ -152,4 +155,18 @@ public void updateLayout() {
((TextView) mView).setTextColor(colorStateList);
}
}

@ColorInt
private int getTitleColor(@ColorInt int color) {
double darkness = 1-(0.299* Color.red(color) + 0.587*Color.green(color) + 0.114*Color.blue(color))/255;
return (darkness < 0.35) ? getDarkerColor(color, 0.25f) : Color.WHITE;
}

@ColorInt
private int getDarkerColor(@ColorInt int color, @FloatRange(from = 0.0f, to = 1.0f) float transparency) {
float[] hsv = new float[3];
Color.colorToHSV(color, hsv);
hsv[2] *= transparency;
return Color.HSVToColor(hsv);
}
}