Quantcast
Channel: xda-developers - Verizon Galaxy S III Android Development
Viewing all articles
Browse latest Browse all 352

[MOD][GUIDE] Setting up a custom settings tab

$
0
0
This tutorial is not the conventional type but more like a one way discussion for those familiar with decompiling/recompiling and the basic file structure of JARs and APKs.

So recently I have decided to take steps to minimize the effort involved in setting up new mods. Call me lazy, but it just seemed to make sense. Let me explain what I mean by that. The way I like to think about creating mods is that you have three pieces of the pie.

XML Settings
This is where you set up your toggles and/or list preferences as well as your strings and other attributes needed within your XML files. Located in SecSettings.apk

Smali Settings
This is the code behind the XML that allows the toggles to function. This code determines the true/false of toggles(Bools) as well as the values given to selections when there are more then two options (List preferences). Located in SecSettings.apk

Logic Code
This is the code that checks for preset values (set by your smali settings code) and performs actions based on those preset settings. The logic code is found in what ever smali you happen to be manipulating. If you wanted to change battery options, you would be working in BatteryController.smali, clock options would be clock.smali, etc.

So my goal was to eliminate 2 out of three of those steps by creating my own custom settings tab where I could develop my own XML code as well as my own smali code that would never be changed by android updates. The only time this code would change is when I change it. So now all you need to do is deal with the third piece of the pie, piece one and two are controlled now by you!

So here are the steps to setting up a custom tab within Androids settings menu.

 

We will be working within SecSettings only for this tutorial.

Navigate to res/xml/settings_headers.xml

Here is where you will set up your new tab. Have a look at one of the lines of code in this XML
 
Code:

<header android:icon="@drawable/ic_settings_display" android:id="@id/display_settings" android:title="@string/display_settings" android:fragment="com.android.settings.DisplaySettings" />


header android:icon="@drawable/ic_settings_display = The icon you see in the tab and the location that icon is stored
android:id="@id/display_settings" = Android ID thats stored in res/values/id's
android:title="@string/display_settings" = The title the new tab is given located in res/values/strings
android:fragment="com.android.settings.DisplaySett ings" = points to the smali that controls this tab

So now create your own tab code based off of the example above.
Create your own icon.png ( size 50 x 50) and drop it in res/drawable-xhdpi.
Add the newly created lines to strings and ID's respectively

Now its time to create an XML file. Your XML file should have a similar name to the smali file you just created the name of above. Dont worry yet about actually creating the smali, just the name for now is fine. So if you named your smali something like RomControl.smali you should name your XML rom_control.xml. So its easy to identify they are related.

Your XML can be as simple as one checkbox or very involved. My suggestion is you start simple and build it out as you get it functional. An XML file with one checkbox would look like this.

 
Code:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen android:title="@string/rom_settings"
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:settings="http://schemas.android.com/apk/res/com.android.settings.didact">
    <CheckBoxPreference android:title="@string/enable_lockscreen_torch" android:key="enable_lockscreen_torch" android:summary="@string/enable_lockscreen_torch_text" />
</PreferenceScreen>

You will need to add the necassary lines to res/strings found in the XML.
You will need to add the XML reference to res/public as well. If your XML is called new_tab.xml you would need to add the following line to res/public
 
Code:

<public type="xml" name="new_tab" id="0x7f070082" />

The ID would be whatever number is next in the list. This ID also needs to be added to the OnCreate method of your new smali file.


Now its time to create your smali file. I am not going to take this time to explain how to make this file but I will attach what i call a "blank" smali file that will allow what ever XML file you create to be visible. It wont be funtional until the smali gets correctly coded but maybe we can attack that task some other time.

So for now you have added a new line to settings_header.xml
You have added the icon you created to res/drawable-xhdpi
Added the new submissions to strings and IDs
Created your new XML file and put it in rex/xml. We can focus on the structure and coding of an XML file in another post later.
Created your new "Blank" smali. and put it in the folder of your choice

You should now be able to open settings and see your new tab with icon (see photo attached).


It took some work to get here, but now you have secured your code on the SecSettings side and you wont have to worry about updates changing it!

Now its time to code the smali and get the new tab functional...........

Attached Thumbnails
Click image for larger version

Name:	Screenshot_2013-02-25-19-41-59.jpg
Views:	N/A
Size:	24.1 KB
ID:	1761072   Click image for larger version

Name:	Screenshot_2013-02-25-19-42-08.jpg
Views:	N/A
Size:	32.2 KB
ID:	1761073  
Attached Files
File Type: zip Smali.zip - [Click for QR Code] (581 Bytes)

Viewing all articles
Browse latest Browse all 352

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>