Theme Settings

Mode Layout
Theme color
Choose your colors
Background Color:
Reset

Android firmware smart tv box development some experience sharing

Android firmware smart tv box development some experience sharing

First, running and debugging:

    In the mobile version of Android development, to run our program, you can choose to use the emulator or USB connection phone to run. However, when developing the TV (set-top box) version, since the current output resolution of the Smart tv box is above 720P, it is not very convenient to use the simulator to simulate, and the method of connecting the data lines is also inconvenient. Objectively limited by the length of the data line and the interface on the TV set (set-top box), and this time before our development, we found that the device was not recognized by the data cable connection (maybe related to the driver). In general, the methods used to develop on mobile phones have not been easy to use on TVs (set-top boxes). How to debug and run, can not be packaged every time, and then install the package by other means? The answer is of course: no.

     Here are a few adb commands that I found very useful in this development on TV (set-top box):

1.adb connect [ip]:

    With this command, you can connect to the device with the specified ip. With this command, the previous problem can be solved. Just connect our computer and TV (set-top box) to the same LAN, you can connect to the corresponding device, and then you can run or debug the program directly in eclipse. It is. Corresponding

      Adb disconnect [ip]

The function is believed to be understood by everyone and will not be explained.

2.adb uninstall [package]

    Look at the name and I believe everyone knows that this command can be used to uninstall the application. Uninstalling an application on a TV set (set-top box) is not as convenient as using it on a mobile phone. All of them must be operated with a remote control. This command is much more convenient. Moreover, during this development process, due to the limited equipment of ours, several people use a TV set, and often need to uninstall the different signature programs installed by others. This command saves us a lot of time.

3.adb shell input text ****

The function of this command can be guessed literally, which is used to input text. When we debug the program, we have to type the text in many cases. This may not be a problem on the mobile phone. On the TV, pressing the keyboard with the remote control will really make you crash. This command is simply a gospel!

     The above three are the three commands I use most frequently in this development, and the second and third use must be meaningful after using the first one to connect. Of course, there are a lot of adb commands, so I won't go into details here. If you are interested, you can search for them yourself.

Second, focus control

Regarding the focus, in mobile phone development, we may be more concerned about the logical processing of a control when the focus changes. When developing on a TV set (set-top box), each control can only be operated with focus, so it is a very important issue to ensure that the controls that need to be operated can get focus and control the focus. For example, if there are multiple controls in a layout, when clicking the up, down, left, and right direction keys of the remote control, the focus will be moved to which control, which controls are only displayed, but do not need to get focus and so on.

     In order to ensure the controllability of the above problems, we can achieve this by:

1. Control the control to get focus

Android:focusable="true/false"

When this property is set to true, it means that the current control can get the focus, and false means that the focus is not available. Correspondingly, we can also set it in the program with the following code:

v.setFocusable(true/false);

2. Control the next control to get the focus when pressing the remote control up, down, left and right

Android: nextFocusUp="@+id/..."

Android: nextFocusDown="@+id/..."

Android:nextFocusLeft="@+id/..."

Android:nextFocusRight="@+id/..."

I believe that there is no need to explain more, and the meaning of these four attributes can be clearly understood from the literal meaning. Correspondingly, it can also be implemented in the code:

v.setNextFocusUp(id);

v.setNextFocusDown(id);

v.setNextFocusLeft(id);

v.setNextFocusRight(id);

Third, UI adaptation

UI adaptation is a cumbersome and unavoidable thing in Android development. In this development, it also encountered this problem. We developed this time, mainly adapting to 1080p and 720p resolutions. The initial idea is that since these two resolutions are adapted, the resources for these two resolutions are specified, ie

    Drawable-1920×1080

    Drawable-1280×720

Accordingly, the dimensions at the corresponding resolution are provided:

    Values-1920×1080

    Values-1280×720

When we developed, there was a 42-inch TV box with two set-top boxes. The TV supports up to 4k resolution, and the box can only output 720p resolution. According to our adaptation strategy, testing on TV and set-top boxes proved to be correct. However, when the development was over and sent to the test side, they used a 32-inch 1080p TV, and there was a problem. The program crashed directly and could not run. By looking at the log, it was found to be an OOM problem. After the analysis of colleagues, I feel that because the tested TV is 1080p, but the size is small, dpi is high, all the pictures will be compressed, resulting in OOM. Finally, I changed the adaptation strategy and adopted

    Drawable-sw1080dp

    Drawable-sw720dp

Accordingly, the dimensions at the corresponding resolution are provided:

    Values-sw1080dp

    Values-sw720dp

Solved the problem of program crash.

    Although the problem is solved, I think the reason is that although we used the resolution to adapt, but in the values ​​file, it uses the dp unit, but the TV developed at that time, just dpi is 160, which makes the UI shows normal. Therefore, using the initial adaptation scheme, it is also possible to change the unit of size in values ​​to px. Of course, this has not been verified, and I will verify it later.

Fourth, the shadow of the program to achieve

In order to make the interface beautiful and dynamic, in the TV app design, the effect of reflection and shadow is often used. Our demo design is no exception. In development, I am responsible for the module needs to achieve reflection and shadow, originally wanted to let the artist to cut the map, but the artist is not willing, let us use the program to achieve, the negotiations for a long time without results, have to come by themselves. The generation of the reflection was realized by another colleague who wrote a public method. I won't share it with you here. The principle is basically to invert the original image, draw it on the canvas, and then add a translucent mask. nailed it.

     The shadow effect is my own implementation. In fact, there are a lot of tutorials on shadows on the web, but it doesn't work for me. What I need is to add a shadow effect around the image of a rounded rectangle. After a long period of consideration, the final solution is to add a rectangular shadow to the four sides of the original image, and then draw a fan-shaped shadow in the four rounded corners. Not much to say, directly on the code:

Android firmware smart tv box development some experience sharing

All comments

Leave a Reply