Languages

Menu
Sites
Language
Gear : Can you explain settings.xml and updatedsettings.xml

I don't have Gear 2 and Gear manager and it is hard to understand how this works.

1- Define settings.xml in the widget

2- It is going to be parsed by Gear Manager with default value

3- User make update and then Gear manager sends  updatedsettings.xml file

4- Widget App must parse it and the ...?

Set the changes to localeStroge or settings.xml or ...?

 

I can't understand the last step. .. sample code would be perfect

 

Edited by: Anonymous on 08 May, 2014

Responses

14 Replies

someone knows how this works?

how to receive the notification when the settings are changed?

Anyone has a working code for this?

Rumata Estorish

Hello!

Settings are placed to wgt-private/updatedsettings.xml when they're changed only (if I understood correctly). So, samsung gives you example, how you can receive this file, which is xml:

function readUpdatedSetting(doSetting)
{
   if(!doSetting)

   return;

   var path = "wgt-private/updatedsettings.xml";
   tizen.filesystem.resolve(path, function(file) 
   {
      file.readAsText(function(text)
      {
         doSetting((new DOMParser()).parseFromString(text, "text/xml"));
      });
      file.parent.deleteFile(path);
   });
}

 

and if you ask, what should you write in doSettings, I can write following code:

function procSettings(set){
    
	alert(set.getElementsByTagName("SwitchButton")[0].getAttribute("switch_checked"));
	
}

function onsettingsclick(){
	readUpdatedSetting(procSettings);
}

and don't forget to write correct package name of you application in settings.xml

Rumata Estorish

To be correct, file is placed to /opt/usr/apps/YOUPACKAGENAME/data/updatedsettings.xml

or

tizen.filesystem.resolve("wgt-private/updatedsettings.xml" ...

mekabe remain

Hi,

I could not understand how to parse the received settings.

Can anyone give an example code ?

I know that the API documentation has the sample code (which is alsd given above) but I didn't understand how to read the individual updated setting.

Any help would be nice.

 

Thx..

Rumata Estorish

Hi! I think you should parce it with XML Parcer, you should print it somehow and see what you need from that file.

mekabe remain

I still could not understand how to implement that.

Let me tell you what I understood and what not...

 

1. When the settings on phone is updated, I should get a trigger on my wear side app  What is this trigger ? When shall I call ."readUpdatedSetting" in  my code ?

2. You say above that in "doSettings" I can write :

unction procSettings(set){
    
	alert(set.getElementsByTagName("SwitchButton")[0].getAttribute("switch_checked"));
	
}

function onsettingsclick(){
	readUpdatedSetting(procSettings);
}

but these are not in dosettings. which one will call which ?

I assume , onsettingsClick is to be called when settings is updated. But how will that happen ?

3. Here, I understand that parser will parse the string variable text, but where will that be written ?

  doSetting((new DOMParser()).parseFromString(text, "text/xml"));

Thanks.

mekabe remain

Btw, without implementing "readUpdatedSetting" , I tried to access:

/opt/usr/apps/YOUPACKAGENAME/data/updatedsettings.xml

But there is no "data" folder in my app folder 

 

How will that folder come there ?

 

mekabe remain

I'm helpless.Please help me....

 

AVSukhov

Hello,

I think the algorithm should be as follows:

1. Create app (f.e. i use standalone app)

2. Add settings.xml and strings.xml to setting folder of your project

3. Add tizen:app-control with "remote_settings" operation to config.xml

4. Add "filesystem.read" privilege to config.xml

5. Add "readUpdateSettings()" function to window.onload event

6. In "readUpdateSettings()" function read updatesettings.xml and change your content according settings

If your app is running, after change settings in Gear Manager appcontrol relaunch your app and readUpdateSettings invoked.

If your app isn`t running, after user restart app readUpdateSettings invoked.

My code following:

index.html

<body>
  <div class=contents>
      <div style='margin:auto;'>
  		<span class=content_text id=textbox></span>
  	</div>
  </div>
</body>

config.xml

<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets" xmlns:tizen="http://tizen.org/ns/widgets" id="http://yourdomain/testBasic" version="1.0.0" viewmodes="maximized">
    <tizen:application id="0jBO4g3zSQ.testBasic" package="0jBO4g3zSQ" required_version="2.2"/>
    <content src="index.html"/>
    <feature name="http://tizen.org/feature/screen.size.all"/>
    <tizen:privilege name="http://tizen.org/privilege/filesystem.read"/>
    <icon src="icon.png"/>
    <name>testBasic</name>
    <tizen:app-control>
   <tizen:src name="index.html"/>
   <tizen:operation name="http://tizen.org/appcontrol/operation/remote_settings"/>
</tizen:app-control>
</widget>

settings.xml (from example)

<?xml version="1.0" encoding="utf-8"?>
<Application xmlns:android="http://schemas.android.com/apk/res/android" type="application" version="001" language="english">
<packageName>0jBO4g3zSQ</packageName>
<DisplayName>@Clock_Name</DisplayName>
<Settings>
<Item id="24format" title_type="title_subtitle" setting_type="checkbox">
<Title>@24_Hour_Format</Title>
<SubTitle options="checkbox">@Hour_Format_Item2</SubTitle>
<CheckBox id="24format" checked="yes">
<CheckBoxItem>@Hour_Format_Item1</CheckBoxItem>
<CheckBoxItem>@Hour_Format_Item2</CheckBoxItem>
</CheckBox>
</Item>
</Settings>
</Application>

strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resource>
<string name="Clock_Name">Weather Clock</string>
<string name="24_Hour_Format">Use 24-hour format</string>
<string name="Hour_Format_Item1">1:00 PM</string>
<string name="Hour_Format_Item2">13:00 PM</string>
</resource>

main.js

window.onload = function () {
    // TODO:: Do your initialization job

    // add eventListener for tizenhwkey
    document.addEventListener('tizenhwkey', function(e) {
        if(e.keyName == "back")
            tizen.application.getCurrentApplication().exit();
    });
    
    readUpdatedSetting(doSettings);
};

function doSettings(value) {
	var box = document.querySelector('#textbox');
	if(value == "yes") {
		box.innerHTML = "Selected";
	} else {
		box.innerHTML = "Deselected";
	}
}
function readUpdatedSetting(doSetting)
{
   if(!doSetting)
   return;

   var path = "wgt-private/updatedsettings.xml";
   tizen.filesystem.resolve(path, function(file) 
   {
      file.readAsText(function(text)
      {
         var xml=(new DOMParser()).parseFromString(text, "text/xml");
         doSettings(xml.getElementsByTagName("CheckBox")[0].getAttribute("checked"));
      });
      file.parent.deleteFile(path);
   });
}

 

mekabe remain

thank you.

 

This was a very nice explanation. And it works.

 

But now I have a problem with free text setting. I want to get a free text from user in settings. I got that it is done by "inputbox" type. Actually it makes a free entry in the settings. But when I try to ready it with 

xml.getElementsByTagName("InputBox")

all I get is "undefined"

 

this works with checkbox but what can I do to get free text ?

thx

Marco Buettner

Open your updatedsetting.xml and look for the structure of the XML file

mekabe remain

how do I reach that file ? where is it ?

 

thx

 

AVSukhov

Hello,

You can find this file under "wgt-private" virtual root location.

You can read this file using Fylesystem API and determine the structure of the file and parse it.