Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make pointer to new repository

  • Loading branch information...
commit 13a3e1234ea54dd6b00745d344a2ce1790273058 1 parent 3ebd2d1
Daniel Solano Gómez authored
Showing with 4 additions and 4,282 deletions.
  1. +0 −8 AndroidManifest.xml
  2. +4 −505 README.asciidoc
  3. +0 −18 ant.properties
  4. +0 −89 build-support/clojure-compile.clj
  5. +0 −12 build-support/clojure.properties.example
  6. +0 −137 build-support/clojure.xml
  7. +0 −85 build.xml
  8. +0 −20 proguard-project.txt
  9. +0 −40 proguard.cfg
  10. +0 −12 project.properties
  11. +0 −78 src/clojure/neko/_protocols/resolvable.clj
  12. +0 −35 src/clojure/neko/_utils.clj
  13. +0 −102 src/clojure/neko/activity.clj
  14. +0 −68 src/clojure/neko/compilation.clj
  15. +0 −180 src/clojure/neko/context.clj
  16. +0 −91 src/clojure/neko/dialog/alert.clj
  17. +0 −97 src/clojure/neko/find_view.clj
  18. +0 −130 src/clojure/neko/listeners/adapter_view.clj
  19. +0 −131 src/clojure/neko/listeners/dialog.clj
  20. +0 −53 src/clojure/neko/listeners/text_view.clj
  21. +0 −218 src/clojure/neko/listeners/view.clj
  22. +0 −65 src/clojure/neko/log.clj
  23. +0 −185 src/clojure/neko/threading.clj
  24. +0 −20 src/java/neko/threading/AsyncTask.java
  25. +0 −35 test/AndroidManifest.xml
  26. +0 −18 test/ant.properties
  27. +0 −142 test/build.xml
  28. +0 −20 test/proguard-project.txt
  29. +0 −40 test/proguard.cfg
  30. +0 −11 test/project.properties
  31. BIN  test/res/drawable-hdpi/icon.png
  32. BIN  test/res/drawable-ldpi/icon.png
  33. BIN  test/res/drawable-mdpi/icon.png
  34. +0 −13 test/res/layout/main.xml
  35. +0 −12 test/res/values/strings.xml
  36. +0 −24 test/src/clojure/com/sattvik/neko/tests/TestActivity.clj
  37. +0 −54 test/src/clojure/junit/assert.clj
  38. +0 −151 test/src/clojure/neko/activity_test.clj
  39. +0 −238 test/src/clojure/neko/context_test.clj
  40. +0 −189 test/src/clojure/neko/dialog/alert_test.clj
  41. +0 −151 test/src/clojure/neko/find_view_test.clj
  42. +0 −124 test/src/clojure/neko/listeners/adapter_view_test.clj
  43. +0 −119 test/src/clojure/neko/listeners/dialog_test.clj
  44. +0 −42 test/src/clojure/neko/listeners/text_view_test.clj
  45. +0 −132 test/src/clojure/neko/listeners/view_test.clj
  46. +0 −101 test/src/clojure/neko/log_test.clj
  47. +0 −30 test/src/clojure/neko/test_utils.clj
  48. +0 −257 test/src/clojure/neko/threading_test.clj
8 AndroidManifest.xml
View
@@ -1,8 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.sattvik.android_toolkit"
- android:versionCode="1"
- android:versionName="1.0">
- <uses-sdk android:minSdkVersion="7"
- android:targetSdkVersion="10"/>
-</manifest>
509 README.asciidoc
View
@@ -1,507 +1,6 @@
-Neko: The Clojure/Android Toolkit
-=================================
+Moved!
+======
Daniel Solano_Gómez
-Neko is a toolkit designed to make Android development using Clojure easier and
-more fun. It accomplishes this by making adding Clojure support to your
-Android project easy and providing functional wrappers and alternatives to
-Android’s Java API.
-
-Features
---------
-
-WARNING: Note that the libraries are under heavy development. APIs are subject
-to change. In particular, `neko.threading` will be changed.
-
-The toolkit comes as two components:
-
-. Simplified build support for Clojure using Android’s Ant-based build system,
- and
-
-. The following Clojure libraries:
-
- * `neko.compilation` helps set up dynamic compilation.
-
- * `neko.context` helps retrieve resources from the application’s context.
-
- * `neko.listeners` contains namespaces that take the tedium to adding
- callback code to various widgets.
-
- * `neko.log` interns functions that make logging from your code clean and
- simple.
-
- * `neko.threading` will contain utilities to manage asynchronous tasks and
- working with UI threads.
-
-Requirements
-------------
-
-Using Neko requires the following:
-
-Clojure 1.2 or newer::
- Clojure 1.2 works on Android 2.2 and newer. Clojure 1.3 and newer work on
- Android 2.3 and newer.
-+
-If you would like to use dynamic compilation with Android 2.3 and newer, use
-the Clojure available from the `android` branch from
-https://github.com/sattvik/clojure/tree/android[this repository on
- GitHub]. This branch is based off the latest Clojure development version.
-+
-If you would like to use dynamic compilation, but must support Android 2.1, you
-will need to use the version from branch `android-1.2.x`, available
-https://github.com/sattvik/clojure/tree/android-1.2.x[here]. This is based off
-of Clojure 1.2.1.
-
-Android SDK Tools::
- Neko has been developed with the latest revision of the Android SDK tools,
- and is compatible with r17 and up of the Android SDK.
-+
-WARNING: Revisions 14 and 17 of the Android SDK introduced changes in the Ant
-build system. Neko has been updated to use the build system in r17. You will
-probably need to change your project if you have been using an older version of
-Neko/SDK. For more detailed information, check the Android Tools Project site
-for information about the breaking changes in
-http://tools.android.com/recent/buildchangesinrevision14[r14] and
-http://tools.android.com/recent/dealingwithdependenciesinandroidprojects[r17].
-
-Android Platform SDK 7 (2.1/Eclair) or newer::
- In order to maintain backwards-compatibility, Neko does not support any APIs
- for newer versions of the platform.
-
-
-Getting started with Neko
--------------------------
-
-The following instructions should help you to add Clojure support to your
-project’s build and allow you to use the libraries within your application.
-
-=== 1. Install the Android SDK ===
-
-You can get this from https://developer.android.com/sdk/index.html[directly
-from Google]. You will need to be sure to also install a platform for
-development. The
-http://wiki.cyanogenmod.com/index.php?title=Howto:_Install_the_Android_SDK[CyanogenMod
-wiki] has some more detailed instructions.
-
-=== 2. Get Neko ===
-
-Just clone the repository to your computer:
-
-----
-% git clone https://github.com/sattvik/neko.git
-----
-
-If all went well, Neko should now be in a directory called `neko`.
-
-
-=== 3. Add Clojure ===
-
-Now, go into the `neko` directory and created a directory called `libs`. Copy
-`clojure.jar` into that directory. If you don't already have Clojure
-installed, http://clojure.org/downloads[you can download it from the project’s
-page].
-
-=== 4. Create your project ===
-
-Next, you will need to create a new Android project using the `android` command
-from the Android SDK, as follows:
-
-----
-% android create project -p <directory> -t <target> -k <package> -a <activity>
-----
-
-The arguments to this command are:
-
-`<directory>`::
-
- The name of the directory for your new project.
-
-`<target>`::
-
- The target API version you will use for development. For example, you could
- use `android-15` to target the Android 4.0.3 platform. You can see a list of
- targets available by running `android list targets`.
-
-`<package>`::
-
- This unique string will be used to identify your application. You should follow the
- http://www.oracle.com/technetwork/java/codeconventions-135099.html[package
- naming conventions]. An example may be `com.example.cool_clojure_app`.
-
-`<activity>`::
-
- This is the name of a class that will be the entry point of your application.
-
-
-Once you run this, you will see a bunch of output as the SDK generates your
-project, for example:
-
-----
-% android create project -p hello -k com.example.hello_clojure -a HelloActivity -t android-15
-Created project directory: hello
-Created directory /home/dan/devel/android/hello/src/com/example/hello_clojure
-Added file hello/src/com/example/hello_clojure/HelloActivity.java
-Created directory /home/dan/devel/android/hello/res
-Created directory /home/dan/devel/android/hello/bin
-Created directory /home/dan/devel/android/hello/libs
-Created directory /home/dan/devel/android/hello/res/values
-Added file hello/res/values/strings.xml
-Created directory /home/dan/devel/android/hello/res/layout
-Added file hello/res/layout/main.xml
-Created directory /home/dan/devel/android/hello/res/drawable-hdpi
-Created directory /home/dan/devel/android/hello/res/drawable-mdpi
-Created directory /home/dan/devel/android/hello/res/drawable-ldpi
-Added file hello/AndroidManifest.xml
-Added file hello/build.xml
-Added file hello/proguard-project.txt
-----
-
-=== 5. Add Neko as a library for your project ===
-
-Change into the new directory for your project and calculate the relative path
-to the directory where you cloned Neko. Now, run the following command:
-
-----
-% android update project -p . -l <../relative/path/to/neko>
-----
-
-For example:
-
-----
-% cd hello
-% android update project -p . -l ../neko
-Resolved location of library project to: /home/user/work/neko
-Updated project.properties
-Updated local.properties
-Updated file ./proguard-project.txt
-----
-
-=== 6. Get Ant to build your Clojure code ===
-
-To enable Neko’s build support for Clojure, you will need to make two
-modifications to the `build.xml` file in your project directory.
-
-. You must add a line to similar to the following *before the line with `<import file="${sdk.dir}/tools/ant/build.xml" />`*.
-+
-----
-<import file="/path/to/neko/build-support/clojure.xml"/>
-----
-+
-The important thing is that the value of the `file` attribute should resolve to
-the `clojure.xml` in the `build-support` directory of this repository. It may
-be either a relative or absolute path.
-
-. You must find the line that reads `<!-- version-tag: 1 -->` and change the
- `1` to `custom`. If you do not do this, Android may overwrite your changes.
-
-=== 7. Get rid of that Java file ===
-
-You may have noticed that when you created the project file, Android generated
-a Java file corresponding to the package and activity name. Delete it. For
-example:
-
-----
-% rm -r src/com
-----
-
-=== 8. Create a source directory for you Clojure files ===
-
-By default, Neko looks in `src/clojure`.
-
-----
-% mkdir src/clojure
-----
-
-=== 9. Write your first Android application in Clojure ===
-
-For replicate the default activity that the SDK created in Clojure, you will
-need to create a source file with the same namespace as the original file.
-For example, given the package `com.example.hello_clojure` and the activity
-`HelloActivity`, you would create the file
-`src/clojure/com/example/hello_clojure/HelloActivity.clj` as follows:
-
-[source,lisp]
-----
-(ns com.example.hello_clojure.HelloActivity
- (:gen-class :main false
- :extends android.app.Activity
- :exposes-methods {onCreate superOnCreate})
- (:import [com.example.hello_clojure R$layout]))
-
-(defn -onCreate
- [this bundle]
- (doto this
- (.superOnCreate bundle)
- (.setContentView R$layout/main)))
-----
-
-As a gist: https://gist.github.com/2361385[]
-
-=== 10. Build and run it ===
-
-You can now run and install the application to a running emulator or a
-connected device using:
-
-----
-% ant debug install
-----
-
-If all went well, you should be able to find your application in the launcher.
-When you run it, after several seconds, you should see a simple `Hello World'
-appear.
-
-=== 11. Make something wonderful ===
-
-From this point on, it is up to you to create something wonderful.
-
-
-Advanced topics
----------------
-
-Here are some more things you can do with Neko:
-
-=== `clojure.properties` ===
-
-You can place a `clojure.properties` file in the `build-support` directory from
-Neko (where `clojure.xml` lives). This file will be sourced and used in any
-project in which you have enabled Clojure build support.
-
-=== Reflection warnings ===
-
-To enable reflection warnings during compilation, simply set the
-`clojure.warn.reflection` property to `true`. This is something that might be
-good to put in that `clojure.properties` file.
-
-=== Mixed Java/Clojure projects ===
-
-Neko will build all Java sources you have placed in `src/java` before any
-Clojure sources.
-
-
-Legal information
------------------
-
-Copyright © 2011 Sattvik Software & Technology Resources, Ltd. Co. +
-All rights reserved.
-
-=== Eclipse Public License - v 1.0 ===
-
-THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC
-LICENSE (“AGREEMENT”). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE
-PROGRAM CONSTITUTES RECIPIENT’S ACCEPTANCE OF THIS AGREEMENT.
-
-==== 1. DEFINITIONS ====
-
-“Contribution” means:
-
-a. in the case of the initial Contributor, the initial
- code and documentation distributed under this Agreement, and
-
-b. in the case of each subsequent Contributor:
-
- i) changes to the Program, and
-
- ii) additions to the Program;
-+
-where such changes and/or additions to the Program originate from and are
-distributed by that particular Contributor. A Contribution ‘originates’ from a
-Contributor if it was added to the Program by such Contributor itself or anyone
-acting on such Contributor’s behalf. Contributions do not include additions to
-the Program which: (i) are separate modules of software distributed in
-conjunction with the Program under their own license agreement, and (ii) are
-not derivative works of the Program.
-
-“Contributor” means any person or entity that distributes the Program.
-
-“Licensed Patents” mean patent claims licensable by a Contributor which are
-necessarily infringed by the use or sale of its Contribution alone or when
-combined with the Program.
-
-“Program” means the Contributions distributed in accordance with this
-Agreement.
-
-“Recipient” means anyone who receives the Program under this Agreement,
-including all Contributors.
-
-==== 2. GRANT OF RIGHTS ====
-
-a. Subject to the terms of this Agreement, each Contributor hereby grants
- Recipient a non-exclusive, worldwide, royalty-free copyright license to
- reproduce, prepare derivative works of, publicly display, publicly perform,
- distribute and sublicense the Contribution of such Contributor, if any, and
- such derivative works, in source code and object code form.
-
-b. Subject to the terms of this Agreement, each Contributor hereby grants
- Recipient a non-exclusive, worldwide, royalty-free patent license under
- Licensed Patents to make, use, sell, offer to sell, import and otherwise
- transfer the Contribution of such Contributor, if any, in source code and
- object code form. This patent license shall apply to the combination of the
- Contribution and the Program if, at the time the Contribution is added by
- the Contributor, such addition of the Contribution causes such combination
- to be covered by the Licensed Patents. The patent license shall not apply to
- any other combinations which include the Contribution. No hardware per se is
- licensed hereunder.
-
-c. Recipient understands that although each Contributor grants the licenses to
- its Contributions set forth herein, no assurances are provided by any
- Contributor that the Program does not infringe the patent or other
- intellectual property rights of any other entity. Each Contributor disclaims
- any liability to Recipient for claims brought by any other entity based on
- infringement of intellectual property rights or otherwise. As a condition to
- exercising the rights and licenses granted hereunder, each Recipient hereby
- assumes sole responsibility to secure any other intellectual property rights
- needed, if any. For example, if a third party patent license is required to
- allow Recipient to distribute the Program, it is Recipient’s responsibility
- to acquire that license before distributing the Program.
-
-d. Each Contributor represents that to its knowledge it has sufficient
- copyright rights in its Contribution, if any, to grant the copyright license
- set forth in this Agreement.
-
-==== 3. REQUIREMENTS ====
-
-A Contributor may choose to distribute the Program in object code form under
-its own license agreement, provided that:
-
-a. it complies with the terms and conditions of this Agreement; and
-
-b. its license agreement:
-
- i) effectively disclaims on behalf of all Contributors all warranties and
- conditions, express and implied, including warranties or conditions of
- title and non-infringement, and implied warranties or conditions of
- merchantability and fitness for a particular purpose;
-
- ii) effectively excludes on behalf of all Contributors all liability for
- damages, including direct, indirect, special, incidental and
- consequential damages, such as lost profits;
-
- iii) states that any provisions which differ from this Agreement are offered
- by that Contributor alone and not by any other party; and
-
- iv) states that source code for the Program is available from such
- Contributor, and informs licensees how to obtain it in a reasonable
- manner on or through a medium customarily used for software
- exchange.
-
-When the Program is made available in source code form:
-
-a. it must be made available under this Agreement; and
-
-b. a copy of this Agreement must be included with each copy of the Program.
-
-Contributors may not remove or alter any copyright notices contained within the
-Program.
-
-Each Contributor must identify itself as the originator of its Contribution, if
-any, in a manner that reasonably allows subsequent Recipients to identify the
-originator of the Contribution.
-
-==== 4. COMMERCIAL DISTRIBUTION ====
-
-Commercial distributors of software may accept certain responsibilities with
-respect to end users, business partners and the like. While this license is
-intended to facilitate the commercial use of the Program, the Contributor who
-includes the Program in a commercial product offering should do so in a manner
-which does not create potential liability for other Contributors. Therefore, if
-a Contributor includes the Program in a commercial product offering, such
-Contributor (“Commercial Contributor”) hereby agrees to defend and indemnify
-every other Contributor (“Indemnified Contributor”) against any losses, damages
-and costs (collectively “Losses”) arising from claims, lawsuits and other legal
-actions brought by a third party against the Indemnified Contributor to the
-extent caused by the acts or omissions of such Commercial Contributor in
-connection with its distribution of the Program in a commercial product
-offering. The obligations in this section do not apply to any claims or Losses
-relating to any actual or alleged intellectual property infringement. In order
-to qualify, an Indemnified Contributor must: a) promptly notify the Commercial
-Contributor in writing of such claim, and b) allow the Commercial Contributor
-to control, and cooperate with the Commercial Contributor in, the defense and
-any related settlement negotiations. The Indemnified Contributor may
-participate in any such claim at its own expense.
-
-For example, a Contributor might include the Program in a commercial product
-offering, Product X. That Contributor is then a Commercial Contributor. If that
-Commercial Contributor then makes performance claims, or offers warranties
-related to Product X, those performance claims and warranties are such
-Commercial Contributor’s responsibility alone. Under this section, the
-Commercial Contributor would have to defend claims against the other
-Contributors related to those performance claims and warranties, and if a court
-requires any other Contributor to pay any damages as a result, the Commercial
-Contributor must pay those damages.
-
-==== 5. NO WARRANTY ====
-
-EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS
-PROVIDED ON AN “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS
-OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION,
-ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY
-OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely
-responsible for determining the appropriateness of using and
-distributing the Program and assumes all risks associated with its
-exercise of rights under this Agreement , including but not limited to
-the risks and costs of program errors, compliance with applicable laws,
-damage to or loss of data, programs or equipment, and unavailability or
-interruption of operations.
-
-==== 6. DISCLAIMER OF LIABILITY ====
-
-EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT
-NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT,
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING
-WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF
-LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR
-DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
-HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
-
-==== 7. GENERAL ====
-
-If any provision of this Agreement is invalid or unenforceable under
-applicable law, it shall not affect the validity or enforceability of
-the remainder of the terms of this Agreement, and without further action
-by the parties hereto, such provision shall be reformed to the minimum
-extent necessary to make such provision valid and enforceable.
-
-If Recipient institutes patent litigation against any entity
-(including a cross-claim or counterclaim in a lawsuit) alleging that the
-Program itself (excluding combinations of the Program with other
-software or hardware) infringes such Recipient’s patent(s), then such
-Recipient’s rights granted under Section 2(b) shall terminate as of the
-date such litigation is filed.
-
-All Recipient’s rights under this Agreement shall terminate if it
-fails to comply with any of the material terms or conditions of this
-Agreement and does not cure such failure in a reasonable period of time
-after becoming aware of such noncompliance. If all Recipient’s rights
-under this Agreement terminate, Recipient agrees to cease use and
-distribution of the Program as soon as reasonably practicable. However,
-Recipient’s obligations under this Agreement and any licenses granted by
-Recipient relating to the Program shall continue and survive.
-
-Everyone is permitted to copy and distribute copies of this
-Agreement, but in order to avoid inconsistency the Agreement is
-copyrighted and may only be modified in the following manner. The
-Agreement Steward reserves the right to publish new versions (including
-revisions) of this Agreement from time to time. No one other than the
-Agreement Steward has the right to modify this Agreement. The Eclipse
-Foundation is the initial Agreement Steward. The Eclipse Foundation may
-assign the responsibility to serve as the Agreement Steward to a
-suitable separate entity. Each new version of the Agreement will be
-given a distinguishing version number. The Program (including
-Contributions) may always be distributed subject to the version of the
-Agreement under which it was received. In addition, after a new version
-of the Agreement is published, Contributor may elect to distribute the
-Program (including its Contributions) under the new version. Except as
-expressly stated in Sections 2(a) and 2(b) above, Recipient receives no
-rights or licenses to the intellectual property of any Contributor under
-this Agreement, whether expressly, by implication, estoppel or
-otherwise. All rights in the Program not expressly granted under this
-Agreement are reserved.
-
-This Agreement is governed by the laws of the State of New York and
-the intellectual property laws of the United States of America. No party
-to this Agreement will bring a legal action under this Agreement more
-than one year after the cause of action arose. Each party waives its
-rights to a jury trial in any resulting litigation.
-
-// vim:set spell ft=asciidoc:
+Neko has moved to the new Clojure/Android organisation at
+https://github.com/clojure-android/neko[].
18 ant.properties
View
@@ -1,18 +0,0 @@
-# This file is used to override default values used by the Ant build system.
-#
-# This file must be checked in Version Control Systems, as it is
-# integral to the build system of your project.
-
-# This file is only used by the Ant script.
-
-# You can use this to override default values such as
-# 'source.dir' for the location of your java source folder and
-# 'out.dir' for the location of your output folder.
-
-# You can also use it define how the release builds are signed by declaring
-# the following properties:
-# 'key.store' for the location of your keystore and
-# 'key.alias' for the name of the key to use.
-# The password will be asked during the build when you use the 'release' target.
-
-source.dir=src/java
89 build-support/clojure-compile.clj
View
@@ -1,89 +0,0 @@
-; Copyright © 2011 Sattvik Software & Technology Resources, Ltd. Co.
-; All rights reserved.
-;
-; This program and the accompanying materials are made available under the
-; terms of the Eclipse Public License v1.0 which accompanies this distribution,
-; and is available at <http://www.eclipse.org/legal/epl-v10.html>.
-;
-; By using this software in any fashion, you are agreeing to be bound by the
-; terms of this license. You must not remove this notice, or any other, from
-; this software.
-
-(use 'clojure.java.io)
-(use 'clojure.stacktrace)
-(import '[java.io File PushbackReader]
- '[java.util.regex Matcher Pattern])
-
-(set! *warn-on-reflection*
- (Boolean/valueOf (System/getProperty "clojure.warn.reflection" "false")))
-
-(defn find-clojure-files
- "Finds all Clojure source files in a given directory."
- [path]
- (let [file (as-file path)]
- (cond
- (.isDirectory file) (mapcat find-clojure-files (.listFiles file))
- (and (.isFile file)
- (.. file getName (endsWith ".clj"))) [file]
- :else nil)))
-
-(defn file->ns
- "Looks for the namespace in a Clojure source file."
- [file]
- (binding [*in* (PushbackReader. (reader file))]
- (let [next-form (fn [] (read *in* false ::eof))]
- (loop [form (next-form)]
- (cond
- (= ::eof form)
- nil
- (and (list? form)
- (= 'ns (first form)))
- (second form)
- :else
- (recur (next-form)))))))
-
-(def compiled-ns (atom #{}))
-
-(defn compile-ns
- "Compiles a namespace."
- ([ns failed-ns]
- (when-not (@compiled-ns ns)
- (try
- (println (format "Compiling %s…" ns))
- (compile ns)
- (swap! compiled-ns conj ns)
- true
- (catch Exception e
- (let [msg (.getMessage e)
- cnfe-pattern #".*java\.lang\.ClassNotFoundException: ([a-zA-z0-9-_.]+)(, compiling:| )\(.*:\d+\)$"]
- (if-let [matches (re-matches cnfe-pattern msg)]
- (let [not-found-ns (symbol (matches 1))]
- (println (format "Dependency failure detected, will try to compile %s." not-found-ns))
- (if (failed-ns not-found-ns)
- (throw e)
- (if (compile-ns not-found-ns (conj failed-ns ns))
- (do
- (println "Failure resolved.")
- (compile-ns ns failed-ns))
- (throw e))))
- (throw e)))))))
- ([ns]
- (compile-ns ns #{})))
-
-(defn compile-dir
- "Compiles all Clojure files in the given directory."
- [dir]
- (binding [*compile-path* (System/getProperty "clojure.compile.path")]
- (->> (find-clojure-files dir)
- (map file->ns)
- (remove nil?)
- (map compile-ns)
- (dorun))))
-
-(defn args->dirs
- "Splits any path arguments into directories"
- [args]
- (let [split-path (fn [^String arg] (seq (.split arg (Pattern/quote File/pathSeparator))))]
- (flatten (map split-path args))))
-
-(dorun (map compile-dir (args->dirs *command-line-args*)))
12 build-support/clojure.properties.example
View
@@ -1,12 +0,0 @@
-# This file will be sourced every time the ‘clojure.xml’ is imported into your
-# build. You can set properties here that will affect all of your Android
-# projects that include Clojure support.
-#
-# Probably, the most important property to set is ‘clojure.jar’, which will
-# set up the default Clojure libray to use during compilation. Note that you
-# still need to include a Clojure JAR in the ‘libs’ directory of your main
-# application. It is library and test projects that really need this property.
-
-clojure.jar=/path/to/clojure-nosrc-1.2.0.jar
-
-# vim:set ft=jproperties:
137 build-support/clojure.xml
View
@@ -1,137 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<!--
- Copyright © 2011 Sattvik Software & Technology Resources, Ltd. Co.
- All rights reserved.
-
- This program and the accompanying materials are made available under the
- terms of the Eclipse Public License v1.0 which accompanies this distribution,
- and is available at <http://www.eclipse.org/legal/epl-v10.html>.
-
- By using this software in any fashion, you are agreeing to be bound by the
- terms of this license. You must not remove this notice, or any other, from
--->
-
-<project name="android-clojure-support" basedir=".">
- <dirname property="android-clojure-support.dir" file="${ant.file.android-clojure-support}"/>
-
- <property file="${android-clojure-support.dir}/clojure.properties"/>
-
- <!-- Modified input directories -->
- <property name="source.dir" value="src/java" />
- <property name="clojure.source.dir" value="src/clojure" />
- <property name="clojure.source.absolute.dir" location="${clojure.source.dir}" />
-
- <!-- Clojure output directories -->
- <property name="out.dir" value="bin"/>
- <property name="clojure.out.dir" value="${out.dir}" />
- <property name="clojure.out.absolute.dir" location="${clojure.out.dir}" />
- <property name="clojure.out.classes.dir" value="${clojure.out.absolute.dir}/classes" />
- <property name="clojure.out.classes.absolute.dir" location="${clojure.out.classes.dir}" />
-
- <!-- Ensure that the Java source directory exists since Git does not
- preserve empty directories -->
- <target name="-pre-build">
- <mkdir dir="${source.absolute.dir}"/>
- <mkdir dir="${clojure.out.classes.absolute.dir}"/>
- </target>
-
- <!-- Compiles this project's .java files into .class files. -->
- <target name="-compile" depends="-build-setup, -pre-build, -code-gen, -pre-compile">
- <do-only-if-manifest-hasCode elseText="hasCode = false. Skipping...">
- <!-- If android rules are used for a test project, its classpath should include
- tested project's location -->
- <condition property="extensible.classpath"
- value="${tested.project.absolute.dir}/bin/classes"
- else=".">
- <isset property="tested.project.absolute.dir" />
- </condition>
- <condition property="extensible.libs.classpath"
- value="${tested.project.absolute.dir}/${jar.libs.dir}"
- else="${jar.libs.dir}">
- <isset property="tested.project.absolute.dir" />
- </condition>
- <condition property="clojure.warn.reflection.env"
- value="${clojure.warn.reflection}"
- else="false">
- <isset property="clojure.warn.reflection"/>
- </condition>
- <javac encoding="${java.encoding}"
- source="${java.source}" target="${java.target}"
- debug="true" extdirs="" includeantruntime="false"
- destdir="${out.classes.absolute.dir}"
- bootclasspathref="android.target.classpath"
- verbose="${verbose}"
- classpath="${extensible.classpath}"
- classpathref="project.libraries.jars"
- fork="${need.javac.fork}">
- <src path="${source.absolute.dir}" />
- <src path="${gen.absolute.dir}" />
- <classpath>
- <fileset dir="${extensible.libs.classpath}" includes="*.jar" />
- </classpath>
- <compilerarg line="${java.compilerargs}" />
- </javac>
- <java classname="clojure.main"
- classpath="${clojure.jar}"
- classpathref="android.target.classpath"
- fork="true"
- failonerror="true">
- <sysproperty key="clojure.compile.path" value="${clojure.out.classes.absolute.dir}"/>
- <sysproperty key="clojure.warn.reflection" value="${clojure.warn.reflection.env}"/>
- <classpath>
- <pathelement path="${extensible.classpath}"/>
- <pathelement path="${clojure.source.absolute.dir}"/>
- <path refid="project.libraries.jars"/>
- <fileset dir="${extensible.libs.classpath}" includes="*.jar" />
- <pathelement path="${clojure.out.classes.absolute.dir}"/>
- </classpath>
- <arg file="${android-clojure-support.dir}/clojure-compile.clj"/>
- <arg path="${clojure.source.absolute.dir}"/>
- </java>
- <!-- if the project is a library then we generate a jar file -->
- <if condition="${project.is.library}">
- <then>
- <echo>Creating library output jar file...</echo>
- <property name="out.library.jar.file" location="${out.absolute.dir}/classes.jar" />
- <if>
- <condition>
- <length string="${android.package.excludes}" trim="true" when="greater" length="0" />
- </condition>
- <then>
- <echo>Custom jar packaging exclusion: ${android.package.excludes}</echo>
- </then>
- </if>
-
- <propertybyreplace name="manifest.package.path" input="${manifest.package}" replace="." with="/" />
-
- <jar destfile="${out.library.jar.file}">
- <fileset dir="${out.classes.absolute.dir}"
- includes="**/*.class"
- excludes="${manifest.package.path}/R.class ${manifest.package.path}/R$*.class ${manifest.package.path}/Manifest.class ${manifest.package.path}/Manifest$*.class ${manifest.package.path}/BuildConfig.class"/>
- <fileset dir="${source.absolute.dir}" excludes="**/*.java ${android.package.excludes}" />
- </jar>
- </then>
- </if>
-
- <!-- if the project is instrumented, intrument the classes -->
- <if condition="${build.is.instrumented}">
- <then>
- <echo>Instrumenting classes from ${out.absolute.dir}/classes...</echo>
- <!-- It only instruments class files, not any external libs -->
- <emma enabled="true">
- <instr verbosity="${verbosity}"
- mode="overwrite"
- instrpath="${out.absolute.dir}/classes"
- outdir="${out.absolute.dir}/classes">
- <filter excludes="${manifest.package}.R,${manifest.package}.R$$*,${manifest.package}.BuildConfig" />
- <filter value="${emma.filter}" />
- </instr>
- </emma>
- </then>
- </if>
- </do-only-if-manifest-hasCode>
- </target>
-</project>
-
-<!-- vim:set ts=4 sw=4 et: -->
85 build.xml
View
@@ -1,85 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project name="Neko" default="help">
-
- <!-- The local.properties file is created and updated by the 'android' tool.
- It contains the path to the SDK. It should *NOT* be checked into
- Version Control Systems. -->
- <property file="local.properties" />
-
- <!-- The ant.properties file can be created by you. It is only edited by the
- 'android' tool to add properties to it.
- This is the place to change some Ant specific build properties.
- Here are some properties you may want to change/update:
-
- source.dir
- The name of the source directory. Default is 'src'.
- out.dir
- The name of the output directory. Default is 'bin'.
-
- For other overridable properties, look at the beginning of the rules
- files in the SDK, at tools/ant/build.xml
-
- Properties related to the SDK location or the project target should
- be updated using the 'android' tool with the 'update' action.
-
- This file is an integral part of the build system for your
- application and should be checked into Version Control Systems.
-
- -->
- <property file="ant.properties" />
-
- <!-- The project.properties file is created and updated by the 'android'
- tool, as well as ADT.
-
- This contains project specific properties such as project target, and library
- dependencies. Lower level build properties are stored in ant.properties
- (or in .classpath for Eclipse projects).
-
- This file is an integral part of the build system for your
- application and should be checked into Version Control Systems. -->
- <loadproperties srcFile="project.properties" />
-
- <!-- quick check on sdk.dir -->
- <fail
- message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var"
- unless="sdk.dir"
- />
-
- <!--
- Import per project custom build rules if present at the root of the project.
- This is the place to put custom intermediary targets such as:
- -pre-build
- -pre-compile
- -post-compile (This is typically used for code obfuscation.
- Compiled code location: ${out.classes.absolute.dir}
- If this is not done in place, override ${out.dex.input.absolute.dir})
- -post-package
- -post-build
- -pre-clean
- -->
- <import file="custom_rules.xml" optional="true" />
-
- <import file="build-support/clojure.xml" />
-
- <!-- Import the actual build file.
-
- To customize existing targets, there are two options:
- - Customize only one target:
- - copy/paste the target into this file, *before* the
- <import> task.
- - customize it to your needs.
- - Customize the whole content of build.xml
- - copy/paste the content of the rules files (minus the top node)
- into this file, replacing the <import> task.
- - customize to your needs.
-
- ***********************
- ****** IMPORTANT ******
- ***********************
- In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
- in order to avoid having your file be overridden by tools such as "android update project"
- -->
- <!-- version-tag: custom -->
- <import file="${sdk.dir}/tools/ant/build.xml" />
-
-</project>
20 proguard-project.txt
View
@@ -1,20 +0,0 @@
-# To enable ProGuard in your project, edit project.properties
-# to define the proguard.config property as described in that file.
-#
-# Add project specific ProGuard rules here.
-# By default, the flags in this file are appended to flags specified
-# in ${sdk.dir}/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 *;
-#}
40 proguard.cfg
View
@@ -1,40 +0,0 @@
--optimizationpasses 5
--dontusemixedcaseclassnames
--dontskipnonpubliclibraryclasses
--dontpreverify
--verbose
--optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-
--keep public class * extends android.app.Activity
--keep public class * extends android.app.Application
--keep public class * extends android.app.Service
--keep public class * extends android.content.BroadcastReceiver
--keep public class * extends android.content.ContentProvider
--keep public class * extends android.app.backup.BackupAgentHelper
--keep public class * extends android.preference.Preference
--keep public class com.android.vending.licensing.ILicensingService
-
--keepclasseswithmembernames class * {
- native <methods>;
-}
-
--keepclasseswithmembers class * {
- public <init>(android.content.Context, android.util.AttributeSet);
-}
-
--keepclasseswithmembers class * {
- public <init>(android.content.Context, android.util.AttributeSet, int);
-}
-
--keepclassmembers class * extends android.app.Activity {
- public void *(android.view.View);
-}
-
--keepclassmembers enum * {
- public static **[] values();
- public static ** valueOf(java.lang.String);
-}
-
--keep class * implements android.os.Parcelable {
- public static final android.os.Parcelable$Creator *;
-}
12 project.properties
View
@@ -1,12 +0,0 @@
-# This file is automatically generated by Android Tools.
-# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
-#
-# This file must be checked in Version Control Systems.
-#
-# To customize properties used by the Ant build system use,
-# "ant.properties", and override values to adapt the script to your
-# project structure.
-
-android.library=true
-# Project target.
-target=android-7
78 src/clojure/neko/_protocols/resolvable.clj
View
@@ -1,78 +0,0 @@
-; Copyright © 2011 Sattvik Software & Technology Resources, Ltd. Co.
-; All rights reserved.
-;
-; This program and the accompanying materials are made available under the
-; terms of the Eclipse Public License v1.0 which accompanies this distribution,
-; and is available at <http://www.eclipse.org/legal/epl-v10.html>.
-;
-; By using this software in any fashion, you are agreeing to be bound by the
-; terms of this license. You must not remove this notice, or any other, from
-; this software.
-
-(ns neko.-protocols.resolvable
- "Home of the Resolvable protocol and related utilities."
- {:author "Daniel Solano Gómez"}
- (:import android.content.Context))
-
-(defn- resolve-from-keyword
- "Resolves a resource reprensented as a keyword."
- [context type name]
- {:pre [(instance? Context context)
- (keyword? type)
- (keyword? name)]
- :post [(integer? %)]}
- (let [package (or (namespace name) (.getPackageName ^Context context))
- type (clojure.core/name type)
- name (.. (clojure.core/name name) (replace \- \_) (replace \. \_))]
- (try
- (let [class (Class/forName (str package ".R$" type))
- field (.getField class name)]
- (.getInt field nil))
- (catch ClassNotFoundException _
- (throw (IllegalArgumentException.
- (format "Could not find class corresponding to '%s.R.%s'"
- package
- type))))
- (catch NoSuchFieldException _
- (throw (IllegalArgumentException.
- (format "Resource not found: '%s.R.%s.%s'"
- package
- type
- name)))))))
-
-(defprotocol Resolvable
- "Protocol for resolving a resource given some sort of id, a context, and a
- type."
- (resolve-it [id context type])
- (resolve-id [id context])
- (resolve-string [id context])
- (resolve-layout [id context]))
-
-(extend-protocol Resolvable
- Integer
- (resolve-it [id _1 _2] id)
- (resolve-id [id _] id)
- (resolve-string [id _] id)
- (resolve-layout [id _] id)
-
- Long
- (resolve-it [id _1 _2] (.intValue id))
- (resolve-id [id _] (.intValue id))
- (resolve-string [id _] (.intValue id))
- (resolve-layout [id _] (.intValue id))
-
- clojure.lang.Keyword
- (resolve-it
- [name context type] (resolve-from-keyword context type name))
- (resolve-id
- [name context] (resolve-from-keyword context :id name))
- (resolve-string
- [name context] (resolve-from-keyword context :string name))
- (resolve-layout
- [name context] (resolve-from-keyword context :layout name)))
-
-(defn resolvable?
- "Determines whether the argument represents an argument that can be resolved
- as a resource."
- [x]
- (satisfies? Resolvable x))
35 src/clojure/neko/_utils.clj
View
@@ -1,35 +0,0 @@
-; Copyright © 2011 Sattvik Software & Technology Resources, Ltd. Co.
-; All rights reserved.
-;
-; This program and the accompanying materials are made available under the
-; terms of the Eclipse Public License v1.0 which accompanies this distribution,
-; and is available at <http://www.eclipse.org/legal/epl-v10.html>.
-;
-; By using this software in any fashion, you are agreeing to be bound by the
-; terms of this license. You must not remove this notice, or any other, from
-; this software.
-
-(ns neko.-utils
- "Internal utilities used by Neko, not intended for external consumption."
- {:author "Daniel Solano Gómez"})
-
-(defn static-field-value
- "Takes a keyword and converts it to a field name by getting the name from the
- keyword, converting all hypens to underscores, capitalizing all letters, and
- applying the transformation function."
- ([^Class class field xform]
- {:pre [(class? class)
- (keyword? field)
- (fn? xform)]}
- (let [field (.. (name field) (replace \- \_) toUpperCase)
- field ((fn [x] {:post [(string? %)]} (xform x)) field)
- field (.getField class ^String field)]
- (.get field nil)))
- ([class field]
- (static-field-value class field identity)))
-
-(defn integer-or-keyword?
- "Convenient method for testing if the argument is an integer or a keyword."
- [x]
- (or (integer? x)
- (keyword? x)))
102 src/clojure/neko/activity.clj
View
@@ -1,102 +0,0 @@
-; Copyright © 2011 Sattvik Software & Technology Resources, Ltd. Co.
-; All rights reserved.
-;
-; This program and the accompanying materials are made available under the
-; terms of the Eclipse Public License v1.0 which accompanies this distribution,
-; and is available at <http://www.eclipse.org/legal/epl-v10.html>.
-;
-; By using this software in any fashion, you are agreeing to be bound by the
-; terms of this license. You must not remove this notice, or any other, from
-; this software.
-
-(ns neko.activity
- "Utilities to aid in working with an activity."
- {:author "Daniel Solano Gómez"}
- (:import android.app.Activity
- android.view.View)
- (:require [neko.context :as context])
- (:use neko.-protocols.resolvable
- neko.-utils))
-
-(def
- ^{:doc "The current activity to operate on."
- :dynamic true}
- *activity*)
-
-(defmacro with-activity
- "Evaluates body such that both *activity* and *context* are bound to the given activiy."
- [activity & body]
- `(let [activity# ~activity]
- (binding [context/*context* activity#
- *activity* activity#]
- ~@body)))
-
-(defn activity?
- "Determines whether the argument is an instance of Activity."
- [x]
- (instance? Activity x))
-
-(defn has-*activity*?
- "Ensures that the calling context has a valid *activity* var."
- []
- (and (bound? #'*activity*)
- (activity? *activity*)))
-
-(defn set-content-view!
- "Sets the content for the activity. The view may be one of:
-
- + A view object, which will be used directly
- + An integer presumed to be a valid layout ID
- + A keyword used to resolve to a layout ID using
- (neko.context/resolve-resource)"
- ([view]
- {:pre [(or (instance? View view)
- (resolvable? view))]}
- (set-content-view! *activity* view))
- ([^Activity activity view]
- {:pre [(activity? activity)
- (or (instance? View view)
- (resolvable? view))]}
- (cond
- (instance? View view)
- (.setContentView activity ^View view)
- (integer? view)
- (.setContentView activity ^Integer view)
- :else
- (.setContentView activity ^Integer (resolve-layout view activity)))))
-
-(defn request-window-features!
- "Requests the given features for the activity. The features should be
- keywords such as :no-title or :indeterminate-progress corresponding
- FEATURE_NO_TITLE and FEATURE_INDETERMINATE_PROGRESS, respectively. Returns a
- sequence of boolean values corresponding to each feature, where a true value
- indicates the requested feature is supported and now enabled.
-
- If within a with-activity form, supplying an activity as the first argument
- is not necessary.
-
- This function should be called before set-content-view!."
- {:arglists '([& features] [activity & features])}
- [activity & features]
- {:pre [(or (activity? activity)
- (and (keyword? activity)
- (has-*activity*?)))
- (every? keyword? features)]
- :post [%
- (every? (fn [x] (instance? Boolean x)) %)]}
- (let [[^Activity activity features]
- (if (instance? Activity activity)
- [activity features]
- [*activity* (cons activity features)])
- keyword->int (fn [k]
- (static-field-value android.view.Window
- k
- #(str "FEATURE_" %)))
- request-feature (fn [k]
- (try
- (.requestWindowFeature activity (keyword->int k))
- (catch NoSuchFieldException _
- (throw (IllegalArgumentException.
- (format "‘%s’ is not a valid feature."
- k))))))]
- (doall (map request-feature features))))
68 src/clojure/neko/compilation.clj
View
@@ -1,68 +0,0 @@
-; Copyright © 2011 Sattvik Software & Technology Resources, Ltd. Co.
-; All rights reserved.
-;
-; This program and the accompanying materials are made available under the
-; terms of the Eclipse Public License v1.0 which accompanies this distribution,
-; and is available at <http://www.eclipse.org/legal/epl-v10.html>.
-;
-; By using this software in any fashion, you are agreeing to be bound by the
-; terms of this license. You must not remove this notice, or any other, from
-; this software.
-
-(ns neko.compilation
- "Utility functions for managing the compilation environment when using
- version of Clojure that supports dynamic compilation on the Dalvik virtual
- machine.
-
- To use this namespace, you need to call init with a context, such as an
- activity object. This will create a cache directory where temporary files
- will be placed and will set the 'clojure.compile.path' system property and
- the '*compile-path*' var. If the cache directory already exists, it will be
- cleaned out.
-
- Note that additional invocations to init within the same process will not have
- any effect."
- {:author "Daniel Solano Gómez"}
- (:import android.content.Context
- java.io.File))
-
-(def #^{:doc "Whether or not compilation has been initialised"
- :private true}
- cache-dir (atom nil))
-
-(def #^{:doc "The default name of the cache directory."}
- default-cache-dir "clojure_cache")
-
-(defn- cache-file?
- "Predicate for determining if a given file name is a cache file."
- [^String name]
- (and (.startsWith name "repl-")
- (or (.endsWith name ".dex")
- (.endsWith name ".jar"))))
-
-(defn clear-cache
- "Clears all DEX and JAR files from the cache directory."
- []
- (locking cache-dir
- (let [^File dir @cache-dir
- delete-file (fn [^String name] (.delete (File. dir name)))]
- (when dir
- (->>
- (.list dir)
- (filter cache-file?)
- (map delete-file)
- (dorun))))))
-
-(defn init
- "Initialises the compilation path, creating or cleaning cache directory as
- necessary."
- ([^Context context ^String dir-name]
- (locking cache-dir
- (when-not @cache-dir
- (let [dir (.getDir context dir-name Context/MODE_PRIVATE)
- path (.getAbsolutePath dir)]
- (reset! cache-dir dir)
- (System/setProperty "clojure.compile.path" path)
- (alter-var-root #'clojure.core/*compile-path* (constantly path))))))
- ([^Context context]
- (init context default-cache-dir)))
180 src/clojure/neko/context.clj
View
@@ -1,180 +0,0 @@
-; Copyright © 2011 Sattvik Software & Technology Resources, Ltd. Co.
-; All rights reserved.
-;
-; This program and the accompanying materials are made available under the
-; terms of the Eclipse Public License v1.0 which accompanies this distribution,
-; and is available at <http://www.eclipse.org/legal/epl-v10.html>.
-;
-; By using this software in any fashion, you are agreeing to be bound by the
-; terms of this license. You must not remove this notice, or any other, from
-; this software.
-
-(ns neko.context
- "Utilities to aid in working with a context."
- {:author "Daniel Solano Gómez"}
- (:import android.content.Context)
- (:use neko.-protocols.resolvable
- neko.-utils))
-
-(def
- ^{:doc "The current context object to operate on."
- :dynamic true}
- *context*)
-
-(defn context?
- "Predict to determine if the is an instance of Context."
- [x]
- (instance? Context x))
-
-(defn has-*context*?
- "Tests that the caller has a valid binding for *context*."
- []
- (and (bound? #'*context*)
- (context? *context*)))
-
-(defmacro with-context
- "Evaluates body such that *context* is bound to the given context."
- [context & body]
- `(binding [*context* ~context]
- ~@body))
-
-(defn resolve-resource
- "Resolves the resource ID of a given type with the given name. For example,
- to refer to what in Java would be R.string.my_string, you can use:
-
- (resolve-resource context :string :my_string)
-
- The type should be a keyword corresponding to a resource type such as
- :layout, :attr, or :id.
-
- The name should be a keyword. If the keyword has a namespace, it will be
- used as the package from which to retrieve the resources. Generally, this is
- not required as the default will be the context’s package. However, this can
- be used to access the resources from the platform. For example, the
- equivalent to android.R.layout.simple_list_item_1 is:
-
- (resolve-resource context :layout :android/simple_list_item_1)
-
- The name portion of the name argument will be converted to a string and any
- hyphens or periods will be transformed to underscores. Note that hyphens are
- not valid in Android names, but are allowed here to be Clojure friendly.
-
- If the name argument is an integer, it is assumed to be a valid resource ID
- and will be returned as is without any processing.
-
- If used within a with-context form, the context may be left out.
-
- Note that this method is much slower than using the constant directly, but
- results in more readable code."
- ([^Context context type name]
- {:pre [(context? context)
- (keyword? type)
- (resolvable? name)]
- :post [(integer? %)]}
- (resolve-it name context type))
- ([type name]
- {:pre [(has-*context*?)
- (keyword? type)
- (resolvable? name)]
- :post [(integer? %)]}
- (resolve-it name *context* type)))
-
-(defn get-id
- "Finds the ID for the XML item with the given name. This is simply a
- convenient way of calling (resolve-resource context :id name)."
- ([name]
- {:pre [(has-*context*?)
- (resolvable? name)]
- :post [(integer? %)]}
- (resolve-id name *context*))
- ([context name]
- {:pre [(context? context)
- (resolvable? name)]
- :post [(integer? %)]}
- (resolve-id name context)))
-
-(defn get-string
- "Gets the localized string with the given ID or name from the context. If an
- integer ID is given, it will be used directly; otherwise, the name will be
- resolved using resolve-resource.
-
- If additional arguments are supplied, the string will be interpreted as a
- format and the arguments will be applied to the format.
-
- If within a with-context form, the context parameter may be omitted."
- {:arglists '([context? id-or-name & args])}
- ([id-or-name]
- {:pre [(has-*context*?)
- (resolvable? id-or-name)]
- :post [(string? %)]}
- (get-string *context* id-or-name))
- ([context id-or-name]
- {:pre [(or (and (context? context)
- (resolvable? id-or-name))
- (and (has-*context*?)
- (resolvable? context)))]
- :post [(string? %)]}
- (if (instance? Context context)
- (.getString ^Context context (resolve-string id-or-name context))
- (get-string *context* context id-or-name)))
- ([context id-or-name & args]
- {:pre [(or (and (context? context)
- (resolvable? id-or-name))
- (and (has-*context*?)
- (resolvable? context)))]
- :post [(string? %)]}
- (if (instance? Context context)
- (.getString ^Context context
- (resolve-string id-or-name context)
- (to-array args))
- (apply get-string *context* context id-or-name args))))
-
-(defn get-layout
- "Finds the resource ID for the layout with the given name. This is simply a
- convenient way of calling (resolve-resource context :layout name)."
- ([name]
- {:pre [(has-*context*?)
- (resolvable? name)]
- :post [(integer? %)]}
- (resolve-layout name *context*))
- ([context name]
- {:pre [(context? context)
- (resolvable? name)]
- :post [(integer? %)]}
- (resolve-layout name context)))
-
-(defn get-system-service
- "Gets a system service from the context. The type argument is a keyword that
- names the service type. Examples include :alarm for the alarm service and
- :layout-inflater for the layout inflater service. If within a with-context
- form, the context may be omitted."
- ([type]
- {:pre [(has-*context*?)]}
- (get-system-service *context* type))
- ([^Context context type]
- {:pre [(keyword? type)
- (context? context)]}
- ; using reflection here allows forward-compatibility
- (try
- (.getSystemService context (static-field-value Context type #(str % "_SERVICE")))
- (catch NoSuchFieldException _
- (throw (IllegalArgumentException.
- (format "No service type '%s' exists." (name type))))))))
-
-(defn inflate-layout
- "Inflates the layout with the given ID or name. The id-or-name argument must
- be an integer ID or a keyword name for the desired layout. If within a
- with-context form, the context may be omitted."
- ([id-or-name]
- {:pre [(has-*context*?)
- (resolvable? id-or-name)]
- :post [(instance? android.view.View %)]}
- (get-layout *context* id-or-name))
- ([context id-or-name]
- {:pre [(context? context)
- (resolvable? id-or-name)]
- :post [(instance? android.view.View %)]}
- (.. android.view.LayoutInflater
- (from context)
- (inflate ^Integer (resolve-layout id-or-name context)
- nil))))
91 src/clojure/neko/dialog/alert.clj
View
@@ -1,91 +0,0 @@
-; Copyright © 2011 Sattvik Software & Technology Resources, Ltd. Co.
-; All rights reserved.
-;
-; This program and the accompanying materials are made available under the
-; terms of the Eclipse Public License v1.0 which accompanies this distribution,
-; and is available at <http://www.eclipse.org/legal/epl-v10.html>.
-;
-; By using this software in any fashion, you are agreeing to be bound by the
-; terms of this license. You must not remove this notice, or any other, from
-; this software.
-
-(ns neko.dialog.alert
- "Helps build and manage alert dialogs. The core functionality of this
- namespace is built around the AlertDialogBuilder protocol. This allows using
- the protocol with the FunctionalAlertDialogBuilder generated by new-builder
- as well as the AlertDialog.Builder class provided by the Android platform.
-
- In general, it is preferable to use the functional version of the builder as
- it is immutable. Using the protocol with an AlertDialog.Builder object works
- by mutating the object."
- {:author "Daniel Solano Gómez"}
- (:import android.app.AlertDialog$Builder)
- (:use neko.context)
- )
-
-(defprotocol AlertDialogBuilder
- "Defines the functionality needed to build new alert dialogues."
- (create [builder]
- "Actually creates the AlertDialog.")
- (get-builder-object [builder]
- "Returns an instance of AlertDialog.Builder with the properties from this
- builder.")
- (with-cancellation [builder cancellable?]
- "Sets whether or not the dialog may be cancelled.")
- )
-
-(defrecord FunctionalAlertDialogBuilder
- [^android.content.Context context
- ^boolean cancellable])
-
-(defn- new-builder?
- "Predicate used for testing whether a new builder is a functional builder but
- is different from the original builder."
- [old-builder new-builder]
- (and (instance? FunctionalAlertDialogBuilder old-builder)
- (not (identical? old-builder new-builder))))
-
-(extend-type FunctionalAlertDialogBuilder
- AlertDialogBuilder
- (create [this]
- {:post [(instance? android.app.AlertDialog %)]}
- (.create (get-builder-object this)))
-
- (get-builder-object [this]
- {:post [(instance? AlertDialog$Builder %)]}
- (doto (AlertDialog$Builder. (.context this))
- (.setCancelable (.cancellable this))
- ))
-
- (with-cancellation [this cancellable?]
- {:post [(new-builder? this %)
- (= (:cancellable %) cancellable?)]}
- (assoc this :cancellable (boolean cancellable?)))
- )
-
-(extend-type AlertDialog$Builder
- AlertDialogBuilder
- (create [this]
- {:post [(instance? android.app.AlertDialog %)]}
- (.create this))
-
- (get-builder-object [this]
- {:post [(identical? this %)]}
- this)
-
- (with-cancellation [this cancellable?]
- {:post [(identical? this %)]}
- (.setCancelable this (boolean cancellable?)))
- )
-
-(defn new-builder
- "Creates a new functional alert dialog builder. If within a with-context
- form, the context argument may be omitted."
- ([]
- {:pre [(has-*context*?)]
- :post [(instance? FunctionalAlertDialogBuilder %)]}
- (new-builder *context*))
- ([context]
- {:pre [(context? context)]
- :post [(instance? FunctionalAlertDialogBuilder %)]}
- (FunctionalAlertDialogBuilder. context true)))
97 src/clojure/neko/find_view.clj
View
@@ -1,97 +0,0 @@
-; Copyright © 2011 Sattvik Software & Technology Resources, Ltd. Co.
-; All rights reserved.
-;
-; This program and the accompanying materials are made available under the
-; terms of the Eclipse Public License v1.0 which accompanies this distribution,
-; and is available at <http://www.eclipse.org/legal/epl-v10.html>.
-;
-; By using this software in any fashion, you are agreeing to be bound by the
-; terms of this license. You must not remove this notice, or any other, from
-; this software.
-
-(ns neko.find-view
- "Home of the ViewFinder protocol, which should simplify and unify use of the
- findViewById method introduced in various Android classes. To use the
- protocol, you need an object that supports findViewById, and these are:
-
- + activities
- + dialogs
- + views
- + windows
-
- Given one of these objects, you can (find-view obj id). The id argument can
- be an integer ID, as in the original method, or it can be a keyword that will
- be resolved like:
-
- (neko.context/resolve-resource context :id id)
-
- For example, instead of calling:
-
- (.findViewById activity R$id/my_view)
-
- You can now use:
-
- (find-view activity :my_view)
-
- In addition, if within a with-activity form, you can leave out the activity
- argument, simplifying the above call to:
-
- (find-view :my_view)"
- {:author "Daniel Solano Gómez"}
- (:use neko.activity
- neko.-protocols.resolvable))
-
-(defn- nil-or-view?
- [x]
- (or (nil? x)
- (instance? android.view.View x)))
-
-(defprotocol ViewFinder
- "Protocol for finding child views by an ID."
- (find-view [id] [finder id]
- "The two-arg version is the general version used outside of any context.
- The one-arg version is designed for use within a (with-activity)
- context."))
-
-(extend-protocol ViewFinder
- android.view.Window
- (find-view [window id]
- {:pre [(resolvable? id)]
- :post [(nil-or-view? %)]}
- (.findViewById window (resolve-id id (.getContext window))))
-
- android.app.Activity
- (find-view [activity id]
- {:pre [(resolvable? id)]
- :post [(nil-or-view? %)]}
- (.findViewById activity (resolve-id id activity)))
-
- android.view.View
- (find-view [view id]
- {:pre [(resolvable? id)]
- :post [(nil-or-view? %)]}
- (.findViewById view (resolve-id id (.getContext view))))
-
- android.app.Dialog
- (find-view [dialog id]
- {:pre [(resolvable? id)]
- :post [(nil-or-view? %)]}
- (.findViewById dialog (resolve-id id (.getContext dialog))))
-
- Integer
- (find-view [id]
- {:pre [(has-*activity*?)]
- :post [(nil-or-view? %)]}
- (find-view *activity* id))
-
- Long
- (find-view [id]
- {:pre [(has-*activity*?)]
- :post [(nil-or-view? %)]}
- (find-view *activity* (.intValue id)))
-
- clojure.lang.Keyword
- (find-view [id]
- {:pre [(has-*activity*?)]
- :post [(nil-or-view? %)]}
- (find-view *activity* id)))
130 src/clojure/neko/listeners/adapter_view.clj
View
@@ -1,130 +0,0 @@
-; Copyright © 2011 Sattvik Software & Technology Resources, Ltd. Co.
-; All rights reserved.
-;
-; This program and the accompanying materials are made available under the
-; terms of the Eclipse Public License v1.0 which accompanies this distribution,
-; and is available at <http://www.eclipse.org/legal/epl-v10.html>.
-;
-; By using this software in any fashion, you are agreeing to be bound by the
-; terms of this license. You must not remove this notice, or any other, from
-; this software.
-
-(ns neko.listeners.adapter-view
- "Uility functions and macros for creating listeners corresponding to the
- android.widget.AdapterView class."
- {:author "Daniel Solano Gómez"})
-
-(defn on-item-click-call
- "Takes a function and yields an AdapterView.OnItemClickListener object that
- will invoke the function. This function must take the following four
- arguments:
-
- parent the AdapterView where the click happened
- view the view within the AdapterView that was clicked
- position the position of the view in the adapter
- id the row id of the item that was clicked"
- [handler-fn]
- {:pre [(fn? handler-fn)]
- :post [(instance? android.widget.AdapterView$OnItemClickListener %)]}
- (reify android.widget.AdapterView$OnItemClickListener
- (onItemClick [this parent view position id]
- (handler-fn parent view position id))))
-
-(defmacro on-item-click
- "Takes a body of expressions and yields an AdapterView.OnItemClickListener
- object that will invoke the body. The body takes the following implicit
- arguments:
-
- parent the AdapterView where the click happened
- view the view within the AdapterView that was clicked
- position the position of the view in the adapter
- id the row id of the item that was clicked"
- [& body]
- `(on-item-click-call (fn [~'parent ~'view ~'position ~'id] ~@body)))
-
-(defn on-item-long-click-call
- "Takes a function and yields an AdapterView.OnItemLongClickListener object
- that will invoke the function. This function must take the following four
- arguments:
-
- parent the AdapterView where the click happened
- view the view within the AdapterView that was clicked
- position the position of the view in the adapter
- id the row id of the item that was clicked
-
- The function should evaluate to a logical true value if it has consumed the
- long click; otherwise logical false."
- [handler-fn]
- {:pre [(fn? handler-fn)]
- :post [(instance? android.widget.AdapterView$OnItemLongClickListener %)]}
- (reify android.widget.AdapterView$OnItemLongClickListener
- (onItemLongClick [this parent view position id]
- (boolean (handler-fn parent view position id)))))
-
-(defmacro on-item-long-click
- "Takes a body of expressions and yields an
- AdapterView.OnItemLongClickListener object that will invoke the body. The
- body takes the following implicit arguments:
-
- parent the AdapterView where the click happened
- view the view within the AdapterView that was clicked
- position the position of the view in the adapter
- id the row id of the item that was clicked
-
- The body should evaluate to a logical true value if it has consumed the long
- click; otherwise logical false."
- [& body]
- `(on-item-long-click-call (fn [~'parent ~'view ~'position ~'id] ~@body)))
-
-(defn on-item-selected-call
- "Takes one or two functions and yields an AdapterView.OnItemSelectedListener object
- that will invoke the functions. The first function will be called to handle the
- onItemSelected(…) method and must take the following four arguments:
-
- parent the AdapterView where the selection happened
- view the view within the AdapterView that was clicked
- position the position of the view in the adapter
- id the row id of the item that was selected
-
- If a second function is provided, it will be called when the selection
- disappears from the view. It takes a single argument, the AdapterView that
- now contains no selected item."
- ([item-fn]
- {:pre [(fn? item-fn)]
- :post [(instance? android.widget.AdapterView$OnItemSelectedListener %)]}
- (on-item-selected-call item-fn nil))
- ([item-fn nothing-fn]
- {:pre [(fn? item-fn)
- (or (nil? nothing-fn)
- (fn? nothing-fn))]
- :post [(instance? android.widget.AdapterView$OnItemSelectedListener %)]}
- (reify android.widget.AdapterView$OnItemSelectedListener
- (onItemSelected [this parent view position id]
- (item-fn parent view position id))
- (onNothingSelected [this parent]
- (when nothing-fn
- (nothing-fn parent))))))
-
-(defmacro on-item-selected
- "Takes a body of expressions and yields an AdapterView.OnItemSelectedListener
- object that will invoke the body The body takes the following implicit
- arguments:
-
- type either :item corresponding an onItemSelected(…) call or :nothing
- corresponding to an onNothingSelected(…) call
- parent the AdapterView where the selection happened or now contains no
- selected item
- view the view within the AdapterView that was clicked. If type is
- :nothing, this will be nil
- position the position of the view in the adapter. If type is :nothing, this
- will be nil.
- id the row id of the item that was selected. If type is :nothing,
- this will be nil."
- [& body]
- `(let [handler-fn# (fn [~'type ~'parent ~'view ~'position ~'id]
- ~@body)]
- (on-item-selected-call
- (fn ~'item-handler [parent# view# position# id#]
- (handler-fn# :item parent# view# position# id#))
- (fn ~'nothing-handler [parent#]
- (handler-fn# :nothing parent# nil nil nil)))))
131 src/clojure/neko/listeners/dialog.clj
View
@@ -1,131 +0,0 @@
-; Copyright © 2011 Sattvik Software & Technology Resources, Ltd. Co.
-; All rights reserved.
-;
-; This program and the accompanying materials are made available under the
-; terms of the Eclipse Public License v1.0 which accompanies this distribution,
-; and is available at <http://www.eclipse.org/legal/epl-v10.html>.
-;
-; By using this software in any fashion, you are agreeing to be bound by the
-; terms of this license. You must not remove this notice, or any other, from
-; this software.
-
-(ns neko.listeners.dialog
- "Uility functions and macros for setting listeners corresponding to the
- android.content DialogInterface interface."
- {:author "Daniel Solano Gómez"}
- (:import android.content.DialogInterface))
-
-(defn on-cancel-call
- "Takes a function and yields a DialogInterface.OnCancelListener object that
- will invoke the function. This function must take one argument, the dialog
- that was cancelled."
- [handler-fn]
- (reify android.content.DialogInterface$OnCancelListener
- (onCancel [this dialog]
- (handler-fn dialog))))
-
-(defmacro on-cancel
- "Takes a body of expressions and yields a DialogInterface.OnCancelListener object that
- will invoke the body. The body takes an implicit argument 'dialog' that is the
- dialog that was cancelled."
- [& body]
- `(on-cancel-call (fn [~'dialog] ~@body)))
-
-(defn on-click-call
- "Takes a function and yields a DialogInterface.OnCancelListener object that
- will invoke the function. This function must take two arguments:
-
- dialog: the dialog that received the click
- which: the button that was clicked (one of :negative, :neutral, or
- :positive) or the position of the item that was clicked"
- [handler-fn]
- (reify android.content.DialogInterface$OnClickListener
- (onClick [this dialog which]
- (let [which (condp = which
- DialogInterface/BUTTON_NEGATIVE :negative
- DialogInterface/BUTTON_NEUTRAL :neutral
- DialogInterface/BUTTON_POSITIVE :positive
- which)]
- (handler-fn dialog which)))))
-
-(defmacro on-click
- "Takes a body of expressions and yields a DialogInterface.OnCancelListener
- object that will invoke the function. The body will take the following two
- implicit arguments:
-
- dialog: the dialog that received the click
- which: the button that was clicked (one of :negative, :neutral, or
- :positive) or the position of the item that was clicked"
- [& body]
- `(on-click-call (fn [~'dialog ~'which] ~@body)))
-
-(defn on-dismiss-call
- "Takes a function and yields a DialogInterface.OnDismissListener object that
- will invoke the function. This function must take one argument, the dialog
- that was dismissed."
- [handler-fn]
- (reify android.content.DialogInterface$OnDismissListener
- (onDismiss [this dialog]
- (handler-fn dialog))))
-
-(defmacro on-dismiss
- "Takes a body of expressions and yields a DialogInterface.OnDismissListener
- object that will invoke the body. The body takes an implicit argument
- 'dialog' that is the dialog that was dismissed."
- [& body]
- `(on-dismiss-call (fn [~'dialog] ~@body)))
-
-(defn on-key-call
- "Takes a function and yields a DialogInterface.OnKeyListener object that will
- invoke the function. This function must take the following three arguments:
-
- dialog: the dialog the key has been dispatched to
- key-code: the code for the physical key that was pressed
- event: the KeyEvent object containing full information about the event
-
- The function should evaluate to a logical true value if it has consumed the
- event, otherwise logical false."
- [handler-fn]
- (reify android.content.DialogInterface$OnKeyListener
- (onKey [this dialog key-code event]
- (boolean (handler-fn dialog key-code event)))))
-
-(defmacro on-key
- "Takes a body of expressions and yields a DialogInterface.OnKeyListener
- object that will invoke the body. The body takes the following three
- implicit arguments:
-
- dialog: the dialog the key has been dispatched to
- key-code: the code for the physical key that was pressed
- event: the KeyEvent object containing full information about the event
-
- The body should evaluate to a logical true value if it has consumed the
- event, otherwise logical false."
- [& body]
- `(on-key-call (fn [~'dialog ~'key-code ~'event] ~@body)))
-
-(defn on-multi-choice-click-call
- "Takes a function and yields a DialogInterface.OnMultiChoiceClickListener
- object that will invoke the function. This function must take the following
- three arguments:
-
- dialog: the dialog where the selection was made
- which: the position of the item in the list that was clicked
- checked?: true if the click checked the item, else false"
- [handler-fn]
- (reify android.content.DialogInterface$OnMultiChoiceClickListener
- (onClick [this dialog which checked?]
- (handler-fn dialog which checked?))))
-
-(defmacro on-multi-choice-click
- "Takes a body of expressions and yields a
- DialogInterface.OnMultiChoiceClickListener object that will invoke the body.
- The body takes the following three implicit arguments:
-
- dialog: the dialog where the selection was made
- which: the position of the item in the list that was clicked
- checked?: true if the click checked the item, else false"
- [& body]
- `(on-multi-choice-click-call (fn [~'dialog ~'which ~'checked?] ~@body)))
-
-(comment -- OnShowListener is added in API level 8)
53 src/clojure/neko/listeners/text_view.clj
View
@@ -1,53 +0,0 @@
-; Copyright © 2011 Sattvik Software & Technology Resources, Ltd. Co.
-; All rights reserved.
-;
-; This program and the accompanying materials are made available under the
-; terms of the Eclipse Public License v1.0 which accompanies this distribution,
-; and is available at <http://www.eclipse.org/legal/epl-v10.html>.
-;
-; By using this software in any fashion, you are agreeing to be bound by the
-; terms of this license. You must not remove this notice, or any other, from
-; this software.
-
-(ns neko.listeners.text-view
- "Uility functions and macros for creating listeners corresponding to the
- android.widget.TextView class."
- {:author "Daniel Solano Gómez"})
-
-(defn on-editor-action-call
- "Takes a function and yields a TextView.OnEditorActionListener object that
- will invoke the function. This function must take the following three
- arguments:
-
- view the view that was clicked
- action-id identifier of the action, this will be either the identifier you
- supplied or EditorInfo/IME_NULL if being called to the enter key
- being pressed
- key-event if triggered by an enter key, this is the event; otherwise, this
- is nil
-
- The function should evaluate to a logical true value if it has consumed the
- action, otherwise logical false."
- [handler-fn]
- {:pre [(fn? handler-fn)]
- :post [(instance? android.widget.TextView$OnEditorActionListener %)]}
- (reify android.widget.TextView$OnEditorActionListener
- (onEditorAction [this view action-id key-event]
- (boolean (handler-fn view action-id key-event)))))
-
-(defmacro on-editor-action
- "Takes a body of expressions and yields a TextView.OnEditorActionListener
- object that will invoke the body. The body takes the following implicit
- arguments:
-
- view the view that was clicked
- action-id identifier of the action, this will be either the identifier you
- supplied or EditorInfo/IME_NULL if being called to the enter key
- being pressed
- key-event if triggered by an enter key, this is the event; otherwise, this
- is nil
-
- The body should evaluate to a logical true value if it has consumed the
- action, otherwise logical false."
- [& body]
- `(on-editor-action-call (fn [~'view ~'action-id ~'key-event] ~@body)))
218 src/clojure/neko/listeners/view.clj
View
@@ -1,218 +0,0 @@
-; Copyright © 2011 Sattvik Software & Technology Resources, Ltd. Co.
-; All rights reserved.
-;
-; This program and the accompanying materials are made available under the
-; terms of the Eclipse Public License v1.0 which accompanies this distribution,
-; and is available at <http://www.eclipse.org/legal/epl-v10.html>.
-;
-; By using this software in any fashion, you are agreeing to be bound by the
-; terms of this license. You must not remove this notice, or any other, from
-; this software.
-
-(ns neko.listeners.view
- "Uility functions and macros for setting listeners corresponding to the
- android.view.View class."
- {:author "Daniel Solano Gómez"})
-
-(defn on-click-call
- "Takes a function and yields a View.OnClickListener object that will invoke
- the function. This function must take one argument, the view that was
- clicked."
- [handler-fn]
- (reify android.view.View$OnClickListener
- (onClick [this view]
- (handler-fn view))))
-
-(defmacro on-click
- "Takes a body of expressions and yields a View.OnClickListener object that
- will invoke the body. The body takes an implicit argument 'view' that is the
- view that was clicked."
- [& body]
- `(on-click-call (fn [~'view] ~@body)))
-
-(defn on-create-context-menu-call
- "Takes a function and yields a View.OnCreateContextMenuListener object that
- will invoke the function. This function must take the following three
- arguments:
-
- menu: the context menu that is being built
- view: the view for which the context menu is being built
- info: extra information about the item for which the context menu should be
- shown. This information will vary depending on the class of view."
- [handler-fn]
- (reify android.view.View$OnCreateContextMenuListener
- (onCreateContextMenu [this menu view info]
- (handler-fn menu view info))))
-
-(defmacro on-create-context-menu
- "Takes a body of expressions and yields a View.OnCreateContextMenuListener
- object that will invoke the body. The body takes the following three
- implicit arguments:
-
- menu: the context menu that is being built
- view: the view for which the context menu is being built
- info: extra information about the item for which the context menu should be
- shown. This information will vary depending on the class of view."
- [& body]
- `(on-create-context-menu-call (fn [~'menu ~'view ~'info] ~@body)))
-
-(comment -- Introduced in SDK version 11 (Honeycomb)
-(defn on-drag-call
- "Takes a function and yields a View.OnDragListener object that will invoke
- the function. This function must take the two arguments described in
- on-drag and should return a boolean."
- [handler-fn]
- (reify android.view.View$OnDragListener
- (onDrag [this view event]
- (handler-fn view event))))
-
-(defmacro on-drag
- "Takes a body of expressions and yields a View.OnDragListener object that
- will invoke the body. The body takes the following two implicit arguments:
-
- view: the view that received the drag event
- event: the DragEvent object for the drag event"
- [& body]
- `(on-drag-call (fn [~'view ~'event] ~@body))))
-
-(defn on-focus-change-call
- "Takes a function and yields a View.OnFocusChangeListener object that will
- invoke the function. This function must take the following two arguments:
-
- view: the view whose state has changed
- focused?: the new focuse state for view"
- [handler-fn]
- (reify android.view.View$OnFocusChangeListener
- (onFocusChange [this view focused?]
- (handler-fn view focused?))))
-
-(defmacro on-focus-change
- "Takes a body of expressions and yields a View.OnFocusChangeListener object
- that will invoke the body. The body takes the following two implicit
- arguments:
-
- view: the view whose state has changed
- focused?: the new focuse state for view"
- [& body]
- `(on-focus-change-call (fn [~'view ~'focused?] ~@body)))
-
-(defn on-key-call
- "Takes a function and yields a View.OnKeyListener object that will invoke the
- function. This function must take the following three arguments:
-
- view: the view the key has been dispatched to
- key-code: the code for the physical key that was pressed
- event: the KeyEvent object containing full information about the event
-
- The function should evaluate to a logical true value if it has consumed the
- event, otherwise logical false."
- [handler-fn]
- (reify android.view.View$OnKeyListener
- (onKey [this view key-code event]
- (boolean (handler-fn view key-code event)))))
-
-(defmacro on-key
- "Takes a body of expressions and yields a View.OnKeyListener object that will
- invoke the body. The body takes the following three implicit arguments:
-
- view: the view the key has been dispatched to
- key-code: the code for the physical key that was pressed
- event: the KeyEvent object containing full information about the event
-
- The body should evaluate to a logical true value if it has consumed the
- event, otherwise logical false."
- [& body]
- `(on-key-call (fn [~'view ~'key-code ~'event] ~@body)))
-
-(comment -- as of API level 11
-(defn on-layout-change-call
- "Takes a function and yields a View.OnLayoutChangeListener object that
- will invoke the function. This function must take the arguments described
- in on-layout-change."
- [handler-fn]
- (reify android.view.View$OnLayoutChangeListener
- (onLayoutChange [this view left top right bottom
- old-left old-top old-right old-bottom]
- (handler-fn view left top right bottom
- old-left olt-top old-right old-bottom))))
-
-(defmacro on-layout-change
- "Takes a body of expressions and yields a View.OnLayoutChangeListener
- object that will invoke the body. The body takes the following implicit
- arguments:
-
- view: the view whose state has changed
- left: the new value of the view's left property
- top: the new value of the view's top property
- right: the new value of the view's right property
- bottom: the new value of the view's bottom property
- old-left: the previous value of the view's left property
- old-top: the previous value of the view's top property
- old-right: the previous value of the view's right property
- old-bottom: the previous value of the view's bottom property"
- [& body]
- `(on-key-call (fn [~'view ~'left ~'top ~'right ~'bottom
- ~'old-left ~'old-top ~'old-right ~'old-bottom] ~@body))))
-
-(defn on-long-click-call
- "Takes a function and yields a View.OnLongClickListener object that will
- invoke the function. This function must take one argument, the view that was
- clicked, and must evaluate to a logical true value if it has consumed the
- long click, otherwise logical false."
- [handler-fn]
- (reify android.view.View$OnLongClickListener
- (onLongClick [this view]
- (boolean (handler-fn view)))))
-
-(defmacro on-long-click
- "Takes a body of expressions and yields a View.OnLongClickListener object
- that will invoke the body. The body takes an implicit argument 'view' that
- is the view that was clicked and held. The body should also evaluate to a
- logical true value if it consumes the long click, otherwise logical false."
- [& body]
- `(on-long-click-call (fn [~'view] ~@body)))
-
-(comment -- incomplete -- also for API level 11 (Honeycomb)
-(defn on-system-ui-visibility-change-call
- "Takes a function and yields a View.OnSystemUiVisibilityChangeListener object
- that will invoke the function. This function must take one argument, the
- view that was clicked, and must evaluate to true if it has consumed the long
- click, false otherwise."
- [handler-fn]
- (reify android.view.View$OnSystemUiVisibilityChangeListener
- (onLongClick [this view]
- (handler-fn view))))
-
-(defmacro on-system-ui-visibility-change
- "Takes a body of expressions and yields a
- View.OnSystemUiVisibilityChangeListener object that will invoke the body.
- The body takes an implicit argument 'visibility' which will be either
- :status-bar-hidden or :status-bar-visible."
- [& body]
- `(on-system-ui-visibility-change-call (fn [~'visibility] ~@body))))
-
-(defn on-touch-call
- "Takes a function and yields a View.OnTouchListener object that will invoke
- the function. This function must take the following two arguments:
-
- view: the view the touch event has been dispatched to
- event: the MotionEvent object containing full information about the event
-
- The function should evaluate to a logical true value if it consumes the
- event, otherwise logical false."
- [handler-fn]
- (reify android.view.View$OnTouchListener
- (onTouch [this view event]
- (boolean (handler-fn view event)))))
-
-(defmacro on-touch
- "Takes a body of expressions and yields a View.OnTouchListener object that
- will invoke the body. The body takes the following implicit arguments:
-
- view: the view the touch event has been dispatched to
- event: the MotionEvent object containing full information about the event
-
- The body should evaluate to a logical value if it consumes the event,
- otherwise logical false."
- [& body]
- `(on-touch-call (fn [~'view ~'event] ~@body)))
65 src/clojure/neko/log.clj
View
@@ -1,65 +0,0 @@
-; Copyright © 2011 Sattvik Software & Technology Resources, Ltd. Co.
-; All rights reserved.
-;
-; This program and the accompanying materials are made available under the
-; terms of the Eclipse Public License v1.0 which accompanies this distribution,
-; and is available at <http://www.eclipse.org/legal/epl-v10.html>.
-;
-; By using this software in any fashion, you are agreeing to be bound by the
-; terms of this license. You must not remove this notice, or any other, from
-; this software.
-
-(ns neko.log
- "Utility for logging in Android. To use this utility simply use the deflog
- macro as follows:
-
- (deflog \"MyTag\")
-
- This will intern a number of functions in your namespace, namely: log-d,
- log-v, log-i, log-w, log-e, and log-wtf. These functions will perform the
- equivalent of calling the corresponding method on the android.util.Log
- class with the tag given in the deflog macro call.
-
- For example, given the above deflog call,
-
- (log-d \"Some log string\")
-
- is equivalent to:
-
- (android.util.Log/d \"MyTag\" \"Some log string\")
-
- Calls to log-wtf on platforms that do not support Log.wtf() will be
- downgraded to Log.e() calls."
- {:author "Daniel Solano Gómez"}
- (:import android.util.Log))
-
-(defmacro deflogfn
- "Macro for generating log functions."
- {:private true}
- [fn-name doc-string method-name]
- `(defn ~fn-name
- ~doc-string
- ([tag# message#]
- (. Log (~method-name tag# message#)))
- ([tag# message# throwable#]
- (. Log (~method-name tag# message# throwable#)))))
-
-(deflogfn log-debug "Sends a DEBUG log message." d)
-
-(deflogfn log-error "Sends a ERROR log message." e)
-
-(deflogfn log-info "Sends a INFO log message." i)
-
-(deflogfn log-verbose "Sends a VERBOSE log message." v)
-
-(deflogfn log-warn "Sends a WARN log message." w)
-
-(defmacro deflog
- "Creates a number of logging functions for the given tag."
- [tag]
- `(do
- (intern *ns* (with-meta (symbol "log-d") {:private true}) (partial log-debug ~tag))
- (intern *ns* (with-meta (symbol "log-e") {:private true}) (partial log-error ~tag))
- (intern *ns* (with-meta (symbol "log-i") {:private true}) (partial log-info ~tag))
- (intern *ns* (with-meta (symbol "log-v") {:private true}) (partial log-verbose ~tag))
- (intern *ns* (with-meta (symbol "log-w") {:private true}) (partial log-warn ~tag))))
185 src/clojure/neko/threading.clj
View
@@ -1,185 +0,0 @@
-; Copyright © 2011 Sattvik Software & Technology Resources, Ltd. Co.
-; All rights reserved.
-;
-; This program and the accompanying materials are made available under the
-; terms of the Eclipse Public License v1.0 which accompanies this distribution,
-; and is available at <http://www.eclipse.org/legal/epl-v10.html>.
-;
-; By using this software in any fashion, you are agreeing to be bound by the
-; terms of this license. You must not remove this notice, or any other, from
-; this software.
-
-(ns neko.threading
- "Utilities used to manage multiple threads on Android."
- {:author "Daniel Solano Gómez"}
- (:import android.app.Activity
- android.view.View
- clojure.lang.IFn
- java.util.concurrent.TimeUnit
- neko.threading.AsyncTask))
-
-(defn run-on-ui-thread*
- "Runs the given nullary function on the UI thread. If this function is
- called on the UI thread, it will evaluate immediately."
- [^Activity activity ^IFn f]
- (.runOnUiThread activity (reify Runnable (run [this] (f)))))
-
-(defmacro run-on-ui-thread
- "Runs the macro body on the UI thread. If this macro is called on the UI
- thread, it will evaluate immediately."
- [activity & body]
- `(run-on-ui-thread* ~activity (fn [] ~@body)))
-
-(defn post*
- "Causes the function to be added to the message queue. The function will
- execute on the UI thread. Returns true if successfully placed in the message
- queue."
- [^View view ^IFn f]
- (.post view (reify Runnable (run [this] (f)))))
-
-(defmacro post
- "Causes the macro body to be added to the message queue. It will execute on
- the UI thread. Returns true if successfully placed in the message queue."
- [^View view & body]
- `(post* ~view (fn [] ~@body)))
-
-(defn post-delayed*
- "Causes the function to be added to the message queue, to be run after the
- specified amount of time elapses. The function will execute on the UI
- thread. Returns true if successfully placed in the message
- queue."
- [^View view ^long millis ^IFn f]
- (.postDelayed view (reify Runnable (run [this] (f))) millis ))
-
-(defmacro post-delayed
- "Causes the macro body to be added to the message queue. It will execute on
- the UI thread. Returns true if successfully placed in the message queue."
- [view millis & body]
- `(post-delayed* ~view ~millis (fn [] ~@body)))
-
-(defn on-ui-thread?
- "Returns a logical true value if the current thread is a UI thread."
- []
- (android.os.Looper/myLooper))
-
-(defrecord Task
- [^IFn bg-fn
- ^IFn pre-fn
- ^IFn post-fn
- ^IFn progress-fn
- ^IFn cancel-fn
- ^AsyncTask real-task])
-
-(defn new-task
- "Creates a new asynchronous task that will execute the given function in the background."
- [f]
- (Task. f nil nil nil nil nil))
-
-(defn with-pre-execute
- [task f]
- (assoc task :pre-fn f))
-
-(defn with-post-execute
- [task f]
- (assoc task :post-fn f))
-
-(defn with-on-progress-update
- [task f]
- (assoc task :progress-fn f))
-
-(defn with-on-cancelled
- [task f]
- (assoc task :cancel-fn f))
-
-(def ^{:private true
- :dynamic true}
- *async-task*)
-
-(defn publish-progress
- [& values]
- {:pre [(bound? #'*async-task*)]}
- (.superPublishProgress ^AsyncTask *async-task* (to-array values)))
-
-(defn execute!
- ""
- ([^Task task & params]
- (let [real-task (proxy [AsyncTask] []
- (doInBackground [_]
- (binding [*async-task* this]
- (let [bg-fn (.bg_fn task)]
- (if (= [::no-args] params)
- (bg-fn)
- (apply bg-fn params)))))
-
- (onPreExecute []
- (when-let [pre-fn (.pre_fn task)]
- (pre-fn)))
-
- (onPostExecute [result]
- (when-let [post-fn (.post_fn task)]
- (post-fn result)))
-
- (onProgressUpdate [values]
- (when-let [progress-fn (.progress_fn task)]
- (apply progress-fn values)))
-
- (onCancelled []
- (when-let [cancel-fn (.cancel_fn task)]
- (cancel-fn))))]
- (assoc task :real-task (.execute real-task nil))))
- ([task]
- (execute! task ::no-args)))
-
-(def ^{:doc "A map of unit keywords to TimeUnit instances."
- :private true}
- unit-map
- {; days/hours/minutes added in API level 9
- ;:days TimeUnit/DAYS
- ;:hours TimeUnit/HOURS
- ;:minutes TimeUnit/MINUTES
- :seconds TimeUnit/SECONDS
- :millis TimeUnit/MILLISECONDS
- :micros TimeUnit/MICROSECONDS
- :nanos TimeUnit/NANOSECONDS})
-
-(defn result-of
- "Gets the result of an executed task. The bare version will block until the
- task is complete. If provided a time with no unit, the unit is assumed to be
- milliseconds. The unit may be a an instance of java.util.concurrent.TimeUnit
- or one of the following keywords: :seconds, :millis, :micros, or :nanos.
-
- Note that if you use a TimeUnit instance, units larger than seconds are not
- supported before API level 9."
- ([task]
- (result-of task ::ignored ::ignored))
- ([task time]
- (result-of task time TimeUnit/MILLISECONDS))
- ([^Task task time units]
- {:pre [; must be executed
- (.real_task task)
- ; time must be ::ignored or a non-negative number
- (or (= ::ignored time)
- (and (number? time)
- (not (neg? time))))
- ; units must be a valid keyword or a TimeUnit
- (or (= ::ignored units)
- (and (keyword? units)
- (units unit-map))
- (instance? TimeUnit units))]}
- (let [^AsyncTask real-task (.real_task task)]
- (if (= ::ignored time)
- (.get real-task)
- (.get real-task time (cond
- (keyword? units) (units unit-map)
- :else units))))))
-
-(defn cancel
- ([^Task task may-interrupt?]
- {:pre [; must be executed
- (.real_task task)]}
- (let [^AsyncTask real-task (.real_task task)]
- (.cancel real-task (boolean may-interrupt?))))
- ([task]
- (cancel task true))
- )
-
20 src/java/neko/threading/AsyncTask.java
View
@@ -1,20 +0,0 @@
-/*
- * Copyright © 2011 Sattvik Software & Technology Resources, Ltd. Co.
- * All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this
- * distribution, and is available at
- * <http://www.eclipse.org/legal/epl-v10.html>.
- *
- * By using this software in any fashion, you are agreeing to be bound by the
- * terms of this license. You must not remove this notice, or any other, from
- * this software.
- */
-package neko.threading;
-
-public abstract class AsyncTask<Params,Progress,Result> extends android.os.AsyncTask<Params,Progress,Result> {
- public final void superPublishProgress(Progress... values) {
- super.publishProgress(values);
- }
-}
35 test/AndroidManifest.xml
View
@@ -1,35 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- package name must be unique so suffix with "tests" so package loader doesn't ignore us -->
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.sattvik.neko.tests"
- android:versionCode="1"
- android:versionName="1.0">
- <uses-sdk android:minSdkVersion="7"
- android:targetSdkVersion="10"/>
- <!-- We add an application tag here just so that we can indicate that
- this package needs to link against the android.test library,
- which is needed when building test cases. -->
- <application android:label="@string/app_name" android:icon="@drawable/icon">
- <activity android:name="TestActivity"
- android:label="@string/app_name">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- <uses-library android:name="android.test.runner" />
- </application>
- <!--
- This declares that this application uses the instrumentation test runner targeting
- the package of clojure.contrib.android. To run the tests use the command:
- "adb shell am instrument -w clojure.contrib.android.tests/android.test.InstrumentationTestRunner"
- -->
- <instrumentation android:name="android.test.InstrumentationTestRunner"
- android:targetPackage="com.sattvik.neko.tests"
- android:label="Tests for Neko"/>
-
- <uses-permission android:name="android.permission.INTERNET"/>
- <uses-permission android:name="android.permission.READ_LOGS"/>
-</manifest>
-
-<!-- vim:set et sw=4 ts=4: -->
18 test/ant.properties
View
@@ -1,18 +0,0 @@
-# This file is used to override default values used by the Ant build system.
-#
-# This file must be checked in Version Control Systems, as it is
-# integral to the build system of your project.
-
-# This file is only used by the Ant script.
-
-# You can use this to override default values such as
-# 'source.dir' for the location of your java source folder and
-# 'out.dir' for the location of your output folder.
-
-# You can also use it define how the release builds are signed by declaring
-# the following properties:
-# 'key.store' for the location of your keystore and
-# 'key.alias' for the name of the key to use.
-# The password will be asked during the build when you use the 'release' target.
-
-android.library.reference.1=..
142 test/build.xml
View
@@ -1,142 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project name="NekoTests" default="help">
-
- <!-- The local.properties file is created and updated by the 'android' tool.
- It contains the path to the SDK. It should *NOT* be checked into
- Version Control Systems. -->
- <property file="local.properties" />
-
- <!-- The ant.properties file can be created by you. It is only edited by the
- 'android' tool to add properties to it.
- This is the place to change some Ant specific build properties.
- Here are some properties you may want to change/update:
-
- source.dir
- The name of the source directory. Default is 'src'.
- out.dir
- The name of the output directory. Default is 'bin'.
-
- For other overridable properties, look at the beginning of the rules
- files in the SDK, at tools/ant/build.xml
-
- Properties related to the SDK location or the project target should
- be updated using the 'android' tool with the 'update' action.
-
- This file is an integral part of the build system for your
- application and should be checked into Version Control Systems.
-
- -->
- <property file="ant.properties" />
-
- <!-- The project.properties file is created and updated by the 'android'
- tool, as well as ADT.
-
- This contains project specific properties such as project target, and library
- dependencies. Lower level build properties are stored in ant.properties
- (or in .classpath for Eclipse projects).
-
- This file is an integral part of the build system for your
- application and should be checked into Version Control Systems. -->
- <loadproperties srcFile="project.properties" />
-
- <!-- quick check on sdk.dir -->
- <fail
- message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var"
- unless="sdk.dir"
- />
-
- <!--
- Import per project custom build rules if present at the root of the project.
- This is the place to put custom intermediary targets such as:
- -pre-build
- -pre-compile
- -post-compile (This is typically used for code obfuscation.
- Compiled code location: ${out.classes.absolute.dir}
- If this is not done in place, override ${out.dex.input.absolute.dir})
- -post-package
- -post-build
- -pre-clean
- -->
- <import file="custom_rules.xml" optional="true" />
-
- <import file="../build-support/clojure.xml" />
-
- <target name="test"
- description="Runs tests from the package defined in test.package property">
-
- <property name="tested.project.absolute.dir" location="." />
-
- <property name="test.runner" value="android.test.InstrumentationTestRunner" />
-
- <!-- Application package of the tested project extracted from its manifest file -->
- <xpath input="${tested.project.absolute.dir}/AndroidManifest.xml"
- expression="/manifest/@package" output="tested.manifest.package" />
- <xpath input="AndroidManifest.xml"
- expression="/manifest/@package" output="manifest.package" />
-
- <property name="emma.dump.file"
- value="/data/data/${tested.manifest.package}/coverage.ec" />
-
- <if condition="${emma.enabled}">