# See the License for the specific language governing permissions and
# limitations under the License.
-# Targets the Android platform
+# Android services and implementation of app.nit
#
# To use this module and compile for Android, you must install the
# Android SDK (with API level 10) and NDK (with the API level 9).
# The tools `android`, `ndk-build` and `ant` must be in your PATH.
#
-# Will, in the near future, provide services specific to Android.
+# This module provides basic logging facilities, advanced logging can be
+# achieved by importing `android::log`.
module android
import platform
+private import log
+
+# Uses Android logs to print everything
+redef fun print(text) do log_write(priority_info, app.log_prefix.to_cstring, text.to_s.to_cstring)
+
+redef class App
+ redef fun log_error(msg) do log_write(priority_error, log_prefix.to_cstring, msg.to_cstring)
+
+ redef fun log_warning(msg) do log_write(priority_warn, log_prefix.to_cstring, msg.to_cstring)
+end
--- /dev/null
+# This file is part of NIT (http://www.nitlanguage.org).
+#
+# Copyright 2014 Alexis Laferrière <alexis.laf@xymus.net>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Advanced Android logging services
+module log
+
+import platform
+
+in "C" `{
+ #include <android/log.h>
+`}
+
+# Default Android log priority
+protected fun priority_default: Int do return 1
+
+# Verbose Android log priority
+protected fun priority_verbose: Int do return 2
+
+# Debug Android log priority
+protected fun priority_debug: Int do return 3
+
+# Info Android log priority
+protected fun priority_info: Int do return 4
+
+# Warn Android log priority
+protected fun priority_warn: Int do return 5
+
+# Error Android log priority
+protected fun priority_error: Int do return 6
+
+# Fatal Android log priority
+protected fun priority_fatal: Int do return 7
+
+# Silent Android log priority
+protected fun priority_silent: Int do return 8
+
+# Write `text` to Android log at priority `level` with tag `tag`
+protected fun log_write(level: Int, tag, text: NativeString) `{
+ __android_log_write(level, tag, text);
+`}
fun is_search_key: Bool do return key_code == 84
end
-redef class Object
- # Uses Android logs for every print
- redef fun print(text: Object) is extern import Object.to_s, String.to_cstring `{
- __android_log_print(ANDROID_LOG_INFO, "mnit print", "%s", String_to_cstring(Object_to_s(text)));
- `}
-end
-
redef class App
redef type IE: AndroidInputEvent
redef type D: Opengles1Display
var eventqueue: ASensorEventQueue
var sensors_support_enabled writable = false
- redef fun log_warning(msg) is extern import String.to_cstring `{
- LOGW("%s", String_to_cstring(msg));
- `}
- redef fun log_info(msg) is extern import String.to_cstring `{
- LOGI("%s", String_to_cstring(msg));
- `}
-
redef fun init_window
do
super