List of usage examples for android.text TextUtils equals
public static boolean equals(CharSequence a, CharSequence b)
From source file:com.murati.oszk.audiobook.playback.LocalPlayback.java
@Override public void play(QueueItem item) { mPlayOnFocusGain = true;//from w w w. j a va2 s . c o m tryToGetAudioFocus(); registerAudioNoisyReceiver(); String mediaId = item.getDescription().getMediaId(); boolean mediaHasChanged = !TextUtils.equals(mediaId, mCurrentMediaId); if (mediaHasChanged) { mCurrentMediaId = mediaId; } if (mediaHasChanged || mExoPlayer == null) { releaseResources(false); // release everything except the player MediaMetadataCompat track = mMusicProvider .getTrack(MediaIDHelper.extractMusicIDFromMediaID(item.getDescription().getMediaId())); String source = OfflineBookService.getTrackSource(track); if (mExoPlayer == null) { mExoPlayer = ExoPlayerFactory.newSimpleInstance(mContext, new DefaultTrackSelector(), new DefaultLoadControl()); mExoPlayer.addListener(mEventListener); } // Android "O" makes much greater use of AudioAttributes, especially // with regards to AudioFocus. All of UAMP's tracks are music, but // if your content includes spoken word such as audiobooks or podcasts // then the content type should be set to CONTENT_TYPE_SPEECH for those // tracks. final AudioAttributes audioAttributes = new AudioAttributes.Builder().setContentType(CONTENT_TYPE_MUSIC) .setUsage(USAGE_MEDIA).build(); mExoPlayer.setAudioAttributes(audioAttributes); // Produces DataSource instances through which media data is loaded. DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(mContext, Util.getUserAgent(mContext, "uamp"), null); // Produces Extractor instances for parsing the media data. ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); // The MediaSource represents the media to be played. MediaSource mediaSource = new ExtractorMediaSource(Uri.parse(source), dataSourceFactory, extractorsFactory, null, null); // Prepares media to play (happens on background thread) and triggers // {@code onPlayerStateChanged} callback when the stream is ready to play. mExoPlayer.prepare(mediaSource); // 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(); } configurePlayerState(); }
From source file:com.foodie.app.fragment.MeFragment.java
private void updateUserInfo(String userId) { if (HttpUtils.isNetworkConnected(getActivity())) { //Toast.makeText(getActivity(),"sharedPref?ID"+userId,Toast.LENGTH_LONG).show(); if (userId != null && !TextUtils.equals(userId, "")) { HttpUtils.get("user/" + userId, new AsyncHttpResponseHandler() { @Override//from ww w . ja v a 2 s. co m public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) { Gson gson = new Gson(); Type type = new TypeToken<JsonResult<User>>() { }.getType(); JsonResult<User> jsonResult = gson.fromJson(new String(responseBody), type); //String status=jsonResult.getStatus(); user = jsonResult.getData(); isUserLogin = true; mUserNotLoginView.setVisibility(View.GONE); mUserLoginView.setVisibility(View.VISIBLE); mNicknameView.setText(user.getNickname()); mPhoneView.setText(user.getPhone()); //?? DisplayImageOptions userImageOptions = new DisplayImageOptions.Builder() .showImageOnLoading(R.drawable.loading_small).showImageOnFail(R.drawable.user) .cacheInMemory(true).cacheOnDisk(true).bitmapConfig(Bitmap.Config.RGB_565).build(); ImageLoader.getInstance().displayImage(user.getAvator(), mUserAvatorView, userImageOptions); } @Override public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) { Toast.makeText(getActivity(), "?" + new String(responseBody), Toast.LENGTH_LONG).show(); } }); //?? HttpUtils.getWithAuth(getActivity().getApplicationContext(), "user/fanscount/", new AsyncHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) { Gson gson = new Gson(); Type type = new TypeToken<JsonResult<Integer>>() { }.getType(); JsonResult<Integer> jsonResult = gson.fromJson(new String(responseBody), type); String status = jsonResult.getStatus(); int fansCount = 0; if (jsonResult.getData() != null) { fansCount = jsonResult.getData(); } mFansView.setText(fansCount + ""); } @Override public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) { Toast.makeText(getActivity(), "" + new String(responseBody), Toast.LENGTH_LONG).show(); } }); //? HttpUtils.getWithAuth(getActivity().getApplicationContext(), "user/followcount/", new AsyncHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) { Gson gson = new Gson(); Type type = new TypeToken<JsonResult<Integer>>() { }.getType(); JsonResult<Integer> jsonResult = gson.fromJson(new String(responseBody), type); String status = jsonResult.getStatus(); int followCount = 0; if (jsonResult.getData() != null) { followCount = jsonResult.getData(); } mFollowView.setText(followCount + ""); } @Override public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) { Toast.makeText(getActivity(), "?" + new String(responseBody), Toast.LENGTH_LONG).show(); } }); } else { Toast.makeText(getActivity(), "", Toast.LENGTH_LONG).show(); startActivity(new Intent(getActivity(), LoginActivity.class)); } } else { Toast.makeText(getActivity(), "!", Toast.LENGTH_LONG).show(); } }
From source file:im.neon.util.VectorUtils.java
/** * Vector client formats the room display with a different manner than the SDK one. * * @param context the application context. * @param session the room session./* w w w . ja v a 2 s . c o m*/ * @param room the room. * @return the room display name. */ public static String getRoomDisplayName(Context context, MXSession session, Room room) { // sanity checks if (null == room) { return null; } // this algorithm is the one defined in // https://github.com/matrix-org/matrix-js-sdk/blob/develop/lib/models/room.js#L617 // calculateRoomName(room, userId) RoomState roomState = room.getLiveState(); if (!TextUtils.isEmpty(roomState.name)) { return roomState.name; } String alias = roomState.alias; if (TextUtils.isEmpty(alias) && (roomState.getAliases().size() > 0)) { alias = roomState.getAliases().get(0); } if (!TextUtils.isEmpty(alias)) { return alias; } String myUserId = session.getMyUserId(); Collection<RoomMember> members = roomState.getDisplayableMembers(); ArrayList<RoomMember> othersActiveMembers = new ArrayList<>(); ArrayList<RoomMember> activeMembers = new ArrayList<>(); for (RoomMember member : members) { if (!TextUtils.equals(member.membership, RoomMember.MEMBERSHIP_LEAVE)) { if (!TextUtils.equals(member.getUserId(), myUserId)) { othersActiveMembers.add(member); } activeMembers.add(member); } } Collections.sort(othersActiveMembers, new Comparator<RoomMember>() { @Override public int compare(RoomMember m1, RoomMember m2) { long diff = m1.getOriginServerTs() - m2.getOriginServerTs(); return (diff == 0) ? 0 : ((diff < 0) ? -1 : +1); } }); String displayName = ""; if (othersActiveMembers.size() == 0) { if (activeMembers.size() == 1) { RoomMember member = activeMembers.get(0); if (TextUtils.equals(member.membership, RoomMember.MEMBERSHIP_INVITE)) { if (!TextUtils.isEmpty(member.getInviterId())) { // extract who invited us to the room displayName = context.getString(R.string.room_displayname_invite_from, roomState.getMemberName(member.getInviterId())); } else { displayName = context.getString(R.string.room_displayname_room_invite); } } else { displayName = context.getString(R.string.room_displayname_no_title); } } } else if (othersActiveMembers.size() == 1) { RoomMember member = othersActiveMembers.get(0); displayName = roomState.getMemberName(member.getUserId()); } else if (othersActiveMembers.size() == 2) { RoomMember member1 = othersActiveMembers.get(0); RoomMember member2 = othersActiveMembers.get(1); displayName = context.getString(R.string.room_displayname_two_members, roomState.getMemberName(member1.getUserId()), roomState.getMemberName(member2.getUserId())); } else { RoomMember member = othersActiveMembers.get(0); displayName = context.getString(R.string.room_displayname_more_than_two_members, roomState.getMemberName(member.getUserId()), othersActiveMembers.size() - 1); } return displayName; }
From source file:im.vector.util.VectorRoomMediasSender.java
/** * Send a list of images from their URIs *///from ww w. j av a2s . c om private void sendMedias() { // sanity checks if ((null == mVectorRoomActivity) || (null == mVectorMessageListFragment) || (null == mMediasCache)) { Log.d(LOG_TAG, "sendMedias : null parameters"); return; } // detect end of messages sending if ((null == mSharedDataItems) || (0 == mSharedDataItems.size())) { Log.d(LOG_TAG, "sendMedias : done"); mImageCompressionDescription = null; mSharedDataItems = null; mVectorRoomActivity.runOnUiThread(new Runnable() { @Override public void run() { mVectorMessageListFragment.scrollToBottom(); mVectorRoomActivity.cancelSelectionMode(); mVectorRoomActivity.setProgressVisibility(View.GONE); } }); return; } // display a spinner mVectorRoomActivity.cancelSelectionMode(); mVectorRoomActivity.setProgressVisibility(View.VISIBLE); Log.d(LOG_TAG, "sendMedias : " + mSharedDataItems.size() + " items to send"); mMediasSendingHandler.post(new Runnable() { @Override public void run() { SharedDataItem sharedDataItem = mSharedDataItems.get(0); String mimeType = sharedDataItem.getMimeType(mVectorRoomActivity); // avoid null case if (null == mimeType) { mimeType = ""; } if (TextUtils.equals(ClipDescription.MIMETYPE_TEXT_INTENT, mimeType)) { Log.d(LOG_TAG, "sendMedias : unsupported mime type"); // don't know how to manage it -> skip it // GA issue if (mSharedDataItems.size() > 0) { mSharedDataItems.remove(0); } sendMedias(); } else if (TextUtils.equals(ClipDescription.MIMETYPE_TEXT_PLAIN, mimeType) || TextUtils.equals(ClipDescription.MIMETYPE_TEXT_HTML, mimeType)) { sendTextMessage(sharedDataItem); } else { // check if it is an uri // else we don't know what to do if (null == sharedDataItem.getUri()) { Log.e(LOG_TAG, "sendMedias : null uri"); // manage others if (mSharedDataItems.size() > 0) { mSharedDataItems.remove(0); } sendMedias(); return; } final String fFilename = sharedDataItem.getFileName(mVectorRoomActivity); ResourceUtils.Resource resource = ResourceUtils.openResource(mVectorRoomActivity, sharedDataItem.getUri(), sharedDataItem.getMimeType(mVectorRoomActivity)); if (null == resource) { Log.e(LOG_TAG, "sendMedias : " + fFilename + " is not found"); mVectorRoomActivity.runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(mVectorRoomActivity, mVectorRoomActivity.getString(R.string.room_message_file_not_found), Toast.LENGTH_LONG).show(); } }); // manage others if (mSharedDataItems.size() > 0) { mSharedDataItems.remove(0); } sendMedias(); return; } if (mimeType.startsWith("image/")) { sendImageMessage(sharedDataItem, resource); } else if (mimeType.startsWith("video/")) { sendVideoMessage(sharedDataItem, resource); } else { sendFileMessage(sharedDataItem, resource); } } } }); }
From source file:im.neon.util.VectorRoomMediasSender.java
/** * Send a list of images from their URIs *///from w w w . j ava 2 s.c om private void sendMedias() { // sanity checks if ((null == mVectorRoomActivity) || (null == mVectorMessageListFragment) || (null == mMediasCache)) { Log.d(LOG_TAG, "sendMedias : null parameters"); return; } // detect end of messages sending if ((null == mSharedDataItems) || (0 == mSharedDataItems.size())) { Log.d(LOG_TAG, "sendMedias : done"); mImageCompressionDescription = null; mSharedDataItems = null; mVectorRoomActivity.runOnUiThread(new Runnable() { @Override public void run() { mVectorMessageListFragment.scrollToBottom(); mVectorRoomActivity.cancelSelectionMode(); mVectorRoomActivity.setProgressVisibility(View.GONE); } }); return; } // display a spinner mVectorRoomActivity.cancelSelectionMode(); mVectorRoomActivity.setProgressVisibility(View.VISIBLE); Log.d(LOG_TAG, "sendMedias : " + mSharedDataItems.size() + " items to send"); mMediasSendingHandler.post(new Runnable() { @Override public void run() { SharedDataItem sharedDataItem = mSharedDataItems.get(0); String mimeType = sharedDataItem.getMimeType(mVectorRoomActivity); // avoid null case if (null == mimeType) { mimeType = ""; } if (TextUtils.equals(ClipDescription.MIMETYPE_TEXT_INTENT, mimeType)) { Log.d(LOG_TAG, "sendMedias : unsupported mime type"); // don't know how to manage it -> skip it // GA issue if (mSharedDataItems.size() > 0) { mSharedDataItems.remove(0); } sendMedias(); } else if ((null == sharedDataItem.getUri()) && (TextUtils.equals(ClipDescription.MIMETYPE_TEXT_PLAIN, mimeType) || TextUtils.equals(ClipDescription.MIMETYPE_TEXT_HTML, mimeType))) { sendTextMessage(sharedDataItem); } else { // check if it is an uri // else we don't know what to do if (null == sharedDataItem.getUri()) { Log.e(LOG_TAG, "sendMedias : null uri"); // manage others if (mSharedDataItems.size() > 0) { mSharedDataItems.remove(0); } sendMedias(); return; } final String fFilename = sharedDataItem.getFileName(mVectorRoomActivity); ResourceUtils.Resource resource = ResourceUtils.openResource(mVectorRoomActivity, sharedDataItem.getUri(), sharedDataItem.getMimeType(mVectorRoomActivity)); if (null == resource) { Log.e(LOG_TAG, "sendMedias : " + fFilename + " is not found"); mVectorRoomActivity.runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(mVectorRoomActivity, mVectorRoomActivity.getString(R.string.room_message_file_not_found), Toast.LENGTH_LONG).show(); } }); // manage others if (mSharedDataItems.size() > 0) { mSharedDataItems.remove(0); } sendMedias(); return; } if (mimeType.startsWith("image/")) { sendImageMessage(sharedDataItem, resource); } else if (mimeType.startsWith("video/")) { sendVideoMessage(sharedDataItem, resource); } else { sendFileMessage(sharedDataItem, resource); } } } }); }
From source file:com.ntsync.android.sync.activities.ImportActivity.java
private void updateBtnState() { Spinner sourceAcSpinner = (Spinner) findViewById(R.id.sourceAccountSpinner); AccountInfo sourceAcInfo = (AccountInfo) sourceAcSpinner.getSelectedItem(); String destAccountName = gestDestinationAccountName(); boolean destMatchSource = sourceAcInfo != null && Constants.ACCOUNT_TYPE.equals(sourceAcInfo.accountType) && TextUtils.equals(sourceAcInfo.accountName, destAccountName); boolean importEnabled = accountAvailable && sourceAcInfo != null && !destMatchSource && destAccountName != null; // Enabled/Disable Import findViewById(R.id.buttonImport).setEnabled(importEnabled); boolean showSourceAccountSpinner = false; boolean showDestAccountSpinner = false; boolean showNoContactsMsg = false; if (sourceAccountAdapter.getCount() == 0) { showNoContactsMsg = true;/*from ww w . j a v a 2 s . c o m*/ } else { showSourceAccountSpinner = true; if (destAccountAdapter.getCount() > 0) { showDestAccountSpinner = true; } } setNoContactsMsg(showNoContactsMsg); setDestinationAccountSelector(showDestAccountSpinner); setSourceAccountSelector(showSourceAccountSpinner, sourceAcInfo != null && sourceAcInfo.localAccount); }
From source file:com.example.chu.googleplaylibrary.playback.CastPlayback.java
private void loadMedia(String mediaId, boolean autoPlay) throws TransientNetworkDisconnectionException, NoConnectionException, JSONException { String musicId = MediaIDHelper.extractMusicIDFromMediaID(mediaId); // MediaMetadataCompat track = mMusicProvider.getMusic(musicId); // if (track == null) { // throw new IllegalArgumentException("Invalid mediaId " + mediaId); // }//w w w . jav a 2 s .co m if (!TextUtils.equals(mediaId, mCurrentMediaId)) { mCurrentMediaId = mediaId; mCurrentPosition = 0; } JSONObject customData = new JSONObject(); customData.put(ITEM_ID, mediaId); MediaInfo media = toCastMediaMetadata(track, customData); VideoCastManager.getInstance().loadMedia(media, autoPlay, mCurrentPosition, customData); }
From source file:com.ruesga.rview.fragments.SetAccountStatusDialogFragment.java
private void performAccountStateChanged() { if (TextUtils.equals(mModel.description, mOriginalStatus)) { dismiss();/* ww w . ja v a 2 s . com*/ return; } mSetAccountStateLoader.clear(); mSetAccountStateLoader.restart(mModel.description); }
From source file:be.evias.cloudLogin.cloudLoginRunPointActivity.java
/** * Show all the accounts registered on the account manager. * Request an auth token upon user select. * * @param authTokenType String// w ww . java2s .co m */ private void displayAccountPicker(final String authTokenType) { final boolean isActiveAccount = mPrefs.getBoolean("cloudlogin_active_account", false); final String activeAccountName = mPrefs.getString("cloudlogin_active_account_name", ""); final Account availableAccounts[] = mAccountManager.getAccountsByType(AccountBase.ACCOUNT_TYPE); if (availableAccounts.length == 0) { Toast.makeText(this, getBaseContext().getString(R.string.message_no_accounts_yet), Toast.LENGTH_SHORT) .show(); addNewAccount(AccountBase.ACCOUNT_TYPE, AccountBase.AUTHTOKEN_TYPE_FULL_ACCESS); } else if (!isActiveAccount) { /* accounts are available but login is needed. */ showMessage(getBaseContext().getString(R.string.message_session_expired), Toast.LENGTH_SHORT); /* user must re-login for more security (token is invalidated.) */ addNewAccount(AccountBase.ACCOUNT_TYPE, AccountBase.AUTHTOKEN_TYPE_FULL_ACCESS); } else if (availableAccounts.length == 1) { /* single account, try to auto-login. */ getAccountAuthToken(availableAccounts[0], authTokenType); } else { /* more than one account registered. Display a list of available accounts for the user to pick. */ /* no account is currently active on the device. Display a list of available cloudLogin accounts. */ String name[] = new String[availableAccounts.length]; for (int i = 0; i < availableAccounts.length; i++) name[i] = availableAccounts[i].name; mAlertDialog = new AlertDialog.Builder(this) .setTitle(getBaseContext().getString(R.string.title_pick_account)) .setAdapter( new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_list_item_1, name), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (TextUtils.equals(activeAccountName, availableAccounts[which].name)) getAccountAuthToken(availableAccounts[which], authTokenType); else addNewAccount(AccountBase.ACCOUNT_TYPE, AccountBase.AUTHTOKEN_TYPE_FULL_ACCESS); } }) .create(); mAlertDialog.show(); } }
From source file:com.guoxiaoxing.music.playback.CastPlayback.java
private void loadMedia(String mediaId, boolean autoPlay) throws TransientNetworkDisconnectionException, NoConnectionException, JSONException { String musicId = MediaIDHelper.extractMusicIDFromMediaID(mediaId); MediaMetadataCompat track = mMusicProvider.getMusic(musicId); if (track == null) { throw new IllegalArgumentException("Invalid mediaId " + mediaId); }/*from w ww.j ava2 s . c om*/ if (!TextUtils.equals(mediaId, mCurrentMediaId)) { mCurrentMediaId = mediaId; mCurrentPosition = 0; } JSONObject customData = new JSONObject(); customData.put(ITEM_ID, mediaId); MediaInfo media = toCastMediaMetadata(track, customData); VideoCastManager.getInstance().loadMedia(media, autoPlay, mCurrentPosition, customData); }