Android Open Source - WeatherMate Tweet Adapter






From Project

Back to project page WeatherMate.

License

The source code is released under:

Apache License

If you think the Android project WeatherMate listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.brightr.weathermate.adapters;
/*from w  w  w .  j  a v a  2  s  .c  om*/
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.content.Context;
import android.text.util.Linkify;
import android.text.util.Linkify.TransformFilter;
import android.util.Patterns;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.brightr.weathermate.R;

public class TweetAdapter extends BaseAdapter {
  
  private Context mContext;
  private ArrayList<String> tweets;
  private ArrayList<String> times;
  private ArrayList<Integer> icons;
  private ArrayList<String> mUsernames ;
  
  LayoutInflater inflater;
  
  
  public TweetAdapter(Context context, ArrayList<String> tweets, ArrayList<String> times){
    
    this.mContext = context;
    this.tweets = tweets;
    this.times = times;
    
    inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    
    mUsernames = new ArrayList<String>();
    mUsernames.add("cnn");
    mUsernames.add("yahoonews");
    mUsernames.add("abcnews");
    mUsernames.add("nytimes");
    mUsernames.add("cnetnews");
    mUsernames.add("engadget");
    mUsernames.add("reddit");
    mUsernames.add("rawstory");
    mUsernames.add("reuters");
    mUsernames.add("drudge_report");
    mUsernames.add("huffingtonpost");
    
    mUsernames.add("espn");
    mUsernames.add("yahoosports");
    mUsernames.add("cbssports");
    mUsernames.add("bleacherreport");
    mUsernames.add("sinow");
    
    mUsernames.add("youtube");
    mUsernames.add("collegehumor");
    mUsernames.add("forbes");
    mUsernames.add("9gag");
    mUsernames.add("funnyordie");
    mUsernames.add("ted_tweets");
    
    icons = new ArrayList<Integer>();
    icons.add(R.drawable.news_cnn);
    icons.add(R.drawable.news_yahoo);
    icons.add(R.drawable.news_abc);
    icons.add(R.drawable.news_nytimes);
    icons.add(R.drawable.news_cnet);
    icons.add(R.drawable.news_engadget);
    icons.add(R.drawable.news_reddit);
    icons.add(R.drawable.news_rawstory);
    icons.add(R.drawable.news_reuters);
    icons.add(R.drawable.news_drudge);
    icons.add(R.drawable.news_huffingtonpost);
    icons.add(R.drawable.news_espn);
    icons.add(R.drawable.news_yahoosports);
    icons.add(R.drawable.news_cbssports);
    icons.add(R.drawable.news_bleacherreport);
    icons.add(R.drawable.news_sportsillustrated);
    icons.add(R.drawable.news_logo);
    icons.add(R.drawable.news_collegehumor);
    icons.add(R.drawable.news_forbes);
    icons.add(R.drawable.news_ninegag);
    icons.add(R.drawable.news_funnyordie);
    icons.add(R.drawable.news_ted);
    
    
    
    
    
  }
  
  public void linkifyText(TextView text){
    
    TransformFilter filter = new TransformFilter() {
        public final String transformUrl(final Matcher match, String url) {
            return match.group();
        }
    };

    Pattern mentionPattern = Pattern.compile("@([A-Za-z0-9_-]+)");
    String mentionScheme = "http://www.twitter.com/";
    Linkify.addLinks(text, mentionPattern, mentionScheme, null, filter);

    Pattern hashtagPattern = Pattern.compile("#([A-Za-z0-9_-]+)");
    String hashtagScheme = "http://www.twitter.com/search/";
    Linkify.addLinks(text, hashtagPattern, hashtagScheme, null, filter);

    Pattern urlPattern = Patterns.WEB_URL;
    Linkify.addLinks(text, urlPattern, null, null, filter);
    
  }

  @Override
  public int getCount() {
    
    return tweets.size();
  }

  @Override
  public Object getItem(int position) {
    
    return null;
  }

  @Override
  public long getItemId(int position) {
    
    return 0;
  }
  
  private class ViewHolder{
    
    TextView tweet;
    TextView username;
    TextView time;
    ImageView icon;
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    
    ViewHolder v;
    
    if(convertView == null){
      
      convertView = inflater.inflate(R.layout.social_list_row, null);
      v = new ViewHolder();
      v.tweet = (TextView) convertView.findViewById(R.id.tvTweet);
      v.time = (TextView) convertView.findViewById(R.id.tvTweetTime);
      v.icon = (ImageView) convertView.findViewById(R.id.ivTwitterIcon);
      v.username = (TextView) convertView.findViewById(R.id.tvTwitterUsername);
      
      convertView.setTag(v);
    }
    
    else
      v = (ViewHolder) convertView.getTag();
        v.tweet.setText(tweets.get(position));
        linkifyText(v.tweet);
        v.time.setText(times.get(position));
        v.icon.setImageResource(icons.get(position));
        v.username.setText(mUsernames.get(position));
        
    
    
    
    return convertView;
  }

}




Java Source Code List

.PullToRefreshListView.java
com.brightr.listeners.FlingGestureListener.java
com.brightr.listeners.OnFlingGestureListener.java
com.brightr.listeners.SimpleGestureFilter.java
com.brightr.weathermate.activities.LocationMapview.java
com.brightr.weathermate.activities.MainActivity.java
com.brightr.weathermate.activities.MyFlightsActivity.java
com.brightr.weathermate.activities.NewsViewerActivity.java
com.brightr.weathermate.activities.SearchLocationsActivity.java
com.brightr.weathermate.activities.SettingsActivity.java
com.brightr.weathermate.activities.SocialMediaActivity.java
com.brightr.weathermate.activities.WebsiteViewActivity.java
com.brightr.weathermate.adapters.FlightListAdapter.java
com.brightr.weathermate.adapters.LocationListAdapter.java
com.brightr.weathermate.adapters.MenuAdapter.java
com.brightr.weathermate.adapters.MyPagerAdapter.java
com.brightr.weathermate.adapters.NewsPagerAdapter.java
com.brightr.weathermate.adapters.SavedFlightsAdapter.java
com.brightr.weathermate.adapters.SearchListAdapter.java
com.brightr.weathermate.adapters.TweetAdapter.java
com.brightr.weathermate.adapters.WeatherAdapter.java
com.brightr.weathermate.databases.FlightStorage.java
com.brightr.weathermate.databases.LocationStorage.java
com.brightr.weathermate.databases.NewsStorage.java
com.brightr.weathermate.fragments.EntertainmentNewsFragment.java
com.brightr.weathermate.fragments.GeneralNewsFragment.java
com.brightr.weathermate.fragments.MainWeatherFragment.java
com.brightr.weathermate.fragments.MenuFragment.java
com.brightr.weathermate.fragments.PoliticalNewsFragment.java
com.brightr.weathermate.fragments.SidePanelFragment.java
com.brightr.weathermate.fragments.SportsNewsFragment.java
com.brightr.weathermate.parsers.FlightTrackingParser.java
com.brightr.weathermate.parsers.JSONParser.java
com.brightr.weathermate.parsers.JSONTrafficParser.java
com.brightr.weathermate.parsers.TwitterFeedParser.java
com.brightr.weathermate.providers.FlightTrackingProvider.java
com.brightr.weathermate.providers.LocationSearchProvider.java
com.brightr.weathermate.providers.TrafficIncidentProvider.java
com.brightr.weathermate.providers.WeatherProvider.java
com.brightr.weathermate.utils.AirlineNamesCollection.java
com.brightr.weathermate.views.CustomDialogPreference.java
com.brightr.weathermate.views.CustomPreferenceCategory.java