Changeset 6b13b7f in orbit for android/src
- Timestamp:
- 12/21/13 00:36:56 (9 years ago)
- Branches:
- master, Servo
- Children:
- 70c6c13
- Parents:
- 34f56db
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
android/src/info/puzzlebox/orbit/FragmentTabAdvanced.java
r34f56db r6b13b7f 8 8 import java.util.Enumeration; 9 9 import java.util.Iterator; 10 import java.util.List; 10 11 11 12 import org.apache.http.conn.util.InetAddressUtils; … … 29 30 import android.widget.SeekBar; 30 31 import android.widget.TextView; 32 import android.widget.Toast; 31 33 import android.text.method.ScrollingMovementMethod; 32 34 … … 90 92 private SensorManager sensorManager; 91 93 private Sensor orientationSensor = null; 92 94 // private Sensor accelerationSensor = null; 95 // private Sensor gravitySensor = null; 93 96 94 97 LinearLayout layoutControl; … … 262 265 // ################################################################ 263 266 267 public void onPause() { 268 269 /** 270 * This method is called when the Activity has been 271 * paused and placed in the background 272 */ 273 274 sensorManager.unregisterListener(this); 275 super.onPause(); 276 277 } // onResume 278 279 280 // ################################################################ 281 264 282 public void onResume() { 265 283 … … 270 288 271 289 updateAdvancedOptions(); 290 onCheckBoxTiltSensorControlClicked(); 272 291 super.onResume(); 273 292 … … 307 326 if (tv != null) 308 327 tv.append(text); 328 329 Log.v(TAG, "Debug Console Line Count: " + tv.getLineCount()); 330 331 332 // try: 333 // tv.setText(s); 334 // sv.post(new Runnable() { 335 // void run() { 336 // sv.scrollTo(0, yPosition); 337 // } 338 // }); 339 340 // tv.setVerticalScrollbarPosition(tv.getLineCount()); 309 341 310 342 // if (tv != null) { … … 355 387 public void updateScreenLayoutSmall() { 356 388 357 // radioGroupChannel.setVisibility(View.GONE);358 // // checkBoxAdvancedOptions.setText("Advanced");359 //360 // // checkBoxGenerateAudio.setText("Generate Signal");361 // // checkBoxInvertControlSignal.setText("Invert Signal");362 363 389 String generateSignalLabel = getResources().getString(R.string.checkbox_generate_audio_small); 364 390 checkBoxGenerateAudio.setText(generateSignalLabel); … … 437 463 // ################################################################ 438 464 439 @SuppressWarnings("deprecation")440 465 public void onCheckBoxTiltSensorControlClicked(View view) { 466 // Drop the View as we don't use it 467 // This is necessary for the onPause/onResume functions which don't receive a View 468 onCheckBoxTiltSensorControlClicked(); 469 } 470 471 472 // ################################################################ 473 474 @SuppressWarnings("unused") 475 public void onCheckBoxTiltSensorControlClicked() { 441 476 442 477 // ((OrbitTabActivity)getActivity()).tiltSensorControl = checkBoxTiltSensorControl.isChecked(); … … 460 495 if (checkBoxTiltSensorControl.isChecked()) { 461 496 462 // register for orientation sensor events: 497 // Log.v(TAG, "Sensor TYPE_ACCELEROMETER: " + Sensor.TYPE_ACCELEROMETER); 498 // // Log.v(TAG, "Sensor TYPE_GAME_ROTATION_VECTOR: " + Sensor.TYPE_GAME_ROTATION_VECTOR); // API 19 499 // // Log.v(TAG, "Sensor TYPE_GEOMAGNETIC_ROTATION_VECTOR: " + Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR); // API 19 500 // Log.v(TAG, "Sensor TYPE_GYROSCOPE: " + Sensor.TYPE_GYROSCOPE); 501 // Log.v(TAG, "Sensor TYPE_LINEAR_ACCELERATION: " + Sensor.TYPE_LINEAR_ACCELERATION); 502 // Log.v(TAG, "Sensor TYPE_MAGNETIC_FIELD: " + Sensor.TYPE_MAGNETIC_FIELD); 503 // // Log.v(TAG, "Sensor TYPE_GAME_ROTATION_VECTOR: " + Sensor.TYPE_GAME_ROTATION_VECTOR); // API 18 504 // Log.v(TAG, "Sensor TYPE_ORIENTATION: " + Sensor.TYPE_ORIENTATION); 505 // Log.v(TAG, "Sensor TYPE_MAGNETIC_FIELD: " + Sensor.TYPE_MAGNETIC_FIELD); 506 507 // // register for orientation sensor events: 463 508 sensorManager = (SensorManager) ((OrbitTabActivity)getActivity()).getSystemService(Context.SENSOR_SERVICE); 464 for (Sensor sensor : sensorManager.getSensorList(Sensor.TYPE_ORIENTATION)) { 465 if (sensor.getType() == Sensor.TYPE_ORIENTATION) { 466 orientationSensor = sensor; 509 510 511 Log.v(TAG, "Sensors: " + sensorManager.getSensorList(Sensor.TYPE_ALL)); 512 513 514 // for (Sensor sensor : sensorManager.getSensorList()) { 515 //// for (Sensor sensor : sensorManager.getSensorList(Sensor.TYPE_ORIENTATION)) { 516 //// if (sensor.getType() == Sensor.TYPE_ORIENTATION) { 517 //// orientationSensor = sensor; 518 //// } 519 // 520 // Log.v(TAG, "Sensor Type Found: " + sensor.getType()); 521 // 522 // if (sensor.getType() == Sensor.TYPE_ACCELEROMETER) { 523 // accelerationSensor = sensor; 524 // } 525 // 526 // } 527 528 529 if (sensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY) != null) { 530 List<Sensor> gravSensors = sensorManager.getSensorList(Sensor.TYPE_GRAVITY); 531 for(int i=0; i < gravSensors.size(); i++) { 532 // if ((gravSensors.get(i).getVendor().contains("Google Inc.")) && 533 // (gravSensors.get(i).getVersion() == 3)){ 534 // Use the version 3 gravity sensor. 535 orientationSensor = gravSensors.get(i); 536 Log.v(TAG, "Tilt Control: Using Gravity Sensor"); 537 appendDebugConsole("Tilt Control: Using Gravity Sensor"); 538 break; 539 // } 467 540 } 468 541 } 542 else if (sensorManager.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION) != null) { 543 orientationSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); 544 Log.v(TAG, "Linear accelerometer sensor found"); 545 } 546 547 else { 548 549 Log.v(TAG, "Tilt Control: Using Accelerometer Sensor"); 550 appendDebugConsole("Tilt Control: Using Linear Accelerometer Sensor"); 551 552 // Use the accelerometer. 553 if (sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) != null){ 554 orientationSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); 555 Log.v(TAG, "Tilt Control: Using Accelerometer Sensor"); 556 appendDebugConsole("Tilt Control: Using Accelerometer Sensor"); 557 } 558 else { 559 // Sorry, there are no accelerometers on your device. 560 Log.v(TAG, "Sorry, there are no tilt sensors on your device."); 561 appendDebugConsole("Tilt Control: Using Gravity Sensor"); 562 } 563 } 469 564 470 565 // if we can't access the orientation sensor then exit: 471 566 if (orientationSensor == null) { 472 appendDebugConsole("Failed to attach to Orientation Sensor."); 473 // cleanup(); 567 Toast.makeText(((OrbitTabActivity)getActivity()), "No Tilt Sensor Found", Toast.LENGTH_SHORT).show(); 568 appendDebugConsole("Tilt Control: Not Found"); 569 checkBoxTiltSensorControl.setChecked(false); 474 570 sensorManager.unregisterListener(this); 475 571 } else { … … 657 753 658 754 public void onAccuracyChanged(Sensor sensor, int accuracy) { 659 // Not interested in this event 660 755 756 // No operation 757 661 758 } // onAccuracyChanged 662 759 … … 664 761 // ################################################################ 665 762 666 // Called whenever a new Orientation Sensor reading is taken.667 763 public void onSensorChanged(SensorEvent sensorEvent) { 668 // TODO Auto-generated method stub 669 670 tiltX = sensorEvent.values[1]; 671 tiltY = -sensorEvent.values[2]; // invert the Y axis so that negative values equal left 672 // tiltZ = sensorEvent.values[0]; 673 674 // appendDebugConsole("X: " + tiltX + ", Y: " + tiltY + "\n"); 764 765 // Sensor.TYPE_ORIENTATION method 766 // tiltX = sensorEvent.values[1]; 767 // tiltY = -sensorEvent.values[2]; // invert the Y axis so that negative values equal left 768 769 // Sensor.TYPE_GRAVITY method 770 tiltX = sensorEvent.values[1] * -4; 771 tiltY = sensorEvent.values[0] * -6; 772 773 // appendDebugConsole("X: " + tiltX + ", Y: " + tiltY + "\n"); 675 774 676 775 if (referenceTiltX == 0) { … … 679 778 } 680 779 681 // seekBarYaw.setProgress(defaultControlYaw + (int) tiltY); 682 // seekBarPitch.setProgress(defaultControlPitch + 12 + ((int) tiltX / 2)); 780 // Sensor.TYPE_OPERATION method 781 // seekBarYaw.setProgress(defaultControlYaw + (int) (tiltY - referenceTiltY)); 782 // seekBarPitch.setProgress(defaultControlPitch + (int) ((tiltX / 2) - (referenceTiltX / 2))); 783 784 // Sensor.TYPE_GRAVITY 683 785 seekBarYaw.setProgress(defaultControlYaw + (int) (tiltY - referenceTiltY)); 684 seekBarPitch.setProgress(defaultControlPitch + (int) ( (tiltX / 2) - (referenceTiltX / 2)));786 seekBarPitch.setProgress(defaultControlPitch + (int) (tiltX - referenceTiltX)); 685 787 686 788
Note: See TracChangeset
for help on using the changeset viewer.