Skip to content

Adding Android Studio support #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
26 changes: 25 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,35 @@ If anybody figures out how to do text paths, please let me know!
Installation
===

Eclipse
---

If you like you can import the project into eclipse, and use it as a library project
[This is a decent tutorial on using library projects](http://www.vogella.com/blog/2011/03/03/android-library-projects/)

Realistically, just copy MagicTextView.java & attrs.xml into your project and use them as your own.

Android Studio
---

For using it with Android Studio:

* Add the folder into your project
* Edit build.gradle and change `apply plugin: 'android'` into `apply plugin: 'android-library'`
* Remove activity tag in AndroidManifest.xml
* Add `':MagicTextView'` in the includes of the settings.xml of your project
* Add `compile project(':MagicTextView')` in the dependencies section of the module in which you want to use the library
* Use it in this module

You're done !

If you use it as a library into Android Studio, replace in your XML layout:

xmlns:qwerjk="http://schemas.android.com/apk/res/com.qwerjk.better_text"

By:

xmlns:qwerjk="http://schemas.android.com/apk/res-auto"

Usage
===
Expand All @@ -35,7 +59,7 @@ From Xml:
android:drawableLeft="@android:drawable/btn_star"
android:textStyle="bold"
android:padding="10dp"
qwerjk:foreground="@drawable/fake_luxury_tiled"
qwerjk:mtv_foreground="@drawable/fake_luxury_tiled"
qwerjk:innerShadowDy="2"
qwerjk:innerShadowColor="#FF000000"
qwerjk:innerShadowRadius="1"
Expand Down
32 changes: 32 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
buildscript {
repositories {
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}

apply plugin: 'android'

android {

compileSdkVersion 19
buildToolsVersion "19.0.3"

defaultConfig {
minSdkVersion 8
targetSdkVersion 19
}

sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
2 changes: 1 addition & 1 deletion res/layout/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
android:drawableLeft="@android:drawable/btn_star"
android:textStyle="bold"
android:padding="10dp"
qwerjk:foreground="@drawable/fake_luxury_tiled"
qwerjk:mtv_foreground="@drawable/fake_luxury_tiled"
qwerjk:innerShadowDy="2"
qwerjk:innerShadowColor="#FF000000"
qwerjk:innerShadowRadius="1"
Expand Down
4 changes: 2 additions & 2 deletions res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

<attr name="typeface" format="string" />

<attr name="foreground" format="reference|color"/>
<attr name="background" format="reference|color"/>
<attr name="mtv_foreground" format="reference|color"/>
<attr name="mtv_background" format="reference|color"/>

<attr name="strokeWidth" format="float" />
<attr name="strokeMiter" format="float" />
Expand Down
12 changes: 6 additions & 6 deletions src/com/qwerjk/better_text/MagicTextView.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,21 @@ public void init(AttributeSet attrs){
setTypeface(tf);
}

if(a.hasValue(R.styleable.MagicTextView_foreground)){
Drawable foreground = a.getDrawable(R.styleable.MagicTextView_foreground);
if(a.hasValue(R.styleable.MagicTextView_mtv_foreground)){
Drawable foreground = a.getDrawable(R.styleable.MagicTextView_mtv_foreground);
if(foreground != null){
this.setForegroundDrawable(foreground);
}else{
this.setTextColor(a.getColor(R.styleable.MagicTextView_foreground, 0xff000000));
this.setTextColor(a.getColor(R.styleable.MagicTextView_mtv_foreground, 0xff000000));
}
}

if(a.hasValue(R.styleable.MagicTextView_background)){
Drawable background = a.getDrawable(R.styleable.MagicTextView_background);
if(a.hasValue(R.styleable.MagicTextView_mtv_background)){
Drawable background = a.getDrawable(R.styleable.MagicTextView_mtv_background);
if(background != null){
this.setBackgroundDrawable(background);
}else{
this.setBackgroundColor(a.getColor(R.styleable.MagicTextView_background, 0xff000000));
this.setBackgroundColor(a.getColor(R.styleable.MagicTextView_mtv_background, 0xff000000));
}
}

Expand Down