List of usage examples for android.text TextUtils equals
public static boolean equals(CharSequence a, CharSequence b)
From source file:com.waz.zclient.MainActivity.java
private void handleReferral() { String referralToken = getControllerFactory().getUserPreferencesController().getReferralToken(); getControllerFactory().getUserPreferencesController().setReferralToken(null); if (TextUtils.isEmpty(referralToken) || TextUtils.equals(referralToken, AppEntryStore.GENERAL_GENERIC_INVITE_TOKEN)) { return;// w w w.j a va2 s.co m } getStoreFactory().getConnectStore().requestConnection(referralToken); getControllerFactory().getTrackingController().tagEvent(new AcceptedGenericInviteEvent()); }
From source file:im.vector.fragments.VectorRecentsListFragment.java
/** * Add a MXEventListener to the session listeners. *///from w w w .ja v a2 s. c om private void addSessionListener() { mEventsListener = new MXEventListener() { private boolean mInitialSyncComplete = false; @Override public void onInitialSyncComplete() { Log.d(LOG_TAG, "## onInitialSyncComplete()"); getActivity().runOnUiThread(new Runnable() { @Override public void run() { mInitialSyncComplete = true; notifyDataSetChanged(); } }); } @Override public void onLiveEventsChunkProcessed() { getActivity().runOnUiThread(new Runnable() { @Override public void run() { Log.d(LOG_TAG, "onLiveEventsChunkProcessed"); if (!mIsPaused && refreshOnChunkEnd && !mIsWaitingTagOrderEcho) { notifyDataSetChanged(); } refreshOnChunkEnd = false; } }); } @Override public void onLiveEvent(final Event event, final RoomState roomState) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { // refresh the UI at the end of the next events chunk refreshOnChunkEnd |= ((event.roomId != null) && RoomSummary.isSupportedEvent(event)) || Event.EVENT_TYPE_STATE_ROOM_MEMBER.equals(event.type) || Event.EVENT_TYPE_TAGS.equals(event.type) || Event.EVENT_TYPE_REDACTION.equals(event.type) || Event.EVENT_TYPE_RECEIPT.equals(event.type) || Event.EVENT_TYPE_STATE_ROOM_AVATAR.equals(event.type) || Event.EVENT_TYPE_STATE_ROOM_THIRD_PARTY_INVITE.equals(event.type); // highlight notified messages // the SDK only highlighted invitation messages // it lets the application chooses the behaviour. ViewedRoomTracker rTracker = ViewedRoomTracker.getInstance(); String viewedRoomId = rTracker.getViewedRoomId(); String fromMatrixId = rTracker.getMatrixId(); MXSession session = VectorRecentsListFragment.this.mSession; String matrixId = session.getCredentials().userId; // If we're not currently viewing this room or not sent by myself, increment the unread count if ((!TextUtils.equals(event.roomId, viewedRoomId) || !TextUtils.equals(matrixId, fromMatrixId)) && !TextUtils.equals(event.getSender(), matrixId)) { RoomSummary summary = session.getDataHandler().getStore().getSummary(event.roomId); if (null != summary) { summary.setHighlighted( summary.isHighlighted() || EventUtils.shouldHighlight(session, event)); } } } }); } @Override public void onReceiptEvent(String roomId, List<String> senderIds) { // refresh only if the current user read some messages (to update the unread messages counters) refreshOnChunkEnd |= (senderIds .indexOf(VectorRecentsListFragment.this.mSession.getCredentials().userId) >= 0); } @Override public void onRoomTagEvent(String roomId) { mIsWaitingTagOrderEcho = false; refreshOnChunkEnd = true; } /** * These methods trigger an UI refresh asap because the user could have created / joined / left a room * but the server events echos are not yet received. * */ private void onForceRefresh() { if (mInitialSyncComplete) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { notifyDataSetChanged(); } }); } } @Override public void onStoreReady() { onForceRefresh(); } @Override public void onLeaveRoom(final String roomId) { // clear any pending notification for this room EventStreamService.cancelNotificationsForRoomId(mSession.getMyUserId(), roomId); onForceRefresh(); } @Override public void onNewRoom(String roomId) { onForceRefresh(); } @Override public void onJoinRoom(String roomId) { onForceRefresh(); } }; mSession.getDataHandler().addListener(mEventsListener); }
From source file:com.google.android.apps.muzei.provider.MuzeiProvider.java
private Uri insertArtwork(@NonNull final Uri uri, final ContentValues values) { Context context = getContext(); if (context == null) { return null; }/*from w w w. j a va2 s . co m*/ if (values == null) { throw new IllegalArgumentException("Invalid ContentValues: must not be null"); } if (!values.containsKey(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME) || TextUtils.isEmpty(values.getAsString(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME))) { throw new IllegalArgumentException("Initial values must contain component name: " + values); } // Check to make sure the component name is valid ComponentName componentName = ComponentName .unflattenFromString(values.getAsString(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME)); if (componentName == null) { throw new IllegalArgumentException("Invalid component name: " + values.getAsString(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME)); } // Make sure they are using the short string format values.put(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME, componentName.flattenToShortString()); // Ensure the app inserting the artwork is either Muzei or the same app as the source String callingPackageName = getCallingPackage(); if (!context.getPackageName().equals(callingPackageName) && !TextUtils.equals(callingPackageName, componentName.getPackageName())) { throw new IllegalArgumentException("Calling package name (" + callingPackageName + ") must match the source's package name (" + componentName.getPackageName() + ")"); } if (values.containsKey(MuzeiContract.Artwork.COLUMN_NAME_VIEW_INTENT)) { String viewIntentString = values.getAsString(MuzeiContract.Artwork.COLUMN_NAME_VIEW_INTENT); Intent viewIntent; try { if (!TextUtils.isEmpty(viewIntentString)) { // Make sure it is a valid Intent URI viewIntent = Intent.parseUri(viewIntentString, Intent.URI_INTENT_SCHEME); // Make sure we can construct a PendingIntent for the Intent PendingIntent.getActivity(context, 0, viewIntent, PendingIntent.FLAG_UPDATE_CURRENT); } } catch (URISyntaxException e) { Log.w(TAG, "Removing invalid View Intent: " + viewIntentString, e); values.remove(MuzeiContract.Artwork.COLUMN_NAME_VIEW_INTENT); } catch (RuntimeException e) { // This is actually meant to catch a FileUriExposedException, but you can't // have catch statements for exceptions that don't exist at your minSdkVersion Log.w(TAG, "Removing invalid View Intent that contains a file:// URI: " + viewIntentString, e); values.remove(MuzeiContract.Artwork.COLUMN_NAME_VIEW_INTENT); } } // Ensure the related source has been added to the database. // This should be true in 99.9% of cases, but the insert will fail if this isn't true Cursor sourceQuery = querySource(MuzeiContract.Sources.CONTENT_URI, new String[] { BaseColumns._ID }, MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME + "=?", new String[] { componentName.flattenToShortString() }, null); if (sourceQuery == null || sourceQuery.getCount() == 0) { ContentValues initialValues = new ContentValues(); initialValues.put(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME, componentName.flattenToShortString()); insertSource(MuzeiContract.Sources.CONTENT_URI, initialValues); } if (sourceQuery != null) { sourceQuery.close(); } values.put(MuzeiContract.Artwork.COLUMN_NAME_DATE_ADDED, System.currentTimeMillis()); final SQLiteDatabase db = databaseHelper.getWritableDatabase(); long rowId = db.insert(MuzeiContract.Artwork.TABLE_NAME, MuzeiContract.Artwork.COLUMN_NAME_IMAGE_URI, values); // If the insert succeeded, the row ID exists. if (rowId > 0) { // Creates a URI with the artwork ID pattern and the new row ID appended to it. final Uri artworkUri = ContentUris.withAppendedId(MuzeiContract.Artwork.CONTENT_URI, rowId); File artwork = getCacheFileForArtworkUri(artworkUri); if (artwork != null && artwork.exists()) { // The image already exists so we'll notifyChange() to say the new artwork is ready // Otherwise, this will be called when the file is written with openFile() // using this Uri and the actual artwork is written successfully notifyChange(artworkUri); } return artworkUri; } // If the insert didn't succeed, then the rowID is <= 0 throw new SQLException("Failed to insert row into " + uri); }
From source file:assistive.com.scanme.com.googlecode.eyesfree.utils.AccessibilityNodeInfoUtils.java
/** * Determines if the generating class of an * {@link AccessibilityNodeInfoCompat} matches a given {@link Class} by * type.//from w w w.ja v a 2 s .c om * * @param node A sealed {@link AccessibilityNodeInfoCompat} dispatched by * the accessibility framework. * @param referenceClass A {@link Class} to match by type or inherited type. * @return {@code true} if the {@link AccessibilityNodeInfoCompat} object * matches the {@link Class} by type or inherited type, * {@code false} otherwise. */ public static boolean nodeMatchesClassByType(Context context, AccessibilityNodeInfoCompat node, Class<?> referenceClass) { if ((node == null) || (referenceClass == null)) { return false; } // Attempt to take a shortcut. final CharSequence nodeClassName = node.getClassName(); if (TextUtils.equals(nodeClassName, referenceClass.getName())) { return true; } final ClassLoadingManager loader = ClassLoadingManager.getInstance(); final CharSequence appPackage = node.getPackageName(); return loader.checkInstanceOf(context, nodeClassName, appPackage, referenceClass); }
From source file:com.zhihu.android.app.mirror.app.MainActivity.java
private void onMirrorLostEvent(MirrorLostEvent event) { MirrorInfo mirrorInfo = event.getMirrorInfo(); int position = -1; for (int i = 0; i < mMirrorInfoList.size(); i++) { MirrorInfo info = mMirrorInfoList.get(i); if (TextUtils.equals(info.getName(), mirrorInfo.getName())) { position = i;//from ww w. ja va2 s .com break; } } // add 1 for top placeholder if (position >= 0) { mMirrorInfoList.remove(position); mMirrorListAdapter.notifyItemRemoved(position + 1); } if (mCurrentMirror != null && TextUtils.equals(mCurrentMirror.getName(), mirrorInfo.getName())) { String currentSketch = MirrorUtils.getCurrentSketch(this, mCurrentMirror); mConnectStatusLayout.setConnectStatus(ConnectStatusLayout.DISCONNECTED, currentSketch); switchToMirrorListView(); } }
From source file:com.android.messaging.datamodel.BugleNotifications.java
/** * Returns the thumbnailUri from the avatar URI, or null if avatar URI does not have thumbnail. *//* w w w .java2s . co m*/ private static Uri getThumbnailUri(final Uri avatarUri) { Uri localUri = null; final String avatarType = AvatarUriUtil.getAvatarType(avatarUri); if (TextUtils.equals(avatarType, AvatarUriUtil.TYPE_LOCAL_RESOURCE_URI)) { localUri = AvatarUriUtil.getPrimaryUri(avatarUri); } else if (UriUtil.isLocalResourceUri(avatarUri)) { localUri = avatarUri; } if (localUri != null && localUri.getAuthority().equals(ContactsContract.AUTHORITY)) { // Contact photos are of the form: content://com.android.contacts/contacts/123/photo final List<String> pathParts = localUri.getPathSegments(); if (pathParts.size() == 3 && pathParts.get(2).equals(Contacts.Photo.CONTENT_DIRECTORY)) { return localUri; } } return null; }
From source file:im.neon.fragments.VectorRecentsListFragment.java
/** * Add a MXEventListener to the session listeners. *///from w ww.j a v a 2s.co m private void addSessionListener() { mEventsListener = new MXEventListener() { private boolean mInitialSyncComplete = false; @Override public void onInitialSyncComplete(String toToken) { Log.d(LOG_TAG, "## onInitialSyncComplete()"); getActivity().runOnUiThread(new Runnable() { @Override public void run() { mInitialSyncComplete = true; notifyDataSetChanged(); } }); } @Override public void onLiveEventsChunkProcessed(String fromToken, String toToken) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { Log.d(LOG_TAG, "onLiveEventsChunkProcessed"); if (!mIsPaused && refreshOnChunkEnd && !mIsWaitingTagOrderEcho && !mIsWaitingDirectChatEcho) { notifyDataSetChanged(); } refreshOnChunkEnd = false; } }); } @Override public void onLiveEvent(final Event event, final RoomState roomState) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { String eventType = event.getType(); // refresh the UI at the end of the next events chunk refreshOnChunkEnd |= ((event.roomId != null) && RoomSummary.isSupportedEvent(event)) || Event.EVENT_TYPE_STATE_ROOM_MEMBER.equals(eventType) || Event.EVENT_TYPE_TAGS.equals(eventType) || Event.EVENT_TYPE_REDACTION.equals(eventType) || Event.EVENT_TYPE_RECEIPT.equals(eventType) || Event.EVENT_TYPE_STATE_ROOM_AVATAR.equals(eventType) || Event.EVENT_TYPE_STATE_ROOM_THIRD_PARTY_INVITE.equals(eventType); // highlight notified messages // the SDK only highlighted invitation messages // it lets the application chooses the behaviour. ViewedRoomTracker rTracker = ViewedRoomTracker.getInstance(); String viewedRoomId = rTracker.getViewedRoomId(); String fromMatrixId = rTracker.getMatrixId(); MXSession session = VectorRecentsListFragment.this.mSession; String matrixId = session.getCredentials().userId; // If we're not currently viewing this room or not sent by myself, increment the unread count if ((!TextUtils.equals(event.roomId, viewedRoomId) || !TextUtils.equals(matrixId, fromMatrixId)) && !TextUtils.equals(event.getSender(), matrixId)) { RoomSummary summary = session.getDataHandler().getStore().getSummary(event.roomId); if (null != summary) { summary.setHighlighted( summary.isHighlighted() || EventUtils.shouldHighlight(session, event)); } } } }); } @Override public void onReceiptEvent(String roomId, List<String> senderIds) { // refresh only if the current user read some messages (to update the unread messages counters) refreshOnChunkEnd |= (senderIds .indexOf(VectorRecentsListFragment.this.mSession.getCredentials().userId) >= 0); } @Override public void onRoomTagEvent(String roomId) { mIsWaitingTagOrderEcho = false; refreshOnChunkEnd = true; } /** * These methods trigger an UI refresh asap because the user could have created / joined / left a room * but the server events echos are not yet received. * */ private void onForceRefresh() { if (mInitialSyncComplete) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { notifyDataSetChanged(); } }); } } @Override public void onStoreReady() { onForceRefresh(); } @Override public void onLeaveRoom(final String roomId) { // clear any pending notification for this room EventStreamService.cancelNotificationsForRoomId(mSession.getMyUserId(), roomId); onForceRefresh(); } @Override public void onNewRoom(String roomId) { onForceRefresh(); } @Override public void onJoinRoom(String roomId) { onForceRefresh(); } @Override public void onDirectMessageChatRoomsListUpdate() { mIsWaitingDirectChatEcho = false; refreshOnChunkEnd = true; } @Override public void onEventDecrypted(Event event) { RoomSummary summary = mSession.getDataHandler().getStore().getSummary(event.roomId); if (null != summary) { // test if the latest event is refreshed Event latestReceivedEvent = summary.getLatestReceivedEvent(); if ((null != latestReceivedEvent) && TextUtils.equals(latestReceivedEvent.eventId, event.eventId)) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { notifyDataSetChanged(); } }); } } } }; mSession.getDataHandler().addListener(mEventsListener); }
From source file:com.silentcircle.contacts.list.ScContactEntryListFragment.java
public void setQueryString(String queryString, boolean delaySelection) { // Normalize the empty query. if (TextUtils.isEmpty(queryString)) queryString = null;//from ww w. ja v a2s. c o m if (!TextUtils.equals(mQueryString, queryString)) { mQueryString = queryString; setSearchMode(!TextUtils.isEmpty(mQueryString)); if (mAdapter != null) { mAdapter.setQueryString(queryString); reloadData(); } } }
From source file:com.google.android.apps.muzei.settings.ChooseSourceFragment.java
private void redrawSources() { if (mSourceContainerView == null || !isAdded()) { return;/*from w ww . j av a2 s .c om*/ } mSourceContainerView.removeAllViews(); for (final Source source : mSources) { source.rootView = LayoutInflater.from(getContext()).inflate(R.layout.settings_choose_source_item, mSourceContainerView, false); source.selectSourceButton = source.rootView.findViewById(R.id.source_image); source.selectSourceButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (source.componentName.equals(mSelectedSource)) { if (getContext() instanceof Callbacks) { ((Callbacks) getContext()).onRequestCloseActivity(); } else if (getParentFragment() instanceof Callbacks) { ((Callbacks) getParentFragment()).onRequestCloseActivity(); } } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && source.targetSdkVersion >= Build.VERSION_CODES.O) { AlertDialog.Builder builder = new AlertDialog.Builder(getContext()) .setTitle(R.string.action_source_target_too_high_title) .setMessage(R.string.action_source_target_too_high_message) .setNegativeButton(R.string.action_source_target_too_high_learn_more, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse( "https://medium.com/@ianhlake/the-muzei-plugin-api-and-androids-evolution-9b9979265cfb"))); } }) .setPositiveButton(R.string.action_source_target_too_high_dismiss, null); final Intent sendFeedbackIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + source.componentName.getPackageName())); if (sendFeedbackIntent.resolveActivity(getContext().getPackageManager()) != null) { builder.setNeutralButton( getString(R.string.action_source_target_too_high_send_feedback, source.label), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { startActivity(sendFeedbackIntent); } }); } builder.show(); } else if (source.setupActivity != null) { Bundle bundle = new Bundle(); bundle.putString(FirebaseAnalytics.Param.ITEM_ID, source.componentName.flattenToShortString()); bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, source.label); bundle.putString(FirebaseAnalytics.Param.ITEM_CATEGORY, "sources"); FirebaseAnalytics.getInstance(getContext()).logEvent(FirebaseAnalytics.Event.VIEW_ITEM, bundle); mCurrentInitialSetupSource = source.componentName; launchSourceSetup(source); } else { Bundle bundle = new Bundle(); bundle.putString(FirebaseAnalytics.Param.ITEM_ID, source.componentName.flattenToShortString()); bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "sources"); FirebaseAnalytics.getInstance(getContext()).logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle); SourceManager.selectSource(getContext(), source.componentName); } } }); source.selectSourceButton.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { final String pkg = source.componentName.getPackageName(); if (TextUtils.equals(pkg, getContext().getPackageName())) { // Don't open Muzei's app info return false; } // Otherwise open third party extensions try { startActivity(new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.fromParts("package", pkg, null))); } catch (final ActivityNotFoundException e) { return false; } return true; } }); float alpha = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && source.targetSdkVersion >= Build.VERSION_CODES.O ? ALPHA_DISABLED : ALPHA_UNSELECTED; source.rootView.setAlpha(alpha); source.icon.setColorFilter(source.color, PorterDuff.Mode.SRC_ATOP); source.selectSourceButton.setBackground(source.icon); TextView titleView = source.rootView.findViewById(R.id.source_title); titleView.setText(source.label); titleView.setTextColor(source.color); updateSourceStatusUi(source); source.settingsButton = source.rootView.findViewById(R.id.source_settings_button); TooltipCompat.setTooltipText(source.settingsButton, source.settingsButton.getContentDescription()); source.settingsButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { launchSourceSettings(source); } }); animateSettingsButton(source.settingsButton, false, false); mSourceContainerView.addView(source.rootView); } updateSelectedItem(mCurrentSourceLiveData.getValue(), false); }
From source file:com.taobao.weex.WXSDKInstance.java
private void renderByUrlInternal(String pageName, final String url, Map<String, Object> options, final String jsonInitData, final WXRenderStrategy flag) { ensureRenderArchor();/*from w w w.j ava2s.c o m*/ pageName = wrapPageName(pageName, url); mBundleUrl = url; if (WXSDKManager.getInstance().getValidateProcessor() != null) { mNeedValidate = WXSDKManager.getInstance().getValidateProcessor().needValidate(mBundleUrl); } Map<String, Object> renderOptions = options; if (renderOptions == null) { renderOptions = new HashMap<>(); } if (!renderOptions.containsKey(BUNDLE_URL)) { renderOptions.put(BUNDLE_URL, url); } mApmForInstance.doInit(); Uri uri = Uri.parse(url); if (uri != null && TextUtils.equals(uri.getScheme(), "file")) { mApmForInstance.onStage(WXInstanceApm.KEY_PAGE_STAGES_DOWN_BUNDLE_START); String template = WXFileUtils.loadFileOrAsset(assembleFilePath(uri), mContext); mApmForInstance.onStage(WXInstanceApm.KEY_PAGE_STAGES_DOWN_BUNDLE_END); render(pageName, template, renderOptions, jsonInitData, flag); return; } IWXHttpAdapter adapter = WXSDKManager.getInstance().getIWXHttpAdapter(); WXRequest wxRequest = new WXRequest(); wxRequest.url = rewriteUri(Uri.parse(url), URIAdapter.BUNDLE).toString(); if (wxRequest != null && !TextUtils.isEmpty(wxRequest.url)) { requestUrl = wxRequest.url; } else { requestUrl = pageName; } if (wxRequest.paramMap == null) { wxRequest.paramMap = new HashMap<String, String>(); } wxRequest.instanceId = getInstanceId(); wxRequest.paramMap.put(KEY_USER_AGENT, WXHttpUtil.assembleUserAgent(mContext, WXEnvironment.getConfig())); WXHttpListener httpListener = new WXHttpListener(pageName, renderOptions, jsonInitData, flag, System.currentTimeMillis()); httpListener.setSDKInstance(this); adapter.sendRequest(wxRequest, (IWXHttpAdapter.OnHttpListener) httpListener); }