Android Open Source - android_twitter_client Compose Activity






From Project

Back to project page android_twitter_client.

License

The source code is released under:

GNU General Public License

If you think the Android project android_twitter_client 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.github.snambi.twitterclient.activities;
//from  w w w  . ja va  2  s .co m
import org.json.JSONObject;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.github.snambi.twitterclient.R;
import com.github.snambi.twitterclient.TwitterApplication;
import com.github.snambi.twitterclient.clients.TwitterRestClient;
import com.github.snambi.twitterclient.models.Tweet;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.nostra13.universalimageloader.core.ImageLoader;

public class ComposeActivity extends Activity {
  
  private TextView tvScreenName = null;
  private ImageView imgProfileImageUrl = null;
  private EditText etTweetText = null;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_compose);
    
    SharedPreferences prefs = getSharedPreferences("com.github.snambi.twitterclient", Context.MODE_PRIVATE);
    
    // read screen_name and profile_image_url
    String screenName = prefs.getString("screen_name", null);
    String profileImageUrl = prefs.getString("image_profile_url", null);
    
    tvScreenName = (TextView) findViewById(R.id.tvScreenName2);
    imgProfileImageUrl = (ImageView) findViewById(R.id.imgProfileImage2);
    etTweetText = (EditText) findViewById(R.id.etTweetBox);
    
    tvScreenName.setText("@" + screenName);
    
    ImageLoader imageLoader = ImageLoader.getInstance();
    imageLoader.displayImage(profileImageUrl, imgProfileImageUrl);
    
    // attach a listener that warns the user a
  }
  
  public void onCancelClick( View view){
    // go back to the timeline activity
    Intent intent = new Intent();
    setResult(RESULT_CANCELED, intent);
    finish();
  }
  
  public void onTweetClick( View view){
    
    TwitterRestClient restClient =TwitterApplication.getRestClient();
    
    String tweet = etTweetText.getText().toString();
    
    restClient.createTweet(tweet, new JsonHttpResponseHandler(){
      @Override
      public void onFailure(Throwable arg0, JSONObject arg1) {
        // TODO Auto-generated method stub
        super.onFailure(arg0, arg1);
      }
      
      @Override
      public void onSuccess(JSONObject jsonObject) {
        
        // on success finish the activity
        Tweet tweet = Tweet.fromJSON(jsonObject);
        Intent i = new Intent();
        i.putExtra("tweet", tweet);
        
        setResult(RESULT_OK, i);
        finish();
      }
    });
  }
}




Java Source Code List

com.github.snambi.twitterclient.TwitterApplication.java
com.github.snambi.twitterclient.activities.ComposeActivity.java
com.github.snambi.twitterclient.activities.LoginActivity.java
com.github.snambi.twitterclient.activities.ProfileActivity.java
com.github.snambi.twitterclient.activities.TimelineActivity.java
com.github.snambi.twitterclient.adapters.TwitterArrayAdapter.java
com.github.snambi.twitterclient.clients.TwitterRestClient.java
com.github.snambi.twitterclient.db.TweetDbHelper.java
com.github.snambi.twitterclient.fragemets.HomeTimelineFragment.java
com.github.snambi.twitterclient.fragemets.MentionsTimelineFragment.java
com.github.snambi.twitterclient.fragemets.ProfileHeaderFragment.java
com.github.snambi.twitterclient.fragemets.TwitterListFragment.java
com.github.snambi.twitterclient.fragemets.UserTimelineFragment.java
com.github.snambi.twitterclient.listeners.EndlessScrollListener.java
com.github.snambi.twitterclient.listeners.FragmentTabListener.java
com.github.snambi.twitterclient.models.SampleModel.java
com.github.snambi.twitterclient.models.Tweet.java
com.github.snambi.twitterclient.models.User.java
com.github.snambi.twitterclient.utils.TwitterTimeUtils.java