add weibo src
[freespace.git] / weibosrc / com / weibo / sina / RetweetMessage.java
blobe90184c246880d00ba101caa54217af2befff969
1 package com.weibo.sina;
3 import weibo4android.Weibo;
4 import weibo4android.WeiboException;
5 import weibo4android.androidexamples.OAuthConstant;
6 import android.app.Activity;
7 import android.os.Bundle;
8 import android.os.Handler;
9 import android.os.Message;
10 import android.util.Log;
11 import android.view.View;
12 import android.view.View.OnClickListener;
13 import android.view.View.OnFocusChangeListener;
14 import android.view.inputmethod.InputMethodManager;
15 import android.widget.Button;
16 import android.widget.EditText;
17 import android.widget.TextView;
18 import android.widget.Toast;
20 public class RetweetMessage extends Activity {
21 private static final String TAG = "RetweetMessage";
22 private EditText mUpdate_edit;
23 private static final int RETWEET = 0x00;
24 private long mId;
25 private final Handler mHandler = new Handler() {
26 public void handleMessage(Message msg) {
27 switch (msg.what) {
28 case RETWEET:
29 String tmpString = mUpdate_edit.getEditableText().toString();
30 tmpString=tmpString.trim();
31 if(tmpString.length()==0){
32 Toast.makeText(getBaseContext(), R.string.content_empty, Toast.LENGTH_LONG).show();
33 return;
35 if(tmpString.length()>140){
36 Toast.makeText(getBaseContext(), R.string.content_outnumber, Toast.LENGTH_LONG).show();
37 return;
39 Weibo weibo = OAuthConstant.getInstance().getWeibo();
40 try {
41 weibo.updateStatus(mUpdate_edit.getEditableText().toString(), mId);
42 } catch (WeiboException e) {
43 e.printStackTrace();
45 // ProgressBar progressBar = (ProgressBar) findViewById(R.id.updateProgressBar);
46 // progressBar.setVisibility(View.INVISIBLE);
47 Toast.makeText(getBaseContext(), R.string.tips_send_ok, Toast.LENGTH_LONG).show();
48 finish();
49 overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
54 @Override
55 protected void onCreate(Bundle savedInstanceState) {
56 setContentView(R.layout.reply_layout);
57 super.onCreate(savedInstanceState);
58 mUpdate_edit = (EditText) findViewById(R.id.post_edit);
60 mUpdate_edit.setOnFocusChangeListener(new OnFocusChangeListener() {
62 public void onFocusChange(View v, boolean hasFocus) {
63 // TODO Auto-generated method stub
64 // Log.e(TAG, "onFocuseChange");
65 if (hasFocus) {
66 Log.e(TAG, "get Focuse");
67 InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
68 if (imm != null) {
70 imm.showSoftInput(mUpdate_edit, InputMethodManager.SHOW_FORCED);
72 } else {
73 Log.e(TAG, "lost Focuse");
74 if (RetweetMessage.this.getCurrentFocus() != null) {
75 // Log.e(TAG, "hideSoftInputFromWindow");
76 ((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(RetweetMessage.this
77 .getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
81 });
83 Button btn = (Button) findViewById(R.id.update_button);
84 btn.setOnClickListener(new OnClickListener() {
86 public void onClick(View v) {
88 // ProgressBar progressBar = (ProgressBar) findViewById(R.id.updateProgressBar);
89 // progressBar.setVisibility(View.VISIBLE);
90 mHandler.obtainMessage(RETWEET).sendToTarget();
93 });
94 btn = (Button) findViewById(R.id.cancel_button);
95 btn.setOnClickListener(new OnClickListener() {
96 public void onClick(View v) {
97 finish();
98 Log.e(TAG, "finish()");
99 overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
102 mUpdate_edit.requestFocus();
103 View reply = (View)findViewById(R.id.reply_view);
104 reply.setVisibility(View.VISIBLE);
105 TextView nick = (TextView) findViewById(R.id.nick);
106 Log.e(TAG, "name="+getIntent().getStringExtra("name"));
107 Log.e(TAG, "content="+getIntent().getStringExtra("content"));
108 nick.setText(getIntent().getStringExtra("name"));
109 nick = (TextView) findViewById(R.id.content);
110 nick.setText(getIntent().getStringExtra("content"));
111 mId=getIntent().getLongExtra("id",0);