List of usage examples for java.lang CharSequence length
int length();
From source file:org.archive.modules.extractor.ExtractorHTML.java
protected void processScript(CrawlURI curi, CharSequence sequence, int endOfOpenTag) { // first, get attributes of script-open tag // as per any other tag processGeneralTag(curi, sequence.subSequence(0, 6), sequence.subSequence(0, endOfOpenTag)); // then, apply best-effort string-analysis heuristics // against any code present (false positives are OK) processScriptCode(curi, sequence.subSequence(endOfOpenTag, sequence.length())); }
From source file:com.healthmarketscience.jackcess.Column.java
/** * Returns {@code true} if the given text can be compressed using simple * ASCII encoding, {@code false} otherwise. */// ww w . j a v a 2 s. com private static boolean isAsciiCompressible(CharSequence text) { // only attempt to compress > 2 chars (compressing less than 3 chars would // not result in a space savings due to the 2 byte compression header) if (text.length() <= TEXT_COMPRESSION_HEADER.length) { return false; } // now, see if it is all printable ASCII for (int i = 0; i < text.length(); ++i) { char c = text.charAt(i); if (!Compress.isAsciiCrLfOrTab(c)) { return false; } } return true; }
From source file:org.esigate.parser.Parser.java
/** * Parses all the CharSequence./* w w w . j av a 2s.c om*/ * * @param in * The CharSequence to parse * @param out * The Writable to write the result to * @throws IOException * @throws HttpErrorPage */ public void parse(CharSequence in, Appendable out) throws IOException, HttpErrorPage { ParserContextImpl ctx = new ParserContextImpl(out, httpRequest, httpResponse); Matcher matcher = pattern.matcher(in); int currentPosition = 0; while (matcher.find()) { String tag = matcher.group(); ctx.characters(in, currentPosition, matcher.start()); currentPosition = matcher.end(); if (ctx.isCurrentTagEnd(tag)) { // check if this is the end tag for current element LOG.info("Processing end tag {}", tag); ctx.endElement(tag); } else { // if not, it is an opening tag for a new element LOG.info("Processing start tag {}", tag); ElementType type = null; for (ElementType t : elementTypes) { if (t.isStartTag(tag)) { type = t; break; } } Element element = type.newInstance(); ctx.startElement(type, element, tag); if (type.isSelfClosing(tag)) { ctx.endElement(tag); } } } // we reached the end of input ctx.characters(in, currentPosition, in.length()); }
From source file:cn.sinobest.jzpt.framework.utils.string.StringUtils.java
/** * /* www. j a v a 2 s.co m*/ * * @param source * @param offset * @param keyword * @return */ public static boolean matchChars(CharSequence source, int offset, CharSequence keyword) { int max = offset + keyword.length(); for (int i = offset; i < max; i++) { if (source.charAt(i) != keyword.charAt(i - offset)) { return false; } } return true; }
From source file:com.xgf.inspection.qrcode.google.zxing.client.CaptureActivity.java
private void handleDecodeInternally(Result rawResult, ResultHandler resultHandler, Bitmap barcode) { statusView.setVisibility(View.GONE); viewfinderView.setVisibility(View.GONE); resultView.setVisibility(View.VISIBLE); ImageView barcodeImageView = (ImageView) findViewById(R.id.barcode_image_view); if (barcode == null) { barcodeImageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.qr_scan)); } else {/* w ww. j ava2 s .c o m*/ barcodeImageView.setImageBitmap(barcode); } TextView formatTextView = (TextView) findViewById(R.id.format_text_view); formatTextView.setText(rawResult.getBarcodeFormat().toString()); TextView typeTextView = (TextView) findViewById(R.id.type_text_view); typeTextView.setText(resultHandler.getType().toString()); DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); String formattedTime = formatter.format(new Date(rawResult.getTimestamp())); TextView timeTextView = (TextView) findViewById(R.id.time_text_view); timeTextView.setText(formattedTime); TextView metaTextView = (TextView) findViewById(R.id.meta_text_view); View metaTextViewLabel = findViewById(R.id.meta_text_view_label); metaTextView.setVisibility(View.GONE); metaTextViewLabel.setVisibility(View.GONE); Map<ResultMetadataType, Object> metadata = rawResult.getResultMetadata(); if (metadata != null) { StringBuilder metadataText = new StringBuilder(20); for (Map.Entry<ResultMetadataType, Object> entry : metadata.entrySet()) { if (DISPLAYABLE_METADATA_TYPES.contains(entry.getKey())) { metadataText.append(entry.getValue()).append('\n'); } } if (metadataText.length() > 0) { metadataText.setLength(metadataText.length() - 1); metaTextView.setText(metadataText); metaTextView.setVisibility(View.VISIBLE); metaTextViewLabel.setVisibility(View.VISIBLE); } } TextView contentsTextView = (TextView) findViewById(R.id.contents_text_view); CharSequence displayContents = resultHandler.getDisplayContents(); contentsTextView.setText(displayContents); // Crudely scale betweeen 22 and 32 -- bigger font for shorter text int scaledSize = Math.max(22, 32 - displayContents.length() / 4); contentsTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, scaledSize); TextView supplementTextView = (TextView) findViewById(R.id.contents_supplement_text_view); supplementTextView.setText(""); supplementTextView.setOnClickListener(null); if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(PreferencesActivity.KEY_SUPPLEMENTAL, true)) { SupplementalInfoRetriever.maybeInvokeRetrieval(supplementTextView, resultHandler.getResult(), historyManager, this); } int buttonCount = resultHandler.getButtonCount(); ViewGroup buttonView = (ViewGroup) findViewById(R.id.result_button_view); buttonView.requestFocus(); for (int x = 0; x < ResultHandler.MAX_BUTTON_COUNT; x++) { TextView button = (TextView) buttonView.getChildAt(x); if (x < buttonCount) { button.setVisibility(View.VISIBLE); button.setText(resultHandler.getButtonText(x)); button.setOnClickListener(new ResultButtonListener(resultHandler, x)); } else { button.setVisibility(View.GONE); } } if (copyToClipboard && !resultHandler.areContentsSecure()) { ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); if (displayContents != null) { clipboard.setText(displayContents); } } }
From source file:com.insthub.O2OMobile.Activity.D1_OrderActivity.java
private void showOrderPriceDialog() { LayoutInflater inflater = LayoutInflater.from(D1_OrderActivity.this); View view = inflater.inflate(R.layout.d1_order_price_dialog, null); mPriceDialog = new Dialog(D1_OrderActivity.this, R.style.dialog); mPriceDialog.setContentView(view);//w w w. ja v a 2s. c o m mPriceDialog.setCanceledOnTouchOutside(false); mPriceDialog.show(); mOrderPriceDialogPrice = (TextView) view.findViewById(R.id.order_price_dialog_price); mOrderPriceDialogChangePrice = (EditText) view.findViewById(R.id.order_price_dialog_change_price); mOrderPriceDialogOk = (Button) view.findViewById(R.id.order_price_dialog_ok); mOrderPriceDialogCancel = (Button) view.findViewById(R.id.order_price_dialog_cancel); if (mOrderInfoModel.publicOrder.offer_price != null) { mOrderPriceDialogPrice.setText(Utils.formatBalance(mOrderInfoModel.publicOrder.offer_price) + ""); } mOrderPriceDialogChangePrice.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub if (s.toString().length() > 0) { if (s.toString().substring(0, 1).equals(".")) { s = s.toString().substring(1, s.length()); mOrderPriceDialogChangePrice.setText(s); } } if (s.toString().length() > 1) { if (s.toString().substring(0, 1).equals("0")) { if (!s.toString().substring(1, 2).equals(".")) { s = s.toString().substring(1, s.length()); mOrderPriceDialogChangePrice.setText(s); CharSequence charSequencePirce = mOrderPriceDialogChangePrice.getText(); if (charSequencePirce instanceof Spannable) { Spannable spanText = (Spannable) charSequencePirce; Selection.setSelection(spanText, charSequencePirce.length()); } } } } boolean flag = false; for (int i = 0; i < s.toString().length() - 1; i++) { String getstr = s.toString().substring(i, i + 1); if (getstr.equals(".")) { flag = true; break; } } if (flag) { int i = s.toString().indexOf("."); if (s.toString().length() - 3 > i) { String getstr = s.toString().substring(0, i + 3); mOrderPriceDialogChangePrice.setText(getstr); CharSequence charSequencePirce = mOrderPriceDialogChangePrice.getText(); if (charSequencePirce instanceof Spannable) { Spannable spanText = (Spannable) charSequencePirce; Selection.setSelection(spanText, charSequencePirce.length()); } } } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } @Override public void afterTextChanged(Editable s) { // TODO Auto-generated method stub } }); mOrderPriceDialogCancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub mPriceDialog.dismiss(); } }); mOrderPriceDialogOk.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub mOrderInfoModel.done(mOrderId, mOrderPriceDialogChangePrice.getText().toString()); mPriceDialog.dismiss(); } }); }
From source file:com.insthub.O2OMobile.Activity.C1_PublishOrderActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.c1_publish_order); mFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); File file = new File(newFileName()); if (file.exists()) { file.delete();/*from ww w .jav a2s . co m*/ } Intent intent = getIntent(); mServiceType = (SERVICE_TYPE) intent.getSerializableExtra(O2OMobileAppConst.SERVICE_TYPE); mDefaultReceiverId = intent.getIntExtra(DEFAULT_RECEIVER_ID, 0); service_list = intent.getStringExtra("service_list"); mBack = (ImageView) findViewById(R.id.top_view_back); mTitle = (TextView) findViewById(R.id.top_view_title); mBack.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub finish(); } }); mArrowImage = (ImageView) findViewById(R.id.top_view_arrow_image); mClose = (ImageView) findViewById(R.id.top_view_right_close); mTitleView = (LinearLayout) findViewById(R.id.top_view_title_view); mServiceTypeView = (FrameLayout) findViewById(R.id.c1_publish_order_service_type_view); mServiceTypeListview = (ListView) findViewById(R.id.c1_publish_order_service_type_list); mPrice = (EditText) findViewById(R.id.c1_publish_order_price); mTime = (TextView) findViewById(R.id.c1_publish_order_time); mLocation = (EditText) findViewById(R.id.c1_publish_order_location); mText = (EditText) findViewById(R.id.c1_publish_order_text); mVoice = (Button) findViewById(R.id.c1_publish_order_voice); mVoicePlay = (Button) findViewById(R.id.c1_publish_order_voicePlay); mVoiceReset = (ImageView) findViewById(R.id.c1_publish_order_voiceReset); mPublish = (Button) findViewById(R.id.c1_publish_order_publish); mVoiceView = (FrameLayout) findViewById(R.id.c1_publish_order_voice_view); mVoiceAnim = (ImageView) findViewById(R.id.c1_publish_order_voice_anim); mVoiceAnim.setImageResource(R.anim.voice_animation); mAnimationDrawable = (AnimationDrawable) mVoiceAnim.getDrawable(); mAnimationDrawable.setOneShot(false); mTitleView.setEnabled(false); mServiceTypeView.setOnClickListener(null); mServiceTypeListview.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // TODO Auto-generated method stub if (mDefaultReceiverId == 0) { mTitle.setText(mHomeModel.publicServiceTypeList.get(position).title); mServiceTypeId = mHomeModel.publicServiceTypeList.get(position).id; mC1PublishOrderAdapter = new C1_PublishOrderAdapter(C1_PublishOrderActivity.this, mHomeModel.publicServiceTypeList, position); mServiceTypeListview.setAdapter(mC1PublishOrderAdapter); mClose.setVisibility(View.GONE); mArrowImage.setImageResource(R.drawable.b3_arrow_down); AnimationUtil.backAnimationFromBottom(mServiceTypeListview); Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); mServiceTypeView.setVisibility(View.GONE); } }; mHandler.sendEmptyMessageDelayed(0, 200); } else { mTitle.setText(mServiceTypeList.get(position).title); mServiceTypeId = mServiceTypeList.get(position).id; mC1PublishOrderAdapter = new C1_PublishOrderAdapter(C1_PublishOrderActivity.this, mServiceTypeList, position); mServiceTypeListview.setAdapter(mC1PublishOrderAdapter); mClose.setVisibility(View.GONE); mArrowImage.setImageResource(R.drawable.b3_arrow_down); AnimationUtil.backAnimationFromBottom(mServiceTypeListview); Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); mServiceTypeView.setVisibility(View.GONE); } }; mHandler.sendEmptyMessageDelayed(0, 200); } } }); mTitleView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub if (mServiceTypeView.getVisibility() == View.GONE) { mServiceTypeView.setVisibility(View.VISIBLE); mClose.setVisibility(View.VISIBLE); mArrowImage.setImageResource(R.drawable.b4_arrow_up); AnimationUtil.showAnimationFromTop(mServiceTypeListview); closeKeyBoard(); } else { mClose.setVisibility(View.GONE); mArrowImage.setImageResource(R.drawable.b3_arrow_down); AnimationUtil.backAnimationFromBottom(mServiceTypeListview); Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); mServiceTypeView.setVisibility(View.GONE); } }; mHandler.sendEmptyMessageDelayed(0, 200); } } }); mClose.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub mClose.setVisibility(View.GONE); mArrowImage.setImageResource(R.drawable.b3_arrow_down); AnimationUtil.backAnimationFromBottom(mServiceTypeListview); Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); mServiceTypeView.setVisibility(View.GONE); } }; mHandler.sendEmptyMessageDelayed(0, 200); } }); mPrice.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub if (s.toString().length() > 0) { if (s.toString().substring(0, 1).equals(".")) { s = s.toString().substring(1, s.length()); mPrice.setText(s); } } if (s.toString().length() > 1) { if (s.toString().substring(0, 1).equals("0")) { if (!s.toString().substring(1, 2).equals(".")) { s = s.toString().substring(1, s.length()); mPrice.setText(s); CharSequence charSequencePirce = mPrice.getText(); if (charSequencePirce instanceof Spannable) { Spannable spanText = (Spannable) charSequencePirce; Selection.setSelection(spanText, charSequencePirce.length()); } } } } boolean flag = false; for (int i = 0; i < s.toString().length() - 1; i++) { String getstr = s.toString().substring(i, i + 1); if (getstr.equals(".")) { flag = true; break; } } if (flag) { int i = s.toString().indexOf("."); if (s.toString().length() - 3 > i) { String getstr = s.toString().substring(0, i + 3); mPrice.setText(getstr); CharSequence charSequencePirce = mPrice.getText(); if (charSequencePirce instanceof Spannable) { Spannable spanText = (Spannable) charSequencePirce; Selection.setSelection(spanText, charSequencePirce.length()); } } } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } @Override public void afterTextChanged(Editable s) { // TODO Auto-generated method stub } }); initData(); mHomeModel = new HomeModel(this); mHomeModel.addResponseListener(this); if (mDefaultReceiverId == 0) { mShared = getSharedPreferences(O2OMobileAppConst.USERINFO, 0); mHomeData = mShared.getString("home_data", ""); if ("".equals(mHomeData)) { mHomeModel.getServiceTypeList(); } else { try { servicetypelistResponse response = new servicetypelistResponse(); response.fromJson(new JSONObject(mHomeData)); mHomeModel.publicServiceTypeList = response.services; setServiceTypeAdater(); } catch (JSONException e) { e.printStackTrace(); } } } else { if (service_list != null && !"".equals(service_list)) { try { JSONObject userJson = new JSONObject(service_list); myservicelistResponse response = new myservicelistResponse(); response.fromJson(userJson); for (int i = 0; i < response.services.size(); i++) { SERVICE_TYPE service = new SERVICE_TYPE(); service = response.services.get(i).service_type; mServiceTypeList.add(service); } if (mServiceTypeList.size() > 0) { mTitleView.setEnabled(true); mArrowImage.setVisibility(View.VISIBLE); if (mServiceType != null) { for (int i = 0; i < mServiceTypeList.size(); i++) { if (mServiceType.id == mServiceTypeList.get(i).id) { mC1PublishOrderAdapter = new C1_PublishOrderAdapter(this, mServiceTypeList, i); mServiceTypeListview.setAdapter(mC1PublishOrderAdapter); mTitle.setText(mServiceTypeList.get(i).title); mServiceTypeId = mServiceTypeList.get(i).id; break; } } } else { mC1PublishOrderAdapter = new C1_PublishOrderAdapter(this, mServiceTypeList); mServiceTypeListview.setAdapter(mC1PublishOrderAdapter); mTitle.setText(getString(R.string.select_service)); } } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { mShared = getSharedPreferences(O2OMobileAppConst.USERINFO, 0); mHomeData = mShared.getString("home_data", ""); if ("".equals(mHomeData)) { mHomeModel.getServiceTypeList(); } else { try { servicetypelistResponse response = new servicetypelistResponse(); response.fromJson(new JSONObject(mHomeData)); mHomeModel.publicServiceTypeList = response.services; setServiceTypeAdater(); } catch (JSONException e) { e.printStackTrace(); } } } } mLocationInfoModel = new LocationInfoModel(this); mLocationInfoModel.addResponseListener(this); mLocationInfoModel.get(); mOrderPublishModel = new OrderPublishModel(this); mOrderPublishModel.addResponseListener(this); //?? CharSequence charSequencePirce = mPrice.getText(); if (charSequencePirce instanceof Spannable) { Spannable spanText = (Spannable) charSequencePirce; Selection.setSelection(spanText, charSequencePirce.length()); } CharSequence charSequenceLocation = mLocation.getText(); if (charSequenceLocation instanceof Spannable) { Spannable spanText = (Spannable) charSequenceLocation; Selection.setSelection(spanText, charSequenceLocation.length()); } mVoice.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub if (event.getAction() == MotionEvent.ACTION_DOWN) { closeKeyBoard(); mVoice.setKeepScreenOn(true); mMaxTime = MAX_TIME; mVoiceView.setVisibility(View.VISIBLE); mAnimationDrawable.start(); startRecording(); } else if (event.getAction() == MotionEvent.ACTION_UP) { mVoice.setKeepScreenOn(false); mVoiceView.setVisibility(View.GONE); mAnimationDrawable.stop(); if (mMaxTime > 28) { mVoice.setEnabled(false); Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); stopRecording(); mVoice.setEnabled(true); } }; mHandler.sendEmptyMessageDelayed(0, 500); } else { stopRecording(); } } else if (event.getAction() == MotionEvent.ACTION_CANCEL) { mVoice.setKeepScreenOn(false); mVoiceView.setVisibility(View.GONE); mAnimationDrawable.stop(); if (mMaxTime > 28) { mVoice.setEnabled(false); Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); stopRecording(); mVoice.setEnabled(true); } }; mHandler.sendEmptyMessageDelayed(0, 500); } else { stopRecording(); } } else if (event.getAction() == MotionEvent.ACTION_MOVE) { mVoice.getParent().requestDisallowInterceptTouchEvent(true); } return false; } }); mVoicePlay.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub if (mPlayer == null) { File file = new File(mFileName); if (file.exists()) { mPlayer = new MediaPlayer(); mVoicePlay.setBackgroundResource(R.anim.record_animation); mAnimationDrawable2 = (AnimationDrawable) mVoicePlay.getBackground(); mAnimationDrawable2.setOneShot(false); mAnimationDrawable2.start(); try { mPlayer.setDataSource(mFileName); mPlayer.prepare(); mPlayer.start(); mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { mp.reset(); mPlayer = null; mVoicePlay.setBackgroundResource(R.drawable.b5_play_btn); mAnimationDrawable2.stop(); } }); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { Toast.makeText(C1_PublishOrderActivity.this, getString(R.string.file_does_not_exist), Toast.LENGTH_SHORT).show(); } } else { mPlayer.release(); mPlayer = null; mVoicePlay.setBackgroundResource(R.drawable.b5_play_btn); mAnimationDrawable2.stop(); } } }); mVoiceReset.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub if (mPlayer != null) { mPlayer.release(); mPlayer = null; mVoicePlay.setBackgroundResource(R.drawable.b5_play_btn); mAnimationDrawable2.stop(); } File file = new File(mFileName); if (file.exists()) { file.delete(); } mVoice.setVisibility(View.VISIBLE); mVoicePlay.setVisibility(View.GONE); mVoiceReset.setVisibility(View.GONE); } }); mPublish.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub File file = new File(newFileName()); int duration = 0; if (file.exists()) { MediaPlayer mp = MediaPlayer.create(C1_PublishOrderActivity.this, Uri.parse(mFileName)); if (null != mp) { duration = mp.getDuration();//? ms mp.release(); } if (duration % 1000 > 500) { duration = duration / 1000 + 1; } else { duration = duration / 1000; } } else { file = null; } int num = 0; try { // ?? Date date = new Date(); Date date1 = mFormat.parse(mFormat.format(date)); Date date2 = mFormat.parse(mTime.getText().toString()); num = date2.compareTo(date1); if (num < 0) { long diff = date1.getTime() - date2.getTime(); long mins = diff / (1000 * 60); if (mins < 3) { num = 1; } } } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (mServiceTypeId == 0) { ToastView toast = new ToastView(C1_PublishOrderActivity.this, getString(R.string.select_service)); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); } else if (mPrice.getText().toString().equals("")) { ToastView toast = new ToastView(C1_PublishOrderActivity.this, getString(R.string.price_range)); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); } else if (mPrice.getText().toString().equals("0.")) { ToastView toast = new ToastView(C1_PublishOrderActivity.this, getString(R.string.right_price)); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); } else if (mTime.getText().toString().equals("")) { ToastView toast = new ToastView(C1_PublishOrderActivity.this, getString(R.string.appoint_time)); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); } else if (num < 0) { ToastView toast = new ToastView(C1_PublishOrderActivity.this, getString(R.string.wrong_appoint_time_hint)); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); } else if (mLocation.getText().toString().equals("")) { ToastView toast = new ToastView(C1_PublishOrderActivity.this, getString(R.string.appoint_location_hint)); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); } else { mOrderPublishModel.publish(mPrice.getText().toString(), mTime.getText().toString(), mLocation.getText().toString(), mText.getText().toString(), file, mServiceTypeId, mDefaultReceiverId, duration); } } }); }
From source file:cn.sinobest.jzpt.framework.utils.string.StringUtils.java
/** * HTML//from w ww. j av a 2s . c o m */ public static CharSequence escapeHtml(CharSequence s, boolean unicode) { if (unicode) return StringEscapeUtils.escapeHtml3(s.toString()); StringBuilder sb = new StringBuilder(s.length() + 16); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); int n = htmlEscEntities.indexOf(c); if (n > -1) { sb.append(htmlEscapeSequence[n]); } else { sb.append(c); } } return sb.length() == s.length() ? s : sb.toString();// string }
From source file:br.msf.commons.text.EnhancedStringBuilder.java
public EnhancedStringBuilder replace(final CharSequence paramName, final Object replacement, final String startDelimiter, final String endDelimiter) { if (CharSequenceUtils.isEmptyOrNull(paramName) || this.isEmpty()) { return this; }//www . j ava2 s.co m // TODO : cross-reference resolving, when has delimiters // merge delimiters on the param key, if applicable int keyLen = paramName.length() + length(startDelimiter, endDelimiter); final String key = new StringBuilder(keyLen).append(startDelimiter).append(paramName).append(endDelimiter) .toString(); // get the param value as a String, to do the replacement final CharSequence value = format(replacement); int idx = indexOf(key); while (idx >= 0) { replace(idx, idx + key.length(), value); idx = indexOf(key, idx + value.length()); } return this; }
From source file:org.shredzone.cilla.web.tag.FormatTag.java
@Override public int doEndTag() throws JspException { CharSequence result; TextFormat txtFormat;//from www. j a v a 2 s.com if (text != null && text instanceof FormattedText) { if (format != null) { throw new IllegalArgumentException("text contains FormattedText, format must not be set"); } result = ((FormattedText) text).getText(); txtFormat = ((FormattedText) text).getFormat(); } else { if (format != null && format instanceof TextFormat) { txtFormat = (TextFormat) format; } else if (format != null) { txtFormat = TextFormat.valueOf(format.toString()); } else if (text == null) { // if no text and no format was set, render the body as HTML txtFormat = TextFormat.HTML; } else { throw new IllegalArgumentException("format not set"); } if (text != null) { result = text.toString(); } else if (bodyContent != null) { result = bodyContent.toString().trim(); } else { result = ""; } } if (result == null) result = ""; result = textFormatter.format(result, txtFormat, () -> linkService.linkTo().page(page)); if (stripHtml) { result = textFormatter.stripHtml(result); } if (truncate != null && result.length() > truncate) { StringBuilder trunc = new StringBuilder(result); int truncpos = trunc.lastIndexOf(" ", truncate); if (truncpos < truncate - 30) { truncpos = truncate; } trunc.setLength(truncpos); trunc.append("\u2026"); result = trunc; } if (var != null) { TagUtils.setScopedAttribute(pageContext, var, result, scope); } else { try { pageContext.getOut().print(result); } catch (IOException ex) { throw new JspException(ex); } } return EVAL_PAGE; }