package com.sdk.example;

import org.json.JSONObject;

import android.app.Activity;
import android.os.Bundle;
import android.text.Html;
import android.text.SpannableString;
import android.text.Spanned;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.sdk.util.Parser;
import com.wole56.sdk.Video;

/**
 * 获取某用户的视频，支持分页
 * 
 * @author susie
 * 
 */
public class GetUserVideo extends Activity {
	private String TAG = "GetUserVideo";

	private EditText userIdEt;
	private Button getBtn;
	private TextView resultTxtV;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.video_user);
		// init ui
		userIdEt = (EditText) findViewById(R.id.user_id_et);
		getBtn = (Button) findViewById(R.id.user_video_btn);
		resultTxtV = (TextView) findViewById(R.id.uservideo_result_txt);
		// set action listener
		getBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				String sid = userIdEt.getText().toString().trim();// "qq123456";
				String page = "1";// 第几页
				String num = "5";// 每页数量
				JSONObject result = Video.getUserVideo(getApplicationContext(),
						sid, num, page);
				Log.i(TAG, result.toString());
				// 数据简单解析与呈现
				String parseStr = Parser.simpleParser(result);

				// 富文本形式展现
				Spanned span = Html.fromHtml(parseStr);
				SpannableString spanStr = new SpannableString(span);
				// show result
				resultTxtV.setText(spanStr);
			}
		});
	}
}
