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 GetChannelVideo extends Activity {
	private String TAG = "GetChannelVideo";
	private EditText channelIdEt;
	private Button getBtn;
	private TextView resultTxtV;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.video_channel);
		
		//init ui
		channelIdEt = (EditText) findViewById(R.id.channel_id_et);
		getBtn = (Button) findViewById(R.id.get_channelvideo_btn);
		resultTxtV = (TextView) findViewById(R.id.channel_result_txt);
		
		//set action listener
		getBtn.setOnClickListener(new OnClickListener() {

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

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

	}
}
