Ticket #9249: android-alternative-mouse.patch
File android-alternative-mouse.patch, 8.1 KB (added by , 14 years ago) |
---|
-
backends/platform/android/org/inodes/gus/scummvm/AlternativeTouchScreenMouse.java
=== added file 'backends/platform/android/org/inodes/gus/scummvm/AlternativeTouchScreenMouse.java'
1 package org.inodes.gus.scummvm; 2 3 import android.util.Log; 4 import android.view.View; 5 import android.view.MotionEvent; 6 import android.view.HapticFeedbackConstants; 7 8 public class AlternativeTouchScreenMouse implements View.OnTouchListener { 9 private ScummVM scummvm; 10 private int press_type; 11 private int release_type; 12 private boolean longpress; 13 private float down_x; 14 private float down_y; 15 16 private final static long LONG_PRESS_TIMEOUT = 1000; 17 private final static float LONG_PRESS_MOVE_THRESHOLD = 8; 18 19 AlternativeTouchScreenMouse(ScummVM vm) { 20 scummvm = vm; 21 press_type = Event.EVENT_INVALID; 22 release_type = Event.EVENT_INVALID; 23 longpress = true; 24 down_x = 0; 25 down_y = 0; 26 } 27 28 @Override 29 public boolean onTouch(View v, MotionEvent event) { 30 Event e; 31 switch (event.getAction()) { 32 case MotionEvent.ACTION_DOWN: 33 longpress = true; 34 down_x = event.getX(); 35 down_y = event.getY(); 36 press_type = Event.EVENT_LBUTTONDOWN; 37 release_type = Event.EVENT_LBUTTONUP; 38 break; 39 case MotionEvent.ACTION_UP: 40 e = new Event(press_type); 41 e.mouse_x = (int)event.getX(); 42 e.mouse_y = (int)event.getY(); 43 e.mouse_relative = false; 44 scummvm.pushEvent(e); 45 46 e = new Event(release_type); 47 e.mouse_x = (int)event.getX(); 48 e.mouse_y = (int)event.getY(); 49 e.mouse_relative = false; 50 scummvm.pushEvent(e); 51 break; 52 case MotionEvent.ACTION_MOVE: 53 if(longpress && press_type != Event.EVENT_RBUTTONDOWN) { 54 if((event.getEventTime() - event.getDownTime()) > LONG_PRESS_TIMEOUT) { 55 press_type = Event.EVENT_RBUTTONDOWN; 56 release_type = Event.EVENT_RBUTTONUP; 57 v.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); 58 } 59 else if((Math.abs(event.getX() - down_x) > LONG_PRESS_MOVE_THRESHOLD) || (Math.abs(event.getY() - down_y) > LONG_PRESS_MOVE_THRESHOLD)) { 60 longpress = false; 61 } 62 } 63 e = new Event(Event.EVENT_MOUSEMOVE); 64 e.mouse_x = (int)event.getX(); 65 e.mouse_y = (int)event.getY(); 66 e.mouse_relative = false; 67 scummvm.pushEvent(e); 68 break; 69 default: 70 return false; 71 } 72 73 return true; 74 } 75 76 } -
backends/platform/android/org/inodes/gus/scummvm/ScummVMActivity.java
=== modified file 'backends/platform/android/org/inodes/gus/scummvm/ScummVMActivity.java'
17 17 import android.view.View; 18 18 import android.view.ViewConfiguration; 19 19 import android.view.inputmethod.InputMethodManager; 20 import android.view.Menu; 21 import android.view.MenuItem; 20 22 import android.widget.Toast; 21 23 22 24 import java.io.IOException; … … 29 31 // FIXME: replace this with proper mouse acceleration 30 32 private final static int TRACKBALL_SCALE = 2; 31 33 34 private final static int MENU_TOGGLE_MOUSE = 0; 35 32 36 private class MyScummVM extends ScummVM { 33 37 private boolean scummvmRunning = false; 34 38 … … 105 109 } 106 110 } 107 111 } 112 113 private class OriginalTouchScreenMouse implements View.OnTouchListener { 114 public boolean onTouch(View v, MotionEvent event) { 115 return onTouchEvent(event); 116 } 117 } 118 119 private OriginalTouchScreenMouse original_mouse; 120 private AlternativeTouchScreenMouse alternative_mouse; 121 108 122 private MyScummVM scummvm; 109 123 private Thread scummvm_thread; 110 124 … … 137 151 } 138 152 139 153 SurfaceView main_surface = (SurfaceView)findViewById(R.id.main_surface); 140 main_surface.setOnTouchListener(new View.OnTouchListener() {141 public boolean onTouch(View v, MotionEvent event) {142 return onTouchEvent(event);143 }144 });154 //main_surface.setOnTouchListener(new View.OnTouchListener() { 155 // public boolean onTouch(View v, MotionEvent event) { 156 // return onTouchEvent(event); 157 // } 158 // }); 145 159 main_surface.setOnKeyListener(new View.OnKeyListener() { 146 160 public boolean onKey(View v, int code, KeyEvent ev) { 147 161 return onKeyDown(code, ev); … … 151 165 152 166 // Start ScummVM 153 167 scummvm = new MyScummVM(); 168 original_mouse = new OriginalTouchScreenMouse(); 169 alternative_mouse = new AlternativeTouchScreenMouse(scummvm); 170 main_surface.setOnTouchListener(original_mouse); 154 171 scummvm_thread = new Thread(new Runnable() { 155 172 public void run() { 156 173 try { … … 247 264 }; 248 265 249 266 @Override 267 public boolean onCreateOptionsMenu(Menu menu) { 268 menu.add(0, MENU_TOGGLE_MOUSE, 0, "Toggle Alternative Mouse").setCheckable(true).setChecked(false); 269 return true; 270 } 271 272 @Override 273 public boolean onPrepareOptionsMenu(Menu menu) { 274 scummvm.pushEvent(new Event(Event.EVENT_MAINMENU)); 275 return true; 276 } 277 278 @Override 279 public boolean onOptionsItemSelected(MenuItem item) { 280 switch (item.getItemId()) { 281 case MENU_TOGGLE_MOUSE: 282 SurfaceView main_surface = (SurfaceView)findViewById(R.id.main_surface); 283 if(item.isChecked()) 284 { 285 main_surface.setOnTouchListener(original_mouse); 286 item.setTitle("Toggle Alternative Mouse"); 287 item.setChecked(false); 288 } 289 else 290 { 291 main_surface.setOnTouchListener(alternative_mouse); 292 item.setTitle("Toggle Original Mouse"); 293 item.setChecked(true); 294 } 295 break; 296 297 } 298 return false; 299 } 300 301 @Override 250 302 public boolean onKeyUp(int keyCode, KeyEvent kevent) { 251 303 return onKeyDown(keyCode, kevent); 252 304 } … … 261 313 public boolean onKeyDown(int keyCode, KeyEvent kevent) { 262 314 // Filter out "special" keys 263 315 switch (keyCode) { 264 case KeyEvent.KEYCODE_MENU:265 // Have to reimplement hold-down-menu-brings-up-softkeybd266 // ourselves, since we are otherwise hijacking the menu267 // key :(268 // See com.android.internal.policy.impl.PhoneWindow.onKeyDownPanel()269 // for the usual Android implementation of this feature.270 if (kevent.getRepeatCount() > 0)271 // Ignore keyrepeat for menu272 return false;273 boolean timeout_fired = false;274 if (getResources().getConfiguration().keyboard ==275 Configuration.KEYBOARD_NOKEYS) {276 timeout_fired = !keycodeMenuTimeoutHandler.hasMessages(MSG_MENU_LONG_PRESS);277 keycodeMenuTimeoutHandler.removeMessages(MSG_MENU_LONG_PRESS);278 if (kevent.getAction() == KeyEvent.ACTION_DOWN) {279 keycodeMenuTimeoutHandler.sendMessageDelayed(280 keycodeMenuTimeoutHandler.obtainMessage(MSG_MENU_LONG_PRESS),281 ViewConfiguration.getLongPressTimeout());282 return true;283 }284 }285 if (kevent.getAction() == KeyEvent.ACTION_UP) {286 if (!timeout_fired)287 scummvm.pushEvent(new Event(Event.EVENT_MAINMENU));288 return true;289 }290 return false;316 // case KeyEvent.KEYCODE_MENU: 317 // // Have to reimplement hold-down-menu-brings-up-softkeybd 318 // // ourselves, since we are otherwise hijacking the menu 319 // // key :( 320 // // See com.android.internal.policy.impl.PhoneWindow.onKeyDownPanel() 321 // // for the usual Android implementation of this feature. 322 // if (kevent.getRepeatCount() > 0) 323 // // Ignore keyrepeat for menu 324 // return false; 325 // boolean timeout_fired = false; 326 // if (getResources().getConfiguration().keyboard == 327 // Configuration.KEYBOARD_NOKEYS) { 328 // timeout_fired = !keycodeMenuTimeoutHandler.hasMessages(MSG_MENU_LONG_PRESS); 329 // keycodeMenuTimeoutHandler.removeMessages(MSG_MENU_LONG_PRESS); 330 // if (kevent.getAction() == KeyEvent.ACTION_DOWN) { 331 // keycodeMenuTimeoutHandler.sendMessageDelayed( 332 // keycodeMenuTimeoutHandler.obtainMessage(MSG_MENU_LONG_PRESS), 333 // ViewConfiguration.getLongPressTimeout()); 334 // return true; 335 // } 336 // } 337 // if (kevent.getAction() == KeyEvent.ACTION_UP) { 338 // if (!timeout_fired) 339 // scummvm.pushEvent(new Event(Event.EVENT_MAINMENU)); 340 // return true; 341 // } 342 // return false; 291 343 case KeyEvent.KEYCODE_CAMERA: 292 344 case KeyEvent.KEYCODE_SEARCH: 293 345 _do_right_click = (kevent.getAction() == KeyEvent.ACTION_DOWN);