var GADGET_FRAME_L=["gadget_frame_l.png","gadget_frame_l2.png","gadget_frame_l3.png","gadget_frame_l4.png"];
var GADGET_FRAME_M=["gadget_frame_m.png","gadget_frame_m2.png","gadget_frame_m3.png","gadget_frame_m4.png"];
var GADGET_FRAME_R=["gadget_frame_r.png","gadget_frame_r2.png","gadget_frame_r3.png","gadget_frame_r4.png"];
var TV_FRAME_L="tv_frame_l.png";
var TV_FRAME_M="tv_frame_m.png";
var TV_FRAME_R="tv_frame_r.png";
var ADD_MARK="add_mark.png";
var DEBUG_TOP=0;
var GADGET_WIDTH=412;
var GADGET_HEIGHT=232;
var TVINFO_HEIGHT=36;
function Screen(screen_key,list_of_uniq_id,focus_moveto,isPowerOn){
if(!list_of_uniq_id)return;
this.superClass=container;
this.superClass({});
this.gadgets=[];
if(!this._mapping){
var map=[[0,1,2,3],[4,5,6,7],[8,9,10,11],[12,13,14,15]];
this._create_map(map);}
this.init_list_of_uniq_id=list_of_uniq_id;
this._pre_tv(list_of_uniq_id);
if(focus_moveto instanceof Function){
this.requestFocus=focus_moveto;}
this.status={};
this.status["activate"]=false;
this.status["setShow"]=false;
this.status["onFocus"]=false;
this.status["destroy"]=false;
this.status["removable"]=false;
this.status["editmode"]=false;
this.status["editable"]=true;
this.status["launching"]=false;
this.status["fullscreen"]=false;
this.status["suspend"]=false;
this.status["freeResource"]=!isActiveStatus();
this.status["snapshot"]=false;
this.status["error"]=false;
this.status["unlock"]=false;
this.status["animation"]=false;
this.status["confirm"]=false;
this.status["guidanceTV"]=false;
this.status["notice"]=false;
this._create();
this.setSnapshot(false);
if(isPowerOn){
this.pre_window.visible_p=true;
if(show_smad)
this._addSMAd();
show_smad=false;}
this.setScreenName();
this.setScreenKey(screen_key);};
Screen.prototype=new container({});
Screen.prototype.destroy=function (){
this._do_all_gadgets("destroy");
this._SMAd_destroy();
this.status["destroy"]=true;};
Screen.prototype.vanish=function (ids){
if(!ids||ids.length<=0||!this.gadgets)return;
var len=this.gadgets.length;
for(var i=0;i<len;i++){
var gadget_obj=this.gadgets[i];
for(var j=0;j<ids.length;j++){
if(ids[j]&&ids[j].substr(0,16)==gadget_obj.product_id)
this._do_gadget(gadget_obj,"vanish");}
};};
Screen.prototype.setFullscreen=function (bool){
try{
if(!this.status["suspend"]){
if(bool){
system.key_control.set_key_mode(system.key_control.MODE_HOME);
system.key_control.color=false;
ebus.asr.set_recog_option(ebus.asr.RECOG_OPT_TUNE,1);}else{
system.key_control.set_key_mode(system.key_control.MODE_OTHER);
ebus.asr.set_recog_option(ebus.asr.RECOG_OPT_TUNE,0);}
}
}catch(e){}
this._do_all_gadgets("setFullscreen",[bool]);
this.status["fullscreen"]=bool;
if(bool&&!this.status["confirm"])
this.reportNotice();
if(!bool){
this._SMAd_destroy();}
};
Screen.prototype.activate=function (bool){
if(bool&&!isActiveStatus())
return;
if(!(bool&&this.status["notice"])){
this.cancelReportError();
this.cancelReportNotice();
this.cancelRequestConfirmPanel();}
if(bool&&(!this.getTVGadget())){
this.pre_window.visible_p=true;}else{
this.pre_window.visible_p=false;}
if(this.status["snapshot"]){
this.status["activate"]=bool;
return;}
if(!this.status["editmode"]){
if(bool){
this._start_animation(this,0);
this.status["launching"]=false;}else{
this._stop_animation(this);
if(this.status["launching"]){
this._reset_fullscreen_appli(this.cursor);
this._do_gadget(this.cursor,"onFocus",[true]);}
this.screenname_frame.visible_p=bool;};}
if(this.status["unlock"]){
this._showPasswordPanel(false);}
this._do_all_gadgets("activate",[bool]);
this._locked_list=this._getLockedList();
this._setLockedFace(this._locked_list);
this.status["activate"]=bool;};
Screen.prototype.reset=function (){
this.cancelReportError();
this.cancelRequestConfirmPanel();
if(this.status["snapshot"]){
if(this.status["activate"]&&(!this.getTVGadget())){
this.pre_window.visible_p=true;}else{
this.pre_window.visible_p=false;}
}
if(!this.status["editmode"]){
this._reset_fullscreen_appli(this.cursor);
this._do_gadget(this.cursor,"onFocus",[this.status["onFocus"]]);
this.status["launching"]=false;this.screenname_frame.visible_p=this.status["activate"];}
if(this.status["unlock"]){
this._showPasswordPanel(false);}
if(!this.status["editmode"]){
if(this.status["activate"]){
this._start_animation(this,0);}else{
this._stop_animation(this);}
}
this._do_all_gadgets("activate",[this.status["activate"]]);
this._locked_list=this._getLockedList();
this._setLockedFace(this._locked_list);};
Screen.prototype.updateLockedFace=function (){
updateLockedList();
this._locked_list=this._getLockedList();
this._setLockedFace(this._locked_list);};
Screen.prototype.suspend=function (bool){
if(this.status["unlock"]){
this._showPasswordPanel(false);}
this._do_all_gadgets("suspend",[bool]);
this.status["suspend"]=bool;};
Screen.prototype.setShow=function (bool){
this.visible_p=bool;
this._do_all_gadgets("setShow",[bool]);
this.status["setShow"]=bool;};
Screen.prototype.onFocus=function (bool,keysym,point_env){
if(this._SMAd_status()==true)return true;
if(!this.status["editmode"]){
if(bool){
if(keysym==null&&point_env&&!this.status["confirm"]){
var id=this.search_gadget_id(point_env.x,point_env.y)
if(id!=-1){
var gadgetX=point_env.x-this._mapping[id].pos_x;
var gadgetY=point_env.y-this._mapping[id].pos_y;
var point_env2={x:gadgetX,y:gadgetY};
this._do_gadget(this.cursor,"onFocus",[false,null,point_env2]);
this.cursor=this.gadgets[id];
this._do_gadget(this.cursor,"onFocus",[true,null,point_env2]);
if(this.status["activate"])this._do_gadget(this.cursor,"voicePlay");}
}else{
if(!this.status["confirm"]){
this._do_gadget(this.cursor,"onFocus",[true,keysym]);
if(this.status["activate"])this._do_gadget(this.cursor,"voicePlay");}
}
}else{
this._do_gadget(this.cursor,"onFocus",[false,keysym]);}
if(keysym==TXK_DOWN){
if(this.cursor.product_id==TV_GADGET){
HOME.HomeSoundPlay(1);}else{
HOME.HomeSoundPlay(0);}
}
}else{
if(bool){
var ret=this._do_gadget(this.cursor,"getStatus");
if(ret["movable"]==false&&ret["removable"]==false){
for(var i=0,max=this.gadgets.length;i<max;i++){
ret=this._do_gadget(this.gadgets[i],"getStatus");
if(ret["movable"]==true||ret["removable"]==true){
this.cursor=this.gadgets[i];
break;}
}
}
}
this._set_focus(bool);};
this.status["onFocus"]=bool;
if(this.cursor
&&!this.status["error"]
&&!this.status["unlock"]
&&!this.status["confirm"])
this.cursor.status["onFocus"]=bool;};
Screen.prototype.key_hook=function (up_down,keysym){
if(this.getMoveStatus()==true)return true;
if(this._SMAd_status()==true){
var ret=false;
switch(keysym){
case TXK_ENTER:
this._do_SMAd("launchApl",["use_gwin",null]);
ret=true;
break;
case TXK_RETURN:
case TXK_EXIT:
this._SMAd_destroy();
ret=false;
break;
case TXK_UP:
case TXK_DOWN:
case TXK_LEFT:
case TXK_RIGHT:
this._do_SMAd("key_hook",[up_down,keysym]);
ret=true;
break;}
return ret;}
var screen_obj=this;
if(this.status["error"]
||this.status["unlock"]
||this.status["confirm"]){
if(this.cursor&&this.cursor.key_hook){
if(this.cursor.key_hook(up_down,keysym)){
if(keysym==TXK_RETURN){
HOME.HomeSoundPlay("cancel");}else{
HOME.HomeSoundPlay("enter");}
return true;}
if((this.status["unlock"])&&(keysym==TXK_EXIT)){
this.cursor=screen_obj._last_cursor;
this._showPasswordPanel(false);}
}
return false;}
if(!this.status["editmode"]){
var ret=this._do_gadget(this.cursor,"key_hook",[up_down,keysym]);
if(ret)return true;}
if((up_down!=KEY_PRESS)||(this.status["launching"]))
return false;
switch(keysym){
case TXK_ENTER:
this.launchFocusedGadget();
return true;
case TXK_UP:
case TXK_DOWN:
case TXK_LEFT:
case TXK_RIGHT:
var next_id=this._search_map(keysym);
if(isNumber(next_id)){
if(!this.status["editmode"]){
this._do_gadget(this.cursor,"onFocus",[false,keysym]);
this.cursor=this.gadgets[next_id];
this._do_gadget(this.cursor,"onFocus",[true,keysym]);
if(this.status["activate"])this._do_gadget(this.cursor,"voicePlay");}else{
var ret=this._do_gadget(this.gadgets[next_id],"getStatus");
this._set_focus(false);
this.cursor=this.gadgets[next_id];
this._set_focus(true);}
if(this.cursor.product_id==TV_GADGET){
HOME.HomeSoundPlay(1);}else{
HOME.HomeSoundPlay(0);}
return true;}
break;};
return false;};
Screen.prototype.activeTouchesList=[];
Screen.prototype.point_hook=function (type,identifier,x,y,screenX,screenY){
if(this.getMoveStatus()==true)return true;
if(this._SMAd_status()==true)return true;
if(this.status["unlock"])return true;
if(this.status["error"]||this.status["confirm"]){
if(this.cursor&&this.cursor.point_hook){
var ret=this.cursor.point_hook(type,identifier,x,y,screenX,screenY);
if(ret)return true;}
return false;}
if(this.status["launching"])return true;
if(this.status["editmode"])return true;
var active_id=this.activeTouchesList[identifier];
if(!isNumber(active_id))active_id=-1;
var id=this.search_gadget_id(x,y);
switch(type){
case "touchstart":
this.activeTouchesList[identifier]=id;
active_id=id;
break;
case "touchmove":
if(active_id!=id){
type="touchcancel";
this.activeTouchesList[identifier]=-1;}
break;
case "touchend":
case "touchcancel":
this.activeTouchesList[identifier]=-1;
break;}
if(type=="touchstart"){
if(this.gadgets[id]){
if(this.cursor!=this.gadgets[id]){
var gadgetX=x-this._mapping[id].pos_x;
var gadgetY=y-this._mapping[id].pos_y;
var point_env={x:gadgetX,y:gadgetY};
this._do_gadget(this.cursor,"onFocus",[false,null,point_env]);
this.cursor=this.gadgets[id];
this._do_gadget(this.cursor,"onFocus",[true,null,point_env]);
if(this.status["activate"])this._do_gadget(this.cursor,"voicePlay");
if(this.cursor.product_id==TV_GADGET){
HOME.HomeSoundPlay(1);}else{
HOME.HomeSoundPlay(0);}
}
}
}
if(active_id!=-1){
var gadgetX=x-this._mapping[active_id].pos_x;
var gadgetY=y-this._mapping[active_id].pos_y;
var args=[type,identifier,gadgetX,gadgetY,screenX,screenY];
var ret=this._do_gadget(this.gadgets[active_id],"point_hook",args);
if(ret)return true;}
if(type=="touchend"&&active_id!=-1&&active_id==id){
if(this.gadgets[id]){
if(this.cursor==this.gadgets[id]){
this.launchFocusedGadget();}
return true;}
}
return false;};
Screen.prototype.launchFocusedGadget=function(){
return this.launchTargetGadget(this.cursor);};
Screen.prototype.launchTargetGadget=function(target){
if(!target)return;
var screen_obj=this;
if(!target.product_id){
HOME.HomeSoundPlay("enter");
var report=this._collectAccessReportInfo(target);
this._do_gadget(target,"launchApl",[null,report]);
return true;}
switch(target.product_id){
case TV_GADGET:
HOME.HomeSoundPlay("enter");
this.status["launching"]=true;
this._launch_fullscreen_appli(target,function(){
screen_obj.status["launching"]=false;});
break;
case APPS_GADGET:
var report=this._collectAccessReportInfo(target);
this._do_gadget(target,"launchApl",[null,report]);
break;
default:
HOME.HomeSoundPlay("enter");
this.status["launching"]=true;
this._launch_anim(target,"check",function(){
screen_obj.status["launching"]=false;});
break;}
return;};
Screen.prototype.search_gadget_id=function(x,y){
var mapping=this._mapping;
if(!mapping)return -1;
var len=mapping.length;
for(var i=0;i<len;i++){
var target=mapping[i];
var margin_top=0;
var margin_bottom=0;
var margin_left=0;
var margin_right=0;
var pid=this.gadgets[i].product_id;
switch(pid){
case ZAPPING_GADGET:
margin_right=60;
break;}
if(x<target.pos_x-target.width/2-margin_left)continue;
if(target.pos_x+target.width/2+margin_right<x)continue;
if(y<target.pos_y-target.height/2-margin_bottom)continue;
if(target.pos_y+target.height/2+margin_top<y)continue;
return i;}
return -1;};
Screen.prototype.setScreenName=function (name){
if(!isString(name)){
name="";}
this._screen_name=name.toString();
if(this.screenname_plate.text!=this._screen_name){
if(isActiveStatus())
setf_text(this.screenname_plate,this._screen_name);
else
this.screenname_plate.org_text=this._screen_name;}
};
Screen.prototype.setScreenNameColor=function (color){
if(color instanceof Array){
this.screenname_plate.color=color;}
};
Screen.prototype.setScreenNameShow=function (b){
this.screenname_plate.visible_p=b;};
Screen.prototype.getScreenName=function (){
if(this._screen_name)
return this._screen_name;
return "";};
Screen.prototype.setScreenKey=function (key){
this._screen_key=key;};
Screen.prototype.getScreenKey=function (){
if(this._screen_key===undefined)
return "";
return this._screen_key;};
Screen.prototype.getProductId=function (){
if(!this.gadgets)return;
var list=[];
for(var i=0;i<this.gadgets.length;i++){
if(this.gadgets[i]&&this.gadgets[i].product_id){
list[i]=this.gadgets[i].product_id;}else {
list[i]="";}
}
return list;};
Screen.prototype.getUniqId=function (){
if(!this.gadgets)return;
var list=[];
for(var i=0;i<this.gadgets.length;i++){
if(this.gadgets[i]&&this.gadgets[i].uniq_id){
list[i]=this.gadgets[i].uniq_id;}else {
list[i]="";}
}
return list;};
Screen.prototype.setTemplateName=function (name){
this._template_name=name;};
Screen.prototype.getTemplateName=function (){
return this._template_name||"default";};
Screen.prototype.canSetOwner=function (){
return true;};
Screen.prototype.setSnapshot=function (bool){
if(bool){
this.snapshot.src=IMG_PATH+"temp_life.png";}else{
this.snapshot.src="";}
if(this.status["activate"]&&(!this.getTVGadget())){
this.pre_window.visible_p=true;}else{
this.pre_window.visible_p=false;}
this.snapshot.visible_p=bool;
this.wall_paper.visible_p=!bool;
if(this.wall_paper.src==DEFAULT_SCREEN_WALLPAPER){
this.wall_bg.visible_p=true;
this.wall_paper.blend=true;
this.wall_paper.color=COL_TEXT_SUB_ONBASE;}else{
this.wall_bg.visible_p=false;
this.wall_paper.blend=false;
this.wall_paper.color=[255,255,255,255];}
this.accessory.visible_p=!bool;
this.status["snapshot"]=bool;};
Screen.prototype.setEditMode=function (bool){
this.status["editmode"]=bool;
this._add_mark.visible_p=bool;
if(bool==true)this._SMAd_destroy();
for(var i=0,max=this.gadgets.length;i<max;i++){
this.gadgets[i].frame_b.visible_p=bool;}
this.screenname_frame.visible_p=bool;
this._do_all_gadgets("setEditMode",[bool]);};
Screen.prototype.setGadgetFrameColor=function (color){
for(var i=0,max=this.gadgets.length;i<max;i++){
var gadget=this.gadgets[i];
var ret=this._do_gadget(gadget,"getStatus");
if(ret["movable"]==true||ret["removable"]==true){
gadget.frame_b.color=color;}
}
force_redraw();};
Screen.prototype.setScreenNameFrameColor=function (color){
this.screenname_frame.color=color;
force_redraw();};
Screen.prototype.moveTo=function (pos,size,angle,speed,func){
var callback=func;
if(pos[0]>-400&&pos[0]<400){
var trans=this.pre_window.translate;
var x=pos[0]+trans[0];
var y=pos[1]+trans[1];
var z=pos[2]+trans[2];
var width=this.pre_window.videoframe.width;
var height=this.pre_window.videoframe.height;
set_pre_videobox(true,x,y,z,width,height);
this._my_df_control(pos);
var zapping_obj=this._getGadgetObject(ZAPPING_GADGET);
try{
var zapping=zapping_obj.gadget;
var mapping=this._mapping;
var id=this.gadgets.indexOf(zapping_obj);
var pos_x=mapping[id].pos_x;
var pos_y=mapping[id].pos_y;
var x=pos[0]+pos_x+zapping.videoframe.translate[0];
var y=pos[1]+pos_y+zapping.videoframe.translate[1];
var z=pos[2]+0;
var isOpen=zapping.isOpenSubVideobox();
zapping.closeSubVideobox();
set_pre_videobox_sub(isOpen,x,y,z,16*21,9*21);
callback=function(){
try{
if(isOpen)zapping.openSubVideobox();
set_pre_videobox_sub(false);}catch(e){};
if(func)func();};}catch(e){
set_pre_videobox_sub(false,0,0,0,16*21,9*21,true);
};}
AnimationLib.moveTo.apply(this,[pos,size,angle,speed,callback]);};
Screen.prototype.moveTo2=function (pos,angle,alpha,max_count,func){
if(pos[0]>-500&&pos[0]<500){
var trans=this.pre_window.translate;
var x=pos[0]+trans[0];
var y=pos[1]+trans[1];
var z=pos[2]+trans[2];
var width=this.pre_window.videoframe.width;
var height=this.pre_window.videoframe.height;
set_pre_videobox(true,x,y,z,width,height);
set_pre_videobox_sub(false,0,0,0,16*21,9*21,true);}else{
var zapping=this._getGadgetObject(ZAPPING_GADGET);
if(zapping&&zapping.gadget&&zapping.gadget.closeSubVideobox){
zapping.gadget.closeSubVideobox();}
}
AnimationLib.moveTo2.apply(this,[pos,angle,alpha,max_count,func]);};
Screen.prototype.rotateTo=function (angle,r,speed,z_margin,end_func){
var obj=this;
var target_angle=angle;
var radius=r;
var rotation=obj.rotation[0];
var vector=(angle-obj.rotation[0]>0)?1:-1;
delete_timer(obj);
var max_count=Math.floor((vector*(angle-obj.rotation[0]))/speed);
append_timer(obj,100,function (obj,count){
if(count==max_count){
delete_timer(obj);
obj.translate[0]=-radius*Math.sin(target_angle*(Math.PI/180));
obj.translate[2]=-radius*Math.cos(target_angle*(Math.PI/180))+z_margin;
obj.rotation[0]=target_angle;
if(end_func){
end_func();}
}else {
obj.translate[0]=-radius*Math.sin((rotation+vector*speed*count)*(Math.PI/180));
obj.translate[2]=-radius*Math.cos((rotation+vector*speed*count)*(Math.PI/180))+z_margin;
obj.rotation[0]+=vector*speed;}
force_redraw();});}
Screen.prototype.removeGadget=function (){
if(!(this.cursor&&this.cursor.gadget))
return false;
var status=this._do_gadget(this.cursor,"getStatus");
if(!status["removable"])
return false;
this._do_gadget(this.cursor,"remove");
this.cursor=this._swap_new_gadget(this.cursor);
force_redraw();
return true;};
Screen.prototype.addGadget=function (uniq_id){
if(!(this.cursor&&this.cursor.gadget))
return false;
if(isString(this.cursor.product_id)||!isString(uniq_id))
return false;
this.cursor=this._swap_new_gadget(this.cursor,uniq_id);
force_redraw();
return true;};
Screen.prototype.swapGadget=function (){
if(!this.cursor||!this.select)return false;
var status=this._do_gadget(this.cursor,"getStatus");
if(!status["movable"]){
this.selectFocusedGadget(false);
return false;}
var src_id=this.cursor.map_id;
var dst_id=this.select.map_id;
if(src_id==dst_id){
this.selectFocusedGadget(false);
return true;}
this._set_focus(false);
this._set_gadget_args(this.cursor,dst_id);
this._set_gadget_args(this.select,src_id);
this.gadgets.splice(src_id,1,this.select);
this.gadgets.splice(dst_id,1,this.cursor);
this.selectFocusedGadget(false);
this.cursor=this.gadgets[src_id];
this._set_focus(true);
var mapping=this._mapping;
this.src_obj=this.gadgets[src_id];
this.src_x=mapping[src_id].pos_x||999,
this.src_y=mapping[src_id].pos_y||-999,
this.src_w=mapping[src_id].width||GADGET_WIDTH;
this.src_h=mapping[src_id].height||GADGET_HEIGHT;
this.dst_obj=this.gadgets[dst_id];
this.dst_x=mapping[dst_id].pos_x||999,
this.dst_y=mapping[dst_id].pos_y||-999,
this.dst_w=mapping[dst_id].width||GADGET_WIDTH;
this.dst_h=mapping[dst_id].height||GADGET_HEIGHT;
this.max_count=8;
this.src_obj.translate=[this.dst_x,this.dst_y,5];
this.dst_obj.translate=[this.src_x,this.src_y,4.5];
var index=this.components.indexOf(this.src_obj);
this.components.splice(index,1);
this._set_gadget_obj(this.src_obj);
var index=this.components.indexOf(this.dst_obj);
this.components.splice(index,1);
this._set_gadget_obj(this.dst_obj);
var index=this.components.indexOf(this.select_focus);
this.components.splice(index,1);
this._set_gadget_obj(this.select_focus);
this.end_func=function(obj){
obj.status["animation"]=false;
obj.end_func=null;}
this.status["animation"]=true;
if(!this._swap_timer)
this._swap_timer={parent:this};
append_timer(this._swap_timer,80,this._swap_anim);
return true;};
Screen.prototype.getFocusedGadgetStatus=function (){
var ret=this._do_gadget(this.cursor,"getStatus");
if(!ret)return;
var map_id=this.cursor.map_id;
if(map_id<0)return;
var mapping=this._mapping;
var addable=!isString(this.cursor.product_id);
var status={"addable":addable,"movable":ret["movable"],"removable":ret["removable"]}
status["translate"]=[mapping[map_id].pos_x||0,mapping[map_id].pos_y||0,0];
return status;};
Screen.prototype.getFocusedProductId=function (){
if(!this.cursor)return null;
if(!isString(this.cursor.product_id))
return null;
return this.cursor.product_id;};
Screen.prototype.getFocusedUniqId=function (){
if(!this.cursor)return null;
if(!isString(this.cursor.uniq_id))
return null;
return this.cursor.uniq_id;};
Screen.prototype.selectFocusedGadget=function (bool){
if(!this.cursor)return false;
if(bool){
var status=this._do_gadget(this.cursor,"getStatus");
if(!status["movable"])
return false;
this.select=this.cursor;
var mapping=this._mapping;
var map_id=this.cursor.map_id;
this.select_focus.setSize(mapping[map_id].width+11,mapping[map_id].height+11);
this.select_focus.setTranslate(mapping[map_id].pos_x,mapping[map_id].pos_y,2);}else{
this.select=null;}
this.select_focus.setShow(bool);
force_redraw();
return true;};
Screen.prototype.getScreenInfo=function (){
var info=[];
for(var i=0;i<this.gadgets.length;i++)
info.push(this.gadgets[i].product_id||null);
return info;};
Screen.prototype.launchTVPlayer=function (){
var tv=this._getGadgetObject(TV_GADGET);
if(tv){
var screen_obj=this;
this.status["launching"]=true;
this.cursor=tv;
this._launch_fullscreen_appli(tv,function(){
screen_obj.status["launching"]=false;});}
};
Screen.prototype.launchTV=function (bool){
var screen_obj=this;
var target=this._getGadgetObject(TV_GADGET);
if(target){
this.status["launching"]=bool;
if(bool){
this.status["guidanceTV"]=true;
this._launch_fullscreen_appli_for_guide(target,function(){
screen_obj.status["launching"]=false;});}else{
if(this.status["guidanceTV"]){
this._do_gadget(this.cursor,"onFocus",[false]);
if(system.mdl_cfg.with_bp_transit_effect){
HOME.setVisibilityForTransit("resume");
var id=this.gadgets.indexOf(target);
if(id!=-1){
var orig_x=this._mapping[id].pos_x;
var orig_y=this._mapping[id].pos_y;
var width=this._mapping[id].width;
var height=this._mapping[id].height;
target.translate=[orig_x,orig_y,0];
this._do_gadget(target,"setSize",[width,height]);
this.requestFocus(target.translate,[width,height],null,9999,null);
set_pre_videobox(false);
for(var i=0;i<this.gadgets.length;i++){
var gadget_obj=this.gadgets[i];
this._do_gadget(gadget_obj,"activate",[true]);};}
this.transitReturnHOME();}else{
this._reset_fullscreen_appli(target);}
}
this.status["guidanceTV"]=false;
this.cursor=target;
this._do_gadget(target,"onFocus",[true]);
this.reset();}
}
};
Screen.prototype.launchTVWithAnim=function (){
var tv=this._getGadgetObject(TV_GADGET);
if(tv){
var screen_obj=this;
this.status["launching"]=true;
this.cursor=tv;
this._launch_fullscreen_appli(tv,function(){
screen_obj.status["launching"]=false;
system.screensaver.reset_brightness();
system.screensaver.show_message();});}
};
Screen.prototype.setEdgeMask=function (bool){
this._set_mask(bool);}
Screen.prototype.createGadgets=function (list_of_uniq_id,is_force){
if(!isActiveStatus()&&!is_force)return;
if(this.gadgets.length>0)return;
this.gadgets=[];
if(!list_of_uniq_id)
list_of_uniq_id=this.init_list_of_uniq_id;
if(!list_of_uniq_id)return;
this.status["destroy"]=false;
var mapping=this._mapping;
for(var i=0;i<list_of_uniq_id.length&&i<mapping.length;i++){
if(list_of_uniq_id[i]&&list_of_uniq_id[i]!=""){
var gadget_obj=this._create_a_gadget(list_of_uniq_id[i]);
this.gadgets[i]=gadget_obj;}
}
this._apply_map();
for(var i=0,max=this.gadgets.length;i<max;i++){
if(this.gadgets[i].frame_b){
this.gadgets[i].frame_b.visible_p=false;}
}
this.cursor=this.gadgets[0];};
Screen.prototype.destroyGadgets=function (){
this._do_all_gadgets("destroy");
this._SMAd_destroy();
this.status["destroy"]=true;
var len=this.gadgets.length;
for(var i=0;i<len;i++){
var id=this.components.indexOf(this.gadgets[i]);
if(id!=-1)this.components.splice(id,1);}
this.gadgets=[];
if(this.status["activate"]&&(!this.getTVGadget())){
this.pre_window.visible_p=true;}else{
this.pre_window.visible_p=false;}
};
Screen.prototype.setScreenStatus=function(attr){
for(var prop in attr)this.status[prop]=attr[prop];};
Screen.prototype.getScreenStatus=function(){
return this.status||null;};
Screen.prototype.setWallPaper=function(bin){
var prop="src";
if(!isActiveStatus())
prop="org_src";
if(!bin)bin=DEFAULT_SCREEN_WALLPAPER;
if(bin==DEFAULT_SCREEN_WALLPAPER){
this.wall_bg.visible_p=true;
this.wall_paper.blend=true;
this.wall_paper.color=COL_TEXT_SUB_ONBASE;}else{
this.wall_bg.visible_p=false;
this.wall_paper.blend=false;
this.wall_paper.color=[255,255,255,255];}
if(this.wall_paper[prop]!=bin){
this.wall_paper[prop]=bin;};};
Screen.prototype.freeResource=function(bool){
if(this.status["freeResource"]==bool)return;
gimageResource(this.wall_paper,bool);
gimageResource(this.upper_mask,bool);
gimageResource(this.under_mask,bool);
gimageResource(this._add_mark,bool);
gtextResource(this.screenname_plate,bool);
for(var i=0;i<this.gadgets.length;i++){
if(this.gadgets[i]){
if(this.gadgets[i].frame_l)
gimageResource(this.gadgets[i].frame_l,bool);
if(this.gadgets[i].frame_m)
gimageResource(this.gadgets[i].frame_m,bool);
if(this.gadgets[i].frame_r)
gimageResource(this.gadgets[i].frame_r,bool);}
}
this._do_all_gadgets("freeResource",[bool]);
this.status["freeResource"]=bool;};
Screen.prototype.resetFullscreenAppli=function(obj){
return this._reset_fullscreen_appli(obj);};
Screen.prototype.transitReturnHOME=function(){
this._my_transit_return_HOME();};
Screen.prototype.requestConfirmPanel=function (confirmData){
this.status["confirm"]=true;
this._SMAd_destroy();
if(!confirmData||!confirmData.button)return;
var id=this.components.indexOf(this.confirm);
if(id!=-1)this.components.splice(id,1);
var len=confirmData.button.length;
if(len<1)return;
var type=len-1;
var buttons=[];
for(var i=0;i<len;i++){
var action_func=function(){
var action=confirmData.button[i].action;
return function(){
me.cancelRequestConfirmPanel();
if(action)action();}};
buttons.push(action_func());}
var labels=[];
for(var i=0;i<len;i++){
var tmp_label=confirmData.button[i].label;
var label=isString(tmp_label)?tmp_label:"";
labels.push(label);}
var me=this;
var focus=function(translate,size,angle,speed,func){
if(!me.requestFocus)return;
translate[2]+=1.0;
me.requestFocus(translate,size,angle,speed,func);};
this.confirm=new container({translate:[0,0,1.0]});
this.confirm.mask=new gbox({width:1920+10,height:1080+10,color:[0,0,0,128]});
this.confirm.panel=new Confirmpanel(type,buttons,focus);
this.confirm.point_hook=function (type,id,x,y,screenX,screenY){
return this.panel.point_hook(type,id,x,y,screenX,screenY);};
this.confirm.key_hook=function(up_down,key){
if(!(confirmData.cancel&&up_down==KEY_PRESS&&key==TXK_RETURN))
if(this.panel.key_hook(up_down,key))
return true;
if(up_down!=KEY_PRESS)
return false;
switch(key){
case TXK_UP:
case TXK_DOWN:
case TXK_LEFT:
case TXK_RIGHT:
case TXK_RED:
case TXK_YELLOW:
case TXK_GREEN:
case TXK_BLUE:
return true;
default:
if(confirmData.cancel){
me.cancelRequestConfirmPanel();
confirmData.cancel();
return true;}
}
return false;}
this.confirm.components.push(this.confirm.mask,this.confirm.panel);
var panel=this.confirm.panel;
panel.setTitle(isString(confirmData.title)?confirmData.title:"");
panel.setMessageText(isString(confirmData.msg)?confirmData.msg:"");
panel.setButtonLabel.apply(panel,labels);
panel.setTranslate(0,0,0);
panel.setSize(1080,420);
panel.setShow(true);
panel.onFocus(true);
this.components.push(this.confirm);
this.confirm.last_cursor=this.cursor;
this.cursor=this.confirm;};
Screen.prototype.cancelRequestConfirmPanel=function (){
if(!this.status["confirm"])return;
this.status["confirm"]=false;
var id=this.components.indexOf(this.confirm);
if(id!=-1)this.components.splice(id,1);
this.cursor=this.confirm.last_cursor||this.gadgets[0];
this.confirm.last_cursor=null;
this._do_gadget(this.cursor,"onFocus",[true]);};
Screen.prototype.reportError=function (errcode){
this.status["error"]=true;
var confirmData={
"title":"",
"msg":"",
"cancel":null,
"button":[
{"label":LANG("LT_PM_RETURN"),"action":null}
]
};

var msg="";
switch(errcode){
case "NETWORK ERROR":
msg=LANG("LT_NETWORK_CONNECTION_MSG1");
break;
case "LT_APPS_PREPARE_MESSAGE":
msg=LANG("LT_APPS_PREPARE_MESSAGE");
break;
default:
if(isString(errcode))
msg=errcode;
break;}
var me=this;
confirmData.cancel=function(){
me.cancelReportError();};
confirmData.msg=msg;
confirmData.button[0].action=function(){
me.cancelReportError();};
this.requestConfirmPanel(confirmData);};
Screen.prototype.cancelReportError=function (){
this.status["error"]=false;
this.cancelRequestConfirmPanel();};
Screen.prototype.reportNotice=function (){
if(is_available_guidance())return;
var notice=startup_screen.isScreenNoticeMessage(this.getScreenKey());
if(!notice)return false;
var msg=startup_screen.getScreenNoticeMessage(this.getScreenKey());
if(!msg||!isString(msg))return false;
var me=this;
var confirmData={
"title":"",
"msg":msg,
"cancel":function(){
me.cancelReportNotice();},
"button":[
{"label":LANG("LT_PM_RETURN"),"action":null}
]
};
confirmData.button[0].action=confirmData.cancel;
this.status["notice"]=true;
this.requestConfirmPanel(confirmData);
append_timer(this.confirm,1,function(obj){
delete_timer(obj);
if(me.status["confirm"])
obj.panel.onFocus(true);});
return true;};
Screen.prototype.cancelReportNotice=function (){
this.status["notice"]=false;
this.cancelRequestConfirmPanel();};
Screen.prototype.getMoveStatus=function(){
if(this.status["animation"]){
return true;}else {
return false;}
};
Screen.prototype.getUnlockStatus=function(){
if(this.status["unlock"]){
return true;}else {
return false;}
};
Screen.prototype.uninstallGadgets=function (ids){
if(!this.gadgets)return;
if(!ids||ids.length<=0)return;
var len=this.gadgets.length;
for(var i=0;i<len;i++){
var gadget_obj=this.gadgets[i];
if(gadget_obj&&gadget_obj.product_id){
if((ids.indexOf(gadget_obj.product_id)==-1)
&&(!this.$isDebugGadget(gadget_obj.product_id))
&&(gadget_obj.product_id!=TV_GADGET)
&&(gadget_obj.product_id!=ZAPPING_GADGET)
&&(gadget_obj.product_id!=APPS_GADGET)
&&(gadget_obj.product_id!=BOOKMARK_GADGET)
&&(gadget_obj.product_id!=SIGNAGELINK_GADGET)
&&(gadget_obj.product_id!=WEBLINK_GADGET)){
this._do_gadget(gadget_obj,"remove");
this._do_gadget(gadget_obj,"vanish");
var map_id=gadget_obj.map_id;
var id=this.components.indexOf(gadget_obj);
if(map_id<0||id==-1)
return;
var new_gadget=this._create_a_gadget();
this._set_frame(new_gadget,map_id);
this._set_gadget_args(new_gadget,map_id);
this.gadgets.splice(map_id,1,new_gadget);
this.components.splice(id,1,new_gadget);
if(this.cursor===gadget_obj){
this.cursor=new_gadget;}
}
}
}
};
Screen.prototype.updateGadget=function (){
if(!this.gadgets)return;
var len=this.gadgets.length;
for(var i=0;i<len;i++){
var ret=this._do_gadget(this.gadgets[i],"isInstaller");
if(!ret)continue;
var old=this.gadgets[i];
var id=this.components.indexOf(old);
var new_gadget=this._create_a_gadget(old.uniq_id);
this._set_frame(new_gadget,old.map_id);
this._set_gadget_args(new_gadget,old.map_id);
var tmp=this.gadgets.splice(old.map_id,1,new_gadget);
this.components.splice(id,1,new_gadget);
if(this.cursor.map_id==old.map_id){
this.cursor=new_gadget;}
}
};
Screen.prototype.removeAll=function (){
if(!this.gadgets)return;
this._do_all_gadgets("remove");};
Screen.prototype.getTVGadgetObject=function (){
return this._getGadgetObject(TV_GADGET);};
Screen.prototype.getTVGadget=function (){
var gadget_obj=this._getGadgetObject(TV_GADGET);
if(gadget_obj)
return gadget_obj.gadget;
return null;};
Screen.prototype.getGadgets=function (){
return this.gadgets||[];};
Screen.prototype.getGadgetData=function (){
if(!this.gadgets)return [];
var rval=[];
for(var i=0;i<this.gadgets.length;i++)
rval[i]=this._do_gadget(this.gadgets[i],"getGadgetData");
return rval;};
Screen.prototype.isTVGadget=function(){
if(this.cursor&&this.cursor.product_id==TV_GADGET)
return true;
return false;};
Screen.prototype.focusNoTVGadget=function(){
if(!this.gadgets)return;
var len=this.gadgets.length;
for(var i=0;i<len;i++){
var target=this.gadgets[i];
if(target&&target.product_id!=TV_GADGET){
this.cursor=target;
break;}
}
};
Screen.prototype.$setDebugGadgetList=function(list){
if(!list)return;
this.__debugGadgetList=list;};
Screen.prototype.$getDebugGadgetList=function(){
return this.__debugGadgetList;};
Screen.prototype.$isDebugGadget=function(pid){
if(this.__debugGadgetList&&this.__debugGadgetList[pid])
return true;
return false;};
Screen.prototype._animation_timer={};
Screen.prototype._results=false;
Screen.prototype._start_animation=function (owner,count){
var me=owner;
var interval=ANIM_INTERVAL;
if((interval*count)%10000==0){
if(!checkNetworkAvailable("net"))judgeNetworkAvailable("net");
if(!checkNetworkAvailable("power"))judgeNetworkAvailable("power");
if(!checkNetworkAvailable("clock"))judgeNetworkAvailable("clock");}
if(!me._animation_timer)me._animation_timer={};
append_timer(me._animation_timer,interval,function(obj){
delete_timer(obj);
var ret=false;
if(!me.gadgets)return;
var len=me.gadgets.length;
for(var i=0;i<len;i++){
if(me._SMAd_status()&&me._SMAd_block&&me._SMAd_block.indexOf(i)!=-1)continue;
var gadget_obj=me.gadgets[i];
ret|=me._do_gadget(gadget_obj,"animation",[count]);}
ret|=me._do_SMAd("animation",[count]);
if(ret>0)me._results|=true;
if(me._results){
if(!SU_IS_SLOW_ANIM||(SU_IS_SLOW_ANIM&&count%2==0)){
force_redraw();
me._results=false;}
}
me._start_animation(me,(count+1)%300);});};
Screen.prototype._stop_animation=function (owner){
if(!owner._animation_timer)return;
delete_timer(owner._animation_timer);};
Screen.prototype._set_mask=function (bool){
this.upper_mask.visible_p=bool;
this.under_mask.visible_p=bool;};
Screen.prototype._do_gadget=function (gadget_obj,method,arg_array){
try{
var ret_val=false;
if(!gadget_obj)return ret_val;
var gadget=gadget_obj.gadget;
var owner=gadget_obj.gadget;
if(isString(method)&&method.substr(0,9)=="prototype"){
gadget=Gadget.prototype;
method=method.substr(10);}
if(owner&&gadget&&gadget[method] instanceof Function){
try{
ret_val=gadget[method].apply(owner,arg_array);}catch(e){
var dlog="[Gadget]["+gadget_obj.product_id+"] ";
dlog+=method+" method Error. line "+(e.lineNumber-DEBUG_TOP)+": ";
dlog+=e.name+": "+e.message;
console.log(dlog);}
};}catch(e){
console.log("[Error] "+e.message+"\n"+Error().stack);}
return ret_val;};
Screen.prototype._do_all_gadgets=function (method,arg_array){
var ret_val=false;
for(var i=0;i<this.gadgets.length;i++){
var gadget_obj=this.gadgets[i];
var ret=this._do_gadget(gadget_obj,method,arg_array);
ret_val|=ret;};
return ret_val;};
Screen.prototype._evaluate_a_gadget=function (gadget_obj,body){
var gadget,PRODUCT_ID;
try{
PRODUCT_ID="var PRODUCT_ID='"+gadget_obj.product_id+"';";
DEBUG_TOP=Error().lineNumber;
gadget=eval("(function(){"+PRODUCT_ID+PROTECT_GADGET+body+"})();");}catch(e){
var dlog="[Gadget]["+gadget_obj.product_id+"] ";
dlog+="Eval Error. line "+(e.lineNumber-DEBUG_TOP)+": ";
dlog+=e.name+": "+e.message;
console.log(dlog);}
if(!(gadget instanceof Gadget))
gadget=new Gadget();
if(!isString(gadget_obj.product_id)&&this.status["editable"]!==false){
gadget_obj.components.push(this._add_mark);}

gadget_obj.gadget=gadget;
gadget_obj.components.push(gadget);
if(!isString(gadget_obj.product_id)&&this.status["editable"]===false)
gadget.launchApl=NULL_FUNCTION;
var screen_obj=this;
function make_focus_func(){
var closure_obj=gadget_obj;var focus_func=function(translate,size,angle,speed,func){
var trans=[];
for(var i=0;i<3;i++){
trans.push(screen_obj.translate[i]+closure_obj.translate[i]+translate[i]);}
var width=size[0]+4;
var height=size[1]+4;
screen_obj.requestFocus(trans,[width,height],angle,speed,func);};
return focus_func;};
function make_reporterror_func(){
var closure_obj=gadget_obj;var reportError=function(msg){
screen_obj.status["launching"]=false;
screen_obj.reportError(msg);};
return reportError;};
function make_requestConfirmPanel_func(){
var closure_obj=gadget_obj;var requestConfirmPanel=function(confirmData){
screen_obj.status["launching"]=false;
screen_obj.requestConfirmPanel(confirmData);};
return requestConfirmPanel;};
function make_read_product_data_func(){
var closure_obj=gadget_obj;var screen_key=screen_obj.getScreenKey();
if(!isDLScreen(screen_key))
return NULL_FUNCTION;
var screen_install_id=getScreenInstallId(screen_key);
var read_product_data=function(){
var rval=null;
try{
rval=screen_nvram_file.read({screen_id:screen_install_id,filename:"data/"+closure_obj.uniq_id});
rval=sysutil.tconv.binary_to_string(rval);}catch(e){}
return rval;};
return read_product_data;};
function make_launch_func(){
var closure_obj=gadget_obj;var launch=function(){
screen_obj.launchTargetGadget(closure_obj);};
return launch;};
function make_sendBroadcast_func(){
var closure_obj=gadget_obj;var broadcast=function(msg){
if(isString(msg)||isNumber(msg)||msg==null){
var args=["BROADCAST",closure_obj.product_id,closure_obj.uniq_id,msg];
screen_obj._do_all_gadgets("broadcastReceiver",args);}
};
return broadcast;};
gadget.setFocusFunc(make_focus_func());
gadget.setReportErrorFunc(make_reporterror_func());
gadget.setRequestConfirmPanelFunc(make_requestConfirmPanel_func());
gadget.setReadProductDataFunc(make_read_product_data_func());
gadget.setLaunchMyselfFunc(make_launch_func());
gadget.setSendBroadcastFunc(make_sendBroadcast_func());
var size=gadget_obj.getMySize();
var map=[];
var mapping=this._mapping;
var id=gadget_obj.map_id;
if(id>=0&&mapping[id])
map=[mapping[id].map_w,mapping[id].map_h];
screen_obj._do_gadget(gadget_obj,"prototype.setProductId",[gadget_obj.product_id]);
screen_obj._do_gadget(gadget_obj,"prototype.setUniqId",[gadget_obj.uniq_id]);
screen_obj._do_gadget(gadget_obj,"setProductId",[gadget_obj.product_id]);
screen_obj._do_gadget(gadget_obj,"setUniqId",[gadget_obj.uniq_id]);
if(size)screen_obj._do_gadget(gadget_obj,"prototype.setSize",size);
if(map)screen_obj._do_gadget(gadget_obj,"prototype.setMapSize",map);
screen_obj._do_gadget(gadget_obj,"init");
if(!screen_obj._do_gadget(gadget_obj,"isUseFrame"))
gadget_obj.frame.visible_p=false;
if(size)screen_obj._do_gadget(gadget_obj,"setSize",size);
if(map)screen_obj._do_gadget(gadget_obj,"setMapSize",map);
if(gadget_obj.product_id==TV_GADGET){
gadget_obj.gadget.del_pre_window=function(){
screen_obj.pre_window.visible_p=false;};}
var status=screen_obj.status;
screen_obj._do_gadget(gadget_obj,"setShow",[status["setShow"]]);
screen_obj._do_gadget(gadget_obj,"setFullscreen",[status["fullscreen"]]);
screen_obj._do_gadget(gadget_obj,"activate",[status["activate"]]);
if(!this.status["editmode"]){
screen_obj._do_gadget(gadget_obj,"onFocus",[gadget_obj.status["onFocus"]]);}
if(status["onFocus"]==true&&screen_obj.cursor==gadget_obj){
screen_obj._do_gadget(gadget_obj,"onFocus",[true]);
gadget_obj.status["onFocus"]=true;}
if(status["destroy"]==true){
screen_obj._do_gadget(gadget_obj,"destroy");
screen_obj._SMAd_destroy();}

this._setLockedgadget(gadget_obj);
force_redraw();};
Screen.prototype._load_gadget_lst=[];
Screen.prototype._load_gadget_req=function(req){
this._load_gadget_lst.push(req);
if(!this._load_gadget_isActive)this._load_gadget_next();};
Screen.prototype._load_gadget_next=function(){
if(this._load_gadget_lst.length<=0){
this._load_gadget_isActive=false;
return;}
this._load_gadget_isActive=true;
var me=this;
var req=this._load_gadget_lst.shift();
http_request({url:req.url||"",
onload:function(status,header,body){
if(status!=200){
body=null;}
req.callback(body);
me._load_gadget_next();}});};
Screen.prototype._load_gadget_clear=function(){
this._load_gadget_lst=[];};
Screen.prototype._create_a_gadget=function (uniq_id){
var screen_obj=this;
var gadget;
var gadget_obj=new container({});
var product_id=(!uniq_id)?null:uniq_id.substr(0,16);
gadget_obj.status={};
gadget_obj.status["onFocus"]=false;
gadget_obj.setMySize=function(w,h){
if(this.gadget){
screen_obj._do_gadget(this,"setSize",[w,h]);}else{
this._size=[w,h];}
};
gadget_obj.getMySize=function(){
return this._size||null;};
var request={
url:APPLI_PATH+product_id+"/gadget/gadget.js",
callback:function(body){
screen_obj._evaluate_a_gadget(gadget_obj,body);}};
if(this.$isDebugGadget(product_id)){
var debuglist=this.$getDebugGadgetList();
request.url=debuglist[product_id]+"/gadget/gadget.js";}
try{
if(!isString(product_id))
throw "create empty gadget";

gadget_obj.product_id=product_id;
gadget_obj.uniq_id=uniq_id;
var exist=apps_nvram_file.apps_exist({product_id:product_id,filename:"gadget/gadget.js"});
if(!exist)
throw "create default gadget";
screen_obj._load_gadget_req(request);}catch(e){
screen_obj._evaluate_a_gadget(gadget_obj,null);}
return gadget_obj;};
Screen.prototype._create_map=function (map){
if(!map)return;
var num_of_x=map[0].length;
var num_of_y=map.length;
var mapping=[];
for(var yy=0;yy<num_of_y;yy++){
for(var xx=0;xx<num_of_x;xx++){
var width=1;
var height=1;
for(var i=xx+1;i<num_of_x;i++){
if(map[yy][xx]==map[yy][i])width++;}
for(var i=yy+1;i<num_of_y;i++){
if(map[yy][xx]==map[i][xx])height++;}
if(!mapping[map[yy][xx]]){
var w=width*(412+32)-32;
var h=height*(232+18)-18;
var x=((xx*(412+32)-32)+412/2-1920/2+w/2)-88;
var y=-((yy*(232+18)+18)+232/2-1080/2+h/2)+62;
mapping[map[yy][xx]]={"map_x":xx,"map_y":yy,
"pos_x":x,"pos_y":y,
"width":w,"height":h,
"map_w":width,"map_h":height};}
}
}
this._map=map;
this._mapping=mapping;};
Screen.prototype._apply_map=function (){
if(!this._map)return;
var map=this._map;
var mapping=this._mapping;
for(var id=0;id<mapping.length;id++){
if(!this.gadgets[id]){
this.gadgets[id]=this._create_a_gadget();}
this._set_frame(this.gadgets[id],id);
this._set_gadget_args(this.gadgets[id],id);
this._set_gadget_obj(this.gadgets[id]);}
var list=[
this.screenname_frame,
this.screenname_plate,
this.select_focus,
this._SMAd_obj,
];
for(var i=0;i<list.length;i++){
var index=this.components.indexOf(list[i]);
if(index!=-1){
this.components.splice(index,1);}
if(list[i]){
this.components.push(list[i]);}
}
this._gadget_position=list[0];};
Screen.prototype._set_gadget_obj=function (gadget_obj){
var id=this.components.indexOf(this._gadget_position);
if(id==-1||!this._gadget_position){
this.components.push(gadget_obj);}else{
this.components.splice(id,0,gadget_obj);}
};
Screen.prototype._pre_tv=function (list_of_uniq_id){
if(!list_of_uniq_id){
list_of_uniq_id=[TV_GADGET+"0000"];
this.init_list_of_uniq_id=list_of_uniq_id;}
var id=-1;
for(var i=0;i<list_of_uniq_id.length;i++){
if(list_of_uniq_id[i]&&list_of_uniq_id[i].substr(0,16)==TV_GADGET){
id=i;
break;}
}
if(id==-1)
return;
var mapping=this._mapping;
this.pre_window=new container({});
this.pre_window.videoframe=new videobox({color:[0,0,0,0],overscan:true});
var pre_window_obj=this._getPreWindowSize(this._mapping,id);
this.pre_window.translate=pre_window_obj.translate;
this.pre_window.videoframe.width=pre_window_obj.width;
this.pre_window.videoframe.height=pre_window_obj.height;
this.pre_window.components.push(this.pre_window.videoframe);
this.components=[this.pre_window];};
Screen.prototype._getModifiedTVInfo=function (w,h){
var aw=(w-TVINFO_HEIGHT*16/9)/16;
var ah=(h-TVINFO_HEIGHT)/9;
var tv_width,tv_height;
if(aw<ah){
tv_width=Math.floor(w-TVINFO_HEIGHT*16/9);
tv_height=Math.floor(aw*9);}else{
tv_width=Math.floor(ah*16);
tv_height=h-TVINFO_HEIGHT;}
return {"x":0,"y":Math.floor(TVINFO_HEIGHT/2)+2,
"width":tv_width,"height":tv_height};}
Screen.prototype._getPreWindowSize=function (mapping,map_id){
if(SHOW_TVINFO&&(this.getTemplateName()!="tv")){
var size=this._getModifiedTVInfo(mapping[map_id].width,mapping[map_id].height);
return {translate:[mapping[map_id].pos_x+size.x,mapping[map_id].pos_y+size.y,0],
width:size.width,height:size.height,};}else {
var w=mapping[map_id].width;
var h=mapping[map_id].height;
var a=Math.floor(mapping[map_id].width/16*9);
if(a<h){
h=a;}else{
w=Math.floor(h*16/9);}
return {translate:[mapping[map_id].pos_x,mapping[map_id].pos_y,0],
width:w,height:h,};}
}
Screen.prototype._getTransitParam=function (mapping,map_id){
if(SHOW_TVINFO){
var size=this._getModifiedTVInfo(mapping[map_id].width,mapping[map_id].height);
return {x:mapping[map_id].pos_x+size.x,y:mapping[map_id].pos_y+size.y,
width:size.width,height:size.height,};}else {
var w=mapping[map_id].width;
var h=mapping[map_id].height;
var a=Math.floor(mapping[map_id].width*9/16);
if(a<h){
h=a;}else{
w=Math.floor(h*16/9);}
return {x:mapping[map_id].pos_x,y:mapping[map_id].pos_y,
width:w,height:h,};}
}
Screen.prototype._set_gadget_args=function (gadget,id){
var mapping=this._mapping;
var map_w=mapping[id].map_w;
var map_h=mapping[id].map_h;
var height=mapping[id].height;
var width=mapping[id].width;
if(gadget.product_id==TV_GADGET){
var min=(map_w>map_h)?map_h:map_w;
width=min*(412+32)-32;
height=min*(232+18)-18;
if(min<4){
gadget.frame_l.src=IMG_PATH+GADGET_FRAME_L[min-1];
gadget.frame_m.src=IMG_PATH+GADGET_FRAME_M[min-1];
gadget.frame_r.src=IMG_PATH+GADGET_FRAME_R[min-1];}
}
gadget.frame_m.width=width-22;
gadget.frame_l.height=height+10+10;
gadget.frame_m.height=height+10+10;
gadget.frame_r.height=height+10+10;
gadget.frame_l.translate[0]=-width/2;
gadget.frame_m.translate[0]=0;
gadget.frame_r.translate[0]=width/2;
gadget.frame_b.width=width+12;
gadget.frame_b.height=height+12;
gadget.frame_b.translate[0]=0;
gadget.translate=[mapping[id].pos_x,mapping[id].pos_y,0];
gadget.map_id=id;
gadget.setMySize(width,height);
if(this._SMAd_block){
var len=this._SMAd_block.length;
for(var i=0;i<len;i++){
var id=this._SMAd_block[i];
try{
this.gadgets[id].visible_p=false;}catch(e){};}
}
};
Screen.prototype._set_frame=function (gadget_obj,id){
var mapping=this._mapping;
var map_w=mapping[id].map_w;
var map_h=mapping[id].map_h;
var map_size=map_w+"x"+map_h;
var img={"FRAME_L":IMG_PATH+GADGET_FRAME_L[map_h-1],
"FRAME_M":IMG_PATH+GADGET_FRAME_M[map_h-1],
"FRAME_R":IMG_PATH+GADGET_FRAME_R[map_h-1]};
if(gadget_obj.product_id==TV_GADGET){
img={"FRAME_L":"","FRAME_M":"","FRAME_R":""};}

gadget_obj.frame=new container({translate:[0,0,-0.8],components:[
gadget_obj.frame_l=new gimage({src:img.FRAME_L,draw_type:DIRECT,width:22}),
gadget_obj.frame_m=new gimage({src:img.FRAME_M,draw_type:DIRECT}),
gadget_obj.frame_r=new gimage({src:img.FRAME_R,draw_type:DIRECT,width:22}),
]});
gadget_obj.frame_b=new gbox({translate:[0,0,-0.8],color:[0,0,0,0],});
if(!gadget_obj.product_id)
gadget_obj.frame.visible_p=false;
gadget_obj.components.unshift(gadget_obj.frame_b,gadget_obj.frame);
return;};
Screen.prototype._search_map=function(keysym){
if(!this.cursor)return;
var gadget=this.cursor.gadget;
var map_id=this.cursor.map_id;
var mapping=this._mapping[map_id];
var map=this._map;
var num_of_x=map[0].length;
var num_of_y=map.length;
var next_id=NaN;
switch(keysym){
case TXK_UP:
for(var i=mapping["map_y"]-1;i>=0;i--){
if(map[i][mapping["map_x"]]!=map_id){
next_id=map[i][mapping["map_x"]];
break;}
}
break;
case TXK_DOWN:
for(var i=mapping["map_y"]+1;i<num_of_y;i++){
if(map[i][mapping["map_x"]]!=map_id){
next_id=map[i][mapping["map_x"]];
break;}
}
break;
case TXK_LEFT:
for(var i=mapping["map_x"]-1;i>=0;i--){
if(map[mapping["map_y"]][i]!=map_id){
next_id=map[mapping["map_y"]][i];
break;}
}
break;
case TXK_RIGHT:
for(var i=mapping["map_x"]+1;i<num_of_x;i++){
if(map[mapping["map_y"]][i]!=map_id){
next_id=map[mapping["map_y"]][i];
break;}
}
break;
default:
break;}
return (isNumber(next_id))?next_id:NaN;};
Screen.prototype._create=function(){
var screen_obj=this;
var prop="src";
if(!isActiveStatus())
prop="org_src";
this.border=new gbox({translate:[0,0,-2],width:1920+8+4,height:1080+7+4,
color:COL_BORDER_ONBASE,blend:false});
this.wall_bg=new gbox({translate:[0,0,-1.8],width:1920+2,height:1080+2,
color:COL_BASE,blend:false,visible_p:false});
this.wall_paper=new gimage({translate:[0,0,-1.5],draw_type:DIRECT,
visible_p:false,
width:1920+2,height:1080+2,blend:false});
this.accessory=new container({translate:[0,0,-1.4],visible_p:false});
this.snapshot=new gimage({translate:[0,0,-1.2],draw_type:DIRECT,
visible_p:true,
width:1920+1,height:1080+1,blend:false});
this.upper_mask=new gimage({width:1920+4,height:20,color:COL_BORDER_ONBASE,
translate:[0,1080*0.5,1.0],rotation:[0,0,1,0],
draw_type:DIRECT,visible_p:false,});
this.upper_mask[prop]=IMG_PATH+"edge_mask.png";
this.under_mask=new gimage({width:1920+4,height:20,color:COL_BORDER_ONBASE,
translate:[0,-1080*0.5,1.0],rotation:[0,0,1,0],
draw_type:DIRECT,visible_p:false,});
this.under_mask[prop]=IMG_PATH+"edge_mask.png";
this.select_focus=new Focus({color:[255,40,40,255],bold:true});
this.select_focus.setShow(false);

this.wall_paper.onerror=function(){
launch_appli("self_launch","HOME");
screen_obj.setWallPaper();
if(!isVisibleStatus())
setVisibleStatus(true);
force_redraw();};
this.wall_paper.onload=function(){
launch_appli("self_launch","HOME");
HOME.cache_wallpaper=null;
if(!isVisibleStatus())
setVisibleStatus(true);
force_redraw();};
var x=-32*1.5-412*2+460*0.5;
var y=1080/2+-48/2-8;
var y2=1080/2+100;
this.screenname_plate=new gtext({translate:[x,y,0],
color:COL_TEXT_ONBASE,
font_size:40,
width:460,height:48,omitter:"...",});
this.screenname_frame=new gbox({translate:[x,y-3,0],
width:500,height:56,color:[0,0,0,0],});
this.components.unshift(this.upper_mask,this.under_mask);
this.components.unshift(this.select_focus);
this.components.unshift(this.snapshot,this.accessory,this.wall_paper);
this.components.unshift(this.border,this.wall_bg);
if(!SU_SUPPORT_MYHOMESCREEN){
this.screenname_plate.translate[1]+=1080;
this.screenname_frame.translate[1]+=1080;
this.setScreenNameShow(false);}
};
Screen.prototype._launch_timer={};
Screen.prototype._launch_fullscreen_appli=function(target,func){
if(!this.gadgets)return;
for(var i=0;i<this.gadgets.length;i++){
var gadget_obj=this.gadgets[i];
if(gadget_obj.product_id!=target.product_id)
this._do_gadget(gadget_obj,"activate",[false]);};
if(system.mdl_cfg.with_bp_transit_effect){
this._my_launch_with_transit_effect(target,func);}else{
this._my_launch_with_timer_effect(target,func);}
};
Screen.prototype._launch_anim=function(target,locked_panel,func){
var id=this.gadgets.indexOf(target);
var product_id=target.product_id||null;
var orig_x=this._mapping[id].pos_x;
var orig_y=this._mapping[id].pos_y;
var width=this._mapping[id].width;
var height=this._mapping[id].height;
var w=width;
var h=height;
var report=this._collectAccessReportInfo(target);
var ret=this._do_gadget(target,"launchApl",[locked_panel,report]);
if(ret==apputil.CODE.LOCKED){
this._showPasswordPanel(true);
if(func)func();
return true;}
if(ret<0){
this._reset_fullscreen_appli(target);
this.activate(true);
force_redraw();}
if(func)func();
return;};
Screen.prototype._launch_fullscreen_appli_for_guide=function(target,func){
var id=this.gadgets.indexOf(target);

var transit_param=this._getTransitParam(this._mapping,id);
var orig_x=transit_param.x;
var orig_y=transit_param.y;
var width=transit_param.width;
var height=transit_param.height;
var w=width;
var h=height;
for(var i=0;i<this.gadgets.length;i++){
var gadget_obj=this.gadgets[i];
if(gadget_obj.product_id!=target.product_id)
this._do_gadget(gadget_obj,"activate",[false]);};
var zapping=this._getGadgetObject(ZAPPING_GADGET);
if(zapping&&zapping.gadget&&zapping.gadget.closeSubVideobox){
zapping.gadget.closeSubVideobox();}
var me=this;
if(system.mdl_cfg.with_bp_transit_effect)
{
this._do_gadget(target,"activate",[false]);
HOME.setVisibilityForTransit("normal");
var bplayer=new BroadcastPlayer();
bplayer.osd_control(OSD_NORMAL);
set_pre_videobox(true,0,0,0,1920,1080,false);
bplayer.start_transit({
"from":{x:orig_x,y:orig_y,width:width,height:height},
"to":{x:0,y:0,width:1920,height:1080},
"mode":BP_TRANSIT_TO_TV,
"finished":function(){
HOME.setVisibilityForTransit("guidance_only");
if(func)func();}
});
return;}
var target_width=SHOW_TVINFO?Math.floor(1920+TVINFO_HEIGHT*16/9):1920;
var target_height=SHOW_TVINFO?(1080+TVINFO_HEIGHT):1080;
me._do_gadget(target,"_setTVInfoShow",[false]);
if(!SU_IS_13MT5590){
var tv=this.getTVGadgetObject();
var len=this.components.length;
var id=this.components.indexOf(tv);
if(id!=-1&&id!=(len-1)){
this.components.splice(id,1);
this.components.push(tv);}
me._do_gadget(target,"setSize",[target_width,target_height]);
me._do_gadget(target,"_setTVInfoShow",[true]);
target.translate=[0,0-(target_height-1080)/2,1];
me.requestFocus(target.translate,[target_width+8,target_height+8],null,9999,null);
HOME.toolbar.setTranslate(0,TOOLBAR_Y+80,0);
me.setScreenNameShow(false);
if(func){
func();}
var id=this.components.indexOf(tv);
if(id!=-1){
this.components.splice(id,1);
this._set_gadget_obj(tv);}
return;}
append_timer(this._launch_timer,80,function(obj,cnt){
if(cnt>5){
delete_timer(obj);
me._do_gadget(target,"setSize",[target_width,target_height]);
me._do_gadget(target,"_setTVInfoShow",[true]);
target.translate=[0,0-(target_height-1080)/2,1];
me.requestFocus(target.translate,[target_width+8,target_height+8],null,9999,null);
if(func){
func();}
return;}
w+=(target_width+80-w)/2;
h+=(target_height+80-h)/2;
me._do_gadget(target,"setSize",[(w>target_width)?target_width:w,(h>target_height)?target_height:h]);
target.translate[0]+=(0-target.translate[0])/2;
target.translate[1]+=(0-(target_height-1080)/2-target.translate[1])/2;
target.translate[2]=1;
me.requestFocus(target.translate,[w,h],null,9999,null);});};
Screen.prototype._reset_fullscreen_appli=function(obj){
delete_timer(this._launch_timer);
this.status["launching"]=false;
var id=this.gadgets.indexOf(obj);
if(id==-1)return;
var orig_x=this._mapping[id].pos_x;
var orig_y=this._mapping[id].pos_y;
var width=this._mapping[id].width;
var height=this._mapping[id].height;
this._do_gadget(obj,"setSize",[width,height]);
obj.translate=[orig_x,orig_y,0];
HOME.toolbar.setTranslate(0,TOOLBAR_Y,0);
this.setScreenNameShow(true);
if(system.mdl_cfg.with_bp_transit_effect){
HOME.setVisibilityForTransit("resume");
if(this.status["guidanceTV"]){
set_pre_videobox(false);}
}
};
Screen.prototype._swap_anim=function (obj,cnt){
var me=obj.parent;
if(cnt>me.max_count){
delete_timer(obj);
me.src_obj.translate=[me.src_x,me.src_y,0];
me.dst_obj.translate=[me.dst_x,me.dst_y,0];
if(typeof me.end_func=="function"){
me.end_func(me);}
}else{
me.src_obj.translate[0]+=(me.src_x-me.src_obj.translate[0])/(me.max_count-cnt+1);
me.src_obj.translate[1]+=(me.src_y-me.src_obj.translate[1])/(me.max_count-cnt+1);
me.dst_obj.translate[0]+=(me.dst_x-me.dst_obj.translate[0])/(me.max_count-cnt+1);
me.dst_obj.translate[1]+=(me.dst_y-me.dst_obj.translate[1])/(me.max_count-cnt+1);}
force_redraw();};
Screen.prototype._swap_new_gadget=function (old,uniq_id){
var map_id=old.map_id;
var product_id=(!uniq_id)?null:uniq_id.substr(0,16);
var id=this.components.indexOf(old);
var self=this;
if(map_id<0||id==-1)
return null;
var new_gadget=this._create_a_gadget(uniq_id);
this._set_frame(new_gadget,map_id);
this._set_gadget_args(new_gadget,map_id);
this._del_app_anim=function(obj,map_obj,end_func){
obj.src_x=map_obj.pos_x+30;
obj.src_y=map_obj.pos_y;
obj.src_z=0;
obj.dst_x=obj.src_x;
obj.dst_y=map_obj.pos_y-1400;
obj.dst_z=0;
obj.max_count=8;
obj.dx=Math.floor((obj.dst_x-obj.src_x)/obj.max_count);
obj.dy=Math.floor((obj.dst_y-obj.src_y)/obj.max_count);
obj.dz=Math.floor((obj.dst_z-obj.src_z)/obj.max_count);
obj.translate=[obj.src_x,obj.src_y,5];
obj.end_func=end_func;
force_redraw();
append_timer(obj,100,this._move_anim);}
this._add_app_anim=function(obj,map_obj,end_func){
obj.src_x=map_obj.pos_x;
obj.src_y=-730;
obj.src_z=0;
var diff_x=map_obj.pos_x-obj.src_x;
var diff_y=map_obj.pos_y-obj.src_y;
var distance=Math.floor(
Math.sqrt((diff_x*diff_x)+(diff_y*diff_y)));
obj.dst_x=map_obj.pos_x-Math.floor((50*diff_x)/distance);
obj.dst_y=map_obj.pos_y-Math.floor((50*diff_y)/distance);
obj.dst_z=10;
obj.max_count=5;
obj.dx=Math.floor((obj.dst_x-obj.src_x)/obj.max_count);
obj.dy=Math.floor((obj.dst_y-obj.src_y)/obj.max_count);
obj.dz=Math.floor((obj.dst_z-obj.src_z)/obj.max_count);
obj.end_func=function(obj){
obj.src_x=obj.translate[0];
obj.src_y=obj.translate[1];
obj.src_z=obj.translate[2];
obj.dst_x=map_obj.pos_x;
obj.dst_y=map_obj.pos_y;
obj.dst_z=0;
obj.max_count=5;
obj.dx=Math.floor((obj.dst_x-obj.src_x)/obj.max_count);
obj.dy=Math.floor((obj.dst_y-obj.src_y)/obj.max_count);
obj.dz=Math.floor((obj.dst_z-obj.src_z)/obj.max_count);
obj.end_func=end_func;
append_timer(obj,100,self._move_anim);}
obj.translate=[obj.src_x,obj.src_y,obj.src_z];
force_redraw();
append_timer(obj,100,this._move_anim);}
this.status["animation"]=true;
if(!product_id){new_gadget.frame_b.color=COL_POINT;
old.frame_b.color=COL_TRANSPARENT;
this._set_gadget_obj(old);
this._del_app_anim(old,
this._mapping[map_id],
function(){
self.components.splice(self.components.indexOf(old),1);
self.status["animation"]=false;
self.enf_func=null;});}else{var anim_gadget=new container({});
for(var i in new_gadget){
anim_gadget[i]=new_gadget[i];}
anim_gadget.frame_b.color=COL_TRANSPARENT;
new_gadget.visible_p=false;
this._set_gadget_obj(anim_gadget);
this._add_app_anim(anim_gadget,
this._mapping[map_id],
function(){
new_gadget.frame_b.color=COL_POINT;
new_gadget.visible_p=true;
self.components.splice(self.components.indexOf(anim_gadget),1);
self.status["animation"]=false;
self.enf_func=null;});}
var now_id=this.components.indexOf(old);
this.gadgets.splice(map_id,1,new_gadget);
this.components.splice(now_id,1,new_gadget);
return new_gadget;};
Screen.prototype._move_anim=function (obj,cnt){
if(cnt>=this.max_count){
delete_timer(obj);
obj.translate=[obj.dst_x,obj.dst_y,obj.dst_z];
force_redraw();
if(typeof obj.end_func=="function"){
obj.end_func(obj);}
}else{
obj.translate[0]+=obj.dx;
obj.translate[1]+=obj.dy;
if(obj.src_z!=obj.dst_z){
obj.translate[2]+=obj.dz;}
force_redraw();}
};
Screen.prototype._set_focus=function (bool){
if(bool==false)return;
var mapping=this._mapping;
var map_id=this.cursor.map_id;
var trans=[];
trans.push(this.translate[0]+mapping[map_id].pos_x||0);
trans.push(this.translate[1]+mapping[map_id].pos_y||0);
trans.push(this.translate[2]+2);
var width=mapping[map_id].width;
var height=mapping[map_id].height;
var self=this;
this.requestFocus(trans,[width+8,height+8],0,40,null);};
Screen.prototype._add_mark=new container({
visible_p:false,
components:[
new gimage({
width:112,height:103,
src:IMG_PATH+ADD_MARK
}),
]});
Screen.prototype._getLockedList=function (){
return getLockedList();};
Screen.prototype._setLockedFace=function (ids){
if(!this.gadgets)return;
if(!ids||ids.length<=0){
this._do_all_gadgets("setLocked",[false]);
return;}
var len=this.gadgets.length;
for(var i=0;i<len;i++){
var gadget_obj=this.gadgets[i];
if(ids.indexOf(gadget_obj.product_id)!=-1){
this._do_gadget(gadget_obj,"setLocked",[true]);}else {
this._do_gadget(gadget_obj,"setLocked",[false]);}
if((gadget_obj.product_id==WEBLINK_GADGET)
||(gadget_obj.product_id==BOOKMARK_GADGET)){
if(ids.indexOf(BROWSER_APPS)!=-1){
this._do_gadget(gadget_obj,"setLocked",[true]);}else {
this._do_gadget(gadget_obj,"setLocked",[false]);}
}
}
};
Screen.prototype._setLockedgadget=function (gadget_obj){
var lock_list=this._getLockedList();
try{
if(lock_list.indexOf(gadget_obj.product_id)!=-1){
this._do_gadget(gadget_obj,"setLocked",[true]);}else {
this._do_gadget(gadget_obj,"setLocked",[false]);}

if((gadget_obj.product_id==WEBLINK_GADGET)
||(gadget_obj.product_id==BOOKMARK_GADGET)){
if(lock_list.indexOf(BROWSER_APPS)!=-1){
this._do_gadget(gadget_obj,"setLocked",[true]);}else {
this._do_gadget(gadget_obj,"setLocked",[false]);}
}
}catch(e){
}
};
Screen.prototype._showPasswordPanel=function (bool){
var screen_obj=this;
if(bool==true){
screen_obj.status["unlock"]=true;
screen_obj._password_panel=new LockPasswordPanel(
function(){screen_obj.cursor=screen_obj._last_cursor;
screen_obj._showPasswordPanel(false);
screen_obj.status["launching"]=true;
screen_obj._launch_anim(screen_obj.cursor,"pass",function(){
screen_obj.status["launching"]=false;});},
function(){screen_obj.cursor=screen_obj._last_cursor;
screen_obj._showPasswordPanel(false);},
function(translate,size,angle,speed,func){translate[2]+=1.0;
screen_obj.requestFocus(translate,size,angle,speed,func);});
screen_obj.components.push(screen_obj._password_panel);
screen_obj._password_panel.setTranslate(0,0,1.0);
screen_obj._password_panel.setShow(true);
screen_obj._last_cursor=screen_obj.cursor;
screen_obj.cursor=screen_obj._password_panel;
screen_obj.cursor.onFocus(true);}else {
screen_obj.cursor=screen_obj._last_cursor;
var map_id=screen_obj.cursor.map_id||0;
var width=screen_obj._mapping[map_id].width;
var height=screen_obj._mapping[map_id].height;
screen_obj.requestFocus(screen_obj.cursor.translate,
[width+8,height+8],null,40,null);
screen_obj.status["unlock"]=false;
screen_obj._password_panel.setShow(false);
screen_obj._password_panel.free();
var index=screen_obj.components.indexOf(screen_obj._password_panel);
if(index!=-1)screen_obj.components.splice(index,1);
screen_obj._password_panel=null;
screen_obj.cursor=screen_obj._last_cursor;
screen_obj._last_cursor=null;}
};
Screen.prototype._collectAccessReportInfo=function (gadget_obj){
if(!gadget_obj)return null;
var id=this.gadgets.indexOf(gadget_obj);
var temp_name=this.getTemplateName();
var screen_key=this.getScreenKey();
if(isDLScreen(screen_key)){
var info=HOME.getScreenInfo(screen_key);
if(info&&isString(info.org_id))
temp_name=info.org_id;}
return {"pos":id,"template":temp_name,"action":"home"};};
Screen.prototype._getGadgetObject=function (pid){
if(!this.gadgets)return null;
for(var i=0;i<this.gadgets.length;i++){
if(this.gadgets[i].product_id!=pid)continue;
return this.gadgets[i];}
return null;};
Screen.prototype._SMAd_obj=null;
Screen.prototype._SMAd_block=null;
Screen.prototype._SMAd_is_startup_fulltv=false;
Screen.prototype._addSMAd=function(){
if(system.is_pnlpow_on&&
!system.is_pnlpow_on()){
return;}
this._my_add_SMAd();
this._SMAd_init();};
Screen.prototype._SMAd_status=function(){
if(this._SMAd_obj)
return true;
return false;};
Screen.prototype._SMAd_init=function (){
if(!this._SMAd_obj)return;
var map=this._map;
var len=map.length;
if(this._SMAd_use_block)
this._SMAd_block=this._map[len-1];
this.components.push(this._SMAd_obj);
this._do_SMAd("init",[this._SMAd_is_startup_fulltv]);
var self=this;
var myDestroyFunc=function(){
self._SMAd_finalize();};
var focusFunc=function(){
if(self._SMAd_obj)
self.requestFocus.apply(self,arguments);};
this._do_SMAd("setDestroyFunc",[myDestroyFunc]);
this._do_SMAd("setFocusFunc",[this.requestFocus]);
this._do_SMAd("onFocus",[true]);};
Screen.prototype._SMAd_finalize=function (){
if(!this._SMAd_obj)return;
this._do_SMAd("onFocus",[false]);
this._do_SMAd("setFocusFunc",[NULL_FUNCTION]);
var id=this.components.indexOf(this._SMAd_obj);
if(id!=-1)this.components.splice(id,1);
this._SMAd_obj=null;
if(this._SMAd_block){
var len=this._SMAd_block.length;
for(var i=0;i<len;i++){
var id=this._SMAd_block[i];
try{
this.gadgets[id].visible_p=true;}catch(e){};}
}
this._SMAd_block=null;
if(this.status["activate"]==true&&
this.status["fullscreen"]==true){
this.onFocus(true);}
force_redraw();};
Screen.prototype._SMAd_destroy=function (){
if(!this._SMAd_obj)return;
this._SMAd_finalize();};
Screen.prototype._do_SMAd=function (method,arg_array){
var ret_val=false;
if(!this._SMAd_obj)return ret_val;
var Ad=this._SMAd_obj;
if(Ad[method] instanceof Function){
try{
ret_val=Ad[method].apply(Ad,arg_array);}catch(e){
var dlog="[SMAd] ";
dlog+=method+" method Error. ";
dlog+=e.name+": "+e.message;
console.log(dlog);}
};
return ret_val;};
Screen.prototype._SMAd_use_block=true;
Screen.prototype._my_add_SMAd=function(){
try{
this._SMAd_obj=SMAd;
this._SMAd_use_block=true;}catch(e){
console.log(e.message);};};
Screen.prototype._my_launch_with_timer_effect=function(target,func){
var id=this.gadgets.indexOf(target);
var orig_x=this._mapping[id].pos_x;
var orig_y=this._mapping[id].pos_y;
var width=this._mapping[id].width;
var height=this._mapping[id].height;
var w=width;
var h=height;
var target_width=SHOW_TVINFO?Math.floor(1920+TVINFO_HEIGHT*16/9):1920;
var target_height=SHOW_TVINFO?(1080+TVINFO_HEIGHT):1080;
var me=this;
me._do_gadget(target,"_setTVInfoShow",[false]);
if(!SU_IS_13MT5590){
var report=me._collectAccessReportInfo(target);
me._do_gadget(target,"launchApl",[null,report]);
me._do_gadget(target,"setSize",[width,height]);
me._do_gadget(target,"_setTVInfoShow",[true]);
target.translate=[orig_x,orig_y,0];
me.requestFocus(target.translate,[width+8,height+8],null,9999,null);
if(func){
func();}
return;}
append_timer(this._launch_timer,80,function(obj,cnt){
if(cnt>5){
delete_timer(obj);
var report=me._collectAccessReportInfo(target);
me._do_gadget(target,"launchApl",[null,report]);
me._do_gadget(target,"setSize",[width,height]);
me._do_gadget(target,"_setTVInfoShow",[true]);
target.translate=[orig_x,orig_y,0];
me.requestFocus(target.translate,[width+8,height+8],null,9999,null);
if(func){
func();}
return;}
w+=(target_width+80-w)/2;
h+=(target_height+80-h)/2;
me._do_gadget(target,"setSize",[(w>target_width)?target_width:w,(h>target_height)?target_height:h]);
target.translate[0]+=(0-target.translate[0])/2;
target.translate[1]+=(0-(target_height-1080)/2-target.translate[1])/2;
target.translate[2]=1;
me.requestFocus(target.translate,[w,h],null,9999,null);});};
Screen.prototype._my_launch_with_transit_effect=function(target,func){
this._my_transit_to_TV(target,func);};
Screen.prototype._my_transit_to_TV=function(target,func){
var id=this.gadgets.indexOf(target);

var transit_param=this._getTransitParam(this._mapping,id);
var orig_x=transit_param.x;
var orig_y=transit_param.y;
var width=transit_param.width;
var height=transit_param.height;
width=width+width%2;
height=height+height%2;
var me=this;
var bplayer=new BroadcastPlayer();
bplayer.df_disconnect();
bplayer.osd_control(OSD_NORMAL);
bplayer.start_transit({
"from":{x:orig_x,y:orig_y,width:width,height:height},
"to":{x:0,y:0,width:1920,height:1080},
"mode":BP_TRANSIT_TO_TV,
"finished":function(){
var report=me._collectAccessReportInfo(target);
me._do_gadget(target,"launchApl",[null,report]);
if(func)func();}
});};
Screen.prototype._my_transit_return_HOME=function(){
if(!system.mdl_cfg.with_bp_transit_effect)return;
var bplayer=new BroadcastPlayer();
var w=this.pre_window.videoframe.width;
var h=this.pre_window.videoframe.height;
var trans=this.pre_window.translate;
var z_pos=trans[2]+this.translate[2];
var xx=Math.round(CAMERA_POS/(z_pos+CAMERA_POS)*trans[0]);
var yy=Math.round(CAMERA_POS/(z_pos+CAMERA_POS)*trans[1]);
var ww=Math.round(CAMERA_POS/(z_pos+CAMERA_POS)*w);
var hh=Math.round(CAMERA_POS/(z_pos+CAMERA_POS)*h);
ww=ww+ww%2;
hh=hh+hh%2;
bplayer.start_transit({
"from":{x:0,y:0,width:1920,height:1080},
"to":{x:xx,y:yy,width:ww,height:hh},
"mode":BP_TRANSIT_RETRUN_HOME,
"finished":function(){force_redraw();}
});};
Screen.prototype._my_df_control=NULL_FUNCTION;
_GLOBAL_.Screen=Screen;
provide("screen");
