UnAngelo blog

…se io fossi un angelo
Subscribe

Unity and uTouch

October 14, 2010 By: Gerry Carr Category: 1

One of the most exciting things about the Ubuntu 10.10 release has been the delivery of the Unity ‘shell’ in Ubuntu Netbook Edition. For the uninitiated,  this delivers a very different user experience to that in the main desktop edition. For a start the icons of the most popular applications are permanently featured on the left-hand side of the screen. This borrows more from the smartphone interfaces but is adapted for use on, in this case, netbooks. So there remains a workspace where users still have sufficient room to watch video, edit photos, create documents, play games, read the web, write emails – all of the usual tasks we use a computer for, day to day.

Everything is optimised however for the more limited screen space. It is sub-optimal for instance to simply port an interface from the full-screen world, shrink it and expect it to be a great experience. Unity does away with the bottom bar for example that Windows, Ubuntu and Mac users will be used to. This is actually a radical step, but in my experience at least, it takes no time at all to forget that there ever was a bottom bar. The result is considerably more ‘vertical space’ for to use  – again maximising the useful area on limited screen sizes.

One of the coolest things though is one that will be experienced by the fewest people at this point – touch. Unity is fully touch-enabled – those big icons are screaming out to have a digit poked at them. But as ever, the boys in the lab, or in this case Duncan McGregor‘s  multi-touch team have gone a step further and created a multi-touch ‘gesture’ library. This allows finger combinations to do groovy things like expand and reduce windows, pull up multiple windows in one workspace, and call up the ‘dash’ automatically. These are in 10.10. In 11.04 we will see a lot more.

Because there are a very limited number of touch-enabled devices out there at present, we thought we would create a video to show some of the features. You can see it below. It has turned out rather nicely even with the clumsy paws.

Gerry Carr, Platform Marketing, Canonical

Angry Birds tweet fury at Redmond • The Register

October 11, 2010 By: (author unknown) Category: Uncategorized

Shared by ianus

Resumen: Microsoft comenta que Angry Bird estará en Windows Phone 7 y Rovio dice k por el momento ni se lo plantearon!
XD

Redmond showed the scowling icon for the game in screen shots of upcoming software titles, where it was spotted by WMPowerUser. This prompted angry tweeting from Rovio, who pointed out that it has nothing against Windows Phone 7, but equally has no existing plans to port its best-selling time-filler to that platform, and furthermore, it objects to having its IP lifted.

“Only thing we said that we have not committed to do WP7 yet, we don’t like others using our IP without asking,” the (not angry) company tweeted.

Unleashing GPU acceleration on the web

September 14, 2010 By: noreply@blogger.com (Google Chrome Blog) Category: google, linux

Since our previous post, we’ve made good progress on 2D graphics performance: 2D canvas acceleration is now available in trunk and the canary build by using the –enable-accelerated-2d-canvas command-line switch (coming to the developer channel shortly). We’ve also been hard at work improving our 3D graphics stack. Today, we’re excited to release a set of WebGL demos to help highlight what you can do with the API.

Chromium’s 2D canvas acceleration uses the same GPU process infrastructure as the compositor, which is designed to maintain the same stability and security Chromium has always had. In addition, this system picks the best graphics API to use on each OS that Chromium supports: Windows XP/Vista/7, Mac OS and Linux. We haven’t finished implementing accelerated 2D canvas support – there’s no Mac support and some functions are not accelerated yet – but Chromium already achieves some impressive gains on the recent IE9 Platform Preview Test Drive 2D canvas demos:

These early numbers show up to 60x speed improvement over the current version of Google Chrome. With Google Chrome’s fast release cycles, we expect to be able to get these enhancements to users quickly and add new performance improvements over time.

We’re excited to give developers fast 2D graphics, but we think truly hardware accelerating graphics on the web means giving developers access to a programmable 3D graphics pipeline with WebGL. Even with accelerated 2D canvas and SVG, it’s still not possible to achieve many graphics effects with these APIs. (To read more about the progression from dynamic 2D to CSS Transforms and WebGL, check out our recent blog post). With WebGL and 3D CSS, developers can create modern games, impressive photo galleries, 3D data visualizations, virtual environments, and whatever else they can dream up.

To give you a taste for what WebGL can do, we’ve worked with a number of talented artists and developers to create the first round of a series of demos, ranging from a realistic aquarium to a 3D wall of photos. We hope these demos help demonstrate even more immersive experiences made possible with these APIs. So check out our demo gallery with an up-to-date canary build or Chromium build and have some fun with using your GPU in the browser! For a quick peek at some of these demos, you can watch our playlist of preview videos:

Posted by James Robinson, Software Engineer and Gregg Tavares, Software Engineer

Internet Explorer 9: Testing Center

September 13, 2010 By: (author unknown) Category: 1, google

Shared by ianus

Para que sirve la competencia?
Para mejorar tu producto…
A ver si por fin el Internet Explorer podrá ser llamado “Navegador” (yo sigo sin pasarme a IE, Mi querido Firefox y Chrome seguirán siendo mis queridos navegadores!) ;)

Thank you for visiting the Windows Internet Explorer Testing Center

This website contains 519 new test cases bringing the total to 2138 tests that we developed within Microsoft as part of the IE9 project in support of several World Wide Web Consortium (W3C) web standards working groups as well as Ecma-262-5, Ecma International’s ECMAScript Fifth Edition specification (also known as ES5).

We listened to your feedback on the tests we had submitted previously and updated 5 test cases. Thank you for your feedback. The web standards development, validation and update process is working. Please continue to provide feedback on the test cases to the appropriate W3C working group. In case of ES5 test cases please provide test case specific feedback via Microsoft Connect.

There are two tables below. The first table is a summary of the test results by specification with the August 2010 IE Platform Preview along each of the major shipping browsers running on Windows. The second table at the bottom of this page provides links to each of the new test cases we submitted to each appropriate W3C working group to help the web become more interoperable.

Thank you,

Jason Upton
Test Manager, Internet Explorer

Cross-browser Test Results Summary:

Web Standards Number of Submitted Tests Internet Explorer 9
Platform Preview
Mozilla Firefox 3.6.8 Opera 10.6 Apple Safari 5 Google Chrome 5 Internet Explorer 8
HTML5 99 94% 57% 59% 53% 48% 0%
SVG 1.1 2nd edition 56 100% 75% 86% 84% 80% 0%
CSS3 117 97% 58% 76% 71% 73% 11%
DOM 183 96% 73% 63% 67% 67% 4%
JavaScript 1683 99% 68% 67% 88% 87% 10%

Google buys social games start-up SocialDeck

September 01, 2010 By: (author unknown) Category: google

Shared by ianus

…otra compra más de Google…

Google Inc. has bought social games start-up SocialDeck Inc., the latest in a series of acquisitions aimed at helping the Internet search giant build a social networking service to compete with Facebook Inc.

The acquisition, coming just days after Google’s previous social acquisition, was announced Monday on SocialDeck’s website. Financial terms were not disclosed.

The Canadian startup has launched several games titles for Facebook, as well as Apple Inc.’s iPhone and Research In Motion Ltd.’s BlackBerry devices. SocialDeck’s games platform technology enables simultaneous game play across multiple mobile devices and social networks.

Android-x86 – Porting Android to x86

August 16, 2010 By: (author unknown) Category: Uncategorized

Shared by ianus

Alguien lo ha probado?

This is a project to port Android open source project to x86 platform, formerly known as “patch hosting for android x86 support“. The original plan is to host different patches for android x86 support from open source community. A few months after we created the project, we found out that we could do much more than just hosting patches. So we decide to fork our code base that will provide android x86 support on different x86 platforms, and set up a git server to host it. To reflect this major change, we create this new project.

Multi-touch Support Lands in Maverick

August 16, 2010 By: Duncan McGreggor Category: 1, linux

Canonical is pleased to announce the release of uTouch 1.0, Ubuntu’s multi-touch and gesture stack. With Ubuntu 10.10 (the Maverick Meerkat), users and developers will have an end-to-end touch-screen framework — from the kernel all the way through to applications. Our multi-touch team has worked closely with the Linux kernel and X.org communities to improve drivers, add support for missing features, and participate in the touch advances being made in open source world. To complete the stack, we’ve created an open source gesture recognition engine and defined a gesture API that provides a means for applications to obtain and use gesture events from the uTouch gesture engine.

Our multi-touch work began in Ubuntu 10.04 LTS, when we worked to get additional touch hardware supported in the Linux kernel, particularly the Dell XT2, HP tx2 tablets and the Lenovo T410s laptops. With that in place, and active development in X well under way, we reviewed our options for gesture recognition in Linux. The Maverick cycle has seen us produce several prototypes for gesture recognition software and the Ubuntu archives now include the results of that effort.

The world’s expectations of software experience are being raised by advances in mobile computing. We are bringing that revolution to the Linux desktop: for window management and applications. Though our work at the application level has only just started, we are certain that multi-touch and gestures will be central to the way we use Linux applications in future.

The success of touch in applications depends on several key factors:

  • toolkit integration of gesture APIs
  • touch support for legacy applications
  • designing new applications for finger-based interactions

Work has begun on all three fronts in Ubuntu, and we expect it to remain an area of active interest over the next few releases up to 12.04 LTS.

Ubuntu is the fruit of collaboration across the huge Ubuntu community, and also the amazing work of many other communities that form around individual projects and initiatives like Debian. The uTouch framework enables work to begin across many of those communities to make touch a first-class interaction model in open source desktop and mobile software.

Existing contributions in other projects have provided fertile ground for uTouch. To name just a few:

  • Stéphane Chatty at ENAC has lead much multi-touch hardware support in the kernel
  • Peter Hutterer at Red Hat defined multi-pointer X and proposed a multi-touch protocol for a future version of X
  • Carlos Garnacho of the GNOME community has done multi-touch work in X and GTK

We’re look forward to continued collaboration, ensuring that Linux remains the preferred platform for people building cutting-edge devices and software.

Canonical is working with manufacturers of touch-enabled products and those of their underlying technology in order to bring innovations in user experience to a broader audience. Our aim is to bring the natural, tactile experience of the world to the desktop, window manager, and applications you value — all the software that you depend upon to get things done and have fun. Touch will be part of the Ubuntu Netbook, Desktop and Light products from 10.10 and beyond.

How to have your (Cup)cake and eat it too

July 12, 2010 By: Tim Bray Category: 1, google

[This post is by Adam Powell, his second touchy-feely outing in just a few weeks. I asked him to send me a better picture than we ran last time, and got this in response. Photo by our own Romain Guy. — Tim Bray]

Android developers concerned with targeting every last device with their apps are no doubt familiar with this chart:

On July 1, 2010 this was the breakdown of active devices running different versions of the Android platform. With all of the new platform features added to the Android SDK in each version, this chart has many developers shouting the F-word when they are forced to choose between integrating newer platform features and providing their app to the widest possible audience.

Savvy Android developers already know that these two options aren’t really mutually exclusive, but that straddling between them can be painful. In this post I’m going to show you that it doesn’t have to be that way.

Several weeks ago we took a look at how to handle multitouch on Android 2.0 (Eclair) and above, and by the end we had a simple demo app. That app uses features exclusive to Android 2.2 (Froyo) which as of this writing hasn’t had a chance to reach many devices yet. In this post we’re going to refactor that demo to run on devices all the way back to Android 1.5 (Cupcake). If you’d like to follow along, start off by grabbing the code in the trunk of the android-touchexample project on Google Code.

The problem manifests

The uses-sdk tag in your AndroidManifest.xml can specify both a minSdkVersion and a targetSdkVersion. You can use this to declare that while your app is prepared to run on an older version of the platform, it knows about newer versions. Your app can now build against newer SDKs. However, if your code accesses newer platform functionality directly you will probably see something like this in the system log of devices running an older version of Android:

E/dalvikvm(  792): Could not find method android.view.MotionEvent.getX, referenced from method com.example.android.touchexample.TouchExampleView.onTouchEvent
W/dalvikvm(  792): VFY: unable to resolve virtual method 17: Landroid/view/MotionEvent;.getX (I)F
W/dalvikvm(  792): VFY:  rejecting opcode 0x6e at 0x0006
W/dalvikvm(  792): VFY:  rejected Lcom/example/android/touchexample/TouchExampleView;.onTouchEvent (Landroid/view/MotionEvent;)Z
W/dalvikvm(  792): Verifier rejected class Lcom/example/android/touchexample/TouchExampleView;
D/AndroidRuntime(  792): Shutting down VM
W/dalvikvm(  792): threadid=3: thread exiting with uncaught exception (group=0x4000fe70)

We broke the contract of minSdkVersion, and here is the result. When we build our app against SDK 8 (Froyo) but declare minSdkVersion="3" (Cupcake) we promise the system that we know what we’re doing and we won’t try to access anything that doesn’t exist. If we mess this up, we see the above, and our users see an ugly error message.

Cue a lot of frustrated users and one-star ratings on Market. We need a safe way of accessing newer platform functionality without making the verifier angry on older platform versions.

Stop and reflect

Many Android developers are already familiar with the practice of accomplishing this through reflection. Reflection lets your code interface with the runtime, detect when certain methods or classes are present, and invoke or instantiate them without touching them directly.

The prospect of querying each platform feature individually and conditionally invoking it using reflection isn’t pretty. It’s ugly. It’s slow. It’s cumbersome. Most of all, heavy use can turn your app’s codebase into an unmaintainable mess. What if I said there is a way to write Android apps that target Android 1.5 (Cupcake) through 2.2 (Froyo) and beyond with a single codebase and no reflection at all?

Lazy Loading

Computer science researcher Bill Pugh published and popularized a method of writing singletons in Java that takes advantage of the laziness of ClassLoaders. Wikipedia explains his solution further. The code looks like this:

public class Singleton {
  // Private constructor prevents instantiation from other classes
  private Singleton() {}

  /**
   * SingletonHolder is loaded on the first execution of Singleton.getInstance()
   * or the first access to SingletonHolder.INSTANCE, not before.
   */
  private static class SingletonHolder {
    private static final Singleton INSTANCE = new Singleton();
  }

  public static Singleton getInstance() {
    return SingletonHolder.INSTANCE;
  }
}

There is a very important guaranteed behavior at work here explained by the comment above SingletonHolder. Java classes are loaded and initialized on first access – instantiating the class or accessing one of its static fields or methods for the first time. This is relevant to us because classes are verified by the VM when they are loaded, not before. We now have everything we need to write Android apps that span versions without reflection.

Designing for compatibility

As it turns out this is fairly simple to apply. You generally will want your app to degrade gracefully on older platform versions, dropping features or providing alternate functionality when the platform support isn’t available. Since Android platform features are tied to the API level you have only one axis to consider when designing for compatibility.

In most cases this version support can be expressed as a simple class hierarchy. You can design your app to access version-sensitive functionality through a version-independent interface or abstract class. Subclasses of that interface intended to run on newer platform versions will support newer platform features, and subclasses intended for older versions might need to present alternate ways for your users to access app functionality.

Your app can use a factory method, abstract factory, or other object creation pattern to instantiate the proper subclass at runtime based on the information exposed by android.os.Build.VERSION. This last step insures that the system will never attempt to load a class it can’t verify, preserving compatibility.

The principle in practice

At the beginning of this post I said that we are going to refactor the touch example app from Making Sense of Multitouch to be compatible from API level 3 (Cupcake) on through API level 8 (Froyo). In that post I pointed out that GestureDetectors can be a useful pattern for abstracting the processing of touch events. At the time I didn’t realize how soon that statement would be put to the test. We can refactor the version-specific elements of the demo app’s touch handling into an abstract GestureDetector.

Before we begin the real work, we need to change our manifest to declare that we support API level 3 devices with minSdkVersion in the uses-sdk tag. Keep in mind that we’re still targeting SDK 8, both with targetSdkVersion in our manifest and in our project configuration. Our manifest now looks like this:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.android.touchexample"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".TouchExampleActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-sdk android:minSdkVersion="3" android:targetSdkVersion="8" />
</manifest>

Our TouchExampleView class isn’t compatible with Android versions prior to Froyo thanks to its use of ScaleGestureDetector, and it isn’t compatible with versions prior to Eclair thanks to its use of the newer MotionEvent methods that return multitouch data. We need to abstract that functionality out into classes that will not be loaded on versions of the platform that don’t support it. To do this, we will create the abstract class VersionedGestureDetector.

The example app allows the user to perform two gestures, drag and scale. VersionedGestureDetector will therefore publish two events to an attached listener, onDrag and onScale. TouchExampleView will obtain a VersionedGestureDetector instance appropriate to the platform version, filter incoming touch events through it, and respond to the resulting onDrag and onScale events accordingly.

The first pass of VersionedGestureDetector looks like this:

public abstract class VersionedGestureDetector {
    OnGestureListener mListener;

    public abstract boolean onTouchEvent(MotionEvent ev);

    public interface OnGestureListener {
        public void onDrag(float dx, float dy);
        public void onScale(float scaleFactor);
    }
}

We’ll start with the simplest functionality first, the VersionedGestureDetector for Cupcake. For simplicity’s sake in this example we will implement each version as a private static inner class of VersionedGestureDetector. You can organize this however you please, of course, as long as you use the lazy loading technique shown above or some equivalent. Don’t touch any class that directly accesses functionality not supported by your platform version.

private static class CupcakeDetector extends VersionedGestureDetector {
    float mLastTouchX;
    float mLastTouchY;

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        switch (ev.getAction()) {
        case MotionEvent.ACTION_DOWN: {
            mLastTouchX = ev.getX();
            mLastTouchY = ev.getY();
            break;
        }
        case MotionEvent.ACTION_MOVE: {
            final float x = ev.getX();
            final float y = ev.getY();

            mListener.onDrag(x - mLastTouchX, y - mLastTouchY);

            mLastTouchX = x;
            mLastTouchY = y;
            break;
        }
        }
        return true;
    }
}

This simple implementation dispatches onDrag events whenever a pointer is dragged across the touchscreen. The values it passes are the X and Y distances traveled by the pointer.

In Eclair and later we will need to properly track pointer IDs during drags so that our draggable object doesn’t jump around as extra pointers enter and leave the touchscreen. The base implementation of onTouchEvent in CupcakeDetector can handle drag events for us with a few tweaks. We’ll add the methods getActiveX and getActiveY to fetch the appropriate touch coordinates and override them in EclairDetector to get the coordinates from the correct pointer:

private static class CupcakeDetector extends VersionedGestureDetector {
    float mLastTouchX;
    float mLastTouchY;

    float getActiveX(MotionEvent ev) {
        return ev.getX();
    }

    float getActiveY(MotionEvent ev) {
        return ev.getY();
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        switch (ev.getAction()) {
        case MotionEvent.ACTION_DOWN: {
            mLastTouchX = getActiveX(ev);
            mLastTouchY = getActiveY(ev);
            break;
        }
        case MotionEvent.ACTION_MOVE: {
            final float x = getActiveX(ev);
            final float y = getActiveY(ev);

            mListener.onDrag(x - mLastTouchX, y - mLastTouchY);

            mLastTouchX = x;
            mLastTouchY = y;
            break;
        }
        }
        return true;
    }
}

And now EclairDetector, overriding the new getActiveX and getActiveY methods. Most of this code should be familiar from the original touch example:

private static class EclairDetector extends CupcakeDetector {
    private static final int INVALID_POINTER_ID = -1;
    private int mActivePointerId = INVALID_POINTER_ID;
    private int mActivePointerIndex = 0;

    @Override
    float getActiveX(MotionEvent ev) {
        return ev.getX(mActivePointerIndex);
    }

    @Override
    float getActiveY(MotionEvent ev) {
        return ev.getY(mActivePointerIndex);
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        final int action = ev.getAction();
        switch (action & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_DOWN:
            mActivePointerId = ev.getPointerId(0);
            break;
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP:
            mActivePointerId = INVALID_POINTER_ID;
            break;
        case MotionEvent.ACTION_POINTER_UP:
            final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK)
                >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
            final int pointerId = ev.getPointerId(pointerIndex);
            if (pointerId == mActivePointerId) {
                // This was our active pointer going up. Choose a new
                // active pointer and adjust accordingly.
                final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
                mActivePointerId = ev.getPointerId(newPointerIndex);
                mLastTouchX = ev.getX(newPointerIndex);
                mLastTouchY = ev.getY(newPointerIndex);
            }
            break;
        }

        mActivePointerIndex = ev.findPointerIndex(mActivePointerId);
        return super.onTouchEvent(ev);
    }
}

EclairDetector calls super.onTouchEvent after determining the active pointer index and lets CupcakeDetector take care of dispatching the drag event. Supporting multiple platform versions doesn’t have to mean code duplication.

Finally, let’s add scale gesture support for Froyo devices that have ScaleGestureDetector. We’ll need a couple more changes to CupcakeDetector first; we don’t want to drag normally while scaling. Some devices have touchscreens that don’t deal well with it, and we would want to handle it differently on devices that do anyway. We’ll add a shouldDrag method to CupcakeDetector that we’ll check before dispatching onDrag events.

The final CupcakeDetector:

private static class CupcakeDetector extends VersionedGestureDetector {
    float mLastTouchX;
    float mLastTouchY;

    float getActiveX(MotionEvent ev) {
        return ev.getX();
    }

    float getActiveY(MotionEvent ev) {
        return ev.getY();
    }

    boolean shouldDrag() {
        return true;
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        switch (ev.getAction()) {
        case MotionEvent.ACTION_DOWN: {
            mLastTouchX = getActiveX(ev);
            mLastTouchY = getActiveY(ev);
            break;
        }
        case MotionEvent.ACTION_MOVE: {
            final float x = getActiveX(ev);
            final float y = getActiveY(ev);

            if (shouldDrag()) {
                mListener.onDrag(x - mLastTouchX, y - mLastTouchY);
            }

            mLastTouchX = x;
            mLastTouchY = y;
            break;
        }
        }
        return true;
    }
}

EclairDetector remains unchanged. FroyoDetector is below. shouldDrag will return true as long as we do not have a scale gesture in progress:

private static class FroyoDetector extends EclairDetector {
    private ScaleGestureDetector mDetector;

    public FroyoDetector(Context context) {
        mDetector = new ScaleGestureDetector(context,
                new ScaleGestureDetector.SimpleOnScaleGestureListener() {
                    @Override public boolean onScale(ScaleGestureDetector detector) {
                        mListener.onScale(detector.getScaleFactor());
                        return true;
                    }
                });
    }

    @Override
    boolean shouldDrag() {
        return !mDetector.isInProgress();
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        mDetector.onTouchEvent(ev);
        return super.onTouchEvent(ev);
    }
}

Now that we have our detector implementations in order we need a way to create them. Let’s add a factory method to VersionedGestureDetector:

public static VersionedGestureDetector newInstance(Context context,
        OnGestureListener listener) {
    final int sdkVersion = Integer.parseInt(Build.VERSION.SDK);
    VersionedGestureDetector detector = null;
    if (sdkVersion < Build.VERSION_CODES.ECLAIR) {
        detector = new CupcakeDetector();
    } else if (sdkVersion < Build.VERSION_CODES.FROYO) {
        detector = new EclairDetector();
    } else {
        detector = new FroyoDetector(context);
    }

    detector.mListener = listener;

    return detector;
}

Since we’re targeting Cupcake, we don’t have access to Build.VERSION.SDK_INT yet. We have to parse the now-deprecated Build.VERSION.SDK instead. But why is accessing Build.VERSION_CODES.ECLAIR and Build.VERSION_CODES.FROYO safe? As primitive static final int constants, these are inlined by the compiler at build time.

Our VersionedGestureDetector is ready. Now we just need to hook it up to TouchExampleView, which has become considerably shorter:

public class TouchExampleView extends View {
    private Drawable mIcon;
    private float mPosX;
    private float mPosY;

    private VersionedGestureDetector mDetector;
    private float mScaleFactor = 1.f;

    public TouchExampleView(Context context) {
        this(context, null, 0);
    }

    public TouchExampleView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public TouchExampleView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        mIcon = context.getResources().getDrawable(R.drawable.icon);
        mIcon.setBounds(0, 0, mIcon.getIntrinsicWidth(), mIcon.getIntrinsicHeight());

        mDetector = VersionedGestureDetector.newInstance(context, new GestureCallback());
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        mDetector.onTouchEvent(ev);
        return true;
    }

    @Override
    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        canvas.save();
        canvas.translate(mPosX, mPosY);
        canvas.scale(mScaleFactor, mScaleFactor);
        mIcon.draw(canvas);
        canvas.restore();
    }

    private class GestureCallback implements VersionedGestureDetector.OnGestureListener {
        public void onDrag(float dx, float dy) {
            mPosX += dx;
            mPosY += dy;
            invalidate();
        }

        public void onScale(float scaleFactor) {
            mScaleFactor *= scaleFactor;

            // Don't let the object get too small or too large.
            mScaleFactor = Math.max(0.1f, Math.min(mScaleFactor, 5.0f));

            invalidate();
        }
    }
}

Wrapping up

We’ve now adapted the touch example app to work from Android 1.5 on through the latest and greatest, taking advantage of newer platform features as available without a single reflective call. The same principles shown here can apply to any new Android feature that you want to use while still allowing your app to run on older platform versions:

  • The ClassLoader loads classes lazily and will only load and verify classes on first access.

  • Factor out app functionality that can differ between platform versions with a version-independent interface or abstract class.

  • Instantiate a version-dependent implementation of it based on the platform version detected at runtime. This keeps the ClassLoader from ever touching a class that it will not be able to verify.

To see the final cross-version touch example app, check out the “cupcake” branch of the android-touchexample project on Google Code.

Extra Credit

In this example we didn’t provide another way for pre-Froyo users to zoom since ScaleGestureDetector was only added as a public API for 2.2. For a real app we would want to offer some alternate affordance to users. Traditionally Android offers a set of small tappable zoom buttons along the bottom of the screen. The ZoomControls and ZoomButtonsController classes in the framework can help you present these controls to the user in a standard way. Implementing this is left as an Lose Weight Exercise for the reader.

Google launches easy app creation tool – Telegraph

July 12, 2010 By: (author unknown) Category: google

The free tool, Google Ap
Inventor for Android
, has been extensively tested among groups of
“amateur” developers who are not computer experts, including schoolchildren,
nursing students and university graduates.

Google said
that the aim of the tool was to enable everyone to write apps for their
mobile phones, and that it was only possible because of the platform’s
“open” nature.

Announcing Google TV: TV meets web. Web meets TV.

May 20, 2010 By: A Googler Category: 1, google

If there’s one entertainment device that people know and love, it’s the television. In fact, 4 billion people across the world watch TV and the average American spends five hours per day in front of one*. Recently, however, an increasing amount of our entertainment experience is coming from our phones and computers. One reason is that these devices have something that the TV lacks: the web. With the web, finding and accessing interesting content is fast and often as easy as a search. But the web still lacks many of the great features and the high-quality viewing experience that the TV offers.

So that got us thinking…what if we helped people experience the best of TV and the best of the web in one seamless experience? Imagine turning on the TV and getting all the channels and shows you normally watch and all of the websites you browse all day — including your favorite video, music and photo sites. We’re excited to announce that we’ve done just that.

Google TV is a new experience for television that combines the TV that you already know with the freedom and power of the Internet. With Google Chrome built in, you can access all of your favorite websites and easily move between television and the web. This opens up your TV from a few hundred channels to millions of channels of entertainment across TV and the web. Your television is also no longer confined to showing just video. With the entire Internet in your living room, your TV becomes more than a TV — it can be a photo slideshow viewer, a gaming console, a music player and much more.

Google TV uses search to give you an easy and fast way to navigate to television channels, websites, apps, shows and movies. For example, already know the channel or program you want to watch? Just type in the name and you’re there. Want to check out that funny YouTube video on your 48” flat screen? It’s just a quick search away. If you know what you want to watch, but you’re not sure where to find it, just type in what you’re looking for and Google TV will help you find it on the web or on one of your many TV channels. If you’d rather browse than search, you can use your standard program guide, your DVR or the Google TV home screen, which provides quick access to all of your favorite entertainment so you’re always within reach of the content you love most.

Because Google TV is built on open platforms like Android and Google Chrome, these features are just a fraction of what Google TV can do. In our announcement today at Google I/O, we challenged web developers to start coming up with the next great web and Android apps designed specifically for the TV experience. Developers can start optimizing their websites for Google TV today. Soon after launch, we’ll release the Google TV SDK and web APIs for TV so that developers can build even richer applications and distribute them through Android Market. We’ve already started building strategic alliances with a number of companies — like Jinni.com and Rovi — at the leading edge of innovation in TV technology. Jinni.com is a next-generation TV application working to provide semantic search, personalized recommendation and social features for Google TV across all sources of premium content available to the user. Rovi is one of the world’s leading guide applications. We’re looking forward to seeing all of the ways developers will use this new platform.

We’re working together with Sony, Logitech and Intel to put Google TV inside of televisions, Blu-ray players and companion boxes. These devices will go on sale this fall, and will be available at Best Buy stores nationwide. You can sign up here to get updates on Google TV availability.

This is an incredibly exciting time — for TV watchers, for developers and for the entire TV ecosystem. By giving people the power to experience what they love on TV and on the web on a single screen, Google TV turns the living room into a new platform for innovation. We’re excited about what’s coming. We hope you are too.

*Nielsen, Three Screen Report, Fourth Quarter 2009

Update 2:26PM: Updated to include more information about other developers.
Update on 5/27/2010: Updated to include additional information about partners.

Posted by Salahuddin Choudhary, Google TV Product Manager