Example usage for twitter4j Trends getTrends

List of usage examples for twitter4j Trends getTrends

Introduction

In this page you can find the example usage for twitter4j Trends getTrends.

Prototype

Trend[] getTrends();

Source Link

Usage

From source file:com.daiv.android.twitter.ui.drawer_activities.discover.trends.LocalTrends.java

License:Apache License

public void getTrends() {

    new Thread(new Runnable() {
        @Override//from  ww  w  .  java 2  s. c o m
        public void run() {
            try {
                Twitter twitter = Utils.getTwitter(context, DrawerActivity.settings);

                int i = 0;
                while (!connected && i < 5) {
                    try {
                        Thread.sleep(1500);
                    } catch (Exception e) {

                    }

                    i++;
                }

                twitter4j.Trends trends;

                if (sharedPrefs.getBoolean("manually_config_location", false)) {
                    trends = twitter.getPlaceTrends(sharedPrefs.getInt("woeid", 2379574)); // chicago to default
                } else {
                    Location location = mLastLocation;

                    ResponseList<twitter4j.Location> locations = twitter
                            .getClosestTrends(new GeoLocation(location.getLatitude(), location.getLongitude()));
                    trends = twitter.getPlaceTrends(locations.get(0).getWoeid());
                }

                final ArrayList<String> currentTrends = new ArrayList<String>();

                for (Trend t : trends.getTrends()) {
                    String name = t.getName();
                    currentTrends.add(name);
                }

                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            if (currentTrends != null) {
                                listView.setAdapter(new TrendsArrayAdapter(context, currentTrends));
                                listView.setVisibility(View.VISIBLE);
                            } else {
                                Toast.makeText(context, getResources().getString(R.string.no_location),
                                        Toast.LENGTH_SHORT).show();
                            }

                            LinearLayout spinner = (LinearLayout) layout.findViewById(R.id.list_progress);
                            spinner.setVisibility(View.GONE);
                        } catch (Exception e) {
                            // not attached to activity
                        }
                    }
                });

                HashtagDataSource source = HashtagDataSource.getInstance(context);

                for (String s : currentTrends) {
                    Log.v("Test_hashtag", "trend: " + s);
                    if (s.contains("#")) {
                        // we want to add it to the auto complete
                        Log.v("Test_hashtag", "adding: " + s);

                        // could be much more efficient by querying and checking first, but I
                        // just didn't feel like it when there is only ever 10 of them here
                        source.deleteTag(s);

                        // add it to the userAutoComplete database
                        source.createTag(s);
                    }
                }

            } catch (Throwable e) {
                e.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            Toast.makeText(context, getResources().getString(R.string.no_location),
                                    Toast.LENGTH_SHORT).show();
                        } catch (Exception e) {
                            // not attached to activity
                        }
                    }
                });
            }
        }
    }).start();
}

From source file:com.daiv.android.twitter.ui.drawer_activities.discover.trends.WorldTrends.java

License:Apache License

public void getTrends() {

    new Thread(new Runnable() {
        @Override/*from  w w  w  . ja  va 2s. c o m*/
        public void run() {
            try {
                Twitter twitter = Utils.getTwitter(context, settings);

                twitter4j.Trends trends = twitter.getPlaceTrends(1);
                final ArrayList<String> currentTrends = new ArrayList<String>();

                for (Trend t : trends.getTrends()) {
                    String name = t.getName();
                    currentTrends.add(name);
                }

                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (currentTrends != null) {
                            listView.setAdapter(new TrendsArrayAdapter(context, currentTrends));
                        }

                        listView.setVisibility(View.VISIBLE);

                        LinearLayout spinner = (LinearLayout) layout.findViewById(R.id.list_progress);
                        spinner.setVisibility(View.GONE);
                    }
                });

                HashtagDataSource source = HashtagDataSource.getInstance(context);

                for (String s : currentTrends) {
                    if (s.contains("#")) {
                        // we want to add it to the userAutoComplete
                        Log.v("Test_hashtag", "adding: " + s);

                        // could be much more efficient by querying and checking first, but I
                        // just didn't feel like it when there is only ever 10 of them here
                        source.deleteTag(s);

                        // add it to the userAutoComplete database
                        source.createTag(s);
                    }
                }
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
    }).start();
}

From source file:com.dwdesign.tweetings.util.Utils.java

License:Open Source License

public static ContentValues[] makeTrendsContentValues(final List<Trends> trends_list) {
    if (trends_list == null)
        return new ContentValues[0];
    final List<ContentValues> result_list = new ArrayList<ContentValues>();
    for (final Trends trends : trends_list) {
        if (trends == null) {
            continue;
        }/*from  w  w  w  . jav a  2 s.  co  m*/
        final long timestamp = trends.getTrendAt().getTime();
        for (final Trend trend : trends.getTrends()) {
            final ContentValues values = new ContentValues();
            values.put(CachedTrends.NAME, trend.getName());
            values.put(CachedTrends.TIMESTAMP, timestamp);
            result_list.add(values);
        }
    }
    return result_list.toArray(new ContentValues[result_list.size()]);
}

From source file:com.fsatir.twitter.TwitterManagedBean.java

public void pullTrendTopicImages() {
    try {//from w w w  .  j  a va 2  s . c  o m
        Twitter twitter = bringMyTwitterInstance();
        Trends trends = twitter.getPlaceTrends(TURKEY_WOEID);
        int counter = 0;
        for (Trend trend : trends.getTrends()) {
            trendImageList(twitter, trend.getName());
            counter++;
        }
        showMessage(counter + " adet sonu getirildi.!");
        FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("myMediaListFiltered",
                myMediaListFiltered);

    } catch (TwitterException ex) {
        ex.printStackTrace();
    }
}

From source file:com.github.moko256.twitlatte.TrendsFragment.java

License:Apache License

private Single<List<Trend>> getResponseSingle(GeoLocation geolocation) {
    return Single.create(subscriber -> {
        try {/*  w w w. j  av  a2s  .  c  o  m*/
            Trends trends = GlobalApplication.twitter
                    .getPlaceTrends(GlobalApplication.twitter.getClosestTrends(geolocation).get(0).getWoeid());
            twitter4j.Trend[] result = trends.getTrends();
            ArrayList<Trend> arrayList = new ArrayList<>(result.length);

            for (twitter4j.Trend trend : result) {
                arrayList.add(new Trend(trend.getName(), trend.getTweetVolume()));
            }

            helper.setTrends(arrayList);

            subscriber.onSuccess(arrayList);
        } catch (TwitterException e) {
            subscriber.tryOnError(e);
        }
    });
}

From source file:com.happy_coding.viralo.twitter.SmartPoster.java

License:Apache License

/**
 * Returns some kind of trends, which is worth writing about.
 *
 * @return//from  www .j  a v  a 2 s  .  c  o m
 */
public String retrieveTrend() {

    Twitter twitter = new TwitterFactory().getInstance();

    try {
        Trends trends = twitter.getLocationTrends(TREND_WOEID);
        Trend[] trendsArr = trends.getTrends();
        logger.debug("size: " + trendsArr.length);

        int lengthCheck = 0;
        String matchedtrend = "";
        for (int i = 0; i < trendsArr.length; i++) {

            logger.debug("Trend: " + trendsArr[i].getName());

            if (trendsArr[i].getName().length() >= lengthCheck) {
                matchedtrend = trendsArr[i].getName();
                lengthCheck = trendsArr[i].getName().length();
            }
        }

        return matchedtrend;

    } catch (TwitterException e) {
        logger.error("can't retrieve trend", e);
        return null;
    }
}

From source file:com.klinker.android.twitter.activities.drawer_activities.discover.trends.LocalTrends.java

License:Apache License

public void getTrends() {

    new Thread(new Runnable() {
        @Override//from w  ww  .  j a va2  s. co m
        public void run() {
            try {
                Twitter twitter = Utils.getTwitter(context, DrawerActivity.settings);

                int i = 0;
                while (!connected && i < 5) {
                    try {
                        Thread.sleep(1500);
                    } catch (Exception e) {

                    }

                    i++;
                }

                twitter4j.Trends trends;

                if (sharedPrefs.getBoolean("manually_config_location", false)) {
                    trends = twitter.getPlaceTrends(sharedPrefs.getInt("woeid", 2379574)); // chicago to default
                } else {
                    Location location = mLastLocation;

                    ResponseList<twitter4j.Location> locations = twitter
                            .getClosestTrends(new GeoLocation(location.getLatitude(), location.getLongitude()));
                    trends = twitter.getPlaceTrends(locations.get(0).getWoeid());
                }

                final ArrayList<String> currentTrends = new ArrayList<String>();

                for (Trend t : trends.getTrends()) {
                    String name = t.getName();
                    currentTrends.add(name);
                }

                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            if (currentTrends != null) {
                                listView.setAdapter(new TrendsArrayAdapter(context, currentTrends));
                                listView.setVisibility(View.VISIBLE);
                            } else {
                                Toast.makeText(context, getResources().getString(R.string.no_location),
                                        Toast.LENGTH_SHORT).show();
                            }

                            LinearLayout spinner = (LinearLayout) layout.findViewById(R.id.list_progress);
                            spinner.setVisibility(View.GONE);
                        } catch (Exception e) {
                            // not attached to activity
                        }
                    }
                });

                HashtagDataSource source = HashtagDataSource.getInstance(context);

                for (String s : currentTrends) {
                    Log.v("talon_hashtag", "trend: " + s);
                    if (s.contains("#")) {
                        // we want to add it to the auto complete
                        Log.v("talon_hashtag", "adding: " + s);

                        // could be much more efficient by querying and checking first, but I
                        // just didn't feel like it when there is only ever 10 of them here
                        source.deleteTag(s);

                        // add it to the userAutoComplete database
                        source.createTag(s);
                    }
                }

            } catch (Throwable e) {
                e.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            Toast.makeText(context, getResources().getString(R.string.no_location),
                                    Toast.LENGTH_SHORT).show();
                        } catch (Exception e) {
                            // not attached to activity
                        }
                    }
                });
            }
        }
    }).start();
}

From source file:com.klinker.android.twitter.activities.drawer_activities.discover.trends.WorldTrends.java

License:Apache License

public void getTrends() {

    new Thread(new Runnable() {
        @Override/* ww w . j a v  a  2s .c o  m*/
        public void run() {
            try {
                Twitter twitter = Utils.getTwitter(context, settings);

                twitter4j.Trends trends = twitter.getPlaceTrends(1);
                final ArrayList<String> currentTrends = new ArrayList<String>();

                for (Trend t : trends.getTrends()) {
                    String name = t.getName();
                    currentTrends.add(name);
                }

                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (currentTrends != null) {
                            listView.setAdapter(new TrendsArrayAdapter(context, currentTrends));
                        }

                        listView.setVisibility(View.VISIBLE);

                        LinearLayout spinner = (LinearLayout) layout.findViewById(R.id.list_progress);
                        spinner.setVisibility(View.GONE);
                    }
                });

                HashtagDataSource source = HashtagDataSource.getInstance(context);

                for (String s : currentTrends) {
                    if (s.contains("#")) {
                        // we want to add it to the userAutoComplete
                        Log.v("talon_hashtag", "adding: " + s);

                        // could be much more efficient by querying and checking first, but I
                        // just didn't feel like it when there is only ever 10 of them here
                        source.deleteTag(s);

                        // add it to the userAutoComplete database
                        source.createTag(s);
                    }
                }
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
    }).start();
}

From source file:com.klinker.android.twitter.ui.drawer_activities.discover.trends.LocalTrends.java

License:Apache License

public void getTrends() {

    new Thread(new Runnable() {
        @Override//from   w w w. java  2  s  .co  m
        public void run() {
            try {
                Twitter twitter = Utils.getTwitter(context, DrawerActivity.settings);

                int i = 0;
                while (!connected && i < 5) {
                    try {
                        Thread.sleep(1500);
                    } catch (Exception e) {

                    }

                    i++;
                }

                twitter4j.Trends trends;

                if (sharedPrefs.getBoolean("manually_config_location", false)) {
                    trends = twitter.getPlaceTrends(sharedPrefs.getInt("woeid", 2379574)); // chicago to default
                } else {
                    Location location = mLocationClient.getLastLocation();

                    ResponseList<twitter4j.Location> locations = twitter
                            .getClosestTrends(new GeoLocation(location.getLatitude(), location.getLongitude()));
                    trends = twitter.getPlaceTrends(locations.get(0).getWoeid());
                }

                final ArrayList<String> currentTrends = new ArrayList<String>();

                for (Trend t : trends.getTrends()) {
                    String name = t.getName();
                    currentTrends.add(name);
                }

                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            if (currentTrends != null) {
                                listView.setAdapter(new TrendsArrayAdapter(context, currentTrends));
                                listView.setVisibility(View.VISIBLE);
                            } else {
                                Toast.makeText(context, getResources().getString(R.string.no_location),
                                        Toast.LENGTH_SHORT).show();
                            }

                            LinearLayout spinner = (LinearLayout) layout.findViewById(R.id.list_progress);
                            spinner.setVisibility(View.GONE);
                        } catch (Exception e) {
                            // not attached to activity
                        }
                    }
                });

                HashtagDataSource source = HashtagDataSource.getInstance(context);

                for (String s : currentTrends) {
                    Log.v("talon_hashtag", "trend: " + s);
                    if (s.contains("#")) {
                        // we want to add it to the auto complete
                        Log.v("talon_hashtag", "adding: " + s);

                        // could be much more efficient by querying and checking first, but I
                        // just didn't feel like it when there is only ever 10 of them here
                        source.deleteTag(s);

                        // add it to the userAutoComplete database
                        source.createTag(s);
                    }
                }

            } catch (Throwable e) {
                e.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            Toast.makeText(context, getResources().getString(R.string.no_location),
                                    Toast.LENGTH_SHORT).show();
                        } catch (Exception e) {
                            // not attached to activity
                        }
                    }
                });
            }
        }
    }).start();
}

From source file:com.mmiagency.knime.nodes.twitter.trends.TwitterTrendsNodeModel.java

License:Open Source License

/**
 * {@inheritDoc}//  w  w w .ja v a 2s  .  c  o  m
 */
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {

    TrendRowFactory factory = new TrendRowFactory();
    BufferedDataContainer container = exec.createDataContainer(factory.tableSpec());
    int index = 0;

    Twitter twitter = ((TwitterApiConnectionPortObject) inObjects[0]).getTwitterApiConnection().getTwitter();

    Trends trends = twitter.getPlaceTrends(m_config.getWoeid());
    Location location = trends.getLocation();

    for (Trend trend : trends.getTrends()) {
        container.addRowToTable(factory.createRow("" + index++, location, trend));
    }

    container.close();
    return new PortObject[] { container.getTable() };

}