Skip to content

Commit baa2740

Browse files
author
michelou
committed
added CanvasDemo example
1 parent 1e3effa commit baa2740

File tree

76 files changed

+2419
-644
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+2419
-644
lines changed

android-app-dev/README.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ free software distributions (tested versions and download sites are given in
3535
parenthesis) :
3636

3737
1) Sun Java SDK 1.6 or newer (1.6.0_26 , www.sun.com/java/jdk/)
38-
2) Scala SDK 2.7.5 or newer (2.9.0.1 , www.scala-lang.org/downloads/)
39-
3) Android SDK 9 or newer (12 , developer.android.com/sdk/)
38+
2) Scala SDK 2.7.5 or newer (2.9.1 , www.scala-lang.org/downloads/)
39+
3) Android SDK 9 or newer (16 , developer.android.com/sdk/)
4040
4) Apache Ant 1.7.0 or newer (1.8.2 , ant.apache.org/)
4141
5) ProGuard 4.4 or newer (4.6 , www.proguard.com/)
4242

@@ -58,14 +58,14 @@ In particular:
5858
system needs to run the application's code (for more details see the docu-
5959
mentation page $ANDROID_SDK_ROOT/docs/guide/topics/manifest/manifest-intro.html)
6060

61-
* The "build.properties" file defines customizable Ant properties for the
61+
* The "ant.properties" file defines customizable Ant properties for the
6262
Android build system; in our case we need to define at least the following
6363
properties (please adapt the respective values to your own environment):
6464

65-
Unix: Windows:
66-
sdk.dir=/opt/android-sdk-linux_x86 sdk.dir=c:/Progra~1/android-sdk-windows
67-
scala.dir=/opt/scala scala.dir=c:/Progra~1/scala
68-
proguard.dir=/opt/proguard proguard.dir=c:/Progra~1/ProGuard
65+
Unix: Windows:
66+
sdk.dir=/opt/android-sdk-linux_x86 sdk.dir=c:/Progra~1/android-sdk-windows
67+
scala.dir=/opt/scala scala.dir=c:/Progra~1/scala
68+
proguard.dir=${sdk.dir}/tools/proguard proguard.dir=${sdk.dir}/tools/proguard
6969

7070
* The "default.properties" file defines the default API level of an Android
7171
(for more details see the documentation page
@@ -106,7 +106,7 @@ one of the following Ant targets :
106106
TriviaQuiz> ant clean
107107
TriviaQuiz> ant compile-scala
108108
TriviaQuiz> ant debug
109-
TriviaQuiz> ant install
109+
TriviaQuiz> ant installd
110110
(now let us play with our application on the emulator !)
111111
TriviaQuiz> ant uninstall
112112

@@ -127,5 +127,5 @@ See also http://developer.android.com/guide/publishing/app-signing.html
127127

128128

129129
Have fun!
130-
The Scala Team
130+
Stephane
131131

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="src" path="gen"/>
5+
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
6+
<classpathentry kind="output" path="bin"/>
7+
</classpath>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>aip-ch12-CanvasDemo</name>
4+
<comment>
5+
Android in Practice
6+
</comment>
7+
<projects>
8+
</projects>
9+
<buildSpec>
10+
<buildCommand>
11+
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
12+
<arguments>
13+
</arguments>
14+
</buildCommand>
15+
<buildCommand>
16+
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
17+
<arguments>
18+
</arguments>
19+
</buildCommand>
20+
<buildCommand>
21+
<name>org.eclipse.jdt.core.javabuilder</name>
22+
<arguments>
23+
</arguments>
24+
</buildCommand>
25+
<buildCommand>
26+
<name>ch.epfl.lamp.sdt.core.scalabuilder</name>
27+
<arguments>
28+
</arguments>
29+
</buildCommand>
30+
<buildCommand>
31+
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
32+
<arguments>
33+
</arguments>
34+
</buildCommand>
35+
</buildSpec>
36+
<natures>
37+
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
38+
<nature>org.eclipse.jdt.core.javanature</nature>
39+
<nature>ch.epfl.lamp.sdt.core.scalanature</nature>
40+
</natures>
41+
</projectDescription>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.manning.aip.canvasdemo" android:versionCode="1"
4+
android:versionName="1.0">
5+
<uses-sdk android:minSdkVersion="4" />
6+
7+
<application android:icon="@drawable/icon" android:label="@string/app_name">
8+
<activity android:name=".Main"
9+
android:label="@string/app_name">
10+
<intent-filter>
11+
<action android:name="android.intent.action.MAIN" />
12+
<category android:name="android.intent.category.LAUNCHER" />
13+
</intent-filter>
14+
</activity>
15+
16+
<activity android:name="Canvas2DRandomColorActivity" />
17+
<activity android:name="Canvas2DRandomColorFullScreenActivity" />
18+
<activity android:name="Canvas2DRandomShapesActivity" />
19+
<activity android:name="Canvas2DRandomShapesWithAlphaActivity" />
20+
<activity android:name="Canvas2DRandomShapesRedrawActivity" />
21+
<activity android:name="Canvas2DShapesAndTextLHXStyleActivity" />
22+
<activity android:name="Canvas2DShapesAndTextFontActivity" />
23+
<activity android:name="Canvas2DShapesAndTextBitmapActivity" />
24+
25+
</application>
26+
</manifest>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# This file is used to override default values used by the Ant build system.
2+
#
3+
# This file must be checked in Version Control Systems, as it is
4+
# integral to the build system of your project.
5+
6+
# This file is only used by the Ant script.
7+
8+
# You can use this to override default values such as
9+
# 'source.dir' for the location of your java source folder and
10+
# 'out.dir' for the location of your output folder.
11+
12+
# You can also use it define how the release builds are signed by declaring
13+
# the following properties:
14+
# 'key.store' for the location of your keystore and
15+
# 'key.alias' for the name of the key to use.
16+
# The password will be asked during the build when you use the 'release' target.
17+
18+
key.store=${user.home}/.android/release.keystore
19+
key.alias=android-in-practice
20+
21+
key.store.password=android
22+
key.alias.password=android
23+
24+
# You can use this to specify compiler arguments for Java:
25+
# 'java.compilerargs' (eg. java.compilerargs=-deprecation -Xlint)
26+
27+
sdk.dir=/opt/android-sdk-linux_x86
28+
29+
scala.dir=/opt/scala
30+
31+
scala.compilerargs=-deprecation
32+
33+
#proguard.dir=/opt/proguard
34+
proguard.dir=${sdk.dir}/tools/proguard
32.3 KB
Binary file not shown.
Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project name="build-scala">
3+
4+
<!-- This file is imported by the main Ant script. -->
5+
6+
<!-- Add Proguard tasks (proguard.sourceforge.net) -->
7+
<property name="proguard.jar" location="${proguard.dir}/lib/proguard.jar" />
8+
<taskdef name="proguard" classname="proguard.ant.ProGuardTask" classpath="${proguard.jar}" />
9+
10+
<!-- Add Scala tasks (www.scala-lang.org) -->
11+
<property name="scala-compiler.jar" value="${scala.dir}/lib/scala-compiler.jar" />
12+
<property name="scala-library.jar" value="${scala.dir}/lib/scala-library.jar" />
13+
<path id="scala.path">
14+
<pathelement path="${scala-compiler.jar}" />
15+
<pathelement path="${scala-library.jar}" />
16+
</path>
17+
<taskdef resource="scala/tools/ant/antlib.xml" classpathref="scala.path" />
18+
<property prefix="scala" resource="compiler.properties" classpathref="scala.path" />
19+
<property
20+
name="scalac.banner"
21+
value="Scala compiler version ${scala.version.number} - http://scala-lang.org" />
22+
<property name="scala.compilerargs" value="" />
23+
24+
<!-- Rules -->
25+
26+
<resourcecount property="scala.files.count">
27+
<fileset dir="${source.dir}" includes="**/*.scala" />
28+
</resourcecount>
29+
<condition property="contains.scala.sources">
30+
<not><equals arg1="${scala.files.count}" arg2="0" /></not>
31+
</condition>
32+
33+
<target name="-compile-scala" depends="-compile" if="contains.scala.sources"
34+
description="Compiles project's .scala files into .class files">
35+
<do-only-if-manifest-hasCode elseText="hasCode = false. Skipping...">
36+
<condition property="logging" value="verbose" else="none">
37+
<istrue value="${verbose}" />
38+
</condition>
39+
<echo message="${scalac.banner}" level="info" taskname="scalac" />
40+
<scalac
41+
destdir="${out.classes.absolute.dir}"
42+
bootclasspathref="android.target.classpath"
43+
logging="${logging}" addparams="${scala.compilerargs}"
44+
classpath="${extensible.classpath}"
45+
classpathref="jar.libs.ref">
46+
<src path="${source.absolute.dir}" />
47+
<src path="${gen.absolute.dir}" />
48+
<classpath>
49+
<pathelement location="${scala-library.jar}" />
50+
<!-- include compiled resources -->
51+
<pathelement location="${out.classes.absolute.dir}" />
52+
<fileset dir="${extensible.libs.classpath}" includes="*.jar" />
53+
</classpath>
54+
</scalac>
55+
<!-- if the project is a library then we generate a jar file -->
56+
<if condition="${project.is.library}">
57+
<then>
58+
<echo>Updating library output jar file...</echo>
59+
<jar destfile="${out.library.jar.file}" update="true">
60+
<fileset dir="${out.classes.absolute.dir}" excludes="**/R.class **/R$*.class"/>
61+
<fileset dir="${source.absolute.dir}" excludes="**/*.scala" />
62+
</jar>
63+
</then>
64+
</if>
65+
66+
<!-- if the project is instrumented, intrument the classes -->
67+
<if condition="${build.is.instrumented}">
68+
<then>
69+
<echo>Instrumenting classes from ${out.absolute.dir}/classes...</echo>
70+
<!-- It only instruments class files, not any external libs -->
71+
<emma enabled="true">
72+
<instr verbosity="${verbosity}"
73+
mode="overwrite"
74+
instrpath="${out.absolute.dir}/classes"
75+
outdir="${out.absolute.dir}/classes">
76+
</instr>
77+
<!-- TODO: exclusion filters on R*.class and allowing custom exclusion from
78+
user defined file -->
79+
</emma>
80+
</then>
81+
</if>
82+
</do-only-if-manifest-hasCode>
83+
</target>
84+
85+
<target name="-post-compile-scala" depends="-compile-scala"
86+
description="Shrink project class files and Scala library into one .jar file">
87+
<condition property="debug.mode" value="" else="#DEBUG#">
88+
<equals arg1="${build.target}" arg2="debug" />
89+
</condition>
90+
<condition property="release.mode" value="" else="#RELEASE#">
91+
<equals arg1="${build.target}" arg2="release" />
92+
</condition>
93+
<!-- priority is given to local ProGuard configuration if present -->
94+
<condition property="template.cfg" value="${basedir}/local-proguard-template.cfg">
95+
<available file="${basedir}/local-proguard-template.cfg" />
96+
</condition>
97+
<condition property="template.cfg" value="${basedir}/proguard-template.cfg">
98+
<available file="${basedir}/proguard-template.cfg" />
99+
</condition>
100+
<fail message="Template file '${template.cfg}' not found">
101+
<condition><not><available file="${template.cfg}" /></not></condition>
102+
</fail>
103+
<property name="proguard.cfg" value="${out.absolute.dir}${file.separator}proguard.cfg" />
104+
<delete file="${proguard.cfg}" />
105+
<echo message="Generating configuration file ${proguard.cfg}" />
106+
<generate-header property="header" />
107+
<if condition="${build.mode.release}"><then>
108+
<!-- needed for obfuscate task -->
109+
<path id="project.libraries.jars">
110+
<pathelement location="${scala-library.jar}" />
111+
</path>
112+
<!-- we use properties defined in main_rules.xml -->
113+
<property name="injars" value="" />
114+
<property name="outjars" value="" />
115+
<property name="libraryjars" value="" />
116+
</then><else>
117+
<property name="shrinked.jar" location="${out.absolute.dir}/shrinked.jar" />
118+
<!-- Secondary dx input (jar files) is empty since all the jar
119+
files will be in the shrinked jar (see tools/ant/build.xml) -->
120+
<path id="out.dex.jar.input.ref" />
121+
<condition property="shrink.required"><not>
122+
<uptodate targetfile="${shrinked.jar}">
123+
<srcfiles dir="${source.absolute.dir}" includes="**/*.scala" />
124+
</uptodate>
125+
</not></condition>
126+
<!-- input for dex will be proguard's output -->
127+
<property name="out.dex.input.absolute.dir" value="${shrinked.jar}" />
128+
<!-- set the compiled project files and Scala library into a single property. -->
129+
<if condition="${uses.ramdisk}"><then>
130+
<pathconvert property="project.injars">
131+
<path location="${out.classes.absolute.dir}" />
132+
<path refid="project.libraries.jars" />
133+
</pathconvert>
134+
</then><else>
135+
<pathconvert property="project.injars">
136+
<path location="${out.classes.absolute.dir}" />
137+
<fileset dir="${jar.libs.dir}" includes="*.jar" />
138+
<path refid="project.libraries.jars" />
139+
<path location="${scala-library.jar}(!META-INF/MANIFEST.MF,!library.properties)" />
140+
</pathconvert>
141+
</else></if>
142+
<split-path property="injars" prefix="-injars" path="${project.injars}" />
143+
<split-path property="outjars" prefix="-outjars" path="${shrinked.jar}" />
144+
<!-- set the android classpath object into a single property. -->
145+
<if condition="${uses.ramdisk}"><then>
146+
<pathconvert property="project.libraryjars">
147+
<path location="${scala-library.jar}(!META-INF/MANIFEST.MF,!library.properties)" />
148+
<path refid="android.target.classpath" />
149+
</pathconvert>
150+
</then><else>
151+
<pathconvert property="project.libraryjars">
152+
<path refid="android.target.classpath" />
153+
</pathconvert>
154+
</else></if>
155+
<split-path property="libraryjars" prefix="-libraryjars" path="${project.libraryjars}" />
156+
</else></if>
157+
<!-- Name of the application package extracted from manifest file -->
158+
<xpath input="AndroidManifest.xml" expression="/manifest/@package"
159+
output="manifest.package" />
160+
<copy file="${template.cfg}" tofile="${proguard.cfg}">
161+
<filterchain>
162+
<replacetokens>
163+
<token key="HEADER" value="${header}" />
164+
<token key="INJARS" value="${injars}" />
165+
<token key="OUTJARS" value="${outjars}" />
166+
<token key="LIBRARYJARS" value="${libraryjars}" />
167+
<token key="PACKAGENAME" value="${manifest.package}" />
168+
<token key="DEBUG" value="${debug.mode}" />
169+
<token key="RELEASE" value="${release.mode}" />
170+
</replacetokens>
171+
</filterchain>
172+
</copy>
173+
<if condition="${shrink.required}"><then>
174+
<proguard configuration="${proguard.cfg}" />
175+
</then></if>
176+
</target>
177+
178+
<!-- Macros -->
179+
180+
<macrodef name="generate-header">
181+
<attribute name="property" />
182+
<sequential>
183+
<dirname property="parentdir" file="${basedir}" />
184+
<pathconvert property="rel.template.cfg">
185+
<map from="${parentdir}${file.separator}" to="" />
186+
<path location="${template.cfg}" />
187+
</pathconvert>
188+
<property name="@{property}" value="# This file is automatically generated from ${rel.template.cfg}" />
189+
</sequential>
190+
</macrodef>
191+
192+
<!-- split 'path' into several lines starting with 'prefix' and save result in 'property' -->
193+
<macrodef name="split-path">
194+
<attribute name="property" />
195+
<attribute name="prefix" />
196+
<attribute name="path" />
197+
<sequential>
198+
<tempfile property="temp.file" destdir="${out.dir}" deleteonexit="true" />
199+
<echo message="@{path}" file="${temp.file}" />
200+
<loadfile srcfile="${temp.file}" property="@{property}.list">
201+
<filterchain>
202+
<replacestring from="${path.separator}" to="${line.separator}"/>
203+
<replaceregex pattern="(.*)" replace="@{prefix} \1" />
204+
</filterchain>
205+
</loadfile>
206+
<property name="@{property}" value="${@{property}.list}" />
207+
</sequential>
208+
</macrodef>
209+
210+
</project>

0 commit comments

Comments
 (0)