Java Code Examples for com.hippo.yorozuya.NumberUtils
The following examples show how to use
com.hippo.yorozuya.NumberUtils.
These examples are extracted from open source projects.
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 Project: MHViewer Author: axlecho File: GalleryPageUrlParser.java License: Apache License 2.0 | 6 votes |
@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 Project: MHViewer Author: axlecho File: GalleryDetailUrlParser.java License: Apache License 2.0 | 6 votes |
@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 Project: Nimingban Author: seven332 File: SettingsActivity.java License: Apache License 2.0 | 6 votes |
@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 #4
Source Project: EhViewer Author: seven332 File: GalleryPageUrlParser.java License: Apache License 2.0 | 6 votes |
@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 #5
Source Project: EhViewer Author: seven332 File: GalleryDetailUrlParser.java License: Apache License 2.0 | 6 votes |
@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 #6
Source Project: EhViewer Author: seven332 File: CleanRedundancyPreference.java License: Apache License 2.0 | 6 votes |
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 #7
Source Project: MHViewer Author: axlecho File: SpiderInfo.java License: Apache License 2.0 | 5 votes |
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 #8
Source Project: MHViewer Author: axlecho File: AdvanceSearchTable.java License: Apache License 2.0 | 5 votes |
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 #9
Source Project: MHViewer Author: axlecho File: CategoryTable.java License: Apache License 2.0 | 5 votes |
/** * 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 Project: MHViewer Author: axlecho File: Settings.java License: Apache License 2.0 | 5 votes |
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 #11
Source Project: EhViewer Author: seven332 File: SpiderInfo.java License: Apache License 2.0 | 5 votes |
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 #12
Source Project: EhViewer Author: seven332 File: GalleryApiParser.java License: Apache License 2.0 | 5 votes |
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 #13
Source Project: EhViewer Author: seven332 File: AdvanceSearchTable.java License: Apache License 2.0 | 5 votes |
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 #14
Source Project: EhViewer Author: seven332 File: CategoryTable.java License: Apache License 2.0 | 5 votes |
/** * 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 Project: EhViewer Author: seven332 File: Settings.java License: Apache License 2.0 | 5 votes |
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 #16
Source Project: MHViewer Author: axlecho File: ParserUtils.java License: Apache License 2.0 | 4 votes |
public static int parseInt(String str, int defValue) { return NumberUtils.parseIntSafely(trim(str).replace(",", ""), defValue); }
Example #17
Source Project: MHViewer Author: axlecho File: ParserUtils.java License: Apache License 2.0 | 4 votes |
public static long parseLong(String str, long defValue) { return NumberUtils.parseLongSafely(trim(str).replace(",", ""), defValue); }
Example #18
Source Project: MHViewer Author: axlecho File: ParserUtils.java License: Apache License 2.0 | 4 votes |
public static float parseFloat(String str, float defValue) { return NumberUtils.parseFloatSafely(trim(str).replace(",", ""), defValue); }
Example #19
Source Project: MHViewer Author: axlecho File: ExcludedTagNamespacesPreference.java License: Apache License 2.0 | 4 votes |
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 #20
Source Project: MHViewer Author: axlecho File: AdvanceSearchTable.java License: Apache License 2.0 | 4 votes |
public int getPageFrom() { if (mSp.isChecked()) { return NumberUtils.parseIntSafely(mSpf.getText().toString(), -1); } return -1; }
Example #21
Source Project: MHViewer Author: axlecho File: AdvanceSearchTable.java License: Apache License 2.0 | 4 votes |
public int getPageTo() { if (mSp.isChecked()) { return NumberUtils.parseIntSafely(mSpt.getText().toString(), -1); } return -1; }
Example #22
Source Project: Nimingban Author: seven332 File: ACPost.java License: Apache License 2.0 | 4 votes |
@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 #23
Source Project: Nimingban Author: seven332 File: FeedActivity.java License: Apache License 2.0 | 4 votes |
@Override public long getItemId(int position) { Post post = mFeedHelper.getDataAt(position); return NumberUtils.parseLongSafely(post.getNMBId(), 0L); }
Example #24
Source Project: Nimingban Author: seven332 File: Settings.java License: Apache License 2.0 | 4 votes |
public static int getIntFromStr(String key, int defValue) { return NumberUtils.parseIntSafely(sSettingsPre.getString(key, Integer.toString(defValue)), defValue); }
Example #25
Source Project: EhViewer Author: seven332 File: ParserUtils.java License: Apache License 2.0 | 4 votes |
public static int parseInt(String str, int defValue) { return NumberUtils.parseIntSafely(trim(str).replace(",", ""), defValue); }
Example #26
Source Project: EhViewer Author: seven332 File: ParserUtils.java License: Apache License 2.0 | 4 votes |
public static long parseLong(String str, long defValue) { return NumberUtils.parseLongSafely(trim(str).replace(",", ""), defValue); }
Example #27
Source Project: EhViewer Author: seven332 File: ParserUtils.java License: Apache License 2.0 | 4 votes |
public static float parseFloat(String str, float defValue) { return NumberUtils.parseFloatSafely(trim(str).replace(",", ""), defValue); }
Example #28
Source Project: EhViewer Author: seven332 File: ExcludedTagNamespacesPreference.java License: Apache License 2.0 | 4 votes |
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 #29
Source Project: EhViewer Author: seven332 File: AdvanceSearchTable.java License: Apache License 2.0 | 4 votes |
public int getPageFrom() { if (mSp.isChecked()) { return NumberUtils.parseIntSafely(mSpf.getText().toString(), -1); } return -1; }
Example #30
Source Project: EhViewer Author: seven332 File: AdvanceSearchTable.java License: Apache License 2.0 | 4 votes |
public int getPageTo() { if (mSp.isChecked()) { return NumberUtils.parseIntSafely(mSpt.getText().toString(), -1); } return -1; }