[Android Head-Units] surfer63:
Modifying the layout of the Joying Radio app.

version 0.2 See changelog at the bottom of this post.

This works in essence for most apks. There are some differences where the layout is defined in xml files or in json files.

Requirements:

java runtime version 7 or better.

apktool: (https://ibotpeaches.github.io/Apktool/)

Editor that handles unix LF correct. Any linux or Mac OS/X editor will do. Notepad on Windows does NOT. On Windows use Notepad++: (https://notepad-plus-plus.org/download/) for example.

Optional: ApkPack: (http://mirrors.gtxlabs.com/joying/3_Misc_Tools/ApkPack/)

Read(!!) the basic apktool Basic, Decoding, Building: (https://ibotpeaches.github.io/Apktool/documentation/) documentation to get a general understanding for the apk structure. It's about 1½ page and prevents a lot of questions.

Knowledge of working in a terminal / command box (some people still call this a DOS-box). These actions are not done using a nice graphical interface/program.

Installation of requirements:

Java: Either use Sun java: (https://www.java.com) for all platforms, Openjdk: (http://openjdk.java.net) for linux, or Mac OS/X's own java version (make sure it is version 7 or better)

apktool: See here: (https://ibotpeaches.github.io/Apktool/install/)

ApkPack.exe: This one can be used to pack/unpack the Allapp.pkg. This allows you to get the apks. Another option is to "adb pull" the original from your unit to work on.

apkPack is a windows binary but runs fine under wine.

General note

An apk file is actually nothing more than a zip file. This means that you can also unzip/rezip an apk. For only modifying buttons and other graphical elements, this is sufficient. When you also want to modify the layout of the main screen or sub-screens, you really need apktool to decompile/compile. If you want to do minor code changes, you also need apktool. (Also a java jar file is also nothing more than a zip file).

Note for Windows users

Text files contain lines (obvious). These lines end with CRLF ("\r\n") line endings on Windows (and MAC versions before OS/X). On linuxes/unixes they end with "\n".

For some files inside an apk this really matters! That's why you need an editor that can handle that correctly, like for example Notepad++.

Android is Case sensitive! Uppercase and lowercase characters do matter and are different (unless when used in strings)

Getting the radio apk

Copy one of my radio mods.

Use ApkPack.exe to get the apk out of the Allapp.pkg.

Use adb to copy the apk from the unit like "adb pull /system/app/JY-1-C9-Radio-V1.0/JY-1-C9-Radio-V1.0.apk ." (the last "." is not a typo). This assumes you already made a connection via USB or tcpip

Download the apk from "http://mirrors.gtxlabs.com/joying/1_Firmware/".

Install framework-res for use in apktool

This step might not be necessary for the radio apk, but is necessary if you modify apks that use system functions. It's anyway better to do this step.

Every Apktool release contains internally the most up to date AOSP framework at the time of the release. This allows you to decode and build most apks without a problem. However, manufacturers add their own framework files in addition to the regular AOSP ones. To use apktool against these manufacturer apks you must first install the manufacturer framework files.

Inside the 5009_60.zip (or previously the 5009_20.zip), you will find inside "/system/framework" the "framework-res.apk". Extract that one from the zip.

In a terminal window, you do on the command line:

<path_to>/apktool if <path_to>/framework-res.apk

You need to do this step for every new ROM upgrade from Joying.

Decompile the apk

Create some folder where you want to work on the apk.

Inside that folder do inside a terminal:

<path_to>/apktool d <path_to>/JY-JY-1-C9-Radio-V1.0.apk

(Change forward slash "/" to backward slash "" on windows.).

This will create a folder "JY-JY-1-C9-Radio-V1.0" containing the decompiled apk including the from-binary-to-UTF-8 text converted AndroidManifest.xml.

AndroidManifest.xml	(file)
apktool.yml	(file)
assets	(folder containing "all kind of things" needed by the apk, but not belonging to the standard res structure. This can be images, files, scripts or even other apks)
original	(folder containing original AndroidManifest.xml)
res	(folder containing layout, graphics, translations, etc.)
smali	(folder containing the decompiled code in "smali" format)

The "res" folder contains a large amount of sub folders.

The three most important folders are:

drawable-land-nodpi-v4	(contains resolution unspecific graphic elements for landscape mode)
drawable-nodpi-v4	(portrait version of above. Only needed because the original apk contains a corrupt png and can't be recompiled)
raw	(contains screen config/layout in json formatted files. Most apks have the config/layout in straight xml)

Initial steps when using the original apk

When using the original apk (instead of one of my mods), you need two extra steps:

- Copy the "ic_point.png" from the folder "drawable-land-nodpi-v4" to the folder "drawable-nodpi-v4". As mentioned: that png is corrupt in the original "drawable-nodpi-v4" which makes that you can't recompile the apk.

- You need to make a small code change in smali to get rid of the "PS:" prefix in front of the PS-text containing the station name.

Edit the "smali/com/syu/radio/RadioController.smali" in a good editor! (NOT Notepad).

Search for the string "PS:" which is in line 1557.

Change:

const-string v3, "PS:"

into

const-string v3, ""

Relation between the graphical elements and the layout definition

All the graphical elements like buttons, the frequency ruler and numbers for the (big) frequency are in "res/drawable-land-nodpi-v4".

The layout definition is in "raw/radio_ui.json". The "radio_ui.json" determines which graphical elements are used, and how and where they are positioned. The "radio_ui.json" also determines which texts in which font and font size are used and where they are positioned.

Examples:

The big frequency ruler is named "type":"HorizontalRuler" in the radio_ui.json and defined by the graphical element "drawables":["bk_ruler"], where "bk_ruler.png" is the image. Note that in the json file no extensions (.png) are used.

The "type":"StationView" determines the 6 buttons with inactive (unselected: *_n), active (current selected: *_p) and "on_click/on_tap" (*_p) state. Note also that you will find a ' "extras":[30,0,0,0],' in these sections. This will offset the x-postion 30 pixels to the right. If you want to center the text, change it to: "extras":[0,0,0,0],

The Frequency numbers and the buttons left/right around it. The frequency numbers are the images "num_0.png" to "num_9.png", plus the "num_point.png". The buttons left/right are the "drawables":["ic_freqm_n", "ic_freqm_p"] (down) and "drawables":["ic_freqp_n", "ic_freqp_p"] (up).

The PS, TA, AF, PTY etcetera can easily be found. These do not contain "drawables" (images), but are defined by textsize and text color.

All elements are positioned in a "X0,Y0,X1,Y1" or "top_left_X, top_left_Y,bottom_right_X, bottom_right_Y] rectangle.

Actually this is all.

You can play with it to change the layout.

If you want to change color or form of buttons, ruler or other elements, you have to modify exiting elements or create new elements in either Gimp or Photoshop or another package you are familiar with.

Note1: most PNGs are stored in "optimized" color mode (only store used colors) instead of "RGB" color mode (use full color palette). On small PNGs this can reduce the files by a factor 2, thereby reducing your apk size from ~2 MB to ~1.5 MB. This also means that in Gimp or Photoshop (or whatever), you first need to set the color mode to "RGB" before altering the elements, and before saving them back to "optimized".

Note2: Remember that Android is case-sensitive. When working with the layout or the graphics, keep this in mind!

Recompile the apk

When you are done "playing" and you want to experience the great and glorious app you created, you need to recompile it.

In your folder where you have the unpacked folder "JY-JY-1-C9-Radio-V1.0", you do a:

<path_to>/apktool -c b JY-JY-1-C9-Radio-V1.0

- Note that you specify the folder name, not some apk name

- the "b" is for build.

- The "-c" is to use the original AndroidManifest.xml

If you see errors, please first google for it before asking questions. There is so much to find on this stuff on the web.

If your apk compiled successfully (don't mind the warnings), you will find it inside "JY-JY-1-C9-Radio-V1.0/disẗ" as a new "JY-JY-1-C9-Radio-V1.0.apk".

Push the apk to your unit.

Simply use one of the scripts from my repository. Make sure to have adb in the right place (windows) or change the script accordingly. Read the Readme: (https://github.com/hvdwolf/Joying-RootAssistant/blob/master/Radio-Mod/Readme.md) on my github repository inside the "Radio-Mod" section for info on how to use the scripts to install it on your unit.

Troubleshooting

Q1. adb or adb.exe can't be found.

A1. Make sure you have adb installed. Use the proper path to adb.

Q2. I can't get a connection to the unit.

A2. Search the web and find out how adb should work, see also the readme in my Radio mods. On 6.0.1 first activate adb over tcpip, or conect via USB.

Q3. You get an android icon instead of the Radio icon and when you tap it, your unit says "application not installed".

A3. Reboot, check again and try another time to copy it to your unit. If nothing works (after a couple of attempts), reboot and copy the original radio apk back in place, reboot again.

Q4. You rebooted the unit and you hear music, but you don't see a Radio icon.

A4. Same as Q3/A3: so do the same. This is due to the fact that the Radio function is a 2-step approach on the Intel joying units. The CarRadio.apk (hidden) does the real work. The Radio.apk is just the visible "tweak and go" app.

Changelog:

Version 0.2, 06 June 2017; few typos and rephrasing; Add reference to working in terminal / cmd box; Add paragraph on installing framework-res.apk as dependency for apktool.

Version 0.1, 05 June 2017; first version