List of usage examples for android.text TextUtils equals
public static boolean equals(CharSequence a, CharSequence b)
From source file:im.vector.VectorApp.java
/** * Provides the current application locale * * @return the application locale//w ww .j a v a 2 s. c o m */ public static Locale getApplicationLocale() { Context context = VectorApp.getInstance(); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); Locale locale; if (!preferences.contains(APPLICATION_LOCALE_LANGUAGE_KEY)) { locale = Locale.getDefault(); // detect if the default language is used String defaultStringValue = getString(context, mApplicationDefaultLanguage, R.string.resouces_country); if (TextUtils.equals(defaultStringValue, getString(context, locale, R.string.resouces_country))) { locale = mApplicationDefaultLanguage; } saveApplicationLocale(locale); } else { locale = new Locale(preferences.getString(APPLICATION_LOCALE_LANGUAGE_KEY, ""), preferences.getString(APPLICATION_LOCALE_COUNTRY_KEY, ""), preferences.getString(APPLICATION_LOCALE_VARIANT_KEY, "")); } return locale; }
From source file:com.songcode.materialnotes.ui.NotesListActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: toggleDrawerLayout();// w ww . j a va2 s .c o m break; case R.id.menu_new_folder: { showCreateOrModifyFolderDialog(true); break; } case R.id.menu_export_text: { exportNoteToText(); break; } case R.id.menu_sync: { if (isSyncMode()) { if (TextUtils.equals(item.getTitle(), getString(R.string.menu_sync))) { GTaskSyncService.startSync(this); } else { GTaskSyncService.cancelSync(this); } } else { startPreferenceActivity(); } break; } case R.id.menu_setting: { startPreferenceActivity(); break; } case R.id.menu_new_note: { createNewNote(); break; } case R.id.menu_search: onSearchRequested(); break; default: break; } return true; }
From source file:im.neon.util.VectorUtils.java
/** * Provide the user online status from his user Id. * if refreshCallback is set, try to refresh the user presence if it is not known * * @param context the context.//from w w w .ja va 2s . c o m * @param session the session. * @param userId the userId. * @param refreshCallback the presence callback. * @return the online status description. */ public static String getUserOnlineStatus(final Context context, final MXSession session, final String userId, final SimpleApiCallback<Void> refreshCallback) { // sanity checks if ((null == session) || (null == userId)) { return null; } final User user = session.getDataHandler().getStore().getUser(userId); // refresh the presence with this conditions boolean triggerRefresh = (null == user) || user.isPresenceObsolete(); if ((null != refreshCallback) && triggerRefresh) { Log.d(LOG_TAG, "Get the user presence : " + userId); final String fPresence = (null != user) ? user.presence : null; session.refreshUserPresence(userId, new ApiCallback<Void>() { @Override public void onSuccess(Void info) { boolean isUpdated = false; User updatedUser = session.getDataHandler().getStore().getUser(userId); // don't find any info for the user if ((null == user) && (null == updatedUser)) { Log.d(LOG_TAG, "Don't find any presence info of " + userId); } else if ((null == user) && (null != updatedUser)) { Log.d(LOG_TAG, "Got the user presence : " + userId); isUpdated = true; } else if (!TextUtils.equals(fPresence, updatedUser.presence)) { isUpdated = true; Log.d(LOG_TAG, "Got some new user presence info : " + userId); Log.d(LOG_TAG, "currently_active : " + updatedUser.currently_active); Log.d(LOG_TAG, "lastActiveAgo : " + updatedUser.lastActiveAgo); } if (isUpdated && (null != refreshCallback)) { try { refreshCallback.onSuccess(null); } catch (Exception e) { Log.e(LOG_TAG, "getUserOnlineStatus refreshCallback failed"); } } } @Override public void onNetworkError(Exception e) { Log.e(LOG_TAG, "getUserOnlineStatus onNetworkError " + e.getLocalizedMessage()); } @Override public void onMatrixError(MatrixError e) { Log.e(LOG_TAG, "getUserOnlineStatus onMatrixError " + e.getLocalizedMessage()); } @Override public void onUnexpectedError(Exception e) { Log.e(LOG_TAG, "getUserOnlineStatus onUnexpectedError " + e.getLocalizedMessage()); } }); } // unknown user if (null == user) { return null; } String presenceText = null; if (TextUtils.equals(user.presence, User.PRESENCE_ONLINE)) { presenceText = context.getResources().getString(R.string.room_participants_online); } else if (TextUtils.equals(user.presence, User.PRESENCE_UNAVAILABLE)) { presenceText = context.getResources().getString(R.string.room_participants_idle); } else if (TextUtils.equals(user.presence, User.PRESENCE_OFFLINE) || (null == user.presence)) { presenceText = context.getResources().getString(R.string.room_participants_offline); } if (presenceText != null) { if ((null != user.currently_active) && user.currently_active) { presenceText += " " + context.getResources().getString(R.string.room_participants_now); } else if ((null != user.lastActiveAgo) && (user.lastActiveAgo > 0)) { presenceText += " " + formatSecondsIntervalFloored(context, user.getAbsoluteLastActiveAgo() / 1000L) + " " + context.getResources().getString(R.string.room_participants_ago); } } return presenceText; }
From source file:im.vector.adapters.VectorMessagesAdapter.java
/** * Tells if the downloadId is the media download id. * @param event the event/* www. j a v a 2 s . c o m*/ * @param downloadId the download id. * @return true if the media is downloading (not the thumbnail) */ private boolean isMediaDownloading(Event event, String downloadId) { String mediaDownloadId = mMediaDownloadIdByEventId.get(event.eventId); if (null == mediaDownloadId) { mediaDownloadId = ""; if (TextUtils.equals(event.type, Event.EVENT_TYPE_MESSAGE)) { Message message = JsonUtils.toMessage(event.content); String url = null; if (TextUtils.equals(message.msgtype, Message.MSGTYPE_IMAGE)) { url = JsonUtils.toImageMessage(event.content).url; } else if (TextUtils.equals(message.msgtype, Message.MSGTYPE_VIDEO)) { url = JsonUtils.toVideoMessage(event.content).url; } else if (TextUtils.equals(message.msgtype, Message.MSGTYPE_FILE)) { url = JsonUtils.toFileMessage(event.content).url; } if (!TextUtils.isEmpty(url)) { mediaDownloadId = mSession.getMediasCache().downloadIdFromUrl(url); } } mMediaDownloadIdByEventId.put(event.eventId, mediaDownloadId); } return TextUtils.equals(mediaDownloadId, downloadId); }
From source file:im.neon.adapters.VectorMessagesAdapter.java
@Override protected boolean manageSubView(int position, View convertView, View subView, int msgType) { MessageRow row = getItem(position);/*from w w w . j a v a 2 s . c o m*/ Event event = row.getEvent(); // mother class implementation boolean isMergedView = super.manageSubView(position, convertView, subView, msgType); // remove the message separator when it is not required View view = convertView.findViewById(org.matrix.androidsdk.R.id.messagesAdapter_message_separator); if (null != view) { View line = convertView.findViewById(org.matrix.androidsdk.R.id.messagesAdapter_message_separator_line); if (null != line) { line.setBackgroundColor(Color.TRANSPARENT); } } // display the day separator View headerLayout = convertView.findViewById(org.matrix.androidsdk.R.id.messagesAdapter_message_header); if (null != headerLayout) { String header = headerMessage(position); if (null != header) { TextView headerText = (TextView) convertView .findViewById(org.matrix.androidsdk.R.id.messagesAdapter_message_header_text); headerText.setText(header); headerLayout.setVisibility(View.VISIBLE); View topHeaderMargin = headerLayout.findViewById(R.id.messagesAdapter_message_header_top_margin); topHeaderMargin.setVisibility((0 == position) ? View.GONE : View.VISIBLE); } else { headerLayout.setVisibility(View.GONE); } } // the timestamp is hidden except for the latest message and when there is no search View rightTsTextLayout = convertView .findViewById(org.matrix.androidsdk.R.id.message_timestamp_layout_right); if (null != rightTsTextLayout) { TextView tsTextView = (TextView) rightTsTextLayout .findViewById(org.matrix.androidsdk.R.id.messagesAdapter_timestamp); if (null != tsTextView) { tsTextView.setVisibility( (((position + 1) == this.getCount()) || mIsSearchMode) ? View.VISIBLE : View.GONE); } } // On Vector application, the read receipts are displayed in a dedicated line under the message View avatarsListView = convertView.findViewById(R.id.messagesAdapter_avatars_list); if (null != avatarsListView) { displayReadReceipts(avatarsListView, event.eventId, row.getRoomState()); } // selection mode manageSelectionMode(convertView, event); // search message mode View highlightMakerView = convertView.findViewById(R.id.messagesAdapter_highlight_message_marker); if (null != highlightMakerView) { if (TextUtils.equals(mSearchedEventId, event.eventId)) { View avatarView = convertView .findViewById(org.matrix.androidsdk.R.id.messagesAdapter_roundAvatar_left); ViewGroup.LayoutParams avatarLayout = avatarView.getLayoutParams(); // align marker view with the message ViewGroup.MarginLayoutParams highlightMakerLayout = (ViewGroup.MarginLayoutParams) highlightMakerView .getLayoutParams(); if (isMergedView) { highlightMakerLayout.setMargins(avatarLayout.width + 5, highlightMakerLayout.topMargin, 5, highlightMakerLayout.bottomMargin); } else { highlightMakerLayout.setMargins(5, highlightMakerLayout.topMargin, 5, highlightMakerLayout.bottomMargin); } highlightMakerView.setLayoutParams(highlightMakerLayout); // move left the body View bodyLayoutView = convertView .findViewById(org.matrix.androidsdk.R.id.messagesAdapter_body_layout); ViewGroup.MarginLayoutParams bodyLayout = (ViewGroup.MarginLayoutParams) bodyLayoutView .getLayoutParams(); bodyLayout.setMargins(4, bodyLayout.topMargin, 4, bodyLayout.bottomMargin); highlightMakerView.setBackgroundColor(ContextCompat.getColor(mContext, R.color.vector_green_color)); } else { highlightMakerView .setBackgroundColor(ContextCompat.getColor(mContext, android.R.color.transparent)); } } // download / upload progress layout if ((ROW_TYPE_IMAGE == msgType) || (ROW_TYPE_FILE == msgType) || (ROW_TYPE_VIDEO == msgType)) { View bodyLayoutView = convertView.findViewById(org.matrix.androidsdk.R.id.messagesAdapter_body_layout); ViewGroup.MarginLayoutParams bodyLayoutParams = (ViewGroup.MarginLayoutParams) bodyLayoutView .getLayoutParams(); int marginLeft = bodyLayoutParams.leftMargin; View downloadProgressLayout = convertView .findViewById(org.matrix.androidsdk.R.id.content_download_progress_layout); if (null != downloadProgressLayout) { ViewGroup.MarginLayoutParams downloadProgressLayoutParams = (ViewGroup.MarginLayoutParams) downloadProgressLayout .getLayoutParams(); downloadProgressLayoutParams.setMargins(marginLeft, downloadProgressLayoutParams.topMargin, downloadProgressLayoutParams.rightMargin, downloadProgressLayoutParams.bottomMargin); downloadProgressLayout.setLayoutParams(downloadProgressLayoutParams); } View uploadProgressLayout = convertView .findViewById(org.matrix.androidsdk.R.id.content_upload_progress_layout); if (null != uploadProgressLayout) { ViewGroup.MarginLayoutParams uploadProgressLayoutParams = (ViewGroup.MarginLayoutParams) uploadProgressLayout .getLayoutParams(); uploadProgressLayoutParams.setMargins(marginLeft, uploadProgressLayoutParams.topMargin, uploadProgressLayoutParams.rightMargin, uploadProgressLayoutParams.bottomMargin); uploadProgressLayout.setLayoutParams(uploadProgressLayoutParams); } } return isMergedView; }
From source file:com.forrestguice.suntimeswidget.SuntimesActivity.java
/** * Show the location on a map.//from w w w . j av a 2 s. com * Intent filtering code based off answer by "gumberculese"; * http://stackoverflow.com/questions/5734678/custom-filtering-of-intent-chooser-based-on-installed-android-package-name */ protected void showMap() { Intent mapIntent = new Intent(Intent.ACTION_VIEW); mapIntent.setData(location.getUri()); //if (mapIntent.resolveActivity(getPackageManager()) != null) //{ // startActivity(mapIntent); //} String myPackage = "com.forrestguice.suntimeswidget"; List<ResolveInfo> info = getPackageManager().queryIntentActivities(mapIntent, 0); List<Intent> geoIntents = new ArrayList<Intent>(); if (!info.isEmpty()) { for (ResolveInfo resolveInfo : info) { String packageName = resolveInfo.activityInfo.packageName; if (!TextUtils.equals(packageName, myPackage)) { Intent geoIntent = new Intent(Intent.ACTION_VIEW); geoIntent.setPackage(packageName); geoIntent.setData(location.getUri()); geoIntents.add(geoIntent); } } } if (geoIntents.size() > 0) { Intent chooserIntent = Intent.createChooser(geoIntents.remove(0), getString(R.string.configAction_mapLocation_chooser)); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, geoIntents.toArray(new Parcelable[geoIntents.size()])); startActivity(chooserIntent); } else { Toast noAppError = Toast.makeText(this, getString(R.string.configAction_mapLocation_noapp), Toast.LENGTH_LONG); noAppError.show(); } }
From source file:im.vector.adapters.VectorRoomSummaryAdapter.java
/** * Retrieves the text to display for a RoomSummary. * * @param aChildRoomSummary the roomSummary. * @return the text to display.//from www.j av a 2 s .c om */ private CharSequence getChildMessageToDisplay(RoomSummary aChildRoomSummary) { CharSequence messageToDisplayRetValue = null; EventDisplay eventDisplay; if (null != aChildRoomSummary) { if (aChildRoomSummary.getLatestReceivedEvent() != null) { eventDisplay = new RiotEventDisplay(mContext, aChildRoomSummary.getLatestReceivedEvent(), aChildRoomSummary.getLatestRoomState()); eventDisplay.setPrependMessagesWithAuthor(true); messageToDisplayRetValue = eventDisplay .getTextualDisplay(ThemeUtils.getColor(mContext, R.attr.riot_primary_text_color)); } // check if this is an invite if (aChildRoomSummary.isInvited() && (null != aChildRoomSummary.getInviterUserId())) { RoomState latestRoomState = aChildRoomSummary.getLatestRoomState(); String inviterUserId = aChildRoomSummary.getInviterUserId(); String myName = aChildRoomSummary.getMatrixId(); if (null != latestRoomState) { inviterUserId = latestRoomState.getMemberName(inviterUserId); myName = latestRoomState.getMemberName(myName); } else { inviterUserId = getMemberDisplayNameFromUserId(aChildRoomSummary.getMatrixId(), inviterUserId); myName = getMemberDisplayNameFromUserId(aChildRoomSummary.getMatrixId(), myName); } if (TextUtils.equals(mMxSession.getMyUserId(), aChildRoomSummary.getMatrixId())) { messageToDisplayRetValue = mContext .getString(org.matrix.androidsdk.R.string.notice_room_invite_you, inviterUserId); } else { messageToDisplayRetValue = mContext.getString(org.matrix.androidsdk.R.string.notice_room_invite, inviterUserId, myName); } } } return messageToDisplayRetValue; }
From source file:com.android.messaging.datamodel.MessageNotificationState.java
/** * Performs a query on the database./*from www. j a va 2s.c om*/ */ private static ConversationInfoList createConversationInfoList() { // Map key is conversation id. We use LinkedHashMap to ensure that entries are iterated in // the same order they were originally added. We scan unseen messages from newest to oldest, // so the corresponding conversations are added in that order, too. final Map<String, ConversationLineInfo> convLineInfos = new LinkedHashMap<>(); int messageCount = 0; Cursor convMessageCursor = null; try { final Context context = Factory.get().getApplicationContext(); final DatabaseWrapper db = DataModel.get().getDatabase(); convMessageCursor = db.rawQuery(ConversationMessageData.getNotificationQuerySql(), null); if (convMessageCursor != null && convMessageCursor.moveToFirst()) { if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) { LogUtil.v(TAG, "MessageNotificationState: Found unseen message notifications."); } final ConversationMessageData convMessageData = new ConversationMessageData(); HashMap<String, Integer> firstNames = null; String conversationIdForFirstNames = null; String groupConversationName = null; final int maxMessages = getMaxMessagesInConversationNotification(); do { convMessageData.bind(convMessageCursor); // First figure out if this is a valid message. String authorFullName = convMessageData.getSenderFullName(); String authorFirstName = convMessageData.getSenderFirstName(); final String messageText = convMessageData.getText(); final String convId = convMessageData.getConversationId(); final String messageId = convMessageData.getMessageId(); CharSequence text = messageText; final boolean isManualDownloadNeeded = convMessageData.getIsMmsNotification(); if (isManualDownloadNeeded) { // Don't try and convert the text from html if it's sms and not a sms push // notification. Assert.equals(MessageData.BUGLE_STATUS_INCOMING_YET_TO_MANUAL_DOWNLOAD, convMessageData.getStatus()); text = context.getResources().getString(R.string.message_title_manual_download); } ConversationLineInfo currConvInfo = convLineInfos.get(convId); if (currConvInfo == null) { final ConversationListItemData convData = ConversationListItemData .getExistingConversation(db, convId); if (!convData.getNotificationEnabled()) { // Skip conversations that have notifications disabled. continue; } final int subId = BugleDatabaseOperations.getSelfSubscriptionId(db, convData.getSelfId()); groupConversationName = convData.getName(); final Uri avatarUri = AvatarUriUtil.createAvatarUri( convMessageData.getSenderProfilePhotoUri(), convMessageData.getSenderFullName(), convMessageData.getSenderNormalizedDestination(), convMessageData.getSenderContactLookupKey()); currConvInfo = new ConversationLineInfo(convId, convData.getIsGroup(), groupConversationName, convData.getIncludeEmailAddress(), convMessageData.getReceivedTimeStamp(), convData.getSelfId(), convData.getNotificationSoundUri(), convData.getNotificationEnabled(), convData.getNotifiationVibrate(), avatarUri, convMessageData.getSenderContactLookupUri(), subId, convData.getParticipantCount()); convLineInfos.put(convId, currConvInfo); } // Prepare the message line if (currConvInfo.mTotalMessageCount < maxMessages) { if (currConvInfo.mIsGroup) { if (authorFirstName == null) { // authorFullName might be null as well. In that case, we won't // show an author. That is better than showing all the group // names again on the 2nd line. authorFirstName = authorFullName; } } else { // don't recompute this if we don't need to if (!TextUtils.equals(conversationIdForFirstNames, convId)) { firstNames = scanFirstNames(convId); conversationIdForFirstNames = convId; } if (firstNames != null) { final Integer count = firstNames.get(authorFirstName); if (count != null && count > 1) { authorFirstName = authorFullName; } } if (authorFullName == null) { authorFullName = groupConversationName; } if (authorFirstName == null) { authorFirstName = groupConversationName; } } final String subjectText = MmsUtils.cleanseMmsSubject(context.getResources(), convMessageData.getMmsSubject()); if (!TextUtils.isEmpty(subjectText)) { final String subjectLabel = context.getString(R.string.subject_label); final SpannableStringBuilder spanBuilder = new SpannableStringBuilder(); spanBuilder.append( context.getString(R.string.notification_subject, subjectLabel, subjectText)); spanBuilder.setSpan(new TextAppearanceSpan(context, R.style.NotificationSubjectText), 0, subjectLabel.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); if (!TextUtils.isEmpty(text)) { // Now add the actual message text below the subject header. spanBuilder.append(System.getProperty("line.separator") + text); } text = spanBuilder; } // If we've got attachments, find the best one. If one of the messages is // a photo, save the url so we'll display a big picture notification. // Otherwise, show the first one we find. Uri attachmentUri = null; String attachmentType = null; final MessagePartData messagePartData = getMostInterestingAttachment(convMessageData); if (messagePartData != null) { attachmentUri = messagePartData.getContentUri(); attachmentType = messagePartData.getContentType(); } currConvInfo.mLineInfos .add(new MessageLineInfo(currConvInfo.mIsGroup, authorFullName, authorFirstName, text, attachmentUri, attachmentType, isManualDownloadNeeded, messageId)); } messageCount++; currConvInfo.mTotalMessageCount++; } while (convMessageCursor.moveToNext()); } } finally { if (convMessageCursor != null) { convMessageCursor.close(); } } if (convLineInfos.isEmpty()) { return null; } else { return new ConversationInfoList(messageCount, Lists.newLinkedList(convLineInfos.values())); } }
From source file:im.vector.adapters.VectorRoomSummaryAdapter.java
/** * Defines the new searched pattern/* ww w . j a v a 2 s. c om*/ * * @param pattern the new searched pattern */ public void setSearchPattern(String pattern) { String trimmedPattern = pattern; if (null != pattern) { trimmedPattern = pattern.trim().toLowerCase(VectorApp.getApplicationLocale()); trimmedPattern = TextUtils.getTrimmedLength(trimmedPattern) == 0 ? null : trimmedPattern; } if (!TextUtils.equals(trimmedPattern, mSearchedPattern)) { mSearchedPattern = trimmedPattern; mMatchedPublicRoomsCount = null; // refresh the layout this.notifyDataSetChanged(); } }
From source file:im.neon.services.EventStreamService.java
/** * Clear any displayed notification for a dedicated room and session id. * @param accountId the account id./*from ww w. j a v a 2s . c om*/ * @param roomId the room id. */ private void cancelNotifications(String accountId, String roomId) { Log.d(LOG_TAG, "cancelNotifications " + accountId + " - " + roomId); // sanity checks if ((null != accountId) && (null != roomId)) { Log.d(LOG_TAG, "cancelNotifications expected " + mNotificationSessionId + " - " + mNotificationRoomId); // cancel the notifications if (TextUtils.equals(mNotificationRoomId, roomId) && TextUtils.equals(accountId, mNotificationSessionId)) { clearNotification(); } } }