Friday, February 7, 2014

Custom Toast

        In this tut , I am going to show you how to create custom toast.There are 3 steps to create custom toast.

1.Create a layout file that defines what your toast should display.
2.Create a simple toast using the following constructor.
    Toast toast = new Toast(Context c)
    Now remember , Don't use Toast.maketext(); because we are creating a custom toast.
    Set properties like duration and gravity.
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setGravity(Gravity.CENTER,0,0);
    Don't show() toast yet.
3.Construct the View from XML that will be used as the Toast's View.
    LayoutInflater lin = getLayoutInflater();
    View appear = lin.inflate(int(id of XML), ViewGroup);
    toast.setView(appear);
    toast.show();

Open “res/layout/activity_main.xml” file, add a button.

File : res/layout/activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="showCustomtoast"
        android:text="Show custom toast" />

</RelativeLayout>

Create a new XML file in res/layout and paste this code.

File : res/layout/custom_toast.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:id="@+id/root"
    android:layout_height="match_parent" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/toast_custom" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/imageView1"
        android:layout_marginTop="34dp"
        android:text="Hello from Jaydeep"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>

Open MainActivity.java file and paste following code.

package com.example.customtoast;

import android.os.Bundle;
import android.app.Activity;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);   
    }
   
    public void showCustomtoast(View v)
    {
        // TODO Auto-generated method stub
        Toast t = new Toast(getApplicationContext());
        t.setDuration(Toast.LENGTH_LONG);
        t.setGravity(Gravity.BOTTOM, 0, 0);
       
        LayoutInflater inflater = getLayoutInflater();
        View appearance = inflater.inflate(R.layout.custom_toast, (ViewGroup)findViewById(R.id.root));
        t.setView(appearance);
        t.show();
    }

    @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;
    }

}

Screen shot:





Don't forget to comment. Happy coding..:-)


Thursday, February 6, 2014

Information on Android

As we know today new technologies are introducing day by day. But nowadays one of the most favorite technology that Google introduce to us is Android. Nearly 400 million Android devices activated today.

History:-
Android Inc, was founded in Palo Alto, California, United States . It is developed by Andy Rubin, Rich Miner, Nick Sears and Cris White in October 2003. Google acquired Android Inc. in August 2005. The Open Handset Alliance, a consortium of several companies was formed in November 2007 and Android Beta SDK released in November 2007.
Android:-
Android is an operating system and it is based on Linux Kernel and platform for touch screen mobile devices such as smart phones and tablets. On the other hand, we can say that it is a chunk of software that we port to a device.
  • Android is an open source product as well as capable of running multiple application programs.
  • It is so famous because of its flexibility and ease of resources.
  • Android’s user interface is based on direct manipulation, using touch inputs like swiping, tapping, pinching and reverse pinching to manipulate on-screen objects.
  • It also provide various customize services to users such as customize their home screens with shortcuts to applications and widgets that allow users to display live content, such as emails and weather information, directly on the home screen.
  • Applications also send notifications to the user to inform them of relevant information, such as new emails and text messages.
  • Android's source code is released by Google under the Apache License and this license allows the software to be freely modified and distributed by device manufacturers, wireless carriers and developers.
  • In July 2013, the largest number of applications ("apps"), available for download in Google Play store: over 1 million apps published, and over 50 billion downloads.
  • In May 2012, Android became the most popular mobile OS.
  • In the third quarter of 2013, Android’s share of the global Smartphone shipment market was led by Samsung products that was 81.3%, the highest ever.
  • One billion Android devices in September 2013 have been activated .
Version of Android:-
Google always introduce various modification and versions of android to us. Android versions are as follow:-
  • Platform | Codename | Release Date 
    • Android | Beta | November 5, 2007 |
    • Android 1.0 |- | September 23, 2008 |
    • Android 1.1 |- | February 9, 2009 |
    • Android 1.5 | Cupcake | April 30, 2009 |
    • Android 1.6 | Donut | September 15, 2009 |
    • Android 2.1 | Éclair | October 26, 2009 |
    • Android 2.2 | Android 2.2 | May 20, 2010 |
    • Android 2.3 | Gingerbread | December 6, 2010 |
    • Android 3.0 | Honeycomb | February 22, 2011 |
    • Android 4.0 | Ice Cream Sandwich | October 19, 2011 |
    • Android 4.1 | Jelly Bean | Announced on June 27, 2012; official release date TBA
    • Android 4.2 | Jelly Bean | 29 October 2012
    • Android 4.3 | Jelly Bean | 22 August 2013
    • Android 4.4 | KitKat | 3 September 2013
     
Key features of Android:-
  • Interface – Android’s interface is based on direct manipulation. In this we are using touch inputs like swiping, tapping, pinching and reverse pinching to manipulate on-screen objects.
  • It provide various customize services to users such as allow users to customize display live content, such as emails and weather information, directly on the home screen.
  • Applications of android also send notifications to the user to inform them of relevant information, such as new emails and text messages.
  • ApplicationsAndroid applications also acquired by third party such as Google Play or the Amazon App store.
  • The Play Store application allows users to browse, download and update apps published by Google and third-party developers.
  • In July 2013,more than one million applications available for Android in the Play Store.
  • In May 2013, 48 billion apps have been installed from the Google Play store.
  • The functionality of devices that extend by applications, are developed in the Java programming language.
  • Memory management - Android devices are usually battery-powered.
  • It also manage memory to keep low power consumption .When an Android app is no longer in use, the system will automatically suspend it in memory that is save power easily.
  • It manages the apps stored in memory automatically: For example:- when memory is low, the system will begin killing apps and processes that have been inactive for a while, in reverse order since they were last used (i.e. oldest first).
List of Other key features of Android:-
  • An Open Accessory API.
  • Cloud-connected experience.
  • Gaming Improvements.
  • Ability to be a USB host.
  • Rich and versatile camera capabilities.
  • Live Effects for transforming video.
  • Powerful web browsing.
  • Improved email.
Advantages of Android:-
  1. Better User Interface.
  2. Resizable Widgets.
  3. Swipe to dismiss notifications, tasks, and browser tabs.
  4. Quick responses for incoming calls.
  5. Improved text input and spell-checking.
  6. Powerful voice input engine.
  7. Control over network data.
  8. Cloud-connected experience.
  9. Google Experience.
  10. Google Maps and FREE voice-guided Navigation.