1 // DO NOT EDIT THIS FILE - it is automatically generated, edit file under project/java dir 2 // This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount 3 package org.warmux; 4 5 import android.app.Activity; 6 import android.content.Context; 7 import android.os.Bundle; 8 import android.view.MotionEvent; 9 import android.view.KeyEvent; 10 import android.view.Window; 11 import android.view.WindowManager; 12 import android.widget.TextView; 13 import android.util.Log; 14 import java.io.*; 15 import android.app.AlertDialog; 16 import android.content.DialogInterface; 17 import android.os.Environment; 18 import android.os.StatFs; 19 import java.util.Locale; 20 import java.util.ArrayList; 21 import java.util.Arrays; 22 import java.util.zip.GZIPInputStream; 23 import java.util.Collections; 24 import android.content.Context; 25 import android.content.res.Configuration; 26 import android.content.res.Resources; 27 import java.lang.String; 28 import android.graphics.Matrix; 29 import android.graphics.RectF; 30 import android.view.ViewGroup; 31 import android.widget.ImageView; 32 import android.widget.FrameLayout; 33 import android.graphics.drawable.BitmapDrawable; 34 import android.graphics.BitmapFactory; 35 import android.graphics.Bitmap; 36 import android.widget.TextView; 37 import android.widget.EditText; 38 import android.text.Editable; 39 import android.text.SpannedString; 40 41 42 // TODO: too much code here, split into multiple files, possibly auto-generated menus? 43 class Settings 44 { 45 static String SettingsFileName = "libsdl-settings.cfg"; 46 47 static boolean settingsLoaded = false; 48 static boolean settingsChanged = false; 49 static final int SETTINGS_FILE_VERSION = 4; 50 Save(final MainActivity p)51 static void Save(final MainActivity p) 52 { 53 try { 54 ObjectOutputStream out = new ObjectOutputStream(p.openFileOutput( SettingsFileName, p.MODE_WORLD_READABLE )); 55 out.writeInt(SETTINGS_FILE_VERSION); 56 out.writeBoolean(Globals.DownloadToSdcard); 57 out.writeBoolean(Globals.PhoneHasArrowKeys); 58 out.writeBoolean(Globals.PhoneHasTrackball); 59 out.writeBoolean(Globals.UseAccelerometerAsArrowKeys); 60 out.writeBoolean(Globals.UseTouchscreenKeyboard); 61 out.writeInt(Globals.TouchscreenKeyboardSize); 62 out.writeInt(Globals.AccelerometerSensitivity); 63 out.writeInt(Globals.AccelerometerCenterPos); 64 out.writeInt(Globals.TrackballDampening); 65 out.writeInt(Globals.AudioBufferConfig); 66 out.writeInt(Globals.TouchscreenKeyboardTheme); 67 out.writeInt(Globals.RightClickMethod); 68 out.writeBoolean(Globals.ShowScreenUnderFinger); 69 out.writeInt(Globals.LeftClickMethod); 70 out.writeBoolean(Globals.MoveMouseWithJoystick); 71 out.writeBoolean(Globals.ClickMouseWithDpad); 72 out.writeInt(Globals.ClickScreenPressure); 73 out.writeInt(Globals.ClickScreenTouchspotSize); 74 out.writeBoolean(Globals.KeepAspectRatio); 75 out.writeInt(Globals.MoveMouseWithJoystickSpeed); 76 out.writeInt(Globals.MoveMouseWithJoystickAccel); 77 out.writeInt(SDL_Keys.JAVA_KEYCODE_LAST); 78 for( int i = 0; i < SDL_Keys.JAVA_KEYCODE_LAST; i++ ) 79 { 80 out.writeInt(Globals.RemapHwKeycode[i]); 81 } 82 out.writeInt(Globals.RemapScreenKbKeycode.length); 83 for( int i = 0; i < Globals.RemapScreenKbKeycode.length; i++ ) 84 { 85 out.writeInt(Globals.RemapScreenKbKeycode[i]); 86 } 87 out.writeInt(Globals.ScreenKbControlsShown.length); 88 for( int i = 0; i < Globals.ScreenKbControlsShown.length; i++ ) 89 { 90 out.writeBoolean(Globals.ScreenKbControlsShown[i]); 91 } 92 out.writeInt(Globals.TouchscreenKeyboardTransparency); 93 out.writeInt(Globals.RemapMultitouchGestureKeycode.length); 94 for( int i = 0; i < Globals.RemapMultitouchGestureKeycode.length; i++ ) 95 { 96 out.writeInt(Globals.RemapMultitouchGestureKeycode[i]); 97 out.writeBoolean(Globals.MultitouchGesturesUsed[i]); 98 } 99 out.writeInt(Globals.MultitouchGestureSensitivity); 100 for( int i = 0; i < Globals.TouchscreenCalibration.length; i++ ) 101 out.writeInt(Globals.TouchscreenCalibration[i]); 102 out.writeInt(Globals.DataDir.length()); 103 for( int i = 0; i < Globals.DataDir.length(); i++ ) 104 out.writeChar(Globals.DataDir.charAt(i)); 105 out.writeInt(Globals.CommandLine.length()); 106 for( int i = 0; i < Globals.CommandLine.length(); i++ ) 107 out.writeChar(Globals.CommandLine.charAt(i)); 108 out.writeInt(Globals.ScreenKbControlsLayout.length); 109 for( int i = 0; i < Globals.ScreenKbControlsLayout.length; i++ ) 110 for( int ii = 0; ii < 4; ii++ ) 111 out.writeInt(Globals.ScreenKbControlsLayout[i][ii]); 112 out.writeInt(Globals.LeftClickKey); 113 out.writeInt(Globals.RightClickKey); 114 out.writeBoolean(Globals.SmoothVideo); 115 out.writeInt(Globals.LeftClickTimeout); 116 out.writeInt(Globals.RightClickTimeout); 117 out.writeBoolean(Globals.RelativeMouseMovement); 118 out.writeInt(Globals.RelativeMouseMovementSpeed); 119 out.writeInt(Globals.RelativeMouseMovementAccel); 120 out.writeBoolean(Globals.MultiThreadedVideo); 121 122 out.writeInt(Globals.OptionalDataDownload.length); 123 for(int i = 0; i < Globals.OptionalDataDownload.length; i++) 124 out.writeBoolean(Globals.OptionalDataDownload[i]); 125 126 out.close(); 127 settingsLoaded = true; 128 129 } catch( FileNotFoundException e ) { 130 } catch( SecurityException e ) { 131 } catch ( IOException e ) {}; 132 } 133 Load( final MainActivity p )134 static void Load( final MainActivity p ) 135 { 136 if(settingsLoaded) // Prevent starting twice 137 { 138 return; 139 } 140 System.out.println("libSDL: Settings.Load(): enter"); 141 nativeInitKeymap(); 142 for( int i = 0; i < SDL_Keys.JAVA_KEYCODE_LAST; i++ ) 143 { 144 int sdlKey = nativeGetKeymapKey(i); 145 int idx = 0; 146 for(int ii = 0; ii < SDL_Keys.values.length; ii++) 147 if(SDL_Keys.values[ii] == sdlKey) 148 idx = ii; 149 Globals.RemapHwKeycode[i] = idx; 150 } 151 for( int i = 0; i < Globals.RemapScreenKbKeycode.length; i++ ) 152 { 153 int sdlKey = nativeGetKeymapKeyScreenKb(i); 154 int idx = 0; 155 for(int ii = 0; ii < SDL_Keys.values.length; ii++) 156 if(SDL_Keys.values[ii] == sdlKey) 157 idx = ii; 158 Globals.RemapScreenKbKeycode[i] = idx; 159 } 160 Globals.ScreenKbControlsShown[0] = Globals.AppNeedsArrowKeys; 161 Globals.ScreenKbControlsShown[1] = Globals.AppNeedsTextInput; 162 for( int i = 2; i < Globals.ScreenKbControlsShown.length; i++ ) 163 Globals.ScreenKbControlsShown[i] = ( i - 2 < Globals.AppTouchscreenKeyboardKeysAmount ); 164 for( int i = 0; i < Globals.RemapMultitouchGestureKeycode.length; i++ ) 165 { 166 int sdlKey = nativeGetKeymapKeyMultitouchGesture(i); 167 int idx = 0; 168 for(int ii = 0; ii < SDL_Keys.values.length; ii++) 169 if(SDL_Keys.values[ii] == sdlKey) 170 idx = ii; 171 Globals.RemapMultitouchGestureKeycode[i] = idx; 172 } 173 for( int i = 0; i < Globals.MultitouchGesturesUsed.length; i++ ) 174 Globals.MultitouchGesturesUsed[i] = true; 175 176 try { 177 ObjectInputStream settingsFile = new ObjectInputStream(new FileInputStream( p.getFilesDir().getAbsolutePath() + "/" + SettingsFileName )); 178 if( settingsFile.readInt() != SETTINGS_FILE_VERSION ) 179 throw new IOException(); 180 Globals.DownloadToSdcard = settingsFile.readBoolean(); 181 Globals.PhoneHasArrowKeys = settingsFile.readBoolean(); 182 Globals.PhoneHasTrackball = settingsFile.readBoolean(); 183 Globals.UseAccelerometerAsArrowKeys = settingsFile.readBoolean(); 184 Globals.UseTouchscreenKeyboard = settingsFile.readBoolean(); 185 Globals.TouchscreenKeyboardSize = settingsFile.readInt(); 186 Globals.AccelerometerSensitivity = settingsFile.readInt(); 187 Globals.AccelerometerCenterPos = settingsFile.readInt(); 188 Globals.TrackballDampening = settingsFile.readInt(); 189 Globals.AudioBufferConfig = settingsFile.readInt(); 190 Globals.TouchscreenKeyboardTheme = settingsFile.readInt(); 191 Globals.RightClickMethod = settingsFile.readInt(); 192 Globals.ShowScreenUnderFinger = settingsFile.readBoolean(); 193 Globals.LeftClickMethod = settingsFile.readInt(); 194 Globals.MoveMouseWithJoystick = settingsFile.readBoolean(); 195 Globals.ClickMouseWithDpad = settingsFile.readBoolean(); 196 Globals.ClickScreenPressure = settingsFile.readInt(); 197 Globals.ClickScreenTouchspotSize = settingsFile.readInt(); 198 Globals.KeepAspectRatio = settingsFile.readBoolean(); 199 Globals.MoveMouseWithJoystickSpeed = settingsFile.readInt(); 200 Globals.MoveMouseWithJoystickAccel = settingsFile.readInt(); 201 int readKeys = settingsFile.readInt(); 202 for( int i = 0; i < readKeys; i++ ) 203 { 204 Globals.RemapHwKeycode[i] = settingsFile.readInt(); 205 } 206 if( settingsFile.readInt() != Globals.RemapScreenKbKeycode.length ) 207 throw new IOException(); 208 for( int i = 0; i < Globals.RemapScreenKbKeycode.length; i++ ) 209 { 210 Globals.RemapScreenKbKeycode[i] = settingsFile.readInt(); 211 } 212 if( settingsFile.readInt() != Globals.ScreenKbControlsShown.length ) 213 throw new IOException(); 214 for( int i = 0; i < Globals.ScreenKbControlsShown.length; i++ ) 215 { 216 Globals.ScreenKbControlsShown[i] = settingsFile.readBoolean(); 217 } 218 Globals.TouchscreenKeyboardTransparency = settingsFile.readInt(); 219 if( settingsFile.readInt() != Globals.RemapMultitouchGestureKeycode.length ) 220 throw new IOException(); 221 for( int i = 0; i < Globals.RemapMultitouchGestureKeycode.length; i++ ) 222 { 223 Globals.RemapMultitouchGestureKeycode[i] = settingsFile.readInt(); 224 Globals.MultitouchGesturesUsed[i] = settingsFile.readBoolean(); 225 } 226 Globals.MultitouchGestureSensitivity = settingsFile.readInt(); 227 for( int i = 0; i < Globals.TouchscreenCalibration.length; i++ ) 228 Globals.TouchscreenCalibration[i] = settingsFile.readInt(); 229 StringBuilder b = new StringBuilder(); 230 int len = settingsFile.readInt(); 231 for( int i = 0; i < len; i++ ) 232 b.append( settingsFile.readChar() ); 233 Globals.DataDir = b.toString(); 234 235 b = new StringBuilder(); 236 len = settingsFile.readInt(); 237 for( int i = 0; i < len; i++ ) 238 b.append( settingsFile.readChar() ); 239 Globals.CommandLine = b.toString(); 240 241 if( settingsFile.readInt() != Globals.ScreenKbControlsLayout.length ) 242 throw new IOException(); 243 for( int i = 0; i < Globals.ScreenKbControlsLayout.length; i++ ) 244 for( int ii = 0; ii < 4; ii++ ) 245 Globals.ScreenKbControlsLayout[i][ii] = settingsFile.readInt(); 246 Globals.LeftClickKey = settingsFile.readInt(); 247 Globals.RightClickKey = settingsFile.readInt(); 248 Globals.SmoothVideo = settingsFile.readBoolean(); 249 Globals.LeftClickTimeout = settingsFile.readInt(); 250 Globals.RightClickTimeout = settingsFile.readInt(); 251 Globals.RelativeMouseMovement = settingsFile.readBoolean(); 252 Globals.RelativeMouseMovementSpeed = settingsFile.readInt(); 253 Globals.RelativeMouseMovementAccel = settingsFile.readInt(); 254 Globals.MultiThreadedVideo = settingsFile.readBoolean(); 255 256 Globals.OptionalDataDownload = new boolean[settingsFile.readInt()]; 257 for(int i = 0; i < Globals.OptionalDataDownload.length; i++) 258 Globals.OptionalDataDownload[i] = settingsFile.readBoolean(); 259 260 settingsLoaded = true; 261 262 System.out.println("libSDL: Settings.Load(): loaded settings successfully"); 263 264 return; 265 266 } catch( FileNotFoundException e ) { 267 } catch( SecurityException e ) { 268 } catch ( IOException e ) {}; 269 270 if( Globals.DataDir.length() == 0 ) 271 Globals.DataDir = Globals.DownloadToSdcard ? 272 Environment.getExternalStorageDirectory().getAbsolutePath() + "/Warmux" : 273 p.getFilesDir().getAbsolutePath(); 274 275 // This code fails for both of my phones! 276 /* 277 Configuration c = new Configuration(); 278 c.setToDefaults(); 279 280 if( c.navigation == Configuration.NAVIGATION_TRACKBALL || 281 c.navigation == Configuration.NAVIGATION_DPAD || 282 c.navigation == Configuration.NAVIGATION_WHEEL ) 283 { 284 Globals.AppNeedsArrowKeys = false; 285 } 286 287 System.out.println( "libSDL: Phone keypad type: " + 288 ( 289 c.navigation == Configuration.NAVIGATION_TRACKBALL ? "Trackball" : 290 c.navigation == Configuration.NAVIGATION_DPAD ? "Dpad" : 291 c.navigation == Configuration.NAVIGATION_WHEEL ? "Wheel" : 292 c.navigation == Configuration.NAVIGATION_NONAV ? "None" : 293 "Unknown" ) ); 294 */ 295 296 System.out.println("libSDL: Settings.Load(): loading settings failed, running config dialog"); 297 p.setUpStatusLabel(); 298 showConfig(p); 299 } 300 301 // =============================================================================================== 302 showConfig(final MainActivity p)303 public static void showConfig(final MainActivity p) { 304 settingsChanged = true; 305 306 if( Globals.OptionalDataDownload == null ) 307 { 308 String downloads[] = Globals.DataDownloadUrl.split("\\^"); 309 Globals.OptionalDataDownload = new boolean[downloads.length]; 310 boolean oldFormat = true; 311 for( int i = 0; i < downloads.length; i++ ) 312 { 313 if( downloads[i].indexOf("!") == 0 ) 314 { 315 Globals.OptionalDataDownload[i] = true; 316 oldFormat = false; 317 } 318 } 319 if( oldFormat ) 320 Globals.OptionalDataDownload[0] = true; 321 } 322 323 showConfigMainMenu(p); 324 } 325 326 static int MainMenuLastSelected = 0; showConfigMainMenu(final MainActivity p)327 static void showConfigMainMenu(final MainActivity p) 328 { 329 ArrayList<CharSequence> items = new ArrayList<CharSequence> (); 330 331 items.add(p.getResources().getString(R.string.storage_question)); 332 333 /*items.add(p.getResources().getString(R.string.downloads));*/ 334 335 /* 336 items.add(p.getResources().getString(R.string.controls_additional)); 337 338 if( Globals.UseTouchscreenKeyboard ) 339 items.add(p.getResources().getString(R.string.controls_screenkb));if( Globals.AppUsesMouse ) 340 items.add(p.getResources().getString(R.string.mouse_emulation)); 341 342 if( Globals.AppNeedsArrowKeys || Globals.MoveMouseWithJoystick ) 343 items.add(p.getResources().getString(R.string.controls_question)); 344 345 if( Globals.UseAccelerometerAsArrowKeys || ! Globals.AppHandlesJoystickSensitivity ) 346 items.add(p.getResources().getString(R.string.accel_question)); 347 348 items.add(p.getResources().getString(R.string.audiobuf_question)); 349 350 items.add(p.getResources().getString(R.string.remap_hwkeys)); 351 352 items.add(p.getResources().getString(R.string.remap_screenkb_button_gestures)); 353 * */ 354 355 items.add(p.getResources().getString(R.string.video)); 356 357 items.add(p.getResources().getString(R.string.ok)); 358 359 AlertDialog.Builder builder = new AlertDialog.Builder(p); 360 builder.setTitle(p.getResources().getString(R.string.device_config)); 361 //builder.setSingleChoiceItems(items.toArray(new CharSequence[0]), MainMenuLastSelected, new DialogInterface.OnClickListener() 362 builder.setItems(items.toArray(new CharSequence[0]), new DialogInterface.OnClickListener() 363 { 364 public void onClick(DialogInterface dialog, int item) 365 { 366 MainMenuLastSelected = item; 367 dialog.dismiss(); 368 int selected = 0; 369 370 if( item == selected ) 371 showDownloadConfig(p); 372 selected++; 373 374 /* 375 if( item == selected ) 376 showOptionalDownloadConfig(p); 377 selected++; 378 379 if( item == selected ) 380 showAdditionalInputConfig(p); 381 selected++; 382 383 if( Globals.UseTouchscreenKeyboard ) { 384 if( item == selected ) 385 showScreenKeyboardConfigMainMenu(p); 386 } else 387 item++; 388 selected++; 389 390 if( Globals.AppUsesMouse ) { 391 if( item == selected ) 392 showMouseConfigMainMenu(p); 393 } else 394 item++; 395 selected++; 396 397 if( Globals.AppNeedsArrowKeys || Globals.MoveMouseWithJoystick ) { 398 if( item == selected ) 399 showArrowKeysConfig(p); 400 } else 401 item++; 402 selected++; 403 404 if( Globals.UseAccelerometerAsArrowKeys || ! Globals.AppHandlesJoystickSensitivity ) { 405 if( item == selected ) 406 showAccelerometerConfig(p); 407 } else 408 item++; 409 selected++; 410 411 if( item == selected ) 412 showAudioConfig(p); 413 selected++; 414 415 if( item == selected ) 416 showRemapHwKeysConfig(p); 417 selected++; 418 419 if( item == selected ) 420 showScreenGesturesConfig(p); 421 selected++; 422 */ 423 424 if( item == selected ) 425 showVideoSettingsConfig(p); 426 selected++; 427 428 if( item == selected ) 429 { 430 Save(p); 431 p.startDownloader(); 432 } 433 } 434 }); 435 builder.setOnCancelListener(new DialogInterface.OnCancelListener() 436 { 437 public void onCancel(DialogInterface dialog) 438 { 439 Save(p); 440 p.startDownloader(); 441 } 442 }); 443 AlertDialog alert = builder.create(); 444 alert.setOwnerActivity(p); 445 alert.show(); 446 } 447 448 /* 449 static int MouseConfigMainMenuLastSelected = 0; 450 static void showMouseConfigMainMenu(final MainActivity p) 451 { 452 ArrayList<CharSequence> items = new ArrayList<CharSequence> (); 453 454 items.add(p.getResources().getString(R.string.leftclick_question)); 455 456 if( Globals.AppNeedsTwoButtonMouse ) 457 items.add(p.getResources().getString(R.string.rightclick_question)); 458 459 items.add(p.getResources().getString(R.string.pointandclick_question)); 460 461 if( Globals.MoveMouseWithJoystick ) 462 items.add(p.getResources().getString(R.string.pointandclick_joystickmouse)); 463 464 if( Globals.RightClickMethod == Globals.RIGHT_CLICK_WITH_PRESSURE || Globals.LeftClickMethod == Globals.LEFT_CLICK_WITH_PRESSURE ) 465 items.add(p.getResources().getString(R.string.measurepressure)); 466 467 items.add(p.getResources().getString(R.string.calibrate_touchscreen)); 468 469 items.add(p.getResources().getString(R.string.ok)); 470 471 AlertDialog.Builder builder = new AlertDialog.Builder(p); 472 builder.setTitle(p.getResources().getString(R.string.mouse_emulation)); 473 //builder.setSingleChoiceItems(items.toArray(new CharSequence[0]), MouseConfigMainMenuLastSelected, new DialogInterface.OnClickListener() 474 builder.setItems(items.toArray(new CharSequence[0]), new DialogInterface.OnClickListener() 475 { 476 public void onClick(DialogInterface dialog, int item) 477 { 478 MouseConfigMainMenuLastSelected = item; 479 dialog.dismiss(); 480 int selected = 0; 481 482 if( item == selected ) 483 showLeftClickConfig(p); 484 selected++; 485 486 if( Globals.AppNeedsTwoButtonMouse ) { 487 if( item == selected ) 488 showRightClickConfig(p); 489 } else 490 item++; 491 selected++; 492 493 if( item == selected ) 494 showAdditionalMouseConfig(p); 495 selected++; 496 497 if( Globals.MoveMouseWithJoystick ) { 498 if( item == selected ) 499 showJoystickMouseConfig(p); 500 } else 501 item++; 502 selected++; 503 504 if( Globals.RightClickMethod == Globals.RIGHT_CLICK_WITH_PRESSURE || Globals.LeftClickMethod == Globals.LEFT_CLICK_WITH_PRESSURE ) { 505 if( item == selected ) 506 showTouchPressureMeasurementTool(p); 507 } else 508 item++; 509 selected++; 510 511 if( item == selected ) 512 showCalibrateTouchscreenMenu(p); 513 selected++; 514 515 if( item == selected ) 516 showConfigMainMenu(p); 517 } 518 }); 519 builder.setOnCancelListener(new DialogInterface.OnCancelListener() 520 { 521 public void onCancel(DialogInterface dialog) 522 { 523 showConfigMainMenu(p); 524 } 525 }); 526 AlertDialog alert = builder.create(); 527 alert.setOwnerActivity(p); 528 alert.show(); 529 } 530 531 static int KeyboardConfigMainMenuLastSelected = 0; 532 static void showScreenKeyboardConfigMainMenu(final MainActivity p) 533 { 534 ArrayList<CharSequence> items = new ArrayList<CharSequence> (); 535 536 items.add(p.getResources().getString(R.string.controls_screenkb_theme)); 537 538 items.add(p.getResources().getString(R.string.controls_screenkb_size)); 539 540 items.add(p.getResources().getString(R.string.controls_screenkb_transparency)); 541 542 items.add(p.getResources().getString(R.string.remap_screenkb)); 543 544 items.add(p.getResources().getString(R.string.screenkb_custom_layout)); 545 546 items.add(p.getResources().getString(R.string.ok)); 547 548 AlertDialog.Builder builder = new AlertDialog.Builder(p); 549 builder.setTitle(p.getResources().getString(R.string.controls_screenkb)); 550 //builder.setSingleChoiceItems(items.toArray(new CharSequence[0]), KeyboardConfigMainMenuLastSelected, new DialogInterface.OnClickListener() 551 builder.setItems(items.toArray(new CharSequence[0]), new DialogInterface.OnClickListener() 552 { 553 public void onClick(DialogInterface dialog, int item) 554 { 555 KeyboardConfigMainMenuLastSelected = item; 556 dialog.dismiss(); 557 int selected = 0; 558 559 if( item == selected ) 560 showScreenKeyboardThemeConfig(p); 561 selected++; 562 563 if( item == selected ) 564 showScreenKeyboardSizeConfig(p); 565 selected++; 566 567 if( item == selected ) 568 showScreenKeyboardTransparencyConfig(p); 569 selected++; 570 571 if( item == selected ) 572 showRemapScreenKbConfig(p); 573 selected++; 574 575 if( item == selected ) 576 showCustomizeScreenKbLayout(p); 577 selected++; 578 579 if( item == selected ) 580 showConfigMainMenu(p); 581 } 582 }); 583 builder.setOnCancelListener(new DialogInterface.OnCancelListener() 584 { 585 public void onCancel(DialogInterface dialog) 586 { 587 showConfigMainMenu(p); 588 } 589 }); 590 AlertDialog alert = builder.create(); 591 alert.setOwnerActivity(p); 592 alert.show(); 593 } 594 */ 595 showDownloadConfig(final MainActivity p)596 static void showDownloadConfig(final MainActivity p) { 597 598 long freeSdcard = 0; 599 long freePhone = 0; 600 try { 601 StatFs sdcard = new StatFs(Environment.getExternalStorageDirectory().getPath()); 602 StatFs phone = new StatFs(Environment.getDataDirectory().getPath()); 603 freeSdcard = (long)sdcard.getAvailableBlocks() * sdcard.getBlockSize() / 1024 / 1024; 604 freePhone = (long)phone.getAvailableBlocks() * phone.getBlockSize() / 1024 / 1024; 605 }catch(Exception e) {} 606 607 final CharSequence[] items = { p.getResources().getString(R.string.storage_phone, freePhone), 608 p.getResources().getString(R.string.storage_sd, freeSdcard), 609 p.getResources().getString(R.string.storage_custom) }; 610 AlertDialog.Builder builder = new AlertDialog.Builder(p); 611 builder.setTitle(p.getResources().getString(R.string.storage_question)); 612 builder.setSingleChoiceItems(items, Globals.DownloadToSdcard ? 1 : 0, new DialogInterface.OnClickListener() 613 { 614 public void onClick(DialogInterface dialog, int item) 615 { 616 dialog.dismiss(); 617 618 if( item == 2 ) 619 showCustomDownloadDirConfig(p); 620 else 621 { 622 Globals.DownloadToSdcard = (item != 0); 623 Globals.DataDir = Globals.DownloadToSdcard ? 624 Environment.getExternalStorageDirectory().getAbsolutePath() + "/Warmux" : 625 p.getFilesDir().getAbsolutePath(); 626 showConfigMainMenu(p); 627 } 628 } 629 }); 630 builder.setOnCancelListener(new DialogInterface.OnCancelListener() 631 { 632 public void onCancel(DialogInterface dialog) 633 { 634 showConfigMainMenu(p); 635 } 636 }); 637 AlertDialog alert = builder.create(); 638 alert.setOwnerActivity(p); 639 alert.show(); 640 }; 641 showCustomDownloadDirConfig(final MainActivity p)642 static void showCustomDownloadDirConfig(final MainActivity p) { 643 644 AlertDialog.Builder builder = new AlertDialog.Builder(p); 645 builder.setTitle(p.getResources().getString(R.string.storage_custom)); 646 647 final EditText edit = new EditText(p); 648 edit.setFocusableInTouchMode(true); 649 edit.setFocusable(true); 650 edit.setText(Globals.DataDir); 651 builder.setView(edit); 652 653 builder.setPositiveButton(p.getResources().getString(R.string.ok), new DialogInterface.OnClickListener() 654 { 655 public void onClick(DialogInterface dialog, int item) 656 { 657 Globals.DataDir = edit.getText().toString(); 658 dialog.dismiss(); 659 showCommandLineConfig(p); 660 } 661 }); 662 builder.setOnCancelListener(new DialogInterface.OnCancelListener() 663 { 664 public void onCancel(DialogInterface dialog) 665 { 666 showConfigMainMenu(p); 667 } 668 }); 669 AlertDialog alert = builder.create(); 670 alert.setOwnerActivity(p); 671 alert.show(); 672 }; 673 showCommandLineConfig(final MainActivity p)674 static void showCommandLineConfig(final MainActivity p) { 675 676 AlertDialog.Builder builder = new AlertDialog.Builder(p); 677 builder.setTitle(p.getResources().getString(R.string.storage_commandline)); 678 679 final EditText edit = new EditText(p); 680 edit.setFocusableInTouchMode(true); 681 edit.setFocusable(true); 682 edit.setText(Globals.CommandLine); 683 builder.setView(edit); 684 685 builder.setPositiveButton(p.getResources().getString(R.string.ok), new DialogInterface.OnClickListener() 686 { 687 public void onClick(DialogInterface dialog, int item) 688 { 689 Globals.CommandLine = edit.getText().toString(); 690 dialog.dismiss(); 691 showConfigMainMenu(p); 692 } 693 }); 694 builder.setOnCancelListener(new DialogInterface.OnCancelListener() 695 { 696 public void onCancel(DialogInterface dialog) 697 { 698 showConfigMainMenu(p); 699 } 700 }); 701 AlertDialog alert = builder.create(); 702 alert.setOwnerActivity(p); 703 alert.show(); 704 }; 705 706 /* 707 static void showOptionalDownloadConfig(final MainActivity p) { 708 709 String [] downloadFiles = Globals.DataDownloadUrl.split("\\^"); 710 711 AlertDialog.Builder builder = new AlertDialog.Builder(p); 712 builder.setTitle(p.getResources().getString(R.string.downloads)); 713 714 CharSequence[] items = new CharSequence[downloadFiles.length]; 715 for(int i = 0; i < downloadFiles.length; i++ ) 716 { 717 items[i] = new String(downloadFiles[i].split("[|]")[0]); 718 if( items[i].toString().indexOf("!") == 0 ) 719 items[i] = items[i].toString().substring(1); 720 } 721 722 if( Globals.OptionalDataDownload == null || Globals.OptionalDataDownload.length != items.length ) 723 { 724 Globals.OptionalDataDownload = new boolean[downloadFiles.length]; 725 boolean oldFormat = true; 726 for( int i = 0; i < downloadFiles.length; i++ ) 727 { 728 if( downloadFiles[i].indexOf("!") == 0 ) 729 { 730 Globals.OptionalDataDownload[i] = true; 731 oldFormat = false; 732 } 733 } 734 if( oldFormat ) 735 Globals.OptionalDataDownload[0] = true; 736 } 737 738 builder.setMultiChoiceItems(items, Globals.OptionalDataDownload, new DialogInterface.OnMultiChoiceClickListener() 739 { 740 public void onClick(DialogInterface dialog, int item, boolean isChecked) 741 { 742 Globals.OptionalDataDownload[item] = isChecked; 743 } 744 }); 745 builder.setPositiveButton(p.getResources().getString(R.string.ok), new DialogInterface.OnClickListener() 746 { 747 public void onClick(DialogInterface dialog, int item) 748 { 749 dialog.dismiss(); 750 showConfigMainMenu(p); 751 } 752 }); 753 builder.setOnCancelListener(new DialogInterface.OnCancelListener() 754 { 755 public void onCancel(DialogInterface dialog) 756 { 757 showConfigMainMenu(p); 758 } 759 }); 760 AlertDialog alert = builder.create(); 761 alert.setOwnerActivity(p); 762 alert.show(); 763 }; 764 765 static void showAdditionalInputConfig(final MainActivity p) 766 { 767 CharSequence[] items = { 768 p.getResources().getString(R.string.controls_screenkb), 769 p.getResources().getString(R.string.controls_accelnav) 770 }; 771 772 boolean defaults[] = { 773 Globals.UseTouchscreenKeyboard, 774 Globals.UseAccelerometerAsArrowKeys 775 }; 776 777 AlertDialog.Builder builder = new AlertDialog.Builder(p); 778 builder.setTitle(p.getResources().getString(R.string.controls_additional)); 779 builder.setMultiChoiceItems(items, defaults, new DialogInterface.OnMultiChoiceClickListener() 780 { 781 public void onClick(DialogInterface dialog, int item, boolean isChecked) 782 { 783 if( item == 0 ) 784 Globals.UseTouchscreenKeyboard = isChecked; 785 if( item == 1 ) 786 Globals.UseAccelerometerAsArrowKeys = isChecked; 787 } 788 }); 789 builder.setPositiveButton(p.getResources().getString(R.string.ok), new DialogInterface.OnClickListener() 790 { 791 public void onClick(DialogInterface dialog, int item) 792 { 793 dialog.dismiss(); 794 showConfigMainMenu(p); 795 } 796 }); 797 builder.setOnCancelListener(new DialogInterface.OnCancelListener() 798 { 799 public void onCancel(DialogInterface dialog) 800 { 801 showConfigMainMenu(p); 802 } 803 }); 804 AlertDialog alert = builder.create(); 805 alert.setOwnerActivity(p); 806 alert.show(); 807 } 808 809 static void showAccelerometerConfig(final MainActivity p) 810 { 811 if( ! Globals.UseAccelerometerAsArrowKeys || Globals.AppHandlesJoystickSensitivity ) 812 { 813 Globals.AccelerometerSensitivity = 2; // Slow, full range 814 showAccelerometerCenterConfig(p); 815 return; 816 } 817 818 final CharSequence[] items = { p.getResources().getString(R.string.accel_fast), 819 p.getResources().getString(R.string.accel_medium), 820 p.getResources().getString(R.string.accel_slow) }; 821 822 AlertDialog.Builder builder = new AlertDialog.Builder(p); 823 builder.setTitle(R.string.accel_question); 824 builder.setSingleChoiceItems(items, Globals.AccelerometerSensitivity, new DialogInterface.OnClickListener() 825 { 826 public void onClick(DialogInterface dialog, int item) 827 { 828 Globals.AccelerometerSensitivity = item; 829 830 dialog.dismiss(); 831 showAccelerometerCenterConfig(p); 832 } 833 }); 834 builder.setOnCancelListener(new DialogInterface.OnCancelListener() 835 { 836 public void onCancel(DialogInterface dialog) 837 { 838 showConfigMainMenu(p); 839 } 840 }); 841 AlertDialog alert = builder.create(); 842 alert.setOwnerActivity(p); 843 alert.show(); 844 } 845 846 static void showAccelerometerCenterConfig(final MainActivity p) 847 { 848 if( ! Globals.UseAccelerometerAsArrowKeys || Globals.AppHandlesJoystickSensitivity ) 849 { 850 Globals.AccelerometerCenterPos = 2; // Fixed horizontal center position 851 showConfigMainMenu(p); 852 return; 853 } 854 855 final CharSequence[] items = { p.getResources().getString(R.string.accel_floating), 856 p.getResources().getString(R.string.accel_fixed_start), 857 p.getResources().getString(R.string.accel_fixed_horiz) }; 858 859 AlertDialog.Builder builder = new AlertDialog.Builder(p); 860 builder.setTitle(R.string.accel_question_center); 861 builder.setSingleChoiceItems(items, Globals.AccelerometerCenterPos, new DialogInterface.OnClickListener() 862 { 863 public void onClick(DialogInterface dialog, int item) 864 { 865 Globals.AccelerometerCenterPos = item; 866 867 dialog.dismiss(); 868 showConfigMainMenu(p); 869 } 870 }); 871 builder.setOnCancelListener(new DialogInterface.OnCancelListener() 872 { 873 public void onCancel(DialogInterface dialog) 874 { 875 showConfigMainMenu(p); 876 } 877 }); 878 AlertDialog alert = builder.create(); 879 alert.setOwnerActivity(p); 880 alert.show(); 881 } 882 883 884 static void showScreenKeyboardSizeConfig(final MainActivity p) 885 { 886 final CharSequence[] items = { p.getResources().getString(R.string.controls_screenkb_large), 887 p.getResources().getString(R.string.controls_screenkb_medium), 888 p.getResources().getString(R.string.controls_screenkb_small), 889 p.getResources().getString(R.string.controls_screenkb_tiny) }; 890 891 for( int i = 0; i < Globals.ScreenKbControlsLayout.length; i++ ) 892 for( int ii = 0; ii < 4; ii++ ) 893 Globals.ScreenKbControlsLayout[i][ii] = 0; 894 895 AlertDialog.Builder builder = new AlertDialog.Builder(p); 896 builder.setTitle(p.getResources().getString(R.string.controls_screenkb_size)); 897 builder.setSingleChoiceItems(items, Globals.TouchscreenKeyboardSize, new DialogInterface.OnClickListener() 898 { 899 public void onClick(DialogInterface dialog, int item) 900 { 901 Globals.TouchscreenKeyboardSize = item; 902 903 dialog.dismiss(); 904 showScreenKeyboardConfigMainMenu(p); 905 } 906 }); 907 builder.setOnCancelListener(new DialogInterface.OnCancelListener() 908 { 909 public void onCancel(DialogInterface dialog) 910 { 911 showConfigMainMenu(p); 912 } 913 }); 914 AlertDialog alert = builder.create(); 915 alert.setOwnerActivity(p); 916 alert.show(); 917 } 918 919 static void showScreenKeyboardThemeConfig(final MainActivity p) 920 { 921 final CharSequence[] items = { 922 p.getResources().getString(R.string.controls_screenkb_by, "Ultimate Droid", "Sean Stieber"), 923 p.getResources().getString(R.string.controls_screenkb_by, "Simple Theme", "Beholder") 924 }; 925 926 AlertDialog.Builder builder = new AlertDialog.Builder(p); 927 builder.setTitle(p.getResources().getString(R.string.controls_screenkb_theme)); 928 builder.setSingleChoiceItems(items, Globals.TouchscreenKeyboardTheme, new DialogInterface.OnClickListener() 929 { 930 public void onClick(DialogInterface dialog, int item) 931 { 932 Globals.TouchscreenKeyboardTheme = item; 933 934 dialog.dismiss(); 935 showScreenKeyboardConfigMainMenu(p); 936 } 937 }); 938 builder.setOnCancelListener(new DialogInterface.OnCancelListener() 939 { 940 public void onCancel(DialogInterface dialog) 941 { 942 showConfigMainMenu(p); 943 } 944 }); 945 AlertDialog alert = builder.create(); 946 alert.setOwnerActivity(p); 947 alert.show(); 948 } 949 950 static void showScreenKeyboardTransparencyConfig(final MainActivity p) 951 { 952 final CharSequence[] items = { p.getResources().getString(R.string.controls_screenkb_trans_0), 953 p.getResources().getString(R.string.controls_screenkb_trans_1), 954 p.getResources().getString(R.string.controls_screenkb_trans_2), 955 p.getResources().getString(R.string.controls_screenkb_trans_3), 956 p.getResources().getString(R.string.controls_screenkb_trans_4) }; 957 958 AlertDialog.Builder builder = new AlertDialog.Builder(p); 959 builder.setTitle(p.getResources().getString(R.string.controls_screenkb_transparency)); 960 builder.setSingleChoiceItems(items, Globals.TouchscreenKeyboardTransparency, new DialogInterface.OnClickListener() 961 { 962 public void onClick(DialogInterface dialog, int item) 963 { 964 Globals.TouchscreenKeyboardTransparency = item; 965 966 dialog.dismiss(); 967 showScreenKeyboardConfigMainMenu(p); 968 } 969 }); 970 builder.setOnCancelListener(new DialogInterface.OnCancelListener() 971 { 972 public void onCancel(DialogInterface dialog) 973 { 974 showConfigMainMenu(p); 975 } 976 }); 977 AlertDialog alert = builder.create(); 978 alert.setOwnerActivity(p); 979 alert.show(); 980 } 981 982 static void showAudioConfig(final MainActivity p) 983 { 984 final CharSequence[] items = { p.getResources().getString(R.string.audiobuf_verysmall), 985 p.getResources().getString(R.string.audiobuf_small), 986 p.getResources().getString(R.string.audiobuf_medium), 987 p.getResources().getString(R.string.audiobuf_large) }; 988 989 AlertDialog.Builder builder = new AlertDialog.Builder(p); 990 builder.setTitle(R.string.audiobuf_question); 991 builder.setSingleChoiceItems(items, Globals.AudioBufferConfig, new DialogInterface.OnClickListener() 992 { 993 public void onClick(DialogInterface dialog, int item) 994 { 995 Globals.AudioBufferConfig = item; 996 dialog.dismiss(); 997 showConfigMainMenu(p); 998 } 999 }); 1000 builder.setOnCancelListener(new DialogInterface.OnCancelListener() 1001 { 1002 public void onCancel(DialogInterface dialog) 1003 { 1004 showConfigMainMenu(p); 1005 } 1006 }); 1007 AlertDialog alert = builder.create(); 1008 alert.setOwnerActivity(p); 1009 alert.show(); 1010 } 1011 1012 static void showLeftClickConfig(final MainActivity p) 1013 { 1014 if( ! Globals.AppUsesMouse ) 1015 { 1016 Globals.LeftClickMethod = Globals.LEFT_CLICK_NORMAL; 1017 showMouseConfigMainMenu(p); 1018 return; 1019 } 1020 final CharSequence[] items = { p.getResources().getString(R.string.leftclick_normal), 1021 p.getResources().getString(R.string.leftclick_near_cursor), 1022 p.getResources().getString(R.string.leftclick_multitouch), 1023 p.getResources().getString(R.string.leftclick_pressure), 1024 p.getResources().getString(R.string.rightclick_key), 1025 p.getResources().getString(R.string.leftclick_timeout), 1026 p.getResources().getString(R.string.leftclick_tap), 1027 p.getResources().getString(R.string.leftclick_tap_or_timeout) }; 1028 1029 AlertDialog.Builder builder = new AlertDialog.Builder(p); 1030 builder.setTitle(R.string.leftclick_question); 1031 builder.setSingleChoiceItems(items, Globals.LeftClickMethod, new DialogInterface.OnClickListener() 1032 { 1033 public void onClick(DialogInterface dialog, int item) 1034 { 1035 Globals.LeftClickMethod = item; 1036 dialog.dismiss(); 1037 if( item == Globals.LEFT_CLICK_WITH_KEY ) 1038 p.keyListener = new KeyRemapToolMouseClick(p, true); 1039 else if( item == Globals.LEFT_CLICK_WITH_TIMEOUT || item == Globals.LEFT_CLICK_WITH_TAP_OR_TIMEOUT ) 1040 showLeftClickTimeoutConfig(p); 1041 else 1042 showMouseConfigMainMenu(p); 1043 } 1044 }); 1045 builder.setOnCancelListener(new DialogInterface.OnCancelListener() 1046 { 1047 public void onCancel(DialogInterface dialog) 1048 { 1049 showConfigMainMenu(p); 1050 } 1051 }); 1052 AlertDialog alert = builder.create(); 1053 alert.setOwnerActivity(p); 1054 alert.show(); 1055 } 1056 1057 static void showLeftClickTimeoutConfig(final MainActivity p) { 1058 final CharSequence[] items = { p.getResources().getString(R.string.leftclick_timeout_time_0), 1059 p.getResources().getString(R.string.leftclick_timeout_time_1), 1060 p.getResources().getString(R.string.leftclick_timeout_time_2), 1061 p.getResources().getString(R.string.leftclick_timeout_time_3), 1062 p.getResources().getString(R.string.leftclick_timeout_time_4) }; 1063 1064 AlertDialog.Builder builder = new AlertDialog.Builder(p); 1065 builder.setTitle(R.string.leftclick_timeout_time); 1066 builder.setSingleChoiceItems(items, Globals.LeftClickTimeout, new DialogInterface.OnClickListener() 1067 { 1068 public void onClick(DialogInterface dialog, int item) 1069 { 1070 Globals.LeftClickTimeout = item; 1071 dialog.dismiss(); 1072 showMouseConfigMainMenu(p); 1073 } 1074 }); 1075 builder.setOnCancelListener(new DialogInterface.OnCancelListener() 1076 { 1077 public void onCancel(DialogInterface dialog) 1078 { 1079 showConfigMainMenu(p); 1080 } 1081 }); 1082 AlertDialog alert = builder.create(); 1083 alert.setOwnerActivity(p); 1084 alert.show(); 1085 } 1086 1087 static void showRightClickConfig(final MainActivity p) 1088 { 1089 if( ! Globals.AppNeedsTwoButtonMouse ) 1090 { 1091 Globals.RightClickMethod = Globals.RIGHT_CLICK_NONE; 1092 showMouseConfigMainMenu(p); 1093 return; 1094 } 1095 final CharSequence[] items = { p.getResources().getString(R.string.rightclick_none), 1096 p.getResources().getString(R.string.rightclick_multitouch), 1097 p.getResources().getString(R.string.rightclick_pressure), 1098 p.getResources().getString(R.string.rightclick_key), 1099 p.getResources().getString(R.string.leftclick_timeout) }; 1100 1101 AlertDialog.Builder builder = new AlertDialog.Builder(p); 1102 builder.setTitle(R.string.rightclick_question); 1103 builder.setSingleChoiceItems(items, Globals.RightClickMethod, new DialogInterface.OnClickListener() 1104 { 1105 public void onClick(DialogInterface dialog, int item) 1106 { 1107 Globals.RightClickMethod = item; 1108 dialog.dismiss(); 1109 if( item == Globals.RIGHT_CLICK_WITH_KEY ) 1110 p.keyListener = new KeyRemapToolMouseClick(p, false); 1111 else if( item == Globals.RIGHT_CLICK_WITH_TIMEOUT ) 1112 showRightClickTimeoutConfig(p); 1113 else 1114 showMouseConfigMainMenu(p); 1115 } 1116 }); 1117 builder.setOnCancelListener(new DialogInterface.OnCancelListener() 1118 { 1119 public void onCancel(DialogInterface dialog) 1120 { 1121 showConfigMainMenu(p); 1122 } 1123 }); 1124 AlertDialog alert = builder.create(); 1125 alert.setOwnerActivity(p); 1126 alert.show(); 1127 } 1128 1129 static void showRightClickTimeoutConfig(final MainActivity p) { 1130 final CharSequence[] items = { p.getResources().getString(R.string.leftclick_timeout_time_0), 1131 p.getResources().getString(R.string.leftclick_timeout_time_1), 1132 p.getResources().getString(R.string.leftclick_timeout_time_2), 1133 p.getResources().getString(R.string.leftclick_timeout_time_3), 1134 p.getResources().getString(R.string.leftclick_timeout_time_4) }; 1135 1136 AlertDialog.Builder builder = new AlertDialog.Builder(p); 1137 builder.setTitle(R.string.leftclick_timeout_time); 1138 builder.setSingleChoiceItems(items, Globals.RightClickTimeout, new DialogInterface.OnClickListener() 1139 { 1140 public void onClick(DialogInterface dialog, int item) 1141 { 1142 Globals.RightClickTimeout = item; 1143 dialog.dismiss(); 1144 showMouseConfigMainMenu(p); 1145 } 1146 }); 1147 builder.setOnCancelListener(new DialogInterface.OnCancelListener() 1148 { 1149 public void onCancel(DialogInterface dialog) 1150 { 1151 showConfigMainMenu(p); 1152 } 1153 }); 1154 AlertDialog alert = builder.create(); 1155 alert.setOwnerActivity(p); 1156 alert.show(); 1157 } 1158 1159 public static class KeyRemapToolMouseClick implements KeyEventsListener 1160 { 1161 MainActivity p; 1162 boolean leftClick; 1163 public KeyRemapToolMouseClick(MainActivity _p, boolean leftClick) 1164 { 1165 p = _p; 1166 p.setText(p.getResources().getString(R.string.remap_hwkeys_press)); 1167 this.leftClick = leftClick; 1168 } 1169 1170 public void onKeyEvent(final int keyCode) 1171 { 1172 p.touchListener = null; 1173 int keyIndex = keyCode; 1174 if( keyIndex < 0 ) 1175 keyIndex = 0; 1176 if( keyIndex > SDL_Keys.JAVA_KEYCODE_LAST ) 1177 keyIndex = 0; 1178 1179 if( leftClick ) 1180 Globals.LeftClickKey = keyIndex; 1181 else 1182 Globals.RightClickKey = keyIndex; 1183 1184 showMouseConfigMainMenu(p); 1185 } 1186 } 1187 1188 static void showAdditionalMouseConfig(final MainActivity p) 1189 { 1190 CharSequence[] items = { 1191 p.getResources().getString(R.string.pointandclick_showcreenunderfinger2), 1192 p.getResources().getString(R.string.pointandclick_joystickmouse), 1193 p.getResources().getString(R.string.click_with_dpadcenter), 1194 p.getResources().getString(R.string.pointandclick_relative) 1195 }; 1196 1197 boolean defaults[] = { 1198 Globals.ShowScreenUnderFinger, 1199 Globals.MoveMouseWithJoystick, 1200 Globals.ClickMouseWithDpad, 1201 Globals.RelativeMouseMovement 1202 }; 1203 1204 1205 AlertDialog.Builder builder = new AlertDialog.Builder(p); 1206 builder.setTitle(p.getResources().getString(R.string.pointandclick_question)); 1207 builder.setMultiChoiceItems(items, defaults, new DialogInterface.OnMultiChoiceClickListener() 1208 { 1209 public void onClick(DialogInterface dialog, int item, boolean isChecked) 1210 { 1211 if( item == 0 ) 1212 Globals.ShowScreenUnderFinger = isChecked; 1213 if( item == 1 ) 1214 Globals.MoveMouseWithJoystick = isChecked; 1215 if( item == 2 ) 1216 Globals.ClickMouseWithDpad = isChecked; 1217 if( item == 3 ) 1218 Globals.RelativeMouseMovement = isChecked; 1219 } 1220 }); 1221 builder.setPositiveButton(p.getResources().getString(R.string.ok), new DialogInterface.OnClickListener() 1222 { 1223 public void onClick(DialogInterface dialog, int item) 1224 { 1225 dialog.dismiss(); 1226 if( Globals.RelativeMouseMovement ) 1227 showRelativeMouseMovementConfig(p); 1228 else 1229 showMouseConfigMainMenu(p); 1230 } 1231 }); 1232 builder.setOnCancelListener(new DialogInterface.OnCancelListener() 1233 { 1234 public void onCancel(DialogInterface dialog) 1235 { 1236 showConfigMainMenu(p); 1237 } 1238 }); 1239 AlertDialog alert = builder.create(); 1240 alert.setOwnerActivity(p); 1241 alert.show(); 1242 } 1243 1244 static void showRelativeMouseMovementConfig(final MainActivity p) 1245 { 1246 final CharSequence[] items = { p.getResources().getString(R.string.accel_veryslow), 1247 p.getResources().getString(R.string.accel_slow), 1248 p.getResources().getString(R.string.accel_medium), 1249 p.getResources().getString(R.string.accel_fast), 1250 p.getResources().getString(R.string.accel_veryfast) }; 1251 1252 AlertDialog.Builder builder = new AlertDialog.Builder(p); 1253 builder.setTitle(R.string.pointandclick_relative_speed); 1254 builder.setSingleChoiceItems(items, Globals.RelativeMouseMovementSpeed, new DialogInterface.OnClickListener() 1255 { 1256 public void onClick(DialogInterface dialog, int item) 1257 { 1258 Globals.RelativeMouseMovementSpeed = item; 1259 1260 dialog.dismiss(); 1261 showRelativeMouseMovementConfig1(p); 1262 } 1263 }); 1264 builder.setOnCancelListener(new DialogInterface.OnCancelListener() 1265 { 1266 public void onCancel(DialogInterface dialog) 1267 { 1268 showConfigMainMenu(p); 1269 } 1270 }); 1271 AlertDialog alert = builder.create(); 1272 alert.setOwnerActivity(p); 1273 alert.show(); 1274 } 1275 1276 static void showRelativeMouseMovementConfig1(final MainActivity p) 1277 { 1278 final CharSequence[] items = { p.getResources().getString(R.string.none), 1279 p.getResources().getString(R.string.accel_slow), 1280 p.getResources().getString(R.string.accel_medium), 1281 p.getResources().getString(R.string.accel_fast) }; 1282 1283 AlertDialog.Builder builder = new AlertDialog.Builder(p); 1284 builder.setTitle(R.string.pointandclick_relative_accel); 1285 builder.setSingleChoiceItems(items, Globals.RelativeMouseMovementAccel, new DialogInterface.OnClickListener() 1286 { 1287 public void onClick(DialogInterface dialog, int item) 1288 { 1289 Globals.RelativeMouseMovementAccel = item; 1290 1291 dialog.dismiss(); 1292 showMouseConfigMainMenu(p); 1293 } 1294 }); 1295 builder.setOnCancelListener(new DialogInterface.OnCancelListener() 1296 { 1297 public void onCancel(DialogInterface dialog) 1298 { 1299 showConfigMainMenu(p); 1300 } 1301 }); 1302 AlertDialog alert = builder.create(); 1303 alert.setOwnerActivity(p); 1304 alert.show(); 1305 } 1306 */ 1307 showArrowKeysConfig(final MainActivity p)1308 static void showArrowKeysConfig(final MainActivity p) 1309 { 1310 if( ! Globals.AppNeedsArrowKeys && ! Globals.MoveMouseWithJoystick ) 1311 { 1312 Globals.PhoneHasArrowKeys = false; 1313 Globals.PhoneHasTrackball = false; 1314 showTrackballConfig(p); 1315 return; 1316 } 1317 1318 final CharSequence[] items = { p.getResources().getString(R.string.controls_arrows), 1319 p.getResources().getString(R.string.controls_trackball), 1320 p.getResources().getString(R.string.controls_touch) }; 1321 1322 AlertDialog.Builder builder = new AlertDialog.Builder(p); 1323 builder.setTitle(p.getResources().getString(R.string.controls_question)); 1324 builder.setSingleChoiceItems(items, Globals.PhoneHasArrowKeys ? 0 : ( Globals.PhoneHasTrackball ? 1 : 2 ), new DialogInterface.OnClickListener() 1325 { 1326 public void onClick(DialogInterface dialog, int item) 1327 { 1328 Globals.PhoneHasArrowKeys = (item == 0); 1329 Globals.PhoneHasTrackball = (item == 1); 1330 1331 dialog.dismiss(); 1332 showTrackballConfig(p); 1333 } 1334 }); 1335 builder.setOnCancelListener(new DialogInterface.OnCancelListener() 1336 { 1337 public void onCancel(DialogInterface dialog) 1338 { 1339 showConfigMainMenu(p); 1340 } 1341 }); 1342 AlertDialog alert = builder.create(); 1343 alert.setOwnerActivity(p); 1344 alert.show(); 1345 } 1346 showTrackballConfig(final MainActivity p)1347 static void showTrackballConfig(final MainActivity p) 1348 { 1349 if( ! Globals.PhoneHasTrackball ) 1350 { 1351 Globals.TrackballDampening = 0; 1352 showConfigMainMenu(p); 1353 return; 1354 } 1355 1356 final CharSequence[] items = { p.getResources().getString(R.string.trackball_no_dampening), 1357 p.getResources().getString(R.string.trackball_fast), 1358 p.getResources().getString(R.string.trackball_medium), 1359 p.getResources().getString(R.string.trackball_slow) }; 1360 1361 AlertDialog.Builder builder = new AlertDialog.Builder(p); 1362 builder.setTitle(p.getResources().getString(R.string.trackball_question)); 1363 builder.setSingleChoiceItems(items, Globals.TrackballDampening, new DialogInterface.OnClickListener() 1364 { 1365 public void onClick(DialogInterface dialog, int item) 1366 { 1367 Globals.TrackballDampening = item; 1368 1369 dialog.dismiss(); 1370 showConfigMainMenu(p); 1371 } 1372 }); 1373 builder.setOnCancelListener(new DialogInterface.OnCancelListener() 1374 { 1375 public void onCancel(DialogInterface dialog) 1376 { 1377 showConfigMainMenu(p); 1378 } 1379 }); 1380 AlertDialog alert = builder.create(); 1381 alert.setOwnerActivity(p); 1382 alert.show(); 1383 } 1384 1385 /* 1386 static void showJoystickMouseConfig(final MainActivity p) 1387 { 1388 if( ! Globals.MoveMouseWithJoystick ) 1389 { 1390 Globals.MoveMouseWithJoystickSpeed = 0; 1391 showJoystickMouseAccelConfig(p); 1392 return; 1393 } 1394 1395 final CharSequence[] items = { p.getResources().getString(R.string.accel_slow), 1396 p.getResources().getString(R.string.accel_medium), 1397 p.getResources().getString(R.string.accel_fast) }; 1398 1399 AlertDialog.Builder builder = new AlertDialog.Builder(p); 1400 builder.setTitle(R.string.pointandclick_joystickmousespeed); 1401 builder.setSingleChoiceItems(items, Globals.MoveMouseWithJoystickSpeed, new DialogInterface.OnClickListener() 1402 { 1403 public void onClick(DialogInterface dialog, int item) 1404 { 1405 Globals.MoveMouseWithJoystickSpeed = item; 1406 1407 dialog.dismiss(); 1408 showJoystickMouseAccelConfig(p); 1409 } 1410 }); 1411 builder.setOnCancelListener(new DialogInterface.OnCancelListener() 1412 { 1413 public void onCancel(DialogInterface dialog) 1414 { 1415 showConfigMainMenu(p); 1416 } 1417 }); 1418 AlertDialog alert = builder.create(); 1419 alert.setOwnerActivity(p); 1420 alert.show(); 1421 } 1422 1423 static void showJoystickMouseAccelConfig(final MainActivity p) 1424 { 1425 if( ! Globals.MoveMouseWithJoystick ) 1426 { 1427 Globals.MoveMouseWithJoystickAccel = 0; 1428 showMouseConfigMainMenu(p); 1429 return; 1430 } 1431 1432 final CharSequence[] items = { p.getResources().getString(R.string.none), 1433 p.getResources().getString(R.string.accel_slow), 1434 p.getResources().getString(R.string.accel_medium), 1435 p.getResources().getString(R.string.accel_fast) }; 1436 1437 AlertDialog.Builder builder = new AlertDialog.Builder(p); 1438 builder.setTitle(R.string.pointandclick_joystickmouseaccel); 1439 builder.setSingleChoiceItems(items, Globals.MoveMouseWithJoystickAccel, new DialogInterface.OnClickListener() 1440 { 1441 public void onClick(DialogInterface dialog, int item) 1442 { 1443 Globals.MoveMouseWithJoystickAccel = item; 1444 1445 dialog.dismiss(); 1446 showMouseConfigMainMenu(p); 1447 } 1448 }); 1449 builder.setOnCancelListener(new DialogInterface.OnCancelListener() 1450 { 1451 public void onCancel(DialogInterface dialog) 1452 { 1453 showConfigMainMenu(p); 1454 } 1455 }); 1456 AlertDialog alert = builder.create(); 1457 alert.setOwnerActivity(p); 1458 alert.show(); 1459 } 1460 */ 1461 1462 public interface TouchEventsListener 1463 { onTouchEvent(final MotionEvent ev)1464 public void onTouchEvent(final MotionEvent ev); 1465 } 1466 1467 public interface KeyEventsListener 1468 { onKeyEvent(final int keyCode)1469 public void onKeyEvent(final int keyCode); 1470 } 1471 1472 /* 1473 static void showTouchPressureMeasurementTool(final MainActivity p) 1474 { 1475 p.setText(p.getResources().getString(R.string.measurepressure_touchplease)); 1476 p.touchListener = new TouchMeasurementTool(p); 1477 } 1478 1479 public static class TouchMeasurementTool implements TouchEventsListener 1480 { 1481 MainActivity p; 1482 ArrayList<Integer> force = new ArrayList<Integer>(); 1483 ArrayList<Integer> radius = new ArrayList<Integer>(); 1484 static final int maxEventAmount = 100; 1485 1486 public TouchMeasurementTool(MainActivity _p) 1487 { 1488 p = _p; 1489 } 1490 1491 public void onTouchEvent(final MotionEvent ev) 1492 { 1493 force.add(new Integer((int)(ev.getPressure() * 1000.0))); 1494 radius.add(new Integer((int)(ev.getSize() * 1000.0))); 1495 p.setText(p.getResources().getString(R.string.measurepressure_response, force.get(force.size()-1), radius.get(radius.size()-1))); 1496 try { 1497 Thread.sleep(10L); 1498 } catch (InterruptedException e) { } 1499 1500 if( force.size() >= maxEventAmount ) 1501 { 1502 p.touchListener = null; 1503 Globals.ClickScreenPressure = getAverageForce(); 1504 Globals.ClickScreenTouchspotSize = getAverageRadius(); 1505 System.out.println("SDL: measured average force " + Globals.ClickScreenPressure + " radius " + Globals.ClickScreenTouchspotSize); 1506 showMouseConfigMainMenu(p); 1507 } 1508 } 1509 1510 int getAverageForce() 1511 { 1512 int avg = 0; 1513 for(Integer f: force) 1514 { 1515 avg += f; 1516 } 1517 return avg / force.size(); 1518 } 1519 int getAverageRadius() 1520 { 1521 int avg = 0; 1522 for(Integer r: radius) 1523 { 1524 avg += r; 1525 } 1526 return avg / radius.size(); 1527 } 1528 } 1529 1530 static void showRemapHwKeysConfig(final MainActivity p) 1531 { 1532 p.setText(p.getResources().getString(R.string.remap_hwkeys_press)); 1533 p.keyListener = new KeyRemapTool(p); 1534 } 1535 1536 public static class KeyRemapTool implements KeyEventsListener 1537 { 1538 MainActivity p; 1539 public KeyRemapTool(MainActivity _p) 1540 { 1541 p = _p; 1542 } 1543 1544 public void onKeyEvent(final int keyCode) 1545 { 1546 p.touchListener = null; 1547 int keyIndex = keyCode; 1548 if( keyIndex < 0 ) 1549 keyIndex = 0; 1550 if( keyIndex > SDL_Keys.JAVA_KEYCODE_LAST ) 1551 keyIndex = 0; 1552 1553 final int KeyIndexFinal = keyIndex; 1554 AlertDialog.Builder builder = new AlertDialog.Builder(p); 1555 builder.setTitle(R.string.remap_hwkeys_select); 1556 builder.setSingleChoiceItems(SDL_Keys.namesSorted, SDL_Keys.namesSortedBackIdx[Globals.RemapHwKeycode[keyIndex]], new DialogInterface.OnClickListener() 1557 { 1558 public void onClick(DialogInterface dialog, int item) 1559 { 1560 Globals.RemapHwKeycode[KeyIndexFinal] = SDL_Keys.namesSortedIdx[item]; 1561 1562 dialog.dismiss(); 1563 showConfigMainMenu(p); 1564 } 1565 }); 1566 builder.setOnCancelListener(new DialogInterface.OnCancelListener() 1567 { 1568 public void onCancel(DialogInterface dialog) 1569 { 1570 showConfigMainMenu(p); 1571 } 1572 }); 1573 AlertDialog alert = builder.create(); 1574 alert.setOwnerActivity(p); 1575 alert.show(); 1576 } 1577 } 1578 1579 static void showRemapScreenKbConfig(final MainActivity p) 1580 { 1581 CharSequence[] items = { 1582 p.getResources().getString(R.string.remap_screenkb_joystick), 1583 p.getResources().getString(R.string.remap_screenkb_button_text), 1584 p.getResources().getString(R.string.remap_screenkb_button) + " 1", 1585 p.getResources().getString(R.string.remap_screenkb_button) + " 2", 1586 p.getResources().getString(R.string.remap_screenkb_button) + " 3", 1587 p.getResources().getString(R.string.remap_screenkb_button) + " 4", 1588 p.getResources().getString(R.string.remap_screenkb_button) + " 5", 1589 p.getResources().getString(R.string.remap_screenkb_button) + " 6", 1590 }; 1591 1592 boolean defaults[] = { 1593 Globals.ScreenKbControlsShown[0], 1594 Globals.ScreenKbControlsShown[1], 1595 Globals.ScreenKbControlsShown[2], 1596 Globals.ScreenKbControlsShown[3], 1597 Globals.ScreenKbControlsShown[4], 1598 Globals.ScreenKbControlsShown[5], 1599 Globals.ScreenKbControlsShown[6], 1600 Globals.ScreenKbControlsShown[7], 1601 }; 1602 1603 AlertDialog.Builder builder = new AlertDialog.Builder(p); 1604 builder.setTitle(p.getResources().getString(R.string.remap_screenkb)); 1605 builder.setMultiChoiceItems(items, defaults, new DialogInterface.OnMultiChoiceClickListener() 1606 { 1607 public void onClick(DialogInterface dialog, int item, boolean isChecked) 1608 { 1609 if( ! Globals.UseTouchscreenKeyboard ) 1610 item += 8; 1611 Globals.ScreenKbControlsShown[item] = isChecked; 1612 } 1613 }); 1614 builder.setPositiveButton(p.getResources().getString(R.string.ok), new DialogInterface.OnClickListener() 1615 { 1616 public void onClick(DialogInterface dialog, int item) 1617 { 1618 dialog.dismiss(); 1619 showRemapScreenKbConfig2(p, 0); 1620 } 1621 }); 1622 builder.setOnCancelListener(new DialogInterface.OnCancelListener() 1623 { 1624 public void onCancel(DialogInterface dialog) 1625 { 1626 showConfigMainMenu(p); 1627 } 1628 }); 1629 AlertDialog alert = builder.create(); 1630 alert.setOwnerActivity(p); 1631 alert.show(); 1632 } 1633 1634 static void showRemapScreenKbConfig2(final MainActivity p, final int currentButton) 1635 { 1636 CharSequence[] items = { 1637 p.getResources().getString(R.string.remap_screenkb_button) + " 1", 1638 p.getResources().getString(R.string.remap_screenkb_button) + " 2", 1639 p.getResources().getString(R.string.remap_screenkb_button) + " 3", 1640 p.getResources().getString(R.string.remap_screenkb_button) + " 4", 1641 p.getResources().getString(R.string.remap_screenkb_button) + " 5", 1642 p.getResources().getString(R.string.remap_screenkb_button) + " 6", 1643 }; 1644 1645 if( currentButton >= Globals.RemapScreenKbKeycode.length ) 1646 { 1647 showScreenKeyboardConfigMainMenu(p); 1648 return; 1649 } 1650 if( ! Globals.ScreenKbControlsShown[currentButton + 2] ) 1651 { 1652 showRemapScreenKbConfig2(p, currentButton + 1); 1653 return; 1654 } 1655 1656 AlertDialog.Builder builder = new AlertDialog.Builder(p); 1657 builder.setTitle(items[currentButton]); 1658 builder.setSingleChoiceItems(SDL_Keys.namesSorted, SDL_Keys.namesSortedBackIdx[Globals.RemapScreenKbKeycode[currentButton]], new DialogInterface.OnClickListener() 1659 { 1660 public void onClick(DialogInterface dialog, int item) 1661 { 1662 Globals.RemapScreenKbKeycode[currentButton] = SDL_Keys.namesSortedIdx[item]; 1663 1664 dialog.dismiss(); 1665 showRemapScreenKbConfig2(p, currentButton + 1); 1666 } 1667 }); 1668 builder.setOnCancelListener(new DialogInterface.OnCancelListener() 1669 { 1670 public void onCancel(DialogInterface dialog) 1671 { 1672 showConfigMainMenu(p); 1673 } 1674 }); 1675 AlertDialog alert = builder.create(); 1676 alert.setOwnerActivity(p); 1677 alert.show(); 1678 } 1679 */ 1680 1681 /* 1682 static void showScreenGesturesConfig(final MainActivity p) 1683 { 1684 CharSequence[] items = { 1685 p.getResources().getString(R.string.remap_screenkb_button_zoomin), 1686 p.getResources().getString(R.string.remap_screenkb_button_zoomout), 1687 p.getResources().getString(R.string.remap_screenkb_button_rotateleft), 1688 p.getResources().getString(R.string.remap_screenkb_button_rotateright), 1689 }; 1690 1691 boolean defaults[] = { 1692 Globals.MultitouchGesturesUsed[0], 1693 Globals.MultitouchGesturesUsed[1], 1694 Globals.MultitouchGesturesUsed[2], 1695 Globals.MultitouchGesturesUsed[3], 1696 }; 1697 1698 AlertDialog.Builder builder = new AlertDialog.Builder(p); 1699 builder.setTitle(p.getResources().getString(R.string.remap_screenkb_button_gestures)); 1700 builder.setMultiChoiceItems(items, defaults, new DialogInterface.OnMultiChoiceClickListener() 1701 { 1702 public void onClick(DialogInterface dialog, int item, boolean isChecked) 1703 { 1704 Globals.MultitouchGesturesUsed[item] = isChecked; 1705 } 1706 }); 1707 builder.setPositiveButton(p.getResources().getString(R.string.ok), new DialogInterface.OnClickListener() 1708 { 1709 public void onClick(DialogInterface dialog, int item) 1710 { 1711 dialog.dismiss(); 1712 showScreenGesturesConfig2(p); 1713 } 1714 }); 1715 builder.setOnCancelListener(new DialogInterface.OnCancelListener() 1716 { 1717 public void onCancel(DialogInterface dialog) 1718 { 1719 showConfigMainMenu(p); 1720 } 1721 }); 1722 AlertDialog alert = builder.create(); 1723 alert.setOwnerActivity(p); 1724 alert.show(); 1725 } 1726 1727 static void showScreenGesturesConfig2(final MainActivity p) 1728 { 1729 final CharSequence[] items = { 1730 p.getResources().getString(R.string.accel_slow), 1731 p.getResources().getString(R.string.accel_medium), 1732 p.getResources().getString(R.string.accel_fast), 1733 p.getResources().getString(R.string.accel_veryfast) 1734 }; 1735 1736 AlertDialog.Builder builder = new AlertDialog.Builder(p); 1737 builder.setTitle(R.string.remap_screenkb_button_gestures_sensitivity); 1738 builder.setSingleChoiceItems(items, Globals.MultitouchGestureSensitivity, new DialogInterface.OnClickListener() 1739 { 1740 public void onClick(DialogInterface dialog, int item) 1741 { 1742 Globals.MultitouchGestureSensitivity = item; 1743 1744 dialog.dismiss(); 1745 showScreenGesturesConfig3(p, 0); 1746 } 1747 }); 1748 builder.setOnCancelListener(new DialogInterface.OnCancelListener() 1749 { 1750 public void onCancel(DialogInterface dialog) 1751 { 1752 showConfigMainMenu(p); 1753 } 1754 }); 1755 AlertDialog alert = builder.create(); 1756 alert.setOwnerActivity(p); 1757 alert.show(); 1758 } 1759 1760 static void showScreenGesturesConfig3(final MainActivity p, final int currentButton) 1761 { 1762 CharSequence[] items = { 1763 p.getResources().getString(R.string.remap_screenkb_button_zoomin), 1764 p.getResources().getString(R.string.remap_screenkb_button_zoomout), 1765 p.getResources().getString(R.string.remap_screenkb_button_rotateleft), 1766 p.getResources().getString(R.string.remap_screenkb_button_rotateright), 1767 }; 1768 1769 if( currentButton >= Globals.RemapMultitouchGestureKeycode.length ) 1770 { 1771 showConfigMainMenu(p); 1772 return; 1773 } 1774 if( ! Globals.MultitouchGesturesUsed[currentButton] ) 1775 { 1776 showScreenGesturesConfig3(p, currentButton + 1); 1777 return; 1778 } 1779 1780 AlertDialog.Builder builder = new AlertDialog.Builder(p); 1781 builder.setTitle(items[currentButton]); 1782 builder.setSingleChoiceItems(SDL_Keys.namesSorted, SDL_Keys.namesSortedBackIdx[Globals.RemapMultitouchGestureKeycode[currentButton]], new DialogInterface.OnClickListener() 1783 { 1784 public void onClick(DialogInterface dialog, int item) 1785 { 1786 Globals.RemapMultitouchGestureKeycode[currentButton] = SDL_Keys.namesSortedIdx[item]; 1787 1788 dialog.dismiss(); 1789 showScreenGesturesConfig3(p, currentButton + 1); 1790 } 1791 }); 1792 builder.setOnCancelListener(new DialogInterface.OnCancelListener() 1793 { 1794 public void onCancel(DialogInterface dialog) 1795 { 1796 showConfigMainMenu(p); 1797 } 1798 }); 1799 AlertDialog alert = builder.create(); 1800 alert.setOwnerActivity(p); 1801 alert.show(); 1802 } 1803 1804 static void showCalibrateTouchscreenMenu(final MainActivity p) 1805 { 1806 p.setText(p.getResources().getString(R.string.calibrate_touchscreen_touch)); 1807 Globals.TouchscreenCalibration[0] = 0; 1808 Globals.TouchscreenCalibration[1] = 0; 1809 Globals.TouchscreenCalibration[2] = 0; 1810 Globals.TouchscreenCalibration[3] = 0; 1811 ScreenEdgesCalibrationTool tool = new ScreenEdgesCalibrationTool(p); 1812 p.touchListener = tool; 1813 p.keyListener = tool; 1814 } 1815 1816 static class ScreenEdgesCalibrationTool implements TouchEventsListener, KeyEventsListener 1817 { 1818 MainActivity p; 1819 ImageView img; 1820 Bitmap bmp; 1821 1822 public ScreenEdgesCalibrationTool(MainActivity _p) 1823 { 1824 p = _p; 1825 img = new ImageView(p); 1826 img.setLayoutParams(new ViewGroup.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT)); 1827 img.setScaleType(ImageView.ScaleType.MATRIX); 1828 bmp = BitmapFactory.decodeResource( p.getResources(), R.drawable.calibrate ); 1829 img.setImageBitmap(bmp); 1830 Matrix m = new Matrix(); 1831 RectF src = new RectF(0, 0, bmp.getWidth(), bmp.getHeight()); 1832 RectF dst = new RectF(Globals.TouchscreenCalibration[0], Globals.TouchscreenCalibration[1], 1833 Globals.TouchscreenCalibration[2], Globals.TouchscreenCalibration[3]); 1834 m.setRectToRect(src, dst, Matrix.ScaleToFit.FILL); 1835 img.setImageMatrix(m); 1836 p.getVideoLayout().addView(img); 1837 } 1838 1839 public void onTouchEvent(final MotionEvent ev) 1840 { 1841 if( Globals.TouchscreenCalibration[0] == Globals.TouchscreenCalibration[1] && 1842 Globals.TouchscreenCalibration[1] == Globals.TouchscreenCalibration[2] && 1843 Globals.TouchscreenCalibration[2] == Globals.TouchscreenCalibration[3] ) 1844 { 1845 Globals.TouchscreenCalibration[0] = (int)ev.getX(); 1846 Globals.TouchscreenCalibration[1] = (int)ev.getY(); 1847 Globals.TouchscreenCalibration[2] = (int)ev.getX(); 1848 Globals.TouchscreenCalibration[3] = (int)ev.getY(); 1849 } 1850 if( ev.getX() < Globals.TouchscreenCalibration[0] ) 1851 Globals.TouchscreenCalibration[0] = (int)ev.getX(); 1852 if( ev.getY() < Globals.TouchscreenCalibration[1] ) 1853 Globals.TouchscreenCalibration[1] = (int)ev.getY(); 1854 if( ev.getX() > Globals.TouchscreenCalibration[2] ) 1855 Globals.TouchscreenCalibration[2] = (int)ev.getX(); 1856 if( ev.getY() > Globals.TouchscreenCalibration[3] ) 1857 Globals.TouchscreenCalibration[3] = (int)ev.getY(); 1858 Matrix m = new Matrix(); 1859 RectF src = new RectF(0, 0, bmp.getWidth(), bmp.getHeight()); 1860 RectF dst = new RectF(Globals.TouchscreenCalibration[0], Globals.TouchscreenCalibration[1], 1861 Globals.TouchscreenCalibration[2], Globals.TouchscreenCalibration[3]); 1862 m.setRectToRect(src, dst, Matrix.ScaleToFit.FILL); 1863 img.setImageMatrix(m); 1864 } 1865 1866 public void onKeyEvent(final int keyCode) 1867 { 1868 p.touchListener = null; 1869 p.keyListener = null; 1870 p.getVideoLayout().removeView(img); 1871 showMouseConfigMainMenu(p); 1872 } 1873 } 1874 1875 static void showCustomizeScreenKbLayout(final MainActivity p) 1876 { 1877 p.setText(p.getResources().getString(R.string.screenkb_custom_layout_help)); 1878 CustomizeScreenKbLayoutTool tool = new CustomizeScreenKbLayoutTool(p); 1879 p.touchListener = tool; 1880 p.keyListener = tool; 1881 }; 1882 1883 static class CustomizeScreenKbLayoutTool implements TouchEventsListener, KeyEventsListener 1884 { 1885 MainActivity p; 1886 FrameLayout layout = null; 1887 ImageView imgs[] = new ImageView[Globals.ScreenKbControlsLayout.length]; 1888 Bitmap bmps[] = new Bitmap[Globals.ScreenKbControlsLayout.length]; 1889 int currentButton = 0; 1890 int buttons[] = { 1891 R.drawable.dpad, 1892 R.drawable.keyboard, 1893 R.drawable.b1, 1894 R.drawable.b2, 1895 R.drawable.b3, 1896 R.drawable.b4, 1897 R.drawable.b5, 1898 R.drawable.b6 1899 }; 1900 1901 public CustomizeScreenKbLayoutTool(MainActivity _p) 1902 { 1903 p = _p; 1904 layout = new FrameLayout(p); 1905 p.getVideoLayout().addView(layout); 1906 currentButton = 0; 1907 setupButton(true); 1908 } 1909 1910 void setupButton(boolean undo) 1911 { 1912 do { 1913 currentButton += undo ? -1 : 1; 1914 if(currentButton >= Globals.ScreenKbControlsLayout.length) 1915 { 1916 p.getVideoLayout().removeView(layout); 1917 layout = null; 1918 p.touchListener = null; 1919 p.keyListener = null; 1920 showScreenKeyboardConfigMainMenu(p); 1921 return; 1922 } 1923 if(currentButton < 0) 1924 { 1925 currentButton = 0; 1926 undo = false; 1927 } 1928 } while( ! Globals.ScreenKbControlsShown[currentButton] ); 1929 1930 if( imgs[currentButton] == null ) 1931 { 1932 imgs[currentButton] = new ImageView(p); 1933 imgs[currentButton].setLayoutParams(new ViewGroup.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT)); 1934 imgs[currentButton].setScaleType(ImageView.ScaleType.MATRIX); 1935 bmps[currentButton] = BitmapFactory.decodeResource( p.getResources(), buttons[currentButton] ); 1936 imgs[currentButton].setImageBitmap(bmps[currentButton]); 1937 layout.addView(imgs[currentButton]); 1938 } 1939 Matrix m = new Matrix(); 1940 RectF src = new RectF(0, 0, bmps[currentButton].getWidth(), bmps[currentButton].getHeight()); 1941 RectF dst = new RectF(Globals.ScreenKbControlsLayout[currentButton][0], Globals.ScreenKbControlsLayout[currentButton][1], 1942 Globals.ScreenKbControlsLayout[currentButton][2], Globals.ScreenKbControlsLayout[currentButton][3]); 1943 m.setRectToRect(src, dst, Matrix.ScaleToFit.FILL); 1944 imgs[currentButton].setImageMatrix(m); 1945 } 1946 1947 public void onTouchEvent(final MotionEvent ev) 1948 { 1949 if( ev.getAction() == MotionEvent.ACTION_DOWN ) 1950 { 1951 Globals.ScreenKbControlsLayout[currentButton][0] = (int)ev.getX(); 1952 Globals.ScreenKbControlsLayout[currentButton][1] = (int)ev.getY(); 1953 Globals.ScreenKbControlsLayout[currentButton][2] = (int)ev.getX(); 1954 Globals.ScreenKbControlsLayout[currentButton][3] = (int)ev.getY(); 1955 } 1956 if( ev.getAction() == MotionEvent.ACTION_MOVE ) 1957 { 1958 if( Globals.ScreenKbControlsLayout[currentButton][0] > (int)ev.getX() ) 1959 Globals.ScreenKbControlsLayout[currentButton][0] = (int)ev.getX(); 1960 if( Globals.ScreenKbControlsLayout[currentButton][1] > (int)ev.getY() ) 1961 Globals.ScreenKbControlsLayout[currentButton][1] = (int)ev.getY(); 1962 if( Globals.ScreenKbControlsLayout[currentButton][2] < (int)ev.getX() ) 1963 Globals.ScreenKbControlsLayout[currentButton][2] = (int)ev.getX(); 1964 if( Globals.ScreenKbControlsLayout[currentButton][3] < (int)ev.getY() ) 1965 Globals.ScreenKbControlsLayout[currentButton][3] = (int)ev.getY(); 1966 } 1967 1968 Matrix m = new Matrix(); 1969 RectF src = new RectF(0, 0, bmps[currentButton].getWidth(), bmps[currentButton].getHeight()); 1970 RectF dst = new RectF(Globals.ScreenKbControlsLayout[currentButton][0], Globals.ScreenKbControlsLayout[currentButton][1], 1971 Globals.ScreenKbControlsLayout[currentButton][2], Globals.ScreenKbControlsLayout[currentButton][3]); 1972 m.setRectToRect(src, dst, Matrix.ScaleToFit.FILL); 1973 imgs[currentButton].setImageMatrix(m); 1974 1975 if( ev.getAction() == MotionEvent.ACTION_UP ) 1976 setupButton(false); 1977 } 1978 1979 public void onKeyEvent(final int keyCode) 1980 { 1981 if( layout != null && imgs[currentButton] != null ) 1982 layout.removeView(imgs[currentButton]); 1983 imgs[currentButton] = null; 1984 setupButton(true); 1985 } 1986 } 1987 * */ 1988 showVideoSettingsConfig(final MainActivity p)1989 static void showVideoSettingsConfig(final MainActivity p) 1990 { 1991 /* 1992 CharSequence[] items = { 1993 p.getResources().getString(R.string.pointandclick_keepaspectratio), 1994 p.getResources().getString(R.string.pointandclick_showcreenunderfinger2), 1995 p.getResources().getString(R.string.video_smooth) 1996 }; 1997 boolean defaults[] = { 1998 Globals.KeepAspectRatio, 1999 Globals.ShowScreenUnderFinger, 2000 Globals.SmoothVideo 2001 }; 2002 2003 if(Globals.SwVideoMode) 2004 { 2005 CharSequence[] items2 = { 2006 p.getResources().getString(R.string.pointandclick_keepaspectratio), 2007 p.getResources().getString(R.string.pointandclick_showcreenunderfinger2), 2008 p.getResources().getString(R.string.video_smooth), 2009 p.getResources().getString(R.string.video_separatethread), 2010 }; 2011 boolean defaults2[] = { 2012 Globals.KeepAspectRatio, 2013 Globals.ShowScreenUnderFinger, 2014 Globals.SmoothVideo, 2015 Globals.MultiThreadedVideo 2016 }; 2017 items = items2; 2018 defaults = defaults2; 2019 } 2020 */ 2021 CharSequence[] items = { 2022 p.getResources().getString(R.string.video_separatethread), 2023 }; 2024 boolean defaults[] = { 2025 Globals.MultiThreadedVideo 2026 }; 2027 2028 /* 2029 if(Globals.Using_SDL_1_3) 2030 { 2031 CharSequence[] items2 = { 2032 p.getResources().getString(R.string.pointandclick_keepaspectratio), 2033 p.getResources().getString(R.string.pointandclick_showcreenunderfinger2) 2034 }; 2035 boolean defaults2[] = { 2036 Globals.KeepAspectRatio, 2037 Globals.ShowScreenUnderFinger 2038 }; 2039 items = items2; 2040 defaults = defaults2; 2041 } 2042 */ 2043 2044 AlertDialog.Builder builder = new AlertDialog.Builder(p); 2045 builder.setTitle(p.getResources().getString(R.string.video)); 2046 builder.setMultiChoiceItems(items, defaults, new DialogInterface.OnMultiChoiceClickListener() 2047 { 2048 public void onClick(DialogInterface dialog, int item, boolean isChecked) 2049 { 2050 /* 2051 if( item == 0 ) 2052 Globals.KeepAspectRatio = isChecked; 2053 if( item == 1 ) 2054 Globals.ShowScreenUnderFinger = isChecked; 2055 if( item == 2 ) 2056 Globals.SmoothVideo = isChecked; 2057 if( item == 3 ) 2058 Globals.MultiThreadedVideo = isChecked; 2059 */ 2060 if (item == 0) 2061 Globals.MultiThreadedVideo = isChecked; 2062 } 2063 }); 2064 builder.setPositiveButton(p.getResources().getString(R.string.ok), new DialogInterface.OnClickListener() 2065 { 2066 public void onClick(DialogInterface dialog, int item) 2067 { 2068 dialog.dismiss(); 2069 showConfigMainMenu(p); 2070 } 2071 }); 2072 builder.setOnCancelListener(new DialogInterface.OnCancelListener() 2073 { 2074 public void onCancel(DialogInterface dialog) 2075 { 2076 showConfigMainMenu(p); 2077 } 2078 }); 2079 AlertDialog alert = builder.create(); 2080 alert.setOwnerActivity(p); 2081 alert.show(); 2082 } 2083 2084 // =============================================================================================== 2085 Apply(Activity p)2086 static void Apply(Activity p) 2087 { 2088 if(Globals.SmoothVideo) 2089 nativeSetSmoothVideo(); 2090 if( Globals.SwVideoMode && Globals.MultiThreadedVideo ) 2091 nativeSetVideoMultithreaded(); 2092 if( Globals.PhoneHasTrackball ) 2093 nativeSetTrackballUsed(); 2094 if( Globals.AppUsesMouse ) 2095 nativeSetMouseUsed( Globals.RightClickMethod, 2096 Globals.ShowScreenUnderFinger ? 1 : 0, 2097 Globals.LeftClickMethod, 2098 Globals.MoveMouseWithJoystick ? 1 : 0, 2099 Globals.ClickMouseWithDpad ? 1 : 0, 2100 Globals.ClickScreenPressure, 2101 Globals.ClickScreenTouchspotSize, 2102 Globals.MoveMouseWithJoystickSpeed, 2103 Globals.MoveMouseWithJoystickAccel, 2104 Globals.LeftClickKey, 2105 Globals.RightClickKey, 2106 Globals.LeftClickTimeout, 2107 Globals.RightClickTimeout, 2108 Globals.RelativeMouseMovement ? 1 : 0, 2109 Globals.RelativeMouseMovementSpeed, 2110 Globals.RelativeMouseMovementAccel ); 2111 if( Globals.AppUsesJoystick && (Globals.UseAccelerometerAsArrowKeys || Globals.UseTouchscreenKeyboard) ) 2112 nativeSetJoystickUsed(); 2113 if( Globals.AppUsesMultitouch ) 2114 nativeSetMultitouchUsed(); 2115 nativeSetAccelerometerSettings(Globals.AccelerometerSensitivity, Globals.AccelerometerCenterPos); 2116 nativeSetTrackballDampening(Globals.TrackballDampening); 2117 if( Globals.UseTouchscreenKeyboard ) 2118 { 2119 boolean screenKbReallyUsed = false; 2120 for( int i = 0; i < Globals.ScreenKbControlsShown.length; i++ ) 2121 if( Globals.ScreenKbControlsShown[i] ) 2122 screenKbReallyUsed = true; 2123 if( screenKbReallyUsed ) 2124 { 2125 nativeSetTouchscreenKeyboardUsed(); 2126 nativeSetupScreenKeyboard( Globals.TouchscreenKeyboardSize, 2127 Globals.TouchscreenKeyboardTheme, 2128 Globals.AppTouchscreenKeyboardKeysAmountAutoFire, 2129 Globals.TouchscreenKeyboardTransparency ); 2130 SetupTouchscreenKeyboardGraphics(p); 2131 for( int i = 0; i < Globals.ScreenKbControlsShown.length; i++ ) 2132 nativeSetScreenKbKeyUsed(i, Globals.ScreenKbControlsShown[i] ? 1 : 0); 2133 for( int i = 0; i < Globals.RemapScreenKbKeycode.length; i++ ) 2134 nativeSetKeymapKeyScreenKb(i, SDL_Keys.values[Globals.RemapScreenKbKeycode[i]]); 2135 for( int i = 0; i < Globals.ScreenKbControlsLayout.length; i++ ) 2136 if( Globals.ScreenKbControlsLayout[i][0] < Globals.ScreenKbControlsLayout[i][2] ) 2137 nativeSetScreenKbKeyLayout( i, Globals.ScreenKbControlsLayout[i][0], Globals.ScreenKbControlsLayout[i][1], 2138 Globals.ScreenKbControlsLayout[i][2], Globals.ScreenKbControlsLayout[i][3]); 2139 } 2140 else 2141 Globals.UseTouchscreenKeyboard = false; 2142 } 2143 2144 for( int i = 0; i < SDL_Keys.JAVA_KEYCODE_LAST; i++ ) 2145 nativeSetKeymapKey(i, SDL_Keys.values[Globals.RemapHwKeycode[i]]); 2146 for( int i = 0; i < Globals.RemapMultitouchGestureKeycode.length; i++ ) 2147 nativeSetKeymapKeyMultitouchGesture(i, Globals.MultitouchGesturesUsed[i] ? SDL_Keys.values[Globals.RemapMultitouchGestureKeycode[i]] : 0); 2148 nativeSetMultitouchGestureSensitivity(Globals.MultitouchGestureSensitivity); 2149 if( Globals.TouchscreenCalibration[2] > Globals.TouchscreenCalibration[0] ) 2150 nativeSetTouchscreenCalibration(Globals.TouchscreenCalibration[0], Globals.TouchscreenCalibration[1], 2151 Globals.TouchscreenCalibration[2], Globals.TouchscreenCalibration[3]); 2152 2153 String lang = new String(Locale.getDefault().getLanguage()); 2154 if( Locale.getDefault().getCountry().length() > 0 ) 2155 lang = lang + "_" + Locale.getDefault().getCountry(); 2156 System.out.println( "libSDL: setting envvar LANGUAGE to '" + lang + "'"); 2157 nativeSetEnv( "LANG", lang ); 2158 nativeSetEnv( "LANGUAGE", lang ); 2159 // TODO: get current user name and set envvar USER, the API is not availalbe on Android 1.6 so I don't bother with this 2160 } 2161 loadRaw(Activity p,int res)2162 static byte [] loadRaw(Activity p,int res) 2163 { 2164 byte [] buf = new byte[65536 * 2]; 2165 byte [] a = new byte[0]; 2166 try{ 2167 InputStream is = new GZIPInputStream(p.getResources().openRawResource(res)); 2168 int readed = 0; 2169 while( (readed = is.read(buf)) >= 0 ) 2170 { 2171 byte [] b = new byte [a.length + readed]; 2172 System.arraycopy(a, 0, b, 0, a.length); 2173 System.arraycopy(buf, 0, b, a.length, readed); 2174 a = b; 2175 } 2176 } catch(Exception e) {}; 2177 return a; 2178 } 2179 SetupTouchscreenKeyboardGraphics(Activity p)2180 static void SetupTouchscreenKeyboardGraphics(Activity p) 2181 { 2182 if( Globals.UseTouchscreenKeyboard ) 2183 { 2184 if(Globals.TouchscreenKeyboardTheme < 0) 2185 Globals.TouchscreenKeyboardTheme = 0; 2186 if(Globals.TouchscreenKeyboardTheme > 1) 2187 Globals.TouchscreenKeyboardTheme = 1; 2188 2189 if( Globals.TouchscreenKeyboardTheme == 0 ) 2190 { 2191 nativeSetupScreenKeyboardButtons(loadRaw(p, R.raw.ultimatedroid)); 2192 } 2193 if( Globals.TouchscreenKeyboardTheme == 1 ) 2194 { 2195 nativeSetupScreenKeyboardButtons(loadRaw(p, R.raw.simpletheme)); 2196 } 2197 } 2198 } 2199 nativeSetTrackballUsed()2200 private static native void nativeSetTrackballUsed(); nativeSetTrackballDampening(int value)2201 private static native void nativeSetTrackballDampening(int value); nativeSetAccelerometerSettings(int sensitivity, int centerPos)2202 private static native void nativeSetAccelerometerSettings(int sensitivity, int centerPos); nativeSetMouseUsed(int RightClickMethod, int ShowScreenUnderFinger, int LeftClickMethod, int MoveMouseWithJoystick, int ClickMouseWithDpad, int MaxForce, int MaxRadius, int MoveMouseWithJoystickSpeed, int MoveMouseWithJoystickAccel, int leftClickKeycode, int rightClickKeycode, int leftClickTimeout, int rightClickTimeout, int relativeMovement, int relativeMovementSpeed, int relativeMovementAccel)2203 private static native void nativeSetMouseUsed(int RightClickMethod, int ShowScreenUnderFinger, int LeftClickMethod, 2204 int MoveMouseWithJoystick, int ClickMouseWithDpad, int MaxForce, int MaxRadius, 2205 int MoveMouseWithJoystickSpeed, int MoveMouseWithJoystickAccel, 2206 int leftClickKeycode, int rightClickKeycode, 2207 int leftClickTimeout, int rightClickTimeout, 2208 int relativeMovement, int relativeMovementSpeed, int relativeMovementAccel); nativeSetJoystickUsed()2209 private static native void nativeSetJoystickUsed(); nativeSetMultitouchUsed()2210 private static native void nativeSetMultitouchUsed(); nativeSetTouchscreenKeyboardUsed()2211 private static native void nativeSetTouchscreenKeyboardUsed(); nativeSetSmoothVideo()2212 private static native void nativeSetSmoothVideo(); nativeSetVideoMultithreaded()2213 private static native void nativeSetVideoMultithreaded(); nativeSetupScreenKeyboard(int size, int theme, int nbuttonsAutoFire, int transparency)2214 private static native void nativeSetupScreenKeyboard(int size, int theme, int nbuttonsAutoFire, int transparency); nativeSetupScreenKeyboardButtons(byte[] img)2215 private static native void nativeSetupScreenKeyboardButtons(byte[] img); nativeInitKeymap()2216 private static native void nativeInitKeymap(); nativeGetKeymapKey(int key)2217 private static native int nativeGetKeymapKey(int key); nativeSetKeymapKey(int javakey, int key)2218 private static native void nativeSetKeymapKey(int javakey, int key); nativeGetKeymapKeyScreenKb(int keynum)2219 private static native int nativeGetKeymapKeyScreenKb(int keynum); nativeSetKeymapKeyScreenKb(int keynum, int key)2220 private static native void nativeSetKeymapKeyScreenKb(int keynum, int key); nativeSetScreenKbKeyUsed(int keynum, int used)2221 private static native void nativeSetScreenKbKeyUsed(int keynum, int used); nativeSetScreenKbKeyLayout(int keynum, int x1, int y1, int x2, int y2)2222 private static native void nativeSetScreenKbKeyLayout(int keynum, int x1, int y1, int x2, int y2); nativeGetKeymapKeyMultitouchGesture(int keynum)2223 private static native int nativeGetKeymapKeyMultitouchGesture(int keynum); nativeSetKeymapKeyMultitouchGesture(int keynum, int key)2224 private static native void nativeSetKeymapKeyMultitouchGesture(int keynum, int key); nativeSetMultitouchGestureSensitivity(int sensitivity)2225 private static native void nativeSetMultitouchGestureSensitivity(int sensitivity); nativeSetTouchscreenCalibration(int x1, int y1, int x2, int y2)2226 private static native void nativeSetTouchscreenCalibration(int x1, int y1, int x2, int y2); nativeSetEnv(final String name, final String value)2227 public static native void nativeSetEnv(final String name, final String value); 2228 } 2229 2230