sync to full minute

This commit is contained in:
Peter Siegmund committed 2016-06-07 15:55:21 +02:00
1 parent eb07329293
commit 201c598425
5 files changed
+91 -13

No files matched your search

@@ -116,6 +116,7 @@
android:paddingRight="@dimen/default_padding_half"
android:textColor="?attr/white"
android:textSize="@dimen/textSize_20"
android:visibility="gone"
tools:text="1:00:00"/>
<TextView
@@ -126,7 +127,7 @@
android:layout_marginLeft="@dimen/default_margin"
android:layout_marginRight="@dimen/default_margin"
android:textColor="?attr/white"
android:textSize="@dimen/textSize_20"
android:textSize="@dimen/textSize_72"
android:visibility="visible"
tools:text="1:01:00"/>
@@ -140,6 +141,7 @@
android:paddingLeft="@dimen/default_padding_half"
android:textColor="?attr/white"
android:textSize="@dimen/textSize_20"
android:visibility="gone"
tools:text="1:02:00"/>
</LinearLayout>
</RelativeLayout>
@@ -185,7 +187,7 @@
android:id="@+id/set_start_time_absolute"
style="?attr/button"
android:layout_width="@dimen/default_button_width"
android:layout_height="wrap_content"
android:layout_height="@dimen/default_button_height"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:layout_marginBottom="@dimen/side_padding"
@@ -194,6 +196,19 @@
android:text="@string/race_set_time"
android:textSize="@dimen/textSize_18"/>
<Button
android:id="@+id/sync_to_minute"
android:layout_width="@dimen/default_button_width"
android:layout_height="@dimen/default_button_height"
android:layout_centerHorizontal="true"
android:background="?attr/button_filled_bordered"
android:layout_above="@id/set_start_time_absolute"
android:paddingLeft="@dimen/default_padding_half"
android:paddingRight="@dimen/default_padding_half"
android:text="@string/sync_to_minute"
android:textColor="?attr/white"
android:textSize="@dimen/textSize_18"/>
<TextView
android:id="@+id/debug_time"
style="?attr/textSmall"
@@ -203,7 +218,6 @@
android:layout_alignParentLeft="true"
android:visibility="gone"
tools:text="12:12:12"/>
</RelativeLayout>
<RelativeLayout
@@ -292,7 +306,7 @@
android:id="@+id/set_start_time_relative"
style="?attr/button"
android:layout_width="@dimen/default_button_width"
android:layout_height="wrap_content"
android:layout_height="@dimen/default_button_height"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:layout_marginBottom="@dimen/side_padding"
@@ -87,7 +87,7 @@
android:layout_height="match_parent"
android:background="?attr/sap_gray_black_30"
android:visibility="gone"
tools:visibility="gone">
tools:visibility="visible">
<RelativeLayout
android:id="@+id/buttonBar"
@@ -112,6 +112,7 @@
android:paddingRight="@dimen/default_padding_half"
android:textAppearance="?attr/textLarge"
android:textColor="?attr/white"
android:visibility="gone"
tools:text="1:00:00"/>
<TextView
@@ -135,6 +136,7 @@
android:paddingLeft="@dimen/default_padding_half"
android:textAppearance="?attr/textLarge"
android:textColor="?attr/white"
android:visibility="gone"
tools:text="1:02:00"/>
</LinearLayout>
</RelativeLayout>
@@ -145,14 +147,31 @@
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<Button
android:id="@+id/set_start_time_absolute"
style="?attr/buttonSolidSmall"
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="@dimen/default_margin_twice"
android:text="@string/race_set_time"/>
android:layout_margin="@dimen/default_margin"
android:orientation="horizontal">
<Button
android:id="@+id/sync_to_minute"
style="?attr/buttonSolidSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/default_margin"
android:background="?attr/button_filled_bordered"
android:text="@string/sync_to_minute"
android:textColor="?attr/white"/>
<Button
android:id="@+id/set_start_time_absolute"
style="?attr/buttonSolidSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/default_margin"
android:text="@string/race_set_time"/>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
@@ -210,7 +229,7 @@
android:layout_height="match_parent"
android:background="?attr/sap_gray_black_30"
android:visibility="gone"
tools:visibility="visible">
tools:visibility="gone">
<RelativeLayout
android:id="@+id/set_start_time_2"
@@ -512,5 +512,6 @@
<string name="abort_dismiss">Verwerfen</string>
<string name="set_column_factor">Setze Faktor</string>
<string name="set_factor_error">Beim Setzen des Faktors ist ein Fehler aufgetreten: %s</string>
<string name="sync_to_minute">Sync zur Minute</string>
</resources>
@@ -540,5 +540,6 @@
<string name="race_factor_format" translatable="false">x #.####</string>
<string name="set_column_factor">Set Factor</string>
<string name="set_factor_error">There was an error while setting the factor: %s</string>
<string name="sync_to_minute">Sync to minute</string>
</resources>
@@ -83,6 +83,7 @@ public class StartTimeFragment extends BaseFragment
private TextView mDebugTime;
private Button mMinuteInc;
private Button mMinuteDec;
private Button mSyncMinute;
private TimePoint mStartTime;
private Calendar mTimeLeft;
private Calendar mTimeRight;
@@ -157,6 +158,7 @@ public class StartTimeFragment extends BaseFragment
}
mCountdown = ViewHelper.get(layout, R.id.start_countdown);
mMinuteInc = ViewHelper.get(layout, R.id.minute_inc);
if (mMinuteInc != null) {
mMinuteInc.setOnClickListener(this);
@@ -167,6 +169,11 @@ public class StartTimeFragment extends BaseFragment
mMinuteDec.setOnClickListener(this);
}
mSyncMinute = ViewHelper.get(layout, R.id.sync_to_minute);
if (mSyncMinute != null) {
mSyncMinute.setOnClickListener(this);
}
View setStartAbsolute = ViewHelper.get(layout, R.id.set_start_time_absolute);
if (setStartAbsolute != null) {
setStartAbsolute.setOnClickListener(this);
@@ -571,7 +578,7 @@ public class StartTimeFragment extends BaseFragment
if (ZERO_TIME.equals(countdown)) {
countdown = countdown.substring(1);
}
mMinuteDec.setText(countdown);
// mMinuteDec.setText(countdown);
}
if (mMinuteInc != null) {
@@ -579,7 +586,7 @@ public class StartTimeFragment extends BaseFragment
if (ZERO_TIME.equals(countdown)) {
countdown = countdown.substring(1);
}
mMinuteInc.setText(countdown);
// mMinuteInc.setText(countdown);
}
if (mDebugTime != null) {
@@ -695,6 +702,10 @@ public class StartTimeFragment extends BaseFragment
changeFragment(MillisecondsTimePoint.now(), new MillisecondsDurationImpl(mTimeOffset.getValue() * 60 * 1000), identifier);
break;
case R.id.sync_to_minute:
syncToMinute();
break;
case R.id.header_text:
if (getArguments() != null && getArguments().getInt(START_MODE, START_MODE_PRESETUP) == START_MODE_PRESETUP) {
changeFragment();
@@ -709,6 +720,38 @@ public class StartTimeFragment extends BaseFragment
}
}
private void syncToMinute() {
TimePoint now = MillisecondsTimePoint.now();
if (mStartTime.after(now)) {
mStartTime = getNewStart( mStartTime.minus(now.asMillis()), false);
} else {
mStartTime = getNewStart(now.minus(mStartTime.asMillis()), true);
}
mListenerIgnore = true;
setPickerTime();
}
private TimePoint getNewStart(TimePoint timePoint, boolean running) {
TimePoint result;
mCalendar.setTime(timePoint.asDate());
int msec = mCalendar.get(Calendar.SECOND) * 1000 + mCalendar.get(Calendar.MILLISECOND);
if (running) {
if (msec >= 30000) {
result = mStartTime.minus(60000 - msec);
} else {
result = mStartTime.plus(msec);
}
} else {
if (msec >= 30000) {
result = mStartTime.plus(60000 - msec);
} else {
result = mStartTime.minus(msec);
}
}
return result;
}
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
if (!mListenerIgnore) {