[Sony Xperia L] niaboc79:
Sera, many people are asking me how to add a new toggle, here's a simple tutorial who can be a base for modder ;)

How to add a new toggle

Our new toggle will be named NewButton and will be a copy of System Settings button.

Use that as base of your new toggle ;)

1) Open all powertoggles folder in notepad++

2) Search this: SystemSettings

This will be our example

You will found it in 6 places like in this screenshot:

http://www.mediafire.com/view/a4iuomzz71on8/Xperia S#l5615zh326ubwv1

3) SystemSettings.smali contains all what is needed by the button, so you can use it as example, paste all SystemSettings.smali inside a new smali called NewButton.smali and save it in \smali\com\serajr\powertoggles\buttons\

In this replace:

SystemSettings

by

NewButton

4) In PowerToggles.smali

Line 19 replace:

.field public static final POWER_TOGGLES_BUTTONS_DEFAULT:Ljava/lang/String; = "MeProfile|SystemSettings|RecentApps|BatteryInfo|Wifi|WifiAp|Bluetooth|GPS|StaminaMode|NFC|Roaming|Throw|Sound|Flashlight|Brightness|ScreenTimeout|StayAwakePlugged|Sync|Lockscreen|AutoRotate|Airplane|MobileData|NetworkMode|USBDebugging|USBTether|USBConnectionMode|Reboot|Shutdown"

by

.field public static final POWER_TOGGLES_BUTTONS_DEFAULT:Ljava/lang/String; = "[COLOR="Green"]NewButton[/COLOR]|MeProfile|SystemSettings|RecentApps|BatteryInfo|Wifi|WifiAp|Bluetooth|GPS|StaminaMode|NFC|Roaming|Throw|Sound|Flashlight|Brightness|ScreenTimeout|StayAwakePlugged|Sync|Lockscreen|AutoRotate|Airplane|MobileData|NetworkMode|USBDebugging|USBTether|USBConnectionMode|Reboot|Shutdown"

Line 1631 replace

const-string v0, "MeProfile|SystemSettings|RecentApps|BatteryInfo|Wifi|WifiAp|Bluetooth|GPS|StaminaMode|NFC|Roaming|Throw|Sound|Flashlight|Brightness|ScreenTimeout|StayAwakePlugged|Sync|Lockscreen|AutoRotate|Airplane|MobileData|NetworkMode|USBDebugging|USBTether|USBConnectionMode|Reboot|Shutdown"

by

const-string v0, "[COLOR="Green"]NewButton[/COLOR]|MeProfile|SystemSettings|RecentApps|BatteryInfo|Wifi|WifiAp|Bluetooth|GPS|StaminaMode|NFC|Roaming|Throw|Sound|Flashlight|Brightness|ScreenTimeout|StayAwakePlugged|Sync|Lockscreen|AutoRotate|Airplane|MobileData|NetworkMode|USBDebugging|USBTether|USBConnectionMode|Reboot|Shutdown"

5) In PowerTogglesButton.smali

Add this line after line 77:

[COLOR="Green"].field public static final BUTTON_SYSTEM_SETTINGS:Ljava/lang/String; = "NewButton"[/COLOR]

In .method static constructor <clinit>()V add this before line 350:

[COLOR="Green"].line 132
sget-object v0, Lcom/serajr/powertoggles/PowerTogglesButton;->BUTTONS:Ljava/util/HashMap;

const-string v1, "NewButton"

const-class v2, Lcom/serajr/powertoggles/buttons/NewButton;

invoke-virtual {v0, v1, v2}, Ljava/util/HashMap;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;[/COLOR]

6) In PowerTogglesPreferencesActivity$4.smali

Line 61 replace

const-string v2, "MeProfile|SystemSettings|RecentApps|BatteryInfo|Wifi|WifiAp|Bluetooth|GPS|StaminaMode|NFC|Roaming|Throw|Sound|Flashlight|Brightness|ScreenTimeout|StayAwakePlugged|Sync|Lockscreen|AutoRotate|Airplane|MobileData|NetworkMode|USBDebugging|USBTether|USBConnectionMode|Reboot|Shutdown"

by

const-string v2, "[COLOR="Green"]NewButton[/COLOR]|MeProfile|SystemSettings|RecentApps|BatteryInfo|Wifi|WifiAp|Bluetooth|GPS|StaminaMode|NFC|Roaming|Throw|Sound|Flashlight|Brightness|ScreenTimeout|StayAwakePlugged|Sync|Lockscreen|AutoRotate|Airplane|MobileData|NetworkMode|USBDebugging|USBTether|USBConnectionMode|Reboot|Shutdown"

7) In PowerTogglesPreferencesActivity.smali

Line 1844 replace

:cond_1c

by

:cond_1d

and add this after line 1843:

[COLOR="Green"]:cond_1c
aget-object v5, v0, v2

const-string v6, "NewButton"

invoke-virtual {v5, v6}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

move-result v5

if-eqz v5, :cond_1d

.line 655
iget-object v5, p0, Lcom/serajr/powertoggles/preferences/PowerTogglesPreferencesActivity;->mContext:Landroid/content/Context;

invoke-virtual {v5}, Landroid/content/Context;->getResources()Landroid/content/res/Resources;

move-result-object v5

const-string v6, "power_toggles_newbutton_text"

invoke-static {v6}, Lcom/serajr/powertoggles/utils/ResourceUtils;->getStringResId(Ljava/lang/String;)I

move-result v6

invoke-virtual {v5, v6}, Landroid/content/res/Resources;->getString(I)Ljava/lang/String;

move-result-object v5

invoke-virtual {v4, v5}, Lcom/serajr/powertoggles/preferences/utils/IconCheckBoxPreference;->setTitle(Ljava/lang/CharSequence;)V

.line 658
iget-object v5, p0, Lcom/serajr/powertoggles/preferences/PowerTogglesPreferencesActivity;->mContext:Landroid/content/Context;

invoke-virtual {v5}, Landroid/content/Context;->getResources()Landroid/content/res/Resources;

move-result-object v5

const-string v6, "power_toggles_newbutton_icon"

invoke-static {v6}, Lcom/serajr/powertoggles/utils/ResourceUtils;->getDrawableResId(Ljava/lang/String;)I

move-result v6

invoke-virtual {v5, v6}, Landroid/content/res/Resources;->getDrawable(I)Landroid/graphics/drawable/Drawable;

move-result-object v3

.line 659
.restart local v3 #icon:Landroid/graphics/drawable/Drawable;
invoke-static {}, Lcom/serajr/powertoggles/utils/ThemeUtils;->getAccentColorFilter()Landroid/graphics/ColorFilter;

move-result-object v5

invoke-virtual {v3, v5}, Landroid/graphics/drawable/Drawable;->setColorFilter(Landroid/graphics/ColorFilter;)V

.line 661
invoke-virtual {v4, v3}, Lcom/serajr/powertoggles/preferences/utils/IconCheckBoxPreference;->setIcon(Landroid/graphics/drawable/Drawable;)V

.line 666
.end local v3 #icon:Landroid/graphics/drawable/Drawable;[/COLOR]

At line 1887 replace:

const-string v0, "MeProfile|SystemSettings|RecentApps|BatteryInfo|Wifi|WifiAp|Bluetooth|GPS|StaminaMode|NFC|Roaming|Throw|Sound|Flashlight|Brightness|ScreenTimeout|StayAwakePlugged|Sync|Lockscreen|AutoRotate|Airplane|MobileData|NetworkMode|USBDebugging|USBTether|USBConnectionMode|Reboot|Shutdown"

by

const-string v0, "[COLOR="Green"]NewButton[/COLOR]|MeProfile|SystemSettings|RecentApps|BatteryInfo|Wifi|WifiAp|Bluetooth|GPS|StaminaMode|NFC|Roaming|Throw|Sound|Flashlight|Brightness|ScreenTimeout|StayAwakePlugged|Sync|Lockscreen|AutoRotate|Airplane|MobileData|NetworkMode|USBDebugging|USBTether|USBConnectionMode|Reboot|Shutdown"

Don't forget to add this string: power_toggles_newbutton_text in strings.xml and this icon: power_toggles_newbutton_icon in drawable/hdpi folder and add them in public.xml

8) In PowerTogglesPreferencesOrderActivity.smali

At line 2020 replace:

:cond_1b

by

:cond_1c

And add after line 2019:

[COLOR="Green"] :cond_1b
const-string v13, "NewButton"

move-object/from16 v0, p1

invoke-virtual {v0, v13}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

move-result v13

if-eqz v13, :cond_1c

.line 474
move-object/from16 v0, p0

iget-object v13, v0, Lcom/serajr/powertoggles/preferences/PowerTogglesPreferencesOrderActivity;->mContext:Landroid/content/Context;

invoke-virtual {v13}, Landroid/content/Context;->getResources()Landroid/content/res/Resources;

move-result-object v13

const-string v14, "power_toggles_newbutton_text"

invoke-static {v14}, Lcom/serajr/powertoggles/utils/ResourceUtils;->getStringResId(Ljava/lang/String;)I

move-result v14

invoke-virtual {v13, v14}, Landroid/content/res/Resources;->getString(I)Ljava/lang/String;

move-result-object v13

invoke-virtual {v10, v13}, Landroid/widget/TextView;->setText(Ljava/lang/CharSequence;)V

.line 477
move-object/from16 v0, p0

iget-object v13, v0, Lcom/serajr/powertoggles/preferences/PowerTogglesPreferencesOrderActivity;->mContext:Landroid/content/Context;

invoke-virtual {v13}, Landroid/content/Context;->getResources()Landroid/content/res/Resources;

move-result-object v13

const-string v14, "power_toggles_newbutton_icon"

invoke-static {v14}, Lcom/serajr/powertoggles/utils/ResourceUtils;->getDrawableResId(Ljava/lang/String;)I

move-result v14

invoke-virtual {v13, v14}, Landroid/content/res/Resources;->getDrawable(I)Landroid/graphics/drawable/Drawable;

move-result-object v6

.line 478
.restart local v6 #icon:Landroid/graphics/drawable/Drawable;
invoke-static {}, Lcom/serajr/powertoggles/utils/ThemeUtils;->getAccentColorFilter()Landroid/graphics/ColorFilter;

move-result-object v13

invoke-virtual {v6, v13}, Landroid/graphics/drawable/Drawable;->setColorFilter(Landroid/graphics/ColorFilter;)V

.line 480
invoke-virtual {v7, v6}, Landroid/widget/ImageView;->setImageDrawable(Landroid/graphics/drawable/Drawable;)V

.line 485
.end local v6 #icon:Landroid/graphics/drawable/Drawable;[/COLOR]

At line 2340 replace

const-string v1, "MeProfile|SystemSettings|RecentApps|BatteryInfo|Wifi|WifiAp|Bluetooth|GPS|StaminaMode|NFC|Roaming|Throw|Sound|Flashlight|Brightness|ScreenTimeout|StayAwakePlugged|Sync|Lockscreen|AutoRotate|Airplane|MobileData|NetworkMode|USBDebugging|USBTether|USBConnectionMode|Reboot|Shutdown"

by

const-string v1, "[COLOR="Green"]NewButton[/COLOR]|MeProfile|SystemSettings|RecentApps|BatteryInfo|Wifi|WifiAp|Bluetooth|GPS|StaminaMode|NFC|Roaming|Throw|Sound|Flashlight|Brightness|ScreenTimeout|StayAwakePlugged|Sync|Lockscreen|AutoRotate|Airplane|MobileData|NetworkMode|USBDebugging|USBTether|USBConnectionMode|Reboot|Shutdown"

To finish add this new array: NewButton in public/arrays

Replace:

<string-array name="power_toggles_available_buttons">
<item>MeProfile</item>
<item>SystemSettings</item>
<item>RecentApps</item>
<item>BatteryInfo</item>
<item>Wifi</item>
<item>WifiAp</item>
<item>Bluetooth</item>
<item>GPS</item>
<item>StaminaMode</item>
<item>NFC</item>
<item>Roaming</item>
<item>Throw</item>
<item>Sound</item>
<item>Flashlight</item>
<item>Brightness</item>
<item>ScreenTimeout</item>
<item>StayAwakePlugged</item>
<item>Sync</item>
<item>Lockscreen</item>
<item>AutoRotate</item>
<item>Airplane</item>
<item>MobileData</item>
<item>NetworkMode</item>
<item>USBConnectionMode</item>
<item>USBDebugging</item>
<item>USBTether</item>
<item>Reboot</item>
<item>Shutdown</item>
</string-array>

by

<string-array name="power_toggles_available_buttons">
[COLOR="Green"]<item>NewButton</item>[/COLOR]
<item>MeProfile</item>
<item>SystemSettings</item>
<item>RecentApps</item>
<item>BatteryInfo</item>
<item>Wifi</item>
<item>WifiAp</item>
<item>Bluetooth</item>
<item>GPS</item>
<item>StaminaMode</item>
<item>NFC</item>
<item>Roaming</item>
<item>Throw</item>
<item>Sound</item>
<item>Flashlight</item>
<item>Brightness</item>
<item>ScreenTimeout</item>
<item>StayAwakePlugged</item>
<item>Sync</item>
<item>Lockscreen</item>
<item>AutoRotate</item>
<item>Airplane</item>
<item>MobileData</item>
<item>NetworkMode</item>
<item>USBConnectionMode</item>
<item>USBDebugging</item>
<item>USBTether</item>
<item>Reboot</item>
<item>Shutdown</item>
</string-array>