diff --git a/android-studio-project/ExoPlayer-AirPlay-Receiver/src/main/java/com/github/warren_bank/exoplayer_airplay_receiver/ui/exoplayer2/MultiFieldTimePickerDialog.java b/android-studio-project/ExoPlayer-AirPlay-Receiver/src/main/java/com/github/warren_bank/exoplayer_airplay_receiver/ui/exoplayer2/MultiFieldTimePickerDialog.java
index 5b2fd21..6fbeb43 100644
--- a/android-studio-project/ExoPlayer-AirPlay-Receiver/src/main/java/com/github/warren_bank/exoplayer_airplay_receiver/ui/exoplayer2/MultiFieldTimePickerDialog.java
+++ b/android-studio-project/ExoPlayer-AirPlay-Receiver/src/main/java/com/github/warren_bank/exoplayer_airplay_receiver/ui/exoplayer2/MultiFieldTimePickerDialog.java
@@ -29,6 +29,7 @@
public class MultiFieldTimePickerDialog
extends AlertDialog implements OnClickListener {
+ private final NumberPicker mSignSpinner;
private final NumberPicker mHourSpinner;
private final NumberPicker mMinuteSpinner;
private final NumberPicker mSecSpinner;
@@ -38,12 +39,13 @@ public class MultiFieldTimePickerDialog
private final int mStep;
private final int mBaseMilli;
private final boolean mIs24hourFormat;
+ private final boolean mIsSigned;
/**
* Adds an onTimeSet() method.
*/
public interface OnMultiFieldTimeSetListener {
- void onTimeSet(int hourOfDay, int minute, int second, int milli);
+ void onTimeSet(boolean isNegative, int hourOfDay, int minute, int second, int milli);
}
private static final int SECOND_IN_MILLIS = 1000;
@@ -53,13 +55,15 @@ public interface OnMultiFieldTimeSetListener {
public MultiFieldTimePickerDialog(
Context context,
int theme,
+ boolean isNegative,
int hour, int minute, int second, int milli,
- int min, int max, int step, boolean is24hourFormat,
+ int min, int max, int step, boolean is24hourFormat, boolean isSigned,
OnMultiFieldTimeSetListener listener) {
super(context, theme);
mListener = listener;
mStep = step;
mIs24hourFormat = is24hourFormat;
+ mIsSigned = isSigned;
if (min >= max) {
min = 0;
@@ -75,6 +79,7 @@ public MultiFieldTimePickerDialog(
View view = inflater.inflate(R.layout.multi_field_time_picker_dialog, null);
setView(view);
+ mSignSpinner = (NumberPicker) view.findViewById(R.id.sign);
mHourSpinner = (NumberPicker) view.findViewById(R.id.hour);
mMinuteSpinner = (NumberPicker) view.findViewById(R.id.minute);
mSecSpinner = (NumberPicker) view.findViewById(R.id.second);
@@ -91,6 +96,18 @@ public MultiFieldTimePickerDialog(
hour = minHour;
}
+ if (!isSigned) {
+ mSignSpinner.setVisibility(View.GONE);
+ } else {
+ int minSign = 0; // + positive
+ int maxSign = 1; // - negative
+ int iniSign = isNegative ? maxSign : minSign;
+ mSignSpinner.setMinValue(minSign);
+ mSignSpinner.setMaxValue(maxSign);
+ mSignSpinner.setDisplayedValues(new String[] { "+", "-" });
+ mSignSpinner.setValue(iniSign);
+ }
+
if (is24hourFormat) {
mAmPmSpinner.setVisibility(View.GONE);
} else {
@@ -171,7 +188,7 @@ public MultiFieldTimePickerDialog(
if (step >= MINUTE_IN_MILLIS) {
// Remove the ':' in front of the second spinner as well.
- view.findViewById(R.id.second_colon).setVisibility(View.GONE);
+ view.findViewById(R.id.second_sep).setVisibility(View.GONE);
mSecSpinner.setVisibility(View.GONE);
}
@@ -200,7 +217,7 @@ public MultiFieldTimePickerDialog(
if (step >= SECOND_IN_MILLIS) {
// Remove the '.' in front of the milli spinner as well.
- view.findViewById(R.id.second_dot).setVisibility(View.GONE);
+ view.findViewById(R.id.milli_sep).setVisibility(View.GONE);
mMilliSpinner.setVisibility(View.GONE);
}
@@ -262,7 +279,13 @@ private void notifyDateSet() {
}
hour += ampm * 12;
}
- mListener.onTimeSet(hour, minute, sec, milli);
+ boolean isNegative = false;
+ if (mIsSigned) {
+ int sign = getPickerValue(mSignSpinner);
+ if (sign == 1)
+ isNegative = true;
+ }
+ mListener.onTimeSet(isNegative, hour, minute, sec, milli);
}
/**
diff --git a/android-studio-project/ExoPlayer-AirPlay-Receiver/src/main/java/com/github/warren_bank/exoplayer_airplay_receiver/ui/exoplayer2/MultiFieldTimePickerDialogContainer.java b/android-studio-project/ExoPlayer-AirPlay-Receiver/src/main/java/com/github/warren_bank/exoplayer_airplay_receiver/ui/exoplayer2/MultiFieldTimePickerDialogContainer.java
index f02da34..6bef0a3 100644
--- a/android-studio-project/ExoPlayer-AirPlay-Receiver/src/main/java/com/github/warren_bank/exoplayer_airplay_receiver/ui/exoplayer2/MultiFieldTimePickerDialogContainer.java
+++ b/android-studio-project/ExoPlayer-AirPlay-Receiver/src/main/java/com/github/warren_bank/exoplayer_airplay_receiver/ui/exoplayer2/MultiFieldTimePickerDialogContainer.java
@@ -25,10 +25,13 @@ private static class TextSynchronizerListener implements MultiFieldTimePickerDia
}
@Override
- public void onTimeSet(int hourOfDay, int minute, int second, int milli) {
+ public void onTimeSet(boolean isNegative, int hourOfDay, int minute, int second, int milli) {
long textOffsetMs = (milli) + (second * 1000) + (minute * 60 * 1000) + (hourOfDay * 60 * 60 * 1000);
long textOffsetUs = (textOffsetMs * 1000);
+ if (isNegative)
+ textOffsetUs *= -1;
+
textSynchronizer.setTextOffset(textOffsetUs);
}
@@ -39,8 +42,9 @@ public void onTimeSet(long textOffsetUs) {
private static void showPickerDialog(
Context mContext,
+ boolean isNegative,
int hourOfDay, int minute, int second, int millis,
- int min, int max, int step, boolean is24hourFormat,
+ int min, int max, int step, boolean is24hourFormat, boolean isSigned,
MultiFieldTimePickerDialog.OnMultiFieldTimeSetListener mListener,
DialogInterface.OnDismissListener onDismissListener
) {
@@ -49,8 +53,9 @@ private static void showPickerDialog(
mDialog = new MultiFieldTimePickerDialog(
mContext,
/* theme= */ 0,
+ isNegative,
hourOfDay, minute, second, millis,
- min, max, step, is24hourFormat,
+ min, max, step, is24hourFormat, isSigned,
mListener
);
@@ -96,6 +101,11 @@ public static void show(
long offsetPositionUs = textSynchronizer.getTextOffset();
+ boolean isNegative = (offsetPositionUs < 0);
+
+ if (isNegative)
+ offsetPositionUs *= -1;
+
int hourOfDay = (int) TimeUnit.MICROSECONDS.toHours(offsetPositionUs);
int minute = (int) (TimeUnit.MICROSECONDS.toMinutes(offsetPositionUs) % 60);
int second = (int) (TimeUnit.MICROSECONDS.toSeconds(offsetPositionUs) % 60);
@@ -106,11 +116,13 @@ public static void show(
int step = 100; // 100 ms
boolean is24hourFormat = true;
+ boolean isSigned = true;
showPickerDialog(
mContext,
+ isNegative,
hourOfDay, minute, second, millis,
- min, max, step, is24hourFormat,
+ min, max, step, is24hourFormat, isSigned,
mListener,
onDismissListener
);
diff --git a/android-studio-project/ExoPlayer-AirPlay-Receiver/src/main/res/layout/multi_field_time_picker_dialog.xml b/android-studio-project/ExoPlayer-AirPlay-Receiver/src/main/res/layout/multi_field_time_picker_dialog.xml
index e037a09..f064485 100644
--- a/android-studio-project/ExoPlayer-AirPlay-Receiver/src/main/res/layout/multi_field_time_picker_dialog.xml
+++ b/android-studio-project/ExoPlayer-AirPlay-Receiver/src/main/res/layout/multi_field_time_picker_dialog.xml
@@ -39,6 +39,18 @@
android:orientation="horizontal"
android:gravity="center">
+
+ android:text="@string/time_picker_dialog_minute_second_separator"
+ />
+
"a.m."
"p.m."
+ "Positive/Negative Sign"
"Hour"
"Minute"
"Second"
"Millisecond"
"AM/PM"
- ":"
- ":"
- "."
+ "hr :"
+ "min :"
+ "sec ."
+ "ms"