Tuesday, April 29, 2014

Android Tip - Displaying App Icons

You often need to display icons in your Android apps. Instead of designing your own, the Android system comes with a set of icons that you can use in your application.

The application icons that come bundled with Android is accessible through the android.R.drawable class.  For example, if you want to display a Share icon on your ImageButton, you simple use the setImageResource() method of the view, like this:

        btnShare = (ImageButton) findViewById(R.id.btnShare);
        btnShare.setImageResource(
            android.R.drawable.ic_menu_share);

The following code snippet shows how you can use Reflection to go through the list of constants defined in the android.R.drawable class and display each icon:

package net.learn2develop.appicons.appicons;

import android.graphics.Color;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.lang.reflect.Field;

public class MainActivity extends ActionBarActivity {

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

        //---display all the icons defined in
        // android.R.drawable---
        DisplayDrawables(android.R.drawable.class);
    }

    //---use reflection to examine the fields in a class---
    public void DisplayDrawables(Class _class){
        LinearLayout linearLayout = (LinearLayout)
            findViewById(R.id.linearLayout);
        LinearLayout.LayoutParams lp = new
            LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);

        final Field[] fields = _class.getDeclaredFields();
        for (Field field : fields) {
            final int drawableId;
            try {
                drawableId = field.getInt(_class);
                ImageButton imageButton = new
                    ImageButton(this);
                imageButton.setImageResource(drawableId);
                imageButton.setLayoutParams(lp);
                imageButton.setBackgroundColor(
                    Color.TRANSPARENT);
                linearLayout.addView(imageButton);

                TextView txtView = new TextView(this);
                txtView.setText(field.getName());
                imageButton.setLayoutParams(lp);
                imageButton.setBackgroundColor(
                    Color.TRANSPARENT);
                linearLayout.addView(txtView);
            } catch (Exception e) {
                continue;
            }
        }
    }

In the activity_main.xml, you use a ScrollView to contain a LinearLayout:

<ScrollView xmlns:android=
    "http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <LinearLayout
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/linearLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingLeft=
            "@dimen/activity_horizontal_margin"
        android:paddingRight=
            "@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:paddingBottom=
            "@dimen/activity_vertical_margin"
        android:orientation="vertical"
        tools:context=
           "net.learn2develop.appicons.appicons.MainActivity">
    </LinearLayout>

</ScrollView>

The following screenshot shows the application icons and their corresponding names:

 


Monday, April 28, 2014

Developing Android UI - 26 June 2014

Want to create professional looking Android UI? Come join our Advanced Android - Developing Android UI course on the 26 June 2014 and you will learn how to build nice-looking Android UI. Among the topics you will learn is how to build an image gallery viewer where you can download files from the Web onto your device and view it on your device. You will also learn how to access your DropBox account and download pictures onto your devices!

Note: This course will use Android Studio.

Venue
Bayview Hotel

Fee
S$699 (nett; no GST)
Includes a lunch and 2 tea-breaks

Time
9am to 5pm

Prerequisites
Basic knowledge of Android Programming

Sunday, April 20, 2014

Courses in June 2014

Please note that the following courses have changes in schedules (http://weimenglee.blogspot.no/2014/05/change-in-course-schedule-in-june-2014.html):

Sunday, April 13, 2014

Learn how to program iBeacons in your Android and iOS apps - CODE Magazine May/June 2014 issue

My article on iBeacon is the cover story for the May/June issue of CODE Magazine! Grab a copy or if you prefer, read the online version here
"One of the buzzwords you hear often is Bluetooth LE, short for Bluetooth Low Energy. Bluetooth LE is a wireless personal area network technology like its previous incarnation, Classic Bluetooth. Most people are familiar with Classic Bluetooth: You pair your Bluetooth headset with your mobile phone and use it to answer your calls, etc.
However, using Bluetooth Low Energy, you don’t necessarily have to pair with a device in order to perform useful work. A number of health-related medical devices, such as the Heart Rate Monitor and Blood Pressure Monitor, allow your mobile device to connect to them and receive vital information about your health. One very cool use of Bluetooth LE is Apple’s iBeacon. Using an iBeacon, a device can detect the presence of an iBeacon and use that information to provide locale-specific functions, such as merchandise promotion, payment information, etc.
In this article, you will learn the basics of Bluetooth LE and explore the world of iBeacons. You will see how you can write iOS and Android apps that use iBeacons to provide location-based services"

Saturday, April 12, 2014

List of Courses for June 2014

I am pleased to launch a couple of new courses this coming June. Check out the list below and more details will be released in the coming days:

16-17 June 2014 (Mon-Tue) - PEB101Foundation of Pebble Programming - $1,295

18 June 2014 (Wed) - AND303Advanced Android - Bluetooth Low Energy Programming - $699

19-20 June 2014 (Thu-Fri) - IOS101 - Foundation of iPhone 
Programming - $1,097


21-22 June 2014 (Sat-Sun) - AND001Developing Android Applications using App Inventor - $1,195

24 June 2014 (Tue) - AND305 - Advanced Android - Developing Android User Interfaces - $699

25-26 June 2014 (Wed-Thu) - AND101Foundation of Android 
Programming - $1,097

27 June 2014 (Fri) - AND304Advanced Android - Android Wear Programming  - $699

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

Thursday, April 10, 2014

Speaking at NDC Oslo on Pebble and Android Wear!


For the upcoming Norwegian Developers Conference (NDC) in Oslo, Norway (2-6 June 2014), my theme is on one key area - Wearable Computing Programming.

Here are the talks that I will be giving:

Programming Pebble
Say Hello to your Google Android Wear Watch

If you are in the area, be sure to say hi!

Wednesday, April 09, 2014

Foundation of iPhone Programming on the 14-15 April is now confirmed!



The Foundation of iPhone Programming course on the 14-15 April is now confirmed! If you have always wanted to learn how to program your iPhone and iPad, come join us! For registration, email weimenglee@learn2develop.net. See you at the course!