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

The following examples show how to use android.text.TextUtils#getTrimmedLength() . 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 want to check out the right sidebar which shows the related API usage.
Example 1
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
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 3
/**
 * 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 Project: delion   File: EditorFieldModel.java    License: 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 5
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 6
Source Project: imsdk-android   File: MySearchView.java    License: 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 7
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 8
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 Project: zen4android   File: SearchView.java    License: 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 10
Source Project: letv   File: TabPageIndicator.java    License: 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 11
Source Project: coursera-android   File: BrowserProvider.java    License: 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 12
/**
 * 暂停广告获取成功 去显�?
 */
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 13
Source Project: talk-android   File: TextChipsEditView.java    License: 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 14
Source Project: coursera-android   File: BrowserProvider.java    License: 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 15
Source Project: Pioneer   File: Texts.java    License: 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 Project: android_9.0.0_r45   File: SearchDialog.java    License: Apache License 2.0 4 votes vote down vote up
private boolean isEmpty(AutoCompleteTextView actv) {
    return TextUtils.getTrimmedLength(actv.getText()) == 0;
}
 
Example 17
/**
 * 启动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 18
Source Project: zhangshangwuda   File: SearchView.java    License: 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 19
Source Project: SimplifyReader   File: PluginImageAD.java    License: 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 20
Source Project: android_9.0.0_r45   File: SearchManager.java    License: 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();
}