本文整理汇总了Java中android.text.TextUtils类的典型用法代码示例。如果您正苦于以下问题:Java TextUtils类的具体用法?Java TextUtils怎么用?Java TextUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TextUtils类属于android.text包,在下文中一共展示了TextUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getNetworkTypeName
import android.text.TextUtils; //导入依赖的package包/类
public static String getNetworkTypeName(Context context) {
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo;
String type = NETWORK_TYPE_DISCONNECT;
if (manager == null || (networkInfo = manager.getActiveNetworkInfo()) == null) {
return type;
}
if (networkInfo.isConnected()) {
String typeName = networkInfo.getTypeName();
if ("WIFI".equalsIgnoreCase(typeName)) {
type = NETWORK_TYPE_WIFI;
} else if ("MOBILE".equalsIgnoreCase(typeName)) {
String proxyHost = android.net.Proxy.getDefaultHost();
type = TextUtils.isEmpty(proxyHost) ? (isFastMobileNetwork(context) ? NETWORK_TYPE_3G : NETWORK_TYPE_2G)
: NETWORK_TYPE_WAP;
} else {
type = NETWORK_TYPE_UNKNOWN;
}
}
return type;
}
示例2: showFirstUserAvatarOnImageView
import android.text.TextUtils; //导入依赖的package包/类
/**
* Отображение аватара первого в списке пользователя на ImageView.
* Если у пользователя нет аватара, то будет отображено изображение
* неизвестного пользователя
*
* @param owners массив пользователей
* @param imageView вьюв
*/
private void showFirstUserAvatarOnImageView(List<Owner> owners, ImageView imageView) {
if (owners == null || owners.size() == 0 || TextUtils.isEmpty(owners.get(0).getMaxSquareAvatar())) {
PicassoInstance.with()
.load(R.drawable.ic_avatar_unknown)
.tag(Constants.PICASSO_TAG)
.into(imageView);
} else {
String url = owners.get(0).getMaxSquareAvatar();
PicassoInstance.with()
.load(url)
.tag(Constants.PICASSO_TAG)
.transform(transformation)
.into(imageView);
}
}
示例3: AssetRelationshipHelper
import android.text.TextUtils; //导入依赖的package包/类
/**
* Setup the helper and validate the input params.
*
* @param context Context
* @param clientPackageName The client app's package name
* @param sourceAssetStatements Asset statements from the 'source' (client) app
* @param targetAssetStatements Asset statements from the various 'targets' referenced by the
* 'source' (client) app
*/
public AssetRelationshipHelper(@NonNull Context context, @NonNull String clientPackageName,
@NonNull List<AssetStatement> sourceAssetStatements, @NonNull List<AssetStatement>
targetAssetStatements) {
require(context, notNullValue());
require(!TextUtils.isEmpty(clientPackageName), "mClientPackageName must not be null or "
+ "empty");
require(sourceAssetStatements, notNullValue());
require(targetAssetStatements, notNullValue());
this.mContext = context.getApplicationContext();
this.mClientPackageName = clientPackageName;
this.mSourceAssetStatements = sourceAssetStatements;
this.mTargetAssetStatements = targetAssetStatements;
}
示例4: getSanitizedUserAgent
import android.text.TextUtils; //导入依赖的package包/类
/**
* Ensures that the default header will pass OkHttp3's checks for header values.
*
* <p>See #2331.
*/
@VisibleForTesting
static String getSanitizedUserAgent() {
String defaultUserAgent = System.getProperty("http.agent");
if (TextUtils.isEmpty(defaultUserAgent)) {
return defaultUserAgent;
}
int length = defaultUserAgent.length();
StringBuilder sb = new StringBuilder(defaultUserAgent.length());
for (int i = 0; i < length; i++) {
char c = defaultUserAgent.charAt(i);
if ((c > '\u001f' || c == '\t') && c < '\u007f') {
sb.append(c);
} else {
sb.append('?');
}
}
return sb.toString();
}
示例5: encode
import android.text.TextUtils; //导入依赖的package包/类
public byte[] encode() {
JSONObject var1 = new JSONObject();
try {
if (!TextUtils.isEmpty(this.getContact_id())) {
var1.put("contact_id", this.contact_id);
}
if (this.getJSONUserInfo() != null) {
var1.put("bribery", this.getJSONUserInfo());
}
} catch (JSONException var4) {
var4.printStackTrace();
}
try {
return var1.toString().getBytes("UTF-8");
} catch (UnsupportedEncodingException var3) {
var3.printStackTrace();
return null;
}
}
示例6: trackPurchase
import android.text.TextUtils; //导入依赖的package包/类
/**
* Manually track purchase event with currency code in your application. It is advised to use
* {@link Leanplum#trackGooglePlayPurchase} instead for in-app purchases.
*
* @param event Name of the event.
* @param value The value of the event. Can be price.
* @param currencyCode The currency code corresponding to the price.
* @param params Key-value pairs with metrics or data associated with the event. Parameters can be
* strings or numbers. You can use up to 200 different parameter names in your app.
*/
public static void trackPurchase(final String event, double value, String currencyCode,
Map<String, ?> params) {
try {
if (TextUtils.isEmpty(event)) {
Log.w("trackPurchase - Empty event parameter provided.");
}
final Map<String, String> requestArgs = new HashMap<>();
if (!TextUtils.isEmpty(currencyCode)) {
requestArgs.put(Constants.Params.IAP_CURRENCY_CODE, currencyCode);
}
LeanplumInternal.track(event, value, null, params, requestArgs);
} catch (Throwable t) {
Log.e("trackPurchase - Failed to track purchase event.");
Util.handleException(t);
}
}
示例7: PersistentCookieStore
import android.text.TextUtils; //导入依赖的package包/类
/**
* Construct a persistent cookie store.
*
* @param context Context to attach cookie store to
*/
public PersistentCookieStore(Context context) {
cookiePrefs = context.getSharedPreferences(COOKIE_PREFS, 0);
cookies = new ConcurrentHashMap<String, Cookie>();
// Load any previously stored cookies into the store
String storedCookieNames = cookiePrefs.getString(COOKIE_NAME_STORE, null);
if (storedCookieNames != null) {
String[] cookieNames = TextUtils.split(storedCookieNames, ",");
for (String name : cookieNames) {
String encodedCookie = cookiePrefs.getString(COOKIE_NAME_PREFIX + name, null);
if (encodedCookie != null) {
Cookie decodedCookie = decodeCookie(encodedCookie);
if (decodedCookie != null) {
cookies.put(name, decodedCookie);
}
}
}
// Clear out expired cookies
clearExpired(new Date());
}
}
示例8: getSketch
import android.text.TextUtils; //导入依赖的package包/类
private PApplet getSketch(String stringExtra) {
if (TextUtils.isEmpty(stringExtra)) {
return null;
}
if (getString(R.string.simple_sketch_one).equals(stringExtra)) {
return new SimpleSketchOne(this);
} else if (getString(R.string.simple_sketch_two).equals(stringExtra)) {
return new SimpleSketchTwo(this);
} else if (getString(R.string.sensor_sketch).equals(stringExtra)) {
return new SensorSketch(this);
} else if (getString(R.string.box2d_sketch).equals(stringExtra)) {
return new Box2DSketch(this);
} else if (getString(R.string.wallpapers_sketch).equals(stringExtra)) {
return new WallpapersSketch(this);
} else if (getString(R.string.compass_sketch).equals(stringExtra)) {
return new CompassSketch(this);
} else if (getString(R.string.location_sketch).equals(stringExtra)) {
return new LocationSketch(this);
}
return null;
}
示例9: recycle
import android.text.TextUtils; //导入依赖的package包/类
public void recycle(ViewBase v) {
if (null != v) {
String type = v.getViewType();
if (!TextUtils.isEmpty(type)) {
v.reset();
List<ViewBase> vList = mViewCache.get(type);
if (null == vList) {
vList = new LinkedList<>();
mViewCache.put(type, vList);
}
vList.add(v);
} else {
Log.e(TAG, "recycle type invalidate:" + type);
RuntimeException here = new RuntimeException("here");
here.fillInStackTrace();
Log.w(TAG, "Called: " + this, here);
}
}
}
示例10: appleStyleAfterCreated
import android.text.TextUtils; //导入依赖的package包/类
@Override
protected void appleStyleAfterCreated(WXEditText editText) {
super.appleStyleAfterCreated(editText);
String rowsStr = (String) getDomObject().getStyles().get(Constants.Name.ROWS);
int rows = TextAreaEditTextDomObject.DEFAULT_ROWS;
try{
if(!TextUtils.isEmpty(rowsStr)) {
rows = Integer.parseInt(rowsStr);
}
}catch (NumberFormatException e){
//ignore
e.printStackTrace();
}
editText.setLines(rows);
editText.setMinLines(rows);
}
示例11: setBorderColor
import android.text.TextUtils; //导入依赖的package包/类
public void setBorderColor(String key, String borderColor) {
if (!TextUtils.isEmpty(borderColor)) {
int colorInt = WXResourceUtils.getColor(borderColor);
if (colorInt != Integer.MIN_VALUE) {
switch (key) {
case Constants.Name.BORDER_COLOR:
getOrCreateBorder().setBorderColor(Spacing.ALL, colorInt);
break;
case Constants.Name.BORDER_TOP_COLOR:
getOrCreateBorder().setBorderColor(Spacing.TOP, colorInt);
break;
case Constants.Name.BORDER_RIGHT_COLOR:
getOrCreateBorder().setBorderColor(Spacing.RIGHT, colorInt);
break;
case Constants.Name.BORDER_BOTTOM_COLOR:
getOrCreateBorder().setBorderColor(Spacing.BOTTOM, colorInt);
break;
case Constants.Name.BORDER_LEFT_COLOR:
getOrCreateBorder().setBorderColor(Spacing.LEFT, colorInt);
break;
}
}
}
}
示例12: checkMD5
import android.text.TextUtils; //导入依赖的package包/类
public static boolean checkMD5(String md5, File updateFile) {
if (TextUtils.isEmpty(md5) || updateFile == null) {
Log.e(TAG, "MD5 string empty or updateFile null");
return false;
}
String calculatedDigest = md5(updateFile);
if (calculatedDigest == null) {
Log.e(TAG, "calculatedDigest null");
return false;
}
Log.v(TAG, "Calculated digest: " + calculatedDigest);
Log.v(TAG, "Provided digest: " + md5);
return calculatedDigest.equalsIgnoreCase(md5);
}
示例13: addFragments
import android.text.TextUtils; //导入依赖的package包/类
public void addFragments(Fragment... fragments) {
if (fragments != null && fragments.length != 0) {
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
for (Fragment fragment : fragments) {
if (fragment instanceof LetvFragmentListener) {
LetvFragmentListener listener = (LetvFragmentListener) fragment;
String tag = listener.getTagName();
if (!TextUtils.isEmpty(tag)) {
int fragmentRes = listener.getContainerId();
if (fragmentRes > 0 && fragmentManager.findFragmentByTag(tag) == null) {
transaction.add(fragmentRes, fragment, tag);
}
}
}
}
try {
transaction.commitAllowingStateLoss();
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例14: removeDupes
import android.text.TextUtils; //导入依赖的package包/类
private void removeDupes() {
final ArrayList<CharSequence> suggestions = mSuggestions;
if (suggestions.size() < 2) return;
int i = 1;
// Don't cache suggestions.size(), since we may be removing items
while (i < suggestions.size()) {
final CharSequence cur = suggestions.get(i);
// Compare each candidate with each previous candidate
for (int j = 0; j < i; j++) {
CharSequence previous = suggestions.get(j);
if (TextUtils.equals(cur, previous)) {
removeFromSuggestions(i);
i--;
break;
}
}
i++;
}
}
示例15: loadView
import android.text.TextUtils; //导入依赖的package包/类
@Override
public void loadView(String lowUrl, String url, int defaultResID) {
try {
mThumbnailPath = null;
mThumbnailUrl = url;
mLowThumbnailUrl = url;
mDefaultResID = defaultResID;
if (!TextUtils.isEmpty(mThumbnailUrl)
&& (mThumbnailUrl.startsWith(FrescoController.HTTP_PERFIX)
|| mThumbnailUrl.startsWith(FrescoController.HTTPS_PERFIX))) {
this.getHierarchy().setPlaceholderImage(defaultResID);
this.setSourceController();
return;
}
this.getHierarchy().setPlaceholderImage(defaultResID);
this.setResourceController();
}catch (OutOfMemoryError e){
e.printStackTrace();
}
}