List of usage examples for twitter4j User getScreenName
String getScreenName();
From source file:com.daiv.android.twitter.utils.NotificationUtils.java
License:Apache License
public static void newInteractions(User interactor, Context context, SharedPreferences sharedPrefs, String type) {// w w w .j a va 2s . c o m String title = ""; String text = ""; String smallText = ""; Bitmap icon = null; AppSettings settings = AppSettings.getInstance(context); int newFollowers = sharedPrefs.getInt("new_followers", 0); int newRetweets = sharedPrefs.getInt("new_retweets", 0); int newFavorites = sharedPrefs.getInt("new_favorites", 0); int newQuotes = sharedPrefs.getInt("new_quotes", 0); // set title if (newFavorites + newRetweets + newFollowers > 1) { title = context.getResources().getString(R.string.new_interactions); } else { title = context.getResources().getString(R.string.new_interaction_upper); } // set text String currText = sharedPrefs.getString("old_interaction_text", ""); if (!currText.equals("")) { currText += "<br>"; } if (settings.displayScreenName) { text = currText + "<b>" + interactor.getScreenName() + "</b> " + type; } else { text = currText + "<b>" + interactor.getName() + "</b> " + type; } sharedPrefs.edit().putString("old_interaction_text", text).commit(); // set icon int types = 0; if (newFavorites > 0) { types++; } if (newFollowers > 0) { types++; } if (newRetweets > 0) { types++; } if (newQuotes > 0) { types++; } if (types > 1) { icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_stat_icon); } else { if (newFavorites > 0) { icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_action_important_dark); } else if (newRetweets > 0) { icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_action_repeat_dark); } else { icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.drawer_user_dark); } } // set shorter text int total = newFavorites + newFollowers + newRetweets + newQuotes; if (total > 1) { smallText = total + " " + context.getResources().getString(R.string.new_interactions_lower); } else { smallText = text; } Intent markRead = new Intent(context, ReadInteractionsService.class); PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0); Intent deleteIntent = new Intent(context, NotificationDeleteReceiverOne.class); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(Html.fromHtml( settings.addonTheme ? smallText.replaceAll("FF8800", settings.accentColor) : smallText)) .setSmallIcon(R.drawable.ic_stat_icon).setLargeIcon(icon).setTicker(title) .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)) .setPriority(NotificationCompat.PRIORITY_HIGH).setAutoCancel(true); if (context.getResources().getBoolean(R.bool.expNotifications)) { mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText( Html.fromHtml(settings.addonTheme ? text.replaceAll("FF8800", settings.accentColor) : text))); } if (settings.vibrate) { mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); } if (settings.sound) { try { mBuilder.setSound(Uri.parse(settings.ringtone)); } catch (Exception e) { mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } } if (settings.led) mBuilder.setLights(0xFFFFFF, 1000, 1000); if (settings.notifications) { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); notificationManager.notify(4, mBuilder.build()); // if we want to wake the screen on a new message if (settings.wakeScreen) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG"); wakeLock.acquire(5000); } // Pebble notification if (sharedPrefs.getBoolean("pebble_notification", false)) { sendAlertToPebble(context, title, text); } // Light Flow notification sendToLightFlow(context, title, text); } }
From source file:com.daiv.android.twitter.utils.text.TouchableSpan.java
License:Apache License
public void longClickMentions() { AlertDialog.Builder builder = getBuilder(); builder.setItems(R.array.long_click_mentions, new DialogInterface.OnClickListener() { @Override//from w ww . j a v a2 s.co m public void onClick(DialogInterface dialogInterface, int i) { final SharedPreferences sharedPrefs = mContext.getSharedPreferences( "com.daiv.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); switch (i) { case 0: // open profile TouchableSpan.this.onClick(null); break; case 1: // copy handle copy(); break; case 2: // search user search(); break; case 3: // favorite user new Thread(new Runnable() { @Override public void run() { try { Twitter twitter = Utils.getTwitter(mContext, settings); User user = twitter.showUser(full.replace("@", "")); int current = sharedPrefs.getInt("current_account", 1); FavoriteUsersDataSource.getInstance(mContext).createUser(user, current); sharedPrefs.edit() .putString("favorite_user_names_" + current, sharedPrefs.getString("favorite_user_names_" + current, "") + user.getScreenName() + " ") .commit(); } catch (Exception e) { } } }).start(); break; case 4: // mute user String current = sharedPrefs.getString("muted_users", ""); sharedPrefs.edit() .putString("muted_users", current + full.replaceAll(" ", "").replaceAll("@", "") + " ") .commit(); sharedPrefs.edit().putBoolean("refresh_me", true).commit(); sharedPrefs.edit().putBoolean("just_muted", true).commit(); if (mContext instanceof DrawerActivity) { ((Activity) mContext).recreate(); } break; case 5: // mute retweets String muted_rts = sharedPrefs.getString("muted_rts", ""); sharedPrefs.edit() .putString("muted_rts", muted_rts + full.replaceAll(" ", "").replaceAll("@", "") + " ") .commit(); sharedPrefs.edit().putBoolean("refresh_me", true).commit(); sharedPrefs.edit().putBoolean("just_muted", true).commit(); if (mContext instanceof DrawerActivity) { ((Activity) mContext).recreate(); } break; case 6: // share profile share("https://twitter.com/" + full.replace("@", "").replace(" ", "")); break; } } }); builder.create().show(); }
From source file:com.dwdesign.tweetings.fragment.UserListDetailsFragment.java
License:Open Source License
public void changeUserList(final long account_id, final UserList user_list) { if (user_list == null || getActivity() == null || !isMyActivatedAccount(getActivity(), account_id)) return;//from w w w .j a v a 2 s. c o m getLoaderManager().destroyLoader(0); final User user = user_list.getUser(); if (user == null) return; final boolean is_my_activated_account = isMyActivatedAccount(getActivity(), user_list.getId()); mErrorRetryContainer.setVisibility(View.GONE); mAccountId = account_id; mUserListId = user_list.getId(); mUserName = user.getName(); mUserId = user.getId(); mUserScreenName = user.getScreenName(); mListName = user_list.getName(); mListSlug = user_list.getSlug(); final boolean is_multiple_account_enabled = getActivatedAccountIds(getActivity()).length > 1; mListView.setBackgroundResource(is_multiple_account_enabled ? R.drawable.ic_label_account_nopadding : 0); if (is_multiple_account_enabled) { final Drawable d = mListView.getBackground(); if (d != null) { d.mutate().setColorFilter(getAccountColor(getActivity(), account_id), PorterDuff.Mode.MULTIPLY); mListView.invalidate(); } } mListNameView.setText(mListName); mUserNameView.setText(mDisplayName ? mUserName : mUserScreenName); final String description = user_list.getDescription(); mDescriptionContainer .setVisibility(is_my_activated_account || !isNullOrEmpty(description) ? View.VISIBLE : View.GONE); mDescriptionContainer.setOnLongClickListener(this); mDescriptionView.setText(description); final TwidereLinkify linkify = new TwidereLinkify(mDescriptionView); linkify.setOnLinkClickListener(this); linkify.addAllLinks(); mDescriptionView.setMovementMethod(LinkMovementMethod.getInstance()); final String profile_image_url_string = parseString(user.getProfileImageURL()); final boolean hires_profile_image = getResources().getBoolean(R.bool.hires_profile_image); mProfileImageLoader.displayProfileImage(mProfileImageView, hires_profile_image ? getBiggerTwitterProfileImage(profile_image_url_string) : profile_image_url_string); mUserList = user_list; //if (mUserId == mAccountId) { mFollowMoreButton.setText(R.string.more); mFollowMoreButton.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.expander_open_holo, 0); //} else { // mFollowMoreButton.setText(user_list.isFollowing() ? R.string.unfollow : R.string.follow); // mFollowMoreButton.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); //} mAdapter.notifyDataSetChanged(); }
From source file:com.dwdesign.tweetings.fragment.UserProfileFragment.java
License:Open Source License
public void changeUser(final long account_id, final User user) { mFriendship = null;/*from www . j av a 2 s . c om*/ mUserId = -1; mAccountId = -1; if (user == null || user.getId() <= 0 || getActivity() == null || !isMyActivatedAccount(getActivity(), account_id)) return; if (mUserInfoTask != null && mUserInfoTask.getStatus() == AsyncTask.Status.RUNNING) { mUserInfoTask.cancel(true); } final boolean is_my_activated_account = isMyActivatedAccount(getActivity(), user.getId()); mUserInfoTask = null; mErrorRetryContainer.setVisibility(View.GONE); mAccountId = account_id; mUserId = user.getId(); mScreenName = user.getScreenName(); updateUserColor(); final boolean is_multiple_account_enabled = getActivatedAccountIds(getActivity()).length > 1; mListView.setBackgroundResource(is_multiple_account_enabled ? R.drawable.ic_label_account_nopadding : 0); if (is_multiple_account_enabled) { final Drawable d = mListView.getBackground(); if (d != null) { d.mutate().setColorFilter(getAccountColor(getActivity(), account_id), PorterDuff.Mode.MULTIPLY); mListView.invalidate(); } } mNameView.setText(user.getName()); mScreenNameView.setText("@" + user.getScreenName()); mScreenNameView.setCompoundDrawablesWithIntrinsicBounds( getUserTypeIconRes(user.isVerified(), user.isProtected()), 0, 0, 0); final String description = user.getDescription(); mDescriptionContainer .setVisibility(is_my_activated_account || !isNullOrEmpty(description) ? View.VISIBLE : View.GONE); mDescriptionContainer.setOnLongClickListener(this); mDescriptionView.setText(description); final TwidereLinkify linkify = new TwidereLinkify(mDescriptionView); linkify.setOnLinkClickListener(this); linkify.addAllLinks(); mDescriptionView.setMovementMethod(LinkMovementMethod.getInstance()); final String location = user.getLocation(); mLocationContainer .setVisibility(is_my_activated_account || !isNullOrEmpty(location) ? View.VISIBLE : View.GONE); mLocationContainer.setOnLongClickListener(this); mLocationView.setText(location); final String url = user.getURL() != null ? user.getURL().toString() : null; mURLContainer.setVisibility(is_my_activated_account || !isNullOrEmpty(url) ? View.VISIBLE : View.GONE); mURLContainer.setOnLongClickListener(this); mURLView.setText(url); mCreatedAtView.setText(formatToLongTimeString(getActivity(), getTimestampFromDate(user.getCreatedAt()))); mTweetCount.setText(String.valueOf(user.getStatusesCount())); mFollowersCount.setText(String.valueOf(user.getFollowersCount())); mFriendsCount.setText(String.valueOf(user.getFriendsCount())); // final boolean display_profile_image = // mPreferences.getBoolean(PREFERENCE_KEY_DISPLAY_PROFILE_IMAGE, true); // mProfileImageView.setVisibility(display_profile_image ? View.VISIBLE // : View.GONE); // if (display_profile_image) { final String profile_image_url_string = parseString(user.getProfileImageURL()); final boolean hires_profile_image = getResources().getBoolean(R.bool.hires_profile_image); mLazyImageLoader.displayProfileImage(mProfileImageView, hires_profile_image ? getBiggerTwitterProfileImage(profile_image_url_string) : profile_image_url_string); // } String profile_banner_url_string = parseString(user.getProfileBannerImageUrl()); if (profile_banner_url_string != null) { final int def_width = getResources().getDisplayMetrics().widthPixels; profile_banner_url_string = profile_banner_url_string + "/" + getBestBannerType(def_width); } final String banner_url = profile_banner_url_string; if (mProfileBackgroundView != null) { mProfileBackgroundView.setScaleType(ImageView.ScaleType.CENTER_CROP); if (banner_url != null) { mLazyImageLoader.displayPreviewImage(mProfileBackgroundView, banner_url); } else { final Drawable d = getResources().getDrawable(R.drawable.linen); mProfileBackgroundView.setImageDrawable(d); } } mUser = user; if (isMyAccount(getActivity(), user.getId())) { final ContentResolver resolver = getContentResolver(); final ContentValues values = new ContentValues(); final URL profile_image_url = user.getProfileImageURL(); if (profile_image_url != null) { values.put(Accounts.PROFILE_IMAGE_URL, profile_image_url.toString()); } values.put(Accounts.USERNAME, user.getScreenName()); final String where = Accounts.USER_ID + " = " + user.getId() + " AND 1 = 1"; resolver.update(Accounts.CONTENT_URI, values, where, null); } mAdapter.add(new UserRecentPhotosAction()); mAdapter.add(new FavoritesAction()); mAdapter.add(new UserMentionsAction()); mAdapter.add(new UserListTypesAction()); if (user.getId() == mAccountId) { mAdapter.add(new MyTweetsRetweetedAction()); mAdapter.add(new SavedSearchesAction()); boolean nativeMapSupported = true; try { Class.forName("com.google.android.maps.MapActivity"); Class.forName("com.google.android.maps.MapView"); } catch (final ClassNotFoundException e) { nativeMapSupported = false; } if (nativeMapSupported) { mAdapter.add(new UserNearbyAction()); } if (user.isProtected()) { mAdapter.add(new IncomingFriendshipsAction()); } mAdapter.add(new UserBlocksAction()); } mAdapter.notifyDataSetChanged(); if (mRecentPhotosGallery != null) { mRecentPhotosGallery.setVisibility(View.GONE); mRecentPhotosGallery.setAdapter(new ImageAdapter(this.getActivity())); mRecentPhotosGallery.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View v, int position, long id) { ParcelableStatus pStatus = mMediaStatuses.get(position); final ImageSpec spec = getAllAvailableImage(pStatus.image_orig_url_string); if (spec != null) { openImage(UserProfileFragment.this.getActivity(), Uri.parse(spec.full_image_link), pStatus.is_possibly_sensitive); } } }); mMediaTimelineTask = new MediaTimelineTask(this.getActivity(), mAccountId, mUser.getScreenName()); if (mMediaTimelineTask != null) { mMediaTimelineTask.execute(); } } getFriendship(); checkPushTracked(); }
From source file:com.dwdesign.tweetings.model.ParcelableDirectMessage.java
License:Open Source License
public ParcelableDirectMessage(final DirectMessage message, final long account_id, final boolean is_gap) { this.account_id = account_id; this.is_gap = is_gap; final User sender = message.getSender(), recipient = message.getRecipient(); message_id = message.getId();//from w ww . j a va2 s . c om message_timestamp = getTime(message.getCreatedAt()); sender_id = sender != null ? sender.getId() : -1; recipient_id = recipient != null ? recipient.getId() : -1; text = message.getText(); sender_name = sender != null ? sender.getName() : null; recipient_name = recipient != null ? recipient.getName() : null; sender_screen_name = sender != null ? sender.getScreenName() : null; recipient_screen_name = recipient != null ? recipient.getScreenName() : null; sender_profile_image_url = sender != null ? sender.getProfileImageURL() : null; recipient_profile_image_url = recipient != null ? recipient.getProfileImageURL() : null; }
From source file:com.dwdesign.tweetings.model.ParcelableStatus.java
License:Open Source License
public ParcelableStatus(Status status, final long account_id, final boolean is_gap, final boolean large_inline_image_preview) { this.is_gap = is_gap; this.account_id = account_id; status_id = status.getId();//from w w w . j a v a 2 s . c o m is_retweet = status.isRetweet(); final Status retweeted_status = is_retweet ? status.getRetweetedStatus() : null; final User retweet_user = retweeted_status != null ? status.getUser() : null; retweet_id = retweeted_status != null ? retweeted_status.getId() : -1; retweeted_by_id = retweet_user != null ? retweet_user.getId() : -1; retweeted_by_name = retweet_user != null ? retweet_user.getName() : null; retweeted_by_screen_name = retweet_user != null ? retweet_user.getScreenName() : null; if (retweeted_status != null) { status = retweeted_status; } final User user = status.getUser(); user_id = user != null ? user.getId() : -1; name = user != null ? user.getName() : null; screen_name = user != null ? user.getScreenName() : null; profile_image_url = user != null ? user.getProfileImageURL() : null; profile_image_url_string = profile_image_url != null ? profile_image_url.toString() : null; is_protected = user != null ? user.isProtected() : false; is_verified = user != null ? user.isVerified() : false; final MediaEntity[] medias = status.getMediaEntities(); status_timestamp = getTime(status.getCreatedAt()); text_html = formatStatusText(status); final PreviewImage preview = getPreviewImage(text_html, large_inline_image_preview ? INLINE_IMAGE_PREVIEW_DISPLAY_OPTION_CODE_LARGE_HIGH : INLINE_IMAGE_PREVIEW_DISPLAY_OPTION_CODE_SMALL); text_plain = status.getText(); retweet_count = status.getRetweetCount(); in_reply_to_screen_name = status.getInReplyToScreenName(); in_reply_to_status_id = status.getInReplyToStatusId(); source = status.getSource(); location = new ParcelableLocation(status.getGeoLocation()); location_string = location.toString(); is_favorite = status.isFavorited(); has_media = medias != null && medias.length > 0 || preview.has_image; text = text_html != null ? Html.fromHtml(text_html) : null; image_preview_url_string = preview.matched_url; image_orig_url_string = preview.orig_url; image_preview_url = parseURL(image_preview_url_string); text_unescaped = unescape(text_html); String play = null; URLEntity[] urls = status.getURLEntities(); if (urls != null) { for (final URLEntity url : urls) { final URL tco_url = url.getURL(); final URL expanded_url = url.getExpandedURL(); if (tco_url != null && expanded_url != null && expanded_url.toString().contains("play.google.com/store/apps")) { play = expanded_url.toString(); break; } } } play_package = play; is_possibly_sensitive = status.isPossiblySensitive(); }
From source file:com.dwdesign.tweetings.model.ParcelableUser.java
License:Open Source License
public ParcelableUser(final User user, final long account_id, final long position) { this.position = position; this.account_id = account_id; user_id = user.getId();// w w w. ja v a2s.c om created_at = getTime(user.getCreatedAt()); is_protected = user.isProtected(); is_verified = user.isVerified(); name = user.getName(); screen_name = user.getScreenName(); description = user.getDescription(); location = user.getLocation(); profile_image_url = user.getProfileImageURL(); profile_image_url_string = parseString(profile_image_url); }
From source file:com.dwdesign.tweetings.model.ParcelableUserList.java
License:Open Source License
public ParcelableUserList(final UserList list, final long account_id, final long position) { final User user = list.getUser(); this.position = position; this.account_id = account_id; list_id = list.getId();//from www .ja v a 2s .co m is_public = list.isPublic(); is_following = list.isFollowing(); name = list.getName(); description = list.getDescription(); user_id = user.getId(); user_name = user.getName(); user_screen_name = user.getScreenName(); user_profile_image_url = user.getProfileImageURL(); user_profile_image_url_string = parseString(user_profile_image_url); }
From source file:com.dwdesign.tweetings.util.Utils.java
License:Open Source License
public static ContentValues makeAccountContentValues(final int color, final AccessToken access_token, final User user, final String rest_base_url, final String oauth_base_url, final String signing_rest_base_url, final String signing_oauth_base_url, final String search_base_url, final String upload_base_url, final String basic_password, final int auth_type) { if (user == null || user.getId() <= 0) return null; final ContentValues values = new ContentValues(); switch (auth_type) { case Accounts.AUTH_TYPE_TWIP_O_MODE: { break;//from w ww . jav a 2 s . co m } case Accounts.AUTH_TYPE_BASIC: { if (basic_password == null) return null; values.put(Accounts.BASIC_AUTH_PASSWORD, basic_password); break; } case Accounts.AUTH_TYPE_OAUTH: case Accounts.AUTH_TYPE_XAUTH: { if (access_token == null) return null; if (user.getId() != access_token.getUserId()) return null; values.put(Accounts.OAUTH_TOKEN, access_token.getToken()); values.put(Accounts.TOKEN_SECRET, access_token.getTokenSecret()); break; } } values.put(Accounts.AUTH_TYPE, auth_type); values.put(Accounts.USER_ID, user.getId()); values.put(Accounts.USERNAME, user.getScreenName()); values.put(Accounts.PROFILE_IMAGE_URL, user.getProfileImageURL().toString()); values.put(Accounts.USER_COLOR, color); values.put(Accounts.IS_ACTIVATED, 1); values.put(Accounts.REST_BASE_URL, rest_base_url); values.put(Accounts.SIGNING_REST_BASE_URL, signing_rest_base_url); values.put(Accounts.SEARCH_BASE_URL, search_base_url); values.put(Accounts.UPLOAD_BASE_URL, upload_base_url); values.put(Accounts.OAUTH_BASE_URL, oauth_base_url); values.put(Accounts.SIGNING_OAUTH_BASE_URL, signing_oauth_base_url); return values; }
From source file:com.dwdesign.tweetings.util.Utils.java
License:Open Source License
public static ContentValues makeCachedUserContentValues(final User user) { if (user == null || user.getId() <= 0) return null; final ContentValues values = new ContentValues(); values.put(CachedUsers.NAME, user.getName()); values.put(CachedUsers.PROFILE_IMAGE_URL, user.getProfileImageURL().toString()); values.put(CachedUsers.SCREEN_NAME, user.getScreenName()); values.put(CachedUsers.USER_ID, user.getId()); return values; }