From 4779f368a46c85c73d75e4f5174f26388d428c22 Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Wed, 30 Nov 2016 03:32:15 +0100 Subject: [PATCH] Resolve bug of time if start with calendar --- ReadMe.md | 2 +- .../switchdatetime/time/SwitchTimePicker.java | 36 ++++++++++++------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/ReadMe.md b/ReadMe.md index 617a1ec..654de7d 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -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' } ``` diff --git a/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/time/SwitchTimePicker.java b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/time/SwitchTimePicker.java index 207e8e7..d84867f 100644 --- a/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/time/SwitchTimePicker.java +++ b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/time/SwitchTimePicker.java @@ -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; @@ -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); } } @@ -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() { @@ -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); @@ -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.