Back to project page SubTweeter.
The source code is released under:
Apache License
If you think the Android project SubTweeter listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.henningta.subtweeter; //from w w w . j a v a 2 s . c o m import twitter4j.ResponseList; import twitter4j.Twitter; import twitter4j.TwitterException; import twitter4j.TwitterFactory; import twitter4j.conf.ConfigurationBuilder; import android.os.AsyncTask; import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ListView; import android.widget.ProgressBar; public class MainActivity extends Activity implements OnClickListener, OnItemClickListener { private Twitter twitter; //private EditText etPin, etTweet; //private Button pinButton, tweetButton; //private RequestToken requestToken; private ListView lvTimeline; private ProgressBar timelineProgress; private StatusAdapter statusAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //etPin = (EditText)findViewById(R.id.etPin); //etTweet = (EditText)findViewById(R.id.etTweet); //pinButton = (Button)findViewById(R.id.pinButton); //pinButton.setOnClickListener(this); //tweetButton = (Button)findViewById(R.id.tweetButton); //tweetButton.setOnClickListener(this); //twitter = new TwitterFactory().getInstance(); //twitter.setOAuthConsumer("x3JRTVlJ2PgrvKHc1uJaJg", "wzGjBW1z2pHTkZ6HJIejGXlqIV13lrvcoq308qU"); /*OAuthTask oauthTask = new OAuthTask(); oauthTask.execute(new Twitter[] {twitter});*/ //AccessToken accessToken = new AccessToken("356448429-YR9A9Y51hPabH1zMlN9RVdlXsHruyhHA6nMDCbZc", "ddXyAFBwsiniCFP0K3I940S6kCFTO3679HATi4WgcnF31"); //twitter.setOAuthAccessToken(accessToken); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true) .setOAuthConsumerKey("x3JRTVlJ2PgrvKHc1uJaJg") .setOAuthConsumerSecret("wzGjBW1z2pHTkZ6HJIejGXlqIV13lrvcoq308qU") .setOAuthAccessToken("356448429-YR9A9Y51hPabH1zMlN9RVdlXsHruyhHA6nMDCbZc") .setOAuthAccessTokenSecret("ddXyAFBwsiniCFP0K3I940S6kCFTO3679HATi4WgcnF31"); twitter = new TwitterFactory(cb.build()).getInstance(); timelineProgress = (ProgressBar)findViewById(R.id.timelineProgress); lvTimeline = (ListView)findViewById(R.id.lvTimeline); lvTimeline.setOnItemClickListener(this); lvTimeline.setEmptyView(timelineProgress); TimelineTask timelineTask = new TimelineTask(this); timelineTask.execute(new Twitter[] {twitter}); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public void onClick(View v) { /*if (v == pinButton) { //PinTask pinTask = new PinTask(); //pinTask.execute(new RequestToken[] {requestToken}); } else if (v == tweetButton) { String tweet = etTweet.getText().toString(); TweetTask tweetTask = new TweetTask(); tweetTask.execute(new String[] {tweet}); }*/ } @Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) { twitter4j.Status status = statusAdapter.getItem(position); } /*private class OAuthTask extends AsyncTask<Twitter, Void, Void> { @Override protected Void doInBackground(Twitter... twitters) { requestToken = null; twitter = twitters[0]; try { requestToken = twitter.getOAuthRequestToken(); System.out.println("Authorization URL: \n" + requestToken.getAuthorizationURL()); } catch (TwitterException te) { System.out.println("Error: \n" + te.getMessage()); } return null; } } private class PinTask extends AsyncTask<RequestToken, Void, Void> { @Override protected Void doInBackground(RequestToken... tokens) { AccessToken accessToken = null; requestToken = tokens[0]; try { String pin = etPin.getText().toString(); accessToken = twitter.getOAuthAccessToken(requestToken, pin); System.out.println("Access Token: " + accessToken.getToken()); System.out.println("Access Token Secret: " + accessToken.getTokenSecret()); } catch (TwitterException te) { System.out.println("Error: \n" + te.getMessage()); } return null; } }*/ /*private class TweetTask extends AsyncTask<String, Void, Void> { @Override protected Void doInBackground(String... tweets) { String tweet = tweets[0]; try { twitter.updateStatus(tweet); System.out.println("success"); } catch (TwitterException te) { System.out.println("Error: \n" + te.getMessage()); } return null; } }*/ private class TimelineTask extends AsyncTask<Twitter, Void, ResponseList<twitter4j.Status>> { private Context context; public TimelineTask(Context context) { this.context = context; } @Override protected ResponseList<twitter4j.Status> doInBackground(Twitter... twitters) { twitter = twitters[0]; try { ResponseList<twitter4j.Status> timeline = twitter.getHomeTimeline(); return timeline; } catch (TwitterException e) { e.printStackTrace(); } return null; } @Override protected void onPostExecute(ResponseList<twitter4j.Status> timeline) { if (timeline == null) return; if (statusAdapter == null) statusAdapter = new StatusAdapter(context, R.layout.status_list_item, timeline); else { statusAdapter.clear(); statusAdapter.addAll(timeline); } lvTimeline.setAdapter(statusAdapter); } } }