Browse Source

12/24h preference is read from device instead

master
Henning Hall 6 years ago
parent
commit
d6491b6c47
5 changed files with 20 additions and 10 deletions
  1. +1
    -1
      android/src/main/java/com/henninghall/date_picker/PickerView.java
  2. +12
    -0
      android/src/main/java/com/henninghall/date_picker/Settings.java
  3. +0
    -5
      android/src/main/java/com/henninghall/date_picker/Utils.java
  4. +3
    -2
      android/src/main/java/com/henninghall/date_picker/wheels/AmPmWheel.java
  5. +4
    -2
      android/src/main/java/com/henninghall/date_picker/wheels/HourWheel.java

+ 1
- 1
android/src/main/java/com/henninghall/date_picker/PickerView.java View File

@ -117,7 +117,7 @@ public class PickerView extends RelativeLayout {
hourWheel.picker.setOnValueChangeListenerInScrolling(new NumberPickerView.OnValueChangeListenerInScrolling() {
@Override
public void onValueChangeInScrolling(NumberPickerView picker, int oldVal, int newVal) {
if(Utils.usesAmPm(locale)){
if(Settings.usesAmPm()){
String oldValue = hourWheel.getValueAtIndex(oldVal);
String newValue = hourWheel.getValueAtIndex(newVal);
boolean passingNoonOrMidnight = (oldValue.equals("12") && newValue.equals("11")) || oldValue.equals("11") && newValue.equals("12");

+ 12
- 0
android/src/main/java/com/henninghall/date_picker/Settings.java View File

@ -0,0 +1,12 @@
package com.henninghall.date_picker;
import android.text.format.DateFormat;
public class Settings {
public static boolean usesAmPm (){
return !DateFormat.is24HourFormat(DatePickerManager.context);
}
}

+ 0
- 5
android/src/main/java/com/henninghall/date_picker/Utils.java View File

@ -18,11 +18,6 @@ import java.util.TimeZone;
public class Utils {
public static boolean usesAmPm(Locale locale) {
DateFormat df = DateFormat.getTimeInstance(DateFormat.FULL, locale);
return df instanceof SimpleDateFormat && ((SimpleDateFormat) df).toPattern().contains("a");
}
public static String printToday(Locale locale) {
return PrettyTime.of(locale).printToday();
}

+ 3
- 2
android/src/main/java/com/henninghall/date_picker/wheels/AmPmWheel.java View File

@ -2,6 +2,7 @@ package com.henninghall.date_picker.wheels;
import com.henninghall.date_picker.Mode;
import com.henninghall.date_picker.PickerView;
import com.henninghall.date_picker.Settings;
import com.henninghall.date_picker.Utils;
import java.util.Calendar;
import cn.carbswang.android.numberpickerview.library.NumberPickerView;
@ -34,12 +35,12 @@ public class AmPmWheel extends Wheel {
@Override
public boolean visible() {
return Utils.usesAmPm(pickerView.locale) && pickerView.mode != Mode.date;
return Settings.usesAmPm() && pickerView.mode != Mode.date;
}
@Override
public String getFormatTemplate() {
return Utils.usesAmPm(pickerView.locale) ? " a " : "";
return Settings.usesAmPm() ? " a " : "";
}
}

+ 4
- 2
android/src/main/java/com/henninghall/date_picker/wheels/HourWheel.java View File

@ -2,9 +2,11 @@ package com.henninghall.date_picker.wheels;
import com.henninghall.date_picker.Mode;
import com.henninghall.date_picker.PickerView;
import com.henninghall.date_picker.Settings;
import com.henninghall.date_picker.Utils;
import java.util.Calendar;
import cn.carbswang.android.numberpickerview.library.NumberPickerView;
@ -16,7 +18,7 @@ public class HourWheel extends Wheel {
@Override
void init() {
int numberOfHours = Utils.usesAmPm(pickerView.locale) ? 12 : 24;
int numberOfHours = Settings.usesAmPm() ? 12 : 24;
Calendar cal = pickerView.getInitialDate();
for(int i=0; i<numberOfHours; i++) {
@ -36,7 +38,7 @@ public class HourWheel extends Wheel {
@Override
public String getFormatTemplate() {
return Utils.usesAmPm(pickerView.locale) ? "h": "HH";
return Settings.usesAmPm() ? "h": "HH";
}
}

Loading…
Cancel
Save