Skip to content

Commit 2bfc098

Browse files
committed
Fixed bintray pushing code
Updated README.md Added checks when creating from existing bitmap that it is mutable and not recycled
1 parent 6bad029 commit 2bfc098

7 files changed

Lines changed: 133 additions & 18 deletions

File tree

README.md

Lines changed: 107 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,115 @@
11
# CanvasScript
22
A canvas rendering wrapper for Android's Canvas and Paint classes
33

4+
[![Download](https://api.bintray.com/packages/52inc/CanvasScript/CanvasScript/images/download.svg) ](https://bintray.com/52inc/CanvasScript/CanvasScript/_latestVersion)
45

56
## Include
67
```groovy
7-
compile 'com.52inc:canvasscript:1.0.0'
8+
compile 'com.52inc:canvasscript:1.0.1'
89
```
910

11+
## How-to-Use
12+
13+
There are two ways to to utilize the wrapper.
14+
15+
1. **Creating a new Bitmap to render to**
16+
17+
```java
18+
CanvasScript.create(int width, int height)
19+
CanvasScript.create(int width, int height, Bitmap.Config config)
20+
CanvasScript.create(Bitmap bitmap);
21+
```
22+
23+
This will create a new script object initialized with new (or provided) bitmap where all subsequent drawing calls will be rendered to and returned.
24+
25+
2. **Wrap an existing canvas**
26+
27+
```java
28+
CanvasScript.wrap(Canvas canvas)
29+
```
30+
31+
This will return a script instance wrapped around an existing `Canvas` (i.e. if you are trying to use the script to render in a custom view object) where all drawing calls will be directed and rendered to.
32+
33+
-
34+
35+
Once you have initialized your script object you can then start chaining drawing and paint calls that will be combined sequentially in the order they were called when you call the `.draw()` function. If you created your script using **Method #1** then it will return the provided/created `Bitmap` that was drawn upon. If you created your script using **Method #2** then it will return `null`.
36+
37+
### Methods
38+
There are basically **two** groups of methods: **Paint** methods, and **Canvas** Methods.
39+
40+
#### Paint
41+
42+
These methods modify an internally tracked `Paint` object that can be implicitly provided for all the `Canvas` drawing calls so you don't have to keep track of creating and supplying your own (unless you want to).
43+
44+
[`CanvasScript.java L151 - L355`](https://github.com/52inc/CanvasScript/blob/master/library/src/main/java/com/ftinc/canvasscript/CanvasScript.java#L151-L355)
45+
46+
One of these methods must be called to initialize the internal paint object before calling and implicity canvas method or else you will get an `IllegalStateException`
47+
48+
#### Canvas
49+
50+
These methods are instructions for calls to the `Canvas` object to be rendered sequentially:
51+
52+
53+
[`CanvasScript.java L358 - L1457`](https://github.com/52inc/CanvasScript/blob/master/library/src/main/java/com/ftinc/canvasscript/CanvasScript.java#L358-L1457)
54+
55+
There is a version of every call to account for all possible drawing methods for their `Canvas` equivelents. There is also a duplicate call where you can supply your own `Paint` object for rendering instead of using the internally tracked one mentioned above.
56+
57+
#### Special
58+
59+
Now there are a few special methods in the API to give you some extra functionality and they are:
60+
61+
```java
62+
public CanvasScript custom(@NonNull CanvasParams customParameter)
63+
```
64+
65+
This call allows you to provide a custom `CanvasParams` object where you can define a custom set of `Canvas` drawing calls to the stack (i.e. If you wanted to create a parameter that auto magically sets up a PorterDuff Xfer call in one line)
66+
67+
```java
68+
public CanvasScript script(CanvasScript script)
69+
public CanvasScript script(float dx, float dy, CanvasScript script)
70+
```
71+
72+
These calls allow you to chain multiple `CanvasScripts` together
73+
74+
### Drawing
75+
76+
Once you have finished your chain of paint and canvas methods and are reading to render everything to the canvas/bitmap just call:
77+
78+
```java
79+
@Nullable
80+
public Bitmap draw()
81+
```
82+
83+
If you wrapped an existing `Canvas` object when you created your `CanvasScript` then this will return `null`, otherwise it will return the `Bitmap` that it created will all the subsequent drawing calls made to it.
84+
85+
##### Special note about save/restore calls
86+
87+
If you make any `Canvas` save calls (i.e. `save()`, `saveLayer(...)`, etc) the CanvasScript will internally keep track of the returned integer (i.e. the save count) so when you later call `restore()` it will automatically restore to that saved count.
88+
89+
### Example
90+
91+
```java
92+
CanvasScript.wrap(canvas)
93+
.saveLayer()
94+
.bitmap(image, measuredWidth, measuredHeight)
95+
.porterDuffXfer(PorterDuff.Mode.CLEAR)
96+
.circle(measuredWidth/2f, measuredHeight/2f, measuredWidth/4f)
97+
.paint(null)
98+
.restore()
99+
.color(color(R.color.colorAccent))
100+
.alpha(0.5f)
101+
.rect(0f, 0f, measuredWidth/2f, measuredHeight/2f)
102+
.alpha(1f)
103+
.color(Color.BLUE)
104+
.roundedRect(measuredWidth/2f, measuredHeight/2f, measuredWidth.toFloat(), measuredHeight.toFloat(), 20f)
105+
.color(Color.YELLOW)
106+
.style(Paint.Style.STROKE)
107+
.strokeWidth(10f)
108+
.strokeCap(Paint.Cap.ROUND)
109+
.arc(20f, 20f, measuredWidth.toFloat() - 40f, measuredHeight.toFloat() - 40f, -135f, 90f, false)
110+
.draw()
111+
```
112+
113+
The result looks like this:
114+
115+
<img src="art/example.png" style="width: 400px"></img>

art/example.png

51 KB
Loading

gradle.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
# limitations under the License.
1515
#
1616

17-
VERSION_CODE=1.0.0
18-
VERSION_DESC="CanvasScript Library v1.0.0"
1917
GROUP=com.52inc
18+
VERSION_NAME=1.0.1
19+
VERSION_DESC="CanvasScript Library v1.0.1"
2020

2121
POM_YEAR=2017
2222
POM_DESCRIPTION=A simple activity that adds sliding functionality to activities to swipe them away
@@ -30,6 +30,6 @@ POM_LICENCE_NAME=The Apache Software License, Version 2.0
3030
POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
3131
POM_LICENCE_DIST=repo
3232

33-
POM_DEVELOPER_ID=52inc
34-
POM_DEVELOPER_NAME=52inc
33+
POM_DEVELOPER_ID=r0adkll
34+
POM_DEVELOPER_NAME=Drew Heavner
3535
POM_DEVELOPER_EMAIL=drew@52inc.com

library/build.gradle

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
apply plugin: 'com.android.library'
1818

1919
group = GROUP
20-
version = VERSION_CODE
20+
version = VERSION_NAME
2121

2222
android {
2323
compileSdkVersion rootProject.ext.androidCompileSdkVersion
@@ -39,3 +39,12 @@ dependencies {
3939
}
4040

4141
apply from: '../tools/bintray-publish.gradle'
42+
//apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
43+
44+
afterEvaluate { project ->
45+
android.libraryVariants.all { variant ->
46+
tasks.androidJavadocs.doFirst {
47+
classpath += files(variant.javaCompile.classpath.files)
48+
}
49+
}
50+
}

library/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
#
1616
POM_NAME=Canvas Script
1717
POM_PACKAGING=aar
18-
ARTIFACT_ID=canvasscript
18+
POM_ARTIFACT_ID=canvasscript

library/src/main/java/com/ftinc/canvasscript/CanvasScript.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ public static CanvasScript create(int width, int height, @NonNull Bitmap.Config
131131
* @see Canvas
132132
*/
133133
public static CanvasScript create(@NonNull Bitmap bitmap) {
134+
if (!bitmap.isMutable() || bitmap.isRecycled()){
135+
throw new IllegalArgumentException("Bitmap must be mutable and unrecycled");
136+
}
134137
return new CanvasScript(bitmap);
135138
}
136139

tools/bintray-publish.gradle

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
apply plugin: 'com.jfrog.bintray'
1718
apply plugin: 'com.github.dcendents.android-maven'
1819

19-
project.archivesBaseName = ARTIFACT_ID
20+
project.archivesBaseName = POM_ARTIFACT_ID
2021

2122
install {
2223
repositories.mavenInstaller {
@@ -29,8 +30,8 @@ install {
2930

3031
packaging POM_PACKAGING
3132
groupId GROUP
32-
artifactId ARTIFACT_ID
33-
version VERSION_CODE
33+
artifactId POM_ARTIFACT_ID
34+
version VERSION_NAME
3435

3536
licenses {
3637
license {
@@ -68,11 +69,13 @@ bintray {
6869
userOrg = '52inc'
6970
licenses = ['Apache-2.0']
7071
vcsUrl = POM_URL
72+
publish = true
73+
publicDownloadNumbers = true
7174
version {
72-
name = VERSION_CODE
75+
name = VERSION_NAME
7376
desc = VERSION_DESC
7477
released = new Date()
75-
vcsTag = "v$VERSION_CODE"
78+
vcsTag = "v$VERSION_NAME"
7679
}
7780
}
7881
}
@@ -82,12 +85,6 @@ task androidJavadocs(type: Javadoc) {
8285
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
8386
}
8487

85-
afterEvaluate {
86-
androidJavadocs.classpath += files(android.libraryVariants.collect { variant ->
87-
variant.javaCompile.classpath.files
88-
})
89-
}
90-
9188
task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
9289
classifier = 'javadoc'
9390
from androidJavadocs.destinationDir

0 commit comments

Comments
 (0)