Skip to content

Commit

Permalink
Resolve bug of time if start with calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Jamet committed Nov 30, 2016
1 parent e29d2a9 commit 4779f36
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Add the JitPack repository in your build.gradle at the end of repositories:
And add the dependency
```
dependencies {
compile 'com.github.Kunzisoft:Android-SwitchDateTimePicker:1.1'
compile 'com.github.Kunzisoft:Android-SwitchDateTimePicker:1.2'
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public class SwitchTimePicker implements RadialPickerLayout.OnValueSelectedListe
private OnTimeSelectedListener onTimeSelectedListener;
private OnClickListener onClickTimeListener;

private int mCurrentViewShow;

private TextView mHourView;
private TextView mHourSpaceView;
private TextView mMinuteView;
Expand Down Expand Up @@ -120,14 +122,19 @@ public SwitchTimePicker(Context context, OnTimeSelectedListener callback) {
public SwitchTimePicker(Context context, OnTimeSelectedListener callback,
Bundle savedInstanceState) {
this(context, callback);
if (savedInstanceState != null && savedInstanceState.containsKey(KEY_HOUR_OF_DAY)
&& savedInstanceState.containsKey(KEY_MINUTE)
&& savedInstanceState.containsKey(KEY_IS_24_HOUR_VIEW)) {
hourOfDay = savedInstanceState.getInt(KEY_HOUR_OF_DAY);
minute = savedInstanceState.getInt(KEY_MINUTE);
mIs24HourMode = savedInstanceState.getBoolean(KEY_IS_24_HOUR_VIEW);
mInKbMode = savedInstanceState.getBoolean(KEY_IN_KB_MODE);
mVibrate = savedInstanceState.getBoolean(KEY_VIBRATE);
if (savedInstanceState != null) {
if(savedInstanceState.containsKey(KEY_HOUR_OF_DAY))
hourOfDay = savedInstanceState.getInt(KEY_HOUR_OF_DAY);
if(savedInstanceState.containsKey(KEY_MINUTE))
minute = savedInstanceState.getInt(KEY_MINUTE);
if(savedInstanceState.containsKey(KEY_IS_24_HOUR_VIEW))
mIs24HourMode = savedInstanceState.getBoolean(KEY_IS_24_HOUR_VIEW);
if(savedInstanceState.containsKey(KEY_CURRENT_ITEM_SHOWING))
mCurrentViewShow = savedInstanceState.getInt(KEY_CURRENT_ITEM_SHOWING);
if(savedInstanceState.containsKey(KEY_IN_KB_MODE))
mInKbMode = savedInstanceState.getBoolean(KEY_IN_KB_MODE);
if(savedInstanceState.containsKey(KEY_VIBRATE))
mVibrate = savedInstanceState.getBoolean(KEY_VIBRATE);
}
}

Expand Down Expand Up @@ -218,12 +225,12 @@ public void onFocusChanged(View view, CharSequence sourceText, boolean focused,
mTimePicker.setOnValueSelectedListener(this);
mTimePicker.setOnKeyListener(keyboardListener);
mTimePicker.initialize(mContext, hourOfDay, minute, mIs24HourMode, mVibrate);
int currentItemShowing = HOUR_INDEX;
mCurrentViewShow = HOUR_INDEX;
if (savedInstanceState != null &&
savedInstanceState.containsKey(KEY_CURRENT_ITEM_SHOWING)) {
currentItemShowing = savedInstanceState.getInt(KEY_CURRENT_ITEM_SHOWING);
mCurrentViewShow = savedInstanceState.getInt(KEY_CURRENT_ITEM_SHOWING);
}
setCurrentItemShowing(currentItemShowing, false, true, true);
setCurrentItemShowing(mCurrentViewShow, false, true, true);
mTimePicker.invalidate();

mHourView.setOnClickListener(new OnClickListener() {
Expand All @@ -238,7 +245,8 @@ public void onClick(View v) {
mMinuteView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
setCurrentItemShowing(MINUTE_INDEX, true, false, true);
// TODO bug
//setCurrentItemShowing(MINUTE_INDEX, true, false, true);
mTimePicker.tryVibrate();
if(onClickTimeListener != null)
onClickTimeListener.onClick(mMinuteView);
Expand Down Expand Up @@ -918,6 +926,10 @@ public void setIs24HourMode(boolean is24HourMode) {
this.mIs24HourMode = is24HourMode;
}

public void setFirstViewShow(int viewIndex) {
mCurrentViewShow = viewIndex;
}

/**
* Simple node class to be used for traversal to check for legal times.
* mLegalKeys represents the keys that can be typed to get to the node.
Expand Down

0 comments on commit 4779f36

Please sign in to comment.