GestureProvider.java

/**
* Copyright (c) 2012-2013 Nokia Corporation. All rights reserved.
* Nokia and Nokia Connecting People are registered trademarks of Nokia Corporation. 
* Oracle and Java are trademarks or registered trademarks of Oracle and/or its
* affiliates. Other product and company names mentioned herein may be trademarks
* or trade names of their respective owners. 
* See LICENSE.TXT for license information.
*/
package com.nokia.example.racer.gestures;

/**
 * Wrapper for providing gesture support, if there is one.
 * @see com.nokia.mid.ui.gestures
 */
public abstract class GestureProvider {

    private static GestureProvider provider;

    /**
     * Enable gestures if supported.
     *
     * @return true or false
     */
    public static boolean enableGestures() {
        provider = getImplementation();
        if (provider == null) {
            return false;
        }
        else {
            return true;
        }
    }

    /**
     * Loads up the isolated implementation class
     *
     * @return Orientation Returns Orientation implementation or null, if
     * orientations are not supported
     */
    private static GestureProvider getImplementation() {
        GestureProvider implementation = null;
        try {
            Class.forName("com.nokia.mid.ui.gestures.GestureInteractiveZone");

            Class c = Class.forName(
                "com.nokia.example.racer.gestures.GestureProviderImpl");
            implementation = (GestureProvider) (c.newInstance());
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        return implementation;
    }
}