Java Code Examples for com.hippo.yorozuya.NumberUtils#parseIntSafely()

The following examples show how to use com.hippo.yorozuya.NumberUtils#parseIntSafely() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GalleryPageUrlParser.java    From MHViewer with Apache License 2.0 6 votes vote down vote up
@Nullable
public static Result parse(String url, boolean strict) {
    if (url == null) {
        return null;
    }

    Pattern pattern = strict ? URL_STRICT_PATTERN : URL_PATTERN;
    Matcher m = pattern.matcher(url);
    if (m.find()) {
        Result result = new Result();
        result.gid = NumberUtils.parseLongSafely(m.group(2), -1L);
        result.pToken = m.group(1);
        result.page = NumberUtils.parseIntSafely(m.group(3), 0) - 1;
        if (result.gid < 0 || result.page < 0) {
            return null;
        }
        return result;
    } else {
        return null;
    }
}
 
Example 2
Source File: SettingsActivity.java    From Nimingban with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
    String key = preference.getKey();
    if (Settings.KEY_CHAOS_LEVEL.equals(key)) {
        getActivity().setResult(ListActivity.RESULT_CODE_REFRESH);
        return true;
    } else if (KEY_APP_ICON.equals(key)) {
        int index = NumberUtils.parseIntSafely((String) newValue, 0);
        if (index < 0 || index >= Settings.ICON_ACTIVITY_ARRAY.length) {
            return false;
        }

        PackageManager p = getActivity().getPackageManager();
        for (int i = 0; i < Settings.ICON_ACTIVITY_ARRAY.length; i++) {
            ComponentName c = new ComponentName(getActivity(), Settings.ICON_ACTIVITY_ARRAY[i]);
            p.setComponentEnabledSetting(c,
                    i == index ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED :
                            PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                    PackageManager.DONT_KILL_APP);
        }
        return true;
    }

    return false;
}
 
Example 3
Source File: GalleryPageUrlParser.java    From EhViewer with Apache License 2.0 6 votes vote down vote up
@Nullable
public static Result parse(String url, boolean strict) {
    if (url == null) {
        return null;
    }

    Pattern pattern = strict ? URL_STRICT_PATTERN : URL_PATTERN;
    Matcher m = pattern.matcher(url);
    if (m.find()) {
        Result result = new Result();
        result.gid = NumberUtils.parseLongSafely(m.group(2), -1L);
        result.pToken = m.group(1);
        result.page = NumberUtils.parseIntSafely(m.group(3), 0) - 1;
        if (result.gid < 0 || result.page < 0) {
            return null;
        }
        return result;
    } else {
        return null;
    }
}
 
Example 4
Source File: SpiderInfo.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
private static int getVersion(String str) {
    if (null == str) {
        return -1;
    }
    if (str.startsWith(VERSION_STR)) {
        return NumberUtils.parseIntSafely(str.substring(VERSION_STR.length()), -1);
    } else {
        return 1;
    }
}
 
Example 5
Source File: Settings.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
public static int getIntFromStr(String key, int defValue) {
    try {
        return NumberUtils.parseIntSafely(sSettingsPre.getString(key, Integer.toString(defValue)), defValue);
    } catch (ClassCastException e) {
        Log.d(TAG, "Get ClassCastException when get " + key + " value", e);
        return defValue;
    }
}
 
Example 6
Source File: SpiderInfo.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
private static int getVersion(String str) {
    if (null == str) {
        return -1;
    }
    if (str.startsWith(VERSION_STR)) {
        return NumberUtils.parseIntSafely(str.substring(VERSION_STR.length()), -1);
    } else {
        return 1;
    }
}
 
Example 7
Source File: GalleryApiParser.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
public static void parse(String body, List<GalleryInfo> galleryInfoList) throws JSONException {
    JSONObject jo = new JSONObject(body);
    JSONArray ja = jo.getJSONArray("gmetadata");

    for (int i = 0, length = ja.length(); i < length; i++) {
        JSONObject g = ja.getJSONObject(i);
        long gid = g.getLong("gid");
        GalleryInfo gi = getGalleryInfoByGid(galleryInfoList, gid);
        if (gi == null) {
            continue;
        }
        gi.title = ParserUtils.trim(g.getString("title"));
        gi.titleJpn = ParserUtils.trim(g.getString("title_jpn"));
        gi.category = EhUtils.getCategory(g.getString("category"));
        gi.thumb = EhUtils.handleThumbUrlResolution(g.getString("thumb"));
        gi.uploader = g.getString("uploader");
        gi.posted = ParserUtils.formatDate(ParserUtils.parseLong(g.getString("posted"), 0) * 1000);
        gi.rating = NumberUtils.parseFloatSafely(g.getString("rating"), 0.0f);
        // tags
        JSONArray tagJa = g.getJSONArray("tags");
        int tagLength = tagJa.length();
        String[] tags = new String[tagLength];
        for (int j = 0; j < tagLength; j++) {
            tags[j] = tagJa.getString(j);
        }
        gi.simpleTags = tags;
        gi.pages = NumberUtils.parseIntSafely(g.getString("filecount"), 0);
        gi.generateSLang();
    }
}
 
Example 8
Source File: Settings.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
public static int getIntFromStr(String key, int defValue) {
    try {
        return NumberUtils.parseIntSafely(sSettingsPre.getString(key, Integer.toString(defValue)), defValue);
    } catch (ClassCastException e) {
        Log.d(TAG, "Get ClassCastException when get " + key + " value", e);
        return defValue;
    }
}
 
Example 9
Source File: ParserUtils.java    From MHViewer with Apache License 2.0 4 votes vote down vote up
public static int parseInt(String str, int defValue) {
    return NumberUtils.parseIntSafely(trim(str).replace(",", ""), defValue);
}
 
Example 10
Source File: AdvanceSearchTable.java    From MHViewer with Apache License 2.0 4 votes vote down vote up
public int getPageFrom() {
    if (mSp.isChecked()) {
        return NumberUtils.parseIntSafely(mSpf.getText().toString(), -1);
    }
    return -1;
}
 
Example 11
Source File: AdvanceSearchTable.java    From MHViewer with Apache License 2.0 4 votes vote down vote up
public int getPageTo() {
    if (mSp.isChecked()) {
        return NumberUtils.parseIntSafely(mSpt.getText().toString(), -1);
    }
    return -1;
}
 
Example 12
Source File: ACPost.java    From Nimingban with Apache License 2.0 4 votes vote down vote up
@Override
public void generate(Site site) {
    mSite = site;

    mTime = parseTime(now);

    if ("1".equals(admin)) {
        Spannable spannable = new SpannableString(userid);
        spannable.setSpan(new ForegroundColorSpan(Color.RED), 0, userid.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        mUser = spannable;
    } else {
        mUser = ACItemUtils.handleUser(Html.fromHtml(userid), getNMBPostId(), getNMBId());
    }

    mReplyCount = NumberUtils.parseIntSafely(replyCount, -1);

    mContent = ACItemUtils.generateContent(content, sage, title, name);

    if (!TextUtils.isEmpty(img)) {
        String ext2 = ext;
        if (".jpe".equals(ext2)) {
            ext2 = ".jpeg";
        }
        String key = img + ext2;
        mThumbKey = "thumb/" + key;
        mImageKey = "image/" + key;
        ACSite acSite = ACSite.getInstance();
        mThumbUrl = acSite.getPictureUrl(mThumbKey);
        mImageUrl = acSite.getPictureUrl(mImageKey);
    }

    List<ACReply> replyList = replys;
    if (replyList != null && replyList.size() > 0) {
        int n = replyList.size();
        Reply[] replies = new Reply[n];
        mReplies = replies;
        for (int i = 0; i < n; i++) {
            replies[i] = replyList.get(i);
        }
    } else {
        mReplies = EMPTY_REPLY_ARRAY;
    }
}
 
Example 13
Source File: Settings.java    From Nimingban with Apache License 2.0 4 votes vote down vote up
public static int getIntFromStr(String key, int defValue) {
    return NumberUtils.parseIntSafely(sSettingsPre.getString(key, Integer.toString(defValue)), defValue);
}
 
Example 14
Source File: ParserUtils.java    From EhViewer with Apache License 2.0 4 votes vote down vote up
public static int parseInt(String str, int defValue) {
    return NumberUtils.parseIntSafely(trim(str).replace(",", ""), defValue);
}
 
Example 15
Source File: AdvanceSearchTable.java    From EhViewer with Apache License 2.0 4 votes vote down vote up
public int getPageFrom() {
    if (mSp.isChecked()) {
        return NumberUtils.parseIntSafely(mSpf.getText().toString(), -1);
    }
    return -1;
}
 
Example 16
Source File: AdvanceSearchTable.java    From EhViewer with Apache License 2.0 4 votes vote down vote up
public int getPageTo() {
    if (mSp.isChecked()) {
        return NumberUtils.parseIntSafely(mSpt.getText().toString(), -1);
    }
    return -1;
}