From 388a56479f0e69646774144f973f5a8fcdc8a37a Mon Sep 17 00:00:00 2001 From: John Slavick Date: Mon, 28 Dec 2015 11:46:15 -0600 Subject: [PATCH] Replaced HashMap method arguments and return values with Map. This allows alternative implementations of the Map interface (such as android.support.v4.util.ArrayMap) to be used. --- .../roomorama/caldroid/CaldroidFragment.java | 33 +++++++++++-------- .../caldroid/CaldroidGridAdapter.java | 25 +++++++------- .../CaldroidSampleCustomAdapter.java | 6 ++-- 3 files changed, 35 insertions(+), 29 deletions(-) diff --git a/caldroid/src/main/java/com/roomorama/caldroid/CaldroidFragment.java b/caldroid/src/main/java/com/roomorama/caldroid/CaldroidFragment.java index d69f094..455dd18 100644 --- a/caldroid/src/main/java/com/roomorama/caldroid/CaldroidFragment.java +++ b/caldroid/src/main/java/com/roomorama/caldroid/CaldroidFragment.java @@ -13,8 +13,12 @@ import android.support.v4.view.ViewPager.OnPageChangeListener; import android.text.format.DateUtils; import android.text.format.Time; -import android.view.*; +import android.view.ContextThemeWrapper; +import android.view.LayoutInflater; +import android.view.View; import android.view.View.OnClickListener; +import android.view.ViewGroup; +import android.view.Window; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemLongClickListener; @@ -35,6 +39,7 @@ import java.util.HashMap; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.TimeZone; import hirondelle.date4j.DateTime; @@ -169,22 +174,22 @@ public class CaldroidFragment extends DialogFragment { /** * caldroidData belongs to Caldroid */ - protected HashMap caldroidData = new HashMap(); + protected Map caldroidData = new HashMap<>(); /** * extraData belongs to client */ - protected HashMap extraData = new HashMap(); + protected Map extraData = new HashMap<>(); /** * backgroundForDateMap holds background resource for each date */ - protected HashMap backgroundForDateTimeMap = new HashMap(); + protected Map backgroundForDateTimeMap = new HashMap<>(); /** * textColorForDateMap holds color for text for each date */ - protected HashMap textColorForDateTimeMap = new HashMap(); + protected Map textColorForDateTimeMap = new HashMap<>(); ; /** @@ -301,11 +306,11 @@ public InfiniteViewPager getDateViewPager() { /* * For client to access background and text color maps */ - public HashMap getBackgroundForDateTimeMap() { + public Map getBackgroundForDateTimeMap() { return backgroundForDateTimeMap; } - public HashMap getTextColorForDateTimeMap() { + public Map getTextColorForDateTimeMap() { return textColorForDateTimeMap; } @@ -346,7 +351,7 @@ public ArrayList getDatePagerAdapters() { * * @return */ - public HashMap getCaldroidData() { + public Map getCaldroidData() { caldroidData.clear(); caldroidData.put(DISABLE_DATES, disableDates); caldroidData.put(SELECTED_DATES, selectedDates); @@ -372,7 +377,7 @@ public HashMap getCaldroidData() { * * @return */ - public HashMap getExtraData() { + public Map getExtraData() { return extraData; } @@ -381,7 +386,7 @@ public HashMap getExtraData() { * * @param extraData */ - public void setExtraData(HashMap extraData) { + public void setExtraData(Map extraData) { this.extraData = extraData; } @@ -389,7 +394,7 @@ public void setExtraData(HashMap extraData) { * Set backgroundForDateMap */ public void setBackgroundResourceForDates( - HashMap backgroundForDateMap) { + Map backgroundForDateMap) { if (backgroundForDateMap == null || backgroundForDateMap.size() == 0) { return; } @@ -414,7 +419,7 @@ public void clearBackgroundResourceForDates(List dates) { } public void setBackgroundResourceForDateTimes( - HashMap backgroundForDateTimeMap) { + Map backgroundForDateTimeMap) { this.backgroundForDateTimeMap.putAll(backgroundForDateTimeMap); } @@ -450,7 +455,7 @@ public void clearBackgroundResourceForDateTime(DateTime dateTime) { * * @return */ - public void setTextColorForDates(HashMap textColorForDateMap) { + public void setTextColorForDates(Map textColorForDateMap) { if (textColorForDateMap == null || textColorForDateMap.size() == 0) { return; } @@ -473,7 +478,7 @@ public void clearTextColorForDates(List dates) { } public void setTextColorForDateTimes( - HashMap textColorForDateTimeMap) { + Map textColorForDateTimeMap) { this.textColorForDateTimeMap.putAll(textColorForDateTimeMap); } diff --git a/caldroid/src/main/java/com/roomorama/caldroid/CaldroidGridAdapter.java b/caldroid/src/main/java/com/roomorama/caldroid/CaldroidGridAdapter.java index 63c4b4e..27ae6c2 100644 --- a/caldroid/src/main/java/com/roomorama/caldroid/CaldroidGridAdapter.java +++ b/caldroid/src/main/java/com/roomorama/caldroid/CaldroidGridAdapter.java @@ -17,6 +17,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.HashMap; +import java.util.Map; import hirondelle.date4j.DateTime; @@ -35,8 +36,8 @@ public class CaldroidGridAdapter extends BaseAdapter { // Use internally, to make the search for date faster instead of using // indexOf methods on ArrayList - protected HashMap disableDatesMap = new HashMap<>(); - protected HashMap selectedDatesMap = new HashMap<>(); + protected Map disableDatesMap = new HashMap<>(); + protected Map selectedDatesMap = new HashMap<>(); protected DateTime minDateTime; protected DateTime maxDateTime; @@ -53,11 +54,11 @@ public class CaldroidGridAdapter extends BaseAdapter { /** * caldroidData belongs to Caldroid */ - protected HashMap caldroidData; + protected Map caldroidData; /** * extraData belongs to client */ - protected HashMap extraData; + protected Map extraData; protected LayoutInflater localInflater; @@ -109,22 +110,22 @@ public int getThemeResource() { return themeResource; } - public HashMap getCaldroidData() { + public Map getCaldroidData() { return caldroidData; } - public void setCaldroidData(HashMap caldroidData) { + public void setCaldroidData(Map caldroidData) { this.caldroidData = caldroidData; // Reset parameters populateFromCaldroidData(); } - public HashMap getExtraData() { + public Map getExtraData() { return extraData; } - public void setExtraData(HashMap extraData) { + public void setExtraData(Map extraData) { this.extraData = extraData; } @@ -138,8 +139,8 @@ public void setExtraData(HashMap extraData) { * @param extraData */ public CaldroidGridAdapter(Context context, int month, int year, - HashMap caldroidData, - HashMap extraData) { + Map caldroidData, + Map extraData) { super(); this.month = month; this.year = year; @@ -236,7 +237,7 @@ protected DateTime getToday() { protected void setCustomResources(DateTime dateTime, View backgroundView, TextView textView) { // Set custom background resource - HashMap backgroundForDateTimeMap = (HashMap) caldroidData + Map backgroundForDateTimeMap = (Map) caldroidData .get(CaldroidFragment._BACKGROUND_FOR_DATETIME_MAP); if (backgroundForDateTimeMap != null) { // Get background resource for the dateTime @@ -249,7 +250,7 @@ protected void setCustomResources(DateTime dateTime, View backgroundView, } // Set custom text color - HashMap textColorForDateTimeMap = (HashMap) caldroidData + Map textColorForDateTimeMap = (Map) caldroidData .get(CaldroidFragment._TEXT_COLOR_FOR_DATETIME_MAP); if (textColorForDateTimeMap != null) { // Get textColor for the dateTime diff --git a/caldroidSampleActivity/src/main/java/com/caldroidsample/CaldroidSampleCustomAdapter.java b/caldroidSampleActivity/src/main/java/com/caldroidsample/CaldroidSampleCustomAdapter.java index a5529ce..5680026 100644 --- a/caldroidSampleActivity/src/main/java/com/caldroidsample/CaldroidSampleCustomAdapter.java +++ b/caldroidSampleActivity/src/main/java/com/caldroidsample/CaldroidSampleCustomAdapter.java @@ -11,15 +11,15 @@ import com.roomorama.caldroid.CaldroidFragment; import com.roomorama.caldroid.CaldroidGridAdapter; -import java.util.HashMap; +import java.util.Map; import hirondelle.date4j.DateTime; public class CaldroidSampleCustomAdapter extends CaldroidGridAdapter { public CaldroidSampleCustomAdapter(Context context, int month, int year, - HashMap caldroidData, - HashMap extraData) { + Map caldroidData, + Map extraData) { super(context, month, year, caldroidData, extraData); }