Android Open Source - Twitter-Android Post Status






From Project

Back to project page Twitter-Android.

License

The source code is released under:

Apache License

If you think the Android project Twitter-Android 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 info.mahmoudhossam.twitter.Activities;
// w  ww  .  ja v  a 2  s. co m
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import info.mahmoudhossam.twitter.R;
import info.mahmoudhossam.twitter.TwitterBackend;
import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterException;

public class PostStatus extends Activity {

  private Twitter twitter;
  private EditText text;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.post);
    twitter = TwitterBackend.getTwitterInstance();
    text = (EditText) findViewById(R.id.editText1);
  }

  public void onTweet(View view) {
    String tweet = text.getText().toString();
    new StatusPoster().execute(tweet);
  }

  class StatusPoster extends AsyncTask<String, Integer, Status> {

    @Override
    protected twitter4j.Status doInBackground(String... params) {
      try {
        return twitter.updateStatus(params[0]);
      } catch (TwitterException e) {
        e.printStackTrace();
        return null;
      }
    }

    @Override
    protected void onPostExecute(twitter4j.Status result) {
      super.onPostExecute(result);
      if (result != null) {
        Toast.makeText(getApplicationContext(), "Posted",
            Toast.LENGTH_SHORT).show();
        finish();
      } else {
        Toast.makeText(getApplicationContext(),
            "Error, could not connect to twitter",
            Toast.LENGTH_SHORT).show();
      }
    }

  }

}




Java Source Code List

info.mahmoudhossam.twitter.MyEndlessAdapter.java
info.mahmoudhossam.twitter.TweetAdapter.java
info.mahmoudhossam.twitter.TwitterBackend.java
info.mahmoudhossam.twitter.Activities.Browser.java
info.mahmoudhossam.twitter.Activities.Login.java
info.mahmoudhossam.twitter.Activities.MainActivity.java
info.mahmoudhossam.twitter.Activities.PostStatus.java
info.mahmoudhossam.twitter.Activities.Tweet.java
info.mahmoudhossam.twitter.Fragments.HomeTweets.java
info.mahmoudhossam.twitter.Fragments.Mentions.java
info.mahmoudhossam.twitter.Fragments.TweetFragment.java
info.mahmoudhossam.twitter.Fragments.UserTweets.java