Example usage for twitter4j Location getName

List of usage examples for twitter4j Location getName

Introduction

In this page you can find the example usage for twitter4j Location getName.

Prototype

String getName();

Source Link

Usage

From source file:Trending.java

private void generateCodes() {
    try {//from www  .j  a v a2  s. c o m
        locations = twitter.getAvailableTrends();
        for (Location location : locations) {
            for (int i = 0; i < size; i++) {
                if (location.getName().equals(countries[i])) {
                    codes[i] = location.getWoeid();
                }
            }
        }
    } catch (TwitterException ex) {
        java.util.logging.Logger.getLogger(Trending.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:ColourUs.Trending.java

private void generateCodes() {
    try {//from www .java 2 s.c om
        locations = twitter.getAvailableTrends();
        for (Location location : locations) {
            for (int i = 0; i < size; i++) {
                if (location.getName().equals(countries[i])) {
                    codes[i] = location.getWoeid();
                }
            }
        }
    } catch (TwitterException ex) {
        java.util.logging.Logger.getLogger(Trending.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.javielinux.adapters.RowTrendsLocationAdapter.java

License:Apache License

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    Location item = elements.get(position);

    View view = null;//from  ww w.j  a va 2 s . com

    if (null == convertView) {
        view = View.inflate(mContext, R.layout.row_trends_location, null);
    } else {
        view = convertView;
    }

    TextView location_name = (TextView) view.findViewById(R.id.location_name);
    location_name.setText(item.getName());

    return view;
}

From source file:com.javielinux.tweettopics2.TrendsLocationActivity.java

License:Apache License

private void createTrendsLocationColumn(Location trendslocation) {

    ArrayList<Entity> created_column_list = DataFramework.getInstance().getEntityList("columns",
            "location_id=" + trendslocation.getWoeid());

    int position = 0;

    if (created_column_list.size() == 0) {
        position = ColumnsUtils.nextPositionColumn();

        Entity type = new Entity("type_columns", (long) TweetTopicsUtils.COLUMN_TRENDING_TOPIC);
        Entity user_list = new Entity("columns");
        user_list.setValue("description", trendslocation.getName());
        user_list.setValue("type_id", type);
        user_list.setValue("position", position);
        user_list.setValue("location_id", trendslocation.getWoeid());
        user_list.save();/* w w w.j av  a 2s  .  c om*/
        Toast.makeText(this, getString(R.string.column_created, trendslocation.getName()), Toast.LENGTH_LONG)
                .show();
    } else {
        position = created_column_list.get(0).getInt("position");
    }

    Intent intent = getIntent();
    intent.putExtra("position", position);

    setResult(RESULT_OK, intent);
    finish();
}

From source file:com.javielinux.tweettopics2.TrendsLocationActivity.java

License:Apache License

@Override
public void onResults(BaseResponse result) {

    TrendsLocationResponse trendsLocationResponse = (TrendsLocationResponse) result;
    ResponseList<Location> trendslocation_data = trendsLocationResponse.getLocationList();

    try {// w  w  w.  j av  a2 s.co m
        Collections.sort(trendslocation_data, new Comparator<Location>() {

            public int compare(Location location1, Location location2) {
                return location1.getName().compareToIgnoreCase(location2.getName());
            }

        });

        for (int i = 0; i < trendslocation_data.size(); i++)
            trendslocation_list.add(trendslocation_data.get(i));

    } catch (Exception e) {
        e.printStackTrace();
    }

    trendslocation_adapter.notifyDataSetChanged();

    if (trendslocation_adapter.getCount() == 0) {
        showNoTrendsLocation();
    } else {
        showTrendsLocationLists();
    }
}

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

License:Open Source License

private void initWoeid(TwitterApiConnection twitterApiConnection) throws TwitterException {

    // don't run again if it's already initialized
    if (m_country.getItemCount() > 1) {
        return;//from   w  ww . j  av  a 2  s.  co  m
    }

    // add worldwide as default
    woeidMap.put(1, "Worldwide");
    placeMap.put("Worldwide", 1);

    // if Twitter API Connection is not available, use Worldwide as default
    if (twitterApiConnection == null) {
        m_country.addItem("Worldwide");
        return;
    }

    Twitter twitter = twitterApiConnection.getTwitter();

    ResponseList<Location> response = twitter.getAvailableTrends();

    for (Location location : response) {
        // skip worldwide as it's already added as default
        if (location.getWoeid() == 1)
            continue;
        // check if it's city or country
        if (location.getPlaceCode() == 12) {
            woeidMap.put(location.getWoeid(), location.getCountryName());
            placeMap.put(location.getCountryName(), location.getWoeid());
        } else {
            woeidMap.put(location.getWoeid(), location.getCountryName() + "|" + location.getName());
            placeMap.put(location.getCountryName() + "|" + location.getName(), location.getWoeid());
        }
    }

    // split country and city
    List<String> cities;
    String[] tokens;
    String lastCountry = "";
    for (Map.Entry<String, Integer> entry : placeMap.entrySet()) {
        // skip worldwide as it's already added as default
        if (entry.getValue() == 1)
            continue;
        tokens = entry.getKey().split("\\|");
        if (!lastCountry.equals(tokens[0])) {
            m_country.addItem(tokens[0]);
        }
        lastCountry = tokens[0];
        if (countryCityMap.containsKey(tokens[0])) {
            cities = countryCityMap.get(tokens[0]);
        } else {
            cities = new ArrayList<String>();
            countryCityMap.put(tokens[0], cities);
        }
        if (tokens.length > 1) {
            cities.add(tokens[1]);
        } else {
            cities.add("-" + tokens[0] + "-");
        }
    }

}

From source file:com.mmiagency.knime.nodes.twitter.util.TrendRow.java

License:Open Source License

private static DataCell[] createCells(final Location location, final Trend trend) {
    List<DataCell> cells = new ArrayList<DataCell>();
    if (location.getCountryName() == null) {
        cells.add(new StringCell(location.getName()));
    } else {/*from ww w . j a v  a2s .  com*/
        cells.add(new StringCell(location.getCountryName() + " - " + location.getName()));
    }
    cells.add(new StringCell(trend.getName()));
    cells.add(new StringCell(trend.getQuery()));
    cells.add(new StringCell(trend.getURL()));
    return cells.toArray(new DataCell[cells.size()]);
}

From source file:DataCollections.LocationHelper.java

public void insertLocations(Location[] l) {
    boolean[] selection = new boolean[Location_dbo.nooffields];
    Location_dbo loc;// w w w .  jav a  2 s. c  om

    //LogPrinter.printLog("No of Locations to be Processed: "+l.length);

    for (Location l1 : l) {
        if (LocationsTable.select("woeid = " + l1.getWoeid(), 0, 1).length == 0) {
            LogPrinter.printLog("Processing a location " + l1.getName());
            loc = convertLocationToLocation_dbo(l1);
            for (int j = 0; j < Location_dbo.nooffields; j++) {
                selection[j] = loc.values[j].used;
            }
            LocationsTable.insert(loc, selection);
        }
    }
}

From source file:DataCollections.LocationHelper.java

public Location_dbo convertLocationToLocation_dbo(Location l) {

    Location_dbo loc = new Location_dbo();
    //LogPrinter.printLog("Conversion of current location to database object is started");
    loc.values[Location_dbo.map.get("country_code")].setValue(l.getCountryCode());
    loc.values[Location_dbo.map.get("country_name")].setValue(l.getCountryName());
    loc.values[Location_dbo.map.get("name")].setValue(l.getName());
    loc.values[Location_dbo.map.get("place_code")].setValue(String.valueOf(l.getPlaceCode()));
    loc.values[Location_dbo.map.get("place_name")].setValue(l.getPlaceName());
    loc.values[Location_dbo.map.get("url")].setValue(l.getURL());
    loc.values[Location_dbo.map.get("woeid")].setValue(String.valueOf(l.getWoeid()));
    //LogPrinter.printLog("Conversion of current location to database object complete");
    return loc;//from   w w  w . ja  v  a  2  s  .  co  m
}

From source file:DataCollections.TrendsCollections.java

public void collectLatestTrendingHashTags() throws InterruptedException {

    ListIterator<Location> i = locations.listIterator();

    while (i.hasNext()) {
        Location l = i.next();

        try {/*  w  w w  .  j  av  a  2  s .c o m*/
            trends = trendsresources.getPlaceTrends(l.getWoeid());
        } catch (TwitterException e) {
            Thread.sleep((e).getRetryAfter() * 1000 + 5000);
            i.previous();
            continue;

        }

        System.out.println("\nLocation:- CountryCode: " + l.getCountryCode() + " Country Name: "
                + l.getCountryName() + " Name: " + l.getName() + " PlaceCode: " + l.getPlaceCode()
                + " PlaceName: " + l.getPlaceName() + " URL: " + l.getURL() + " Woeid: " + l.getWoeid() + "\n");
        Trend[] ts = trends.getTrends();

        for (int t = 0; t < ts.length; t++) {
            System.out.println("Trend " + t + ts[t].getName() + " " + ts[t].toString());
        }
        htaghelper.insertTrends(ts);
    }
}