Search in sources :

Example 1 with IDs

use of twitter4j.IDs in project Talon-for-Twitter by klinker24.

the class TalonPullNotificationService method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    if (TalonPullNotificationService.isRunning) {
        stopSelf();
        return;
    }
    TalonPullNotificationService.isRunning = true;
    settings = AppSettings.getInstance(this);
    mCache = App.getInstance(this).getBitmapCache();
    sharedPreferences = getSharedPreferences("com.klinker.android.twitter_world_preferences", 0);
    showNotification = sharedPreferences.getBoolean("show_pull_notification", true);
    pullUnread = sharedPreferences.getInt("pull_unread", 0);
    Intent notificationIntent = new Intent(this, MainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    Intent stop = new Intent(this, StopPull.class);
    PendingIntent stopPending = PendingIntent.getService(this, 0, stop, 0);
    Intent popup = new Intent(this, RedirectToPopup.class);
    popup.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    popup.putExtra("from_notification", true);
    PendingIntent popupPending = PendingIntent.getActivity(this, 0, popup, 0);
    Intent compose = new Intent(this, WidgetCompose.class);
    popup.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent composePending = PendingIntent.getActivity(this, 0, compose, 0);
    String text;
    int count = 0;
    if (sharedPreferences.getBoolean("is_logged_in_1", false)) {
        count++;
    }
    if (sharedPreferences.getBoolean("is_logged_in_2", false)) {
        count++;
    }
    boolean multAcc = false;
    if (count == 2) {
        multAcc = true;
    }
    if (settings.liveStreaming && settings.timelineNot) {
        text = getResources().getString(R.string.new_tweets_upper) + ": " + pullUnread;
    } else {
        text = getResources().getString(R.string.listening_for_mentions) + "...";
    }
    mBuilder = new NotificationCompat.Builder(this).setSmallIcon(android.R.color.transparent).setContentTitle(getResources().getString(R.string.talon_pull) + (multAcc ? " - @" + settings.myScreenName : "")).setContentText(text).setOngoing(true).setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_stat_icon));
    if (getApplicationContext().getResources().getBoolean(R.bool.expNotifications)) {
        mBuilder.addAction(R.drawable.ic_cancel_dark, getApplicationContext().getResources().getString(R.string.stop), stopPending);
        mBuilder.addAction(R.drawable.ic_popup, getResources().getString(R.string.popup), popupPending);
        mBuilder.addAction(R.drawable.ic_send_dark, getResources().getString(R.string.tweet), composePending);
    }
    try {
        mBuilder.setWhen(0);
    } catch (Exception e) {
    }
    mBuilder.setContentIntent(pendingIntent);
    // priority flag is only available on api level 16 and above
    if (getResources().getBoolean(R.bool.expNotifications)) {
        mBuilder.setPriority(Notification.PRIORITY_MIN);
    }
    mContext = getApplicationContext();
    IntentFilter filter = new IntentFilter();
    filter.addAction("com.klinker.android.twitter.STOP_PUSH");
    registerReceiver(stopPush, filter);
    filter = new IntentFilter();
    filter.addAction("com.klinker.android.twitter.START_PUSH");
    registerReceiver(startPush, filter);
    filter = new IntentFilter();
    filter.addAction("com.klinker.android.twitter.STOP_PUSH_SERVICE");
    registerReceiver(stopService, filter);
    if (settings.liveStreaming && settings.timelineNot) {
        filter = new IntentFilter();
        filter.addAction("com.klinker.android.twitter.UPDATE_NOTIF");
        registerReceiver(updateNotification, filter);
        filter = new IntentFilter();
        filter.addAction("com.klinker.android.twitter.NEW_TWEET");
        registerReceiver(updateNotification, filter);
        filter = new IntentFilter();
        filter.addAction("com.klinker.android.twitter.CLEAR_PULL_UNREAD");
        registerReceiver(clearPullUnread, filter);
    }
    Thread start = new Thread(new Runnable() {

        @Override
        public void run() {
            // get the ids of everyone you follow
            try {
                Log.v("getting_ids", "started getting ids, mine: " + settings.myId);
                Twitter twitter = Utils.getTwitter(mContext, settings);
                long currCursor = -1;
                IDs idObject;
                ids = new ArrayList<Long>();
                do {
                    idObject = twitter.getFriendsIDs(settings.myId, currCursor);
                    long[] lIds = idObject.getIDs();
                    for (int i = 0; i < lIds.length; i++) {
                        ids.add(lIds[i]);
                    }
                } while ((currCursor = idObject.getNextCursor()) != 0);
                ids.add(settings.myId);
                currCursor = -1;
                blockedIds = new ArrayList<Long>();
                do {
                    idObject = twitter.getBlocksIDs(currCursor);
                    long[] lIds = idObject.getIDs();
                    for (int i = 0; i < lIds.length; i++) {
                        blockedIds.add(lIds[i]);
                    }
                } while ((currCursor = idObject.getNextCursor()) != 0);
                idsLoaded = true;
                if (showNotification)
                    startForeground(FOREGROUND_SERVICE_ID, mBuilder.build());
                mContext.sendBroadcast(new Intent("com.klinker.android.twitter.START_PUSH"));
            } catch (Exception e) {
                e.printStackTrace();
                TalonPullNotificationService.isRunning = false;
                pullUnread = 0;
                Thread stop = new Thread(new Runnable() {

                    @Override
                    public void run() {
                        TalonPullNotificationService.shuttingDown = true;
                        try {
                        //pushStream.removeListener(userStream);
                        } catch (Exception x) {
                        }
                        try {
                            pushStream.cleanUp();
                            pushStream.shutdown();
                            Log.v("twitter_stream_push", "stopping push notifications");
                        } catch (Exception e) {
                            // it isn't running
                            e.printStackTrace();
                            // try twice to shut it down i guess
                            try {
                                Thread.sleep(2000);
                                pushStream.cleanUp();
                                pushStream.shutdown();
                                Log.v("twitter_stream_push", "stopping push notifications");
                            } catch (Exception x) {
                                // it isn't running
                                x.printStackTrace();
                            }
                        }
                        TalonPullNotificationService.shuttingDown = false;
                    }
                });
                stop.setPriority(Thread.MAX_PRIORITY);
                stop.start();
                stopSelf();
            } catch (OutOfMemoryError e) {
                TalonPullNotificationService.isRunning = false;
                Thread stop = new Thread(new Runnable() {

                    @Override
                    public void run() {
                        TalonPullNotificationService.shuttingDown = true;
                        try {
                        //pushStream.removeListener(userStream);
                        } catch (Exception x) {
                        }
                        try {
                            pushStream.cleanUp();
                            pushStream.shutdown();
                            Log.v("twitter_stream_push", "stopping push notifications");
                        } catch (Exception e) {
                            // it isn't running
                            e.printStackTrace();
                            // try twice to shut it down i guess
                            try {
                                Thread.sleep(2000);
                                pushStream.cleanUp();
                                pushStream.shutdown();
                                Log.v("twitter_stream_push", "stopping push notifications");
                            } catch (Exception x) {
                                // it isn't running
                                x.printStackTrace();
                            }
                        }
                        TalonPullNotificationService.shuttingDown = false;
                    }
                });
                stop.setPriority(Thread.MAX_PRIORITY);
                stop.start();
                pullUnread = 0;
                stopSelf();
            }
        }
    });
    start.setPriority(Thread.MAX_PRIORITY - 1);
    start.start();
}
Also used : IntentFilter(android.content.IntentFilter) ArrayList(java.util.ArrayList) Twitter(twitter4j.Twitter) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) IDs(twitter4j.IDs) PendingIntent(android.app.PendingIntent)

Example 2 with IDs

use of twitter4j.IDs in project twitter4j by yusuke.

the class GetMutingUsersIDs method main.

/**
     * Usage: java twitter4j.examples.mute.GetMutingUsersIDs
     *
     * @param args message
     */
public static void main(String[] args) {
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        IDs ids = twitter.getMutesIDs(-1L);
        for (long id : ids.getIDs()) {
            System.out.println(id);
        }
        System.out.println("done.");
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get muting user ids: " + te.getMessage());
        System.exit(-1);
    }
}
Also used : Twitter(twitter4j.Twitter) IDs(twitter4j.IDs) TwitterFactory(twitter4j.TwitterFactory) TwitterException(twitter4j.TwitterException)

Example 3 with IDs

use of twitter4j.IDs in project twitter4j by yusuke.

the class GetFollowersIDs method main.

/**
     * Usage: java twitter4j.examples.friendsandfollowers.GetFollowersIDs [screen name]
     *
     * @param args message
     */
public static void main(String[] args) {
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        long cursor = -1;
        IDs ids;
        System.out.println("Listing followers's ids.");
        do {
            if (0 < args.length) {
                ids = twitter.getFollowersIDs(args[0], cursor);
            } else {
                ids = twitter.getFollowersIDs(cursor);
            }
            for (long id : ids.getIDs()) {
                System.out.println(id);
            }
        } while ((cursor = ids.getNextCursor()) != 0);
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get followers' ids: " + te.getMessage());
        System.exit(-1);
    }
}
Also used : Twitter(twitter4j.Twitter) IDs(twitter4j.IDs) TwitterFactory(twitter4j.TwitterFactory) TwitterException(twitter4j.TwitterException)

Example 4 with IDs

use of twitter4j.IDs in project twitter4j by yusuke.

the class GetFriendsIDs method main.

/**
     * Usage: java twitter4j.examples.friendsandfollowers.GetFriendsIDs [screen name]
     *
     * @param args message
     */
public static void main(String[] args) {
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        long cursor = -1;
        IDs ids;
        System.out.println("Listing following ids.");
        do {
            if (0 < args.length) {
                ids = twitter.getFriendsIDs(args[0], cursor);
            } else {
                ids = twitter.getFriendsIDs(cursor);
            }
            for (long id : ids.getIDs()) {
                System.out.println(id);
            }
        } while ((cursor = ids.getNextCursor()) != 0);
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get friends' ids: " + te.getMessage());
        System.exit(-1);
    }
}
Also used : Twitter(twitter4j.Twitter) IDs(twitter4j.IDs) TwitterFactory(twitter4j.TwitterFactory) TwitterException(twitter4j.TwitterException)

Example 5 with IDs

use of twitter4j.IDs in project Talon-for-Twitter by klinker24.

the class ProfileFragment method getFollowers.

public void getFollowers(final User user, final AsyncListView listView) {
    spinner.setVisibility(View.VISIBLE);
    canRefresh = false;
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                Twitter twitter = Utils.getTwitter(context, settings);
                try {
                    if (followingIds == null && user.getId() == settings.myId) {
                        long currCursor = -1;
                        IDs idObject;
                        int rep = 0;
                        do {
                            // gets 5000 ids at a time
                            idObject = twitter.getFriendsIDs(settings.myId, currCursor);
                            long[] lIds = idObject.getIDs();
                            followingIds = new ArrayList<Long>();
                            for (int i = 0; i < lIds.length; i++) {
                                followingIds.add(lIds[i]);
                            }
                            rep++;
                        } while ((currCursor = idObject.getNextCursor()) != 0 && rep < 3);
                    }
                } catch (Throwable t) {
                    followingIds = null;
                }
                PagableResponseList<User> friendsPaging = twitter.getFollowersList(user.getId(), currentFollowers, 100);
                for (int i = 0; i < friendsPaging.size(); i++) {
                    followers.add(friendsPaging.get(i));
                }
                if (friendsPaging.size() > 17) {
                    hasMore = true;
                } else {
                    hasMore = false;
                }
                currentFollowers = friendsPaging.getNextCursor();
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        if (followersAdapter == null) {
                            if (followingIds == null) {
                                // we will do a normal array adapter
                                followersAdapter = new PeopleArrayAdapter(context, followers);
                            } else {
                                followersAdapter = new FollowersArrayAdapter(context, followers, followingIds);
                            }
                            listView.setAdapter(followersAdapter);
                        } else {
                            followersAdapter.notifyDataSetChanged();
                        }
                        if (settings.roundContactImages) {
                            ImageUtils.loadSizedCircleImage(context, profilePicture, thisUser.getOriginalProfileImageURL(), mCache, 96);
                        } else {
                            ImageUtils.loadImage(context, profilePicture, thisUser.getOriginalProfileImageURL(), mCache);
                        }
                        String url = user.getProfileBannerURL();
                        ImageUtils.loadImage(context, background, url, mCache);
                        canRefresh = true;
                        spinner.setVisibility(View.GONE);
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        if (user != null && user.isProtected()) {
                            Toast.makeText(context, getResources().getString(R.string.protected_account), Toast.LENGTH_SHORT).show();
                            if (settings.roundContactImages) {
                                ImageUtils.loadSizedCircleImage(context, profilePicture, thisUser.getOriginalProfileImageURL(), mCache, 96);
                            } else {
                                ImageUtils.loadImage(context, profilePicture, user.getOriginalProfileImageURL(), mCache);
                            }
                            String url = user.getProfileBannerURL();
                            ImageUtils.loadImage(context, background, url, mCache);
                        } else {
                            Toast.makeText(context, getResources().getString(R.string.error_loading_timeline), Toast.LENGTH_SHORT).show();
                        }
                        spinner.setVisibility(View.GONE);
                        canRefresh = false;
                        hasMore = false;
                    }
                });
            }
        }
    }).start();
}
Also used : PeopleArrayAdapter(com.klinker.android.twitter.adapters.PeopleArrayAdapter) User(twitter4j.User) Twitter(twitter4j.Twitter) PhotoViewerActivity(com.klinker.android.twitter.activities.photo_viewer.PhotoViewerActivity) Activity(android.app.Activity) FollowersArrayAdapter(com.klinker.android.twitter.adapters.FollowersArrayAdapter) IDs(twitter4j.IDs)

Aggregations

IDs (twitter4j.IDs)8 Twitter (twitter4j.Twitter)8 TwitterException (twitter4j.TwitterException)6 TwitterFactory (twitter4j.TwitterFactory)6 Activity (android.app.Activity)1 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 PhotoViewerActivity (com.klinker.android.twitter.activities.photo_viewer.PhotoViewerActivity)1 FollowersArrayAdapter (com.klinker.android.twitter.adapters.FollowersArrayAdapter)1 PeopleArrayAdapter (com.klinker.android.twitter.adapters.PeopleArrayAdapter)1 ArrayList (java.util.ArrayList)1 User (twitter4j.User)1