Skip to content

TTSB codes

woalk edited this page Oct 26, 2014 · 6 revisions

Beta 2.0 introduced a new way of saving Activity-specific settings. The TTSB settings code. With this code you can easily share, backup and copy settings from one device to another, from one app to another, from one Activity to another, and so on. Also you can change values more precisely when you're experienced with the TTSB settings code than you can with the UI (although the UI should work in 90% of planned cases).

TTSB settings code is structured as a multi-splitted String value. There are 4 levels of structure, each level with it's own markers and sperators (so you can exactly know in which level the code you're looking at is).

The first level is the easiest. There are general values saved, the most important values for TTSB, if you want - the tinting values. So there's the value status, which can be either status:0 or status:1, where 0 means, the status bar will not be tinted, and 1 means, it will. If last case is true, there's also the value s_color - the color code for the status bar. Can be either #AARRGGBB or #RRGGBB, but I recommend using alpha as it is automatically parsed to color with alpha and otherwise it could confuse a bit when there appear new numbers coming from nowhere. The same is for navbar, too - nav:0 or nav:1, and n_color for the color. You may see that the value is entered behind a colon. The multiple values are separated with a semicolon.

So, as an example, a simple code line would look like this: status:1;s_color:#FFFF0000;nav:1;n_color:#00000000. This will tint the status bar red and the navigation bar transparent.

There are 2 more values, s_plus and n_plus, these are int values, that expand the status/nav bar background's height for the specified value in pixels. This is helpful to hide the annoying one-pixel-line in many many ActionBars.

Now we get a bit more complicated, you should have heard the term View and what it stands for programmatically to proceed without hundreds of question marks in your mind. TTSB code offers you a default set of three views where you can apply extra settings to, settings like “move layout to fit status bar height”. This is required because TTSB removes the unused layout space behind the status bar and everything inside the app moves into it.

Use the setting code command view to start a ViewSettingsPack element. After the colon behind view, you're now in a level-2-setting. The separator between command and value is now >, the separator between settings is a comma.

The ViewSettingsPack knows 4 necessary settings: from: One of the values decview, content, cview (for more info, see below). This is the first View where TTSB should start counting the next setting - levels. This is an signed int value, saying how many levels TTSB should go down or up to find the View you're looking for. It uses getParent() for negative and getChildAt(0) for positive levels to find the view. childindexes: This is if you come to the point where the View you're looking for is not at child position 0 of another View, but maybe at 1 or 182. You can either specify just one single int value defining which child index TTSB should use at any call of getChildAt(childindex), or you can pass an int[] array, which will be worked from 0 to it's end with every call of getChildAt(childindexes[i]). The array is then a level-3-setting: the separator for values here is &. Now, the last and most important one: settings: Here are located the settings for this view, also as level-3-settings. The separator between command and value here is =, by the way.

Here you can set 3 more values: setFSW to either =0 or =1 to set the fitsSystemWindows attribute of this View to false or true, setCTP to set the clipToPadding attribute in the same way, and padding to set the padding of the View. Padding becomes a bit more complex because it is the only level-4-setting - it has 4 sides. Padding is set by padding=left@top@right@bottom. The values between the @s are ints defining the padding in dp. You can add also the following dynamic constants: At top padding you can set +status_h and/or actionbar_h to add the status bar/ActionBar height to padding. At the right you can add +nav_w to add the navigation bar width when it is at the right of the screen (landscape mode). And at the bottom you can add +nav_h to add the nav bar height.

You can set the settings of cview (most time the best choice, it's the first view inside of the Activity's layout content), content (the Content View set by setContentView(View view), and decview (the “Decor View”, the outest View of all, containing everything, including content behind status bar etc.) also directly, without using view:(...), by just writing cview:(...), decview:(...) or content:(...) and just directly writing the settings value. The settings you can set to them are only the level-3-settings from the settings setting, without the command setting.

How can I know which View I have to tint? Most time it is a try-and-error process and needs it's time, but there is a helper inside TTSB, if you have access to LogCat log files of Android. TTSB prints at every start of an Activity the full layout tree of this Activity, so you can see where which View is.


For example I'm taking the difficult Twitter MainActivity. It uses completely different settings than every other Activity from Twitter (all the others are working fine with the automatic option).

The default setting for Twitter should be: status:1;s_color:#FF55ACEE;nav:1;n_color:FFFFFFFF;s_plus:0;n_plus:0;cview:setFSW=1&setCTP=0

This is our starting point for changing it to a working one.

The LogCat output is:

>TTSB: [ INFO: ] Activity is
>TTSB [VIEWTEST] ┕$DecorView
>TTSB [VIEWTEST] ┕╾android.widget.LinearLayout
>TTSB [VIEWTEST] ┕╾╾android.view.ViewStub
>TTSB [VIEWTEST] ┕╾╾android.widget.FrameLayout (ContentView)
>TTSB [VIEWTEST] ┕╾╾╾╾android.widget.LinearLayout
>TTSB [VIEWTEST] ┕╾╾╾╾╾android.widget.LinearLayout
>TTSB [VIEWTEST] ┕╾╾╾╾╾╾android.widget.ImageView
>TTSB [VIEWTEST] ┕╾╾╾╾╾android.view.View
> [...]

As you can see, the cview would be the 5th one in the list (the one starting with com.twitter.internal...). It seems like it doesn't work. Trying content, to get the one marked with ContentView, does also not work. So you should consider using a padding.

The finally working code is: status:1;s_color:#FF55ACEE;nav:1;n_color:FFFFFFFF;s_plus:0;n_plus:0;cview:setFSW=1&setCTP=0;content:padding=0@0+status_h@0@0+nav_h

Just to describe, you can do this also with the view command instead of the direct commands: The ContentView is at level 2 below the DecorView (you can see this at the bars in front of the View name). But it is not the first child of the first LinearLayout, it is the second. So we have to set childindexes.

The code would be: view:from>decview,levels>2,childindexes>0&1,settings>padding=0@0+status_h@0@0+nav_h (childindexes is zero-based, while levels is 1/(-1)-based).

This code does also work very nice.

Most of this you can add by using the Advanced UI - but it can be very helpful to know, what every setting does. Now, thank you for taking time for reading this long article, if you really did. Have fun with the TTSB-produced look and feel of your KitKat smartphone!

You can’t perform that action at this time.