Wednesday, January 30, 2013

Android Notification

Starting with API level 11, all notification can be created by Notification.Builder()

Notification.Builder()
extends Object

Instead of create Notification directly, Notification.Builder() provides all necessary flags and features for Notification Here is example usage with all the settings:

new Notification.Builder(this.getApplicationContext())
        .setAutoCancel(boolean autoCancel)
        .setContent(RemoteViews views)
        .setContentInfo(CharSequence info)
        .setContentIntent(PendingIntent intent)
        .setContentText(CharSequence text)
        .setContentTitle(CharSequence title)
        .setDefaults(int defaults)
        .setDeleteIntent(PendingIntent intent))
        .setFullScreenIntent(PendingIntent intent, boolean highPriority)
        .setLargeIcon(Bitmap icon)
        .setLights(int argb, int onMs, int offMs)
        .setNumber(int number)
        .setOngoing(boolean ongoing)
        .setOnlyAlertOnce(boolean onlyAlertOnce)
        .setPriority(int pri)
        .setProgress(int max, int progress, boolean indeterminate)
        .setShowWhen(boolean show)
        .setSmallIcon(int icon, int level)
        .setSmallIcon(int icon)
        .setSound(Uri sound)
        .setSound(Uri sound, int streamType)
        .setStyle(Notification.Style style)
        .setSubText(CharSequence text)
        .setTicker(CharSequence tickerText, RemoteViews views)
        .setTicker(CharSequence tickerText)
        .setUsesChronometer(boolean b)
        .setVibrate(long[] pattern)
        .setWhen(long when)
        .addAction(int icon, CharSequence title, PendingIntent intent)
        .build()

Of course, you do not have to use every settings, as most of them have defaults value, however, you have to specify below elements at least to build Notification object. A small icon, set by setSmallIcon(), A title, set by setContentTitle()Detail text, set by setContentText()

Notification
extends Object
implements Parcelable

After API level 11, there are not much to discuss with Notification object as we can build it with new Notificaion.Build.build(). However, since this object is implementing Parcelable, it provides below 2 method:
  • void writeToParcel(Parcel parcel, int flags)
  • Flatten this notification from a parcel.
  • int describeContents()
  • Describe the kinds of special objects contained in this Parcelable's marshalled representation.

NotificationManager
extends Object

This object usually takes care of all the notifications, as its name states. In Android, there are 3 different type of notifications based on their UI; 1.A persistent icon that goes in the status bar and is accessible through the launcher, (when the user selects it, a designated Intent can be launched) 2.Turning on or flashing LEDs on the device, or 3.Alerting the user by flashing the backlight, playing a sound, or vibrating.
Here is general usage of NotificationManager

Notification mNotification = new Notification.Builder(this.getApplicationContext())
        .setBLAH()
        .setBLAH()
        .setBLAH()
        .build()
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(mId, mNotification);

mNotificationManager.cancel(mId); will dismiss based on mId or you can use .cancelAll() to simply kill all the notifications.

From the API level 16, Notification supports these styles, which can provides better UI experience; Style, BigPictureStyle, InboxStyle, BigTextStyle. Each style can take Notification.Builder(), and it will generate Notification with build() method.

This can be done simply taking Notification.Builder as a parameter with each Style, and you can find more details in Android Developer .

Wednesday, January 23, 2013

Android build trouble shooting

Assume that building system is either Ubuntu 12.04 LTS or 12.10
  • Sun JDK 6 installation
  • AOSP needs Sun JDK 6 compiler, however, The Sun JDK is no longer in Ubuntu's main package repository.
    Here is solution:
    
    $ sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
    $ sudo apt-get update
    $ sudo apt-get install sun-java6-jdk
    
  • Sun JDK 6 installation 2
  • You can find the latest release of Sun (Oracle) JDK6 here:
    Oracle JDK download
  • Sun JDK 6 installation 3
  • Gaggle has well-documented installation process: Here
  • When compilation fails from /external/guava with SortedMap<K, V> onlyOnLeft = Maps.newTreeMap(comparator);
  • Google Group for android-porting has patch for the SortedMap<K, V> compilation error. To be specific, you can just modify Line number 228-229 with this:
     
    228-  public static <C, K extends C, V> TreeMap<K, V> newTreeMap(
    229-      @Nullable Comparator<C> comparator) {
    228+  public static <K, V> TreeMap<K, V> newTreeMap(
    229+      @Nullable Comparator<? super K> comparator) {
    
    

Useful links for Tizen

Wednesday, January 9, 2013

Chromium project

This only gives basic development setup for Chromium project, not Chromium OS.

For the latest version of Chrome Project, you might wanna use: Chrome Canary (a.k.a. Nightly build)

Chromium Project

  • Sync tools - depot tools
  • Here contains bunch of information for depot_tools; such as:
    gclient, gcl, git-cl, hammer, svn, drover, ccplint.py, presubmit_support.py, repo, trychange.py, git-try, wtf, weekly, git-gs, zsh-goodies
  • Sync tools - gyp
  • is a acronym for Generate Your Project. For more details: You can refer to gyp on Google Code or gyp Google Groups
  • Getting the codes - Here
  • ninja build
  • ninja build is build system focused on speed. Here are github page for ninja build, usage for Chromium project, and Google groups for ninja build.

Android.mk

For more details, refer to:Android NDK Documentation

Common used keywords from Android NDK, Revision 8d (December 2012)

Pre-reserved variable names:

  • names that begin with LOCAL_ (e.g. LOCAL_MODULE)
  • names that begin with PRIVATE_, NDK_ or APP_ (used internally)
  • lower-case names (used internally, e.g. 'my-dir')

Module-description variables:

  • LOCAL_PATH
  • This variable is used to give the path of the current file.
  • LOCAL_MODULE
  • This is the name of your module. It must be unique among all module names, and shall not contain any space. You MUST define it before including any $(BUILD_XXXX) script.
  • LOCAL_MODULE_FILENAME
  • This variable is optional, and allows you to redefine the name of generated files. By default, module <foo> will always generate a static library named lib<foo>.a or a shared library named lib<foo>.so, which are standard Unix conventions.
    NOTE: You should not put a path or file extension in your LOCAL_MODULE_FILENAME, these will be handled automatically by the build system.
  • LOCAL_SRC_FILES
  • This is a list of source files that will be built for your module. Only list the files that will be passed to a compiler, since the build system automatically computes dependencies for you. Note that source files names are all relative to LOCAL_PATH and you can use path components.
    NOTE: Always use Unix-style forward slashes (/) in build files. Windows-style back-slashes will not be handled properly.
  • LOCAL_CPP_EXTENSION
  • This is an optional variable that can be defined to indicate the file extension of C++ source files. The default is '.cpp' but you can change it.
  • LOCAL_C_INCLUDES
  • An optional list of paths, relative to the NDK *root* directory, which will be appended to the include search path when compiling all sources (C, C++ and Assembly).
  • LOCAL_CFLAGS
  • An optional set of compiler flags that will be passed when building C *and* C++ source files.
  • LOCAL_CXXFLAGS
  • An alias for LOCAL_CPPFLAGS. Note that use of this flag is obsolete as it may disappear in future releases of the NDK.
  • LOCAL_CPPFLAGS
  • An optional set of compiler flags that will be passed when building C++ source files *only*. They will appear after the LOCAL_CFLAGS on the compiler's command-line.
  • LOCAL_STATIC_LIBRARIES
  • The list of static libraries modules (built with BUILD_STATIC_LIBRARY) that should be linked to this module. This only makes sense in shared library modules.
  • LOCAL_SHARED_LIBRARIES
  • The list of shared libraries *modules* this module depends on at runtime. This is necessary at link time and to embed the corresponding information in the generated file.
  • LOCAL_WHOLE_STATIC_LIBRARIES
  • A variant of LOCAL_STATIC_LIBRARIES used to express that the corresponding library module should be used as "whole archives" to the linker. See the GNU linker's documentation for the --whole-archive flag. This is generally useful when there are circular dependencies between several static libraries. Note that when used to build a shared library, this will force all object files from your whole static libraries to be added to the final binary. This is not true when generating executables though.
  • LOCAL_LDLIBS
  • The list of additional linker flags to be used when building your module. This is useful to pass the name of specific system libraries with the "-l" prefix.
  • LOCAL_ALLOW_UNDEFINED_SYMBOLS
  • By default, any undefined reference encountered when trying to build a shared library will result in an "undefined symbol" error. This is a great help to catch bugs in your source code.
  • LOCAL_ARM_MODE
  • By default, ARM target binaries will be generated in 'thumb' mode, where each instruction are 16-bit wide. You can define this variable to 'arm' if you want to force the generation of the module's object files in 'arm' (32-bit instructions) mode.
  • LOCAL_ARM_NEON
  • Defining this variable to 'true' allows the use of ARM Advanced SIMD (a.k.a. NEON) GCC intrinsics in your C and C++ sources, as well as NEON instructions in Assembly files.
  • LOCAL_DISABLE_NO_EXECUTE
  • Android NDK r4 added support for the "NX bit" security feature. It is enabled by default, but you can disable it if you *really* need to by setting this variable to 'true'.
  • LOCAL_EXPORT_CFLAGS
  • Define this variable to record a set of C/C++ compiler flags that will be added to the LOCAL_CFLAGS definition of any other module that uses this one with LOCAL_STATIC_LIBRARIES or LOCAL_SHARED_LIBRARIES.
  • LOCAL_EXPORT_CPPFLAGS
  • Same as LOCAL_EXPORT_CFLAGS, but for C++ flags only.
  • LOCAL_EXPORT_C_INCLUDES
  • Same as LOCAL_EXPORT_CFLAGS, but for C include paths. This can be useful if 'bar.c' wants to include headers that are provided by module 'foo'.
  • LOCAL_EXPORT_LDLIBS
  • Same as LOCAL_EXPORT_CFLAGS, but for linker flags. Note that the imported linker flags will be appended to your module's LOCAL_LDLIBS though, due to the way Unix linkers work.
  • LOCAL_FILTER_ASM
  • Define this variable to a shell command that will be used to filter the assembly files from, or generated from, your LOCAL_SRC_FILES.

NDK-provided variables:

  • $CLEAR_VARS
  • Points to a build script that undefines nearly all LOCAL_XXX variables listed in the "Module-description" section below. You must include the script before starting a new module.
  • $BUILD_SHARED_LIBRARY
  • Points to a build script that collects all the information about the module you provided in LOCAL_XXX variables and determines how to build a target shared library from the sources you listed. Note that you must have LOCAL_MODULE and LOCAL_SRC_FILES defined, at a minimum before including this file.
    this will generate a file named lib$(LOCAL_MODULE).so
  • $BUILD_STATIC_LIBRARY
  • This is the same as PREBUILT_SHARED_LIBRARY, but for a static library file instead.
  • $PREBUILT_SHARED_LIBRARY
  • Points to a build script used to specify a prebuilt shared library. Unlike BUILD_SHARED_LIBRARY and BUILD_STATIC_LIBRARY, the value of LOCAL_SRC_FILES must be a single path to a prebuilt shared library (e.g. foo/libfoo.so), instead of a source file.
  • $PREBUILT_STATIC_LIBRARY
  • This is the same as PREBUILT_SHARED_LIBRARY, but for a static library file instead.
  • $TARGET_ARCH
  • Name of the target CPU architecture as it is specified by the full Android open-source build. This is 'arm' for any ARM-compatible build, independent of the CPU architecture revision.
  • $TARGET_PLATFORM
  • Name of the target Android platform when this Android.mk is parsed. For example, 'android-3' correspond to Android 1.5 system images.
  • $TARGET_ARCH_ABI
  • Name of the target CPU+ABI when this Android.mk is parsed. Two values are supported at the moment: armeabi, armeabi-v7a
  • $TARGET_ABI
  • The concatenation of target platform and ABI, it really is defined as $(TARGET_PLATFORM)-$(TARGET_ARCH_ABI) and is useful when you want to test against a specific target system image for a real device. By default, this will be 'android-3-armeabi'

NDK-provided function macros:

  • my-dir
  • Returns the path of the last included Makefile, which typically is the current Android.mk's directory.
  • all-subdir-makefiles
  • Returns a list of Android.mk located in all sub-directories of the current 'my-dir' path.
  • this-makefile
  • Returns the path of the current Makefile (i.e. where the function is called).
  • parent-makefile
  • Returns the path of the parent Makefile in the inclusion tree, i.e. the path of the Makefile that included the current one.
  • grand-parent-makefile
  • Returns the path of the grand-parent Makefile in the inclusion tree.
  • import-module
  • A function that allows you to find and include the Android.mk of another module by name.

Tuesday, January 8, 2013

Machine Learning

Stanford UFLDL Google Tensorflow

RoR: get started

Prerequisite


Ruby

Here is interesting quote from the chief designer of Ruby, Yukihiro Matsumoto
Often people, especially computer engineers, focus on the machines. They think, "By doing this, the machine will run faster. By doing this, the machine will run more effectively. By doing this, the machine will something something something." They are focusing on machines. But in fact we need to focus on humans, on how humans care about doing programming or operating the application of the machines. We are the masters. They are the slaves.
Ruby is a dynamic, reflective, general-purpose object-oriented programming language that combines syntax inspired by Perl with Smalltalk-like features. It was also influenced by Eiffel and Lisp. Ruby supports multiple programming paradigms, including functional, object oriented and imperative. It also has a dynamic type system and automatic memory management; it is therefore similar in varying respects to Smalltalk, Python, Perl, Lisp, Dylan, and CLU.

Ruby on Rails a.k.a Rails

Ruby on Rails, often simply Rails, is an open source web application framework which runs on the Ruby programming language. It is a full-stack framework: it allows creating pages and applications that gather information from the web server, talk to or query the database, and render templates out of the box. As a result, Rails features a routing system that is independent of the web server. Ruby on Rails emphasizes the use of well-known software engineering patterns and principles, such as active record pattern, convention over configuration, don't repeat yourself, and model-view-controller.

jRuby

JRuby is an implementation of the Ruby programming language atop the Java Virtual Machine, written largely in Java. It is free software released under a three-way CPL/GPL/LGPL license. JRuby is tightly integrated with Java to allow the embedding of the interpreter into any Java application with full two-way access between the Java and the Ruby code (similar to Jython for the Python language).

RubyGems

RubyGems is just a package manager for the Ruby programming language that provides a standard format for distributing Ruby programs and libraries (in a self-contained format called a "gem"), a tool designed to easily manage the installation of gems, and a server for distributing them.

Ruby on Rails installation: For Ubuntu (12.10 especially),

$ sudo add-apt install ruby1.9.3
$ sudo gem install rails
$ rails new $PATH
$ cd $PATH
$ rails server
For Mac OS X (Mountain Lion especially), Install homebrew, then

$ brew install ruby
$ gem install rails
$ rails new $PATH
$ cd $PATH
$ rails server
and that's it! You can check the http://localhost:3000 (by default)

If you face any errors with
/var/lib/gems/1.8/gems/execjs-1.4.0/lib/execjs/runtimes.rb:51:in `autodetect': Could not find a JavaScript runtime.
, try to install nodejs.

Monday, January 7, 2013

HTML5 on Mobile

HTML5 on Android


Titanium


PhoneGap


Ansca Mobile


Appcelerator


Useful links


envsetup.sh

Refer to: Building the System from Android and Android Build System from KAndroid

envsetup.sh
- lunch: lunch -
- tapas: tapas [ ...] [arm|x86|mips] [eng|userdebug|user]
- croot: Changes directory to the top of the tree.
- m: Makes from the top of the tree.
- mm: Builds all of the modules in the current directory.
- mmm: Builds all of the modules in the supplied directories.
- cgrep: Greps on all local C/C++ files.
- jgrep: Greps on all local Java files.
- resgrep: Greps on all local res/*.xml files.
- godir: Go to the directory containing a file.

Tizen build setup

Tizen released SDK 2.0 Alpha
Build environment setup for Ubuntu 12.10