Example usage for android.text TextUtils equals

List of usage examples for android.text TextUtils equals

Introduction

In this page you can find the example usage for android.text TextUtils equals.

Prototype

public static boolean equals(CharSequence a, CharSequence b) 

Source Link

Document

Returns true if a and b are equal, including if they are both null.

Usage

From source file:com.google.blockly.model.BlocklyCategory.java

/**
 * Read the full definition of the category's contents in from XML.
 *
 * @param parser The {@link XmlPullParser} to read from.
 * @param factory The {@link BlockFactory} to use to generate blocks from their names.
 *
 * @return A new {@link BlocklyCategory} with the contents given by the XML.
 * @throws BlockLoadingException If any error occurs with the input. It may wrap an IOException
 *                               or XmlPullParserException as a root cause.
 *///from ww w  .j  a v  a  2 s. com
public static BlocklyCategory fromXml(XmlPullParser parser, BlockFactory factory) throws BlockLoadingException {
    try {
        BlocklyCategory result;
        String customType = parser.getAttributeValue("", "custom");
        if (CATEGORY_FACTORIES.containsKey(customType)) {
            result = CATEGORY_FACTORIES.get(customType).obtainCategory(customType);
        } else {
            result = new BlocklyCategory();
        }
        result.mCategoryName = parser.getAttributeValue("", "name");
        result.mCustomType = parser.getAttributeValue("", "custom");
        result.mIsVariableCategory = result.mCustomType != null
                && TextUtils.equals("VARIABLE", result.mCustomType.toUpperCase());
        result.mIsFunctionCategory = result.mCustomType != null
                && TextUtils.equals("FUNCTION", result.mCustomType.toUpperCase());
        String colourAttr = parser.getAttributeValue("", "colour");
        if (!TextUtils.isEmpty(colourAttr)) {
            try {
                result.mColor = ColorUtils.parseColor(colourAttr, TEMP_IO_THREAD_FLOAT_ARRAY);
            } catch (ParseException e) {
                Log.w(TAG, "Invalid toolbox category colour \"" + colourAttr + "\"");
            }
        }
        int eventType = parser.next();
        while (eventType != XmlPullParser.END_DOCUMENT) {
            String tagname = parser.getName();
            switch (eventType) {
            case XmlPullParser.START_TAG:
                if (parser.getName().equalsIgnoreCase("category")) {
                    result.addSubcategory(BlocklyCategory.fromXml(parser, factory));
                } else if (parser.getName().equalsIgnoreCase("block")) {
                    result.addItem(new BlockItem(factory.fromXml(parser)));
                } else if (parser.getName().equalsIgnoreCase("shadow")) {
                    throw new IllegalArgumentException("Shadow blocks may not be top level toolbox blocks.");
                }
                break;
            case XmlPullParser.END_TAG:
                if (tagname.equalsIgnoreCase("category")) {
                    return result;
                }
                break;
            default:
                break;
            }
            eventType = parser.next();
        }
        return result;
    } catch (IOException | XmlPullParserException e) {
        throw new BlockLoadingException(e);
    }
}

From source file:com.taobao.weex.utils.WXUtils.java

public static float parseFloat(String value) {
    try {/* w ww  .j a  v a2  s. com*/
        if (!TextUtils.isEmpty(value) && !TextUtils.equals(value, "null")) {
            return Float.parseFloat(value);
        } else {
            if (WXEnvironment.isApkDebugable()) {
                WXLogUtils.e("WXUtils parseFloat illegal value is " + value);
            }
        }
    } catch (NumberFormatException e) {
        if (WXEnvironment.isApkDebugable()) {
            WXLogUtils.e(WXLogUtils.getStackTrace(e));
        }
    }
    return 0;
}

From source file:com.markupartist.sthlmtraveling.utils.DateTimeUtil.java

/**
 * Formats the passed display time to something translated and human readable.
 *
 * @param displayTime The display time, can be null, Nu, HH:MM or in the M min.
 * @param context     A contect//from w ww  .  j  ava2  s .c o  m
 * @return
 */
public static CharSequence formatDisplayTime(@Nullable String displayTime, @NonNull Context context) {
    // time str can be "Nu", "2 min" or in the "12:00" format, and possible some unknown
    // ones as well.

    // Maybe we should use some memoization func for this.

    // Catch when we should show "Now"
    if (TextUtils.isEmpty(displayTime) || TextUtils.equals(displayTime, "0 min")
            || TextUtils.equals(displayTime, "Nu")) {
        return context.getString(R.string.now);
    }
    // Catch "2 min"
    if (displayTime.contains("min")) {
        String minutes = displayTime.replace(" min", "");
        // Try to convert minutes to millis.
        try {
            long minutesConverted = Long.valueOf(minutes);
            return formatShortDuration(context.getResources(), minutesConverted * 60000);
        } catch (NumberFormatException e) {
            return displayTime;
        }
    }
    // Catch the "HH:MM" format.
    try {
        Date date = HOUR_MINUTE_FORMAT.parse(displayTime);
        return DateFormat.getTimeFormat(context).format(date);
    } catch (ParseException e) {
        return displayTime;
    }
}

From source file:com.google.android.gms.nearby.messages.samples.hellobeacons.MainActivity.java

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    if (TextUtils.equals(key, Utils.KEY_CACHED_MESSAGES)) {
        mNearbyMessagesList.clear();//from   w  w w.jav  a2s . co  m
        mNearbyMessagesList.addAll(Utils.getCachedMessages(this));
        mNearbyMessagesArrayAdapter.notifyDataSetChanged();
    }
}

From source file:com.example.android.uamp.utils.QueueHelper.java

/**
 * Determine if two queues contain identical media id's in order.
 *
 * @param list1 containing {@link MediaSessionCompat.QueueItem}'s
 * @param list2 containing {@link MediaSessionCompat.QueueItem}'s
 * @return boolean indicating whether the queue's match
 *//* ww w .j  a v  a  2 s  .  c  om*/
public static boolean equals(List<MediaSessionCompat.QueueItem> list1,
        List<MediaSessionCompat.QueueItem> list2) {
    if (list1 == list2) {
        return true;
    }
    if (list1 == null || list2 == null) {
        return false;
    }
    if (list1.size() != list2.size()) {
        return false;
    }
    for (int i = 0; i < list1.size(); i++) {
        if (list1.get(i).getQueueId() != list2.get(i).getQueueId()) {
            return false;
        }
        if (!TextUtils.equals(list1.get(i).getDescription().getMediaId(),
                list2.get(i).getDescription().getMediaId())) {
            return false;
        }
    }
    return true;
}

From source file:com.radiofarda.istgah.utils.QueueHelper.java

/**
 * Determine if queue item matches the currently playing queue item
 *
 * @param context   for retrieving the {@link MediaControllerCompat}
 * @param queueItem to compare to currently playing {@link MediaSessionCompat.QueueItem}
 * @return boolean indicating whether queue item matches currently playing queue item
 *///  w  ww.j a  va2 s .  com
public static boolean isQueueItemPlaying(Context context, MediaSessionCompat.QueueItem queueItem) {
    // Queue item is considered to be playing or paused based on both the controller's
    // current media id and the controller's active queue item id
    MediaControllerCompat controller = ((FragmentActivity) context).getSupportMediaController();
    if (controller != null && controller.getPlaybackState() != null) {
        long currentPlayingQueueId = controller.getPlaybackState().getActiveQueueItemId();
        String currentPlayingMediaId = controller.getMetadata().getDescription().getMediaId();
        String itemMusicId = queueItem.getDescription().getMediaId();
        if (queueItem.getQueueId() == currentPlayingQueueId && currentPlayingMediaId != null
                && TextUtils.equals(currentPlayingMediaId, itemMusicId)) {
            return true;
        }
    }
    return false;
}

From source file:com.jefftharris.passwdsafe.PreferencesFragment.java

@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
    switch (key) {
    case Preferences.PREF_FILE_DIR: {
        File pref = Preferences.getFileDirPref(prefs);
        if (pref == null) {
            itsFileDirPref.setText(null);
            itsFileDirPref.setSummary(null);
            break;
        }//from w  ww  . jav  a2 s .  c  o  m
        if (TextUtils.isEmpty(pref.toString())) {
            pref = new File(Preferences.PREF_FILE_DIR_DEF);
            itsFileDirPref.setText(pref.toString());
        }
        if (!TextUtils.equals(pref.toString(), itsFileDirPref.getText())) {
            itsFileDirPref.setText(pref.toString());
        }
        itsFileDirPref.setSummary(pref.toString());
        break;
    }
    case Preferences.PREF_DEF_FILE: {
        new DefaultFileResolver(Preferences.getDefFilePref(prefs)).execute();
        break;
    }
    case Preferences.PREF_FILE_CLOSE_TIMEOUT: {
        FileTimeoutPref pref = Preferences.getFileCloseTimeoutPref(prefs);
        itsFileClosePref.setSummary(pref.getDisplayName(getResources()));
        break;
    }
    case Preferences.PREF_FILE_BACKUP: {
        FileBackupPref pref = Preferences.getFileBackupPref(prefs);
        itsFileBackupPref.setSummary(pref.getDisplayName(getResources()));
        break;
    }
    case Preferences.PREF_PASSWD_ENC: {
        itsPasswdEncPref.setSummary(Preferences.getPasswordEncodingPref(prefs));
        break;
    }
    case Preferences.PREF_PASSWD_EXPIRY_NOTIF: {
        PasswdExpiryNotifPref pref = Preferences.getPasswdExpiryNotifPref(prefs);
        Resources res = getResources();
        itsPasswdExpiryNotifPref.setSummary(pref.getDisplayName(res));
        break;
    }
    case Preferences.PREF_PASSWD_DEFAULT_SYMS: {
        String val = Preferences.getPasswdDefaultSymbolsPref(prefs);
        itsPasswdDefaultSymsPref.setSummary(getString(R.string.symbols_used_by_default, val));
        break;
    }
    case Preferences.PREF_RECORD_SORT_ORDER: {
        RecordSortOrderPref pref = Preferences.getRecordSortOrderPref(prefs);
        Resources res = getResources();
        itsRecordSortOrderPref.setSummary(pref.getDisplayName(res));
        break;
    }
    case Preferences.PREF_DISPLAY_THEME_LIGHT: {
        ApiCompat.recreateActivity(getActivity());
        break;
    }
    }
}

From source file:com.example.android.spotifystreamer.CastPlayback.java

private void loadMedia(String mediaId, boolean autoPlay)
        throws TransientNetworkDisconnectionException, NoConnectionException, JSONException {
    String musicId = MediaIDHelper.extractMusicIDFromMediaID(mediaId);
    android.media.MediaMetadata track = mMusicProvider.getMusic(musicId);
    if (track == null) {
        throw new IllegalArgumentException("Invalid mediaId " + mediaId);
    }// w ww .  j  a v a2  s.c  o m
    if (!TextUtils.equals(mediaId, mCurrentMediaId)) {
        mCurrentMediaId = mediaId;
        mCurrentPosition = 0;
    }
    JSONObject customData = new JSONObject();
    customData.put(ITEM_ID, mediaId);
    MediaInfo media = toCastMediaMetadata(track, customData);
    mCastManager.loadMedia(media, autoPlay, mCurrentPosition, customData);
}

From source file:com.android.settingslib.drawer.SettingsDrawerActivity.java

private boolean isTopLevelTile(Intent intent) {
    final ComponentName componentName = intent.getComponent();
    if (componentName == null) {
        return false;
    }//from w w  w.  ja  v  a2  s.  c om
    // Look for a tile that has the same component as incoming intent
    final List<DashboardCategory> categories = getDashboardCategories();
    for (DashboardCategory category : categories) {
        for (Tile tile : category.tiles) {
            if (TextUtils.equals(tile.intent.getComponent().getClassName(), componentName.getClassName())) {
                if (DEBUG) {
                    Log.d(TAG, "intent is for top level tile: " + tile.title);
                }
                return true;
            }
        }
    }
    if (DEBUG) {
        Log.d(TAG, "Intent is not for top level settings " + intent);
    }
    return false;
}

From source file:com.appdevper.mediaplayer.app.CastPlayback.java

private void loadMedia(String mediaId, boolean autoPlay)
        throws TransientNetworkDisconnectionException, NoConnectionException, JSONException {

    MediaMetadataCompat track = mMusicProvider.getMusic(mediaId);
    if (track == null) {
        throw new IllegalArgumentException("Invalid mediaId " + mediaId);
    }//from ww  w  .j a  va2 s.  c  o m
    if (!TextUtils.equals(mediaId, mCurrentMediaId)) {
        mCurrentMediaId = mediaId;
        mCurrentPosition = 0;
    }
    JSONObject customData = new JSONObject();
    customData.put(ITEM_ID, mediaId);
    MediaInfo media = toCastMediaMetadata(track, customData);
    mCastManager.loadMedia(media, autoPlay, mCurrentPosition, customData);
}