SPStaticUtils.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  1. package com.cooleshow.base.utils;
  2. import android.content.SharedPreferences;
  3. import androidx.annotation.NonNull;
  4. import java.util.Map;
  5. import java.util.Set;
  6. /**
  7. * <pre>
  8. * author: Blankj
  9. * blog : http://blankj.com
  10. * time : 2019/01/04
  11. * desc : utils about shared preference
  12. * </pre>
  13. */
  14. public final class SPStaticUtils {
  15. private static SPUtils sDefaultSPUtils;
  16. /**
  17. * Set the default instance of {@link SPUtils}.
  18. *
  19. * @param spUtils The default instance of {@link SPUtils}.
  20. */
  21. public static void setDefaultSPUtils(final SPUtils spUtils) {
  22. sDefaultSPUtils = spUtils;
  23. }
  24. /**
  25. * Put the string value in sp.
  26. *
  27. * @param key The key of sp.
  28. * @param value The value of sp.
  29. */
  30. public static void put(@NonNull final String key, final String value) {
  31. put(key, value, getDefaultSPUtils());
  32. }
  33. /**
  34. * Put the string value in sp.
  35. *
  36. * @param key The key of sp.
  37. * @param value The value of sp.
  38. * @param isCommit True to use {@link SharedPreferences.Editor#commit()},
  39. * false to use {@link SharedPreferences.Editor#apply()}
  40. */
  41. public static void put(@NonNull final String key, final String value, final boolean isCommit) {
  42. put(key, value, isCommit, getDefaultSPUtils());
  43. }
  44. /**
  45. * Return the string value in sp.
  46. *
  47. * @param key The key of sp.
  48. * @return the string value if sp exists or {@code ""} otherwise
  49. */
  50. public static String getString(@NonNull final String key) {
  51. return getString(key, getDefaultSPUtils());
  52. }
  53. /**
  54. * Return the string value in sp.
  55. *
  56. * @param key The key of sp.
  57. * @param defaultValue The default value if the sp doesn't exist.
  58. * @return the string value if sp exists or {@code defaultValue} otherwise
  59. */
  60. public static String getString(@NonNull final String key, final String defaultValue) {
  61. return getString(key, defaultValue, getDefaultSPUtils());
  62. }
  63. /**
  64. * Put the int value in sp.
  65. *
  66. * @param key The key of sp.
  67. * @param value The value of sp.
  68. */
  69. public static void put(@NonNull final String key, final int value) {
  70. put(key, value, getDefaultSPUtils());
  71. }
  72. /**
  73. * Put the int value in sp.
  74. *
  75. * @param key The key of sp.
  76. * @param value The value of sp.
  77. * @param isCommit True to use {@link SharedPreferences.Editor#commit()},
  78. * false to use {@link SharedPreferences.Editor#apply()}
  79. */
  80. public static void put(@NonNull final String key, final int value, final boolean isCommit) {
  81. put(key, value, isCommit, getDefaultSPUtils());
  82. }
  83. /**
  84. * Return the int value in sp.
  85. *
  86. * @param key The key of sp.
  87. * @return the int value if sp exists or {@code -1} otherwise
  88. */
  89. public static int getInt(@NonNull final String key) {
  90. return getInt(key, getDefaultSPUtils());
  91. }
  92. /**
  93. * Return the int value in sp.
  94. *
  95. * @param key The key of sp.
  96. * @param defaultValue The default value if the sp doesn't exist.
  97. * @return the int value if sp exists or {@code defaultValue} otherwise
  98. */
  99. public static int getInt(@NonNull final String key, final int defaultValue) {
  100. return getInt(key, defaultValue, getDefaultSPUtils());
  101. }
  102. /**
  103. * Put the long value in sp.
  104. *
  105. * @param key The key of sp.
  106. * @param value The value of sp.
  107. */
  108. public static void put(@NonNull final String key, final long value) {
  109. put(key, value, getDefaultSPUtils());
  110. }
  111. /**
  112. * Put the long value in sp.
  113. *
  114. * @param key The key of sp.
  115. * @param value The value of sp.
  116. * @param isCommit True to use {@link SharedPreferences.Editor#commit()},
  117. * false to use {@link SharedPreferences.Editor#apply()}
  118. */
  119. public static void put(@NonNull final String key, final long value, final boolean isCommit) {
  120. put(key, value, isCommit, getDefaultSPUtils());
  121. }
  122. /**
  123. * Return the long value in sp.
  124. *
  125. * @param key The key of sp.
  126. * @return the long value if sp exists or {@code -1} otherwise
  127. */
  128. public static long getLong(@NonNull final String key) {
  129. return getLong(key, getDefaultSPUtils());
  130. }
  131. /**
  132. * Return the long value in sp.
  133. *
  134. * @param key The key of sp.
  135. * @param defaultValue The default value if the sp doesn't exist.
  136. * @return the long value if sp exists or {@code defaultValue} otherwise
  137. */
  138. public static long getLong(@NonNull final String key, final long defaultValue) {
  139. return getLong(key, defaultValue, getDefaultSPUtils());
  140. }
  141. /**
  142. * Put the float value in sp.
  143. *
  144. * @param key The key of sp.
  145. * @param value The value of sp.
  146. */
  147. public static void put(@NonNull final String key, final float value) {
  148. put(key, value, getDefaultSPUtils());
  149. }
  150. /**
  151. * Put the float value in sp.
  152. *
  153. * @param key The key of sp.
  154. * @param value The value of sp.
  155. * @param isCommit True to use {@link SharedPreferences.Editor#commit()},
  156. * false to use {@link SharedPreferences.Editor#apply()}
  157. */
  158. public static void put(@NonNull final String key, final float value, final boolean isCommit) {
  159. put(key, value, isCommit, getDefaultSPUtils());
  160. }
  161. /**
  162. * Return the float value in sp.
  163. *
  164. * @param key The key of sp.
  165. * @return the float value if sp exists or {@code -1f} otherwise
  166. */
  167. public static float getFloat(@NonNull final String key) {
  168. return getFloat(key, getDefaultSPUtils());
  169. }
  170. /**
  171. * Return the float value in sp.
  172. *
  173. * @param key The key of sp.
  174. * @param defaultValue The default value if the sp doesn't exist.
  175. * @return the float value if sp exists or {@code defaultValue} otherwise
  176. */
  177. public static float getFloat(@NonNull final String key, final float defaultValue) {
  178. return getFloat(key, defaultValue, getDefaultSPUtils());
  179. }
  180. /**
  181. * Put the boolean value in sp.
  182. *
  183. * @param key The key of sp.
  184. * @param value The value of sp.
  185. */
  186. public static void put(@NonNull final String key, final boolean value) {
  187. put(key, value, getDefaultSPUtils());
  188. }
  189. /**
  190. * Put the boolean value in sp.
  191. *
  192. * @param key The key of sp.
  193. * @param value The value of sp.
  194. * @param isCommit True to use {@link SharedPreferences.Editor#commit()},
  195. * false to use {@link SharedPreferences.Editor#apply()}
  196. */
  197. public static void put(@NonNull final String key, final boolean value, final boolean isCommit) {
  198. put(key, value, isCommit, getDefaultSPUtils());
  199. }
  200. /**
  201. * Return the boolean value in sp.
  202. *
  203. * @param key The key of sp.
  204. * @return the boolean value if sp exists or {@code false} otherwise
  205. */
  206. public static boolean getBoolean(@NonNull final String key) {
  207. return getBoolean(key, getDefaultSPUtils());
  208. }
  209. /**
  210. * Return the boolean value in sp.
  211. *
  212. * @param key The key of sp.
  213. * @param defaultValue The default value if the sp doesn't exist.
  214. * @return the boolean value if sp exists or {@code defaultValue} otherwise
  215. */
  216. public static boolean getBoolean(@NonNull final String key, final boolean defaultValue) {
  217. return getBoolean(key, defaultValue, getDefaultSPUtils());
  218. }
  219. /**
  220. * Put the set of string value in sp.
  221. *
  222. * @param key The key of sp.
  223. * @param value The value of sp.
  224. */
  225. public static void put(@NonNull final String key, final Set<String> value) {
  226. put(key, value, getDefaultSPUtils());
  227. }
  228. /**
  229. * Put the set of string value in sp.
  230. *
  231. * @param key The key of sp.
  232. * @param value The value of sp.
  233. * @param isCommit True to use {@link SharedPreferences.Editor#commit()},
  234. * false to use {@link SharedPreferences.Editor#apply()}
  235. */
  236. public static void put(@NonNull final String key,
  237. final Set<String> value,
  238. final boolean isCommit) {
  239. put(key, value, isCommit, getDefaultSPUtils());
  240. }
  241. /**
  242. * Return the set of string value in sp.
  243. *
  244. * @param key The key of sp.
  245. * @return the set of string value if sp exists
  246. * or {@code Collections.<String>emptySet()} otherwise
  247. */
  248. public static Set<String> getStringSet(@NonNull final String key) {
  249. return getStringSet(key, getDefaultSPUtils());
  250. }
  251. /**
  252. * Return the set of string value in sp.
  253. *
  254. * @param key The key of sp.
  255. * @param defaultValue The default value if the sp doesn't exist.
  256. * @return the set of string value if sp exists or {@code defaultValue} otherwise
  257. */
  258. public static Set<String> getStringSet(@NonNull final String key,
  259. final Set<String> defaultValue) {
  260. return getStringSet(key, defaultValue, getDefaultSPUtils());
  261. }
  262. /**
  263. * Return all values in sp.
  264. *
  265. * @return all values in sp
  266. */
  267. public static Map<String, ?> getAll() {
  268. return getAll(getDefaultSPUtils());
  269. }
  270. /**
  271. * Return whether the sp contains the preference.
  272. *
  273. * @param key The key of sp.
  274. * @return {@code true}: yes<br>{@code false}: no
  275. */
  276. public static boolean contains(@NonNull final String key) {
  277. return contains(key, getDefaultSPUtils());
  278. }
  279. /**
  280. * Remove the preference in sp.
  281. *
  282. * @param key The key of sp.
  283. */
  284. public static void remove(@NonNull final String key) {
  285. remove(key, getDefaultSPUtils());
  286. }
  287. /**
  288. * Remove the preference in sp.
  289. *
  290. * @param key The key of sp.
  291. * @param isCommit True to use {@link SharedPreferences.Editor#commit()},
  292. * false to use {@link SharedPreferences.Editor#apply()}
  293. */
  294. public static void remove(@NonNull final String key, final boolean isCommit) {
  295. remove(key, isCommit, getDefaultSPUtils());
  296. }
  297. /**
  298. * Remove all preferences in sp.
  299. */
  300. public static void clear() {
  301. clear(getDefaultSPUtils());
  302. }
  303. /**
  304. * Remove all preferences in sp.
  305. *
  306. * @param isCommit True to use {@link SharedPreferences.Editor#commit()},
  307. * false to use {@link SharedPreferences.Editor#apply()}
  308. */
  309. public static void clear(final boolean isCommit) {
  310. clear(isCommit, getDefaultSPUtils());
  311. }
  312. ///////////////////////////////////////////////////////////////////////////
  313. // dividing line
  314. ///////////////////////////////////////////////////////////////////////////
  315. /**
  316. * Put the string value in sp.
  317. *
  318. * @param key The key of sp.
  319. * @param value The value of sp.
  320. * @param spUtils The instance of {@link SPUtils}.
  321. */
  322. public static void put(@NonNull final String key, final String value, @NonNull final SPUtils spUtils) {
  323. spUtils.put(key, value);
  324. }
  325. /**
  326. * Put the string value in sp.
  327. *
  328. * @param key The key of sp.
  329. * @param value The value of sp.
  330. * @param isCommit True to use {@link SharedPreferences.Editor#commit()},
  331. * false to use {@link SharedPreferences.Editor#apply()}
  332. * @param spUtils The instance of {@link SPUtils}.
  333. */
  334. public static void put(@NonNull final String key,
  335. final String value,
  336. final boolean isCommit,
  337. @NonNull final SPUtils spUtils) {
  338. spUtils.put(key, value, isCommit);
  339. }
  340. /**
  341. * Return the string value in sp.
  342. *
  343. * @param key The key of sp.
  344. * @param spUtils The instance of {@link SPUtils}.
  345. * @return the string value if sp exists or {@code ""} otherwise
  346. */
  347. public static String getString(@NonNull final String key, @NonNull final SPUtils spUtils) {
  348. return spUtils.getString(key);
  349. }
  350. /**
  351. * Return the string value in sp.
  352. *
  353. * @param key The key of sp.
  354. * @param defaultValue The default value if the sp doesn't exist.
  355. * @param spUtils The instance of {@link SPUtils}.
  356. * @return the string value if sp exists or {@code defaultValue} otherwise
  357. */
  358. public static String getString(@NonNull final String key,
  359. final String defaultValue,
  360. @NonNull final SPUtils spUtils) {
  361. return spUtils.getString(key, defaultValue);
  362. }
  363. /**
  364. * Put the int value in sp.
  365. *
  366. * @param key The key of sp.
  367. * @param value The value of sp.
  368. * @param spUtils The instance of {@link SPUtils}.
  369. */
  370. public static void put(@NonNull final String key, final int value, @NonNull final SPUtils spUtils) {
  371. spUtils.put(key, value);
  372. }
  373. /**
  374. * Put the int value in sp.
  375. *
  376. * @param key The key of sp.
  377. * @param value The value of sp.
  378. * @param isCommit True to use {@link SharedPreferences.Editor#commit()},
  379. * false to use {@link SharedPreferences.Editor#apply()}
  380. * @param spUtils The instance of {@link SPUtils}.
  381. */
  382. public static void put(@NonNull final String key,
  383. final int value,
  384. final boolean isCommit,
  385. @NonNull final SPUtils spUtils) {
  386. spUtils.put(key, value, isCommit);
  387. }
  388. /**
  389. * Return the int value in sp.
  390. *
  391. * @param key The key of sp.
  392. * @param spUtils The instance of {@link SPUtils}.
  393. * @return the int value if sp exists or {@code -1} otherwise
  394. */
  395. public static int getInt(@NonNull final String key, @NonNull final SPUtils spUtils) {
  396. return spUtils.getInt(key);
  397. }
  398. /**
  399. * Return the int value in sp.
  400. *
  401. * @param key The key of sp.
  402. * @param defaultValue The default value if the sp doesn't exist.
  403. * @param spUtils The instance of {@link SPUtils}.
  404. * @return the int value if sp exists or {@code defaultValue} otherwise
  405. */
  406. public static int getInt(@NonNull final String key, final int defaultValue, @NonNull final SPUtils spUtils) {
  407. return spUtils.getInt(key, defaultValue);
  408. }
  409. /**
  410. * Put the long value in sp.
  411. *
  412. * @param key The key of sp.
  413. * @param value The value of sp.
  414. * @param spUtils The instance of {@link SPUtils}.
  415. */
  416. public static void put(@NonNull final String key, final long value, @NonNull final SPUtils spUtils) {
  417. spUtils.put(key, value);
  418. }
  419. /**
  420. * Put the long value in sp.
  421. *
  422. * @param key The key of sp.
  423. * @param value The value of sp.
  424. * @param isCommit True to use {@link SharedPreferences.Editor#commit()},
  425. * false to use {@link SharedPreferences.Editor#apply()}
  426. * @param spUtils The instance of {@link SPUtils}.
  427. */
  428. public static void put(@NonNull final String key,
  429. final long value,
  430. final boolean isCommit,
  431. @NonNull final SPUtils spUtils) {
  432. spUtils.put(key, value, isCommit);
  433. }
  434. /**
  435. * Return the long value in sp.
  436. *
  437. * @param key The key of sp.
  438. * @param spUtils The instance of {@link SPUtils}.
  439. * @return the long value if sp exists or {@code -1} otherwise
  440. */
  441. public static long getLong(@NonNull final String key, @NonNull final SPUtils spUtils) {
  442. return spUtils.getLong(key);
  443. }
  444. /**
  445. * Return the long value in sp.
  446. *
  447. * @param key The key of sp.
  448. * @param defaultValue The default value if the sp doesn't exist.
  449. * @param spUtils The instance of {@link SPUtils}.
  450. * @return the long value if sp exists or {@code defaultValue} otherwise
  451. */
  452. public static long getLong(@NonNull final String key, final long defaultValue, @NonNull final SPUtils spUtils) {
  453. return spUtils.getLong(key, defaultValue);
  454. }
  455. /**
  456. * Put the float value in sp.
  457. *
  458. * @param key The key of sp.
  459. * @param value The value of sp.
  460. * @param spUtils The instance of {@link SPUtils}.
  461. */
  462. public static void put(@NonNull final String key, final float value, @NonNull final SPUtils spUtils) {
  463. spUtils.put(key, value);
  464. }
  465. /**
  466. * Put the float value in sp.
  467. *
  468. * @param key The key of sp.
  469. * @param value The value of sp.
  470. * @param isCommit True to use {@link SharedPreferences.Editor#commit()},
  471. * false to use {@link SharedPreferences.Editor#apply()}
  472. * @param spUtils The instance of {@link SPUtils}.
  473. */
  474. public static void put(@NonNull final String key,
  475. final float value,
  476. final boolean isCommit,
  477. @NonNull final SPUtils spUtils) {
  478. spUtils.put(key, value, isCommit);
  479. }
  480. /**
  481. * Return the float value in sp.
  482. *
  483. * @param key The key of sp.
  484. * @param spUtils The instance of {@link SPUtils}.
  485. * @return the float value if sp exists or {@code -1f} otherwise
  486. */
  487. public static float getFloat(@NonNull final String key, @NonNull final SPUtils spUtils) {
  488. return spUtils.getFloat(key);
  489. }
  490. /**
  491. * Return the float value in sp.
  492. *
  493. * @param key The key of sp.
  494. * @param defaultValue The default value if the sp doesn't exist.
  495. * @param spUtils The instance of {@link SPUtils}.
  496. * @return the float value if sp exists or {@code defaultValue} otherwise
  497. */
  498. public static float getFloat(@NonNull final String key, final float defaultValue, @NonNull final SPUtils spUtils) {
  499. return spUtils.getFloat(key, defaultValue);
  500. }
  501. /**
  502. * Put the boolean value in sp.
  503. *
  504. * @param key The key of sp.
  505. * @param value The value of sp.
  506. * @param spUtils The instance of {@link SPUtils}.
  507. */
  508. public static void put(@NonNull final String key, final boolean value, @NonNull final SPUtils spUtils) {
  509. spUtils.put(key, value);
  510. }
  511. /**
  512. * Put the boolean value in sp.
  513. *
  514. * @param key The key of sp.
  515. * @param value The value of sp.
  516. * @param isCommit True to use {@link SharedPreferences.Editor#commit()},
  517. * false to use {@link SharedPreferences.Editor#apply()}
  518. * @param spUtils The instance of {@link SPUtils}.
  519. */
  520. public static void put(@NonNull final String key,
  521. final boolean value,
  522. final boolean isCommit,
  523. @NonNull final SPUtils spUtils) {
  524. spUtils.put(key, value, isCommit);
  525. }
  526. /**
  527. * Return the boolean value in sp.
  528. *
  529. * @param key The key of sp.
  530. * @param spUtils The instance of {@link SPUtils}.
  531. * @return the boolean value if sp exists or {@code false} otherwise
  532. */
  533. public static boolean getBoolean(@NonNull final String key, @NonNull final SPUtils spUtils) {
  534. return spUtils.getBoolean(key);
  535. }
  536. /**
  537. * Return the boolean value in sp.
  538. *
  539. * @param key The key of sp.
  540. * @param defaultValue The default value if the sp doesn't exist.
  541. * @param spUtils The instance of {@link SPUtils}.
  542. * @return the boolean value if sp exists or {@code defaultValue} otherwise
  543. */
  544. public static boolean getBoolean(@NonNull final String key,
  545. final boolean defaultValue,
  546. @NonNull final SPUtils spUtils) {
  547. return spUtils.getBoolean(key, defaultValue);
  548. }
  549. /**
  550. * Put the set of string value in sp.
  551. *
  552. * @param key The key of sp.
  553. * @param value The value of sp.
  554. * @param spUtils The instance of {@link SPUtils}.
  555. */
  556. public static void put(@NonNull final String key, final Set<String> value, @NonNull final SPUtils spUtils) {
  557. spUtils.put(key, value);
  558. }
  559. /**
  560. * Put the set of string value in sp.
  561. *
  562. * @param key The key of sp.
  563. * @param value The value of sp.
  564. * @param isCommit True to use {@link SharedPreferences.Editor#commit()},
  565. * false to use {@link SharedPreferences.Editor#apply()}
  566. * @param spUtils The instance of {@link SPUtils}.
  567. */
  568. public static void put(@NonNull final String key,
  569. final Set<String> value,
  570. final boolean isCommit,
  571. @NonNull final SPUtils spUtils) {
  572. spUtils.put(key, value, isCommit);
  573. }
  574. /**
  575. * Return the set of string value in sp.
  576. *
  577. * @param key The key of sp.
  578. * @param spUtils The instance of {@link SPUtils}.
  579. * @return the set of string value if sp exists
  580. * or {@code Collections.<String>emptySet()} otherwise
  581. */
  582. public static Set<String> getStringSet(@NonNull final String key, @NonNull final SPUtils spUtils) {
  583. return spUtils.getStringSet(key);
  584. }
  585. /**
  586. * Return the set of string value in sp.
  587. *
  588. * @param key The key of sp.
  589. * @param defaultValue The default value if the sp doesn't exist.
  590. * @param spUtils The instance of {@link SPUtils}.
  591. * @return the set of string value if sp exists or {@code defaultValue} otherwise
  592. */
  593. public static Set<String> getStringSet(@NonNull final String key,
  594. final Set<String> defaultValue,
  595. @NonNull final SPUtils spUtils) {
  596. return spUtils.getStringSet(key, defaultValue);
  597. }
  598. /**
  599. * Return all values in sp.
  600. *
  601. * @param spUtils The instance of {@link SPUtils}.
  602. * @return all values in sp
  603. */
  604. public static Map<String, ?> getAll(@NonNull final SPUtils spUtils) {
  605. return spUtils.getAll();
  606. }
  607. /**
  608. * Return whether the sp contains the preference.
  609. *
  610. * @param key The key of sp.
  611. * @param spUtils The instance of {@link SPUtils}.
  612. * @return {@code true}: yes<br>{@code false}: no
  613. */
  614. public static boolean contains(@NonNull final String key, @NonNull final SPUtils spUtils) {
  615. return spUtils.contains(key);
  616. }
  617. /**
  618. * Remove the preference in sp.
  619. *
  620. * @param key The key of sp.
  621. * @param spUtils The instance of {@link SPUtils}.
  622. */
  623. public static void remove(@NonNull final String key, @NonNull final SPUtils spUtils) {
  624. spUtils.remove(key);
  625. }
  626. /**
  627. * Remove the preference in sp.
  628. *
  629. * @param key The key of sp.
  630. * @param isCommit True to use {@link SharedPreferences.Editor#commit()},
  631. * false to use {@link SharedPreferences.Editor#apply()}
  632. * @param spUtils The instance of {@link SPUtils}.
  633. */
  634. public static void remove(@NonNull final String key, final boolean isCommit, @NonNull final SPUtils spUtils) {
  635. spUtils.remove(key, isCommit);
  636. }
  637. /**
  638. * Remove all preferences in sp.
  639. *
  640. * @param spUtils The instance of {@link SPUtils}.
  641. */
  642. public static void clear(@NonNull final SPUtils spUtils) {
  643. spUtils.clear();
  644. }
  645. /**
  646. * Remove all preferences in sp.
  647. *
  648. * @param isCommit True to use {@link SharedPreferences.Editor#commit()},
  649. * false to use {@link SharedPreferences.Editor#apply()}
  650. * @param spUtils The instance of {@link SPUtils}.
  651. */
  652. public static void clear(final boolean isCommit, @NonNull final SPUtils spUtils) {
  653. spUtils.clear(isCommit);
  654. }
  655. private static SPUtils getDefaultSPUtils() {
  656. return sDefaultSPUtils != null ? sDefaultSPUtils : SPUtils.getInstance();
  657. }
  658. }