From 7cfd527f4b6e2e0fa1416a06eb730a4058638ccc Mon Sep 17 00:00:00 2001 From: Wouter Dullaert Date: Fri, 30 Aug 2019 12:38:02 +0200 Subject: [PATCH] Checking for presence of a key is safer than a 'magic' default value --- .../materialdatetimepicker/date/DatePickerDialog.java | 9 +++------ .../materialdatetimepicker/time/TimePickerDialog.java | 8 +++----- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/library/src/main/java/com/wdullaer/materialdatetimepicker/date/DatePickerDialog.java b/library/src/main/java/com/wdullaer/materialdatetimepicker/date/DatePickerDialog.java index ddb95af1..040822aa 100644 --- a/library/src/main/java/com/wdullaer/materialdatetimepicker/date/DatePickerDialog.java +++ b/library/src/main/java/com/wdullaer/materialdatetimepicker/date/DatePickerDialog.java @@ -325,20 +325,17 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, highlightedDays = (HashSet) savedInstanceState.getSerializable(KEY_HIGHLIGHTED_DAYS); mThemeDark = savedInstanceState.getBoolean(KEY_THEME_DARK); mThemeDarkChanged = savedInstanceState.getBoolean(KEY_THEME_DARK_CHANGED); - mAccentColor = savedInstanceState.getInt(KEY_ACCENT, Integer.MAX_VALUE); - if (mAccentColor == Integer.MAX_VALUE) mAccentColor = null; + if (savedInstanceState.containsKey(KEY_ACCENT)) mAccentColor = savedInstanceState.getInt(KEY_ACCENT); mVibrate = savedInstanceState.getBoolean(KEY_VIBRATE); mDismissOnPause = savedInstanceState.getBoolean(KEY_DISMISS); mAutoDismiss = savedInstanceState.getBoolean(KEY_AUTO_DISMISS); mTitle = savedInstanceState.getString(KEY_TITLE); mOkResid = savedInstanceState.getInt(KEY_OK_RESID); mOkString = savedInstanceState.getString(KEY_OK_STRING); - mOkColor = savedInstanceState.getInt(KEY_OK_COLOR, Integer.MAX_VALUE); - if (mOkColor == Integer.MAX_VALUE) mOkColor = null; + if (savedInstanceState.containsKey(KEY_OK_COLOR)) mOkColor = savedInstanceState.getInt(KEY_OK_COLOR); mCancelResid = savedInstanceState.getInt(KEY_CANCEL_RESID); mCancelString = savedInstanceState.getString(KEY_CANCEL_STRING); - mCancelColor = savedInstanceState.getInt(KEY_CANCEL_COLOR, Integer.MAX_VALUE); - if (mCancelColor == Integer.MAX_VALUE) mCancelColor = null; + if (savedInstanceState.containsKey(KEY_CANCEL_COLOR)) mCancelColor = savedInstanceState.getInt(KEY_CANCEL_COLOR); mVersion = (Version) savedInstanceState.getSerializable(KEY_VERSION); mScrollOrientation = (ScrollOrientation) savedInstanceState.getSerializable(KEY_SCROLL_ORIENTATION); mTimezone = (TimeZone) savedInstanceState.getSerializable(KEY_TIMEZONE); diff --git a/library/src/main/java/com/wdullaer/materialdatetimepicker/time/TimePickerDialog.java b/library/src/main/java/com/wdullaer/materialdatetimepicker/time/TimePickerDialog.java index 2485ea68..ba2786b9 100644 --- a/library/src/main/java/com/wdullaer/materialdatetimepicker/time/TimePickerDialog.java +++ b/library/src/main/java/com/wdullaer/materialdatetimepicker/time/TimePickerDialog.java @@ -640,20 +640,18 @@ public void onCreate(Bundle savedInstanceState) { mTitle = savedInstanceState.getString(KEY_TITLE); mThemeDark = savedInstanceState.getBoolean(KEY_THEME_DARK); mThemeDarkChanged = savedInstanceState.getBoolean(KEY_THEME_DARK_CHANGED); - mAccentColor = savedInstanceState.getInt(KEY_ACCENT, Integer.MAX_VALUE); - if (mAccentColor == Integer.MAX_VALUE) mAccentColor = null; + if (savedInstanceState.containsKey(KEY_ACCENT)) mAccentColor = savedInstanceState.getInt(KEY_ACCENT); mVibrate = savedInstanceState.getBoolean(KEY_VIBRATE); mDismissOnPause = savedInstanceState.getBoolean(KEY_DISMISS); mEnableSeconds = savedInstanceState.getBoolean(KEY_ENABLE_SECONDS); mEnableMinutes = savedInstanceState.getBoolean(KEY_ENABLE_MINUTES); mOkResid = savedInstanceState.getInt(KEY_OK_RESID); mOkString = savedInstanceState.getString(KEY_OK_STRING); - mOkColor = savedInstanceState.getInt(KEY_OK_COLOR, Integer.MAX_VALUE); + if (savedInstanceState.containsKey(KEY_OK_COLOR)) mOkColor = savedInstanceState.getInt(KEY_OK_COLOR); if (mOkColor == Integer.MAX_VALUE) mOkColor = null; mCancelResid = savedInstanceState.getInt(KEY_CANCEL_RESID); mCancelString = savedInstanceState.getString(KEY_CANCEL_STRING); - mCancelColor = savedInstanceState.getInt(KEY_CANCEL_COLOR, Integer.MAX_VALUE); - if (mCancelColor == Integer.MAX_VALUE) mCancelColor = null; + if (savedInstanceState.containsKey(KEY_CANCEL_COLOR)) mCancelColor = savedInstanceState.getInt(KEY_CANCEL_COLOR); mVersion = (Version) savedInstanceState.getSerializable(KEY_VERSION); mLimiter = savedInstanceState.getParcelable(KEY_TIMEPOINTLIMITER); mLocale = (Locale) savedInstanceState.getSerializable(KEY_LOCALE);