Skip to content

Commit 7810dd8

Browse files
committed
Changes to period calc ui
1 parent b4277a5 commit 7810dd8

File tree

2 files changed

+32
-33
lines changed

2 files changed

+32
-33
lines changed

app/src/main/java/com/googleresearch/capturesync/MainActivity.java

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,36 @@ public void onTimestampNs(long timestampNs) {
393393

394394
/* Set up UI controls and listeners based on if device is currently a leader of client. */
395395
private void setLeaderClientControls(boolean isLeader) {
396+
getPeriodButton.setOnClickListener(
397+
view -> {
398+
Log.d(TAG, "Calculating frames period.");
399+
400+
FutureTask<Integer> periodTask = new FutureTask<Integer>(
401+
() -> {
402+
try {
403+
long periodNs = periodCalculator.getPeriodNs();
404+
Log.d(TAG, "Calculated period: " + periodNs);
405+
if (latestToast != null) {
406+
latestToast.cancel();
407+
}
408+
latestToast =
409+
Toast.makeText(
410+
this,
411+
"Calculated period: " + periodNs,
412+
Toast.LENGTH_LONG);
413+
latestToast.show();
414+
phaseAlignController.setPeriodNs(periodNs);
415+
} catch (InterruptedException e) {
416+
Log.d(TAG, "Failed calculating period");
417+
e.printStackTrace();
418+
}
419+
return 0;
420+
}
421+
);
422+
periodTask.run();
423+
}
424+
);
425+
396426
if (isLeader) {
397427
// Leader, all controls visible and set.
398428
captureStillButton.setVisibility(View.VISIBLE);
@@ -444,36 +474,6 @@ private void setLeaderClientControls(boolean isLeader) {
444474
String.valueOf(futureTimestamp));*/
445475
});
446476

447-
getPeriodButton.setOnClickListener(
448-
view -> {
449-
Log.d(TAG, "Calculating frames period.");
450-
451-
FutureTask<Integer> periodTask = new FutureTask<Integer>(
452-
() -> {
453-
try {
454-
long periodNs = periodCalculator.getPeriodNs();
455-
Log.d(TAG, "Calculated period: " + periodNs);
456-
if (latestToast != null) {
457-
latestToast.cancel();
458-
}
459-
latestToast =
460-
Toast.makeText(
461-
this,
462-
"Calculated period: " + periodNs,
463-
Toast.LENGTH_LONG);
464-
latestToast.show();
465-
phaseAlignController.setPeriodNs(periodNs);
466-
} catch (InterruptedException e) {
467-
Log.d(TAG, "Failed calculating period");
468-
e.printStackTrace();
469-
}
470-
return 0;
471-
}
472-
);
473-
periodTask.run();
474-
}
475-
);
476-
477477
phaseAlignButton.setOnClickListener(
478478
view -> {
479479
Log.d(TAG, "Broadcasting phase alignment request.");
@@ -544,7 +544,7 @@ public void onStopTrackingTouch(SeekBar seekBar) {
544544
// Client. All controls invisible.
545545
captureStillButton.setVisibility(View.INVISIBLE);
546546
phaseAlignButton.setVisibility(View.INVISIBLE);
547-
getPeriodButton.setVisibility(View.INVISIBLE);
547+
getPeriodButton.setVisibility(View.VISIBLE);
548548
exposureSeekBar.setVisibility(View.INVISIBLE);
549549
sensitivitySeekBar.setVisibility(View.INVISIBLE);
550550

app/src/main/java/com/googleresearch/capturesync/softwaresync/phasealign/PeriodCalculator.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import java.util.stream.Collectors;
88

99
public class PeriodCalculator {
10-
private final static long CALC_DURATION_MS = 5000;
10+
private final static long CALC_DURATION_MS = 10000;
1111
private volatile boolean shouldRegister;
1212
private ArrayList<Long> registeredTimestamps;
1313

@@ -23,7 +23,6 @@ public long getPeriodNs() throws InterruptedException {
2323
Thread.sleep(CALC_DURATION_MS);
2424
// Stop recording timestamps and calculate period
2525
shouldRegister = false;
26-
// TODO: switch to clusters!
2726
return calcPeriodNsClusters(getDiff(registeredTimestamps));
2827
}
2928

0 commit comments

Comments
 (0)