package org.shokai.voicetweet;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.UiThread;
import org.androidannotations.annotations.ViewById;

import twitter4j.Twitter;
import twitter4j.TwitterException;


@EActivity(R.layout.activity_tweet_test)
public class TweetTestActivity extends Activity {

    private Twitter mTwitter;
    private TwitterUtil mTwitterUtil;

    @ViewById(R.id.button)
    Button mButton;

    @ViewById(R.id.editText)
    EditText mEditText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mTwitterUtil = new TwitterUtil(this);
        mTwitter = mTwitterUtil.getTwitterInstance();
    }

    @Click
    void button() {
        updateTweetAsync(mEditText.getText().toString());
    }

    @Background
    void updateTweetAsync(String tweet) {
        try {
            twitter4j.Status res = mTwitter.updateStatus(tweet);
            if (res == null || !(res.getId() > 0)) {
                displayTweetResult("failed");
                return;
            }
        } catch (TwitterException e) {
            e.printStackTrace();
            displayTweetResult(e.getMessage());
            return;
        }
        displayTweetResult("success");
    }

    @UiThread
    void displayTweetResult(String message) {
        Toast.makeText(TweetTestActivity.this, message, Toast.LENGTH_SHORT).show();
    }

}

@@ -84,38 +84,8 @@
 le;%0A
-import android.widget.Button;%0A
 impo
@@ -631,56 +631,8 @@
 l;%0A%0A
-    @ViewById(R.id.button)%0A    Button mButton;%0A%0A
     
@@ -914,16 +914,29 @@
   @Click
+(R.id.button)
 %0A    voi
@@ -941,17 +941,23 @@
 oid 
-b
+onB
 utton
+Click
 ()
- 
 %7B%0A  

update TweetTest #16