LightBlog

vendredi 12 mai 2017

How to Add Custom Buttons to the Nav Bar on the Samsung Galaxy S8/S8+

Samsung’s Galaxy S8 and Galaxy S8+ are two of the hottest smartphones on the market, largely thanks to the great strides Samsung made with their display technology. Since Samsung aimed to reduce bezels as much as possible with their new flagship devices, the company has finally gotten rid of the capacitive keys that were once staples of Samsung hardware. In its place are software navigation keys, which can be modified to some extent within the Samsung Experience UI.

As usual, however, the stock implementation of the nav bar tuner is quite lacking in its customizability. Most of the customization centers around the home button – you can change the sensitivity and whether or not it directly unlocks the phone. While there is an option to change the button layout, the only layout you can switch to is an inverted layout whereby the back and the recents key are flipped.

Galaxy S8, Galaxy S8+, nav bar Galaxy S8, Galaxy S8+, nav bar

We at XDA-Developers are always looking beyond what the manufacturer offers in order to find more ways to customize your phone. That’s why today we’re introducing a method to add additional buttons to the navigation bar on the Samsung Galaxy S8 and S8+.

If you’ve been following the XDA Portal (as you should be), you may have seen my post last month about how nav bar customization could be performed in Android 7.X devices without requiring System UI mods, custom ROMs, or root access of any kind. The method involves directly modifying the settings that are responsible for tuning the nav bar, even though the GUI to modify the nav bar has been hidden from the user. This is because the code that makes up the hidden nav bar tuner has been in the Android Open Source Project (AOSP) repositories since Android Nougat, but it wasn’t until Android O that Google exposed this activity under the System UI Tuner. However, so long as the software shipped on your device running Android Nougat did not remove the code behind the nav bar tuner entirely, it’s possible to use this feature without waiting.

Modifying the navigation bar involves sending shell commands either through ADB or an app that has been granted the WRITE_SECURE_SETTINGS permission. Due to the fact that messing with ADB is something many people are not familiar with, XDA Senior Member paphonb developed an app called Custom Navigation Bar to make everything easier for you.

As thousands of people began testing his app, many users on the Galaxy S8 and Galaxy S8+ began encountering frequent System UI crashes when attempting to use the app. We thus assumed that modifying the nav bar beyond Samsung’s implementation was impossible – but that assumption has since been found wrong. Here’s how to do just that.

Adding Custom Buttons to the Nav Bar on the Galaxy S8 or S8+

After some initial testing, we discovered that the same shell commands we were sending in my original tutorial also work on the Galaxy S8 and S8+, but with one major caveat. The original back, home, recent, and IME switcher keys MUST be present no matter what layout you use. If any one of these keys is missing, the System UI will begin to repeatedly crash. Furthermore, any key that you add to the nav bar will look a bit strange when the Samsung nav bar automatically changes colors to a white background, but I’m looking into ways around this minor inconvenience.

Anyways, let us dive in to the commands you’ll need to learn in order to modify the nav bar on your Samsung Galaxy device. The first thing you’ll need to do is to set up ADB on your machine.

Setting up ADB

First, download the ADB binary straight from Google for your particular OS and extract it to a separate directory on your computer. Next, install the proper driver for your Samsung phone. Then, enable “USB Debugging” in Settings –> Developer Options. If you don’t see Developer Options, then you will need to enable it by going to Settings –> About Phone then tapping on Build number 7 times. Finally, ensure that ADB is working by starting a command prompt in the same directory as the ADB binary (hold shift + right-click –> “open command prompt here”) and run the following command:

adb devices

If you see your device’s serial number (and it doesn’t say unauthorized), you’re golden. If you see a pop-up on your phone asking you to grant your computer ADB access, then say yes. If you don’t see either happen, then try rebooting your computer/phone and re-plugging it into your computer. Otherwise, try re-installing the driver.

Modifying the Nav Bar – ADB Method

The syntax to modify the navigation bar is as follows:

settings put secure sysui_nav_bar "key(KEYCODE_CONSTANT:file:///path/to/icon.png),back;home;recent,menu_ime"

where KEYCODE_CONSTANT refers to the constant of a KeyEvent and the icon path is the file URI that allows you to specify a custom icon to add to the nav bar. I’ve found that 64×64 size icons work pretty well for our purposes. You can download many free icons from the IconsDB website.

As an example, the command I sent to add a nav bar key that launches the Gmail app is this:

settings put secure sysui_nav_bar "key(65:file:///storage/emulated/0/NavIcons/gmail.png),back;home;recent,menu_ime"

Since we absolutely have to have back, home, recent, and menu_ime somewhere in the command, that means we unfortunately cannot replace these stock keys so we can use our own custom nav bar icons. But at the very least, we can play around with the spacing to be able to fit more custom keys in or to just get the layout we would prefer. For instance:

settings put secure sysui_nav_bar "space[#],back[#];home[#];recent[#],menu_ime[#]"

The value in brackets is a relative size multiplier, allowing you to shrink or expand the button width. Note that typical values for the relative size multiplier should remain between 0.85-1.15, otherwise buttons will start taking up way too little or too much width to really be usable. Don’t try to put “0” for the relative size in an effort to hide the nav bar key – you’ll just end up crashing the System UI.

In case you mess with something and end up with System UI crashes, you can return to the default layout of the nav bar by entering either of the following two commands:

settings put secure sysui_nav_bar "space,back;home;recent,menu_ime"
settings delete secure sysui_nav_bar

As a reminder of some of the crazy things you can do with the hidden Android Nougat nav bar tuner, here’s a screenshot of a nav bar layout one of our readers made for giggles.

Has science gone too far? Credits: AndyYan

Modifying the Nav Bar – App Method

I’m sure this is the part most of you are really interested in. XDA Senior Member paphonb‘s Custom Navigation Bar app would make all of this easier. The developer recently figured out how to intercept certain KeyEvents that call certain apps – there are up to 5 KeyEvents that he figured out how to intercept in total. The exact explanation of how he got this working is not necessary here, so we won’t go into more detail. With that in mind, the developer was able to update the app (starting with version 0.5.0) so that you can essentially perform whatever action you please.

For instance, the developer recently added the ability to add an action that pulls down the status bar, directly launch an app of your choosing, and most importantly to trigger a Tasker event. The Tasker event feature in particular is the most amazing part, because through Tasker the amount of actions you can perform is limitless. If you want your nav bar button to do something, it can do it. Couple this with the already existing Tasker Profile integration, and you can contextually modify the nav bar on your device to add certain keys only under conditions of your choosing.

In order to use these special features of the app, you will have to dish out $1.99 to upgrade to the pro version of the app. At this time, to use the app on your Samsung Galaxy S8/S8+, you need to be on the latest beta version (0.7.0). The app will automatically detect if you’re using a Galaxy S8/S8+ and disable some features that will cause your device to start crashing.

I have been told by the developer that he is still working on getting the app ready for stable release for users on these Samsung phones. Right now, I would wait a few days for the developer to update his app so you’ll have an easy way to modify the nav bar without having to use ADB commands. The developer is quick to update his app – since the app was released less than a month ago it has already seen numerous feature additions.


Conclusion

If you’re adventurous enough though, you can play around with the hidden nav bar tuner already by using the syntax I’ve shown earlier. Most people will likely wait for the Custom Navigation Bar app to be updated – I just wanted to get this news out there so all of our Galaxy S8/S8+ friends will know what to expect. I will continue to post tutorials related to the nav bar tuner, with my next one focusing on how to add double/trick clicks to the nav bar buttons.

Please support XDA-Developers in whatever way you can! We recently discovered that there were several blogs cut, copy, pasting our original tutorials and other content shared by our users on the forums. These blogs have been trying to take credit for the huge amount of effort we do in compiling these tutorials rather than providing quality content on their own. You won’t find tutorials such as the ones we’ve written in our tutorials category or tutorials from our forums anywhere else.

Follow us on TwitterGoogle+Facebook, or YouTube. Check out our XDA Labs app for a fast way to browse our forums (and consider getting XDA Ad-Free too!) on your mobile device! Thanks, and stay tuned for our next tutorial!



from xda-developers http://ift.tt/2q9IbTN
via IFTTT

Aucun commentaire:

Enregistrer un commentaire