Browse Source

progress

master
Henning Hall 5 years ago
parent
commit
37eb16d8ac
19 changed files with 107 additions and 79 deletions
  1. +11
    -2
      android/src/main/java/com/henninghall/date_picker/DerivedData.java
  2. +7
    -23
      android/src/main/java/com/henninghall/date_picker/PickerView.java
  3. +21
    -6
      android/src/main/java/com/henninghall/date_picker/pickers/AndroidNative.java
  4. +1
    -1
      android/src/main/java/com/henninghall/date_picker/pickers/Picker.java
  5. +2
    -2
      android/src/main/java/com/henninghall/date_picker/ui/EmptyWheels.java
  6. +1
    -6
      android/src/main/java/com/henninghall/date_picker/ui/UIManager.java
  7. +5
    -0
      android/src/main/java/com/henninghall/date_picker/wheels/AmPmWheel.java
  8. +5
    -0
      android/src/main/java/com/henninghall/date_picker/wheels/DateWheel.java
  9. +5
    -0
      android/src/main/java/com/henninghall/date_picker/wheels/DayWheel.java
  10. +5
    -0
      android/src/main/java/com/henninghall/date_picker/wheels/HourWheel.java
  11. +5
    -0
      android/src/main/java/com/henninghall/date_picker/wheels/MinutesWheel.java
  12. +5
    -0
      android/src/main/java/com/henninghall/date_picker/wheels/MonthWheel.java
  13. +2
    -0
      android/src/main/java/com/henninghall/date_picker/wheels/Wheel.java
  14. +5
    -0
      android/src/main/java/com/henninghall/date_picker/wheels/YearWheel.java
  15. +0
    -12
      android/src/main/res/layout/ios_clone.xml
  16. +12
    -18
      android/src/main/res/layout/native_picker.xml
  17. +10
    -6
      android/src/main/res/values/styles.xml
  18. +4
    -3
      defaultProps.js
  19. +1
    -0
      examples/detox/src/examples/Minimal.js

+ 11
- 2
android/src/main/java/com/henninghall/date_picker/DerivedData.java View File

@ -97,8 +97,17 @@ public class DerivedData {
return oddShowCount;
}
public boolean isIosClone() {
return state.getVariant() == Variant.iosClone;
public boolean hasNativeStyle() {
return state.getVariant() == Variant.nativeAndroid;
}
public int getRootLayout() {
switch (state.getVariant()){
case nativeAndroid: return R.layout.native_picker;
case iosClone: return R.layout.ios_clone;
default: return R.layout.ios_clone;
}
}
}

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

@ -19,33 +19,21 @@ import java.util.ArrayList;
public class PickerView extends RelativeLayout {
// private final View rootView = inflate(getContext(), R.layout.datepicker_view, this);
private View rootView = inflate(getContext(), R.layout.native_picker, this);
private final UIManager uiManager;
private State state;
private UIManager uiManager;
private State state = new State();
private ArrayList<String> updatedProps = new ArrayList<>();
private boolean initialized = false;
public PickerView() {
super(DatePickerManager.context);
state = new State();
uiManager = new UIManager(state, this);
}
public void update() {
if(updatedProps.contains(VariantProp.name)) {
uiManager.setVariant();
// rootView = inflate(getContext(), R.layout.native_picker, this);
// NumberPicker np = findViewById(R.id.numberPicker);
// np.setMinValue(0);
// np.setMaxValue(1);
// np.setDisplayedValues(new String[]{"Today", "Tomorrow"});
// np.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
// @Override
// public void onValueChange(NumberPicker numberPicker, int i, int i1) {
// Log.d("onValueChange", String.valueOf(i));
// }
// });
if(!initialized){
inflate(getContext(), state.derived.getRootLayout(), this);
uiManager = new UIManager(state, this);
initialized = true;
}
if(updatedProps.contains(FadeToColorProp.name)) {
@ -93,10 +81,6 @@ public class PickerView extends RelativeLayout {
uiManager.scroll(wheelIndex, scrollTimes);
}
public View getRootView(){
return rootView;
}
private final Runnable measureAndLayout = new Runnable() {
@Override
public void run() {

+ 21
- 6
android/src/main/java/com/henninghall/date_picker/pickers/AndroidNative.java View File

@ -5,11 +5,17 @@ import android.graphics.Paint;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.NumberPicker;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import cn.carbswang.android.numberpickerview.library.NumberPickerView;
import static android.widget.NumberPicker.OnScrollListener.SCROLL_STATE_IDLE;
public class AndroidNative extends NumberPicker implements Picker {
public AndroidNative(Context context) {
@ -31,7 +37,6 @@ public class AndroidNative extends NumberPicker implements Picker {
@Override
public void smoothScrollToValue(int value) {
// TODO
setValue(value);
}
@ -51,16 +56,25 @@ public class AndroidNative extends NumberPicker implements Picker {
}
@Override
public void setOnValueChangeListenerInScrolling(OnValueChangeListenerInScrolling listener) {
public void setOnValueChangeListenerInScrolling(final OnValueChangeListenerInScrolling listener) {
final Picker self = this;
super.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker numberPicker, int from, int to) {
listener.onValueChangeInScrolling(self, from, to);
}
});
}
@Override
public void setOnValueChangedListener(final Picker.OnValueChangeListener listener) {
super.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
super.setOnScrollListener(new OnScrollListener() {
int previousState = SCROLL_STATE_IDLE;
@Override
public void onValueChange(NumberPicker numberPicker, int from, int to) {
listener.onValueChange();
public void onScrollStateChange(NumberPicker numberPicker, int state) {
boolean stoppedScrolling = previousState != SCROLL_STATE_IDLE && state == SCROLL_STATE_IDLE;
if (stoppedScrolling) listener.onValueChange();
previousState = state;
}
});
}
@ -68,6 +82,7 @@ public class AndroidNative extends NumberPicker implements Picker {
@Override
public void setShownCount(int count) {
// always 3 date rows -> nothing needs to be done here
}
@Override

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

@ -18,10 +18,10 @@ public interface Picker {
void setSelectedTextColor(int value);
void setOnValueChangeListenerInScrolling(Picker.OnValueChangeListenerInScrolling listener);
void setOnValueChangedListener(Picker.OnValueChangeListener onValueChangeListener);
void setShownCount(int count);
View getView();
void setVisibility(int visibility);
void setWrapSelectorWheel(boolean wrapSelectorWheel);
interface OnValueChangeListenerInScrolling {
void onValueChangeInScrolling(Picker picker, int oldVal, int newVal);

+ 2
- 2
android/src/main/java/com/henninghall/date_picker/ui/EmptyWheels.java View File

@ -33,7 +33,7 @@ class EmptyWheels {
private ArrayList<NumberPickerView> getAll() {
ArrayList<NumberPickerView> wheels = new ArrayList<>();
if(!state.derived.isIosClone()) return wheels;
if(state.derived.hasNativeStyle()) return wheels;
for (int id: emptyWheelIds) {
NumberPickerView view = (NumberPickerView) rootView.findViewById(id);
wheels.add(view);
@ -42,7 +42,7 @@ class EmptyWheels {
}
void add() {
if(!state.derived.isIosClone()) return;
if(state.derived.hasNativeStyle()) return;
int numberOfVisibleWheels = state.derived.getVisibleWheels().size();
int emptyViewsToAdd = numberOfVisibleWheels + 1;
for (int i = 0; i < emptyViewsToAdd; i++) {

+ 1
- 6
android/src/main/java/com/henninghall/date_picker/ui/UIManager.java View File

@ -38,7 +38,7 @@ public class UIManager {
}
public void updateFadeToColor(){
if(!state.derived.isIosClone()) return;
if(state.derived.hasNativeStyle()) return;
fadingOverlay.updateColor();
}
@ -79,9 +79,4 @@ public class UIManager {
WheelChangeListener onWheelChangeListener = new WheelChangeListenerImpl(wheels, state, this, rootView);
wheels.applyOnAll(new AddOnChangeListener(onWheelChangeListener));
}
public void setVariant() {
}
}

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

@ -35,6 +35,11 @@ public class AmPmWheel extends Wheel {
return Utils.usesAmPm() && state.getMode() != Mode.date;
}
@Override
public boolean wrapSelectorWheel() {
return false;
}
@Override
public String getFormatPattern() {
return Utils.usesAmPm() ? " a " : "";

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

@ -34,6 +34,11 @@ public class DateWheel extends Wheel
return state.getMode() == Mode.date;
}
@Override
public boolean wrapSelectorWheel() {
return true;
}
@Override
public String getFormatPattern() {
return LocaleUtils.getPatternIncluding("d", state.getLocale());

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

@ -110,6 +110,11 @@ public class DayWheel extends Wheel {
return state.getMode() == Mode.datetime;
}
@Override
public boolean wrapSelectorWheel() {
return false;
}
@Override
public String getFormatPattern() {

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

@ -34,6 +34,11 @@ public class HourWheel extends Wheel {
return state.getMode() != Mode.date;
}
@Override
public boolean wrapSelectorWheel() {
return true;
}
@Override
public String getFormatPattern() {
return Utils.usesAmPm() ? "h": "HH";

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

@ -35,6 +35,11 @@ public class MinutesWheel extends Wheel {
return state.getMode() != Mode.date;
}
@Override
public boolean wrapSelectorWheel() {
return true;
}
@Override
public String getFormatPattern() {
return "mm";

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

@ -31,6 +31,11 @@ public class MonthWheel extends Wheel
return state.getMode() == Mode.date;
}
@Override
public boolean wrapSelectorWheel() {
return true;
}
@Override
public String getFormatPattern() {
return "LLLL";

+ 2
- 0
android/src/main/java/com/henninghall/date_picker/wheels/Wheel.java View File

@ -17,6 +17,7 @@ public abstract class Wheel {
private Calendar userSetValue;
public abstract boolean visible();
public abstract boolean wrapSelectorWheel();
public abstract Paint.Align getTextAlign();
public abstract String getFormatPattern();
public abstract ArrayList<String> getValues();
@ -34,6 +35,7 @@ public abstract class Wheel {
this.picker = picker;
this.format = new SimpleDateFormat(getFormatPattern(), state.getLocale());
picker.setTextAlign(getTextAlign());
picker.setWrapSelectorWheel(wrapSelectorWheel());
}
private int getIndexOfDate(Calendar date){

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

@ -59,6 +59,11 @@ public class YearWheel extends Wheel
return state.getMode() == Mode.date;
}
@Override
public boolean wrapSelectorWheel() {
return false;
}
@Override
public Paint.Align getTextAlign() {
return Paint.Align.RIGHT;

android/src/main/res/layout/datepicker_view.xml → android/src/main/res/layout/ios_clone.xml View File

@ -24,7 +24,6 @@
custom:npv_TextColorSelected="#000000"
custom:npv_TextSizeNormal="18dp"
custom:npv_TextSizeSelected="21dp"
custom:npv_WrapSelectorWheel="true"
custom:npv_ItemPaddingHorizontal="0dp"
/>
<com.henninghall.date_picker.pickers.IosClone
@ -36,7 +35,6 @@
custom:npv_RespondChangeOnDetached="false"
custom:npv_TextSizeNormal="18dp"
custom:npv_TextSizeSelected="21dp"
custom:npv_WrapSelectorWheel="false"
custom:npv_TextColorSelected="#000000"
custom:npv_TextColorNormal="#aaaaaa"
custom:npv_DividerColor="#cccccc"
@ -54,7 +52,6 @@
custom:npv_TextColorSelected="#000000"
custom:npv_TextSizeNormal="18dp"
custom:npv_TextSizeSelected="21dp"
custom:npv_WrapSelectorWheel="true"
custom:npv_ItemPaddingHorizontal="0dp"
/>
<com.henninghall.date_picker.pickers.IosClone
@ -66,7 +63,6 @@
custom:npv_RespondChangeOnDetached="false"
custom:npv_TextSizeNormal="18dp"
custom:npv_TextSizeSelected="21dp"
custom:npv_WrapSelectorWheel="true"
custom:npv_TextColorSelected="#000000"
custom:npv_TextColorNormal="#aaaaaa"
custom:npv_DividerColor="#cccccc"
@ -84,7 +80,6 @@
custom:npv_TextColorSelected="#000000"
custom:npv_TextSizeNormal="18dp"
custom:npv_TextSizeSelected="21dp"
custom:npv_WrapSelectorWheel="true"
custom:npv_ItemPaddingHorizontal="0dp"
/>
<com.henninghall.date_picker.pickers.IosClone
@ -96,7 +91,6 @@
custom:npv_RespondChangeOnDetached="false"
custom:npv_TextSizeNormal="18dp"
custom:npv_TextSizeSelected="21dp"
custom:npv_WrapSelectorWheel="true"
custom:npv_TextColorSelected="#000000"
custom:npv_TextColorNormal="#aaaaaa"
custom:npv_DividerColor="#cccccc"
@ -114,7 +108,6 @@
custom:npv_TextColorSelected="#000000"
custom:npv_TextSizeNormal="18dp"
custom:npv_TextSizeSelected="21dp"
custom:npv_WrapSelectorWheel="true"
custom:npv_ItemPaddingHorizontal="0dp"
/>
<com.henninghall.date_picker.pickers.IosClone
@ -129,7 +122,6 @@
custom:npv_TextColorSelected="#000000"
custom:npv_TextSizeNormal="18dp"
custom:npv_TextSizeSelected="21dp"
custom:npv_WrapSelectorWheel="true"
custom:npv_ItemPaddingHorizontal="3dp"
/>
<com.henninghall.date_picker.pickers.IosClone
@ -141,7 +133,6 @@
custom:npv_RespondChangeOnDetached="false"
custom:npv_TextSizeNormal="18dp"
custom:npv_TextSizeSelected="21dp"
custom:npv_WrapSelectorWheel="false"
custom:npv_TextColorSelected="#000000"
custom:npv_TextColorNormal="#aaaaaa"
custom:npv_DividerColor="#cccccc"
@ -160,7 +151,6 @@
custom:npv_TextColorSelected="#000000"
custom:npv_TextSizeNormal="18dp"
custom:npv_TextSizeSelected="21dp"
custom:npv_WrapSelectorWheel="true"
custom:npv_ItemPaddingHorizontal="3dp"
/>
@ -176,7 +166,6 @@
custom:npv_TextColorSelected="#000000"
custom:npv_TextSizeNormal="18dp"
custom:npv_TextSizeSelected="21dp"
custom:npv_WrapSelectorWheel="true"
custom:npv_ItemPaddingHorizontal="3dp"
/>
<com.henninghall.date_picker.pickers.IosClone
@ -191,7 +180,6 @@
custom:npv_TextColorSelected="#000000"
custom:npv_TextSizeNormal="18dp"
custom:npv_TextSizeSelected="21dp"
custom:npv_WrapSelectorWheel="true"
custom:npv_ItemPaddingHorizontal="0dp"
/>

+ 12
- 18
android/src/main/res/layout/native_picker.xml View File

@ -1,50 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/container"
<LinearLayout android:id="@+id/container"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
android:orientation="horizontal">
<LinearLayout
android:id="@+id/pickerWrapper"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
>
<com.henninghall.date_picker.pickers.AndroidNative
android:id="@+id/year"
android:tag="year"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
style="@style/android_native" />
<com.henninghall.date_picker.pickers.AndroidNative
android:id="@+id/month"
android:tag="month"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
style="@style/android_native" />
<com.henninghall.date_picker.pickers.AndroidNative
android:id="@+id/date"
android:tag="date"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
style="@style/android_native_small" />
<com.henninghall.date_picker.pickers.AndroidNative
android:id="@+id/day"
android:tag="day"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
style="@style/android_native" />
<com.henninghall.date_picker.pickers.AndroidNative
android:id="@+id/hour"
android:tag="hour"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
style="@style/android_native_small" />
<com.henninghall.date_picker.pickers.AndroidNative
android:id="@+id/minutes"
android:tag="minutes"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
style="@style/android_native_small" />
<com.henninghall.date_picker.pickers.AndroidNative
android:id="@+id/ampm"
android:tag="ampm"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
android:layout_width="40dp"
style="@style/android_native_small" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>

+ 10
- 6
android/src/main/res/values/styles.xml View File

@ -1,10 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Dialog_Full_Screen">
<item name="android:windowIsFloating">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:background">@android:color/transparent</item>
<style name="android_native">
<item name="android:layout_marginLeft">5dp</item>
<item name="android:layout_marginRight">5dp</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">match_parent</item>
<item name="android:gravity">right</item>
<item name="android:scaleWidth">0.5</item>
</style>
<style name="android_native_small" parent="android_native">
<item name="android:layout_width">40dp</item>
</style>
</resources>

+ 4
- 3
defaultProps.js View File

@ -1,4 +1,5 @@
export default {
mode: 'datetime',
minuteInterval: 1,
}
mode: 'datetime',
minuteInterval: 1,
androidVariant: 'nativeAndroid',
}

+ 1
- 0
examples/detox/src/examples/Minimal.js View File

@ -8,6 +8,7 @@ export default class MinimalExample extends Component {
<DatePicker
date={this.state.date}
onDateChange={date => this.setState({ date })}
androidVariant="iosClone"
androidVariant="nativeAndroid"
/>
)

Loading…
Cancel
Save