Skip to content

Instantly share code, notes, and snippets.

@tmyt
Created March 28, 2012 08:50
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save tmyt/6b98c32d14d711a0706b to your computer and use it in GitHub Desktop.
package test.project;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import twitter4j.*;
public class TestActivity extends Activity {
private final String[] goHome = { "かえるよー", "帰るよー", "かえるでー", "かえるぅ", "かえるょ", "かえるで!" };
private final String[] face = { "ヾ(>ヮ<)ノ゙", "( ・ω・゛)", "ヽ(´ー`)ノ", "( ー`дー´)", "Σ(゚∀゚ノ)ノ" };
private Handler handler;
private boolean isSent;
private String message;
private Twitter twitter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
handler = new Handler();
isSent = false;
message = goHome[(int) (Math.random() * goHome.length)] + face[(int) (Math.random() * face.length)];
Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
sendDirectMessage();
}
});
}
void sendDirectMessage() {
if (isSent == false) {
try {
twitter.sendDirectMessage("mitsuba_tan", message);
isSent = true;
Timer t = new Timer();
scheduleFinish();
} catch (TwitterException e) {
message = e.getStatusCode() + "";
}
}
}
void scheduleFinish() {
Timer t = new Timer();
t.schedule(new TimerTask() {
@Override
public void run() {
handler.post(new Runnable() {
public void run() {
TestActivity.this.finish();
}
});
}
}, 3 * 1000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment