Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 305
Registered: ‎02-14-2012
My Device: BlackBerry Passport / Nokia N950
My Carrier: -

Change Theme - edit "bar-descriptor.xml" at runtime

Hi Community! Smiley Happy

 

For may users this is a important Topic, but as a developer I were so far unable to satisfy everyone. But I've found something new:

 

I just realized last week that the App FancyTran (looks like a native App) has a setting to switch the theme from bright to dark and back. This setting needs a restart of the application but apart from that it works great.

 

Since I thought so far that it is impossible I contacted the developer of FancyTran instantly but got no reply so far.

 

I'm guessing the App is editing its own "bar-descriptor.xml" File at runtime. When I edit this file for my App via the Target File Navigator from the SDK it works, too. But when I try to read the file from within my code I get a empty file. (maybe no access to it?)

 

Is it possible to open and edit this file by the own App? Perhaps there is something wrong with my C++ code, I'm not sure. Has anyone tried this before? Smiley Happy

Developer
Posts: 82
Registered: ‎11-04-2011
My Device: PlayBook, DAC, SQN100-3, STL100-1, STL100-2
My Carrier: MTS RUS

Re: Change Theme - edit "bar-descriptor.xml" at runtime

[ Edited ]

 

You can change theme in the bar-descriptor.xml in runtime.

For example, pass 1 for bright and 2 for dark theme:

 

void ApplicationUI::changeTheme(int type) {
if (1 != type && 2 != type) {
return;
}

 

//const QString values[] = {"<env var=\"CASCADES_THEME\" value=\"bright\"/>", "<env var=\"CASCADES_THEME\" value=\"dark\"/>"};

const QString values[] = {"<cascadesTheme>bright</cascadesTheme>", "<cascadesTheme>dark</cascadesTheme>"};
QFile file("app/native/bar-descriptor.xml");
QByteArray content;

 

if (!file.open(QIODevice::ReadOnly)) {
return;
} else {
content = file.readAll();
file.close();
}

 

if (content.length()) {
if (!content.contains(values[type - 1].toAscii())) {
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
return;
} else {
if (content.contains(values[type % 2].toAscii())) {
content = content.replace(values[type % 2].toAscii(), values[type - 1].toAscii());
} else {
content = content.replace("</qnx>", (values[type - 1] + "\n</qnx>").toAscii());
}

 

file.write(content);
file.close();
}
}
}
}

 

But after your application restarts nothing happens: theme remains the same.

Developer
Posts: 305
Registered: ‎02-14-2012
My Device: BlackBerry Passport / Nokia N950
My Carrier: -

Re: Change Theme - edit "bar-descriptor.xml" at runtime

[ Edited ]

But after your application restarts nothing happens: theme remains the same.


Hi xnike,

 

I'm currently on the go and can't test. I changed the file on the device using the Target file navigator from the SDK. And changing the setting in the file this way worked without reinstalling the App.

Could you maybe retest it using the 10.1 SDK setting?

 

<cascadesTheme>dark</cascadesTheme>
<cascadesTheme>bright</cascadesTheme>

Maybe the reason nothing changed is because you've used the new kind of setting.

I will check out your code later. I've used a different path, I thought the active path of my App is in the data folder and I used the absolute path instead of relative.

At least the developer of the App FancyTran found a way. There must be a dirty trick to do it! Smiley Wink

 

 

 

 

Developer
Posts: 82
Registered: ‎11-04-2011
My Device: PlayBook, DAC, SQN100-3, STL100-1, STL100-2
My Carrier: MTS RUS

Re: Change Theme - edit "bar-descriptor.xml" at runtime

Yes, you are right.

When I changed constants to the old style, all works great:

const QString values[] = {"<cascadesTheme>bright</cascadesTheme>", "<cascadesTheme>dark</cascadesTheme>"};

Developer
Posts: 305
Registered: ‎02-14-2012
My Device: BlackBerry Passport / Nokia N950
My Carrier: -

Re: Change Theme - edit "bar-descriptor.xml" at runtime

So I guess we've found the Sangreal of Cascades! Smiley Very Happy

 

...can't wait to get home... Smiley Wink

Developer
Posts: 135
Registered: ‎04-25-2009
My Device: Z30
My Carrier: AT&T

Re: Change Theme - edit "bar-descriptor.xml" at runtime

I can confirm this works!!!!!!!!!!!

 

Wow, thank god.

Developer
Posts: 101
Registered: ‎12-02-2012
My Device: Z10 LE, PlayBook 32GB
My Carrier: Beeline

Re: Change Theme - edit "bar-descriptor.xml" at runtime

Why I haven't seen this thread earlier?

It's very useful Smiley Happy



My BB10 apps: Photo Memo | TriQuick | SkidStone | MeeBirthdays
If anyone has been helpful to you, please show your appreciation by clicking the button inside of their post.
Developer
Posts: 135
Registered: ‎04-25-2009
My Device: Z30
My Carrier: AT&T

Re: Change Theme - edit "bar-descriptor.xml" at runtime

Nevermind, this doesnt work when you build a release version, anyone know how to fix this?

 

This method only works when running debug build or unsigned build. It breaks when using release version. 

Developer
Posts: 305
Registered: ‎02-14-2012
My Device: BlackBerry Passport / Nokia N950
My Carrier: -

Re: Change Theme - edit "bar-descriptor.xml" at runtime

Ouh, you're right. Thats not good... :-(

 

Hmm... I wonder how FancyTran was able to solve this?

Developer
Posts: 188
Registered: ‎07-19-2012
My Device: Z10 Limited Edition and Dev Alpha C
My Carrier: Movistar-Venezuela

Re: Change Theme - edit "bar-descriptor.xml" at runtime

How I can create a ToggleButton to change, the Dark to Bright Theme in QML? as in Calendar and Contats in 10.2?


Follow me in Twitter:

@Marcossit

BBM Channel:

MarcossitDev: C0002C366  

DeviceSuite For BlackBerry 10:

Link to Download DeviceSuite:

Support was successful? Accept as Solution and click on: