/gist:6b98c32d14d711a0706b Secret
Created
March 28, 2012 08:50
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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