
try{
ACTIVE_TV;
}catch(e){
ACTIVE_TV=null;
}
var TVINFO_HEIGHT=36;
var gadget=new Gadget();
gadget.init=function(){
this.tv=new container({});
this.tv.video=new videobox({color:[0,0,0,0],overscan:true});
this.tv.components.push(this.tv.video);
this.components.push(this.tv);
this.isFull=false;
if(this.isFullTV===undefined)
this.isFullTV=false;
this.isEditMode=false;
if(SHOW_TVINFO&&!this.isFullTV){
var me=this;
this.tv_info=new container({visible_p:false,});
this.tv_info.label=new gbox({width:412,height:36,color:[0,0,0,160],});
this.tv_info.title=new gtext({width:412-20,font_size:32,align:CENTER,omitter:"...",
color:[255,255,255,255],translate:[0,1,0],text:"",});
this.tv_info.components.push(this.tv_info.label,this.tv_info.title);
this.components.push(this.tv_info);
this.tv_info.update=function (){
try{
if(me.is_activate){
load("/tmp/home_banner.js");
var text_info="";
this.home_banner_info=home_banner_info;

var banner_id=this.home_banner_info[0];
if(banner_id==-1){
text_info=home_banner_info[1]?home_banner_info[1]:"";}else {

switch(banner_id){
case 0:
text_info="地上D ";
break;
case 1:
text_info="BS ";
break;
case 2:
text_info="CS1 ";
break;
case 3:
text_info="CS2 ";
break;
default:
break;}
var info1=this.home_banner_info[1]?this.home_banner_info[1]:"";
var info2=this.home_banner_info[2]?this.home_banner_info[2]:"";
var info3=this.home_banner_info[3]?this.home_banner_info[3]:"";
text_info=text_info+info1+"  "+info2+"     "+info3;}
if((text_info||text_info=="")&&this.title.text!=text_info)
setf_text(this.title,text_info);}
}catch(e){
console.log("Error = "+e.message);};}
this.tv_info.free=function (){
setf_text(this.title,"");}

this.tv_info.setVisible=function (bool){
this.title.visible_p=bool;
this.label.visible_p=bool;}

this.tv_info.setInfoAreaSize=function (w,h){
this.visible_p=true;
this.translate[1]=-Math.floor((h-TVINFO_HEIGHT)/2+1);
this.label.width=w;
this.title.width=w-20;}

}
};
gadget.setSize=function(width,height){
if(SHOW_TVINFO&&!this.isFullTV){
var aw=(width-TVINFO_HEIGHT*16/9)/16;
var ah=(height-TVINFO_HEIGHT)/9;
if(aw<ah){
this.tv.width=Math.floor(width-TVINFO_HEIGHT*16/9);
this.tv.height=Math.floor(aw*9);}else{
this.tv.width=Math.floor(ah*16);
this.tv.height=height-TVINFO_HEIGHT;}
this.tv.translate[1]=Math.floor(TVINFO_HEIGHT/2)+2;
this.tv_info.setInfoAreaSize(this.tv.width,TVINFO_HEIGHT+this.tv.height);}else {
var aw=width/16;
var ah=height/9;
if(aw<ah){
this.tv.width=width;
this.tv.height=Math.floor(aw*9);}else{
this.tv.width=Math.floor(ah*16);
this.tv.height=height;}
}
this.width=width;
this.height=height;
this.tv.video.width=this.tv.width+this.tv.width%2;
this.tv.video.height=this.tv.height+this.tv.height%2;
this.player=new BroadcastPlayer();};
gadget.onFocus=function(is_focused,key){
if(is_focused){
if(SHOW_TVINFO&&!this.isFullTV){
this.requestFocus([0,0,0],[TVINFO_HEIGHT*16/9+this.tv.width,TVINFO_HEIGHT+this.tv.height],0,42,null);}else{
this.requestFocus([0,0,0],[this.tv.width,this.tv.height],0,42,null);}
}
};
gadget.setFullTV=function(bool){
this.isFullTV=bool;};
gadget.setFullscreen=function(bool){
this.isFull=bool;};
gadget.suspend=function(bool){
this.is_suspend=bool;
if(!bool){
this.player.osd_control(OSD_INVISIBLE);}
};
gadget.setEditMode=function(bool){
this.isEditMode=bool;};
gadget._setTVInfoShow=function(bool){
if(this.tv_info)this.tv_info.setVisible(bool);};
gadget.df_connect=function(){
if(this.is_suspend)return;
if(this.df_disconnect_req)return;
this.player.df_connect();};
gadget.df_disconnect=function(){
if(this.is_suspend)return;
this.player.df_disconnect();};
gadget.osd_control=function(type){
if(this.is_suspend)return;
this.player.osd_control(type);};
gadget.need_update=false;
gadget.default_tvplayer_hook_func=function(stg,obj,event){
if(event!=obj.UPDATE)
return false;
try{
ACTIVE_TV;}catch(e){
return;}
if(ACTIVE_TV.is_activate==true){
ACTIVE_TV.need_update=true;};
return true;};
gadget.animation=function(count){
if(SHOW_TVINFO&&!this.isFullTV&&this.need_update==true){
this.need_update=false;
this.tv_info.update();}
};
gadget.activate=function(bool){
var me=this;
this.autoLaunch(false);
if(this.del_pre_window){
this.del_pre_window();
delete this.del_pre_window;
if(this.isFull)this.is_activate=true;}
if(bool){
ACTIVE_TV=this;
this.tv.visible_p=true;
pre_videobox.visible_p=false;
this.need_update=true;

if(SHOW_TVINFO&&!this.isFullTV){
try{
addTVPlayerEventHook("TV_GADGET",tvplayer.UPDATE,this.default_tvplayer_hook_func);}catch(e){
add_default_stage_event_hook(tvplayer,this.default_tvplayer_hook_func);}
}
if(this.isFullTV&&this.isFull&&!this.isEditMode){
this.autoLaunch(true);
this.df_disconnect();
this.osd_control(OSD_INVISIBLE);}else{
this.df_connect();
append_timer(this.player,1000,function(obj){
delete_timer(obj);
if(me.isEditMode)return;
me.osd_control(OSD_SCALE);});}
}else{
delete_timer(this.player);
delete_timer(this.tv);
if(ACTIVE_TV==this){
if(isActiveStatus()){
this.df_connect();
this.osd_control(OSD_INVISIBLE);}
ACTIVE_TV=null;
if(SHOW_TVINFO&&!this.isFullTV){
try{
delTVPlayerEventHook("TV_GADGET");}catch(e){
del_default_stage_event_hook(tvplayer);}
}
}
this.tv.visible_p=false;
this.tv.translate[2]=0;
if(SHOW_TVINFO&&!this.isFullTV)this.tv_info.free();}
this.is_activate=bool;
if(SHOW_TVINFO&&!this.isFullTV&&bool)this.tv_info.update();};
gadget.autoLaunch=function(bool){
var INTERVAL=500;
var INTERVAL_COUNT=3*2;
try{
if(!SU_SUPPORT_MYHOMESCREEN){
INTERVAL=100;
INTERVAL_COUNT=0;}
}catch(e){}
var self=this;
if(bool){
var launch_count=0;
var check=function(){
append_timer(self,INTERVAL,function(obj){
if(!is_available_stage("HOME")||self.isEditMode||
(system.is_apps_launch())||
is_available_stage("search")||
is_available_stage("message")||
is_available_guidance()||
is_available_SMAd()||
(getPowerStatus()==system.POWER_STATUS_OFF)||
(!system.idle.isIdle()&&SU_SUPPORT_MYHOMESCREEN)){
launch_count=0;
return;}
launch_count++;
if(launch_count>INTERVAL_COUNT){
obj.launchApl();
launch_count=0;}});};
check();}else{
delete_timer(this);};};
gadget.getStatus=function(){
return {"movable":false,"removable":false};};
gadget.launchApl=function(locked_panel,report){
this.ACTIVE_TV=null;
var ret=apputil.launch_apl("0387878700000001",null,locked_panel,report);
if(ret==0){
this.df_disconnect();
this.osd_control(OSD_NORMAL);}
};
gadget.voicePlay=function(){
VoicePlay(LANG("LT_VG_MAIN_WINDOW")+" "+this._getTitle());};
return gadget;
