From 32497379a6b186eb3482fd6927eacb9972c9df94 Mon Sep 17 00:00:00 2001 From: Blankj <625783482@qq.com> Date: Fri, 27 Apr 2018 21:05:32 +0800 Subject: [PATCH] see 04/27 log --- .../com/blankj/utilcode/util/SPUtils.java | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/utilcode/src/main/java/com/blankj/utilcode/util/SPUtils.java b/utilcode/src/main/java/com/blankj/utilcode/util/SPUtils.java index fb3bdeec..8b516f90 100644 --- a/utilcode/src/main/java/com/blankj/utilcode/util/SPUtils.java +++ b/utilcode/src/main/java/com/blankj/utilcode/util/SPUtils.java @@ -30,7 +30,17 @@ public final class SPUtils { * @return the single {@link SPUtils} instance */ public static SPUtils getInstance() { - return getInstance(""); + return getInstance("", Context.MODE_PRIVATE); + } + + /** + * Return the single {@link SPUtils} instance + * + * @param mode Operating mode. + * @return the single {@link SPUtils} instance + */ + public static SPUtils getInstance(final int mode) { + return getInstance("", mode); } /** @@ -40,10 +50,21 @@ public final class SPUtils { * @return the single {@link SPUtils} instance */ public static SPUtils getInstance(String spName) { + return getInstance(spName, Context.MODE_PRIVATE); + } + + /** + * Return the single {@link SPUtils} instance + * + * @param spName The name of sp. + * @param mode Operating mode. + * @return the single {@link SPUtils} instance + */ + public static SPUtils getInstance(String spName, final int mode) { if (isSpace(spName)) spName = "spUtils"; SPUtils spUtils = SP_UTILS_MAP.get(spName); if (spUtils == null) { - spUtils = new SPUtils(spName); + spUtils = new SPUtils(spName, mode); SP_UTILS_MAP.put(spName, spUtils); } return spUtils; @@ -53,6 +74,10 @@ public final class SPUtils { sp = Utils.getApp().getSharedPreferences(spName, Context.MODE_PRIVATE); } + private SPUtils(final String spName, final int mode) { + sp = Utils.getApp().getSharedPreferences(spName, mode); + } + /** * Put the string value in sp. * -- GitLab