android/GlueIOIOPort: fix spurious errors after IOIO baud rate change
[xcsoar.git] / android / src / DifferentTouchInput.java
blob40a71fad16e7ed713ffcffa78f1a8d8e6de96a7e
1 /* Copyright_License {
3 XCSoar Glide Computer - http://www.xcsoar.org/
4 Copyright (C) 2000-2013 The XCSoar Project
5 A detailed list of copyright holders can be found in the file "AUTHORS".
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 package org.xcsoar;
25 import android.os.Build;
26 import android.view.MotionEvent;
28 /**
29 * Forward MotionEvent object to EventBridge.
31 abstract class DifferentTouchInput {
32 public static DifferentTouchInput getInstance() {
33 if (Build.VERSION.SDK_INT < 8)
34 /* up to Android 2.1 Eclair */
35 return SingleTouchInput.Holder.sInstance;
36 else
37 /* Android 2.2 Froyo or newer */
38 return MultiTouchInput.Holder.sInstance;
41 public abstract void process(final MotionEvent event);
43 /**
44 * Implementation for Android versions that are not capable of
45 * MultiTouch.
47 private static class SingleTouchInput extends DifferentTouchInput {
48 private static class Holder {
49 private static final SingleTouchInput sInstance = new SingleTouchInput();
52 public void process(final MotionEvent event) {
53 switch (event.getAction()) {
54 case MotionEvent.ACTION_DOWN:
55 EventBridge.onMouseDown((int)event.getX(), (int)event.getY());
56 break;
58 case MotionEvent.ACTION_UP:
59 EventBridge.onMouseUp((int)event.getX(), (int)event.getY());
60 break;
62 case MotionEvent.ACTION_MOVE:
63 EventBridge.onMouseMove((int)event.getX(), (int)event.getY());
64 break;
69 /**
70 * Implementation for Android versions with MultiTouch support.
72 private static class MultiTouchInput extends DifferentTouchInput {
73 private static class Holder {
74 private static final MultiTouchInput sInstance = new MultiTouchInput();
77 public void process(final MotionEvent event) {
78 switch (event.getActionMasked()) {
79 case MotionEvent.ACTION_DOWN:
80 EventBridge.onMouseDown((int)event.getX(), (int)event.getY());
81 break;
83 case MotionEvent.ACTION_UP:
84 EventBridge.onMouseUp((int)event.getX(), (int)event.getY());
85 break;
87 case MotionEvent.ACTION_MOVE:
88 EventBridge.onMouseMove((int)event.getX(), (int)event.getY());
89 break;
91 case MotionEvent.ACTION_POINTER_DOWN:
92 EventBridge.onPointerDown();
93 break;
95 case MotionEvent.ACTION_POINTER_UP:
96 EventBridge.onPointerUp();
97 break;