package com.sfc.ui;
import java.util.ArrayList;
import java.util.List;
import com.sfc.ui.adapter.LoginListAdapter;
import weibo4j.User; //这是新浪开发包中的实体类
import weibo4j.Weibo;//这是新浪开发包中的类
import weibo4j.WeiboException;//这是新浪开发包中的类
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;
public class LoginActivity extends Activity implements Runnable {
private Button loginButton;
private ListView listView;
private ProgressDialog loginDialog;
private Thread loginThread;
private Handler handler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
loginButton = (Button)findViewById(R.id.loginButton);
List<String> list = new ArrayList<String>();
list.add("随便看看");
list.add("推荐用户");
list.add("热门转发");
listView = (ListView)findViewById(R.id.listView);
loginThread = new Thread(this);
handler = new Handler(){
//1代表登陆成功 0代表登陆失败
public void handleMessage(Message msg) {
loginDialog.cancel();
switch (msg.what) {
case 1:
Toast.makeText(LoginActivity.this, "登陆成功 ", 3000).show();
break;
case 0:
Toast.makeText(LoginActivity.this, "登陆失败", 3000).show();
break;
}
};
};
listView.setAdapter(new LoginListAdapter(this,list));
loginButton.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
loginDialog = new ProgressDialog(LoginActivity.this);
loginDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
loginDialog.setMessage("登陆服务器");
loginDialog.show();
loginThread.start();
}
});
}
public void run() {
Log.e("loginThread","start");
Weibo weibo = new Weibo("XXX@sina.com","XXX");//新浪微博用户名和密码
weibo.setHttpConnectionTimeout(5000);
Message msa = new Message();
try {
User user = weibo.verifyCredentials();//该方法会请求新浪微博服务器返回Json对象
msa.what=1;
} catch (WeiboException e) {
msa.what=0;
}
}
}