com.hippo.yorozuya.NumberUtils Java Examples

The following examples show how to use com.hippo.yorozuya.NumberUtils. 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: GalleryDetailUrlParser.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(1), -1L);
        result.token = m.group(2);
        if (result.gid < 0) {
            return null;
        }
        return result;
    } else {
        return null;
    }
}
 
Example #3
Source File: CleanRedundancyPreference.java    From EhViewer with Apache License 2.0 6 votes vote down vote up
private boolean clearFile(UniFile file) {
    String name = file.getName();
    if (name == null) {
        return false;
    }
    int index = name.indexOf('-');
    if (index >= 0) {
        name = name.substring(0, index);
    }
    long gid = NumberUtils.parseLongSafely(name, -1L);
    if (-1L == gid) {
        return false;
    }
    if (mManager.containDownloadInfo(gid)) {
        return false;
    }
    file.delete();
    return true;
}
 
Example #4
Source File: GalleryDetailUrlParser.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(1), -1L);
        result.token = m.group(2);
        if (result.gid < 0) {
            return null;
        }
        return result;
    } else {
        return null;
    }
}
 
Example #5
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 #6
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 #7
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 #8
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 #9
Source File: CategoryTable.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
/**
 * Set each button checked or not according to category.
 *
 * @param category target category
 */
public void setCategory(int category) {
    mDoujinshi.setChecked(!NumberUtils.int2boolean(category & EhConfig.DOUJINSHI), false);
    mManga.setChecked(!NumberUtils.int2boolean(category & EhConfig.MANGA), false);
    mArtistCG.setChecked(!NumberUtils.int2boolean(category & EhConfig.ARTIST_CG), false);
    mGameCG.setChecked(!NumberUtils.int2boolean(category & EhConfig.GAME_CG), false);
    mWestern.setChecked(!NumberUtils.int2boolean(category & EhConfig.WESTERN), false);
    mNonH.setChecked(!NumberUtils.int2boolean(category & EhConfig.NON_H), false);
    mImageSets.setChecked(!NumberUtils.int2boolean(category & EhConfig.IMAGE_SET), false);
    mCosplay.setChecked(!NumberUtils.int2boolean(category & EhConfig.COSPLAY), false);
    mAsianPorn.setChecked(!NumberUtils.int2boolean(category & EhConfig.ASIAN_PORN), false);
    mMisc.setChecked(!NumberUtils.int2boolean(category & EhConfig.MISC), false);
}
 
Example #10
Source File: AdvanceSearchTable.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
public void setAdvanceSearch(int advanceSearch) {
    mSname.setChecked(NumberUtils.int2boolean(advanceSearch & SNAME));
    mStags.setChecked(NumberUtils.int2boolean(advanceSearch & STAGS));
    mSdesc.setChecked(NumberUtils.int2boolean(advanceSearch & SDESC));
    mStorr.setChecked(NumberUtils.int2boolean(advanceSearch & STORR));
    mSto.setChecked(NumberUtils.int2boolean(advanceSearch & STO));
    mSdt1.setChecked(NumberUtils.int2boolean(advanceSearch & SDT1));
    mSdt2.setChecked(NumberUtils.int2boolean(advanceSearch & SDT2));
    mSh.setChecked(NumberUtils.int2boolean(advanceSearch & SH));
    mSfl.setChecked(NumberUtils.int2boolean(advanceSearch & SFL));
    mSfu.setChecked(NumberUtils.int2boolean(advanceSearch & SFU));
    mSft.setChecked(NumberUtils.int2boolean(advanceSearch & SFT));
}
 
Example #11
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 #12
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 #13
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 #14
Source File: CategoryTable.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
/**
 * Set each button checked or not according to category.
 *
 * @param category target category
 */
public void setCategory(int category) {
    mDoujinshi.setChecked(!NumberUtils.int2boolean(category & EhConfig.DOUJINSHI), false);
    mManga.setChecked(!NumberUtils.int2boolean(category & EhConfig.MANGA), false);
    mArtistCG.setChecked(!NumberUtils.int2boolean(category & EhConfig.ARTIST_CG), false);
    mGameCG.setChecked(!NumberUtils.int2boolean(category & EhConfig.GAME_CG), false);
    mWestern.setChecked(!NumberUtils.int2boolean(category & EhConfig.WESTERN), false);
    mNonH.setChecked(!NumberUtils.int2boolean(category & EhConfig.NON_H), false);
    mImageSets.setChecked(!NumberUtils.int2boolean(category & EhConfig.IMAGE_SET), false);
    mCosplay.setChecked(!NumberUtils.int2boolean(category & EhConfig.COSPLAY), false);
    mAsianPorn.setChecked(!NumberUtils.int2boolean(category & EhConfig.ASIAN_PORN), false);
    mMisc.setChecked(!NumberUtils.int2boolean(category & EhConfig.MISC), false);
}
 
Example #15
Source File: AdvanceSearchTable.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
public void setAdvanceSearch(int advanceSearch) {
    mSname.setChecked(NumberUtils.int2boolean(advanceSearch & SNAME));
    mStags.setChecked(NumberUtils.int2boolean(advanceSearch & STAGS));
    mSdesc.setChecked(NumberUtils.int2boolean(advanceSearch & SDESC));
    mStorr.setChecked(NumberUtils.int2boolean(advanceSearch & STORR));
    mSto.setChecked(NumberUtils.int2boolean(advanceSearch & STO));
    mSdt1.setChecked(NumberUtils.int2boolean(advanceSearch & SDT1));
    mSdt2.setChecked(NumberUtils.int2boolean(advanceSearch & SDT2));
    mSh.setChecked(NumberUtils.int2boolean(advanceSearch & SH));
    mSfl.setChecked(NumberUtils.int2boolean(advanceSearch & SFL));
    mSfu.setChecked(NumberUtils.int2boolean(advanceSearch & SFU));
    mSft.setChecked(NumberUtils.int2boolean(advanceSearch & SFT));
}
 
Example #16
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 #17
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 #18
Source File: ParserUtils.java    From MHViewer with Apache License 2.0 4 votes vote down vote up
public static long parseLong(String str, long defValue) {
    return NumberUtils.parseLongSafely(trim(str).replace(",", ""), defValue);
}
 
Example #19
Source File: ParserUtils.java    From MHViewer with Apache License 2.0 4 votes vote down vote up
public static float parseFloat(String str, float defValue) {
    return NumberUtils.parseFloatSafely(trim(str).replace(",", ""), defValue);
}
 
Example #20
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;
}
 
Example #21
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 #22
Source File: ExcludedTagNamespacesPreference.java    From EhViewer with Apache License 2.0 4 votes vote down vote up
private void setExcludedTagNamespaces(View view, int value) {
    for (int i = 0; i < EXCLUDED_TAG_GROUP_RES_ID.length; i++) {
        CheckBox cb = (CheckBox) view.findViewById(EXCLUDED_TAG_GROUP_RES_ID[i]);
        cb.setChecked(NumberUtils.int2boolean(value & EXCLUDED_TAG_GROUP_ID[i]));
    }
}
 
Example #23
Source File: ExcludedTagNamespacesPreference.java    From MHViewer with Apache License 2.0 4 votes vote down vote up
private void setExcludedTagNamespaces(View view, int value) {
    for (int i = 0; i < EXCLUDED_TAG_GROUP_RES_ID.length; i++) {
        CheckBox cb = (CheckBox) view.findViewById(EXCLUDED_TAG_GROUP_RES_ID[i]);
        cb.setChecked(NumberUtils.int2boolean(value & EXCLUDED_TAG_GROUP_ID[i]));
    }
}
 
Example #24
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 #25
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 #26
Source File: ParserUtils.java    From EhViewer with Apache License 2.0 4 votes vote down vote up
public static float parseFloat(String str, float defValue) {
    return NumberUtils.parseFloatSafely(trim(str).replace(",", ""), defValue);
}
 
Example #27
Source File: ParserUtils.java    From EhViewer with Apache License 2.0 4 votes vote down vote up
public static long parseLong(String str, long defValue) {
    return NumberUtils.parseLongSafely(trim(str).replace(",", ""), defValue);
}
 
Example #28
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 #29
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 #30
Source File: FeedActivity.java    From Nimingban with Apache License 2.0 4 votes vote down vote up
@Override
public long getItemId(int position) {
    Post post = mFeedHelper.getDataAt(position);
    return NumberUtils.parseLongSafely(post.getNMBId(), 0L);
}