How to take advantage of the pinch-to-zoom feature in your Xperia™ X10 apps – Part 2

Recently Sony Ericsson rolled out an update to the Android™ 2.1 operating system in its Xperia™ X10 phones. One of the important new features in the update is support for a multi-touch gesture called pinch-to-zoom. The first part of this two-part tutorial showed how to take advantage of the pinch-to-zoom feature in your apps. In this second part of the tutorial, you’ll examine a code example that uses the pinch-to-zoom feature.

Read more

How to take advantage of the pinch-to-zoom feature in your Xperia™ X10 apps – Part 2

Recently Sony Ericsson rolled out an update to the Android™ 2.1 operating system in its Xperia™ X10 phones. One of the important new features in the update is support for a multi-touch gesture called pinch-to-zoom. The first part of this two-part tutorial showed how to take advantage of the pinch-to-zoom feature in your apps. In this second part of the tutorial, you’ll examine a code example that uses the pinch-to-zoom feature.

Read more

How to take advantage of the pinch-to-zoom feature in your Xperia™ X10 apps – Part 1

Recently Sony Ericsson rolled out an update to the Android™ 2.1 operating system in its Xperia™ X10 phones. One of the important new features in the update is support for a multi-touch gesture called pinch-to-zoom. In this first part of a two-part tutorial, you will learn how to take advantage of the pinch-to-zoom feature in your apps. In the second part of the tutorial, you’ll examine a code example that uses the pinch-to-zoom feature.

Read more

How to take advantage of the pinch-to-zoom feature in your Xperia™ X10 apps – Part 1

How to take advantage of the pinch-to-zoom feature in your Xperia™ X10 apps – Part 1

Recently Sony Ericsson rolled out an update to the Android™ 2.1 operating system in its Xperia™ X10 phones. One of the important new features in the update is support for a multi-touch gesture called pinch-to-zoom. In this first part of a two-part tutorial, you will learn how to take advantage of the pinch-to-zoom feature in your apps. In the second part of the tutorial, you’ll examine a code example that uses the pinch-to-zoom feature.


The pinch-to-zoom feature allows users to zoom in and get a closer, more detailed view of a display, or zoom out and get a wider field of view. For example, in the side-by-side image below, the image on the left shows a display zoomed out for a wider field of view. The image on the right shows the display zoomed in for a closer view.

The pinch-to-zoom feature lets users zoom out for a wider field of view, or zoom in for a closer view.

Although not initially available in the Android 2.1 support in Xperia™ X10, pinch-to-zoom is now available as an over-the-air (OTA) enhancement. Note however that Xperia™ X10 is not yet fully optimized for multi-touch. There are some cases where a pinch-to-zoom gesture generates unusual behavior. For more information, see the Limitations section in Part 2 of the tutorial.

You can take advantage of the pinch-to-zoom feature in applications that you develop for Xperia™ X10. Two applications that are packaged with Xperia™ X10 already take advantage of the feature: the web browser and Google Maps. There are also other applications that make use of this feature, such as Angry Birds.

Below is a video that demonstrates the pinch-to-zoom feature in Xperia™ X10.

Providing pinch-to-zoom capability in your Xperia™ X10 application
Your Xperia™ X10 application needs to do the following to provide pinch-to-zoom capability:

  • Detect that the user has made a pinch-to-zoom gesture, such as moving two fingers across the screen. This is further explained below in Detecting and getting information about the gesture.
  • Get information about the gesture, such as what the action was and when it took place. This is further explained below in Detecting and getting information about the gesture.
  • Process the gesture, that is, respond to the user’s action, as appropriate. This is further explained below in Processing the gesture.

Detecting and getting information about the gesture
When a user touches the screen, Android creates an Android™ MotionEvent object to record information about the touch event, such as the action the user performed and the time when the user performed it. Your application needs to access the object in order to detect a pinch-to-zoom gesture and get information about it. This requires the application to first import the MotionEvent class as follows:

import android.view.MotionEvent;

Processing the gesture
To process the gesture, you create a callback handler. You can use the callback handler to take actions such as get information about a pinch-to-zoom gesture. However, first you need to register the callback handler using the setOnTouchListener() method of the Android View class, as shown in the following code snippet.

import android.view.View;
import android.view.View.OnTouchListener;
…
view.setOnTouchListener(onTouchListener);

The parameter to view.setOnTouchListener represented by:

onTouchListener

is the callback handler, that is, the touch listener that you want to register. The callback handler is attached to a specific view. Touch events that are posted to that view are processed by the associated callback handler.

The callback handler must implement Android’s View.OnTouchListener interface and use the onTouch() method defined in the interface to process the touch events. When you call the onTouch() method, you need to supply as parameters a View object and a MotionEvent object, as shown below.

public class MyPinchZoom extends Activity implements OnTouchListener {

   public boolean onTouch(View v, MotionEvent event) {
      // Process touch events
   }

}

A user starts a pinch-to-zoom gesture by touching the screen with one finger. This event is represented in the MotionEvent object by the constant ACTION_DOWN. When the user touches the screen with a second finger while continuing to touch the screen with the first finger, that event is recorded in the MotionEvent object by the constant ACTION_POINTER_DOWN. Other constants represent other actions taken during the pinch-to-zoom gesture. Here are the set of action-related constants for the pinch-to-zoom gesture:

ACTION_DOWN The user touched the screen.
ACTION_POINTER_DOWN The user touched the screen with a second finger while continuing to touch the screen with the first finger.
ACTION_MOVE The user moved a finger on the screen.
ACTION_POINTER_UP The user released one finger from the screen while continuing to touch the screen with the other finger.
ACTION_UP The user released the finger from the screen (only only one finger was touching the screen).
ACTION_CANCEL The user cancelled the current gesture.

After you register the callback handler, you can use it to call methods on the MotionEvent object to get information about a pinch-to-zoom related event. For example, the getAction() method returns the type of action performed: up down, move , or cancel. The following code snippet shows a call to the getAction() method.

// Process touch events
      int action = event.getAction();

The lowest 8 bits of the action returned by getAction() represent the action code. To access the action code, you can perform a bitwise AND operation (using the & operator). The two operands of the AND operation are the result returned by getAction() and the MotionEvent constant, ACTION_MASK. The ACTION_MASK constant is a bit mask of the part of the action code that represents the action itself. The following line of code performs a bitwise AND operation on the action returned by getAction() and the ACTION_MASK constant.

int actionCode = action & MotionEvent.ACTION_MASK;

You can get the number of pointers (fingers) associated with the event by calling the getPointerCount() method of the MotionEvent object, as shown below.

int pCount = event.getPointerCount();

You can also retrieve the X and Y coordinates associated with the touch event by calling the getX() and getY() methods of the MotionEvent object, respectively. Here is an example that retrieves first the X coordinate and then the Y coordinate.

float xcoord = event.getX;
float ycoord = event.getY;

By identifying a pointer index as a parameter to getX() and getY(), you can retrieve the X and Y coordinates of a specific pointer. The following example shows how to get the X coordinate and Y coordinate of the first pointer.

Float  xcoord = event.getX(0);   //Get the X coordinate for the first
                                 // pointer
Float  ycoord = event.getY(1);   //Get the Y coordinate for the second
                                 // pointer

More information

Read more

How to take advantage of the pinch-to-zoom feature in your Xperia™ X10 apps – Part 1

How to enable HD video recording for the Xperia™ X10 with Android update 2.0x

As the roll-out of the Android 2.1 update continues for Xperia™ X10, X10 mini and X10 mini pro users, one of the key features introduced with the update is HD video recording in 720p. Johan Abramsson, Developer Support Engineer at Sony Ericsson, has written a quick tutorial on how you can make use of HD video recording from third party applications.

Read more

Enabling HD video recording on the Xperia™ X10

As the roll-out of the Android 2.1 update continues for Xperia™ X10, X10 mini and X10 mini pro users, one of the key features introduced with the update is HD video recording in 720p. Johan Abramsson, Developer Support Engineer at Sony Ericsson, has written a quick tutorial on how you can make use of HD video recording from third party applications.

Read Johan’s tutorial here.

Read more

New version of Sony Ericsson’s WebSDK Packager tool available

We are excited to introduce a new release of the WebSDK Packager tool, which now provides support for the Mac OS® X platform. WebSDK Packager version 1.2.1 is an all-in-one tool for building, simulating and packaging an application’s web components into a single native shell. The updated WebSDK Packager tool can be used across Windows or Mac OS platforms for development and deployment of web applications on Android™ and Symbian™ devices. WebSDK Packager also provides developers with exciting sample applications that can run on all Sony Ericsson Android and Symbian phones, including the Xperia™ X10 and Xperia X10 mini pro.

Based on PhoneGap’s open source framework, WebSDK Packager is a great tool for someone who has great expertise with HTML CSS and JavaScript and is adept at creating web applications, but is not familiar with the complexities of the mobile environment. WebSDK Packager allows Android™ developers to create mobile web applications by packaging their web components inside a native shell for Android. For Symbian developers, WebSDK Packager uses the PhoneGap API with web runtime (WRT) widgets. This truly enables developers to write code once and deploy on multiple platforms. With support of this tool on Windows and Mac OS platforms, developers can use the tool on their preferred platform.

For those not familiar with PhoneGap, it is an open source development framework for building cross-platform mobile apps that run on different mobile platforms including Android, Symbian, iPhone®, iPad®, Palm® and BlackBerry®. The PhoneGap open source code has been downloaded more than 250,000 times and there are thousands of PhoneGap-based apps in various platform stores. We also welcome the recent announcement by Symbian to integrate PhoneGap library in their web extensions package.

Sony Ericsson supports cross-platform web development and sees this as an important enabler for developers to create exciting new services across web and mobile. Sony Ericsson announced support for PhoneGap framework in 2009 and our WebSDK Packager as part of a broader approach to simplifying the application and services development on mobile devices for developers.

Additionally, we will begin referring to Sony Ericsson’s WebSDK as a “Packager”, which aligns with the true functionality of the product – a complete tool for developers to build, simulate and package their application’s web components into a single native shell.

Read more

New version of Sony Ericsson’s WebSDK Packager tool available

The Xperia™ X10 now available in the U.S. market

The greatly anticipated Sony Ericsson Xperia™ X10 is now available to U.S. customers, as you might have seen in the announcement from AT&T and Sony Ericsson.  This surely is welcome news if you’re in the U.S. and keen to get your hands on the Xperia™ X10. What’s especially interesting with AT&T’s offer is the price – $149.99 on a two contract and minimum data plan. Sounds like a fair deal, right?

For developers, Sony Ericsson has put together an add-on for the Android™ SDK, including the splash screen, backgrounds, an Xperia™ X10 skin and some other stuff.

Read more

Android one finger zoom tutorial – Part 4

Welcome to the fourth and final part of the Android tutorial on how to make your own zoom control like the one used in Sony Ericsson X10 Mini in the Camera and Album applications. Click here to go to the prevoius part of this tutorial. As usual the source code is included, see below. Don’t forgett to download ‘Sony Ericsson Tutorials’ from Android market to see demos of this and other tutorials in action.

Read more

Android one finger zoom tutorial – Part 4

Welcome to the fourth and final part of the Android tutorial on how to make your own zoom control like the one used in Sony Ericsson X10 Mini in the Camera and Album applications. Click here to go to the prevoius part of this tutorial. As usual the source code is included, see below. Don’t forget to download ‘Sony Ericsson Tutorials’ from Android market to see demos of this and other tutorials in action.

Read more

Page 1 of 212