How to create Hint Spinner

Spinners provide a quick way to select one value from a set. In the default state, a spinner shows its currently selected value. Touching the spinner displays a dropdown menu with all other available values, from which the user can select a new one. For example,

Spin Spinner is view that displays one child at a time and lets the user pick among them. The items in the Spinner come from the "Adapter" associated with this view. By default Spinner comes with selection of first item added on the Adapter. However there are the situation when we want to add some "hint" to a Spinner such as "Please select a value from spinner", but unfortunately there's no hint method for adapter/spinner available. Hence if we want to do so we have to extend the "Adapter" class and override the getCount() method. Here's an example :

HintAdapter.java


import android.content.Context;

import android.widget.ArrayAdapter;

public class HintAdapter extends ArrayAdapter<String> {


public HintAdapter(Context context, int textViewResourceId) {

super(context, textViewResourceId);
// TODO Auto-generated constructor stub
}

@Override

public int getCount() {
// TODO Auto-generated method stub
int count = super.getCount();
return count>0 ? count-1 : count ;
}


}

Now, whenever we want to use our custom "HintAdapter" we can simple instantiate the HintAdapter class as,


HintAdapter adapter = new HintAdapter(Activity_1_2.this, android.R.layout.simple_list_item_1);
adapter.addAll(object_of_items_to_be_added);
adapter.add("Here's our hint");
sp.setAdapter(adapter);
sp.setSelection(adapter.getCount());

Above mention code will show us a spinner with selection "Here's our hint." When we will open the dropdown menu this option will not be there in the available items.

Output of above code would be like this :



Starting with the Android App Development

This post is for those ones who are really interested in app developing with android and want to start developing. There's no doubt that Android has a massive market all over the world. Beside of that it is now growing more and more including more devices to work under Android's environment. From a simple touch screen watch to a smart TV android is found everywhere. However, the App development in Android is not a quite big deal as Google provides all the android SDK tools freely available for all the developers also XDA developers are also their to help the newbies. There are just things required to get started :

1) Setting up the Java Development Kit (JDK) :

You can download the latest version of Java JDK from Oracle's Java site: Java SE Downloads. You will find instructions for installing JDK in downloaded files, follow the given instructions to install and configure the setup. Finally set PATH and JAVA_HOME environment variables to refer to the directory that contains java and javac, typically java_install_dir/bin and java_install_dir respectively.
If you are running Windows and installed the JDK in C:\jdk1.6.0_15, you would have to put the following line in your C:\autoexec.bat file.
set PATH=C:\jdk1.6.0_15\bin;%PATH%
set JAVA_HOME=C:\jdk1.6.0_15
Alternatively, you could also right-click on My Computer, select Properties, then Advanced, thenEnvironment Variables. Then, you would update the PATH value and press the OK button.
On Linux, if the SDK is installed in /usr/local/jdk1.6.0_15 and you use the C shell, you would put the following code into your .cshrc file.
setenv PATH /usr/local/jdk1.6.0_15/bin:$PATH
setenv JAVA_HOME /usr/local/jdk1.6.0_15
Alternatively, if you use an Integrated Development Environment (IDE) Eclipse, then it will know automatically where you have installed your Java.

2) Setting up Android SDK :

You can download the latest version of Android SDK from Android official website : Android SDK Downloads. If you are installing SDK on Windows machine, then you will find a installer_rXX-windows.exe, so just download and run this exe which will launch Android SDK Tool Setup wizard to guide you throughout of the installation, so just follow the instructions carefully. Finally you will haveAndroid SDK Tools installed on your machine.
If you are installing SDK either on Mac OS or Linux, check the instructions provided along with the downloaded android-sdk_rXX-macosx.zip file for Mac OS and android-sdk_rXX-linux.tgz file for Linux. This tutorial will consider that you are going to setup your environment on Windows machine having Windows 7 operating system.
So let's launch Android SDK Manager using the option All Programs > Android SDK Tools > SDK Manager, this will give you following window:
Android SDK Manager
Once you launched SDK manager, its time to install other required packages. By default it will list down total 7 packages to be installed, but it is recommended to de-select Documentation for Android SDK and Samples for SDK packages to reduce installation time. Next click Install 7 Packages button to proceed, which will display following dialogue box:
Android Installation
If you agree to install all the packages, select Accept All radio button and proceed by clicking Installbutton. Now let SDK manager do its work and you go, pick up a cup of coffee and wait until all the packages are installed. It may take some time depending on your internet connection. Once all the packages are installed, you can close SDK manager using top-right cross button.

3) Setting up Eclipse IDE :

To install Eclipse IDE, download the latest Eclipse binaries from http://www.eclipse.org/downloads/. Once you downloaded the installation, unpack the binary distribution into a convenient location. For example in C:\eclipse on windows, or /usr/local/eclipse on Linux and finally set PATH variable appropriately.
Eclipse can be started by executing the following commands on windows machine, or you can simply double click on eclipse.exe
 %C:\eclipse\eclipse.exe
Eclipse can be started by executing the following commands on Linux machine:
$/usr/local/eclipse/eclipse
After a successful startup, if everything is fine then it should display following result:
Eclipse Home page

4) Setting up Android Development Tools (ADT) Plugin :

This step will help you in setting Android Development Tool plugin for Eclipse. Let's start with launching Eclipse and then, choose Help > Software Updates > Install New Software. This will display the following dialogue box.
Android Development Plug-in
Now use Add button to add ADT Plugin as name and https://dl-ssl.google.com/android/eclipse/ as the location. Then click OK to add this location, as soon as you will click OK button to add this location, Eclipse starts searching for the plug-in available the given location and finally lists down the found plugins.
Android Development Plug-ins
Now select all the listed plug-ins using Select All button and click Next button which will guide you ahead to install Android Development Tools and other required plugins.

That's all you need!! Go and start your first HelloWorld App!!


Android Studio :

Besides of Eclipse IDE Google has just released Android Studio 1.0, the first stable version of its own IDE on 8th December, 2014 after keeping under development for 2 years. To know more about it see this post : Android Studio 1.0.
However if you're a JAVA familiar Developer I suggest you to use Eclipse IDE as it is like a home for JAVA developers.

Reference : Tutorials Point

Well, I have build my first Android App during Christmas time name SPI calculator. Must see:

Get it on Google Play

You might be interested in :

Three reasons why the most popular Android OS is built on Linux Kernel?

Android is overwhelming. Its spreading and taking over its competitors. For the readers who don’t know, Android is actually Linux-kernel based operating system for mobile devices! That is Android integrates Linux kernel at the bottom of its software stack. In fact Android was created on top of Linux Kernel 2.6. Have you wondered why did Android team choose Linux Kernel? Read on.


Android is open source, therefore any manufacturer can access it, customize it and adapt it according to the requirements of their own gadget. This is the reason why Android is found on variety of gadgets. With camera, without, high-end and low-end, whether a full-fledged tablet or a low-end entertainment device (like Kindle) Android can run on any platform. This has not only given freedom to manufacturers to customize the operating system, add personalized skin, applications or strip-off default Google services (i.e. endless options), adapt the OS to run on high/low spec gadget but it has also given freedom to people—freedom of choice. You are no longer tied to the single company’s ecosystem. You have myriad of devices to choose from. You no longer need a hefty 500 USD you can get a decent Android tablet for just 100 USD. Thanks to open source nature of Android which has made tablet devices so accessible!

Having introduced you to the much popular Android, let me tell you that Android is built on top of Linux kernel 2.6! Kernel? A kernel is the first layer of software that interacts with the device hardware. The kernel is responsible for providing basic architectural model for process scheduling, resource handling, memory management, networking and isolation etc. It must be noted that while Android is built on Linux Kernel, Google has maintained its own forked version of Linux Kernel specifically for android since 2010.

There are number of reasons for selecting Linux kernel. Linux Kernel boasts some proven core features that are integrated in Android operating system. The features of Linux Kernel are:

1) Portability:

In a post regarding “Who runs Linux?” it's illustrated the fact that Linux runs on devices of diverse architecture from enormous machines like supercomputers to Large Hadron Collider to smaller devices like motor bikes and tiVo. This is due to the fact that Linux is an immensely portable platform. It is fairly easy to compile Linux on various hardware!
What do you think is the major concern of Android? Well that is that it is picked by many manufacturers and is used on a variety of gadgets. Linux makes that possible. Linux brings Android a level of hardware abstraction. Most parts particularly the low-level ones are written in portable C code that can be accessed and modified by manufacturer easily. This means manufacturers can pick up Android and modify it to adapt it according to their hardware requirements rather that improving the hardware to fit the software!

2) Features:

Linux brings to Android some useful features. The Linux Kernel 2.6 includes these features:
Memory Management: While developing for mobile devices memory handling becomes a point of great concern. Thanks to Linux Kernel over which Android is built you can free yourself from the worry. Linux will handle Linux kernel forthreading and lowlevel memory management for Android. Linux kernel is responsible to manage the core feature of any mobile device i.e. memory cache. Linux kernel manages memory by allocating and de-allocating memory for the file system, processes, applications etc.
  1. Process Management: Linux Kernel is responsible to start stop and execute the program. For a beginner a process can be thought of as an instance of computer program. i.e. whenever a program is run on computer the OS creates its instance or process for it which is executed by the OS. In case of Android Linux is responsible to allocate resources to various processes that need them.
  2. Driver Model: As evident this is the layer where all the device specific drivers run. Here Linux ensures that your application is able to run on Android. Manufacturers/ hardware vendors can develop their drivers into Linux in a familiar environment. That is giving plenty room for hardware vendors to optimizing OS. This is one major reason Linux kernel was chosen for Android.
  3. File System Management: Linux also manages the file system which in turn controls the data storage service for android device.
  4. Network Stack: Linux Kernel is responsible to communicate with the network. It also controls networking stack, drivers, routing devices and network adapters.
  5. User account (Security): Linux kernel handles the security between application and the system. Linux takes control of authentication of users and is responsible for user management.Besides this Linux kernel is also responsible for power management and for undertaking various services like internet search, voice communication, system logging etc.
3) Security: 

Linux runs in scientific research labs, supercomputers and systems for mission critical tasks. Android completely relies on Linux for security. All android applications run as distinct Linux processes under permissions set by Linux system.

Above all, Linux is the poster child of open source and Linux is freely available! Its interesting to note that while Android has gained quiet momentum the former popular PALM smartphone running WebOS were also built on Linux kernel!

Reference : UnixMen

Sync audio with your video permanently

So you might have come across  a situation when you finally got your movie after a long wait and then you find that the audio-video is not synchronised. Audio is leading/lagging the video,it is a common problem and VLC media player simple provides for delaying the audio in ms(by pressing J and K keys) for temporary playing. Here's the tutorial how you can permanently sync you audio with the video.

MKV ToolNix :

MKVToolNix’ is not an encoder as you can only use it to ‘extract’ audio/video/subtitle tracks from other containers (MP4, AVI, FLV etc) and put them into the powerful and open-source MKV container. While doing so this tools also lets you pass certain settings (sync, fps, aspect ratio …) and it is through that we can attempt to fix sync problems.

But please be aware that the only output format it support is MKV (and few of its variations such as ‘MKA’ for audio’, ‘MKS’ for subtitles etc) and unlike MP4 or AVI, MKV is not supported by a lot of commercial and strictly hardware based multimedia players. Computer users however do not have to worry about it as popular players (VLC, MPC, PotPlayer, SMPlayer, KMPlayer …) support it. Enough talking, let’s do it!.

Note: Make sure you have downloaded and installed the latest builds of ‘MKVToolNix’ from here. I also recommend that you use VLC because both these utilities are available for multiple operating system platforms, so you can use this ‘guide’ in any of them.

What we are going to do is …

  •  First we are going to play the ‘troublesome’ file in VLC (or any other player that lets you change the sync temporarily) and we will try to identify the proper sync value.
  • Then we will simply enter that sync value into ‘MKVToolNix’ and save it as a new MKV file so that it is saved permanently. That is it!.

Step 1:

So open your ‘troublesome’ file in VLC, and let it play for a few seconds. Then simply press the ‘j’ key on your keyboard. This will make VLC play the audio track a bit ahead of the video. A single click increases the value by 50 milliseconds only, so unless the ‘gap’ is very small, you will have to press it a few times to get see its effect.



Anyhow, if after pressing ‘j’ key for a few times it worsens the ‘gap’, then it is an indication that you actually have to make VLC play the audio track a bit behind (delay) the video. The shortcut key for that is ‘k’. Again, to feel its effect, you might have to press it a few times. If after doing that it seems to shorten the ‘gap’ then it is an indication that you are on the right track. So keep doing that until you come up with the perfect sync value.


So as a general rule, play with ‘j’ and ‘k’ keys, until you find the perfect sync value for that multimedia file. Once you have found it, simply take a note of it (note that depending on the file the value could be positive or a negative one. If it is a negative/minus one, then you should enter a minus sign before entering the value in ‘MKVToolNix’, more below) and close VLC.

Step 2:

Now open ‘MKVToolNix’ and load the ‘troublesome’ file into it. Then under ‘Tracks, chapters and tags’ field, select the audio stream/track (shown below is an example).


Step 3:

Then from under it, click on the ‘Format specific options’ tab and you will see an empty field that says ‘Delay (in ms)’. Now simply enter the sync value you found above into that field.



Make sure to enter a minus sign (-) when needed (-200 for instance)

Step 4:

Now click on the ‘Browse’ button under ‘Output filename’ field. Select a location and a file name for the output MKV file. Once done, simply click on the ‘Start muxing’ button. If everything goes without any errors, try playing the newly saved MKV file and now you should be able to enjoy it without any ‘lip-sync’ issues! See you at the movies. ;)

References : Hectic Geek.

Blueticks on WhatsApp



Apparently, there has been a huge rush of tweets since last night about the trending topic on our beloved app WhatsApp's most confusing feature Blueticks. Some people are irritated with this feature,some are appreciating WhatsApp's this new effort and some people(like i was before writing this post!) are confused what does it actully do? Why it is there? Here's the explanation.

What’s with the blue double check in WhatsApp?

The myth of the double check in WhatsApp has messed with the heads of many users of this app to the point of becoming the cause of a psychological syndrome and many, many breakups(Seriously!). Misinterpreting this little symbol has caused more than one romantic quarrel and now it seems the company is testing a new method to avoid such confusion: the double check will appear in blue when your message has actually been read. Problem solved?
Yesterday's update now officially incorporates this feature on all types of devices. In other words, 
a grey check means the message has been sent
two grey checks that it’s been delivered to the recipient
and two blue checks that it’s been read
Group Chats and Voice Messages :

A blue double check alongside the text is used to occur with voice notes also.It works the same way it worked with the texts. Single tick means voice note has been sent double tick means it has been delivered(may not be played by recipient). Finally, the change of color means that the recording had been played.
Same thing goes with the group messages also.In a group chat, the second check marks will appear when all participants in the group have received your message. The two blue check marks will appear when all participants in the group have read your message.

Updated WhatsApp but not getting BlueTicks?

So,you've updated your whatsapp to latest version still you're not getting bluestick? (I finally figured it out that if both the sender and the receiver have updated their whatsapp to this version then only you can see the blueticks on your chats. However it works the same way even if the receiver has not updated his whatsapp yet.) Try this to know how it works :
(1) Long press on any message you sent.
(2) Selection the option which looks like "i" (info) next to copt and forward option from the panel.(If you're not seeing any such option then you have not updated your whatsapp to the latest version.)


(3) There you go.

In groups you will get the list of the peopl who has read your message. It will look like this:

Previous Myths :
Until now, the tick marks accompanying your WhatsApp messages indicated one of two things : one tick to show that the message had been sent to the recipient and two to show it had been correctly delivered, which did not imply it had been read which was what most of the users had assumed. The myth that the double check=message read eventually became so widespread that the company had to clarify how the ticks actually work on their official Twitter account.
Why people are getting frustrated?
The only way for users to check if their WhatsApp messages had been read previously, was to check the last time the recipient was online, a piece of information that WhatsApp allowed iOS users to opt out of, choosing not to see anyone else’s ‘last seen’ status if they were unwilling to share their own. The feature rolled out to Android users of WhatsApp in March this year, allowing those users who didn’t want the pressure of someone knowing you had seen their message but had chosen not to reply immediately the privacy they had chosen.

The two blue ticks read reports are impervious to this setting, now making it impossible for users to avoid this kind of scrutiny leading to some frustration on Twitter.


Swiping left or long pressing and selecting ‘Info’ on a particular sent message will even go so far as to show you the time at which the recipient read your message.

References : WhatsApp FAQs , Beatriz Rojo

Difference between Declaration, Instantiation and Initialization of the objects in Java

Most of the time Java beginners get confused between the terminology "object","reference","instance". Also, there's a  misunderstanding between Declaration of object, instantiation of the object and initialization of objects. Find out the difference between three of them.

Before we continue remember one most important line "A reference refers (points) to an instance of an object."

1. Declaration of objects:

Declaration of objects in Java is similar as we declare variables of built in data types that is,
data_type   variable_name;

For example,
int  number;

Same way we can declare an object variable that refers to type “Class”. It takes the following syntax,
Class_name   object_variable;

For example,
Person  p;

will declare object variable “p” that refers to type “Person” in the memory heap.(Here we can consider our class to be a user defined data-type.)

If you declare “p” like this, its value will be undetermined until an object is actually created and assigned to it.

Simply declaring a reference variable does not create an object. For that, you need to use the new operator, as described in the next section.

You must assign an object to “p” before you use it in your code. Otherwise, you will get a compiler error.


2. Instantiation of Objects:

Once we have declared the object variable we need to instantiate it with an object of the corresponding data-type i.e. class.

The new operator instantiates a class by allocating memory for a new object and returning a reference to that memory. The new operator also invokes the object constructor.

In short, Instantiating the object means nothing but just allocating the heap memory of the declared object variable of class type.

For above example we can instantiate the object variable “p” like this,
p = new Person();

We can also declare and instantiate the object by following,
Person p = new Person();


3. Initialization of the objects:

The new operator is followed by a call to a constructor, which actually initializes the new object.

Thus, in above statement “ Person(); ” will initialize the actual object and will recognize the appropriate constructor.

Initialization concept can be more precisely understood when we have multiple constructor for the same class. For example,

public class Person {

int age = 20 ;

String name = "Mr. Lazy";

Person(){
System.out.println("Default constructor called.");
}


Person(int argument1){
System.out.println("Constructor with one argument called.");
}


Person(int argument1,int argument2){
System.out.println("Constructor with two arguments called.");
}


public static void main(String args[]){

Person p1 = new Person(); // this will invoke default constructor.

Person p2 = new Person(10); // this will invoke constructor with one argument

Person p3 = new Person(10,20);// this will invoke constructor with two arguments.

}

}

As we can see in this example the Java compiler differentiates the constructors based on the number and the type of the arguments. Thus, the object is initialized based on the arguments provided with it.

Happy coding! :)

"Safely remove your hardware" What's that and Why do we need it?

You might have seen in most of the OS it tells you to safely remove your hardware for instance a flash drive or usb drive. Have you ever wondered what does it mean by "safely removing your hardware"? Most of the time you can see that you pull out your pen drives without such procedures and no harm happened to it. Then why it is there? Here's a complete description to it. 

This is one of those questions that has a short answer and a long answer. The short answer is this: you should probably always eject a drive before removing it, even if the context menu doesn't have an eject option. Mac and Linux will always provide you a way to eject a drive, but like you said, Sometimes Windows doesn't have an obvious "Eject" button for certain drives. On Windows, click the "Safely Remove Hardware" icon in the system tray, choose your drive from the list, and then remove it once it notifies you of its safe removal.

Now, the long answer : In Windows, you can sometimes remove a flash drive without ejecting. Here's a bit more information on how computers deal with USB drives.

Why Computers Want You to Eject Drives:


Obviously, yanking out a drive while it's being written to could corrupt the data. However, even if the drive isn't activelybeing written to, you could still corrupt the data. By default, most operating systems use what's called write caching to get better performance out of your computer. When you write a file to another drive—like a flash drive—the OS waits to actually perform those actions until it has a number of requests to fulfill, and then it fulfills them all at once (this is more common when writing small files). When you hit that eject button, it tells your OS to flush the cache—that is, make sure all pending actions have been performed—so you can safely unplug the drive without any data corruption.



Why Windows Doesn't Bug You to Do It:


Do I Really Need to Eject USB Drives Before Removing Them?Mac and Linux use write caching on pretty much all drives, and will let you eject any drive through your file manager. Windows, however, is a bit more mysterious on this front. It actually disables this write cache feature for drives it sees as "removable", because it knows people are likely to yank them out without ejecting (though you can still eject them by right-clicking on them and pressing "Eject"). As such, disabling this feature on removable drives decreases the chance of data corruption. It keeps the cache enabled on non-removable drives, though—and sometimes it recognizes external USB drives as not removable, which is why your USB drive doesn't have an eject button. Paradoxically, it's also why you need to eject that drive: since Windows doesn't see it as removable, it's enabled the write cache for it, increasing the chance of data corruption.
You can edit the write cache settings for any drive from the Device Manager. Just expand the Disk Drives section, right click on the drive you want to edit, and hit Properties. Go to the Policies tab, and click the "Quick Removal" radio button to disable the cache (or click "Better Performance" to enable the write cache).

Tip : Always keep your disk in Quick Removal Mode.

Why You Should Probably Manually Eject All Your USB Drives Anyway:

Do I Really Need to Eject USB Drives Before Removing Them?
So, unlike OS X and Linux, Windows has a few precautions in place for preventing data loss. However, the write cache isn't the only thing that can cause data loss. Have you ever tried to eject a drive and gotten a "file is in use" error? Sometimes there's something going on in the background you don't know about, or sometimes a program is just being silly and has still locked a file on the drive even if it isn't using it. If you were to yank it out during one of these situations, you could still cause data loss. Ejecting it will warn you of the situation, and let you close the program in question (or use something like Unlocker to unlock the in-use file).


In the end, there's no reason not to eject your drives, and doing so will ensure your data is uber-safe. Windows users may be less likely to experience issues due to the way Windows handles removable drives, but they aren't 100% immune. Ejecting the drive is a great habit to get into, since without it, you wouldn't always know if it were safe to remove or not.

Got questions? Leave it in the comments.

Reference : LifeHacker