The Touch Handler Interface

In order to be able to use our two handler classes interchangeably, we need to define a common interface. Listing 5-8 shows this interface, called TouchHandler.

Listing 5-8., to Be Implemented for Android 1.5 and 1.6.

package com.badlogic.androidgames.framework.impl;

import java.util.List;

import android.view.View.OnTouchListener;

import com.badlogic.androidgames.framework.Input.TouchEvent;

public interface TouchHandler extends OnTouchListener { public boolean isTouchDown(int pointer);

public int getTouchX(int pointer);

public int getTouchY(int pointer);

public List<TouchEvent> getTouchEvents();

All TouchHandlers must also implement the OnTouchListener interface, which we use to register the handler with a View. The methods of the interface correspond to the respective methods in the Input interface defined in Chapter 3. The first three are for polling the state of a specific pointer, and the last one is for getting TouchEvents so we can do event-based input handling. Note that the polling methods take a pointer ID.

Was this article helpful?

0 0

Post a comment