Skip to content

Instantly share code, notes, and snippets.

@tmyt
Created Mar 28, 2012
Embed
What would you like to do?
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