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 GetVideoAddress extends Activity {

	protected static final String TAG = "GetVideoAddress";
	private EditText videoIdEt;
	private Button getAddressBtn;
	private TextView resultTxtV;

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

		setContentView(R.layout.video_address);
		// init ui
		videoIdEt = (EditText) findViewById(R.id.video_id_et);
		getAddressBtn = (Button) findViewById(R.id.video_adress_btn);
		resultTxtV = (TextView) findViewById(R.id.address_result_txt);
		// set action listener
		getAddressBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// 视频id
				String vid = videoIdEt.getText().toString().trim();// "72613970";
				JSONObject result = Video.getVideoAddress(
						getApplicationContext(), vid);
				Log.i(TAG, "address " + result);
				// 数据简单解析与呈现
				String parseStr = Parser.simpleParser(result);

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

		});
	}
}
