Wednesday, March 26, 2014

Comparing Pebble and Android Wear

A number of readers have wrote in to ask me how does Android Wear compare to Pebble. Here is a list of items that I have compiled which I hope would be useful for those of you wanting to choose a wearable platform to develop for.

Note that this is a work-in-progress and I welcome your feedbacks if any of the items listed here is inaccurate. I will update it as more information is made available. 



Android Wear




Pebble








Android Wear is a modified version of the Android OS adapted for wearable devices sich as watches. The primary function of Android Wear is as an extension of your Android device – displaying notifications and allowing users to interact with the device through voice navigation on the wearable device.

The Pebble is a smart watch that allows you to write apps that run on the watch as well as on your mobile device. It displays notifications from your device.

Pebble also allows companion apps running on the mobile devices to provide additional functionalities to the apps running on the Pebble watch.
  
Availability
Devices such as Moto 360 and LG G watches have been announced; availability not known yet
Pebble and Pebble Steel
Manufacturer support
Motorola, LG, Asus, HTC, Samsung, and more
Pebble
Interaction with users
Voice control and touch screen
Four buttons – Up, Select, Down, and Back
Device Network connectivity
Classic Bluetooth, Bluetooth Low Energy (LE)
Classic Bluetooth, Bluetooth Low Energy (LE)
Hardware Features
Not clear at this moment
Accelerometer, ambient light sensor, magnetometer
Standalone apps
Not available in the Developer Preview release
Yes, watchface apps and watch apps can run standalone on the watch
Companion apps on the mobile device
Android Wear devices require apps on the mobile device to send notifications to it
Companion apps on the mobile device can send notifications as well as provide additional functionalities such as Web services access, location-based services, etc
Connection to mobile device
Requires connection to a Android device
Optional; connection to a mobile device is only required for the installation of watchfaces and watch apps;
Color Screen
Yes
No, only black and white support
Touch Screen
Yes
No
Platform support
Android only
iOS and Android
Supports notifications
Yes. The primarily function of Android Wear is to display notifications from the Android device
Yes. Displays notifications from the iOS and Android device
SDK
Android Wear Developer Preview + Android SDK
Pebble SDK
Programming language support
Java
C (native apps), Javascript, Objective C and Java (Pebble Mobile apps)
Smartphone compatibility
Works with Android 4.3 and above devices. At this moment, Android Wear can only connect to phone devices; but Google has announced that the Android Wear Developer Preview release will be updated to support non-phone devices as well
Works with iOS 6.0 and newer and Android 4.0 and newer devices

Thursday, March 20, 2014

Announcing the AND304 - Foundation of Android Wear Programming

Block your calendar now! I am super excited to announce the launching of a new course - 
AND304 - Foundation of Android Wear Programming


In this course, you will learn how to integrate Android Wear into your Android applications and how you can use your Android wearable to display notifications, perform voice commands, and more!

Details coming soon! Block your calendar now - 25-26 June 2014!



Android Tip: Displaying Dialogs

In Android, you usually use a dialog to solicit a reply from the user. The most commonly used dialog is a yes/no dialog.
  
You can create a dialog using the AlertDialog class. The following shows a quick way to display a yes/no dialog:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       
        new AlertDialog.Builder(this)
        .setTitle("Delete Item")
        .setMessage("Are you sure you want to delete this?")
        .setPositiveButton(android.R.string.yes,
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog,
                                    int which) {
                Toast.makeText(getBaseContext(),
                    "YES", Toast.LENGTH_LONG).show();
            }
         })
        .setNegativeButton(android.R.string.no,
            new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog,
                                int which) {
                Toast.makeText(getBaseContext(),
                    "NO", Toast.LENGTH_LONG).show();
            }
         })
        .setIcon(R.drawable.ic_launcher)
        .show();       
    }

The above code displays the dialog as shown below:
  

Android Tip - Displaying Notifications

In Android, a good way to notify the user outside of your application is through posting a notification in the notification area of the device. The notification will appear until the user opens the notification drawer and taps on it. Usually, tapping the notification will launch the application that displays the notification.

To create a notification, use the NotificationCompat.Builder class to create a Notification object, as shown in the following method:

    private void postNotification(String title, String msg) {
        //---which activity should be launched when the
        // notification is tapped---        
        Intent resultIntent = new Intent(this,
            MainActivity.class);
        PendingIntent pendingIntent =
                PendingIntent.getActivity(
                this,
                0,
                resultIntent,
                PendingIntent.FLAG_UPDATE_CURRENT
            );       
       
        //---create a notification---
        Notification notification = new
            NotificationCompat.Builder(this)   
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle(title)
            .setContentText(msg)
            .setAutoCancel(true)
            .setContentIntent(pendingIntent)
            .setNumber(1)
            .build();
       
        //---set the sound and lights---
        notification.defaults |= Notification.DEFAULT_SOUND;
        notification.defaults |= Notification.DEFAULT_LIGHTS;
       
        //---display the notification---
        notificationManager.notify(
            NOTIFICATION_ID,
            notification);       
    }

Each notification is identified using a notification id. Posting another notification using the same id replaces the previous notifications. You also need to use the NotificationManager class to post the notification:

public class MainActivity extends Activity { 
    private static final int NOTIFICATION_ID = 123;
    NotificationManager notificationManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       
        notificationManager = (NotificationManager)
            getSystemService(
                Context.NOTIFICATION_SERVICE);
    }

You can now post a notification by calling the method that you have just defined:

        postNotification(
            "A sample notification",
            "Just testing the notification...");  


Monday, March 17, 2014

Foundation of Pebble Programming - 7-8 April 2014


The next run of the Foundation of Pebble Programming course would be held on the 7-8 April 2014. Come and learn how to write interesting apps on your Pebble watch. You will also learn how to write Javascript code that communicates with your Pebble watch. Once you learn that, you will be able to write apps that tells your location, displays stock prices, and more!

The fee of S$1,295 includes a Pebble watch! Download course brochures and application form here

Tuesday, March 11, 2014

Schedule for April to June 2014 posted!

I have just posted the new schedule for courses from April to June 2014. Check out the link here for the list of courses. There is something for everybody!



Wednesday, March 05, 2014

HRD101 - Getting Started with Raspberry Pi - 9 April 2014

I am pleased to announce that the next run of the Raspberry Pi course is on 9 April 2014.


Based on feedbacks from the previous runs of the course, we have put in more focus on hardware-related projects, such as:

    * How to build your own CCTV surveillance using a Webcam
    * How to build an iBeacon
    * How to detect motion
    * How to connect to a LCD display to display Twitter feeds

In addition, we will also cover how to set up your own Web server using Apache and PHP!

Venue
Bayview Hotel Singapore
30 Bencoolen Street 
Singapore 189621
9am to 5pm

Fee
S$699 (nett; no GST)

Date
9 April 2014 (Wed)



Download course outline and application form here.

WEB102 – 1-Day Developing HTML5 Web Applications - 20 March 2014

The next run of the HTML5 programming course is on 20 March 2014.

HTML 5 is the new standard for the venerable HTML specification, a standard for displaying Web content. HTML has come a long way, going through a number of revisions - with the last version - 4.01, recommended by the W3C in 1999. The design goal of HTML 5 is to ensure that an application that you write can work on all browsers without the need to install additional plug-ins. It should be able to do everything from animation, to music and videos, local storage, offline applications, and more. HTML 5 is also cross platforms, meaning that your apps should be able to work whether it is run on a notebook, smartphone, tablet, or desktop computer.

In this 1-day course, you will be able to understand and use the new features of HTML5 through working with practical examples.

Topics

          Quick Introduction to HTML
          Crash Course in JavaScript and CSS
          Using Canvas for drawing graphics    
          Using SVG (Scalable Vector Graphics) in your HTML 5 pages
          Implementing drag-and-drop in your Web Pages
          Implementing LBS (Location-Based Services) in your Web applications
          Embedding audios and videos in your Web pages
          Using different input types in your Web pages
          Using Web storage in HTML 5
          Creating offline Web applications
          Creating responsive Web applications using Web Worker
          Implementing notifications in your Web applications through server messaging

Venue
Bayview Hotel Singapore
30 Bencoolen Street 
Singapore 189621

9am to 5pm

Fee
S$699 (nett)

Dates
20 March 2014 (Thu)

Download course outline and application form here.

Sunday, March 02, 2014

Android Tip - Detecting if your App is in the Foreground

Very often, your application will continue to work in the background. When an event occurred (such as entering an iBeacon region),  you might need to inform the user about it. If the application is in the foreground, you can use the Toast class to display a message. If the application is in the background, then a more persistent form of notification is needed, such as using Notification messages. In either case, you need to programmatically check if the application is running in the foreground or background when the event occurred.

Declare the following method named isAppInForeground() in your activity:

    //---helper method to determine if the app is in the
    // foreground---
    public static boolean isAppInForeground(Context context) {
        List tasks =
            ((ActivityManager) context.getSystemService(
             Context.ACTIVITY_SERVICE))
             .getRunningTasks(1);
        if (tasks.isEmpty()) {
            return false;
        }
        return tasks
            .get(0)
            .topActivity
            .getPackageName()
            .equalsIgnoreCase(context.getPackageName());
    }

In order for the method to work, you need to add the GET_TASKS permission in your AndroidManifest.xml file:

    <uses-permission
        android:name="android.permission.GET_TASKS"/>

To check if your app is in the foreground, simply call the isAppInForeground() method:

        if (isAppInForeground(getApplicationContext())) {
            Toast.makeText(this, "App is in the foreground",
                Toast.LENGTH_LONG).show();
        } else {
            //---create notifications, etc---       
        }


If the apps is in the background, you might want to create a notifications, etc, to inform the user.