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 SearchVideo extends Activity {
	private String TAG = "SearchVideo";
	private EditText keyEt;
	private Button searchBtn;
	private TextView resultTxtV;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.video_search);
		// init ui
		keyEt = (EditText) findViewById(R.id.key_word_et);
		searchBtn = (Button) findViewById(R.id.search_btn);
		resultTxtV = (TextView) findViewById(R.id.search_result_txt);
		// set action listener
		searchBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				String keyword = keyEt.getText().toString().trim();// 搜索关键词

				String page = "1";// 第几页
				String num = "5";// 每页数量
				JSONObject result = Video.searchVideo(getApplicationContext(),
						keyword, 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);
			}
		});

	}
}
