Java Code Examples for android.text.TextUtils#getTrimmedLength()

The following examples show how to use android.text.TextUtils#getTrimmedLength() . 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: AbstractCustomVirtualView.java    From input-samples with Apache License 2.0 6 votes vote down vote up
protected AccessibilityNodeInfo provideAccessibilityNodeInfo(View parent, Context context) {
    final AccessibilityNodeInfo node = AccessibilityNodeInfo.obtain();
    node.setSource(parent, id);
    node.setPackageName(context.getPackageName());
    node.setClassName(getClassName());
    node.setEditable(editable);
    node.setViewIdResourceName(idEntry);
    node.setVisibleToUser(true);
    final Rect absBounds = line.getAbsCoordinates();
    if (absBounds != null) {
        node.setBoundsInScreen(absBounds);
    }
    if (TextUtils.getTrimmedLength(text) > 0) {
        // TODO: Must checked trimmed length because input fields use 8 empty spaces to
        // set width
        node.setText(text);
    }
    return node;
}
 
Example 2
Source File: EditorFieldModel.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Returns true if the field value is valid. Also updates the error message.
 *
 * @return Whether the field value is valid.
 */
public boolean isValid() {
    if (isRequired()
            && (TextUtils.isEmpty(mValue) || TextUtils.getTrimmedLength(mValue) == 0)) {
        mErrorMessage = mRequiredErrorMessage;
        return false;
    }

    if (mValidator != null && !mValidator.isValid(mValue)) {
        mErrorMessage = mInvalidErrorMessage;
        return false;
    }

    mErrorMessage = null;
    return true;
}
 
Example 3
Source File: EditorFieldModel.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Returns true if the field value is valid. Also updates the error message.
 *
 * @return Whether the field value is valid.
 */
public boolean isValid() {
    if (isRequired()
            && (TextUtils.isEmpty(mValue) || TextUtils.getTrimmedLength(mValue) == 0)) {
        mErrorMessage = mRequiredErrorMessage;
        return false;
    }

    if (mValidator != null && !mValidator.isValid(mValue)) {
        mErrorMessage = mInvalidErrorMessage;
        return false;
    }

    mErrorMessage = null;
    return true;
}
 
Example 4
Source File: AcceleraterService.java    From SimplifyReader with Apache License 2.0 6 votes vote down vote up
private int checkCacheDir(Intent intent) {
	String cachePath =AcceleraterServiceManager.getDefauleSDCardPath();
	if (cachePath != null
			&& TextUtils.getTrimmedLength(cachePath) > 0) {
		File f = new File(cachePath + "/youku/youkudisk/");
		if (!f.exists()) {
			if (mAccServiceManager.getCurrentStatus() == AcceleraterStatus.STARTED) {
				mAccServiceManager.pauseAcc();
			}
			intent.putExtra(AcceleraterServiceManager.RESTRICTBY, "10-无youkudisk文件夹");
			sendBroadcast(intent);
			Logger.d(TAG, "统计失败原因");
			return -1;
		} 
	} else {
		if (mAccServiceManager.getCurrentStatus() == AcceleraterStatus.STARTED) {
			mAccServiceManager.pauseAcc();
		}
		intent.putExtra(AcceleraterServiceManager.RESTRICTBY, "7-获取缓存路径失败:" + cachePath);
		sendBroadcast(intent);
		Logger.d(TAG, "统计失败原因");
		return -1;
	}
	
	return 0;
}
 
Example 5
Source File: MySearchView.java    From imsdk-android with MIT License 5 votes vote down vote up
private void onSubmitQuery() {
    CharSequence query = search_src_text.getText();
    if (query != null && TextUtils.getTrimmedLength(query) > 0) {
        if (mOnQueryChangeListener !=null) {
            mOnQueryChangeListener.onQueryTextSubmit(query.toString());
        }
    }
}
 
Example 6
Source File: SimpleSearchView.java    From SimpleSearchView with Apache License 2.0 5 votes vote down vote up
private void onSubmitQuery() {
    CharSequence submittedQuery = searchEditText.getText();
    if (submittedQuery != null && TextUtils.getTrimmedLength(submittedQuery) > 0) {
        if (onQueryChangeListener == null || !onQueryChangeListener.onQueryTextSubmit(submittedQuery.toString())) {
            closeSearch();
            searchIsClosing = true;
            searchEditText.setText(null);
            searchIsClosing = false;
        }
    }
}
 
Example 7
Source File: SearchView.java    From CSipSimple with GNU General Public License v3.0 5 votes vote down vote up
private void onSubmitQuery() {
    CharSequence query = mQueryTextView.getText();
    if (query != null && TextUtils.getTrimmedLength(query) > 0) {
        if (mOnQueryChangeListener == null
                || !mOnQueryChangeListener.onQueryTextSubmit(query.toString())) {
            if (mSearchable != null) {
                launchQuerySearch(KeyEvent.KEYCODE_UNKNOWN, null, query.toString());
                setImeVisibility(false);
            }
            dismissSuggestions();
        }
    }
}
 
Example 8
Source File: SearchView.java    From zen4android with MIT License 5 votes vote down vote up
private void onSubmitQuery() {
    CharSequence query = mQueryTextView.getText();
    if (query != null && TextUtils.getTrimmedLength(query) > 0) {
        if (mOnQueryChangeListener == null
                || !mOnQueryChangeListener.onQueryTextSubmit(query.toString())) {
            if (mSearchable != null) {
                launchQuerySearch(KeyEvent.KEYCODE_UNKNOWN, null, query.toString());
                setImeVisibility(false);
            }
            dismissSuggestions();
        }
    }
}
 
Example 9
Source File: TabPageIndicator.java    From letv with Apache License 2.0 5 votes vote down vote up
protected int getTabWidth(CharSequence text) {
    if (TextUtils.isEmpty(text) || TextUtils.getTrimmedLength(text) == 0) {
        return 0;
    }
    Pattern p = Pattern.compile("[一-龥]");
    int len = 0;
    for (int i = 0; i < text.length(); i++) {
        char cr = text.charAt(i);
        int i2 = p.matcher(String.valueOf(cr)).matches() ? WOLD_DEFAULT_WIDTH : !Character.isLowerCase(cr) ? (WOLD_DEFAULT_WIDTH / 3) * 2 : WOLD_DEFAULT_WIDTH / 2;
        len += i2;
    }
    return UIsUtils.dipToPx(TitleBar.SHAREBTN_RIGHT_MARGIN) + len;
}
 
Example 10
Source File: BrowserProvider.java    From coursera-android with MIT License 5 votes vote down vote up
/**
 * Provides the title (text line 1) for a browser suggestion, which should be the
 * webpage title. If the webpage title is empty, returns the stripped url instead.
 *
 * @return the title string to use
 */
private String getHistoryTitle() {
    String title = mHistoryCursor.getString(2 /* webpage title */);
    if (TextUtils.isEmpty(title) || TextUtils.getTrimmedLength(title) == 0) {
        title = stripUrl(mHistoryCursor.getString(1 /* url */));
    }
    return title;
}
 
Example 11
Source File: PluginFullScreenPauseAD.java    From SimplifyReader with Apache License 2.0 5 votes vote down vote up
/**
 * 暂停广告获取成功 去显�?
 */
private void showADImageWhenLoaded() {
	if (null != mADClickURL && TextUtils.getTrimmedLength(mADClickURL) > 0) {
		adImageView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Logger.e("PlayFlow", "点击:" + mADClickURL);
				AdvInfo advInfo = getAdvInfo();
				// 用户点击跳转发送CUM
				DisposableStatsUtils.disposeCUM(advInfo);
				dismissPauseAD();
				if (mADClickURL.endsWith(".apk")
						&& IMediaPlayerDelegate.mIDownloadApk != null
						&& mediaPlayerDelegate != null && !Util.isWifi()) {
					creatSelectDownloadDialog(mActivity);
					return;
				}
				new AdvClickProcessor().processAdvClick(mActivity,
						mADClickURL, mAdForward);
			}
		});
	} else {
		adImageView.setOnClickListener(null);
	}
	setVisible(true);
}
 
Example 12
Source File: TextChipsEditView.java    From talk-android with MIT License 5 votes vote down vote up
/**
 * Convenience method: Append the specified text slice to the TextView's
 * display buffer, upgrading it to BufferType.EDITABLE if it was
 * not already editable. Commas are excluded as they are added automatically
 * by the view.
 */
@Override
public void append(CharSequence text, int start, int end) {
    // We don't care about watching text changes while appending.
    if (mTextWatcher != null) {
        removeTextChangedListener(mTextWatcher);
    }
    super.append(text, start, end);
    if (!TextUtils.isEmpty(text) && TextUtils.getTrimmedLength(text) > 0) {
        String displayString = text.toString();

        if (!displayString.trim().endsWith(String.valueOf(COMMIT_CHAR_COMMA))) {
            // We have no separator, so we should add it
            super.append(SEPARATOR, 0, SEPARATOR.length());
            displayString += SEPARATOR;
        }

        if (!TextUtils.isEmpty(displayString)
                && TextUtils.getTrimmedLength(displayString) > 0) {
            mPendingChipsCount++;
            mPendingChips.add(displayString);
        }
    }
    // Put a message on the queue to make sure we ALWAYS handle pending
    // chips.
    if (mPendingChipsCount > 0) {
        postHandlePendingChips();
    }
    mHandler.post(mAddTextWatcher);
}
 
Example 13
Source File: BrowserProvider.java    From coursera-android with MIT License 5 votes vote down vote up
/**
 * Provides the subtitle (text line 2) for a browser suggestion, which should be the
 * webpage url. If the webpage title is empty, then the url should go in the title
 * instead, and the subtitle should be empty, so this would return null.
 *
 * @return the subtitle string to use, or null if none
 */
private String getHistoryUrl() {
    String title = mHistoryCursor.getString(2 /* webpage title */);
    if (TextUtils.isEmpty(title) || TextUtils.getTrimmedLength(title) == 0) {
        return null;
    } else {
        return stripUrl(mHistoryCursor.getString(1 /* url */));
    }
}
 
Example 14
Source File: AbstractCustomVirtualView.java    From input-samples with Apache License 2.0 5 votes vote down vote up
protected AutofillValue getAutofillValue() {
    switch (type) {
        case AUTOFILL_TYPE_TEXT:
            return (TextUtils.getTrimmedLength(text) > 0)
                    ? AutofillValue.forText(text)
                    : null;
        case AUTOFILL_TYPE_DATE:
            return AutofillValue.forDate(date);
        default:
            return null;
    }
}
 
Example 15
Source File: Texts.java    From Pioneer with Apache License 2.0 5 votes vote down vote up
/**
 * null 安全版的 TextUtils.getTrimmedLength
 */
public static int trimmedLength(CharSequence s) {
    if (s == null) {
        return 0;
    }
    return TextUtils.getTrimmedLength(s);
}
 
Example 16
Source File: AcceleraterServiceManager.java    From SimplifyReader with Apache License 2.0 4 votes vote down vote up
/**
 * 启动acc
 * 
 * @param context
 * @return 成功返回0, 失败返回-1或错误码
 */

public int startAcc(Context context) {
	Logger.d(TAG, "startAcc()");
	int flag = 0;
	int port;
	
	if (mCurrentStatus != AcceleraterStatus.INIT) {
		Logger.e(TAG, "startAcc() error : mCurrentStatus = " + mCurrentStatus);
		return -1;
	}
	
	String cachePath = getDefauleSDCardPath();
	if (cachePath != null
			&& TextUtils.getTrimmedLength(cachePath) > 0) {
		File f = new File(cachePath + "/youku/");
		boolean success = true;
		if (!f.exists()) {
			success = f.mkdirs();
		}
		
		if (success) {
			int i = start("--mobile-data-path=" + cachePath
					+ " --mobile-meta-path=" + cachePath + "/youku"
					+ " --android-version=android_"
					+ android.os.Build.VERSION.RELEASE);
			if (i == 0) {
				port = getHttpProxyPort();
				if (port != -1) {
					ACC_PORT = "&myp=" + port;
					mCurrentStatus = AcceleraterStatus.STARTED;
					Logger.d(TAG, "ACC启动成功/PORT地址:" + ACC_PORT);
				} else {
					Logger.d(TAG,
							"ACC启动失败/Accstub.getHttpProxyPort()==-1");
					ACC_PORT = "";
					sFailReason = "6-获取端口号失败";
					flag = -1;
				}
			} else {
				Logger.d(TAG, "ACC启动失败/Accstub.start()==" + i);
				ACC_PORT = "";
				flag = i;
				sFailReason = "11-其他因素失败:" + i;
			}
		} else {
			flag = -1;
			sFailReason = "10-无youkudisk文件夹";
		}
		
	} else {
		Logger.d(TAG, "ACC启动失败 /cachePath:" + cachePath);
		sFailReason = "7-获取缓存路径失败:" + cachePath;
		flag = -1;
	}
	
	Intent intent = new Intent("android.intent.action.DOWNLOAD_TRACKER");
	intent.putExtra("from", FROM_ACC);
	if (flag != 0) {
		intent.putExtra(RESTRICTBY, sFailReason);
		context.sendBroadcast(intent);
		Logger.d(TAG, "统计失败原因");
	} else {
		intent.putExtra(SUCCSTARTP2P, "0-加速器启动成功");
		context.sendBroadcast(intent);
		Logger.d(TAG, "统计启动成功");
	}
	
	return flag;
}
 
Example 17
Source File: SearchView.java    From zhangshangwuda with Apache License 2.0 4 votes vote down vote up
/**
 * Returns true if the text field is empty, or contains only whitespace.
 */
private boolean isEmpty() {
    return TextUtils.getTrimmedLength(getText()) == 0;
}
 
Example 18
Source File: PluginImageAD.java    From SimplifyReader with Apache License 2.0 4 votes vote down vote up
/**
 * 全屏广告获取成功 去显�?
 */
private void showADImageWhenLoaded() {
	if (null != mADClickURL && TextUtils.getTrimmedLength(mADClickURL) > 0) {
		adImageView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Logger.e("PlayFlow", "点击:" + mADClickURL);
				if (isOnClick) {
					return;
				}
				AdvInfo advInfo = getAdvInfo();
				// 用户点击跳转发送CUM
				DisposableStatsUtils.disposeCUM(advInfo);
				isOnClick = true;
				if (mADClickURL.endsWith(".apk")
						&& IMediaPlayerDelegate.mIDownloadApk != null
						&& mediaPlayerDelegate != null) {
					if (!Util.isWifi()) {
						creatSelectDownloadDialog(mActivity);
						return;
					}
					dismissImageAD();
					mediaPlayerDelegate.pluginManager.onLoading();
					mediaPlayerDelegate.startPlayAfterImageAD();
				} else if (mediaPlayerDelegate != null) {
					dismissImageAD();
					mediaPlayerDelegate.pluginManager.onLoaded();
				}
				new AdvClickProcessor().processAdvClick(mActivity,
						mADClickURL, mAdForward);
			}
		});
	} else {
		adImageView.setOnClickListener(null);
	}
	if (StaticsUtil.PLAY_TYPE_LOCAL.equals(mediaPlayerDelegate.videoInfo
			.getPlayType())
			&& mediaPlayerDelegate != null
			&& mediaPlayerDelegate.pluginManager != null) {
		mediaPlayerDelegate.pluginManager.onVideoInfoGetted();
		mediaPlayerDelegate.pluginManager.onChangeVideo();
	}
	if (mActivity.isFinishing()) {
		disposeAdLoss(URLContainer.AD_LOSS_STEP3);
		return;
	}
	if (Profile.PLANTFORM == Plantform.YOUKU && isLand()) {
		// youku客户端播放器不再挤压,横屏view尺寸需要重新初始化
		mActivity.updatePlugin(PLUGIN_SHOW_IMAGE_AD);
	}
	if (UIUtils.hasKitKat()) {
		mActivity.setPluginHolderPaddingZero();
	}
	mActivity.isImageADShowing = true;
	Track.onImageAdStart();
	setVisible(true);
	setVisibility(View.VISIBLE);
	mHandler.postDelayed(new Runnable() {
		@Override
		public void run() {
			startTimer();
		}
	}, 400);
}
 
Example 19
Source File: SearchDialog.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private boolean isEmpty(AutoCompleteTextView actv) {
    return TextUtils.getTrimmedLength(actv.getText()) == 0;
}
 
Example 20
Source File: SearchManager.java    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
/**
 * Similar to {@link #startSearch} but actually fires off the search query after invoking
 * the search dialog.  Made available for testing purposes.
 *
 * @param query The query to trigger.  If empty, request will be ignored.
 * @param launchActivity The ComponentName of the activity that has launched this search.
 * @param appSearchData An application can insert application-specific
 * context here, in order to improve quality or specificity of its own
 * searches.  This data will be returned with SEARCH intent(s).  Null if
 * no extra data is required.
 *
 * @see #startSearch
 */
public void triggerSearch(String query,
                          ComponentName launchActivity,
                          Bundle appSearchData) {
    if (query == null || TextUtils.getTrimmedLength(query) == 0) {
        Log.w(TAG, "triggerSearch called with empty query, ignoring.");
        return;
    }
    startSearch(query, false, launchActivity, appSearchData, false);
    mSearchDialog.launchQuerySearch();
}