lang
1package com.ora_nge.topic_tweet; 2 3import android.app.Activity; 4import android.content.Intent; 5import android.content.SharedPreferences; 6import android.content.res.TypedArray; 7import android.net.Uri; 8import android.os.AsyncTask; 9import android.os.Bundle; 10import android.view.View; 11import android.view.Window; 12import android.widget.Button; 13import android.widget.EditText; 14import android.widget.RatingBar; 15import android.widget.TextView; 16import android.widget.Toast; 17 18import java.io.File; 19 20import twitter4j.conf.ConfigurationBuilder; 21 22 23public class TweetActivity extends Activity implements View.OnClickListener { 24 25 public static final String PREF_NAME = "access_token"; 26 public static final String TOKEN = "token"; 27 public static final String TOKEN_SECRET = "token_secret"; 28 Button button1; 29 TextView textView1; 30 31 private static final int SELECT_PIC = 1; 32 private Uri uri =null; 33 private File picPath = null; 34 private RatingBar rb; 35 private String token; 36 private String tokenSecret; 37 38 @Override 39 public void onCreate(Bundle savedInstanceState) { 40 super.onCreate(savedInstanceState); 41 getWindow().requestFeature(Window.FEATURE_NO_TITLE); 42 setContentView(R.layout.activity_tweet); 43 44 button1 = (Button)findViewById(R.id.button1); 45 button1.setOnClickListener(this); 46 47 textView1 = (TextView)findViewById(R.id.textView1); 48 49 SharedPreferences preferences = getSharedPreferences(PREF_NAME, MODE_PRIVATE); 50 token = preferences.getString(TOKEN, null); 51 tokenSecret = preferences.getString(TOKEN_SECRET, null); 52 if (token == null || tokenSecret == null) { 53 Intent intent = new Intent(this, OAuthActivity.class); 54 startActivity(intent); 55 finish(); 56 } 57 58 Button btn2 = (Button)findViewById(R.id.button2); 59 btn2.setOnClickListener(this); 60 } 61 62 @Override 63 public void onClick(View view) { 64 switch (view.getId()) { 65 case R.id.button2: 66 doTweet(); 67 return; 68 69 default: 70 break; 71 } 72 73 if(view == button1){ 74 TypedArray typedArray = getResources().obtainTypedArray(R.array.tango); 75 int i = (int) (Math.floor(Math.random() * (14)) ); 76 String str = typedArray.getString(i); 77 textView1.setText(str);} 78 } 79 80 81 82 private void doTweet(){ 83 EditText edCusine= (EditText)findViewById(R.id.editText1); 84 String tweet = edCusine.getText().toString(); 85 if (tweet.equals("")){ 86 Toast.makeText(this, "つぶやこう。", Toast.LENGTH_SHORT).show(); 87 edCusine.requestFocus(); 88 return; 89 } 90 new TweetTask().execute(tweet); 91 92 } 93 94 public class TweetTask extends AsyncTask<String,Void,Void>{ 95 96 @Override 97 protected Void doInBackground(String... params){ 98 ConfigurationBuilder builder = new ConfigurationBuilder(); 99 builder.setOAuthConsumerKey(getString(R.string.consumer_key)); 100 builder.setOAuthConsumerSecret(getString(R.string.consumer_secret)); 101 builder.setOAuthAccessToken(token); 102 builder.setOAuthAccessTokenSecret(tokenSecret); 103 builder.setMediaProvider("TWITTER"); 104 105 String tweet = params[0]; 106 tweet = tweet +"あ"; 107 108 return null; 109 } 110 111 @Override 112 protected void onPostExecute(Void result){ 113 super.onPostExecute(result); 114 showShortToast("つぶやきました!"); 115 } 116 117 } 118 private void showShortToast(String text){ 119 Toast.makeText(this, text, Toast.LENGTH_SHORT).show(); 120 } 121 122}
つぶやけません。
なぜかわかりますか?
つぶやきました!とは、でるのですが
つぶやけていません。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/03/30 17:20