Java Code Examples for android.text.TextUtils.isDigitsOnly()

The following are Jave code examples for showing how to use isDigitsOnly() of the android.text.TextUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: SimpleBible   File: ReadFragment.java   View Source Code Vote up 6 votes
@Override
public void update(Observable observable, Object o) {
    Activity activity = getActivity();
    if (activity instanceof AppCompatActivity) {
        ActionBar actionBar = ((AppCompatActivity) activity).getSupportActionBar();
        if (actionBar != null) {
            actionBar.setTitle(CurrentSelected.getVersion().getDisplayText());
        }
    }

    if (o instanceof IVerseProvider) {
        //noinspection unchecked
        mAdapter.updateVerses(((IVerseProvider) o).getVerses());

        final IVerse verse = CurrentSelected.getVerse();
        if (verse != null && !TextUtils.isEmpty(verse.getVerseNumber()) && TextUtils.isDigitsOnly(verse.getVerseNumber())) {
            new Handler().post(() -> scrollToVerse(verse));
        }
    }

    setBookChapterText();
}
 
Example 2
Project: chuck   File: TransactionListFragment.java   View Source Code Vote up 6 votes
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    CursorLoader loader = new CursorLoader(getContext());
    loader.setUri(ChuckContentProvider.TRANSACTION_URI);
    if (!TextUtils.isEmpty(currentFilter)) {
        if (TextUtils.isDigitsOnly(currentFilter)) {
            loader.setSelection("responseCode LIKE ?");
            loader.setSelectionArgs(new String[]{ currentFilter + "%" });
        } else {
            loader.setSelection("path LIKE ?");
            loader.setSelectionArgs(new String[]{ "%" + currentFilter + "%" });
        }
    }
    loader.setProjection(HttpTransaction.PARTIAL_PROJECTION);
    loader.setSortOrder("requestDate DESC");
    return loader;
}
 
Example 3
Project: starcor.xul   File: XulPropParser.java   View Source Code Vote up 6 votes
public static Object doParse(XulAttr prop) {
	xulParsedAttr_Img_FadeIn val = new xulParsedAttr_Img_FadeIn();
	String stringValue = prop.getStringValue();
	if ("true".equals(stringValue) || "enabled".equals(stringValue)) {
		val.enabled = true;
		val.duration = 300;
	} else if (TextUtils.isEmpty(stringValue) || "disabled".equals(stringValue) || "false".equals(stringValue)) {
		val.enabled = false;
		val.duration = 0;
	} else if (TextUtils.isDigitsOnly(stringValue)) {
		val.enabled = true;
		val.duration = XulUtils.tryParseInt(stringValue, 300);
	} else {
		val.enabled = false;
		val.duration = 300;
	}
	return val;
}
 
Example 4
Project: FakeWeather   File: AqiAdapter.java   View Source Code Vote up 6 votes
/**
 * Implement this method and use the helper to adapt the view to the given item.
 *
 * @param helper A fully initialized helper.
 * @param item   The item that needs to be displayed.
 */
@Override
protected void convert(BaseViewHolder helper, AqiDetailBean item) {
    helper.setText(R.id.tv_aqi_name, item.getName());
    helper.setText(R.id.tv_aqi_desc, item.getDesc());
    if (TextUtils.isEmpty(item.getValue())) {
        item.setValue("-1");
    }
    helper.setText(R.id.tv_aqi_value, item.getValue() + "");
    int value = TextUtils.isDigitsOnly(item.getValue()) ? Integer.parseInt(item.getValue()) : 0;
    if (value <= 50) {
        helper.setBackgroundColor(R.id.view_aqi_qlty, 0xFF6BCD07);
    } else if (value <= 100) {
        helper.setBackgroundColor(R.id.view_aqi_qlty, 0xFFFBD029);
    } else if (value <= 150) {
        helper.setBackgroundColor(R.id.view_aqi_qlty, 0xFFFE8800);
    } else if (value <= 200) {
        helper.setBackgroundColor(R.id.view_aqi_qlty, 0xFFFE0000);
    } else if (value <= 300) {
        helper.setBackgroundColor(R.id.view_aqi_qlty, 0xFF970454);
    } else {
        helper.setBackgroundColor(R.id.view_aqi_qlty, 0xFF62001E);
    }
}
 
Example 5
Project: wisebite_android   File: CreateRestaurantInfoActivity.java   View Source Code Vote up 6 votes
/**
 * Validate number of tables
 * @return true if it's validated correctly, false otherwise
 */
private boolean validateNumberOfTables() {
    String numberOfTables = inputNumberOfTables.getText().toString().trim();
    if (TextUtils.isEmpty(numberOfTables) || !TextUtils.isDigitsOnly(numberOfTables)) {
        inputLayoutNumberOfTables.setError(getString(R.string.err_msg_number_of_tables));
        requestFocus(inputNumberOfTables);
        return false;
    } else if (Integer.valueOf(numberOfTables) > 1000) {
        inputLayoutNumberOfTables.setError(getString(R.string.err_msg_number_of_tables_too_much_tables));
        requestFocus(inputNumberOfTables);
        return false;
    } else {
        inputLayoutNumberOfTables.setErrorEnabled(false);
    }
    return true;
}
 
Example 6
Project: mvvm-template   File: SchemeParser.java   View Source Code Vote up 5 votes
@Nullable private static String getGistId(@NonNull Uri uri) {
    List<String> segments = uri.getPathSegments();
    if (segments.size() != 1 && segments.size() != 2) return null;
    String gistId = segments.get(segments.size() - 1);
    if (InputHelper.isEmpty(gistId)) return null;
    if (TextUtils.isDigitsOnly(gistId)) return gistId;
    else if (gistId.matches("[a-fA-F0-9]+")) return gistId;
    else return null;
}
 
Example 7
Project: iosched-reader   File: ScheduleProvider.java   View Source Code Vote up 5 votes
/**
 * Adds the {@code tagsFilter} query parameter to the given {@code builder}. This query
 * parameter is used by the {@link com.google.samples.apps.iosched.explore.ExploreSessionsActivity}
 * when the user makes a selection containing multiple filters.
 */
private void addTagsFilter(SelectionBuilder builder, String tagsFilter, String numCategories) {
    // Note: for context, remember that session queries are done on a join of sessions
    // and the sessions_tags relationship table, and are GROUP'ed BY the session ID.
    String[] requiredTags = tagsFilter.split(",");
    if (requiredTags.length == 0) {
        // filtering by 0 tags -- no-op
        return;
    } else if (requiredTags.length == 1) {
        // filtering by only one tag, so a simple WHERE clause suffices
        builder.where(Tags.TAG_ID + "=?", requiredTags[0]);
    } else {
        // Filtering by multiple tags, so we must add a WHERE clause with an IN operator,
        // and add a HAVING statement to exclude groups that fall short of the number
        // of required tags. For example, if requiredTags is { "X", "Y", "Z" }, and a certain
        // session only has tags "X" and "Y", it will be excluded by the HAVING statement.
        int categories = 1;
        if (numCategories != null && TextUtils.isDigitsOnly(numCategories)) {
            try {
                categories = Integer.parseInt(numCategories);
                LOGD(TAG, "Categories being used " + categories);
            } catch (Exception ex) {
                LOGE(TAG, "exception parsing categories ", ex);
            }
        }
        String questionMarkTuple = makeQuestionMarkTuple(requiredTags.length);
        builder.where(Tags.TAG_ID + " IN " + questionMarkTuple, requiredTags);
        builder.having(
                "COUNT(" + Qualified.SESSIONS_SESSION_ID + ") >= " + categories);
    }
}
 
Example 8
Project: starcor.xul   File: XulPropParser.java   View Source Code Vote up 5 votes
public static Object doParse(XulAttr prop) {
	xulParsedAttr_Img_AutoHide val = new xulParsedAttr_Img_AutoHide();
	String stringValue = prop.getStringValue();
	if ("below".equals(stringValue)) {
		val.enabled = true;
		val.target = -1;
	} else if (!TextUtils.isEmpty(stringValue) && TextUtils.isDigitsOnly(stringValue)) {
		val.enabled = true;
		val.target = XulUtils.tryParseInt(stringValue);
		val.target = Math.min(Math.max(-1, val.target), XulImageRender._MaxImgLayers);
	} else {
		val.enabled = false;
	}
	return val;
}
 
Example 9
Project: TPondof   File: UrlRouterUtil.java   View Source Code Vote up 5 votes
/**
 * 是否是帖子跳转
 * @param context
 * @param url
 * @return
 * https://pondof.fish/d/13
 */
public static boolean isDiscussionJump(Context context, String url,int mDiscussionId){
    if(null!= url && url.length() > ApiManager.URL.length() + 2) {
        String urlPath = url.substring(ApiManager.URL.length() + 2);
        String[] paths = urlPath.split("/");
        // 点击链接的帖子id和本帖子id不同
        if(TextUtils.isDigitsOnly(paths[0]) && TextUtils.isDigitsOnly(paths[1]) && mDiscussionId != Integer.parseInt(paths[0])){
            UIUtil.openDiscussionViewActivity(context,Integer.parseInt(paths[0]));
            return true;
        }
    }
    return false;
}
 
Example 10
Project: TPondof   File: UrlRouterUtil.java   View Source Code Vote up 5 votes
/**
 * 是否是评论跳转
 * @param context
 * @param url
 * @return
 * https://pondof.fish/d/10/2
 */
public static int isCommentJump(Context context, String url, int mDiscussionId) {
    if(null!= url && url.length() > ApiManager.URL.length() + 2){
        String commentPath = url.substring(ApiManager.URL.length() + 2);
        String[] paths = commentPath.split("/");
        // 点击链接的帖子id和本帖子id相同
        if (TextUtils.isDigitsOnly(paths[0]) && TextUtils.isDigitsOnly(paths[1]) && mDiscussionId == Integer.parseInt(paths[0])) {
            return Integer.parseInt(paths[1]);
        }
    }
    return -1;
}
 
Example 11
Project: AndroidOCRFforID   File: OcrIdActivity.java   View Source Code Vote up 5 votes
private String extractIdIFE(String s) {
    String[] lines = s.split("\r\n|\r|\n");
    String result = s.replaceAll("\\s+", "").replaceAll("[-+.^:,]", "");
    if (result.length() > 13) result = result.substring(0, 13);

    if (!TextUtils.isDigitsOnly(result)) {
        result = result.replace('b', '6').replace('L', '6').replace('l', '1').replace('i', '1').replace('I', '1')
                .replace('y', '4').replace('o', '0').replace('O', '0').replace('s', '5').replace('S', '5')
                .replace('z', '2').replace('Z', '2').replace('g', '9').replace('Y', '4').replace('e', '2')
                .replace('?', '7').replace('E', '6');
    }
    return result;
}
 
Example 12
Project: DragBadgeView   File: DragBadgeView.java   View Source Code Vote up 5 votes
/**
 * 获取输入的数字类型文本
 * @return int类型文本
 */
public int getIntText() {
    if (TextUtils.isDigitsOnly(mText))
        return Integer.valueOf(mText);
    else
        return -1;
}
 
Example 13
Project: wisebite_android   File: CreateRestaurantInfoActivity.java   View Source Code Vote up 5 votes
/**
 * Validate restaurant phone
 * @return true if it's validated correctly, false otherwise
 */
private boolean validatePhone() {
    String phone = inputPhone.getText().toString().trim();
    if (TextUtils.isEmpty(phone) || !TextUtils.isDigitsOnly(phone)) {
        inputLayoutPhone.setError(getString(R.string.err_msg_phone));
        requestFocus(inputPhone);
        return false;
    } else {
        inputLayoutPhone.setErrorEnabled(false);
    }
    return true;
}
 
Example 14
Project: HutHelper   File: GradeListAdapter.java   View Source Code Vote up 5 votes
@Override
public void onBindViewHolder(GradeListViewHolder holder, int position) {
    Grade grade = gradeList.get(position);
    String xfjd = "学分&绩点:" + grade.getXf() + "&" + grade.getJd();
    String gradeTime = grade.getXn() + "学年第" + grade.getXq() + "学期";
    String lessonName = grade.getKcmc();
    String gradeScore = grade.getCj();
    if (!TextUtils.isEmpty(grade.getBkcj())) {
        gradeTime += "(补考)";
        gradeScore = grade.getBkcj();
    } else if (!TextUtils.isEmpty(grade.getCxbj()) && grade.getCxbj().equals("1")) {
        gradeTime += "(重修)";
    }

    if (TextUtils.isDigitsOnly(gradeScore)) {
        if (Integer.parseInt(gradeScore) < 60) {
            lessonName += "(未通过)";
        }
        gradeScore += "分";
    } else if (gradeScore.equals("不及格")) {
        lessonName += "(未通过)";
    }
    holder.tvGradeLesson.setText(lessonName);
    holder.tvGradeTime.setText(gradeTime);
    holder.tvGradeJidian.setText(xfjd);
    holder.tvGradeScore.setText(gradeScore);
}
 
Example 15
Project: Brevent   File: AdbPortUtils.java   View Source Code Vote up 5 votes
public static int getAdbPort() {
    // XXX: SystemProperties.get is @hide method
    String port = SystemProperties.get("service.adb.tcp.port", "");
    UILog.i("service.adb.tcp.port: " + port);
    if (!TextUtils.isEmpty(port) && TextUtils.isDigitsOnly(port)) {
        int p = Integer.parseInt(port);
        if (p > 0 && p <= 0xffff) {
            return p;
        }
    }
    return -1;
}
 
Example 16
Project: Rx_java2_soussidev   File: VerifyDigitCompac.java   View Source Code Vote up 4 votes
@Override public Observable<RxVerifyCompacResult<AppCompatEditText>> verify(String text, AppCompatEditText item) {
    if (TextUtils.isDigitsOnly(text)) {
        return Observable.just(RxVerifyCompacResult.createSuccess(item));
    }
    return Observable.just(RxVerifyCompacResult.createImproper(item, digitOnlyMessage));
}
 
Example 17
Project: XPrivacy   File: XContentResolver.java   View Source Code Vote up 4 votes
@SuppressLint("DefaultLocale")
private void handleUriBefore(XParam param) throws Throwable {
	// Check URI
	if (param.args.length > 1 && param.args[0] instanceof Uri) {
		String uri = ((Uri) param.args[0]).toString().toLowerCase();
		String[] projection = (param.args[1] instanceof String[] ? (String[]) param.args[1] : null);

		if (uri.startsWith("content://com.android.contacts/contacts/name_phone_or_email")) {
			// Do nothing

		} else if (uri.startsWith("content://com.android.contacts/")
				&& !uri.equals("content://com.android.contacts/")) {
			String[] components = uri.replace("content://com.android.", "").split("/");
			String methodName = components[0] + "/" + components[1].split("\\?")[0];
			if (methodName.equals("contacts/contacts") || methodName.equals("contacts/data")
					|| methodName.equals("contacts/phone_lookup") || methodName.equals("contacts/raw_contacts"))
				if (isRestrictedExtra(param, PrivacyManager.cContacts, methodName, uri)) {
					// Get ID from URL if any
					int urlid = -1;
					if ((methodName.equals("contacts/contacts") || methodName.equals("contacts/phone_lookup"))
							&& components.length > 2 && TextUtils.isDigitsOnly(components[2]))
						urlid = Integer.parseInt(components[2]);

					// Modify projection
					boolean added = false;
					if (projection != null && urlid < 0) {
						List<String> listProjection = new ArrayList<String>();
						listProjection.addAll(Arrays.asList(projection));
						String cid = getIdForUri(uri);
						if (cid != null && !listProjection.contains(cid)) {
							added = true;
							listProjection.add(cid);
						}
						param.args[1] = listProjection.toArray(new String[0]);
					}
					if (added)
						param.setObjectExtra("column_added", added);
				}
		}
	}
}
 
Example 18
Project: android-contact-extractor   File: BaseContactQueryCB.java   View Source Code Vote up 4 votes
private boolean isValidType(String numberType) {
    return !TextUtils.isEmpty(numberType) && TextUtils.isDigitsOnly(numberType);
}
 
Example 19
Project: FakeWeather   File: TypeUtil.java   View Source Code Vote up 4 votes
private static BaseWeatherType getHeWeatherType(Context context, ShortWeatherInfo info) {
    if (info != null && TextUtils.isDigitsOnly(info.getCode())) {
        int code = Integer.parseInt(info.getCode());
        if (code == 100) {//晴
            return new SunnyType(context, info);
        } else if (code >= 101 && code <= 103) {//多云
            SunnyType sunnyType = new SunnyType(context, info);
            sunnyType.setCloud(true);
            return sunnyType;
        } else if (code == 104) {//阴
            return new OvercastType(context, info);
        } else if (code >= 200 && code <= 213) {//各种风
            return new SunnyType(context, info);
        } else if (code >= 300 && code <= 303) {//各种阵雨
            if (code >= 300 && code <= 301) {
                return new RainType(context, RainType.RAIN_LEVEL_2, RainType.WIND_LEVEL_2);
            } else {
                RainType rainType = new RainType(context, RainType.RAIN_LEVEL_2, RainType.WIND_LEVEL_2);
                rainType.setFlashing(true);
                return rainType;
            }
        } else if (code == 304) {//阵雨加冰雹
            return new HailType(context);
        } else if (code >= 305 && code <= 312) {//各种雨
            if (code == 305 || code == 309) {//小雨
                return new RainType(context, RainType.RAIN_LEVEL_1, RainType.WIND_LEVEL_1);
            } else if (code == 306) {//中雨
                return new RainType(context, RainType.RAIN_LEVEL_2, RainType.WIND_LEVEL_2);
            } else//大到暴雨
                return new RainType(context, RainType.RAIN_LEVEL_3, RainType.WIND_LEVEL_3);
        } else if (code == 313) {//冻雨
            return new HailType(context);
        } else if (code >= 400 && code <= 407) {//各种雪
            if (code == 400) {
                return new SnowType(context, SnowType.SNOW_LEVEL_1);
            } else if (code == 401) {
                return new SnowType(context, SnowType.SNOW_LEVEL_2);
            } else if (code >= 402 && code <= 403) {
                return new SnowType(context, SnowType.SNOW_LEVEL_3);
            } else if (code >= 404 && code <= 406) {
                RainType rainSnowType = new RainType(context, RainType.RAIN_LEVEL_1, RainType.WIND_LEVEL_1);
                rainSnowType.setSnowing(true);
                return rainSnowType;
            } else {
                return new SnowType(context, SnowType.SNOW_LEVEL_2);
            }
        } else if (code >= 500 && code <= 501) {//雾
            return new FogType(context);
        } else if (code == 502) {//霾
            return new HazeType(context);
        } else if (code >= 503 && code <= 508) {//各种沙尘暴
            return new SandstormType(context);
        } else if (code == 900) {//热
            return new SunnyType(context, info);
        } else if (code == 901) {//冷
            return new SnowType(context, SnowType.SNOW_LEVEL_1);
        } else {//未知
            return new SunnyType(context, info);
        }
    } else
        return null;
}
 
Example 20
Project: Simpler   File: GroupAPI.java   View Source Code Vote up 3 votes
/**
 * 更新好友分组中成员的分组说明。
 *
 * @param list_id           好友分组ID,建议使用返回值里的idstr
 * @param uid               需要更新分组成员说明的用户的UID
 * @param group_description 需要更新的分组成员说明,每个说明最多8个汉字,16个半角字符,需要URLencode
 * @param listener          异步请求回调接口
 */
public void updateMembers(long list_id, long uid, String group_description, RequestListener listener) {
    WeiboParameters params = buildMembersParams(list_id, uid);
    if (!TextUtils.isDigitsOnly(group_description)) {
        params.put("group_description", group_description);
    }
    requestAsync(SERVER_URL_PRIX + "/members/update.json", params, HTTPMETHOD_POST, listener);
}