
var CONTEXT_SURFER=(system.mdl_cfg.apps_context==system.mdl_cfg.APPS_CONTEXT_SURFER);
const APPS_POS_NORMAL=[240-12,40,0];
function underApps_menu_part(param,focus_moveto){
this.superClass=container;
this.superClass({});
this.translate=param.translate;
this.width=param.width;
this.height=param.height;
this.visible_p=false;
var back_w=1920-600;var back_h=760;this.background=new container({
translate:[(1920-back_w)/2-80,-320,0],
components:[
new gbox({width:back_w,height:back_h,
color:system.fdp_color.POP_BORDER,
}),
new gbox({width:back_w-4,height:back_h-4,
color:system.fdp_color.POP,
}),
]
});
this.title=new gtext({width:800,translate:[0,0,0],
align:LEFT,valign:MIDDLE,margin_leading:-4,
color:system.fdp_color.TEXT_ONBASE,font_size:42,
text:LANG("LT_APPS_SHOW_AGE_RESTRICTED"),});
var btn_list=[];
btn_list[0]={width:200,height:76,title:LANG("LT_YES"),font_size:42,
action:function(){storeAdultSetting(false);
applications.showRestrictedState(false);}};
btn_list[1]={width:200,height:76,title:LANG("LT_NO"),font_size:42,
action:function(){storeAdultSetting(true);
applications.showRestrictedState(true);}};
this.slideBtn=new slideSelectBtn({width:300,height:74,
translate:[600,0,0]},btn_list);
this.explanation_text=new gtextbox({width:Math.floor(back_w*2/3),height:400,
translate:[230,-400,0],align:LC_TEXT_ALIGN,
color:system.fdp_color.TEXT_SUB_ONBASE,
font_size:32,
text:LANG("LT_APPS_ADULT_ENTER_INFO")});
this.components.push(this.background,this.title,this.slideBtn,this.explanation_text);
change_font_size(this.title);
this.cursor=0;
this.focus_moveto=focus_moveto;
this.org_translate=this.translate.slice(0);
this.org_width=this.width;
this.org_height=this.height;}
append_functions(underApps_menu_part.prototype,GraphicsLib);
append_functions(underApps_menu_part.prototype,AnimationLib);
if(SU_IS_SLOW_ANIM){
underApps_menu_part.prototype.moveTo=AnimationLib.moveToDirect;
underApps_menu_part.prototype.slide=AnimationLib.slideDirect;}
underApps_menu_part.prototype.setShow=function(b){
this.visible_p=b;}
underApps_menu_part.prototype.onFocus=function(b,keysym){
this.setFocus(b,keysym);}
underApps_menu_part.prototype.setFocus=function(b,keysym,func){
if(b==true){
this.correctFocus(60,func);}
this.slideBtn.setFocus(b)
}
underApps_menu_part.prototype.setActiveButton=function(cursor){
this.slideBtn.setActiveButton(cursor);}
underApps_menu_part.prototype.getSize=function(){
return [this.widht,this.height];}
underApps_menu_part.prototype.getOrgPosition=function(){
return this.org_translate;}
underApps_menu_part.prototype.getFocusSize=function(){
return this.slideBtn.getFocusSize();}
underApps_menu_part.prototype.getFocusPosition=function(){
return this.slideBtn.getFocusPosition();}
underApps_menu_part.prototype.getVisible=function(){
return this.visible_p;}
underApps_menu_part.prototype.correctFocus=function(speed,func){
if(!speed)speed=40;
var tra=this.slideBtn.getFocusPosition();
var size=this.slideBtn.getFocusSize();
this.focus_moveto([tra[0]+this.translate[0],
tra[1]+this.translate[1],
tra[2]+this.translate[2]],
size,null,Math.max(40,speed),func);}
underApps_menu_part.prototype.key_hook=function(updown,keysym){
if(updown!=KEY_PRESS)return false;
var ret=this.slideBtn.key_hook(updown,keysym);
return ret;}
function slideSelectBtn(param,btn_list){
this.superClass=container;
this.superClass({});
this.translate=param.translate;
this.width=param.width;
this.height=param.height;
this.cursor=0;
this.btn_num=btn_list.length-1;
this.btn_list=new container({});
var btn=null;
for(var i=0;i<btn_list.length;i++){
if(i<=0){
btn_list[i].translate=[0,0,0]
}else{
btn_list[i].translate=[btn_list[i-1].translate[0]+this.width,0,0];}
btn=new this.Btn(btn_list[i]);
this.btn_list.components.push(btn);}
this.left_arrow=new gimage({translate:[-this.width/2+30,-2,0],
color:system.fdp_color.TEXT_SUB_ONBASE,
src:IMG_PATH+"btn_arrow.png",visible_p:false,});
this.right_arrow=new gimage({translate:[this.width/2-30,-2,0],
color:system.fdp_color.TEXT_SUB_ONBASE,
src:IMG_PATH+"btn_arrow.png",visible_p:false,
rotation:[180,0,0,1],blend:true});
this.left_mask=new gbox({translate:[-this.width*1.5,-10,0.1],
width:this.width*2,height:76,color:[0,0,0,0],
depth_test:true,});
this.right_mask=new gbox({translate:[this.width*1.5,-10,0.1],
width:this.width*2,height:76,color:[0,0,0,0],
depth_test:true,});
this.components.push(this.left_arrow,this.right_arrow,
this.left_mask,this.right_mask,
this.btn_list);}
slideSelectBtn.prototype.getFocusPosition=function(){
return [this.translate[0],this.translate[1],this.translate[2]+1];}
slideSelectBtn.prototype.getFocusSize=function(){
return [this.width+4,this.height+4];}
slideSelectBtn.prototype.setFocus=function(b){
if(b){
this.correctArrows();}else{
this.right_arrow.visible_p=false;
this.left_arrow.visible_p=false;

}
}
slideSelectBtn.prototype.setActiveButton=function (cursor){
this.cursor=cursor;
this.btn_list.translate[0]=
-this.btn_list.components[this.cursor].translate[0];
this.decideOption(false);}
slideSelectBtn.prototype.getActiveButton=function (){
return;}
slideSelectBtn.prototype.correctArrows=function (){
if(this.cursor==0){
this.left_arrow.visible_p=false;
this.right_arrow.visible_p=true;}else if(this.cursor==this.btn_num){
this.right_arrow.visible_p=false;
this.left_arrow.visible_p=true;}else {
this.right_arrow.visible_p=true;
this.left_arrow.visible_p=true;}
};
slideSelectBtn.prototype.moveLeft=function (){
var self=this;
delete_timer(self);
this.correctArrows();
var target_trans=-self.btn_list.components[self.cursor].translate[0];
this.btn_list.translate[0]+=46;
force_redraw();
if(SU_IS_SLOW_ANIM){
self.btn_list.translate[0]=target_trans;
self.decideOption(true);}else{
append_timer(self,30,function(self,count){
self.btn_list.translate[0]+=34;
if(self.btn_list.translate[0]>=target_trans){
delete_timer(self);
self.btn_list.translate[0]=target_trans;
self.decideOption(true);}
force_redraw();});}
}
slideSelectBtn.prototype.moveRight=function (){
var self=this;
delete_timer(self);
this.correctArrows();
var target_trans=-self.btn_list.components[self.cursor].translate[0];
this.btn_list.translate[0]-=46;
force_redraw();
if(SU_IS_SLOW_ANIM){
self.btn_list.translate[0]=target_trans;
self.decideOption(true);}else{
append_timer(self,30,function(self,count){
self.btn_list.translate[0]-=34;
if(self.btn_list.translate[0]<=target_trans){
delete_timer(self);
self.btn_list.translate[0]=target_trans;
self.decideOption(true);}
force_redraw();});}
}
slideSelectBtn.prototype.decideOption=function (is_run_action){
for(var i=0,max=this.btn_list.components.length;i<max;i++){
this.btn_list.components[i].active(false);}
this.btn_list.components[this.cursor].active(true);
if(is_run_action==true){
var self=this;
append_timer({},10,function(obj){
delete_timer(obj);
try{
self.btn_list.components[self.cursor].action();}catch(e){
DEBUG.error(e.message);}
});}
};
slideSelectBtn.prototype.key_hook=function (updown,keysym){
if(updown!=KEY_PRESS)return false;

switch(keysym){
case TXK_UP:
return false;
case TXK_DOWN:
return false;
case TXK_LEFT:
if(this.cursor>0){
this.cursor--;
this.moveLeft();}
return true;
case TXK_RIGHT:
if(this.cursor<this.btn_num){
this.cursor++;
this.moveRight();}
return true;
case TXK_ENTER:
return false;
case TXK_RETURN:
this.setFocus(false);
default:
break;}
return false;}
slideSelectBtn.prototype.Btn=function(param){
this.superClass=container;
this.superClass({});
this.translate=param.translate;
this.width=param.width;
this.height=param.height;

this.title=new gtext({width:this.width-10,align:CENTER,
color:system.fdp_color.TEXT_ONBASE,
font_size:param.font_size,text:param.title,depth_test:true,});
this.components.push(this.title);

change_font_size(this.title);
if(param.action){
this.action=param.action;}
}
slideSelectBtn.prototype.Btn.prototype.setTitle=function(text){
setf_text(this.title,text);
change_font_size(this.title);}
slideSelectBtn.prototype.Btn.prototype.getFocusPosition=function(){
return [this.translate[0],this.translate[1],this.translate[2]];}
slideSelectBtn.prototype.Btn.prototype.getFocusSize=function(){
return [this.width+8,this.height+8];}
slideSelectBtn.prototype.Btn.prototype.active=function(bool){
if(bool){
this.title.color[3]=255;}else{
this.title.color[3]=150;}
force_redraw();}
slideSelectBtn.prototype.Btn.prototype.getactive=function(){
var ret=false;
if(this.title.color[3]==255)ret=true;
return ret;}
var underApps_menu=new underApps_menu_part({translate:[0,-460,0],width:800,height:400},focus_moveto);
function loading_circle_item(param){
this.superClass=container;
this.superClass({});
this.translate=param.translate?param.translate:[0,0,0];
this.width=param.width?param.width:100;
this.height=param.height?param.height:100;
this.visible_p=false;
this.loading=new gimage({rotation:[0,0,0,1],
width:this.width,height:this.height,
color:system.fdp_color.ICON_ONBASE,
src:IMG_PATH+"loading_circle.png",});
this.components.push(this.loading);}
loading_circle_item.prototype.init=function(param){
this.translate=param.translate?param.translate:this.translate;
this.width=param.width?param.width:this.width;
this.height=param.height?param.height:this.height;
this.loading.width=this.width;
this.loading.height=this.height;
delete_timer(this);
this.visible_p=false;
this.loading.rotation=[0,0,0,1];}
loading_circle_item.prototype.setShow=function(bool){
var obj=this;
if(bool==true){
delete_timer(obj);
obj.visible_p=true;
append_timer(obj,SU_IS_SLOW_ANIM?250:100,function(obj,count){
obj.loading.rotation[0]=-(30*count)%360;
force_redraw();});}else{
delete_timer(obj);
obj.visible_p=false;
obj.loading.rotation=[0,0,0,1];}
}
function EditMenuButton(text,editor){
this.superClass=container;
this.superClass({});
this.color=[255,255,255,255];
this.components.push(


this.title=new gtextbox({
width:this.width-100+16,height:this.height,
align:LC_TEXT_ALIGN,valign:MIDDLE,margin_leading:-4,
color:this.TEXT_COLOR_DISABLE,font_size:36,text:"",
})
);
if(isString(text)){
this.setTitle(text);}
if(editor){
this.editor=editor;}
};
EditMenuButton.prototype=new container({});
EditMenuButton.prototype.TEXT_COLOR_ENABLE=system.fdp_color.POINT_ONBASE;
EditMenuButton.prototype.TEXT_COLOR_DISABLE=system.fdp_color.TEXT_ONBASE;
EditMenuButton.prototype.width=430-16;
EditMenuButton.prototype.height=90;
EditMenuButton.prototype.title=null;EditMenuButton.prototype.color=null;EditMenuButton.prototype.editor=null;
EditMenuButton.prototype.getEditor=function(text){
return this.editor;};
EditMenuButton.prototype.setTitle=function(text){
setf_text(this.title,text);
change_font_size_b(this.title);};
EditMenuButton.prototype.setAlpha=function(alpha){
this.color[3]=alpha;
this.title.color[3]=alpha;};
EditMenuButton.prototype.setFocus=function(b){
return 0;};
EditMenuButton.prototype.getFocusPosition=function(){
return this.translate;};
EditMenuButton.prototype.getFocusSize=function(){
return [this.width+4,this.height+4];};
EditMenuButton.prototype.setEnable=function(b){
if(b==true){
this.title.color=this.TEXT_COLOR_ENABLE;}else{
this.title.color=this.TEXT_COLOR_DISABLE;}
};
append_functions(EditMenuButton.prototype,GraphicsLib);
append_functions(EditMenuButton.prototype,AnimationLib);
if(SU_IS_SLOW_ANIM){
EditMenuButton.prototype.transparentTo=AnimationLib.transparentToDirect;}

function EditMenu(focus_moveto){
this.superClass=container;
this.superClass({
translate:[-(1920-this.width)/2,0,0],
components:[
this.background=new gbox({
color:system.fdp_color.BASE,
width:this.width,height:this.height,
}),

new gbox({translate:[this.width/2,0,0],
width:2,height:this.height,
color:system.fdp_color.BORDER_ONBASE,}),
this.title=new gtext({
color:system.fdp_color.TEXT_SUB_ONBASE,
translate:[0,540-140,0],
width:this.width,align:CENTER,
text:LANG("LT_APPS_SETTINGS"),
font_size:52,
}),
]
});
this.item=[];
this.focus_moveto=focus_moveto;};
EditMenu.prototype=new container({});
EditMenu.prototype.MARGIN_V=4;
EditMenu.prototype.background=null;EditMenu.prototype.cursor=0;EditMenu.prototype.width=460;EditMenu.prototype.height=1080;EditMenu.prototype.item=null;EditMenu.prototype.title=null;EditMenu.prototype.focus_moveto=null;
EditMenu.prototype.addItem=function(btn,translateY){
if(this.item.length==0){
btn.translate[1]=540-250;}else if(translateY){
btn.translate[1]=translateY;}else{
var last=this.item[this.item.length-1];
btn.translate[1]
=last.translate[1]-last.height/2-this.MARGIN_V-btn.height/2;}
this.item.push(btn);
this.components.push(btn);};
EditMenu.prototype.onFocus=function(b,keysym){
this.setFocus(b,keysym);};
EditMenu.prototype.setFocus=function(b){
if(b==true){
this.correctFocus(60);
this.item[this.cursor].setFocus(b);
this.item.forEach(
function(ele,idx,ary){
ele.setEnable(!true);}
);}else{
this.item[this.cursor].setFocus(b);}
return this.cursor;};
EditMenu.prototype.correctFocus=function(speed){
if(!speed)speed=40;
var tra=this.item[this.cursor].getFocusPosition();
var size=this.item[this.cursor].getFocusSize();
this.focus_moveto([tra[0]+this.translate[0],
tra[1]+this.translate[1],
tra[2]+this.translate[2]],
size,null,Math.max(40,speed));};
EditMenu.prototype.key_hook=function(updown,keysym){
if(updown!=KEY_PRESS)return false;
switch(keysym){
case TXK_UP:
if(this.cursor==0){
return false;}
HOME_SOUND_PLAY(0);
this.item[this.cursor].setFocus(false,keysym);
this.cursor--;
this.item[this.cursor].setFocus(true,keysym);
this.correctFocus();
return true;
case TXK_DOWN:
if(this.cursor==this.item.length-1){
return false;}
HOME_SOUND_PLAY(0);
this.item[this.cursor].setFocus(false,keysym);
this.cursor++;
this.item[this.cursor].setFocus(true,keysym);
this.correctFocus();
return true;
case TXK_RIGHT:
case TXK_ENTER:
try{
var selected=this.cursor;
this.item.forEach(
function(ele,idx,ary){
ele.setEnable((idx==selected));}
);
HOME_SOUND_PLAY("enter");
var editor=this.item[this.cursor].getEditor();
set_cursor(editor,TXK_ENTER);
return true;}catch(e){
DEBUG.info("No actin. ("+e.message+")");
return false;}
default:
}
return false;};

function Editor(){
this.superClass=container;
this.superClass({});};
Editor.prototype=new container({});
Editor.prototype.init=function(){
DEBUG.info("Editor.init(): no process.");};
Editor.prototype.destroy=function(){
DEBUG.info("Editor.destroy(): no process.");};
Editor.prototype.setFocus=function(b,keysym){
this.onFocus(b,keysym);};
Editor.prototype.onFocus=function(b,keysym){
if(b==true){
this.init();
applications.setFocus(b,keysym);}else{
applications.setFocus(b,keysym);
this.destroy();}
};
Editor.prototype.key_hook=function(updown,keysym){
switch(keysym){
case TXK_LEFT:
case TXK_RIGHT:
case TXK_UP:
case TXK_DOWN:
return applications.key_hook(updown,keysym);}
return false
};


var edit_back=new container({components:[
new gbox({color:system.fdp_color.BASE,
width:1920,height:1080}),
new gimage({src:IMG_PATH+"apps_back_gradation.png",blend:CONTEXT_SURFER,
width:1920,height:1080,draw_type:DIRECT,
color:system.fdp_color.TEXT_SUB_ONBASE,
blend:true,
})
]});
var focus=new Focus();
focus.visible_p=false;
focus.setSize(EditMenuButton.prototype.getFocusSize()[0],
EditMenuButton.prototype.getFocusSize()[1]);
focus.setTranslate(-730,290,0);
if(CONTEXT_SURFER==false){
focus.ANIMATION_TIME_INTERVAL=20;}
focus.icon=new gimage({color:[180,180,180,160],draw_type:DIRECT});
focus.components.push(focus.icon);
focus.setProduct=function(id,restricted){
this.icon.width=this.width;
this.icon.height=this.height;
if(id){
if((restricted==true)&&(getAdultSetting()==true)){
this.icon.src="";}else{
this.icon.src=APPLI_PATH+id+"/icon.png";}
}else{
this.icon.src="";}
};
append_functions(focus,GraphicsLib);
append_functions(focus,AnimationLib);
if(SU_IS_SLOW_ANIM){
focus.slide=AnimationLib.slideDirect;}

var floor=function(val){return Math.floor(val);};
var floor_plus_one=function(val){return Math.floor(val)+1;};
var floor_plus_two=function(val){return Math.floor(val)+2;};
function focus_moveto(pos,size,angle,speed,func){if(!speed)speed=32;
focus.moveTo(pos,size,angle,Math.max(32,speed),func);};
function focus_moveto2(pos,size,angle,speed,func){if(!speed)speed=32;
var pos2=[APPS_POS_NORMAL[0]+pos[0]*0.75,40+pos[1]*0.75,pos[2]*0.75+0.01];
var size2=[size[0]*0.75,size[1]*0.75];
focus.moveTo(pos2.map(floor),size2.map(floor_plus_two),
angle,Math.max(32*(CONTEXT_SURFER?1:2),speed),func);};
function focus_moveto3(pos,size,angle,speed,func){if(!speed)speed=32;
var pos2=[APPS_POS_NORMAL[0]+pos[0]*0.75,40+pos[1]*0.75,pos[2]*0.75+0.01];
var size2=[size[0]*0.75,size[1]*0.75];
focus.moveTo(pos2,size2.map(floor_plus_one),
angle,Math.max(32*(CONTEXT_SURFER?1:2),speed),func);};
var recent=new FavoriteList(focus_moveto2);
recent.translate[1]=210-26;
var apps_list=new AppsPlateOperator(focus_moveto3);
apps_list.translate[1]=-196-36;
var applications=new ApplicationList(recent,apps_list);
applications.init=function(){
this.setTranslate.apply(this,APPS_POS_NORMAL);};
function getApplicationList(fname){
return eval(
sysutil.tconv.binary_to_string(
apps_nvram_file.read({product_id:"home",
filename:fname,
async:false,
})));};
function writeApplicationList(fname,list){
var tmp="[";
for(var i=0;i<list.length;i++){
if(list[i]==null){
tmp+="null,";}else{
tmp+="\""+list[i]+"\",";}
}
tmp+="]";
apps_nvram_file.write({product_id:"home",
filename:fname,
async:false,
data:tmp,
});};
var edit_move=new Editor();
edit_move.selected=null;
edit_move.init=function(){
guide.setGuide(LANG("LT_APPS_MOVE_SELECT_APP"));
guide.setEnable(true);
recent.set_focus_moveto(focus_moveto2);
apps_list.set_focus_moveto(focus_moveto3);
applications.moveTo(APPS_POS_NORMAL,[1440,810],null,32);};
edit_move.destroy=function(){
guide.setEnable(false);};
edit_move.swap=function(from,to){
DEBUG.info("swap: "+from+"  <==>  "+to);
var list=getApplicationList("apps_list");
list[from[0]]=to[1];
list[to[0]]=from[1];
var order_list=applications.orderAppsList(list);
writeApplicationList("apps_list",order_list);
var start=0;
if(to[0]<7){
start=apps_list.getCurrentPage()
}else{
start=Math.floor((to[0]-7)/21);}
applications.addApps(order_list,start);
applications.setSize(1440,810);};
edit_move.key_hook=function(updown,keysym){
if(updown!=KEY_PRESS)return false;
var ret;
switch(keysym){
case TXK_UP:
case TXK_DOWN:
case TXK_RIGHT:
ret=applications.key_hook(updown,keysym);
if(ret==true)HOME_SOUND_PLAY(0);
return ret;
case TXK_LEFT:
if(applications.key_hook(updown,keysym)==true){
HOME_SOUND_PLAY(0);
return true;}else if(this.selected!=null){
return true;}else{
focus.setProduct(null);
return false;}
case TXK_RETURN:
if(this.selected!=null){
guide.setEnable(false,function(){
guide.setGuide(LANG("LT_APPS_MOVE_SELECT_APP"));
guide.setEnable(true);});
HOME_SOUND_PLAY("cancel");
this.selected=null;
focus.setProduct(null);
applications.selectCurrentProduct(false);
return true;}else{
return false;}
case TXK_ENTER:
var tmp=applications.getCurrentProduct();
if(tmp==null){
return true;}
HOME_SOUND_PLAY("enter");
if(this.selected==null){
guide.setEnable(false,function(){
guide.setGuide(LANG("LT_APPS_MOVE_SELECT_PLACE"));
guide.setEnable(true);});
this.selected=tmp;
focus.setProduct(this.selected[1],this.selected[4]);
applications.selectCurrentProduct(true);}else{
this.swap(this.selected,tmp);
guide.setEnable(false,function(){
guide.setGuide(LANG("LT_APPS_MOVE_SELECT_APP"));
guide.setEnable(true);});
this.selected=null;
focus.setProduct(null);
applications.selectCurrentProduct(false);
applications.setFocus(true);}
return true;
break;}
return false;};

var edit_lock=new Editor();
edit_lock.cursor=unlock;
edit_lock.cache_img=new gimage({src:ApplicationIcon.prototype.LOCKED_IMG});
edit_lock.init=function(){
useNumKey(true);
this.cursor=unlock;
recent.set_focus_moveto(focus_moveto2);
apps_list.set_focus_moveto(focus_moveto3);
unlock.setdoAction(this.unlock_cb);
unlock.setShow(true);
applications.slide(1,-800,24,
function(){
applications.showLockState(true);});};
edit_lock.destroy=function(){
useNumKey(false);
unlock.setShow(false);
guide.setEnable(false);
applications.showLockState(false);
if((this.cursor==underApps_menu)&&(underApps_menu.getVisible())){
applications.moveTo(APPS_POS_NORMAL,[1440,810],null,36);
underApps_menu.moveTo([0,-460,0],[800,400],null,36,
function(){underApps_menu.setShow(false);});}else{
applications.moveTo(APPS_POS_NORMAL,[1440,810],null,36,
function(){underApps_menu.setShow(false);});}
};
edit_lock.unlock_cb=function(){
unlock.setShow(false);
guide.setGuide(LANG("LT_APPS_LOCK_SELECT_APP"));
guide.setEnable(true);
applications.moveTo(APPS_POS_NORMAL,[1440,810],null,36,
function(){
edit_lock.cursor=applications;
applications.setFocus(true);
if(menu.market_restriction==true){
if(getAdultSetting()==true){
underApps_menu.setActiveButton(1);}else{
underApps_menu.setActiveButton(0);}
underApps_menu.setShow(true);}
});}
edit_lock.onFocus=function(b,keysym){
if(b==true){
this.init();
unlock.onFocus(true);}else{
applications.setFocus(b,keysym);
this.destroy();}
};
edit_lock.toggleLock=function(product_id){
DEBUG.info("edit_lock.toggleLock: "+product_id);
var ret=null;
var locklist=null;
try{
locklist=getApplicationList("locked_list");}catch(e){
locklist=[];}
if(locklist.some(function(val,idx,arry){return (val==product_id);})==true){
locklist=locklist.filter(
function(val,idx,arry){
return (val!=product_id);});
ret=false;}else{
locklist.push(product_id);
ret=true;}
locklist=locklist.filter(
function(val,idx,arry){
return (val!="0040000800000007");});

writeApplicationList("locked_list",locklist);
system.apps.update_home_lockface();
if(product_id=="0040000100000001"){return this.toggleLock("0387878700000040");}else{
return ret;}
};
edit_lock.key_hook=function(updown,keysym){
var ret;
switch(keysym){
case TXK_LEFT:
case TXK_RIGHT:
ret=this.cursor.key_hook(updown,keysym);
if(ret==true)HOME_SOUND_PLAY(0);
return ret;
case TXK_UP:
ret=this.cursor.key_hook(updown,keysym);
if(ret==true){
HOME_SOUND_PLAY(0);}else{
if((this.cursor==underApps_menu)&&(underApps_menu.getVisible())){
HOME_SOUND_PLAY(0);
applications.moveTo(APPS_POS_NORMAL,[1440,810],null,36);
var focus_tr=underApps_menu.getFocusPosition();
var underApps_org_tr=underApps_menu.getOrgPosition();
focus.moveTo([focus_tr[0],focus_tr[1]+underApps_org_tr[1],focus_tr[2]],
underApps_menu.getFocusSize(),null,36,null);
underApps_menu.moveTo(underApps_org_tr,underApps_menu.getSize(),null,36,
function(){
guide.setEnable(true);
applications.setFocus(true);
underApps_menu.setFocus(false);
edit_lock.cursor=applications;});}
}
return ret;
case TXK_DOWN:
ret=this.cursor.key_hook(updown,keysym);
if(ret==true){
HOME_SOUND_PLAY(0);}else{
if((this.cursor==applications)&&(underApps_menu.getVisible())){
HOME_SOUND_PLAY(0);
guide.setEnable(false);
underApps_menu.setFocus(true,null,
function(){
edit_lock.cursor=underApps_menu;
applications.slide(1,932,24,null);
focus.slide(1,300,24,null);
underApps_menu.slide(1,300,24,null);});}
}
return ret;
case TXK_D1:case TXK_D2:case TXK_D3:case TXK_D4:case TXK_D5:
case TXK_D6:case TXK_D7:case TXK_D8:case TXK_D9:case TXK_D0:
ret=this.cursor.key_hook(updown,keysym);
if(ret==true)HOME_SOUND_PLAY("enter");
return ret;
case TXK_ENTER:
if(this.cursor==unlock){
return this.cursor.key_hook(updown,keysym);}else if(this.cursor==underApps_menu){
ret=this.cursor.key_hook(updown,keysym);
if(ret==true)HOME_SOUND_PLAY("enter");
return true;}else{var tmp=applications.getCurrentProduct();
if(tmp==null){
return true;}
var select=tmp;
DEBUG.info("SelectedObject = "+select);
if(select[2]==true){
if((select[4]==true)&&(getAdultSetting()==true))return true;
var locked=this.toggleLock(select[1]);
if(locked==true){
HOME_SOUND_PLAY("enter");}else{
HOME_SOUND_PLAY("cancel");}
applications.setCurrentLockState(locked);}else{
}
return true;}
break;
case TXK_RETURN:
if(this.cursor==unlock){
var ret=this.cursor.key_hook(updown,keysym);
if(ret==false)HOME_SOUND_PLAY("cancel");
return ret;}else if(this.cursor==underApps_menu){
HOME_SOUND_PLAY(0);
applications.moveTo(APPS_POS_NORMAL,[1440,810],null,36);
var focus_tr=underApps_menu.getFocusPosition();
var underApps_org_tr=underApps_menu.getOrgPosition();
focus.moveTo([focus_tr[0],focus_tr[1]+underApps_org_tr[1],focus_tr[2]],
underApps_menu.getFocusSize(),null,36,null);
underApps_menu.moveTo(underApps_org_tr,underApps_menu.getSize(),
null,36,function(){
guide.setEnable(true);
applications.setFocus(true);
underApps_menu.setFocus(false);
edit_lock.cursor=applications;});
return true;}
break;
default:
break;}
return false
};
var unlock=new LockPasswordPanel(
null,
null,
focus_moveto);
unlock.translate=[240,0,0];
unlock.setTranslate_bg(460-240,0,0);

var edit_uninstall=new Editor();
edit_uninstall.cursor=applications;
edit_uninstall.init=function(){
useNumKey(true);
this.cursor=unlock;
recent.set_focus_moveto(focus_moveto2);
apps_list.set_focus_moveto(focus_moveto3);
unlock.setdoAction(this.unlock_cb);
var unlock_status=unlock.setShow(true,unlock.LOCK_MODE_PRESET);

if(unlock_status==true){
applications.slide(1,-800,24,
function(){
applications.showRemoveState(true);});
unlock.onFocus(true);}else{
applications.showRemoveState(true);}
return unlock_status;};
edit_uninstall.destroy=function(){
useNumKey(false);
unlock.setShow(false);
guide.setEnable(false);
footer_guide.setGuide(null);
applications.showRemoveState(false);
applications.moveTo(APPS_POS_NORMAL,[1440,810],null,36);};
edit_uninstall.unlock_cb=function(b){
unlock.setShow(false);
guide.setGuide(LANG("LT_APPS_UNINSTALL_SELECT_APP"));
guide.setEnable(true);
var func=function(){
edit_uninstall.cursor=applications;
applications.setFocus(true);
footer_guide.setGuide(LANG("LT_APPS_UNINSTALL_NOTICE")?
"* "+LANG("LT_APPS_UNINSTALL_NOTICE"):"");};
if(b!=false){
this.id=null;
applications.moveTo(APPS_POS_NORMAL,[1440,810],null,36,
func);}else{
func();}
}
edit_uninstall.onFocus=function(b,keysym){
if(b==true){
this.init();}else{
applications.setFocus(b,keysym);
this.destroy();}
};
edit_uninstall.releaseLock=function(product_id){
DEBUG.info("edit_uninstall.releaseLock: "+product_id);
var ret=null;
var locklist=null;
try{
locklist=getApplicationList("locked_list");}catch(e){
locklist=[];}
if(locklist.some(function(val,idx,arry){return (val==product_id);})==true){
locklist=locklist.filter(
function(val,idx,arry){
return (val!=product_id)&&(val!="0040000800000007");});
writeApplicationList("locked_list",locklist);
system.apps.update_home_lockface();ret=true;}else{
ret=false;}
return ret;};
edit_uninstall.delete =function(id){
DEBUG.info("delete: "+id);
var list=getApplicationList("apps_list");
DEBUG.info("  before:"+list);
var product_id=list[id[0]];
list[id[0]]=null;
DEBUG.info("  after :"+list);
var order_list=applications.orderAppsList(list);
writeApplicationList("apps_list",order_list);
this.write_apps_del_list(product_id);
try{
system.apps.uninstall_gadgets();}catch(e){};
var start=0;
if(id[0]<7){
start=apps_list.getCurrentPage();}else{
start=Math.floor((id[0]-7)/21);}
applications.addApps(order_list,start);
applications.setSize(1440,810);
this.releaseLock(id[1]);};
edit_uninstall.write_apps_del_list=function(id){
try{
apps_nvram_file.write({product_id:"home",filename:"apps_"+id+".del",data:""});}catch(e){
console.log(e.message);}
};
edit_uninstall.showErrMsg=function(text){
var btn_action_ok=function(){
confirm_errMsg.onFocus(false);
confirm_errMsg.setShow(false);
edit_uninstall.cursor=applications;
applications.setFocus(true);}
confirm_errMsg.setAction([btn_action_ok]);
confirm_errMsg.setMessageText(text);
confirm_errMsg.onFocus(true);
confirm_errMsg.setShow(true);
edit_uninstall.cursor=confirm_errMsg;};
edit_uninstall.key_hook=function(updown,keysym){
if(updown!=KEY_PRESS)return false;

var ret;
switch(keysym){
case TXK_UP:
case TXK_DOWN:
case TXK_RIGHT:
if(this.cursor.key_hook(updown,keysym)==true){
HOME_SOUND_PLAY(0);
return true;}else{
return true;}

case TXK_D1:case TXK_D2:case TXK_D3:case TXK_D4:case TXK_D5:
case TXK_D6:case TXK_D7:case TXK_D8:case TXK_D9:case TXK_D0:
ret=this.cursor.key_hook(updown,keysym);
if(ret==true)HOME_SOUND_PLAY("enter");
return ret;
case TXK_LEFT:
if((this.cursor==applications)&&
(this.cursor.key_hook(updown,keysym)==true)){
HOME_SOUND_PLAY(0);
return true;}else if((this.cursor==confirm)||(this.cursor==confirm_errMsg)){
ret=this.cursor.key_hook(updown,keysym);
if(ret==true)HOME_SOUND_PLAY(0);
return true;}else{
applications.selectCurrentProduct(false);
return false;}
case TXK_RETURN:
if((this.cursor==confirm)||(this.cursor==confirm_errMsg)){
this.cursor.key_hook(updown,keysym);
HOME_SOUND_PLAY("cancel");
return true;}else if(this.cursor==unlock){
var ret=this.cursor.key_hook(updown,keysym);
if(ret==false)HOME_SOUND_PLAY("cancel");
return ret;}else{
applications.selectCurrentProduct(false);
return false;}
break;
case TXK_ENTER:
if(this.cursor==applications){
var tmp=applications.getCurrentProduct();
if(tmp==null){
return true;}
this.id=tmp;
if(this.id[1]!=null){
if(this.id[3]==true){
if((this.id[4]==true)&&(getAdultSetting()==true))return true;
applications.setFocus(false);
confirm.setMessageText(LANG("LT_APPS_UNINSTALL_CONFIRMATION"));
confirm.setShow(true);
confirm.onFocus(true);
this.cursor=confirm;
HOME_SOUND_PLAY("enter");}
}
}else if((this.cursor==confirm)||(this.cursor==confirm_errMsg)){
ret=this.cursor.key_hook(updown,keysym);
if(ret==true)HOME_SOUND_PLAY("enter");
return ret;}else if(this.cursor==unlock){
return this.cursor.key_hook(updown,keysym);}
return true;
break;}
return false;};
function confirm_uninstall(product_id,func){
var ret=false;
var code=null;
var base_url=getHostName()+"/market/hs-uninstall-icon?product_id=";
http_request({url:base_url+product_id,
sync:true,
onload:function(status,header,body){
if(status==200){
code=eval("("+body+")").error;
ret=(code=="0");}else {
if(func){
func();}
edit_uninstall.showErrMsg(LANG("LT_W_NORMAL_ERROR"));}
}
});
return {ret:ret,code:code};};
function get_errsentence_uninstall(code,func){
var errsentence=null;
var ret=false;
var base_url=getHostName()+"/market/get-error-sentence";
http_request({
url:base_url+"?language="+system.locale.language.substr(0,5)
+"&code="+code
+"&api_name=hs-uninstall-icon",
sync:true,
onload:function(status,header,body){
if(status==200){
var result=eval("("+body+")");
if(result.text){
errsentence=result.text;
ret=true;}
}
}
});
if(ret==false){
if(func){
func();}
edit_uninstall.showErrMsg(LANG("LT_W_NORMAL_ERROR"));}
return {ret:ret,text:errsentence};};
var confirm_errMsg=new Confirmpanel(Confirmpanel.prototype.OPTION_TYPE_OK,[null],focus_moveto);
confirm_errMsg.setSize(980,440);
confirm_errMsg.translate=[240,0,0];
var confirm=new Confirmpanel(Confirmpanel.prototype.OPTION_TYPE_YES_NO,
[
function(){
var hide_confirm=function(){
confirm.onFocus(false);
confirm.setShow(false);}
var chk_uninstall=confirm_uninstall(edit_uninstall.id[1],hide_confirm);
if(chk_uninstall.ret==true){
edit_uninstall.delete(edit_uninstall.id);
hide_confirm();
edit_uninstall.cursor=applications;
applications.setFocus(true);}else if(chk_uninstall.code!=null){
var chk_errsentence=get_errsentence_uninstall(chk_uninstall.code,hide_confirm);
if(chk_errsentence.ret!=false){
hide_confirm();
edit_uninstall.showErrMsg(chk_errsentence.text);}
}
},
function(){
confirm.onFocus(false);
confirm.setShow(false);
edit_uninstall.cursor=applications;
applications.setFocus(true);}
],
focus_moveto);
confirm.setSize(940,400);
confirm.setButtonLabel(LANG("LT_YES"),LANG("LT_NO"));
confirm.translate=[240,0,0];

var notices_screen=new container({});
notices_screen.disclaimer=new container({});
var get_disclaimer=function(func){
var req=http_request({"url":getHostName().replace("https://","https://startup-user:start-disclaimer@")
+"/data/startup/ssl/disclaimer_mhc/apps_disclaimer.js",
"method":"GET",
"onload":function(status,header,body){
var ret=false;
try{
if(status==200){
notices_screen.disclaimer=secure_eval(body);
notices_screen.components.push(notices_screen.disclaimer);
ret=true;}
}catch(e){
DEBUG.error("Error to get \"apps_disclaimer14.js\".\n"+e.message);
ret=false;}
if(func){
func(ret);}
},
"sync":false,
});
return req;};
var edit_notices=new Editor();
edit_notices.request_status=-1;
edit_notices.cursor=null;
edit_notices.init=function(){
try{
notices_screen.disclaimer.create(1920-460,focus_moveto,focus.setShow);
return true;}catch(e){
return false;}
};
edit_notices.destroy=function(){
confirm_errMsg.setShow(false);
notices_screen.disclaimer.onFocus(false);
notices_screen.disclaimer.setShow(false);
notices_screen.disclaimer.destroy();
notices_screen.components.splice(0,notices_screen.components.length);};
edit_notices.setFocus=function(b,keysym){
this.onFocus(b,keysym);};
edit_notices.onFocus=function(b,keysym){
cancel_http_request(this.request_status);
if((b==true)&&(isDisclaimerNeeded()==true)){
launch_appli("0387878700000046","apps",getHostName());}else if(b==true){
var obj=this;
applications.slide(1,-800,24,function(){
loading_circle.init({width:200,height:200,});
loading_circle.setShow(true);
obj.cursor=null;
obj.request_status=get_disclaimer(function(bool){
loading_circle.setShow(false);
if(bool==true){
if(obj.init()==true){
notices_screen.disclaimer.setShow(true);
notices_screen.disclaimer.onFocus(true);
obj.cursor=notices_screen.disclaimer;}
}else{
confirm_errMsg.setMessageText(LANG("LT_W_NORMAL_ERROR"));
confirm_errMsg.setAction([
function(){
confirm_errMsg.onFocus(false);
confirm_errMsg.setShow(false);
apps_customize.cursor.setFocus(false);
apps_customize.cursor=menu;
apps_customize.cursor.setFocus(true);}
]);
confirm_errMsg.setShow(true);
confirm_errMsg.onFocus(true);
obj.cursor=confirm_errMsg;}
});});}else{
loading_circle.setShow(false);
applications.moveTo(APPS_POS_NORMAL,[1440,810],null,36);
try{
this.destroy();}catch(e){
return false;}
}
};
edit_notices.key_hook=function(updown,keysym){
if(updown!=KEY_PRESS)return false;
var ret;
var result;
switch(keysym){
case TXK_UP:
case TXK_DOWN:
case TXK_RIGHT:
case TXK_LEFT:
try{
result=this.cursor.key_hook(updown,keysym);
if(result instanceof Object){
ret=result.ret;
if(ret==true){
if("sound" in result){
if(result.sound!=-1)HOME_SOUND_PLAY(result.sound);}else{
HOME_SOUND_PLAY(0);}
}
}else{
ret=result;
if(ret==true){
HOME_SOUND_PLAY(0);}
}
}catch(e){
ret=false;}
break;
case TXK_ENTER:
try{
result=this.cursor.key_hook(updown,keysym);
if(result instanceof Object){
ret=result.ret;
if(ret==true){
if("sound" in result){
if(result.sound!=-1)HOME_SOUND_PLAY(result.sound);}else{
HOME_SOUND_PLAY("enter");}
}
}else{
ret=result;
if(ret==true){
HOME_SOUND_PLAY("enter");}
}
}catch(e){
ret=false;}
break;
case TXK_RETURN:
try{
result=this.cursor.key_hook(updown,keysym);
if(result instanceof Object){
ret=result.ret;
if(ret==true){
if("sound" in result){
if(result.sound!=-1)HOME_SOUND_PLAY(result.sound);}else{
HOME_SOUND_PLAY("cancel");}
}
}else{
ret=result;
if(ret==true){
HOME_SOUND_PLAY("cancel");}
}
}catch(e){
ret=false;}
break;}
return ret;};

var menu=new EditMenu(focus_moveto);
menu.addItem(new EditMenuButton(LANG("LT_APPS_MOVE"),edit_move));
menu.addItem(new EditMenuButton(LANG("LT_APPS_LOCK"),edit_lock));
menu.market_restriction=false;
var market_info=getMarketInfo();
menu.market_restriction=eval("("+market_info+")")["age_restriction"];
if(market_info!=false){
if(system.mdl_cfg.with_vc_market==true){
menu.addItem(new EditMenuButton(LANG("LT_APPS_UNINSTALL"),edit_uninstall));}
}
var footer_guide=new gtextbox({
width:1080,height:140,translate:[460/2,-460,0],
color:system.fdp_color.TEXT_ONBASE,align:LC_TEXT_ALIGN,valign:MIDDLE,font_size:28,
visible_p:false,
});
footer_guide.setGuide=function(word){
this.visible_p=isString(word);
setf_text(this,word||"");};
var guide=new gtextbox({
translate:[1920/2-(1920-460)/2,430,0],
color:[system.fdp_color.TEXT_SUB_ONBASE[0],
system.fdp_color.TEXT_SUB_ONBASE[1],
system.fdp_color.TEXT_SUB_ONBASE[2],
system.fdp_color.TEXT_SUB_ONBASE[3],],
font_size:48,align:CENTER,
width:1000,height:160,valign:MIDDLE,
text:"",visible_p:false,});
guide.default_width=1000;
guide.default_height=160;
guide.default_translate=[1920/2-(1920-460)/2,430,0];
guide.default_font_size=48;
guide.setGuide=function(word,param){
if(param){
this.width=param.width;
this.height=param.height;
this.translate[1]=1080/2-this.height/2-30;}else {
this.width=this.default_width;
this.height=this.default_height;
this.translate=this.default_translate.slice(0);}
this.font_size=this.default_font_size;
setf_text(this,word||"");
change_font_size_b(this);};
guide.setEnable=function(b,func){
var self=this;
if(b)self.visible_p=true;
self.transparentTo((b?255:0),(b?400:150),
function(){
if(!b){
self.visible_p=false;
if(func instanceof Function)func();}
});};
append_functions(guide,GraphicsLib);
append_functions(guide,AnimationLib);
if(SU_IS_SLOW_ANIM){
guide.transparentTo=AnimationLib.transparentToDirect;}
applications.init();
applications.showRestrictedState(getAdultSetting());
applications.addApps(getApplicationList("apps_list"),apps.PAGE_INDEX);
applications.setSize(1440,810);
var loading_circle=new loading_circle_item({width:200,height:200,
translate:[1920/2-(1920-460)/2,0,0],});
function set_cursor(obj,keysym){
apps_customize.cursor.onFocus(false,keysym);
apps_customize.cursor=obj;
apps_customize.cursor.onFocus(true,keysym);};
var apps_customize=stage({
symbol:"apps_customize",
translate:[0,0,0],
bg_translate:[0,0,0],
components:[
edit_back,
guide,
footer_guide,
applications,
menu,
underApps_menu,
notices_screen,
confirm,
confirm_errMsg,
unlock,
loading_circle,
focus,
],
key_hook:function(updown,keysym){
if(updown!=KEY_PRESS)return true;
force_redraw();
try{
if(this.cursor.key_hook(updown,keysym)==true){
return true;}
}catch(e){
console.log("key_hook: "+e.message);}
switch(keysym){
case TXK_LEFT:
if(this.cursor!=menu){
try{
this.cursor.setFocus(false);}catch(e){}
HOME_SOUND_PLAY("cancel");
this.cursor=menu;
this.cursor.setFocus(true);}
return true;
case TXK_ENTER:
if(this.cursor instanceof Editor){
}else{
break;}
case TXK_RETURN:
HOME_SOUND_PLAY("cancel");
if(this.cursor==menu){
apps.PAGE_INDEX=apps_list.getCurrentPage();
on_stage("apps");}else if(this.cursor==null){
this.cursor=menu;
this.cursor.setFocus(true);}else{
this.cursor.setFocus(false);
this.cursor=menu;
this.cursor.setFocus(true);}
return true;
case TXK_HOME:
case TXK_EXIT:
case TXK_APPS:
HOME_SOUND_PLAY("cancel");
try{
complete_off_stage(apps_customize);
discard_stage("apps_customize");}catch(e){
}
try{
discard_stage("apps");}catch(e){
}
return true;
default:
}
return false;},
"in":[{from:["default"],
hook:function(stg){
if(system.apps.lock_apps_list()==false){
throw new Error("[APPS_CUSTOMIZE] Failed to lock for \"apps_list\".");}
complete_on_stage(this);
menu.setFocus(true);
focus.visible_p=true;
LogReport.report(LogReport.OPERATE_HS,"apps.settings",{action:"start",pos:"-1"});
}
}],
"out":[{to:["default"],
hook:function(stg){
system.apps.unlock_apps_list();
complete_off_stage(this);}
}],
});
apps_customize.cursor=menu;
apps_customize.add_event_hook(system.screensaver,
function (stg,obj,ev,data){
switch(ev){
case system.screensaver.NO_OPERATION:
if(data==3){
if(_GLOBAL_.platinum_main)
if(_GLOBAL_.platinum_main.visible_p)
_GLOBAL_.platinum_main.return_func_from_apps();
if(_GLOBAL_.mystream)
if(_GLOBAL_.mystream.visible_p)
_GLOBAL_.mystream.return_func_from_apps();
try{
complete_off_stage(apps_customize);
discard_stage("apps_customize");}catch(e){
}
try{
complete_off_stage(apps);}catch(e){
}
discard_stage("apps");}
break;
default:
break;}
return false;});

