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:cm.confide.ex.chips.RecipientAlternatesAdapter.java

/**
 * Given two {@link RecipientEntry}s for the same email address, this will return the one that
 * contains more complete information for display purposes. Defaults to <code>entry2</code> if
 * no significant differences are found.
 *///  w w w.  j  a v a  2 s  . c  o  m
static RecipientEntry getBetterRecipient(final RecipientEntry entry1, final RecipientEntry entry2) {
    // If only one has passed in, use it
    if (entry2 == null) {
        return entry1;
    }

    if (entry1 == null) {
        return entry2;
    }

    // If only one has a display name, use it
    if (!TextUtils.isEmpty(entry1.getDisplayName()) && TextUtils.isEmpty(entry2.getDisplayName())) {
        return entry1;
    }

    if (!TextUtils.isEmpty(entry2.getDisplayName()) && TextUtils.isEmpty(entry1.getDisplayName())) {
        return entry2;
    }

    // If only one has a display name that is not the same as the destination, use it
    if (!TextUtils.equals(entry1.getDisplayName(), entry1.getDestination())
            && TextUtils.equals(entry2.getDisplayName(), entry2.getDestination())) {
        return entry1;
    }

    if (!TextUtils.equals(entry2.getDisplayName(), entry2.getDestination())
            && TextUtils.equals(entry1.getDisplayName(), entry1.getDestination())) {
        return entry2;
    }

    // If only one has a photo, use it
    if ((entry1.getPhotoThumbnailUri() != null || entry1.getPhotoBytes() != null)
            && (entry2.getPhotoThumbnailUri() == null && entry2.getPhotoBytes() == null)) {
        return entry1;
    }

    if ((entry2.getPhotoThumbnailUri() != null || entry2.getPhotoBytes() != null)
            && (entry1.getPhotoThumbnailUri() == null && entry1.getPhotoBytes() == null)) {
        return entry2;
    }

    // Go with the second option as a default
    return entry2;
}

From source file:com.android.tv.settings.device.storage.FormatActivity.java

private void launchMigrateStorageAndFinish(String diskId) {
    final List<VolumeInfo> candidates = mPackageManager.getPrimaryStorageCandidateVolumes();
    VolumeInfo moveTarget = null;/*from  w  w w  .jav a2  s . c o m*/
    for (final VolumeInfo candidate : candidates) {
        if (TextUtils.equals(candidate.getDiskId(), diskId)) {
            moveTarget = candidate;
            break;
        }
    }

    if (moveTarget != null) {
        startActivity(MigrateStorageActivity.getLaunchIntent(this, moveTarget.getId(), true));
    }

    finish();
}

From source file:de.bahnhoefe.deutschlands.bahnhofsfotos.DetailsActivity.java

private boolean canSetPhoto() {
    return !bahnhof.hasPhoto() || TextUtils.equals(nickname, bahnhof.getPhotographer());
}

From source file:com.ae.apps.tripmeter.fragments.expenses.TripsListFragment.java

@Override
public void onTripUpdated(Trip trip) {
    mExpenseManager.updateTrip(trip);//  w  w  w  . j a v a  2 s . com

    // Convert this trip to an index of the trips list
    int index = -1;
    for (Trip tempTrip : mTrips) {
        if (TextUtils.equals(tempTrip.getId(), trip.getId())) {
            index = mTrips.indexOf(tempTrip);
            break;
        }
    }

    if (index > -1) {
        mTrips.get(index).setName(trip.getName());
    }

    if (null != mViewAdapter) {
        // TODO Optimize the update call?
        // mViewAdapter.notifyItemChanged(index);
        mViewAdapter.notifyDataSetChanged();
    }
}

From source file:com.citrus.sdk.fragments.SavedOptions.java

private void initiateTxn() {
    taskExecuted = new JSONTaskComplete() {

        @Override//from   www. j av a2s .c o m
        public void onTaskExecuted(JSONObject[] paymentObject, String message) {
            if (TextUtils.equals(message, "success")) {
                try {
                    String url = paymentObject[0].getString("redirectUrl");
                    Intent intent = new Intent(getActivity(), Web3DSecure.class);
                    intent.putExtra("redirectUrl", url);
                    startActivity(intent);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        }

    };

    new Pay(getActivity(), paymentObject, taskExecuted).execute();
}

From source file:im.vector.VectorApp.java

@Override
public void onCreate() {
    Log.d(LOG_TAG, "onCreate");
    super.onCreate();

    if (BuildConfig.DEBUG) {
        Stetho.initializeWithDefaults(this);
    }//from   ww  w  .j a v a 2  s  .  c  om

    instance = this;
    mCallsManager = new CallsManager(this);
    mActivityTransitionTimer = null;
    mActivityTransitionTimerTask = null;

    try {
        PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        VERSION_BUILD = packageInfo.versionCode;
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(LOG_TAG, "fails to retrieve the package info " + e.getMessage());
    }

    VECTOR_VERSION_STRING = Matrix.getInstance(this).getVersion(true, true);

    // not the first launch
    if (null != Matrix.getInstance(this).getDefaultSession()) {
        SDK_VERSION_STRING = Matrix.getInstance(this).getDefaultSession().getVersion(true);
    } else {
        SDK_VERSION_STRING = "";
    }

    try {
        PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        SHORT_VERSION = pInfo.versionName;
    } catch (Exception e) {
    }

    mLogsDirectoryFile = new File(getCacheDir().getAbsolutePath() + "/logs");

    org.matrix.androidsdk.util.Log.setLogDirectory(mLogsDirectoryFile);
    org.matrix.androidsdk.util.Log.init("RiotLog");

    // log the application version to trace update
    // useful to track backward compatibility issues

    Log.d(LOG_TAG, "----------------------------------------------------------------");
    Log.d(LOG_TAG, "----------------------------------------------------------------");
    Log.d(LOG_TAG, " Application version: " + VECTOR_VERSION_STRING);
    Log.d(LOG_TAG, " SDK version: " + SDK_VERSION_STRING);
    Log.d(LOG_TAG,
            " Local time: " + (new SimpleDateFormat("MM-dd HH:mm:ss.SSSZ", Locale.US)).format(new Date()));
    Log.d(LOG_TAG, "----------------------------------------------------------------");
    Log.d(LOG_TAG, "----------------------------------------------------------------\n\n\n\n");

    mRageShake = new RageShake(this);

    // init the REST client
    MXSession.initUserAgent(getApplicationContext());

    this.registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
        final Map<String, String> mLocalesByActivity = new HashMap<>();

        @Override
        public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
            Log.d(LOG_TAG, "onActivityCreated " + activity);
            mCreatedActivities.add(activity.toString());
            ThemeUtils.setActivityTheme(activity);
            // piwik
            onNewScreen(activity);
        }

        @Override
        public void onActivityStarted(Activity activity) {
            Log.d(LOG_TAG, "onActivityStarted " + activity);
        }

        /**
         * Compute the locale status value
         * @param activity the activity
         * @return the local status value
         */
        private String getActivityLocaleStatus(Activity activity) {
            return getApplicationLocale().toString() + "_" + getFontScale() + "_"
                    + ThemeUtils.getApplicationTheme(activity);
        }

        @Override
        public void onActivityResumed(final Activity activity) {
            Log.d(LOG_TAG, "onActivityResumed " + activity);
            setCurrentActivity(activity);

            String activityKey = activity.toString();

            if (mLocalesByActivity.containsKey(activityKey)) {
                String prevActivityLocale = mLocalesByActivity.get(activityKey);

                if (!TextUtils.equals(prevActivityLocale, getActivityLocaleStatus(activity))) {
                    Log.d(LOG_TAG,
                            "## onActivityResumed() : restart the activity " + activity
                                    + " because of the locale update from " + prevActivityLocale + " to "
                                    + getActivityLocaleStatus(activity));
                    restartActivity(activity);
                    return;
                }
            }

            // it should never happen as there is a broadcast receiver (mLanguageReceiver)
            if (!TextUtils.equals(Locale.getDefault().toString(), getApplicationLocale().toString())) {
                Log.d(LOG_TAG,
                        "## onActivityResumed() : the locale has been updated to "
                                + Locale.getDefault().toString() + ", restore the expected value "
                                + getApplicationLocale().toString());
                updateApplicationSettings(getApplicationLocale(), getFontScale(),
                        ThemeUtils.getApplicationTheme(activity));
                restartActivity(activity);
            }

            listPermissionStatuses();
        }

        @Override
        public void onActivityPaused(Activity activity) {
            Log.d(LOG_TAG, "onActivityPaused " + activity);
            mLocalesByActivity.put(activity.toString(), getActivityLocaleStatus(activity));
            setCurrentActivity(null);
            onAppPause();
        }

        @Override
        public void onActivityStopped(Activity activity) {
            Log.d(LOG_TAG, "onActivityStopped " + activity);
        }

        @Override
        public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
            Log.d(LOG_TAG, "onActivitySaveInstanceState " + activity);
        }

        @Override
        public void onActivityDestroyed(Activity activity) {
            Log.d(LOG_TAG, "onActivityDestroyed " + activity);
            mCreatedActivities.remove(activity.toString());
            mLocalesByActivity.remove(activity.toString());

            if (mCreatedActivities.size() > 1) {
                Log.d(LOG_TAG, "onActivityDestroyed : \n" + mCreatedActivities);
            }
        }
    });

    // create the markdown parser
    try {
        mMarkdownParser = new VectorMarkdownParser(this);
    } catch (Exception e) {
        // reported by GA
        Log.e(LOG_TAG, "cannot create the mMarkdownParser " + e.getMessage());
    }

    // track external language updates
    // local update from the settings
    // or screen rotation !
    VectorApp.getInstance().registerReceiver(mLanguageReceiver, new IntentFilter(Intent.ACTION_LOCALE_CHANGED));
    VectorApp.getInstance().registerReceiver(mLanguageReceiver,
            new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED));

    PreferencesManager.fixMigrationIssues(this);
    initApplicationLocale();
}

From source file:Main.java

public static Boolean getBoolean(@Nullable Object value, @Nullable Boolean df) {

    if (value == null)
        return df;
    if (TextUtils.equals("false", value.toString())) {
        return false;
    } else if (TextUtils.equals("true", value.toString())) {
        return true;
    }/*from ww w. jav  a2s  . c  o  m*/
    return df;
}

From source file:info.guardianproject.otr.app.im.app.MessageView.java

private void showMediaThumbnail(String mimeType, Uri mediaUri, int id, ViewHolder holder) {
    /* Guess the MIME type in case we received a file that we can display or play*/
    if (TextUtils.isEmpty(mimeType) || mimeType.startsWith("application")) {
        String guessed = URLConnection.guessContentTypeFromName(mediaUri.toString());
        if (!TextUtils.isEmpty(guessed)) {
            if (TextUtils.equals(guessed, "video/3gpp"))
                mimeType = "audio/3gpp";
            else//from  www.ja  v a2s  .com
                mimeType = guessed;
        }
    }
    holder.setOnClickListenerMediaThumbnail(mimeType, mediaUri);

    holder.mMediaThumbnail.setVisibility(View.VISIBLE);
    holder.mTextViewForMessages.setText(lastMessage);
    holder.mTextViewForMessages.setVisibility(View.GONE);

    if (mimeType.startsWith("image/")) {
        setImageThumbnail(getContext().getContentResolver(), id, holder, mediaUri);
        holder.mMediaThumbnail.setBackgroundColor(Color.TRANSPARENT);
        // holder.mMediaThumbnail.setBackgroundColor(Color.WHITE);

    } else if (mimeType.startsWith("audio")) {
        holder.mMediaThumbnail.setImageResource(R.drawable.media_audio_play);
        holder.mMediaThumbnail.setBackgroundColor(Color.TRANSPARENT);
    } else {
        holder.mMediaThumbnail.setImageResource(R.drawable.ic_file); // generic file icon

    }

    holder.mContainer.setBackgroundColor(getResources().getColor(android.R.color.transparent));

}

From source file:com.example.chu.googleplaylibrary.playback.CastPlayback.java

private void setMetadataFromRemote() {
    // Sync: We get the customData from the remote media information and update the local
    // metadata if it happens to be different from the one we are currently using.
    // This can happen when the app was either restarted/disconnected + connected, or if the
    // app joins an existing session while the Chromecast was playing a queue.
    try {/*from   www .  jav  a  2 s.c o  m*/
        MediaInfo mediaInfo = VideoCastManager.getInstance().getRemoteMediaInformation();
        if (mediaInfo == null) {
            return;
        }
        JSONObject customData = mediaInfo.getCustomData();

        if (customData != null && customData.has(ITEM_ID)) {
            String remoteMediaId = customData.getString(ITEM_ID);
            if (!TextUtils.equals(mCurrentMediaId, remoteMediaId)) {
                mCurrentMediaId = remoteMediaId;
                if (mCallback != null) {
                    mCallback.setCurrentMediaId(remoteMediaId);
                }
                updateLastKnownStreamPosition();
            }
        }
    } catch (TransientNetworkDisconnectionException | NoConnectionException | JSONException e) {
        LogHelper.e(TAG, e, "Exception processing update metadata");
    }

}

From source file:im.neon.contacts.ContactsManager.java

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    if (TextUtils.equals(key, PhoneNumberUtils.COUNTRY_CODE_PREF_KEY)) {
        Handler handler = new Handler(Looper.getMainLooper());
        handler.post(new Runnable() {
            @Override//from  w  w w .ja  va  2s .c o  m
            public void run() {
                onCountryCodeUpdate();
            }
        });
    }
}