Skip to content

Commit 20fa867

Browse files
committed
See 11/12 log
1 parent 380ccc2 commit 20fa867

File tree

1 file changed

+27
-37
lines changed

1 file changed

+27
-37
lines changed

utilcode/src/main/java/com/blankj/utilcode/util/StringUtils.java

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.blankj.utilcode.util;
22

33
import android.content.res.Resources;
4+
import android.support.annotation.ArrayRes;
5+
import android.support.annotation.StringRes;
46

57
/**
68
* <pre>
@@ -194,57 +196,45 @@ public static String toSBC(final String s) {
194196
}
195197

196198
/**
197-
* Return the string value associated with a particular resource ID. It
198-
* will be stripped of any styled text information.
199-
* {@more}
199+
* Return the string value associated with a particular resource ID.
200200
*
201-
* @param id The desired resource identifier, as generated by the aapt
202-
* tool. This integer encodes the package, type, and resource
203-
* entry. The value 0 is an invalid identifier.
204-
*
205-
* @throws Resources.NotFoundException Throws NotFoundException if the given ID does not exist.
206-
*
207-
* @return String The string data associated with the resource,
208-
* stripped of styled text information.
201+
* @param id The desired resource identifier.
202+
* @return the string value associated with a particular resource ID.
209203
*/
210-
public static String getString(int id) {
211-
return Utils.getApp().getResources().getString(id);
204+
public static String getString(@StringRes int id) {
205+
try {
206+
return Utils.getApp().getResources().getString(id);
207+
} catch (Resources.NotFoundException ignore) {
208+
return "";
209+
}
212210
}
213211

214212
/**
215-
* Return the string value associated with a particular resource ID,
216-
* substituting the format arguments as defined in {@link java.util.Formatter}
217-
* and {@link java.lang.String#format}. It will be stripped of any styled text
218-
* information.
219-
* {@more}
220-
*
221-
* @param id The desired resource identifier, as generated by the aapt
222-
* tool. This integer encodes the package, type, and resource
223-
* entry. The value 0 is an invalid identifier.
213+
* Return the string value associated with a particular resource ID.
224214
*
215+
* @param id The desired resource identifier.
225216
* @param formatArgs The format arguments that will be used for substitution.
226-
*
227-
* @throws Resources.NotFoundException Throws NotFoundException if the given ID does not exist.
228-
*
229-
* @return String The string data associated with the resource,
230-
* stripped of styled text information.
217+
* @return the string value associated with a particular resource ID.
231218
*/
232-
public static String getString(int id, Object... formatArgs) {
233-
return Utils.getApp().getString(id, formatArgs);
219+
public static String getString(@StringRes int id, Object... formatArgs) {
220+
try {
221+
return Utils.getApp().getString(id, formatArgs);
222+
} catch (Resources.NotFoundException ignore) {
223+
return "";
224+
}
234225
}
235226

236227
/**
237228
* Return the string array associated with a particular resource ID.
238229
*
239-
* @param id The desired resource identifier, as generated by the aapt
240-
* tool. This integer encodes the package, type, and resource
241-
* entry. The value 0 is an invalid identifier.
242-
*
243-
* @throws Resources.NotFoundException Throws NotFoundException if the given ID does not exist.
244-
*
230+
* @param id The desired resource identifier.
245231
* @return The string array associated with the resource.
246232
*/
247-
public static String[] getStringArray(int id){
248-
return Utils.getApp().getResources().getStringArray(id);
233+
public static String[] getStringArray(@ArrayRes int id) {
234+
try {
235+
return Utils.getApp().getResources().getStringArray(id);
236+
} catch (Resources.NotFoundException ignore) {
237+
return new String[0];
238+
}
249239
}
250240
}

0 commit comments

Comments
 (0)