Saturday 22 February 2014

Creating Custom Views in Android: User Defined Views

So you are accustomed to created views using the layout XML files in Android. Let us see how you can more efficiently control the user interface creating your own custom view. This tutorial expects that you have set up Android in your system and that you can run apps that you write in simulator, or even better, on a real device.

Create a new Android application using Eclipse. Modify your activity java class (MainActivity) and add a new java class(MyView). Here is a sample of your source files:

<MainActivity.java>

package com.first;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {
   
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        MyView view =new MyView(this);
        setContentView(view);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
   
}

<MyView.java>

package com.first;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Paint.Style;
import android.graphics.Typeface;
import android.widget.ImageView;

public class MyView extends ImageView {

    private Paint paint;
    private int width;
    private int height;

    public MyView(Context context) {
        super(context);
        paint = new Paint();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        //hello world
        paint.setTypeface(Typeface.DEFAULT_BOLD);
        paint.setTextSize(16);
        paint.setColor(Color.BLACK);
        paint.setTextAlign(Align.CENTER);
        String text = "Hello there!";
        canvas.drawText(text, width / 2, height/2, paint);

        // footer
        paint.setTypeface(Typeface.DEFAULT_BOLD);
        paint.setTextSize(12);
        paint.setColor(Color.BLUE);
        paint.setTextAlign(Align.CENTER);
        String footer = "© Varun Nair.";
        canvas.drawText(footer, width / 2, height - 25, paint);
    }

    @Override
    public void onSizeChanged(int w, int h, int oldW, int oldH) {
        height = h;
        width = w;
    }
}

Tuesday 18 February 2014

Travelling with Android: City Apps

You need to look at a lot of things while you are on a tour- catch a bus, navigate while trekking, find nearby restaurants, go to the nearest ATM and so on. Let us see how the Android world will come to our assistance while you are on the road.

In this age of augmented reality gadgets and apps, we will see a transformation in the way we move about in our cities and towns. You can expect a lot in augmented reality navigation with wearable devices like Galaxy Watch, Google Glass or Pebble and apps like Layar, Wikitude or Google Goggles.

Google Maps is Enough, Right?

Well I never have used anything other than Google Maps while traveling just because it is a headache to keep different useful apps ready while I go out of town.Google Maps may not be the one for your purpose here as it just gives a whole lot of information and expects us to search for it.

What you need while traveling is to have in hand the information that you need without having to dig for a needle in a haystack. This is exactly what City apps brings to the table.


OK, What do You have for Me?

I had a look at the '10 best apps for traveling abroad' listed by Mashable which will give me some idea- listed there is the usual paraphernalia of apps. And then I poked around the Android ecosystem a bit experimenting with some of those apps.

Here is what I did not find useful. I checked out an app for Indian cities- City Guide and it did not even work in the Sony Xperia Mini Pro Gingerbread and Jelly Bean Samsung Galaxy Grand that I tested. There are some other travels apps like TripAdvisor- but they are available for only a handful of cities- only Mumbai and Delhi in India!

What Can I Actually Use?

AroundMe is the most useful app that you can find here- it will always come to your rescue when you have to find a nearby ATM, restaurants, movie thearters, gas stations and what not. Its good to have this app instead of separate apps for doing them. You can have this app if you don't have nothing else other that Google Maps!

If you are traveling in a foreign country, you might find iTranslate very useful for speech-to-text conversion (and vice-versa too) while talking to a native, apart from for translating languages while reading SMS or sending emails.

HeyWire is a messaging app much like Whatsapp and Skype or even like Viber and Tango, the difference being you can message to any number in the world! You will be given a US number and you can message for free back to any number from almost anywhere in the world, whether they are using HeyWire or not. (Sending message costs money but HeyWire get the revenue from ads placed int the app) You can post Tweets, share songs and pictures; and it is a meme generator too! But sadly in India, HeyWire users can message to HeyWire users only. So Whatsapp, Tango or Viber should suffice for now.

Monday 17 February 2014

Looking Through Google Glass

If the new trend around the corner was the rise of smartphones and tablets for a few years now, the stage is all set now for the era of wearable devices. A decade later we would not be able to live without these things. We are now looking at the era of wearable gadgets. Here comes a smart goggles from Google- the Glass!

Wearable devices will be transforming our lives just the way smartphones and tablets have turned our way around. We carry around portable computers now. Now its our turn to wear the computers!

What it does?

Tell the Glass, 'OK Glass, take a picture' and you can take a snap of what you are looking at. The Glass can record videos live and hand-free just as those events unveil in front of you- just tell your Glass to do it for you. You can even give virtual tours to your Hangout friends by video conferencing through the Glass. Share those cool pictures and awesome performances on the go to your favourite social networks and groups just by telling 'OK Glass, share with... so and so... '. See beyond the horizons as navigation information is overlaid on your glass. You get the picture.

You can send messages to your friends while the action unfolds- walking, running, playing cricket, kayaking or almost anything. 'OK Glass, Google Sachin Tendulkar' if you want to know about Sachin. You can Google search on the go. If you don't know Spanish and you want to wish someone good morning in Spanish, you can just ask 'how do you say good morning in Spanish?' and hear how you say it in Spanish. If you are in Japan and you can't read the signs, take a picture and translate it. You can check movies on theatres nearby, check train schedules and so on. Get auto updates from your calendar events and meetings without having to look for them in your smartphone.

The Google Glass is now just a starter hand-free voice-activated assistant who can do some cool things. The Glass in a matter of time, will be able to do what you would want it to do and it will go from 'cool' to 'useful'.


Geeky Looks

The Google glass sports a light, modular and strong design. Google Glass' geeky design comes in many shades, frames and colors- cotton, sky, tangerine, charcoal and shale. Google glass uses light titanium frames and the glasses use Zeal and Maui Jim optics. These compact twist-on frames are impact resistant. The earbud pieces are available in five colors too.
At present only US residents can join the Explorer program for Google Glass. In some time you can see people going around wearing the Glass and talking to themselves- 'OK Glass, Google... do this, and do that... '!

QWERTY Keyboards and Touchscreens

We all learned to type on a QWERTY keyboard and it has crept up into something so natural that our muscles have started to remember them. In this era of smartphones, the traditional physical QWERTY has now a touchscreen cousin. So which do you prefer- the QWERTY keyboard or the touchscreen?

Nowadays we see keyboards in a horde of avatars in desktops, laptops, tablets and smartphones. The era of the petite handheld devices has heralded a radical change in our conception of a keyboard- now they have a new touchscreen design.

Why is QWERTY 'QWERTY'?

The QWERTY keyboard that we see today has historical reasons to have the keys arranged the way it is. Frequently used pairs of letters were spaced out as much as possible because in the age of the typewriters, a fast typist can jam the print hammers of the keys with their typing speed!
Even though in modern computer there is no such limitation, the QWERTY has lived because of the typing standard that it had set which if removed would be so inconvenient. Keyboards will never stop being QWERTY!

Touchscreens to the Fore

The world peeked at wonder at PDAs when they came into the digital world. It was cool. But we really had a good look at the touchscreen keyboards only when the smartphones heaved into reckoning- a trend that evolved with the coming of the first Apple iPhone in 2007. The keyboard in a touchscreen was an instant hit and it became that touchscreens could be much easier to use.

Touchscreens or QWERTY?

Some people still clung to the traditional physical keyboard and this brought the classic conflict among pundits on the better of the two- QWERTY and modern touchscreen keyboards. The simplicity and sleekness of the touchscreen design is not something that you can write off. Once you get accustomed to its ways, a traditional QWERTY keyboard will seem avoidable.
But QWERTYs have their own place- when it comes to act as something that helps you to input data QWERTY keyboards is more useful. When it comes to consuming information and for day-to-day tasks a touchscreen device will suffice. However traditionalists claim that touchscreens are clumsy- they are inaccurate and slows down input.

What to Choose?

If you are asking what to choose- a touchscreen keyboard or a QWERTY, the answer is that it depends on what you want to do with your gadget. If you use for business purposes and have to edit documents and write a lot of emails, then you can consider a physical QWERTY keyboard. A problem with QWERTY keyboards is that they mess up with the smartphone form factor- it almost doubles the phone thickness. QWERTY keyboards don't have much commercial appeal too. For all other purposes, coming to terms with touchscreen keyboard is the best bet.