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.
25 import android
.os
.Build
;
26 import android
.view
.MotionEvent
;
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
;
37 /* Android 2.2 Froyo or newer */
38 return MultiTouchInput
.Holder
.sInstance
;
41 public abstract void process(final MotionEvent event
);
44 * Implementation for Android versions that are not capable of
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());
58 case MotionEvent
.ACTION_UP
:
59 EventBridge
.onMouseUp((int)event
.getX(), (int)event
.getY());
62 case MotionEvent
.ACTION_MOVE
:
63 EventBridge
.onMouseMove((int)event
.getX(), (int)event
.getY());
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());
83 case MotionEvent
.ACTION_UP
:
84 EventBridge
.onMouseUp((int)event
.getX(), (int)event
.getY());
87 case MotionEvent
.ACTION_MOVE
:
88 EventBridge
.onMouseMove((int)event
.getX(), (int)event
.getY());
91 case MotionEvent
.ACTION_POINTER_DOWN
:
92 EventBridge
.onPointerDown();
95 case MotionEvent
.ACTION_POINTER_UP
:
96 EventBridge
.onPointerUp();