Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
mmm-rain
AndroidUtilCode
提交
358cfa77
A
AndroidUtilCode
项目概览
mmm-rain
/
AndroidUtilCode
与 Fork 源项目一致
从无法访问的项目Fork
通知
4
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
AndroidUtilCode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
358cfa77
编写于
1月 04, 2019
作者:
B
Blankj
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
see 01/04 log
上级
fe70516b
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
478 addition
and
93 deletion
+478
-93
utilcode/README-CN.md
utilcode/README-CN.md
+10
-0
utilcode/lib/src/main/java/com/blankj/utilcode/util/AntiShakeUtils.java
...rc/main/java/com/blankj/utilcode/util/AntiShakeUtils.java
+1
-1
utilcode/lib/src/main/java/com/blankj/utilcode/util/CacheDiskUtils.java
...rc/main/java/com/blankj/utilcode/util/CacheDiskUtils.java
+6
-0
utilcode/lib/src/main/java/com/blankj/utilcode/util/ImageUtils.java
...ib/src/main/java/com/blankj/utilcode/util/ImageUtils.java
+12
-5
utilcode/lib/src/main/java/com/blankj/utilcode/util/JsonUtils.java
...lib/src/main/java/com/blankj/utilcode/util/JsonUtils.java
+79
-0
utilcode/lib/src/main/java/com/blankj/utilcode/util/LogUtils.java
.../lib/src/main/java/com/blankj/utilcode/util/LogUtils.java
+5
-1
utilcode/lib/src/main/java/com/blankj/utilcode/util/SPUtils.java
...e/lib/src/main/java/com/blankj/utilcode/util/SPUtils.java
+324
-0
utilcode/lib/src/test/java/com/blankj/utilcode/util/LogUtilsTest.java
.../src/test/java/com/blankj/utilcode/util/LogUtilsTest.java
+19
-3
utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/data/DataManager.java
...c/main/java/com/blankj/utilcode/pkg/data/DataManager.java
+0
-75
utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/sp/SPActivity.java
...n/java/com/blankj/utilcode/pkg/feature/sp/SPActivity.java
+22
-8
未找到文件。
utilcode/README-CN.md
浏览文件 @
358cfa77
...
...
@@ -702,6 +702,16 @@ create : 创建样式字符串
*
### SP 相关 ->
[
SPUtils.java
][
sp.java
]
->
[
Demo
][
sp.demo
]
```
putStatic : SP 中写入数据
getStringStatic : SP 中读取 String
getIntStatic : SP 中读取 int
getLongStatic : SP 中读取 long
getFloatStatic : SP 中读取 float
getBooleanStatic : SP 中读取 boolean
getAllStatic : SP 中获取所有键值对
containsStatic : SP 中是否存在该 key
removeStatic : SP 中移除该 key
clearStatic : SP 中清除所有数据
getInstance : 获取 SP 实例
Instance.put : SP 中写入数据
Instance.getString : SP 中读取 String
...
...
utilcode/lib/src/main/java/com/blankj/utilcode/util/AntiShakeUtils.java
浏览文件 @
358cfa77
...
...
@@ -12,7 +12,7 @@ import android.view.View;
* desc : utils about anti shake
* </pre>
*/
public
class
AntiShakeUtils
{
public
final
class
AntiShakeUtils
{
private
static
final
long
DEFAULT_DURATION
=
200
;
private
static
final
int
TAG_KEY
=
0x7EFFFFFF
;
...
...
utilcode/lib/src/main/java/com/blankj/utilcode/util/CacheDiskUtils.java
浏览文件 @
358cfa77
...
...
@@ -1070,4 +1070,10 @@ public final class CacheDiskUtils implements CacheConstants {
}
return
true
;
}
///////////////////////////////////////////////////////////////////////////
// static
///////////////////////////////////////////////////////////////////////////
}
\ No newline at end of file
utilcode/lib/src/main/java/com/blankj/utilcode/util/ImageUtils.java
浏览文件 @
358cfa77
...
...
@@ -1533,7 +1533,10 @@ public final class ImageUtils {
* @return {@code true}: yes<br>{@code false}: no
*/
public
static
boolean
isImage
(
final
File
file
)
{
return
file
!=
null
&&
isImage
(
file
.
getPath
());
if
(
file
==
null
||
!
file
.
exists
())
{
return
false
;
}
return
isImage
(
file
.
getPath
());
}
/**
...
...
@@ -1543,10 +1546,14 @@ public final class ImageUtils {
* @return {@code true}: yes<br>{@code false}: no
*/
public
static
boolean
isImage
(
final
String
filePath
)
{
String
path
=
filePath
.
toUpperCase
();
return
path
.
endsWith
(
".PNG"
)
||
path
.
endsWith
(
".JPG"
)
||
path
.
endsWith
(
".JPEG"
)
||
path
.
endsWith
(
".BMP"
)
||
path
.
endsWith
(
".GIF"
)
||
path
.
endsWith
(
".WEBP"
);
BitmapFactory
.
Options
options
=
new
BitmapFactory
.
Options
();
options
.
inJustDecodeBounds
=
true
;
try
{
Bitmap
bitmap
=
BitmapFactory
.
decodeFile
(
filePath
,
options
);
return
options
.
outWidth
!=
-
1
&&
options
.
outHeight
!=
-
1
;
}
catch
(
Exception
e
)
{
return
false
;
}
}
/**
...
...
utilcode/lib/src/main/java/com/blankj/utilcode/util/JsonUtils.java
0 → 100644
浏览文件 @
358cfa77
//package com.blankj.utilcode.util;
//
//
//import org.json.JSONException;
//import org.json.JSONObject;
//
//public final class JsonUtils {
//
// private static byte TYPE_LONG = 0x01;
// private static byte TYPE_INT = 0x02;
//
// private JsonUtils() {
// throw new UnsupportedOperationException("u can't instantiate me...");
// }
//
// public static long getLong(final JSONObject jsonObject,
// final String key,
// final long defaultValue) {
// if (jsonObject == null || key == null || key.length() == 0) {
// return defaultValue;
// }
// try {
// return jsonObject.getLong(key);
// } catch (JSONException e) {
// return defaultValue;
// }
// }
//
// public static long getLong(final String json,
// final String key,
// final long defaultValue) {
// if (json == null || json.length() == 0
// || key == null || key.length() == 0) {
// return defaultValue;
// }
//
// try {
// return getLong(new JSONObject(json), key, defaultValue);
// } catch (JSONException e) {
// e.printStackTrace();
// return defaultValue;
// }
// }
//
// public static Object getType(final JSONObject jsonObject,
// final String key,
// final Object defaultValue,
// final byte type) {
// if (jsonObject == null || key == null || key.length() == 0) {
// return defaultValue;
// }
// try {
// if (type == TYPE_LONG) {
// return jsonObject.getLong(key);
// } else if (type == TYPE_INT) {
// return jsonObject.getInt(key);
// }
// } catch (JSONException e) {
// return defaultValue;
// }
// }
//
// public static long getLong(final String json,
// final String key,
// final long defaultValue) {
// if (json == null || json.length() == 0
// || key == null || key.length() == 0) {
// return defaultValue;
// }
//
// try {
// return getLong(new JSONObject(json), key, defaultValue);
// } catch (JSONException e) {
// e.printStackTrace();
// return defaultValue;
// }
// }
//
//}
utilcode/lib/src/main/java/com/blankj/utilcode/util/LogUtils.java
浏览文件 @
358cfa77
...
...
@@ -797,7 +797,11 @@ public final class LogUtils {
if
(
object
instanceof
CharSequence
)
{
return
formatJson
(
object
.
toString
());
}
return
GSON
.
toJson
(
object
);
try
{
return
GSON
.
toJson
(
object
);
}
catch
(
Throwable
t
)
{
return
object
.
toString
();
}
}
static
String
formatXml
(
String
xml
)
{
...
...
utilcode/lib/src/main/java/com/blankj/utilcode/util/SPUtils.java
浏览文件 @
358cfa77
...
...
@@ -442,4 +442,328 @@ public final class SPUtils {
}
return
true
;
}
///////////////////////////////////////////////////////////////////////////
// static
///////////////////////////////////////////////////////////////////////////
/**
* Put the string value in sp.
*
* @param key The key of sp.
* @param value The value of sp.
*/
public
static
void
putStatic
(
@NonNull
final
String
key
,
final
String
value
)
{
SPUtils
.
getInstance
().
put
(
key
,
value
);
}
/**
* Put the string value in sp.
*
* @param key The key of sp.
* @param value The value of sp.
* @param isCommit True to use {@link SharedPreferences.Editor#commit()},
* false to use {@link SharedPreferences.Editor#apply()}
*/
public
static
void
putStatic
(
@NonNull
final
String
key
,
final
String
value
,
final
boolean
isCommit
)
{
SPUtils
.
getInstance
().
put
(
key
,
value
,
isCommit
);
}
/**
* Return the string value in sp.
*
* @param key The key of sp.
* @return the string value if sp exists or {@code ""} otherwise
*/
public
static
String
getStringStatic
(
@NonNull
final
String
key
)
{
return
SPUtils
.
getInstance
().
getString
(
key
);
}
/**
* Return the string value in sp.
*
* @param key The key of sp.
* @param defaultValue The default value if the sp doesn't exist.
* @return the string value if sp exists or {@code defaultValue} otherwise
*/
public
static
String
getStringStatic
(
@NonNull
final
String
key
,
final
String
defaultValue
)
{
return
SPUtils
.
getInstance
().
getString
(
key
,
defaultValue
);
}
/**
* Put the int value in sp.
*
* @param key The key of sp.
* @param value The value of sp.
*/
public
static
void
putStatic
(
@NonNull
final
String
key
,
final
int
value
)
{
SPUtils
.
getInstance
().
put
(
key
,
value
);
}
/**
* Put the int value in sp.
*
* @param key The key of sp.
* @param value The value of sp.
* @param isCommit True to use {@link SharedPreferences.Editor#commit()},
* false to use {@link SharedPreferences.Editor#apply()}
*/
public
static
void
putStatic
(
@NonNull
final
String
key
,
final
int
value
,
final
boolean
isCommit
)
{
SPUtils
.
getInstance
().
put
(
key
,
value
,
isCommit
);
}
/**
* Return the int value in sp.
*
* @param key The key of sp.
* @return the int value if sp exists or {@code -1} otherwise
*/
public
static
int
getIntStatic
(
@NonNull
final
String
key
)
{
return
SPUtils
.
getInstance
().
getInt
(
key
);
}
/**
* Return the int value in sp.
*
* @param key The key of sp.
* @param defaultValue The default value if the sp doesn't exist.
* @return the int value if sp exists or {@code defaultValue} otherwise
*/
public
static
int
getIntStatic
(
@NonNull
final
String
key
,
final
int
defaultValue
)
{
return
SPUtils
.
getInstance
().
getInt
(
key
,
defaultValue
);
}
/**
* Put the long value in sp.
*
* @param key The key of sp.
* @param value The value of sp.
*/
public
static
void
putStatic
(
@NonNull
final
String
key
,
final
long
value
)
{
SPUtils
.
getInstance
().
put
(
key
,
value
);
}
/**
* Put the long value in sp.
*
* @param key The key of sp.
* @param value The value of sp.
* @param isCommit True to use {@link SharedPreferences.Editor#commit()},
* false to use {@link SharedPreferences.Editor#apply()}
*/
public
static
void
putStatic
(
@NonNull
final
String
key
,
final
long
value
,
final
boolean
isCommit
)
{
SPUtils
.
getInstance
().
put
(
key
,
value
,
isCommit
);
}
/**
* Return the long value in sp.
*
* @param key The key of sp.
* @return the long value if sp exists or {@code -1} otherwise
*/
public
static
long
getLongStatic
(
@NonNull
final
String
key
)
{
return
SPUtils
.
getInstance
().
getLong
(
key
);
}
/**
* Return the long value in sp.
*
* @param key The key of sp.
* @param defaultValue The default value if the sp doesn't exist.
* @return the long value if sp exists or {@code defaultValue} otherwise
*/
public
static
long
getLongStatic
(
@NonNull
final
String
key
,
final
long
defaultValue
)
{
return
SPUtils
.
getInstance
().
getLong
(
key
,
defaultValue
);
}
/**
* Put the float value in sp.
*
* @param key The key of sp.
* @param value The value of sp.
*/
public
static
void
putStatic
(
@NonNull
final
String
key
,
final
float
value
)
{
SPUtils
.
getInstance
().
put
(
key
,
value
);
}
/**
* Put the float value in sp.
*
* @param key The key of sp.
* @param value The value of sp.
* @param isCommit True to use {@link SharedPreferences.Editor#commit()},
* false to use {@link SharedPreferences.Editor#apply()}
*/
public
static
void
putStatic
(
@NonNull
final
String
key
,
final
float
value
,
final
boolean
isCommit
)
{
SPUtils
.
getInstance
().
put
(
key
,
value
,
isCommit
);
}
/**
* Return the float value in sp.
*
* @param key The key of sp.
* @return the float value if sp exists or {@code -1f} otherwise
*/
public
static
float
getFloatStatic
(
@NonNull
final
String
key
)
{
return
SPUtils
.
getInstance
().
getFloat
(
key
);
}
/**
* Return the float value in sp.
*
* @param key The key of sp.
* @param defaultValue The default value if the sp doesn't exist.
* @return the float value if sp exists or {@code defaultValue} otherwise
*/
public
static
float
getFloatStatic
(
@NonNull
final
String
key
,
final
float
defaultValue
)
{
return
SPUtils
.
getInstance
().
getFloat
(
key
,
defaultValue
);
}
/**
* Put the boolean value in sp.
*
* @param key The key of sp.
* @param value The value of sp.
*/
public
static
void
putStatic
(
@NonNull
final
String
key
,
final
boolean
value
)
{
SPUtils
.
getInstance
().
put
(
key
,
value
);
}
/**
* Put the boolean value in sp.
*
* @param key The key of sp.
* @param value The value of sp.
* @param isCommit True to use {@link SharedPreferences.Editor#commit()},
* false to use {@link SharedPreferences.Editor#apply()}
*/
public
static
void
putStatic
(
@NonNull
final
String
key
,
final
boolean
value
,
final
boolean
isCommit
)
{
SPUtils
.
getInstance
().
put
(
key
,
value
,
isCommit
);
}
/**
* Return the boolean value in sp.
*
* @param key The key of sp.
* @return the boolean value if sp exists or {@code false} otherwise
*/
public
static
boolean
getBooleanStatic
(
@NonNull
final
String
key
)
{
return
SPUtils
.
getInstance
().
getBoolean
(
key
);
}
/**
* Return the boolean value in sp.
*
* @param key The key of sp.
* @param defaultValue The default value if the sp doesn't exist.
* @return the boolean value if sp exists or {@code defaultValue} otherwise
*/
public
static
boolean
getBooleanStatic
(
@NonNull
final
String
key
,
final
boolean
defaultValue
)
{
return
SPUtils
.
getInstance
().
getBoolean
(
key
,
defaultValue
);
}
/**
* Put the set of string value in sp.
*
* @param key The key of sp.
* @param value The value of sp.
*/
public
static
void
putStatic
(
@NonNull
final
String
key
,
final
Set
<
String
>
value
)
{
SPUtils
.
getInstance
().
put
(
key
,
value
);
}
/**
* Put the set of string value in sp.
*
* @param key The key of sp.
* @param value The value of sp.
* @param isCommit True to use {@link SharedPreferences.Editor#commit()},
* false to use {@link SharedPreferences.Editor#apply()}
*/
public
static
void
putStatic
(
@NonNull
final
String
key
,
final
Set
<
String
>
value
,
final
boolean
isCommit
)
{
SPUtils
.
getInstance
().
put
(
key
,
value
,
isCommit
);
}
/**
* Return the set of string value in sp.
*
* @param key The key of sp.
* @return the set of string value if sp exists
* or {@code Collections.<String>emptySet()} otherwise
*/
public
static
Set
<
String
>
getStringSetStatic
(
@NonNull
final
String
key
)
{
return
SPUtils
.
getInstance
().
getStringSet
(
key
);
}
/**
* Return the set of string value in sp.
*
* @param key The key of sp.
* @param defaultValue The default value if the sp doesn't exist.
* @return the set of string value if sp exists or {@code defaultValue} otherwise
*/
public
static
Set
<
String
>
getStringSetStatic
(
@NonNull
final
String
key
,
final
Set
<
String
>
defaultValue
)
{
return
SPUtils
.
getInstance
().
getStringSet
(
key
,
defaultValue
);
}
/**
* Return all values in sp.
*
* @return all values in sp
*/
public
static
Map
<
String
,
?>
getAllStatic
()
{
return
SPUtils
.
getInstance
().
getAll
();
}
/**
* Return whether the sp contains the preference.
*
* @param key The key of sp.
* @return {@code true}: yes<br>{@code false}: no
*/
public
static
boolean
containsStatic
(
@NonNull
final
String
key
)
{
return
SPUtils
.
getInstance
().
contains
(
key
);
}
/**
* Remove the preference in sp.
*
* @param key The key of sp.
*/
public
static
void
removeStatic
(
@NonNull
final
String
key
)
{
SPUtils
.
getInstance
().
remove
(
key
);
}
/**
* Remove the preference in sp.
*
* @param key The key of sp.
* @param isCommit True to use {@link SharedPreferences.Editor#commit()},
* false to use {@link SharedPreferences.Editor#apply()}
*/
public
static
void
removeStatic
(
@NonNull
final
String
key
,
final
boolean
isCommit
)
{
SPUtils
.
getInstance
().
remove
(
key
,
isCommit
);
}
/**
* Remove all preferences in sp.
*/
public
static
void
clearStatic
()
{
SPUtils
.
getInstance
().
clear
();
}
/**
* Remove all preferences in sp.
*
* @param isCommit True to use {@link SharedPreferences.Editor#commit()},
* false to use {@link SharedPreferences.Editor#apply()}
*/
public
static
void
clearStatic
(
final
boolean
isCommit
)
{
SPUtils
.
getInstance
().
clear
(
isCommit
);
}
}
utilcode/lib/src/test/java/com/blankj/utilcode/util/LogUtilsTest.java
浏览文件 @
358cfa77
package
com.blankj.utilcode.util
;
import
android.app.Application
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
...
...
@@ -7,6 +9,7 @@ import org.junit.Test;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.HashMap
;
import
java.util.Map
;
...
...
@@ -24,7 +27,7 @@ public class LogUtilsTest extends BaseTest {
private
static
final
String
XML
=
"<books><book><author>Jack Herrington</author><title>PHP Hacks</title><publisher>O'Reilly</publisher></book><book><author>Jack Herrington</author><title>Podcasting Hacks</title><publisher>O'Reilly</publisher></book></books>"
;
private
static
final
int
[]
ONE_D_ARRAY
=
new
int
[]{
1
,
2
,
3
};
private
static
final
int
[][]
TWO_D_ARRAY
=
new
int
[][]{{
1
,
2
,
3
},
{
4
,
5
,
6
},
{
7
,
8
,
9
}};
private
static
final
ArrayList
<
String
>
LIST
=
new
ArrayList
<>();
private
static
final
ArrayList
<
Object
>
LIST
=
new
ArrayList
<>();
private
static
final
Map
<
String
,
String
>
MAP
=
new
HashMap
<>();
@Test
...
...
@@ -163,17 +166,30 @@ public class LogUtilsTest extends BaseTest {
LIST
.
add
(
"hello"
);
LIST
.
add
(
"log"
);
LIST
.
add
(
"utils"
);
LIST
.
add
(
new
Application
());
MAP
.
put
(
"name"
,
"AndroidUtilCode"
);
MAP
.
put
(
"class"
,
"LogUtils"
);
LogUtils
.
d
((
Object
)
ONE_D_ARRAY
);
LogUtils
.
d
((
Object
)
TWO_D_ARRAY
);
LogUtils
.
d
(
LIST
);
LogUtils
.
d
(
formatJson
(
collection2String
(
LIST
))
);
LogUtils
.
d
(
MAP
);
LogUtils
.
d
(
formatJson
(
array2String
(
TWO_D_ARRAY
)));
LogUtils
.
d
(
array2String
(
TWO_D_ARRAY
));
}
static
String
collection2String
(
Collection
collection
)
{
JSONObject
jsonObject
=
new
JSONObject
();
try
{
jsonObject
.
put
(
"size"
,
collection
.
size
());
jsonObject
.
put
(
"data"
,
collection
);
return
jsonObject
.
toString
();
}
catch
(
JSONException
ignore
)
{
return
collection
.
toString
();
}
}
private
static
String
formatJson
(
String
json
)
{
try
{
if
(
json
.
startsWith
(
"{"
))
{
...
...
utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/data/DataManager.java
已删除
100644 → 0
浏览文件 @
fe70516b
package
com.blankj.utilcode.pkg.data
;
import
com.blankj.utilcode.util.SPUtils
;
import
java.util.Map
;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2018/01/08
* desc : manager about data
* </pre>
*/
public
class
DataManager
{
private
static
final
SPUtils
SP_UTILS
=
SPUtils
.
getInstance
(
"demo"
);
public
static
void
putString
()
{
SP_UTILS
.
put
(
"STRING"
,
"string"
);
}
public
static
String
getString
()
{
return
SP_UTILS
.
getString
(
"STRING"
);
}
public
static
void
putInt
()
{
SP_UTILS
.
put
(
"INT"
,
21
);
}
public
static
String
getInt
()
{
return
String
.
valueOf
(
SP_UTILS
.
getInt
(
"INT"
));
}
public
static
void
putLong
()
{
SP_UTILS
.
put
(
"LONG"
,
Long
.
MAX_VALUE
);
}
public
static
String
getLong
()
{
return
String
.
valueOf
(
SP_UTILS
.
getLong
(
"LONG"
));
}
public
static
void
putFloat
()
{
SP_UTILS
.
put
(
"FLOAT"
,
(
float
)
Math
.
PI
);
}
public
static
String
getFloat
()
{
return
String
.
valueOf
(
SP_UTILS
.
getFloat
(
"FLOAT"
));
}
public
static
void
putBoolean
()
{
SP_UTILS
.
put
(
"BOOLEAN"
,
true
);
}
public
static
String
getBoolean
()
{
return
String
.
valueOf
(
SP_UTILS
.
getBoolean
(
"BOOLEAN"
));
}
public
static
void
clear
()
{
SP_UTILS
.
clear
();
}
public
static
String
sp2String
()
{
StringBuilder
sb
=
new
StringBuilder
();
Map
<
String
,
?>
map
=
SP_UTILS
.
getAll
();
for
(
Map
.
Entry
<
String
,
?>
entry
:
map
.
entrySet
())
{
sb
.
append
(
entry
.
getKey
())
.
append
(
": "
)
.
append
(
entry
.
getValue
())
.
append
(
"\n"
);
}
return
sb
.
toString
();
}
}
utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/sp/SPActivity.java
浏览文件 @
358cfa77
...
...
@@ -10,7 +10,9 @@ import android.widget.TextView;
import
com.blankj.lib.base.BaseBackActivity
;
import
com.blankj.utilcode.pkg.R
;
import
com.blankj.utilcode.pkg.data.DataManager
;
import
com.blankj.utilcode.util.SPUtils
;
import
java.util.Map
;
/**
* <pre>
...
...
@@ -59,28 +61,40 @@ public class SPActivity extends BaseBackActivity {
public
void
onWidgetClick
(
@NonNull
View
view
)
{
int
i
=
view
.
getId
();
if
(
i
==
R
.
id
.
btn_sp_put_string
)
{
DataManager
.
putString
(
);
SPUtils
.
putStatic
(
"STRING"
,
"string"
);
}
else
if
(
i
==
R
.
id
.
btn_sp_put_int
)
{
DataManager
.
putInt
(
);
SPUtils
.
putStatic
(
"INT"
,
21
);
}
else
if
(
i
==
R
.
id
.
btn_sp_put_long
)
{
DataManager
.
putLong
(
);
SPUtils
.
putStatic
(
"LONG"
,
Long
.
MAX_VALUE
);
}
else
if
(
i
==
R
.
id
.
btn_sp_put_float
)
{
DataManager
.
putFloat
(
);
SPUtils
.
putStatic
(
"FLOAT"
,
(
float
)
Math
.
PI
);
}
else
if
(
i
==
R
.
id
.
btn_sp_put_boolean
)
{
DataManager
.
putBoolean
(
);
SPUtils
.
putStatic
(
"BOOLEAN"
,
true
);
}
else
if
(
i
==
R
.
id
.
btn_sp_clear
)
{
DataManager
.
clear
();
SPUtils
.
clearStatic
();
}
updateAboutSp
();
}
private
void
updateAboutSp
()
{
tvAboutSp
.
setText
(
DataManager
.
sp2String
());
tvAboutSp
.
setText
(
sp2String
());
}
public
static
String
sp2String
()
{
StringBuilder
sb
=
new
StringBuilder
();
Map
<
String
,
?>
map
=
SPUtils
.
getAllStatic
();
for
(
Map
.
Entry
<
String
,
?>
entry
:
map
.
entrySet
())
{
sb
.
append
(
entry
.
getKey
())
.
append
(
": "
)
.
append
(
entry
.
getValue
())
.
append
(
"\n"
);
}
return
sb
.
toString
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录