Pages

Types of Media Files

Wednesday, 20 November 2013


 

VCEG  -  Video Coding Experts Group
MPEG  -  Moving Picture Experts Group
AAC    -  Advanced Audio Coding 
JPEG, JFIF (.jpg or .jpeg) – Joint Photographic Experts Group – a lossy image format widely used to display photographic images.
GIF –  Graphics Interchange Format
PNG - Portable Network Graphic (lossless, recommended for display and edition of graphic images)
3GP  - Third Generation Partnership Project (3GPP)

What is H.264?

H.264 is a video compression standard known as MPEG-4 Part 10, or MPEG-4 AVC (for "advanced video coding"). It's a joint standard promulgated by the ITU-T Video Coding Experts Group (VCEG) and the ISO/IEC Moving Picture Experts Group (MPEG).

Table 1. File extensions for H.264 files produced for Flash Player playback
File Extension FTYP MIME Type Description
.f4v 'F4V ' video/mp4 Video for Flash Player
.f4p 'F4P ' video/mp4 Protected media for Flash Player
.f4a 'F4A ' audio/mp4 Audio for Flash Player
.f4b 'F4B ' audio/mp4 Audio book for Flash Player

XML Programming

Monday, 21 October 2013

We’ll discuss how to use an XML parser to:
• Process an XML document
• Create an XML document
• Manipulate an XML document

XML Architecture
An XML application is typically built around an XML parser. It has an interface to its users, and an interface to some sort of back-end data store.

U I   < ---->  XML Application | XML Parser    <-------->   Data Source

Definitions -
  1. An XML parser is a piece of code that reads a document and analyzes its structure. 
  2. Software that reads an XML document, identifies all the XML tags and passes the data to application.
  3. Parse means to break (a sentence) down into its component parts of speech with an explanation of the form, function, and syntactical relationship of each part. 
Q. How to use a parser?
Ans . Follow the steps-
1. Create a parser object
2. Pass your XML document to the parser
3. Process the results

Kinds of parsers
There are several different ways to categorize parsers:

• Validating versus non-validating parsers
• Parsers that support the Document Object
Model (DOM)
• Parsers that support the Simple API for XML
(SAX)
• Parsers written in a particular language (Java,
C++, Perl, etc.)

Validating parsers validate XML documents as they parse them. Non-validating parsers ignore any validation errors.

The Document Object Model (DOM)

The Document Object Model is an official recommendation of the World Wide WebConsortium (W3C). It defines an interface that enables programs to access and update the style, structure, and contents of XML documents. XML parsers that support the DOM implement that interface.

Q What you get from a DOM parser?
Ans When you parse an XML document with a DOM parser, you get back a tree structure that contains all of the elements of your document. The DOM provides a variety of functions you can use to examine the contents and structure of the document.

Warning
DOM Parser is slow and consumes a lot of memory when it loads an XML document which contains a lot of data. Please consider SAX parser as solution for it, SAX is faster than DOM and use less memory.

DOM interfaces
The DOM defines several Java interfaces. Here are the most common:

• Node:       The base datatype of the DOM.
• Element:    The vast majority of the objects you’ll deal with are Elements.
• Attr:          Represents an attribute of an element.
• Text:         The actual content of an Element or
  Attr.          Document: Represents the entire XML document. A Document object is referred DOM tree.

 staff.xml
<?xml version="1.0"?>
<company>
 <staff id="1001">
  <firstname>Yuvraj</firstname>
  <lastname>Kakkar</lastname>
  <nickname>Yuvi</nickname>
  <salary>700000</salary>
 </staff>
 <staff id="2001">
  <firstname>Azad</firstname>
  <lastname>Chauhan</lastname>
  <nickname>Jaadu</nickname>
  <salary>200000</salary>
 </staff>
</company>



ReadXMLFile.java
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import java.io.File;
 
public class ReadXMLFile {
 
  public static void main(String argv[]) {
 
    try {
 File fXmlFile = new File("yourdir/staff.xml");
 DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
 DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
 Document doc = dBuilder.parse(fXmlFile);
 

 doc.getDocumentElement().normalize();
 
 System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
 
 NodeList nList = doc.getElementsByTagName("staff");
 
 System.out.println("----------------------------");
 
 for (int temp = 0; temp < nList.getLength(); temp++) {
 
  Node nNode = nList.item(temp);
 
  System.out.println("\nCurrent Element :" + nNode.getNodeName());
 
  if (nNode.getNodeType() == Node.ELEMENT_NODE) {
 
   Element eElement = (Element) nNode;
 
   System.out.println("Staff id : " + eElement.getAttribute("id"));
   System.out.println("First Name : " + eElement.getElementsByTagName("firstname").item(0).getTextContent());
   System.out.println("Last Name : " + eElement.getElementsByTagName("lastname").item(0).getTextContent());
   System.out.println("Nick Name : " + eElement.getElementsByTagName("nickname").item(0).getTextContent());
   System.out.println("Salary : " + eElement.getElementsByTagName("salary").item(0).getTextContent());

  }
 }
    } catch (Exception e) {
 e.printStackTrace();
    }
  }
 
}

RESULT
Root element :company
----------------------------
Current Element :staff
Staff id : 1001
First Name : Yuvraj
Last Name : Kakkar
Nick Name : Yuvi
Salary : 700000
 
Current Element :staff
Staff id : 2001
First Name : Azad
Last Name : Chauhan
Nick Name : Jaadu
Salary : 200000

Draw on BufferedImage with transparent background Java

 Draw on BufferedImage with transparent background Java

 If your Buffered Image has transparent background & you want to use transparent color to draw to solve erase purpose then follow the code given below.

  void eraseCanvase(int x1, int y1, int x2, int y2) {
          int  eraserWidth=10;
         Graphics g = OSC.getGraphics();

         int dist = Math.max(Math.abs(x2-x1),Math.abs(y2-y1));
          double dx = (double)(x2-x1)/dist;
         double dy = (double)(y2-y1)/dist;
         for (int d = 1; d <= dist; d++) {
            int x = (int)Math.round(x1 + dx*d);
            int y = (int)Math.round(y1 + dy*d);
                   // Erase a 10-by-10 block by default  of pixels around (x,y) Customizable.
               if( g instanceof Graphics2D ){
                    Graphics2D g2d = (Graphics2D) g;
                    // make sure the background is filled with transparent pixels when cleared !
                    g2d.setBackground(new Color(0,0,0,0));
                    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_IN, 0.0f));
                    g.clearRect(x-3, y-3, eraserWidth, eraserWidth);            
                }
               repaint(x-3,y-3,eraserWidth,eraserWidth);
            }


In code you can change the eraserWidth value as per desired ie. to make size of eraser.You should use it in case of mouse dragged event .

But if u want to use Eraser on white color BufferedImage the just follow the code

void eraseCanvase(int x1, int y1, int x2, int y2) {
          int  eraserWidth=10;
         Graphics g = OSC.getGraphics();

         g.setColor(Color.WHITE);
         int dist = Math.max(Math.abs(x2-x1),Math.abs(y2-y1));
          double dx = (double)(x2-x1)/dist;
         double dy = (double)(y2-y1)/dist;
         for (int d = 1; d <= dist; d++) {
            int x = (int)Math.round(x1 + dx*d);
            int y = (int)Math.round(y1 + dy*d);

                   // Erase a 10-by-10 block by default  of pixels around (x,y) Customizable.
                                       // Erase a 10-by-10 block of pixels around (x,y)
               g.fillRect(x-eraserWidth/2,y-eraserWidth/2,eraserWidth,eraserWidth);
               repaint(x-eraserWidth/2,y-eraserWidth/2,eraserWidth,eraserWidth);
            }


Change Icon of cursor in Java Desktop Application

Thursday, 17 October 2013

 Change Icon of cursor in Java Desktop Application 


Default cursors supported by Java Desktop Application are listed  below -

 CURSOR TYPES  
Modifier and TypeField and Description
static intCROSSHAIR_CURSOR
The crosshair cursor type.
static intCUSTOM_CURSOR
The type associated with all custom cursors.
static intDEFAULT_CURSOR
The default cursor type (gets set if no cursor is defined).
static intE_RESIZE_CURSOR
The east-resize cursor type.
static intHAND_CURSOR
The hand cursor type.
static intMOVE_CURSOR
The move cursor type.
static intN_RESIZE_CURSOR
The north-resize cursor type.
protected Stringname
The user-visible name of the cursor.
static intNE_RESIZE_CURSOR
The north-east-resize cursor type.
static intNW_RESIZE_CURSOR
The north-west-resize cursor type.
protected static Cursor[]predefined
Deprecated.
As of JDK version 1.7, the getPredefinedCursor(int) method should be used instead.
static intS_RESIZE_CURSOR
The south-resize cursor type.
static intSE_RESIZE_CURSOR
The south-east-resize cursor type.
static intSW_RESIZE_CURSOR
The south-west-resize cursor type.
static intTEXT_CURSOR
The text cursor type.
static intW_RESIZE_CURSOR
The west-resize cursor type.
static intWAIT_CURSOR
The wait cursor type.


If u want to add custom image of cursor use following code -

Loading the Cursor Image
The image for the custom cursor needs to be loaded into an Image object.

Image image = Toolkit.getDefaultToolkit().getImage("image.png");  // place image in root folder of ur project

Defining the Cursor Hot Spot
The cursor hot spot is used for the point location in mouse events. For a cursor such as a cross-hair cursor, the hot spot would be in the center of the cursor. In our example, the cursor hot spot will be at the pencil point or the point 0,0.

           Point hotSpot = new Point(0,0);

Creating the Custom Cursor
To create the custom image, we put together the cursor image and the hot spot:

           Cursor oneDisk =getToolkit().createCustomCursor(image, hotSpot,"string ");

Displaying the Custom Cursor
The final step is to notify the component to display the cursor.

           PaintWithOnScreenCanvas.this.setCursor(oneDisk);

Packaging and Deploying Desktop Java Applications

Tuesday, 15 October 2013

Packaging and Deploying Desktop Java Applications

Prerequisites

This tutorial has no prerequisites.
Software or ResourceVersion Required
NetBeans IDEJava SE, Java, or All bundle
Java Development Kit (JDK)version 6 or
version 5

Building the Project and Creating the JAR File

Now that you have your sources ready and your project configured, it is time to build your project.
To build the project:
  • Choose Build > Build Main Project.
When you build your project:
  • build and dist folders are added to your project folder (hereafter referred to as the PROJECT_HOME folder).
  • All of the sources are compiled into .class files, which are placed into the PROJECT_HOME/build folder.
  • A JAR file containing your project is created inside the PROJECT_HOME/dist folder.
  • If you have specified any libraries for the project (in addition to the JDK), a lib folder is created in the dist folder. The libraries are copied intodist/lib.
  • The manifest file in the JAR is updated to include entries that designate main class and any libraries that are on the project's classpath.

To add the JAR file association on Microsoft Windows systems:

  1. Make sure that there is a version of the JRE installed on your system. You should use version 1.4.2 or later. (If you have the JDK installed, you also get the JRE. However, if you are distributing the program to a non-programmer, that person does not necessarily have either the JRE or the JDK.)
    On Windows XP, you can check for installed versions of the JRE by choosing Start > Control Panel > Add or Remove Software.
    If there is not a JRE on the system, you can get one from the Java SE download site.
    If you have a JRE installed on your system but the file association is not working, continue with the steps below.
  2. Choose Start > Control Panel.
  3. Double-click Folder Options.
  4. Select the File Types tab.
  5. In the Registered File Types list, select JAR File.
  6. In the Details section of the dialog box, click Change.
  7. In the Open With dialog box, select Java Platform SE Binary.
  8. Click OK to exit the Open With dialog box.
  9. Click Close to exit the Folder Options dialog box.
If JAR files are associated with the Java Platform SE Binary on your system but double-clicking still does not execute the file JAR file, you might need to specify the -jar option in the file association.
To specify the -jar option in the file association:
  1. Choose Start > Control Panel.
  2. Double-click Folder Options.
  3. Select the File Types tab.
  4. In the Registered File Types list, select JAR File.
  5. In the Details section of the dialog box, click Advanced.
  6. In the Edit File Type dialog box, click Edit.
  7. In the Application Used to Perform Action text field, add the following at the end of the path to the JRE:
     -jar "%1" %*
    Afterwards, the field should contain text similar to the following:
    "C:\Program Files\Java\jre1.6.0_14\bin\javaw.exe" -jar "%1" %*
  8. Click OK to exit the Editing Action for Type dialog box.
  9. Click OK to exit the Edit File Type dialog box.
  10. Click Close to exit the Folder Options dialog box.
For UNIX and Linux systems, the procedure for changing file associations depends on which desktop environment (such as GNOME or KDE) that you are using. Look in your desktop environment's preference settings or consult the documentation for the desktop environment.

Playing Flash FLV Videos in Android applications

Often when you create an app displaying web contents in a mobile device you have to deal with FLV videos, still widely used in the web (until HTML5 will rule the world). The best thing to do is to convert them with some converter (like ffmpeg), but if you don'have access to original videos or for some other reasons you can't do the conversion in some other suitable format, here you can find a quick tutorial on how to embed and play Flash FLV Videos in an Android application.
This is done by using a WebView, a SWF player capable of playing FLVs, and of course the Flash plugin for Android installed.
First, create a layout xml with a WebView, like this:
<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">

 <WebView android:layout_width="fill_parent" android:id="@+id/webview" android:layout_height="fill_parent"></WebView> </LinearLayout>

</webview>

</linearlayout>

Create Activity -

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URLEncoder;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;

public class ViewVideo extends Activity {
   
 WebView webView;
 String htmlPre = "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"utf-8\"></head><body style='margin:0; pading:0; background-color: black;'>";  
 String htmlCode = 
   " <embed style='width:100%; height:100%' src='http://www.platipus.nl/flvplayer/download/1.0/FLVPlayer.swf?fullscreen=true&video=@VIDEO@' " +
   "  autoplay='true' " +
   "  quality='high' bgcolor='#000000' " +
   "  name='VideoPlayer' align='middle'" + // width='640' height='480' 
   "  allowScriptAccess='*' allowFullScreen='true'" +
   "  type='application/x-shockwave-flash' " +
   "  pluginspage='http://www.macromedia.com/go/getflashplayer' />" +
   "";
 String htmlPost = "</body></html>";
 
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.view_video); 

  webView = (WebView)findViewById(R.id.webview);
  
  webView.getSettings().setJavaScriptEnabled(true);
  webView.getSettings().setAllowFileAccess(true);
  webView.getSettings().setPluginsEnabled(true);
  webView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY); //thanks Patrick!
   
  htmlCode = htmlCode.replaceAll("@VIDEO@", video_link);
  webView.loadDataWithBaseURL("fake://fake/fake", htmlPre+htmlCode+htmlPost, "text/html", "UTF-8", null);  
 }
 
 

    
    @Override
    protected void onPause(){
        super.onPause();
        
        callHiddenWebViewMethod("onPause");

        webView.pauseTimers();
        if(isFinishing()){
         webView.loadUrl("about:blank");
            setContentView(new FrameLayout(this));
        }
    }

    @Override
    protected void onResume(){
        super.onResume();

        callHiddenWebViewMethod("onResume");

        webView.resumeTimers();
    }
    
    private void callHiddenWebViewMethod(String name){
     // credits: http://stackoverflow.com/questions/3431351/how-do-i-pause-flash-content-in-an-android-webview-when-my-activity-isnt-visible
        if( webView != null ){
            try {
                Method method = WebView.class.getMethod(name);
                method.invoke(webView);
            } catch (NoSuchMethodException e) {
                Lo.g("No such method: " + name + e);
            } catch (IllegalAccessException e) {
                Lo.g("Illegal Access: " + name + e);
            } catch (InvocationTargetException e) {
                Lo.g("Invocation Target Exception: " + name + e);
            }
        }
    }
    
}

Some explanation:

  • as said, you need a FLV player. I used the great & free FLVPlayer http://www.platipus.nl/flvplayer/download/1.0/
  • FLV player must reside on a website on the net. I tried putting the .swf in the /assets folder of the app and calling it from there, but it failed to load the FLV video. if someone can fix this please let me know! 
  • htmlCode contains the code to show the video as "fullscreen" (filling to full size of the webview). I could not get rid of a small white row some pixel wide, that I suppose is the space for the webview scrollbar. If you found workaround for this, again, please let me know so I can update the tutorialthanks to Patrick van Coeverden for the fix suggestion - see http://stackoverflow.com/questions/2279978/webview-showing-white-bar-on-right-side
  • callHiddenWebViewMethod is very important, otherwise the video will continue playing when the activity is not visible any more (and audio as well). Credis to this goes to the sliseshare poster linked in the comment. Thanks!
  • WARNING: this is mostly an hack! beware, things could not work as expected, or can stop working in the future. Btw, it worked very well for me.

Playing Flash on Android Devices

Playing Flash on Android Devices

Android OS Version > 4.0 no longer supports Flash.  Adobe decided not to support Flash for newer devices, starting from Jelly Bean and on wards mainly because of HTML5 doesn't need flash player to play videos.Therefore following android versions are not going to support flash player.

Android 4.1 Jelly Bean (API level 16)
Android 4.2 Jelly Bean (API level 17)
Android 4.3 Jelly Bean (API level 18)
Android 4.4 KitKat (API level 19)


But it doesn't mean it can't play flash videos.There are a few different ways to access Flash on Android, though none of them are as effective as the days when Flash was ubiquitous across the Android platform.

1.Legacy version of Flash Player for Android

It's still possible to get hold of the last version of Flash for Android and install this on your device.You can download the Flash Player for Android APK from Softonic then transfer it to a folder on your device.

2. Puffin Browser

An alternative route to take is to install Puffin Browser on your Android device. This handy web browser includes Flash support, allowing you to run all kinds of Flash content through the browser.
The experience of running Flash through Puffin Browser is pretty smooth, even on lower end device. That's because Puffin uses remote Flash technology, running Flash on the developers servers to enable the experience on your device.

3. Skyfire

Skyfire is another Android browser with Flash capabilities. The application allows you to freely watch Flash video on your device, although unlike  it doesn't support other types of Flash content, like games or some Flash interfaces on web sites.

4. Adobe Air

One of the reasons mooted by experts why Adobe ditched support for Flash for Android is that it wanted to push its Air platform to mobile developers. Just like Flash and HTML 5, Adobe Air is a platform for rich interactive media content, and there are an increasing number of apps and games that use the technology.
Adobe Air won't let you play Flash content on your Android device but it will allow you to access web apps created using the Air environment, such as the BBC iPlayer. What's more, it works natively outside of the browser, so you can enjoy content directly through the app. You can download Adobe Air free from Google Play.

Thursday, 18 July 2013

CONSTRUCTOR


Definition - Constructor is a special type of method i e. used to initialize a newly created object & is just called after memory is allocated for object.

Rules to be followed while defining constructor
  1. It has same name as that of class.
  2. No return type should be there.
  3. Constructors can use any access modifier, including private.
Note:-  You can define method with the same name as of class. Example-

class A{
  private A()
{
// Constructor with private access modifier, it means object of class A can only be instantiated with //in the class not outside it.To instantiate from outside class you have to use static method with in // //class A.
}
public void A()
{
// Legal method
}

public static void main(String... x)
{
new A(); // anonymous object
}
}

Q1. Do constructors have  return type?
Ans. Yes. Constructors return reference of their class.
         Do some practical .

 class A{
  A( ){

return ; // will not give any error. This proves that constructors returns something.
}
public static void main( )
{
System.out.println(new A( ));  // It will print A@1270b73 (ClassName@hashcode)  constroctur
}
}


Storage Areas in C,C++ & Java

Saturday, 22 June 2013

  

    JVM ARCHITECTURE


STORAGE AREAS

  1. Registers
  2. Stacks
  3. Heap
  4. Constant Storage
  5. Non Ram Storage

REGISTER

 The registers of the Java Virtual Machine are similar to the registers in our computer. However, because the Virtual Machine is stack based, its registers are not used for passing or receiving arguments. In Java, registers hold the machine's state, and are updated after each line of byte code is executed, to maintain that state. The following four registers hold the state of the virtual machine:
  • frame, the reference frame, and contains a pointer to the execution environment of the current method.
  • optop, the operand top, and contains a pointer to the top of the operand stack, and is used to evaluate arithmetic expressions.
  • pc, the program counter, and contains the address of the next byte code to be executed.
  • vars, the variable register, and contains a pointer to local variables.

STACK & HEAP

STACK

The Java Virtual Machine uses an operand stack to supply parameters to methods and operations, and to receive results back from them. All byte code instructions take operands from the stack, operate on them, and return results to the stack. Like registers in the Virtual Machine, the operand stack is 32 bits wide.
The operand stack follows the last-in first-out (LIFO) methodology.
 A call stack is a stack data structure that stores information about the active subroutines of a computer program. This kind of stack is also known as an execution stack,control stackrun-time stack, or machine stack
The stack frame holds the state of the method with three sets of data: the method's local variables, the method's execution environment, and the method's operand stack.








HEAP
What is Heap space in Java?
When a Java program started Java Virtual Machine gets some memory from Operating System. Java Virtual Machine or JVM uses this memory for all its need and part of this memory is call java heap memory.Heap is located at bottom of the address
Size of Java Heap
Default size of Heap space  in Java is 128MB on most of 32 bit Sun's JVM but its highly varies from JVM to JVM  e.g. default maximum and start heap size for the 32-bit Solaris Operating System (SPARC Platform Edition) is -Xms=3670K and -Xmx=64M and Default values of heap size parameters on 64-bit systems have been increased up by approximately 30%. Also if you are using throughput garbage collector in Java 1.5 default maximum heap size of JVM would be Physical Memory/4 and  default initial heap size would be Physical Memory/16. Another way to find default heap size of JVM is to start an application with default heap parameters and monitor in using JConsole which is available on JDK 1.5 onwards, on VMSummary tab you will be able to see maximum heap size.

Milestones to Java Developer

Friday, 21 June 2013

Just Stop where ever you are.Think & Ask yourself following questions.
   Q1. Is I am on right track of becoming Java Developer?
   Q2. What steps should  I follow?

        For Begginers  

Live the life of programmer in well structured and disciplined way. Let prepare yourself  to jump into the battle ground of Java. Every warrior must have ..1. Target to Achieve  (You have to set project goal and deadline to complete them)
2. Weapons   (Your Shield will be your core concepts.)
3.  Decisive, Teamwork etc.   

The blog is going to provide best assignments on C, Data Structures in C & Java chapter wise.

What will Happen If you get a job?

There are many developers who are working in cooperate sectors but still struggling to complete projects with in specified deadline due to weak Core  Java concepts. You should not be job oriented.
Make your Basics Strong even if it takes more than 3 months.Don't worry about jobs.Jobs are in abundance but company seeks for the best.This blog is only to make you the best.

Basics required  

Language C, Data Structures in C(Implementation)
Database - Mysql or Sql Server or Oracle (any of these..)
Operating System - Unix/Linux( preferable atleast have hands on these)
Technology - Java

Collect your weapons   

 Weapon 1. Download following ebooks-
  1. Head First C   by David Griffiths, Dawn Griffiths   Download Head First C ebook
  2. Head First Java by  Bert BatesKathy Sierra              Download Head First Java ebook
  3. Thinking in Java 5th Ediition by Brucel Eckel                Download Thinking in Java ebook
  4. Java 7 Concurrency Cook Book (Threading Concepts)

 Weapon  2 . Know the Oracle Certified Core Java Syllabus 

 Weapon 3   Work on Assingments 
     

Android: Screen Densities, Sizes, Configurations, and Icon Sizes

Android: Screen Densities, Sizes, Configurations, and Icon Sizes

1. Definitions

  • resolution = number of pixels available in the display, scale-independent pixel = sp
  • density = how many pixels appear within a constant area of the display, dots per inch = dpi
  • size = amount of physical space available for displaying an interface, screen's diagonal, inch
  • density-independent pixel = virtual pixel that is independent of the screen density, dp

2. Density Classes

ClassNameDensityFactorDrawable FolderComment
ldpilow density120 dpisp = 3/4 * dpdrawable-ldpi
mdpimedium density160 dpisp = dpdrawable-mdpi OR drawablebaseline size, example: 320x480 (sp or dp)
hdpihigh density240 dpisp = 1.5 x dpdrawable-hdpiexample: 480x800 sp = 320x533 dp
xhdpiextra high density320 dpisp = 2 x dpdrawable-xhdpi
xxhdpiextra extra high density480 dpisp = 3 x dpdrawable-xxhdpi

3. Icon Sizes (full / content)

DensityLauncherMenuAction BarStatus Bar and NotificationTabPop-up Dialog and List ViewSmall and Contextual
ldpi36x36 px36x36 / 24x24 px24x24 / 18x18 px18x18 / 16x16 px24x24 / 22x22 px24x24 px12x12 / 9x9 px
mdpi48x48 px48x48 / 32x32 px32x32 / 24x24 px24x24 / 22x22 px32x32 / 28x28 px32x32 px16x16 / 12x12 px
hdpi72x72 px72x72 / 48x48 px48x48 / 36x36 px36x36 / 33x33 px48x48 / 42x42 px48x48 px24x24 / 18x18 px
xhdpi96x96 px96x96 / 64x64 px64x64 / 48x48 px48x48 / 44x44 px64x64 / 56x56 px64x64 px32x32 / 24x24 px
xxhdpi144x144 px(1)(1)(1)(1)(1)(1)
  • (1) Google documentation says: "Applications should not generally worry about this density; relying on XHIGH graphics being scaled up to it should be sufficient for almost all cases."
  • Launcher icons for Android Market: 512x512 px.

4. Screen Size Classes

ClassSize in dpLayout FolderExamplesComment
small426x320 dplayout-smalltypical phone screen (240x320 ldpi, 320x480 mdpi, etc.)
normal470x320 dplayout-normal OR layouttypical phone screen (480x800 hdpi)baseline size
large640x480 dplayout-largetweener tablet like the Streak (480x800 mdpi), 7" tablet (600x1024 mdpi)
xlarge960x720 dplayout-xlarge10" tablet (720x1280 mdpi, 800x1280 mdpi, etc.)

5. Example Screen Configurations

Screen SizeLow density (120), ldpiMedium density (160), mdpiHigh density (240), hdpiExtra high density (320), xhdpi
smallQVGA (240x320)480x640
normalWQVGA400 (240x400)
WQVGA432 (240x432)
HVGA (320x480)WVGA800 (480x800)
WVGA854 (480x854)
600x1024
640x960
largeWVGA800 (480x800)(2)
WVGA854 (480x854)(2)
WVGA800 (480x800)(1)
WVGA854 (480x854)(1)
600x1024
xlarge1024x600WXGA (1280x800)(3)
1024x768
1280x768
1536x1152
1920x1152
1920x1200
2048x1536
2560x1536
2560x1600
  • (1) To emulate this configuration, specify a custom density of 160 when creating an Android Virtual Device that uses a WVGA800 or WVGA854 skin.
  • (2) To emulate this configuration, specify a custom density of 120 when creating an Android Virtual Device that uses a WVGA800 or WVGA854 skin.
  • (3) This skin is available with the Android 3.0 platform.

6. Screen Orientation

OrientationNameLayout Folder, Example
portportraitlayout-port-large
landlandscapelayout-land-normal OR layout-land
 

Blogger news

Blogroll

Most Reading

Tags