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.radiofarda.istgah.playback.LocalPlayback.java

@Override
public void play(QueueItem item) {
    mPlayOnFocusGain = true;//from  w w w .j ava  2 s  . co  m
    tryToGetAudioFocus();
    registerAudioNoisyReceiver();
    String mediaId = item.getDescription().getMediaId();
    boolean mediaHasChanged = !TextUtils.equals(mediaId, mCurrentMediaId);
    if (mediaHasChanged) {
        mCurrentPosition = 0;
        mCurrentMediaId = mediaId;
    }

    if (mState == PlaybackStateCompat.STATE_PAUSED && !mediaHasChanged && mMediaPlayer != null) {
        configMediaPlayerState();
    } else {
        mState = PlaybackStateCompat.STATE_STOPPED;
        relaxResources(false); // release everything except MediaPlayer
        MediaMetadataCompat track = mMusicProvider.getMusic(item.getDescription().getMediaId());

        Uri mediaUri = track.getDescription().getMediaUri();
        try {
            if (mediaUri == null) {
                throw new IOException("The file is not downloaded yet!");
            }
            createMediaPlayerIfNeeded();

            mState = PlaybackStateCompat.STATE_BUFFERING;

            mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
            mMediaPlayer.setDataSource(mediaUri.toString());

            // Starts preparing the media player in the background. When
            // it's done, it will call our OnPreparedListener (that is,
            // the onPrepared() method on this class, since we set the
            // listener to 'this'). Until the media player is prepared,
            // we *cannot* call start() on it!
            mMediaPlayer.prepareAsync();

            // If we are streaming from the internet, we want to hold a
            // Wifi lock, which prevents the Wifi radio from going to
            // sleep while the song is playing.
            mWifiLock.acquire();

            if (mCallback != null) {
                mCallback.onPlaybackStatusChanged(mState);
            }

        } catch (IOException ex) {
            LogHelper.e(TAG, ex, "Exception playing song");
            if (mCallback != null) {
                mCallback.onError(ex.getMessage());
            }
        }
    }
}

From source file:com.example.android.uamp.playback.LocalPlayback.java

@Override
public void play(QueueItem item) {
    mPlayOnFocusGain = true;//from  www  .  j a  va 2  s.  co  m
    tryToGetAudioFocus();
    registerAudioNoisyReceiver();
    String mediaId = item.getDescription().getMediaId();
    boolean mediaHasChanged = !TextUtils.equals(mediaId, mCurrentMediaId);
    if (mediaHasChanged) {
        mCurrentPosition = 0;
        mCurrentMediaId = mediaId;
    }

    if (mState == PlaybackStateCompat.STATE_PAUSED && !mediaHasChanged && mMediaPlayer != null) {
        configMediaPlayerState();
    } else {
        mState = PlaybackStateCompat.STATE_STOPPED;
        relaxResources(false); // release everything except MediaPlayer
        MediaMetadataCompat track = mMusicProvider
                .getMusic(MediaIDHelper.extractMusicIDFromMediaID(item.getDescription().getMediaId()));

        //noinspection ResourceType
        String source = track.getString(MusicProviderSource.CUSTOM_METADATA_TRACK_SOURCE);
        if (source != null) {
            source = source.replaceAll(" ", "%20"); // Escape spaces for URLs
        }

        try {
            createMediaPlayerIfNeeded();

            mState = PlaybackStateCompat.STATE_BUFFERING;

            mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
            mMediaPlayer.setDataSource(source);

            // Starts preparing the media player in the background. When
            // it's done, it will call our OnPreparedListener (that is,
            // the onPrepared() method on this class, since we set the
            // listener to 'this'). Until the media player is prepared,
            // we *cannot* call start() on it!
            mMediaPlayer.prepareAsync();

            // If we are streaming from the internet, we want to hold a
            // Wifi lock, which prevents the Wifi radio from going to
            // sleep while the song is playing.
            mWifiLock.acquire();

            if (mCallback != null) {
                mCallback.onPlaybackStatusChanged(mState);
            }

        } catch (IOException ex) {
            LogHelper.e(TAG, ex, "Exception playing song");
            if (mCallback != null) {
                mCallback.onError(ex.getMessage());
            }
        }
    }
}

From source file:com.kanedias.vanilla.lyrics.LyricsShowActivity.java

/**
 * Handle incoming intent that may possible be ping, other plugin request or user-interactive plugin request
 * @return true if intent was handled internally, false if activity startup is required
 *///  w  w  w .  j  ava  2  s.c  o  m
private boolean handleLaunchPlugin() {
    if (TextUtils.equals(getIntent().getAction(), ACTION_WAKE_PLUGIN)) {
        // just show that we're okay
        Log.i(LOG_TAG, "Plugin enabled!");
        finish();
        return true;
    }

    if (pluginInstalled(this, PLUGIN_TAG_EDIT_PKG) && !getIntent().hasExtra(EXTRA_PARAM_P2P)) {
        // it's user-requested, try to retrieve lyrics from the tag first
        Intent readLyrics = new Intent(ACTION_LAUNCH_PLUGIN);
        readLyrics.setPackage(PLUGIN_TAG_EDIT_PKG);
        readLyrics.putExtra(EXTRA_PARAM_URI, (Uri) getIntent().getParcelableExtra(EXTRA_PARAM_URI));
        readLyrics.putExtra(EXTRA_PARAM_PLUGIN_APP, getApplicationInfo());
        readLyrics.putExtra(EXTRA_PARAM_P2P, P2P_READ_TAG);
        readLyrics.putExtra(EXTRA_PARAM_P2P_KEY, new String[] { "LYRICS" }); // tag name
        readLyrics.putExtras(getIntent());
        startActivity(readLyrics);
        finish(); // end this activity instance, it will be re-created by incoming intent from Tag Editor
        return true;
    }

    return false;
}

From source file:com.murati.oszk.audiobook.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
 *///from   w  ww .  j a  va2s. c  om
public static boolean isQueueItemPlaying(Activity 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 = MediaControllerCompat.getMediaController(context);
    if (controller != null && controller.getPlaybackState() != null) {
        long currentPlayingQueueId = controller.getPlaybackState().getActiveQueueItemId();
        String currentPlayingMediaId = controller.getMetadata().getDescription().getMediaId();
        String itemMusicId = MediaIDHelper.extractMusicIDFromMediaID(queueItem.getDescription().getMediaId());
        if (queueItem.getQueueId() == currentPlayingQueueId && currentPlayingMediaId != null
                && TextUtils.equals(currentPlayingMediaId, itemMusicId)) {
            return true;
        }
    }
    return false;
}

From source file:com.example.android.AudioArchive.playback.LocalPlayback.java

@Override
public void play(QueueItem item) {
    mPlayOnFocusGain = true;//from w w  w. j  av  a  2 s  . c o m
    tryToGetAudioFocus();
    registerAudioNoisyReceiver();
    String mediaId = item.getDescription().getMediaId();
    boolean mediaHasChanged = !TextUtils.equals(mediaId, mCurrentMediaId);
    if (mediaHasChanged) {
        mCurrentPosition = 0;
        mCurrentMediaId = mediaId;
    }

    if (mState == PlaybackStateCompat.STATE_PAUSED && !mediaHasChanged && mMediaPlayer != null) {
        configMediaPlayerState();
    } else {
        mState = PlaybackStateCompat.STATE_STOPPED;
        relaxResources(false); // release everything except MediaPlayer
        MediaMetadataCompat track = mMusicProvider
                .getMusic(MediaIDHelper.extractMusicIDFromMediaID(item.getDescription().getMediaId()));

        //noinspection ResourceType
        String source = track.getString(MusicProviderSource.CUSTOM_METADATA_TRACK_SOURCE);

        try {
            createMediaPlayerIfNeeded();

            mState = PlaybackStateCompat.STATE_BUFFERING;

            mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
            mMediaPlayer.setDataSource(source);

            // Starts preparing the media player in the background. When
            // it's done, it will call our OnPreparedListener (that is,
            // the onPrepared() method on this class, since we set the
            // listener to 'this'). Until the media player is prepared,
            // we *cannot* call start() on it!
            mMediaPlayer.prepareAsync();

            // If we are streaming from the internet, we want to hold a
            // Wifi lock, which prevents the Wifi radio from going to
            // sleep while the song is playing.
            mWifiLock.acquire();

            if (mCallback != null) {
                mCallback.onPlaybackStatusChanged(mState);
            }

        } catch (IOException ex) {
            LogHelper.e(TAG, ex, "Exception playing song");
            if (mCallback != null) {
                mCallback.onError(ex.getMessage());
            }
        }
    }
}

From source file:com.zapp.library.merchant.util.PBBAAppUtils.java

/**
 * Show the Pay by Bank app popup. It opens the CFI App automatically (without displaying the popup) if the device has CFI App installed and the user has tapped
 * 'Open banking app' button. It closes itself automatically if the user taps the 'Open banking app' button. It closes any other Pay by Bank App popup currently open.
 *
 * @param activity    The activity to use.
 * @param secureToken The secure token for the payment.
 * @param brn         The BRN code for the payment.
 * @param callback    The callback listener for the popup. The popup keeps {@link java.lang.ref.WeakReference} to the callback.
 * @see PBBAPopupCallback// w ww .j  av  a 2  s  .c  om
 * @see #showPBBAErrorPopup(FragmentActivity, String, String, String, PBBAPopupCallback)
 * @see #dismissPBBAPopup(FragmentActivity)
 * @see #setPBBAPopupCallback(FragmentActivity, PBBAPopupCallback)
 */
@SuppressWarnings({ "FeatureEnvy", "OverlyComplexMethod", "OverlyLongMethod", "ElementOnlyUsedFromTestCode" })
public static void showPBBAPopup(@NonNull final FragmentActivity activity, @NonNull final String secureToken,
        @NonNull final String brn, @NonNull final PBBAPopupCallback callback) {

    verifyActivity(activity);

    if (TextUtils.isEmpty(secureToken)) {
        throw new IllegalArgumentException("secureToken is required");
    }

    if (TextUtils.isEmpty(brn)) {
        throw new IllegalArgumentException("BRN is required");
    }
    if (brn.length() != 6) {
        throw new IllegalArgumentException("BRN length is not 6 characters");
    }

    //noinspection ConstantConditions
    if (callback == null) {
        throw new IllegalArgumentException("callback == null");
    }

    final FragmentManager fragmentManager = activity.getSupportFragmentManager();
    final PBBAPopup fragment = (PBBAPopup) fragmentManager.findFragmentByTag(PBBAPopup.TAG);

    final boolean hasBankApp = isCFIAppAvailable(activity);
    if (hasBankApp) {
        final boolean openBankAppAutomatically = PBBALibraryUtils.isOpenBankingAppButtonClicked(activity);

        if (openBankAppAutomatically) {
            //close any open PBBA popup (e.g. error popup was displayed due to network error and retry request was successful with auto bank App open enabled)
            if (fragment != null) {
                fragmentManager.beginTransaction().remove(fragment).commit();
            }
            openBankingApp(activity, secureToken);
            return;
        }
    } else {
        //disable auto bank opening in case of no PBBA enabled App installed (or has been uninstalled)
        PBBALibraryUtils.setOpenBankingAppButtonClicked(activity, false);
    }

    if (fragment instanceof PBBAPopupFragment) {
        final PBBAPopupFragment popupFragment = (PBBAPopupFragment) fragment;
        if (TextUtils.equals(popupFragment.getSecureToken(), secureToken)
                && TextUtils.equals(popupFragment.getBrn(), brn)) {
            //same type of popup is already displayed, only reconnect is needed
            popupFragment.setCallback(callback);
            return;
        }
    }

    final PBBAPopupFragment newFragment = PBBAPopupFragment.newInstance(secureToken, brn);
    newFragment.setCallback(callback);

    final FragmentTransaction transaction = fragmentManager.beginTransaction();
    if (fragment != null) {
        transaction.remove(fragment);
    }
    transaction.add(newFragment, PBBAPopup.TAG).commit();
}

From source file:de.elanev.studip.android.app.frontend.news.NewsListFragment.java

public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    if (getActivity() == null) {
        return;//from w  ww. j a v  a2  s .c o  m
    }

    int idColumnIdx = 0;
    int titleColumnIdx = 0;

    int newsSelector = loader.getId();

    switch (newsSelector) {
    case NewsTabsAdapter.NEWS_COURSES:
        idColumnIdx = cursor.getColumnIndex(CoursesContract.Columns.Courses.COURSE_ID);

        titleColumnIdx = cursor.getColumnIndex(CoursesContract.Columns.Courses.COURSE_TITLE);

        break;
    case NewsTabsAdapter.NEWS_INSTITUTES:
        idColumnIdx = cursor.getColumnIndex(InstitutesContract.Columns.INSTITUTE_ID);

        titleColumnIdx = cursor.getColumnIndex(InstitutesContract.Columns.INSTITUTE_NAME);

        break;
    case NewsTabsAdapter.NEWS_GLOBAL:
        idColumnIdx = -1;
        titleColumnIdx = -1;
        break;
    }

    List<SectionedCursorAdapter.Section> sections = new ArrayList<SectionedCursorAdapter.Section>();
    if (idColumnIdx != -1 || titleColumnIdx != -1) {
        cursor.moveToFirst();
        String previousId = null;
        String currentId;
        while (!cursor.isAfterLast()) {

            currentId = cursor.getString(idColumnIdx);

            if (!TextUtils.equals(previousId, currentId)) {

                SectionedCursorAdapter.Section section = new SectionedCursorAdapter.Section(
                        cursor.getPosition(), cursor.getString(titleColumnIdx));

                sections.add(section);
            }
            previousId = currentId;
            cursor.moveToNext();
        }
    }

    mNewsAdapter.setSections(sections);
    mNewsAdapter.swapCursor(cursor);

    setLoadingViewVisible(false);
}

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

private void loadMedia(String mediaId, boolean autoPlay) throws Exception {
    MediaMetadataCompat track = mMusicProvider.getMusic(mediaId);
    if (track == null) {
        throw new IllegalArgumentException("Invalid mediaId " + mediaId);
    }//from  ww  w .j  av  a2 s.c o  m
    if (!TextUtils.equals(mediaId, mCurrentMediaId)) {
        mCurrentMediaId = mediaId;
        mCurrentPosition = 0;
        upnpPlayer.setURI(track.getString(MusicProviderSource.CUSTOM_METADATA_TRACK_SOURCE), autoPlay);
    } else {
        upnpPlayer.toPlay();
    }

    Log.i(TAG, track.getString(MusicProviderSource.CUSTOM_METADATA_TRACK_SOURCE));
}

From source file:id.ridon.keude.views.fragments.SelectLocalAppsFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    SimpleCursorAdapter adapter = (SimpleCursorAdapter) getListAdapter();
    adapter.swapCursor(cursor);/*from  w  w w.  j  av a 2 s.  c o m*/

    ListView listView = getListView();
    int count = listView.getCount();
    String fdroid = loader.getContext().getPackageName();
    for (int i = 0; i < count; i++) {
        Cursor c = ((Cursor) listView.getItemAtPosition(i));
        String packageName = c.getString(c.getColumnIndex(DataColumns.APP_ID));
        if (TextUtils.equals(packageName, fdroid)) {
            listView.setItemChecked(i, true); // always include Keude
        } else {
            for (String selected : KeudeApp.selectedApps) {
                if (TextUtils.equals(packageName, selected)) {
                    listView.setItemChecked(i, true);
                }
            }
        }
    }

    if (isResumed()) {
        setListShown(true);
    } else {
        setListShownNoAnimation(true);
    }
}

From source file:com.macadamian.blinkup.BlinkUpPluginResult.java

/*************************************
 * Returns JSON containing error//from  w ww  .  ja  v  a 2s . com
 *************************************/
private JSONObject generateErrorJson() {
    JSONObject errorJson = new JSONObject();

    try {
        errorJson.put(ResultKeys.ERROR_TYPE.getKey(), mErrorType);
        errorJson.put(ResultKeys.ERROR_CODE.getKey(), "" + mErrorCode);

        if (TextUtils.equals(mErrorType, ERROR_TYPE_BLINK_UP_SDK_ERROR)) {
            errorJson.put(ResultKeys.ERROR_MSG.getKey(), mErrorMsg);
        }
    } catch (JSONException e) {
        mState = STATE_ERROR;
        setPluginError(BlinkUpPlugin.ERROR_JSON_ERROR);
        sendResultsToCallback();
    }

    return errorJson;
}