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:im.vector.util.ThemeUtils.java

/**
 * Set the TabLayout colors./*from  w w  w .j av a  2  s . c  om*/
 * It seems that there is no proper way to manage it with the manifest file.
 *
 * @param activity the activity
 * @param layout   the layout
 */
public static void setTabLayoutTheme(Activity activity, TabLayout layout) {

    if (activity instanceof VectorGroupDetailsActivity) {
        int textColor;
        int underlineColor;
        int backgroundColor;

        if (TextUtils.equals(getApplicationTheme(activity), THEME_LIGHT_VALUE)) {
            underlineColor = textColor = ContextCompat.getColor(activity, android.R.color.white);
            backgroundColor = ContextCompat.getColor(activity, R.color.tab_groups);
        } else {
            underlineColor = textColor = ContextCompat.getColor(activity, R.color.tab_groups);
            backgroundColor = getColor(activity, R.attr.primary_color);
        }

        layout.setTabTextColors(textColor, textColor);
        layout.setSelectedTabIndicatorColor(underlineColor);
        layout.setBackgroundColor(backgroundColor);
    }
}

From source file:com.android.mail.ui.ActionBarController.java

private void setTitle(String title) {
    if (!TextUtils.equals(title, mActionBar.getTitle())) {
        mActionBar.setTitle(title);
    }
}

From source file:com.android.dialer.calllog.ContactInfoHelper.java

/**
 * Stores differences between the updated contact info and the current call log contact info.
 *
 * @param number The number of the contact.
 * @param countryIso The country associated with this number.
 * @param updatedInfo The updated contact info.
 * @param callLogInfo The call log entry's current contact info.
 *//*from w w  w  .  j a  v a  2 s  .com*/
public void updateCallLogContactInfo(String number, String countryIso, ContactInfo updatedInfo,
        ContactInfo callLogInfo) {
    if (!PermissionsUtil.hasPermission(mContext, android.Manifest.permission.WRITE_CALL_LOG)) {
        return;
    }

    final ContentValues values = new ContentValues();
    boolean needsUpdate = false;

    if (callLogInfo != null) {
        if (!TextUtils.equals(updatedInfo.name, callLogInfo.name)) {
            values.put(Calls.CACHED_NAME, updatedInfo.name);
            needsUpdate = true;
        }

        if (updatedInfo.type != callLogInfo.type) {
            values.put(Calls.CACHED_NUMBER_TYPE, updatedInfo.type);
            needsUpdate = true;
        }

        if (!TextUtils.equals(updatedInfo.label, callLogInfo.label)) {
            values.put(Calls.CACHED_NUMBER_LABEL, updatedInfo.label);
            needsUpdate = true;
        }

        if (!UriUtils.areEqual(updatedInfo.lookupUri, callLogInfo.lookupUri)) {
            values.put(Calls.CACHED_LOOKUP_URI, UriUtils.uriToString(updatedInfo.lookupUri));
            needsUpdate = true;
        }

        // Only replace the normalized number if the new updated normalized number isn't empty.
        if (!TextUtils.isEmpty(updatedInfo.normalizedNumber)
                && !TextUtils.equals(updatedInfo.normalizedNumber, callLogInfo.normalizedNumber)) {
            values.put(Calls.CACHED_NORMALIZED_NUMBER, updatedInfo.normalizedNumber);
            needsUpdate = true;
        }

        if (!TextUtils.equals(updatedInfo.number, callLogInfo.number)) {
            values.put(Calls.CACHED_MATCHED_NUMBER, updatedInfo.number);
            needsUpdate = true;
        }

        if (updatedInfo.photoId != callLogInfo.photoId) {
            values.put(Calls.CACHED_PHOTO_ID, updatedInfo.photoId);
            needsUpdate = true;
        }

        final Uri updatedPhotoUriContactsOnly = UriUtils.nullForNonContactsUri(updatedInfo.photoUri);
        if (!UriUtils.areEqual(updatedPhotoUriContactsOnly, callLogInfo.photoUri)) {
            values.put(Calls.CACHED_PHOTO_URI, UriUtils.uriToString(updatedPhotoUriContactsOnly));
            needsUpdate = true;
        }

        if (!TextUtils.equals(updatedInfo.formattedNumber, callLogInfo.formattedNumber)) {
            values.put(Calls.CACHED_FORMATTED_NUMBER, updatedInfo.formattedNumber);
            needsUpdate = true;
        }
    } else {
        // No previous values, store all of them.
        values.put(Calls.CACHED_NAME, updatedInfo.name);
        values.put(Calls.CACHED_NUMBER_TYPE, updatedInfo.type);
        values.put(Calls.CACHED_NUMBER_LABEL, updatedInfo.label);
        values.put(Calls.CACHED_LOOKUP_URI, UriUtils.uriToString(updatedInfo.lookupUri));
        values.put(Calls.CACHED_MATCHED_NUMBER, updatedInfo.number);
        values.put(Calls.CACHED_NORMALIZED_NUMBER, updatedInfo.normalizedNumber);
        values.put(Calls.CACHED_PHOTO_ID, updatedInfo.photoId);
        values.put(Calls.CACHED_PHOTO_URI,
                UriUtils.uriToString(UriUtils.nullForNonContactsUri(updatedInfo.photoUri)));
        values.put(Calls.CACHED_FORMATTED_NUMBER, updatedInfo.formattedNumber);
        needsUpdate = true;
    }

    if (!needsUpdate) {
        return;
    }

    try {
        if (countryIso == null) {
            mContext.getContentResolver().update(TelecomUtil.getCallLogUri(mContext), values,
                    Calls.NUMBER + " = ? AND " + Calls.COUNTRY_ISO + " IS NULL", new String[] { number });
        } else {
            mContext.getContentResolver().update(TelecomUtil.getCallLogUri(mContext), values,
                    Calls.NUMBER + " = ? AND " + Calls.COUNTRY_ISO + " = ?",
                    new String[] { number, countryIso });
        }
    } catch (SQLiteFullException e) {
        Log.e(TAG, "Unable to update contact info in call log db", e);
    }
}

From source file:com.achep.base.content.ConfigBase.java

private boolean fromBackupText(@NonNull Context context, @NonNull String str, @NonNull String fallback) {
    try {/*w w  w .  j  a v  a2s . c o  m*/
        JSONObject json = new JSONObject(str);
        Iterator<String> i = json.keys();
        while (i.hasNext()) {
            String key = i.next();
            Object value = json.get(key);
            // Apply the value
            Option option = getMap().get(key);
            if (option != null) {
                option.write(this, context, value, null);
            } else {
                Log.w(TAG, "Passed loading an unknown item[" + key + "] from plain text.");
            }
        }
    } catch (Exception e) {
        // Try to fallback to original settings.
        if (!TextUtils.equals(str, fallback))
            fromBackupText(context, fallback, fallback);
        // At this point current config may be partially corrupted and un-recoverable.
        return false;
    }
    return true;
}

From source file:com.dgsd.android.ShiftTracker.Fragment.EditShiftFragment.java

private void prepopulate() {
    if (mInitialShift != null) {
        mName.setText(mInitialShift.name);
        mNotes.setText(mInitialShift.note);
        mSaveAsTemplate.setChecked(mInitialShift.isTemplate);
        if (mInitialShift.julianDay >= 0)
            onDateSelected(TYPE_CODE_START, mInitialShift.julianDay);

        if (mInitialShift.endJulianDay >= 0)
            onDateSelected(TYPE_CODE_END, mInitialShift.endJulianDay);

        if (mInitialShift.getStartTime() != -1)
            setStartTime(mInitialShift.getStartTime());

        if (mInitialShift.getEndTime() != -1)
            setEndTime(mInitialShift.getEndTime());

        if (mInitialShift.breakDuration >= 0)
            mUnpaidBreak.setText(String.valueOf(mInitialShift.breakDuration));

        if (mInitialShift.payRate >= 0)
            mPayRate.setText(String.valueOf(mInitialShift.payRate));

        for (int i = 0, len = mRemindersValues.length; i < len; i++) {
            if (String.valueOf(mInitialShift.reminder).equals(mRemindersValues[i])) {
                setSelection(mReminders, i);
                break;
            }/*from w  ww  .  j a  v a2  s  .com*/
        }

        getSherlockActivity().invalidateOptionsMenu();
    } else {
        //No initial shift, just set up our date/time values
        final int jd = mInitialJulianDay < 0 ? TimeUtils.getCurrentJulianDay() : mInitialJulianDay;
        onDateSelected(TYPE_CODE_START, jd);
        onDateSelected(TYPE_CODE_END, jd);

        //Default 9 - 5 shift
        Time t = new Time();
        t.setToNow();
        t.hour = 9;
        t.minute = 0;
        t.second = 0;
        t.normalize(true);

        final Prefs p = Prefs.getInstance(getActivity());
        setStartTime(p.get(getString(R.string.settings_key_default_start_time), t.toMillis(true)));

        t.hour = 17;
        t.normalize(true);

        setEndTime(p.get(getString(R.string.settings_key_default_end_time), t.toMillis(true)));

        mUnpaidBreak.setText(p.get(getString(R.string.settings_key_default_break_duration), null));
        mPayRate.setText(p.get(getString(R.string.settings_key_default_pay_rate), null));

        String remindersVal = p.get(getString(R.string.settings_key_default_reminder), "None");
        int index = 0;
        for (int i = 0, len = mRemindersLabels.length; i < len; i++) {
            if (TextUtils.equals(remindersVal, mRemindersLabels[i])) {
                index = i;
                break;
            }
        }

        setSelection(mReminders, index);
    }
}

From source file:com.android.contacts.common.list.ShortcutIntentBuilder.java

private void createPhoneNumberShortcutIntent(Uri uri, String displayName, String lookupKey, byte[] bitmapData,
        String phoneNumber, int phoneType, String phoneLabel, String shortcutAction) {
    Drawable drawable = getPhotoDrawable(bitmapData, displayName, lookupKey);

    Bitmap bitmap;/*from   w w  w  . ja  v a 2  s  .c  o m*/
    Uri phoneUri;
    if (Intent.ACTION_CALL.equals(shortcutAction)) {
        // Make the URI a direct tel: URI so that it will always continue to work
        phoneUri = Uri.fromParts(PhoneAccount.SCHEME_TEL, phoneNumber, null);
        bitmap = generatePhoneNumberIcon(drawable, phoneType, phoneLabel, R.drawable.ic_call);
    } else {
        phoneUri = Uri.fromParts(ContactsUtils.SCHEME_SMSTO, phoneNumber, null);
        bitmap = generatePhoneNumberIcon(drawable, phoneType, phoneLabel, R.drawable.ic_message_24dp);
    }

    Intent shortcutIntent = new Intent(shortcutAction, phoneUri);
    shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    Intent intent = new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bitmap);
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);

    if (TextUtils.isEmpty(displayName)) {
        displayName = mContext.getResources().getString(R.string.missing_name);
    }
    if (TextUtils.equals(shortcutAction, Intent.ACTION_CALL)) {
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
                mContext.getResources().getString(R.string.call_by_shortcut, displayName));
    } else if (TextUtils.equals(shortcutAction, Intent.ACTION_SENDTO)) {
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
                mContext.getResources().getString(R.string.sms_by_shortcut, displayName));
    }

    mListener.onShortcutIntentCreated(uri, intent);
}

From source file:com.google.android.apps.muzei.gallery.GallerySettingsActivity.java

@Override
public boolean onPrepareOptionsMenu(final Menu menu) {
    super.onPrepareOptionsMenu(menu);
    // Make sure the 'Import photos' MenuItem is set up properly based on the number of
    // activities that handle ACTION_GET_CONTENT
    // 0 = hide the MenuItem
    // 1 = show 'Import photos from APP_NAME' to go to the one app that exists
    // 2 = show 'Import photos...' to have the user pick which app to import photos from
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("image/*");
    List<ResolveInfo> getContentActivities = getPackageManager().queryIntentActivities(intent, 0);
    mGetContentActivites.clear();/*from  w w w  .  j  a v  a 2  s .  c o m*/
    for (ResolveInfo info : getContentActivities) {
        // Filter out the default system UI
        if (!TextUtils.equals(info.activityInfo.packageName, "com.android.documentsui")) {
            mGetContentActivites.add(info.activityInfo);
        }
    }

    // Hide the 'Import photos' action if there are no activities found
    MenuItem importPhotosMenuItem = menu.findItem(R.id.action_import_photos);
    importPhotosMenuItem.setVisible(!mGetContentActivites.isEmpty());
    // If there's only one app that supports ACTION_GET_CONTENT, tell the user what that app is
    if (mGetContentActivites.size() == 1) {
        importPhotosMenuItem.setTitle(getString(R.string.gallery_action_import_photos_from,
                mGetContentActivites.get(0).loadLabel(getPackageManager())));
    } else {
        importPhotosMenuItem.setTitle(R.string.gallery_action_import_photos);
    }
    return true;
}

From source file:com.mobileglobe.android.customdialer.common.list.ShortcutIntentBuilder.java

private void createPhoneNumberShortcutIntent(Uri uri, String displayName, String lookupKey, byte[] bitmapData,
        String phoneNumber, int phoneType, String phoneLabel, String shortcutAction) {
    Drawable drawable = getPhotoDrawable(bitmapData, displayName, lookupKey);

    Bitmap bitmap;/*from  www. ja  v  a2 s.  c  om*/
    Uri phoneUri;
    if (Intent.ACTION_CALL.equals(shortcutAction)) {
        // Make the URI a direct tel: URI so that it will always continue to work
        phoneUri = Uri.fromParts(PhoneAccount.SCHEME_TEL, phoneNumber, null);
        bitmap = generatePhoneNumberIcon(drawable, phoneType, phoneLabel, R.drawable.ic_call);
    } else {
        phoneUri = Uri.fromParts(ContactsUtils.SCHEME_SMSTO, phoneNumber, null);
        bitmap = generatePhoneNumberIcon(drawable, phoneType, phoneLabel, R.drawable.ic_message_24dp_mirrored);
    }

    Intent shortcutIntent = new Intent(shortcutAction, phoneUri);
    shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    Intent intent = new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bitmap);
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);

    if (TextUtils.isEmpty(displayName)) {
        displayName = mContext.getResources().getString(R.string.missing_name);
    }
    if (TextUtils.equals(shortcutAction, Intent.ACTION_CALL)) {
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
                mContext.getResources().getString(R.string.call_by_shortcut, displayName));
    } else if (TextUtils.equals(shortcutAction, Intent.ACTION_SENDTO)) {
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
                mContext.getResources().getString(R.string.sms_by_shortcut, displayName));
    }

    mListener.onShortcutIntentCreated(uri, intent);
}

From source file:com.jungle.base.utils.MiscUtils.java

public static int getApplicationPid() {
    Context context = BaseApplication.getAppContext();
    String pkgName = getPackageName();

    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningAppProcessInfo> runningList = manager.getRunningAppProcesses();

    for (ActivityManager.RunningAppProcessInfo info : runningList) {
        if (TextUtils.equals(pkgName, info.processName)) {
            return info.pid;
        }//w  w w  .ja  va  2s .  c  o  m
    }

    return 0;
}

From source file:com.google.samples.apps.iosched.explore.ExploreSessionsActivity.java

/**
 * Set the activity title to be that of the selected tag name.
 * If the user chosen tag's category is present in the filter and there is a single tag
 * with that category then set the title to the specific tag name else
 * set the title to R.string.explore./*from   ww  w.j  av a 2  s  . c  om*/
 */
private void setActivityTitle() {
    if (mMode == MODE_EXPLORE && mTagMetadata != null) {
        String tag = getIntent().getStringExtra(EXTRA_FILTER_TAG);
        TagMetadata.Tag titleTag = tag == null ? null : mTagMetadata.getTag(tag);
        String title = null;
        if (titleTag != null && mTagFilterHolder.getCountByCategory(titleTag.getCategory()) == 1) {
            for (String tagId : mTagFilterHolder.getSelectedFilters()) {
                TagMetadata.Tag theTag = mTagMetadata.getTag(tagId);
                if (TextUtils.equals(titleTag.getCategory(), theTag.getCategory())) {
                    title = theTag.getName();
                }
            }
        }
        setTitle(title == null ? getString(R.string.title_explore) : title);
    }
}