Tuesday, April 30, 2013

Android Tip - Monitor a Location


Your application wants to monitor a particular location and when the device is near that location, you want to perform some actions. This is very useful if you are writing an application that reminds you when you are near to some places of interests.
 
One very cool feature of the LocationManager class is its ability to monitor a specific location. This is achieved using the addProximityAlert() method.

The following code snippet shows how to monitor a particular location so that if the user is within a five-meter radius of that location, your application will fire a PendingIntent object to launch the web browser:

import android.app.Activity;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Bundle;

public class MainActivity extends Activity {
    LocationManager lm;
    PendingIntent pendingIntent;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //---use the LocationManager class to obtain
        // locations data---
        lm = (LocationManager)
            getSystemService(Context.LOCATION_SERVICE);
    }

    @Override
    public void onResume() {
        super.onResume();
   
        //---PendingIntent to launch activity if the user
        // is within the proximity of some locations---
        pendingIntent = PendingIntent.getActivity(
            this, 0, new
            Intent(android.content.Intent.ACTION_VIEW,
                   Uri.parse("http://www.amazon.com")), 0);

        lm.addProximityAlert(37.422006, -122.084095,
                             5, -1, pendingIntent);
    }   

    @Override
    public void onDestroy() {
        super.onDestroy();
       
        lm.removeProximityAlert(pendingIntent);   
    }
   
}

The addProximityAlert() method takes five arguments: latitude, longitude, radius (in meters), expiration (time for the proximity alert to be valid, after which it will be deleted; -1 for no expiration), and the PendingIntent object.

Note that if the Android device’s screen goes to sleep, the proximity is also checked once every four minutes in order to preserve the battery life of the device. Also, your app would need the
android.permission.ACCESS_FINE_LOCATION permission.

Come Join Our Android Courses to Learn More!

17-18 June 2013

24-25 June 2013

26 June 2013

Sunday, April 28, 2013

Xamarin Tip: Loading an Image


You have some images in your application bundle and want to display one of the images in your application UI.

Assuming you have the Images folder within the Resources folder. Within the Images folder, you have an image named “A Good Day to Die Hard.jpg”. You can load an UIImageView view with the following method:

    this.imageView.Image = 
        UIImage.FromFile("Images/A Good Day to Die Hard.jpg");
The UIImage.FromFile() method loads the image asynchronously. It also allows the application to load the image from an external location.

Alternatively, you can also use the UIImage.FromBundle() method to load the image:

this.imageView.Image = 
    UIImage.FromBundle("Images/A Good Day to Die Hard.jpg");

Unlike the UIImage.FromFile() method, the UIImage.FromBundle() method is a blocking call and only loads images from within the application bundle. However, it caches the images aftre loading it. In general, use the UIImage.FromBundle() method if you need to frequently load the same image. Otherwise, use the UIImage.FromFile() method as it is asynchronous and will not block your UI. 

Xamarin Tip: Implementing Protocols and Delegates in iOS Apps


If you are familiar with iOS development using Objective-C and are in the process of converting to using C# in Xamarin, here is a common problem you will frequently encounter. How do you implement protocols and delegates in C#? A classic example is that of the UIAlertView class. Using the UIAlertView class, you can display an alert view together with one or more buttons. When the user taps on the button(s), you want to know which button was tapped.

To implement an Objective-C protocol in C#, simply declare a sub-class of the protocol. In the case of the UIAlertView class, the subclass would look like this:

    public class MyAlertDelegate : UIAlertViewDelegate {
        public override void Clicked (UIAlertView alertview,
        int buttonIndex)
        {
            Console.WriteLine(buttonIndex.ToString() +
            " clicked.");
        }
    }

To implement the protocol, create an instance of the MyAlertDelegate class:

        MyAlertDelegate alertDelegate;
        alertDelegate = new MyAlertDelegate();

And then use it together with the UIAlertView object, like this:

        UIAlertView alert =
            new UIAlertView("Hello, World!",
                            "Welcome to Xamarin, ",
                            alertDelegate,
                            "OK",
                            "Cancel");
        alert.Show();

When a button in the alert view is now tapped, a message will be printed in the console window. 

Attending the Xamarin Training in Singapore. Check out this link for more details. 

Friday, April 26, 2013

Download the free updated Chapter 7 on Google Maps for Android v2.0

As my new book Android Application Development Cookbook: 93 Recipes for Building Winning Apps goes to press, version 1.0 of the Google Maps for Android was deprecated and replaced by version 2.0. As a service to my readers, I have worked together with the publisher to make the revised Chapter 7 featuring Google Maps for Android v2.0 available for download free of charge.

You can download the chapter here.








Thursday, April 25, 2013

CSH101 – 2-Day Object-Oriented Programming using C#


Since the release of the Microsoft .NET Framework in July 2000, the C# programming language has gone through a few revisions, with the latest version 5.0. Over the years, the C# language has gained a lot of followers, partly due to its familiar syntax to Java and C. The clear syntax of the language made it easy to learn, and is a popular choice for beginning programmers.

Coupled with Visual Studio, Microsoft’s flagship development environment, developing applications using C# is now available to a wide audience. In this fast-pace 2-day course,
attendees will gain a solid foundation in C# programming. In particular, special focus will be placed on Object-Oriented Programming (OOP) using C#.

Topics
• Basics of the .NET Framework
• C# language syntax
• Data Types
• Arrays and Collections
• Making Decisions
• Exception Handling
• Motivations for Object-Oriented Programming (OOP)
    o Classes
    o Objects
• Interfaces
• Inheritance
• Delegates and Events
• Generics
• Advanced Topics
    o Threading
    o Files and Streams

Course outlines and application form here.

Venue
Bayview Hotel
30 Bencoolen Street
Singapore 189621

Date
27-28 Jun 2013 (Thu-Fri)

Time
9am to 5pm

Fee
S$997

Download the Developer Learning Solutions app from iTunes AppStore

In the upcoming months, I have a series of exciting new courses that I will be running. Besides checking the schedules on this site, you can also download the Developer Learning Solutions app from the iTunes AppStore.

Once the app is installed, launch it and you will see a list of course categories:


Select the category of interest to you. For example, if you are interested in Android programming, click on the Android category and you will be shown a list of courses related to this category:


Select the course that you are interested in and the app will download the course outline and application form. In this screen, you have the option to email the PDF copy of the course outline and application form to someone who might also be interested in this course. 


If you tap on the calendar icon
located at the top-right corner of the page, you will see the course schedule for the course:


Select the schedule that you are interested in. You will now see the details of the course, such as venue, fees, etc. On this page you will be able to tweet about the course, as well as add an entry to your calendar on your phone:


For quick registration, you can tap on the registration icon on the page:


You will be able to email us your details for the purpose of registration. We will contact you to follow up with the payment information, etc. 


Hope to see you at my course!

New Course - MOB101 – 3-Day Writing Cross Platform iOS and Android Apps using Xamarin and C#

In this 3-day workshop, you will learn the fundamentals of building cross-platform mobile apps targeting iOS and Android devices using Xamarin and C#.

Using the Xamarin Studio, you cannow write iOS and Android apps using your familiar C# language. When you are ready to deploy your apps, the Xamarin compiler will compile your app into the native binary for each platform. The end result is you have a first class application that is optimized for the respective platform that it is compiled for.

Topics
• Introduction to Xamarin and Xamarin Studio
• HelloWorld using Xamarin Studio
• Using the emulators and simulator
• Handling Screen Rotations
• User interface Design
• Multi-screen applications
• Files Handling & Data Storage
• Cross-platform Code Sharing for Android and iOS
    o Strategies for cross-platform code sharing
    o Web Services
    o Data Storage

Course outlines and application form here.

Venue
Bayview Hotel
30 Bencoolen Street
Singapore 189621

Date
19-21 Jun 2013 (Wed-Fri)

Time
9am to 5pm

Fee
S$1,495.
Register before 1 June to enjoy a S$100 early bird discount!

Monday, April 22, 2013

Updated Course Schedule for April to Jul 2013


Courses
Apr 2013
May 2013
Jun 2013
Jul 2013
iOS/iPhone/iPad




S$997/pax
8-9 Apr
(Mon-Tue)
9-10 May
(Thu-Fri)
12-13 Jun
(Wed-Thu)
1-2 Jul
(Mon-Tue)
Updated
S$997/pax
11-12 Apr
(Thu-Fri)
13-14 May
(Mon-Tue)

4-5 Jul
(Thu-Fri)
S$599/pax
10 Apr
(Wed)


3 Jul
(Wed)
Updated
S$599/pax
29 Apr
(Mon)
Updated


12 Jul
(Fri)
Updated
S$599/pax




S$599/pax




S$1000/pax




IOS206 – Developing Core Data Applications
S$599/pax




S$1,495/pax


19-21 Jun
(Wed-Fri)

IOS207 – Developing iPhone Web Apps using Dashcode
S$997/pax 









Android




S$997/pax
22-23 Apr
(Mon-Tue)
16-17 May
(Thu-Fri)

25-26 May
(Sat-Sun)
17-18 Jun
(Mon-Tue)

S$997/pax
24-25 Apr
(Wed-Thu)
6-7 May
(Mon-Tue)
24-25 Jun
(Mon-Tue)

S$599/pax




S$599/pax




S$599/pax
5 Apr
(Fri)
22 May 2013
(Wed)


S$599/pax
19 Apr
(Fri)
3 May 2012
(Fri)
Updated

23 May 2013
(Thu)
14 Jun
(Fri)

S$1,495/pax


19-21 Jun
(Wed-Fri)

S$599/pax

21 May 2013
(Tue)
26 Jun
(Wed)






Windows Phone




S$997/pax
16-17 Apr
(Tue-Wed)



S$997/pax
18-19 Apr
(Thu-Fri)








Macintosh



















Microsoft Programming




S$599/pax




S$599/pax




S$997/pax


27-28 Jun
(Thu-Fri)


S$997/pax

2-3 May
(Thu-Fri)








Hardware




S$599/pax