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 android.widget.Toast;

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

/**
 * 删除某视频
 * 
 */
public class DeleteVideo extends Activity {
	/**
	 * log tag
	 */
	static final String TAG = "DeleteVideo";

	private Button deleteBtn;
	private EditText videoIdEt;
	private TextView resultTxtV;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.video_delete);

		// init UI
		resultTxtV = (TextView) findViewById(R.id.result_txt);
		deleteBtn = (Button) findViewById(R.id.video_delete_btn);
		videoIdEt = (EditText) findViewById(R.id.video_id_et);

		// set action listener
		deleteBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				final String videoId = videoIdEt.getText().toString().trim();

				if ("".equals(videoId)) {
					// input null
					String msg = "请输入video id";
					Toast.makeText(getApplicationContext(), msg,
							Toast.LENGTH_SHORT).show();
				} else {
					// get data
					JSONObject result = Video.deleteVideo(DeleteVideo.this,
							videoId);
					Log.i(TAG, "get video info " + result);

					// resultTxtV.setText(result.toString());

					// 数据简单解析与呈现
					String parseStr = Parser.simpleParser(result);

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

					resultTxtV.setText(spanStr);
				}
			}
		});
	}
}
