Browse Source

larger touchable wheel area (#222)

master
Henning Hall 5 years ago
committed by GitHub
parent
commit
37c1338b3c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 63 additions and 164 deletions
  1. +1
    -1
      android/build.gradle
  2. +4
    -3
      android/src/main/java/com/henninghall/date_picker/PickerView.java
  3. +4
    -0
      android/src/main/java/com/henninghall/date_picker/pickers/AndroidNative.java
  4. +1
    -0
      android/src/main/java/com/henninghall/date_picker/pickers/Picker.java
  5. +0
    -62
      android/src/main/java/com/henninghall/date_picker/ui/EmptyWheels.java
  6. +5
    -0
      android/src/main/java/com/henninghall/date_picker/ui/UIManager.java
  7. +0
    -9
      android/src/main/java/com/henninghall/date_picker/ui/Wheels.java
  8. +15
    -0
      android/src/main/java/com/henninghall/date_picker/wheelFunctions/HorizontalPadding.java
  9. +6
    -0
      android/src/main/java/com/henninghall/date_picker/wheels/MonthWheel.java
  10. +14
    -0
      android/src/main/java/com/henninghall/date_picker/wheels/Wheel.java
  11. +13
    -89
      android/src/main/res/layout/ios_clone.xml

+ 1
- 1
android/build.gradle View File

@ -25,7 +25,7 @@ android {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.facebook.react:react-native:+'
implementation 'com.henninghall.android:NumberPickerView:1.1.2'
implementation 'com.henninghall.android:NumberPickerView:1.1.4'
implementation 'org.apache.commons:commons-lang3:3.7'
implementation group: 'net.time4j', name: 'time4j-android', version: '4.2-2018i'
}

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

@ -15,10 +15,7 @@ import com.henninghall.date_picker.props.LocaleProp;
import com.henninghall.date_picker.props.ModeProp;
import com.henninghall.date_picker.props.TextColorProp;
import com.henninghall.date_picker.ui.UIManager;
import com.henninghall.date_picker.wheels.AmPmWheel;
import java.util.ArrayList;
import java.util.Date;
public class PickerView extends RelativeLayout {
@ -58,6 +55,10 @@ public class PickerView extends RelativeLayout {
uiManager.updateWheelOrder();
}
if (didUpdate(ModeProp.name)) {
uiManager.updateWheelPadding();
}
if (didUpdate(DateProp.name, HeightProp.name, LocaleProp.name,
MaximumDateProp.name, MinimumDateProp.name, MinuteIntervalProp.name, ModeProp.name,
UtcProp.name, VariantProp.name

+ 4
- 0
android/src/main/java/com/henninghall/date_picker/pickers/AndroidNative.java View File

@ -77,6 +77,10 @@ public class AndroidNative extends NumberPicker implements Picker {
return this;
}
@Override
public void setItemPaddingHorizontal(int padding) {
// Not needed for this picker
}
@Override
public void smoothScrollToValue(final int value) {

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

@ -22,6 +22,7 @@ public interface Picker {
View getView();
void setVisibility(int visibility);
void setWrapSelectorWheel(boolean wrapSelectorWheel);
void setItemPaddingHorizontal(int padding);
interface OnValueChangeListenerInScrolling {
void onValueChangeInScrolling(Picker picker, int oldVal, int newVal);

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

@ -1,62 +0,0 @@
package com.henninghall.date_picker.ui;
import android.view.View;
import com.henninghall.date_picker.R;
import com.henninghall.date_picker.State;
import java.util.ArrayList;
import cn.carbswang.android.numberpickerview.library.NumberPickerView;
class EmptyWheels {
private final ArrayList<NumberPickerView> views;
private final PickerWrapper pickerWrapper;
private View rootView;
private State state;
private int[] emptyWheelIds = {
R.id.emptyStart,
R.id.empty1,
R.id.empty2,
R.id.empty3,
R.id.emptyEnd
};
EmptyWheels(View rootView, PickerWrapper pickerWrapper, State state) {
this.pickerWrapper = pickerWrapper;
this.rootView = rootView;
this.state = state;
this.views = getAll();
}
private ArrayList<NumberPickerView> getAll() {
ArrayList<NumberPickerView> wheels = new ArrayList<>();
if(state.derived.hasNativeStyle()) return wheels;
for (int id: emptyWheelIds) {
NumberPickerView view = (NumberPickerView) rootView.findViewById(id);
wheels.add(view);
}
return wheels;
}
void add() {
if(state.derived.hasNativeStyle()) return;
int numberOfVisibleWheels = state.derived.getVisibleWheels().size();
int emptyViewsToAdd = numberOfVisibleWheels + 1;
for (int i = 0; i < emptyViewsToAdd; i++) {
int index = i * 2;
pickerWrapper.addPicker(views.get(i), index);
}
}
void setShownCount(int shownCount) {
for (int id : emptyWheelIds) {
NumberPickerView view = (NumberPickerView) rootView.findViewById(id);
if(view != null) view.setShownCount(shownCount);
}
}
}

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

@ -9,6 +9,7 @@ import com.henninghall.date_picker.wheelFunctions.Refresh;
import com.henninghall.date_picker.wheelFunctions.SetDate;
import com.henninghall.date_picker.wheelFunctions.TextColor;
import com.henninghall.date_picker.wheelFunctions.UpdateVisibility;
import com.henninghall.date_picker.wheelFunctions.HorizontalPadding;
import com.henninghall.date_picker.wheels.Wheel;
import java.text.SimpleDateFormat;
@ -80,4 +81,8 @@ public class UIManager {
WheelChangeListener onWheelChangeListener = new WheelChangeListenerImpl(wheels, state, this, rootView);
wheels.applyOnAll(new AddOnChangeListener(onWheelChangeListener));
}
public void updateWheelPadding() {
wheels.applyOnVisible(new HorizontalPadding());
}
}

+ 0
- 9
android/src/main/java/com/henninghall/date_picker/ui/Wheels.java View File

@ -21,7 +21,6 @@ import com.henninghall.date_picker.wheels.YearWheel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
@ -37,7 +36,6 @@ public class Wheels {
private YearWheel yearWheel;
private View rootView;
private final PickerWrapper pickerWrapper;
private final EmptyWheels emptyWheels;
private HashMap<WheelType, Wheel> wheelPerWheelType;
@ -55,7 +53,6 @@ public class Wheels {
hourWheel = new HourWheel(getPickerWithId(R.id.hour), state);
wheelPerWheelType = getWheelPerType();
emptyWheels = new EmptyWheels(rootView, pickerWrapper, state);
changeAmPmWhenPassingMidnightOrNoon();
}
@ -82,13 +79,11 @@ public class Wheels {
void updateHeight() {
int shownCount = state.derived.getShownCount();
applyOnAll(new SetShowCount(shownCount));
emptyWheels.setShownCount(shownCount);
}
void updateWheelOrder() {
pickerWrapper.removeAll();
addInOrder();
addEmpty();
}
Wheel getWheel(WheelType type){
@ -179,8 +174,4 @@ public class Wheels {
}};
}
private void addEmpty() {
emptyWheels.add();
}
}

+ 15
- 0
android/src/main/java/com/henninghall/date_picker/wheelFunctions/HorizontalPadding.java View File

@ -0,0 +1,15 @@
package com.henninghall.date_picker.wheelFunctions;
import com.henninghall.date_picker.wheels.Wheel;
import java.util.Calendar;
public class HorizontalPadding implements WheelFunction {
@Override
public void apply(Wheel wheel) {
wheel.setHorizontalPadding();
}
}

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

@ -6,6 +6,7 @@ import java.util.*;
import com.henninghall.date_picker.*;
import com.henninghall.date_picker.models.Mode;
import com.henninghall.date_picker.pickers.Picker;
import com.henninghall.date_picker.wheelFunctions.HorizontalPadding;
public class MonthWheel extends Wheel
{
@ -46,5 +47,10 @@ public class MonthWheel extends Wheel
return Paint.Align.LEFT;
}
@Override
public int getHorizontalPadding() {
return 1;
}
}

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

@ -3,6 +3,7 @@ package com.henninghall.date_picker.wheels;
import android.graphics.Paint;
import android.view.View;
import com.henninghall.date_picker.models.Mode;
import com.henninghall.date_picker.pickers.Picker;
import com.henninghall.date_picker.State;
@ -115,4 +116,17 @@ public abstract class Wheel {
return getFormat(locale).format(cal.getTime());
}
public void setHorizontalPadding(){
picker.setItemPaddingHorizontal(getHorizontalPadding());
}
public int getHorizontalPadding() {
Mode mode = state.getMode();
switch (mode){
case time: return 15;
case date: return 10;
case datetime:
default: return 5;
}
}
}

+ 13
- 89
android/src/main/res/layout/ios_clone.xml View File

@ -11,21 +11,9 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="center_horizontal"
>
<com.henninghall.date_picker.pickers.IosClone
android:id="@+id/emptyStart"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
custom:npv_DividerColor="#cccccc"
custom:npv_RespondChangeOnDetached="false"
custom:npv_ShownCount="5"
custom:npv_TextColorNormal="#aaaaaa"
custom:npv_TextColorSelected="#000000"
custom:npv_TextSizeNormal="18dp"
custom:npv_TextSizeSelected="21dp"
custom:npv_ItemPaddingHorizontal="0dp"
/>
<com.henninghall.date_picker.pickers.IosClone
android:id="@+id/year"
android:tag="year"
@ -37,23 +25,8 @@
custom:npv_TextSizeSelected="21dp"
custom:npv_TextColorSelected="#000000"
custom:npv_TextColorNormal="#aaaaaa"
custom:npv_DividerColor="#cccccc"
custom:npv_ItemPaddingHorizontal="3dp"
/>
<com.henninghall.date_picker.pickers.IosClone
android:id="@+id/empty1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
custom:npv_DividerColor="#cccccc"
custom:npv_RespondChangeOnDetached="false"
custom:npv_ShownCount="5"
custom:npv_TextColorNormal="#aaaaaa"
custom:npv_TextColorSelected="#000000"
custom:npv_TextSizeNormal="18dp"
custom:npv_TextSizeSelected="21dp"
custom:npv_ItemPaddingHorizontal="0dp"
/>
custom:npv_DividerColor="#cccccc" />
<com.henninghall.date_picker.pickers.IosClone
android:id="@+id/month"
android:tag="month"
@ -66,22 +39,8 @@
custom:npv_TextColorSelected="#000000"
custom:npv_TextColorNormal="#aaaaaa"
custom:npv_DividerColor="#cccccc"
custom:npv_ItemPaddingHorizontal="3dp"
/>
<com.henninghall.date_picker.pickers.IosClone
android:id="@+id/empty2"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
custom:npv_DividerColor="#cccccc"
custom:npv_RespondChangeOnDetached="false"
custom:npv_ShownCount="5"
custom:npv_TextColorNormal="#aaaaaa"
custom:npv_TextColorSelected="#000000"
custom:npv_TextSizeNormal="18dp"
custom:npv_TextSizeSelected="21dp"
custom:npv_ItemPaddingHorizontal="0dp"
/>
<com.henninghall.date_picker.pickers.IosClone
android:id="@+id/date"
android:tag="date"
@ -94,21 +53,19 @@
custom:npv_TextColorSelected="#000000"
custom:npv_TextColorNormal="#aaaaaa"
custom:npv_DividerColor="#cccccc"
custom:npv_ItemPaddingHorizontal="3dp"
/>
<com.henninghall.date_picker.pickers.IosClone
android:id="@+id/empty3"
android:layout_width="0dp"
android:layout_weight="1"
android:id="@+id/day"
android:tag="day"
android:layout_height="match_parent"
custom:npv_DividerColor="#cccccc"
custom:npv_RespondChangeOnDetached="false"
android:layout_width="wrap_content"
custom:npv_ShownCount="5"
custom:npv_TextColorNormal="#aaaaaa"
custom:npv_TextColorSelected="#000000"
custom:npv_RespondChangeOnDetached="false"
custom:npv_TextSizeNormal="18dp"
custom:npv_TextSizeSelected="21dp"
custom:npv_ItemPaddingHorizontal="0dp"
custom:npv_TextColorSelected="#000000"
custom:npv_TextColorNormal="#aaaaaa"
custom:npv_DividerColor="#cccccc"
/>
<com.henninghall.date_picker.pickers.IosClone
android:id="@+id/hour"
@ -122,23 +79,7 @@
custom:npv_TextColorSelected="#000000"
custom:npv_TextSizeNormal="18dp"
custom:npv_TextSizeSelected="21dp"
custom:npv_ItemPaddingHorizontal="3dp"
/>
<com.henninghall.date_picker.pickers.IosClone
android:id="@+id/day"
android:tag="day"
android:layout_height="match_parent"
android:layout_width="wrap_content"
custom:npv_ShownCount="5"
custom:npv_RespondChangeOnDetached="false"
custom:npv_TextSizeNormal="18dp"
custom:npv_TextSizeSelected="21dp"
custom:npv_TextColorSelected="#000000"
custom:npv_TextColorNormal="#aaaaaa"
custom:npv_DividerColor="#cccccc"
custom:npv_ItemPaddingHorizontal="3dp"
/>
<com.henninghall.date_picker.pickers.IosClone
android:id="@+id/minutes"
android:tag="minutes"
@ -151,8 +92,7 @@
custom:npv_TextColorSelected="#000000"
custom:npv_TextSizeNormal="18dp"
custom:npv_TextSizeSelected="21dp"
custom:npv_ItemPaddingHorizontal="3dp"
/>
/>
<com.henninghall.date_picker.pickers.IosClone
android:id="@+id/ampm"
@ -166,23 +106,7 @@
custom:npv_TextColorSelected="#000000"
custom:npv_TextSizeNormal="18dp"
custom:npv_TextSizeSelected="21dp"
custom:npv_ItemPaddingHorizontal="3dp"
/>
<com.henninghall.date_picker.pickers.IosClone
android:id="@+id/emptyEnd"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
custom:npv_DividerColor="#cccccc"
custom:npv_RespondChangeOnDetached="false"
custom:npv_ShownCount="5"
custom:npv_TextColorNormal="#aaaaaa"
custom:npv_TextColorSelected="#000000"
custom:npv_TextSizeNormal="18dp"
custom:npv_TextSizeSelected="21dp"
custom:npv_ItemPaddingHorizontal="0dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"

Loading…
Cancel
Save