[MOD][HOW-TO] Add Flashlight quick toggle [4.3|4.4]

Search This thread

The Sickness

Retired Recognized Developer
Oct 27, 2012
9,785
22,733
Somewhere in Texas
LOL....I just noticed that the flashlight IS NOT in the notifications panel......but the toggle works. Man this is tripping me out. Is this correct?

Code:
    .line 666
    iget-object v0, p0, Lcom/android/settings/NotificationPanelMenu;->mConvertPanelItemstring:Ljava/util/HashMap;

    const-string v1, "Flashlight"

    const-string v2, "notification_panel_flashlight"

    const-string v1, "Flashlight"

    const-string v2, "notification_panel_flashlight"

Im just trying to figure out WHY the tile isnt showing up in notification panel.....
 
Last edited:

decalman

Senior Member
Mar 4, 2013
921
572
PUERTO RICO
ratrodbikes.com
LOL....I just noticed that the flashlight IS NOT in the notifications panel......but the toggle works. Man this is tripping me out. Is this correct?


On SecSettings/smali/com/android/settings i was adding the lines all the way at the bottom. i searched for


Code:
.method private makeConvertPanelName

1958194_870298419663755_42123565_n.jpg


and at the end of that section i added the needed lines

1524632_870298502997080_2118129442_n.jpg


and on SecSettings/res/values/strings.xml i was also adding the needed lines all the way at the end. i looked for where the strings started to look like

Code:
<string name="notification_panel_

and i place the line here

1797477_870298492997081_1832753497_n.jpg




My Tapatalk Signature
 

Netuser

Senior Member
Feb 4, 2006
1,662
778
Toronto
@CNexus Thanks for this great guide, i learn some stuff :)

I need a little bit of your help please, I don't want to have those 2 underline bars under the icon, what part of the code should I edit/delete to get rid of it please ?

The fat one i can get rid of it by deleting and image file in my drawable folder (but maybe this image serve other purpose so I want to keep it if possible) but the thin line in 2nd screenshot is some where in your code, and I cant find it how to get rid of it :(

See attach screenshot:

Thanks a lot for your help :)
 

Attachments

  • underline.jpg
    underline.jpg
    155.2 KB · Views: 160
  • underline2.jpg
    underline2.jpg
    155 KB · Views: 163
Last edited:

CNexus

Senior Member
May 17, 2012
9,010
14,000
~/android
Google Pixel 7
@CNexus Thanks for this great guide, i learn some stuff :)

I need a little bit of your help please, I don't want to have those 2 underline bars under the icon, what part of the code should I edit/delete to get rid of it please ?

The fat one i can get rid of it by deleting and image file in my drawable folder (but maybe this image serve other purpose so I want to keep it if possible) but the thin line in 2nd screenshot is some where in your code, and I cant find it how to get rid of it :(

See attach screenshot:

Thanks a lot for your help :)

QuickSettingButton.smali you need to set that view to GONE (0x8) using a call to setVisibility

I forget what the field that holds that view is called but it'll be something like this

Code:
iget-object v0, p0, Lcom/android/systemui/policy/quicksetting/QuickSettingButton;->FIELD_NAME_HERE:Landroid/view/View;
const v1, 0x8
invoke-virtual {v0, v1}, Landroid/view/View;->setVisibility(I)V
 

Netuser

Senior Member
Feb 4, 2006
1,662
778
Toronto
QuickSettingButton.smali you need to set that view to GONE (0x8) using a call to setVisibility

I forget what the field that holds that view is called but it'll be something like this

Code:
iget-object v0, p0, Lcom/android/systemui/policy/quicksetting/QuickSettingButton;->FIELD_NAME_HERE:Landroid/view/View;
const v1, 0x8
invoke-virtual {v0, v1}, Landroid/view/View;->setVisibility(I)V

Thanks for the reply :)

I am sorry I know nothing about smali or java :( What should i do with this code ? And how become other icons don't have underline but only the flash light ?

can you please give a little more noob instructions

Thanks
 

Netuser

Senior Member
Feb 4, 2006
1,662
778
Toronto
@CNexus

I searched by image id and find this in Quicksetting button that refer to that image which is the Thicker underline : Can i comment or edit any part to make it not load the underline ? What about the thinner underline which is not part of any image, dont know from where it is coming :(
Code:
    .line 285
    iget-object v0, p0, Lcom/android/systemui/statusbar/policy/quicksetting/QuickSettingButton;->mBtnLED:Landroid/widget/ImageView;

    const v1, 0x7f0201a1

    invoke-virtual {v0, v1}, Landroid/widget/ImageView;->setImageResource(I)V
 

Netuser

Senior Member
Feb 4, 2006
1,662
778
Toronto
Place this code immediately after the setImageResource line

Code:
const v1, 0x8
invoke-virtual {v0, v1}, Landroid/view/View;->setVisibility(I)V

Thanks :) Ok I will try it now, But i posted the wrong code :( that was for dim image

Here is the On and Off bottom bar image id that are all together :

Code:
.method public setActivateStatus(I)V
    .locals 4
    .parameter "activateStatus"

    .prologue
    const v3, 0x7f02022a

    const v2, 0x7f02022b

    .line 245
    iput p1, p0, Lcom/android/systemui/statusbar/policy/quicksetting/QuickSettingButton;->mActivateStatus:I

    .line 247
    iget v0, p0, Lcom/android/systemui/statusbar/policy/quicksetting/QuickSettingButton;->mTextID:I

    if-eqz v0, :cond_0


---------- Post added at 10:51 PM ---------- Previous post was at 10:31 PM ----------


@CNexus YESSS You are Amazing :D it worked here is the code I put as you told but after v2 and v3 But now I still have that 2nd thin line left :( How to get rid of that now (screenshot added, think line gone thin one is still here )?

Code:
    invoke-virtual {v0, v2}, Landroid/widget/ImageView;->setImageResource(I)V
	
	const v2, 0x8
	invoke-virtual {v0, v2}, Landroid/view/View;->setVisibility(I)V


Also I have another question, all my other toggle are not shown by ON and Off image but only 1 image called round at the end of image for exemple : tw_quick_panel_icon_airplane_round.png

Then if I turn on it will show these above mention image on a background image which is : tw_quick_panel_quick_setting_button_round_bg_on.png or if it is turn on it will show it on tw_quick_panel_quick_setting_button_round_bg_off.png

Is it possible to modify your code to do same with Flashlight meaning I have 1 image called tw_quick_panel_icon_flashlight_round.png that will show on aboive mentioned BG On and Off image instead of different On off image ? : or I am forced to use On and Off image ?

Thanks so much for all your help. I am also learning so much with all these edit :)
 

Attachments

  • Screenshot_2014-04-17-23-05-18.png
    Screenshot_2014-04-17-23-05-18.png
    208 KB · Views: 389
Last edited:

Netuser

Senior Member
Feb 4, 2006
1,662
778
Toronto
@CNexus sorry to bump this, do you have any idea how to do those 2 things ?

-Remove thin underline
-Use 1 icon with flash light with On and Off background image change.

Do you need me to post any files that can help you how it is done for other toggles ?

Thanks again for all your help :)
 

CNexus

Senior Member
May 17, 2012
9,010
14,000
~/android
Google Pixel 7
@CNexus sorry to bump this, do you have any idea how to do those 2 things ?

-Remove thin underline
-Use 1 icon with flash light with On and Off background image change.

Do you need me to post any files that can help you how it is done for other toggles ?

Thanks again for all your help :)
I'm not sure...since it doesn't work like that on my device that is

I hesitate to do things that I can't test myself unless it's really simple, and this looks to require some more digging...maybe ask for help from one of your local forum devs?
 
  • Like
Reactions: Netuser

Netuser

Senior Member
Feb 4, 2006
1,662
778
Toronto
I'm not sure...since it doesn't work like that on my device that is

I hesitate to do things that I can't test myself unless it's really simple, and this looks to require some more digging...maybe ask for help from one of your local forum devs?

Ok thanks :)

Will see for that part with the developer of the Rom I hope he can help me. :)

And what about the Thin line how can get rid of it ? Where it is coming from As I see many other who posted there Screenshot with just icons and no underline in those icons. Do you have any idea ? I also tried with plain Stock systemui and I am getting same result with that underline :S
 

icedventimocha

Senior Member
Great guide. Got the SystemUI.apk edited successfully, but when I build SecSettings.apk it will not smali file. I just copied and pasted the lines provided in the OP, not sure what I'm doing wrong. Tried with 2 versions of apktool several times with no success. Any ideas would be tits. Verizon Galaxy Note II on 4.3 touchwiz.


EDIT:Nevermind, had to have been doing something basic wrong. I guess 112th times a charm lol.

qysyradu.jpg


Sent from my Galaxy Note II
 
Last edited:
  • Like
Reactions: Mongo23ny

android.zealot.fervor

Senior Member
Nov 8, 2013
1,382
1,672
★◢↿MUSCAT↾◣★

1brainsurgeon

Senior Member
Apr 7, 2011
3,027
6,250
Gig Harbor
Thanks again cnexus for eliminating the need to use a 3rd party apk. Gotta have my flashlight easily accessible. It gets dark, especially on garbage-to-the-curb nights.
 

Attachments

  • uploadfromtaptalk1399066176840.jpg
    uploadfromtaptalk1399066176840.jpg
    49.6 KB · Views: 195
  • Like
Reactions: bilgerryan

Top Liked Posts

  • There are no posts matching your filters.
  • 98
    Hey guys! Today I'll be showing you how to add the Flashlight toggle to your quick toggles:

    i4gop5j.png

    UPDATE: Once you have completed the mod below, you (and your users) can enable the flashlight toggle by flashing the zip HERE. It uses busybox and an included binary to add the toggle to notification_panel_active_app_list, so it will work with all devices that this mod applies to. Again, feel free to share this but give credits where due!

    Items you will need
    1. SystemUI.apk from the rom you are modding
    2. SecSettings.apk from the rom you are modding
    3. Notepad++ or another text editor of your choice (NOT regular Notepad, it messes up the encoding)
    4. apktool or baksmali+smali or VTS, etc


    Now before we get started, download the attachment with the files you will need for this mod (attached to this post...make sure you grab the right version for the system you are modifying)




    Now lets get started!


    [size=+1]Step 1: Modding SystemUI.apk[/size]
    1. Decompile SystemUI.apk and navigate to com/android/systemui/statusbar/policy/quicksetting in your file browser
    2. Copy and paste FlashlightQuickSettingButton.smali from inside the zip you downloaded (flashlight_files.zip/SystemUI/FlashlightQuickSettingButton.smali) into this folder
    3. Navigate to SystemUI/res/drawable-xhdpi (or SystemUI/res/drawable-xxhdpi depending on your device)
    4. Copy and paste the two pngs (tw_quick_panel_icon_flashlight_off.png and tw_quick_panel_icon_flashlight_on.png) from the SystemUI folder of the attachment into the decompiled drawable folder you opened above
    5. Now navigate to SystemUI/res/values and open the strings.xml with your text editor
    6. Search for "quickpanel_flashlight_text". If it does not exist anywhere in the file, add this to the bottom of your strings.xml file:
      PHP:
      <string name="quickpanel_flashlight_text">Flashlight</string>
    7. That's it or SystemUI! Now recompile SystemUI.apk and move on to step 2. At this point, the toggle will show up in the full toggles view (when you add ";Flashlight" to the CscFeature... or to the notification_panel_active_app_list in /data/data/com.android.providers.settings/settings.db) in the status bar, but Settings will FC if you try to go into edit mode/rearrange toggles mode
    74
    [SIZE=+1]Step 2: Modding SecSettings.apk[/SIZE]
    1. Decompile SecSettings and navigate to com/android/settings
    2. Open NotificationPanelMenu.smali and search for the method ".method private makeConvertPanelName"
    3. Make sure that the following lines are present somewhere in the makeConvertPanelName method. Notice that they are NOT the same, but indeed very similar.
      Code:
      iget-object v0, p0, Lcom/android/settings/NotificationPanelMenu;->mConvertPanelItemstring:Ljava/util/HashMap;
      const-string v1, "Flashlight"
      const-string v2, "notification_panel_flashlight"
      invoke-virtual {v0, v1, v2}, Ljava/util/HashMap;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      
      [B]AND[/B]
      
      iget-object v0, p0, Lcom/android/settings/NotificationPanelMenu;->mConvertPanelItemstring:Ljava/util/HashMap;
      const-string v1, "notification_panel_flashlight"
      const-string v2, "Flashlight"
      invoke-virtual {v0, v1, v2}, Ljava/util/HashMap;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

      If the 8 lines above are not anywhere in the
      Code:
      makeConvertPanelName
      method, then add them to the end of the method before the
      Code:
      return-void
    4. Now save the file and close it and navigate to SecSettings/res/values/strings.xml
    5. Add the following line to your strings.xml if it does not already exist (yes, it has the same name as the image. That's supposed to happen so don't worry)
      PHP:
      <string name="notification_panel_flashlight">Flashlight</string>
    6. Save and close strings.xml and navigate to SecSettings/res/drawable-xhdpi or drawable-xxhdpi depending on your device
    7. Extract the notification_panel_flashlight.png from attachment.zip/SecSettings and copy it into the drawable folder from above
    8. Finally, recompile SecSettings with your modifications


    Now for the final step, take your modified SecSettings.apk, SystemUI.apk and add them to the /system/app folder of your rom and you are good to go!

    Congratulations, you just added the Flashlight toggle to your rom. Enjoy :D:D

    AzsLTFa.png
    ENxGR0l.png

    Note: Devs are free to use this mod in their rom. Just make sure you give credits where they are due :)
    If you have any issues, I'd be more than happy to help :good:


    Thanks to:
    Samsung for the AT&T base code this was pulled from!
    Rompnit for finding the at&t code and the first part of the mod!
    Google for the wonderful logcat tool built into Android that allowed me to figure out the second part of the mod!!
    9
    @Chad The Pathfinder @vesatile1
    Here is a new smali for SystemUI that is working for me on 4.4.2.
    Give it a try and let me know how it works for you. I fought with this bad boy for quite a while. :rolleyes:

    Instructions:
    This smali requires you to compile then decompile your completed SystemUI (then compile one last time once the values are correct) to input the appropriate values for the public construct. I added fields to each line for which public values to look for. You can leave those comment lines in, they will be ignored when you compile the smali.
    Code:
    .method public constructor <init>(Landroid/content/Context;)V
        .locals 8
    
        const v2, 0x7f0b0211  [COLOR="Blue"]## quickpanel_flashlight_text[/COLOR]
    
        const v1, 0x7f0b0211  [COLOR="Blue"]## quickpanel_flashlight_text[/COLOR]
    
        const/4 v5, 0x0
    
        const/4 v0, 0x0
    
        sget-boolean v3, Lcom/android/systemui/statusbar/Feature;->mIsTablet:Z
    
        invoke-direct {p0, p1, v0, v3}, Lcom/android/systemui/statusbar/policy/quicksetting/QuickSettingButton;-><init>(Landroid/content/Context;Landroid/util/AttributeSet;Z)V
    
        sget-boolean v0, Lcom/android/systemui/statusbar/Feature;->mIsPhone:Z
    
        if-eqz v0, :cond_0
    
        const v3, 0x7f020355  [COLOR="Blue"]## tw_quick_panel_icon_flashlight_on[/COLOR]
    
        const v4, 0x7f020354  [COLOR="Blue"]## tw_quick_panel_icon_flashlight_off[/COLOR]
    
        move-object v0, p0
    
        move v6, v5
    
        move v7, v5
    
        invoke-virtual/range {v0 .. v7}, Lcom/android/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;->initLayout(IIIIIII)V
    
        iput-object p1, p0, Lcom/android/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;->mContext:Landroid/content/Context;
    
        :goto_0
        invoke-virtual {p0, p0}, Lcom/android/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;->setListener(Lcom/android/systemui/statusbar/policy/quicksetting/QuickSettingButton$Listener;)V
    
        return-void
    
        :cond_0
        const v0, 0x7f020354  [COLOR="Blue"]## tw_quick_panel_icon_flashlight_off
    [/COLOR]
        invoke-virtual {p0, v1, v2, v0}, Lcom/android/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;->initLayout(III)V
    
        goto :goto_0
    .end method

    Also see this post:
    http://xdaforums.com/showpost.php?p=53122589&postcount=321
    9
    MOD UPDATED
    ==============
    - 4.3 and 4.4 zips added
    - No need to write down ANY id's anymore. I've made it so that the id's get looked up on the fly by name, so just make sure you don't rename the drawables/string names as per this guide
    - Flashlight is super fast now, no need to use an external app
    8
    Ok here it is

    Replace the onClick method of the FlashlightQuickSettingButton.smali with the following, then you don't need an external app

    Code:
    .method public onClick(Z)V
        .locals 5
        .parameter "paramBoolean"
    
        .prologue
        .line 29
        const/4 v2, 0x0
    
        .line 30
        .local v2, localIntent:Landroid/content/Intent;
        const/4 v1, 0x0
    
        .line 32
        .local v1, bc:Ljava/lang/String;
        const/4 v0, 0x2
    
        .line 34
        .local v0, activateStatus:I
        iget v3, p0, Lcom/android/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;->mFlashlight:I
    
        add-int/lit8 v3, v3, 0x1
    
        iput v3, p0, Lcom/android/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;->mFlashlight:I
    
        .line 36
        iget v3, p0, Lcom/android/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;->mFlashlight:I
    
        rem-int/lit8 v3, v3, 0x2
    
        iput v3, p0, Lcom/android/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;->mFlashlight:I
    
        .line 38
        iget v3, p0, Lcom/android/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;->mFlashlight:I
    
        const/4 v4, 0x1
    
        if-ne v3, v4, :cond_0
    
        .line 39
        const-string v1, "com.sec.samsung.torchwidget.torch_on_3"
    
        .line 40
        const/4 v0, 0x1
    
        .line 45
        :goto_0
        invoke-virtual {p0, v0}, Lcom/android/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;->setActivateStatus(I)V
    
        .line 47
        new-instance v2, Landroid/content/Intent;
    
        .end local v2           #localIntent:Landroid/content/Intent;
        invoke-direct {v2, v1}, Landroid/content/Intent;->(Ljava/lang/String;)V
    
        .line 49
        .restart local v2       #localIntent:Landroid/content/Intent;
        iget-object v3, p0, Lcom/android/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;->mContext:Landroid/content/Context;
    
        invoke-virtual {v3, v2}, Landroid/content/Context;->sendBroadcast(Landroid/content/Intent;)V
    
        .line 53
        return-void
    
        .line 42
        :cond_0
        const-string v1, "com.sec.samsung.torchwidget.torch_off"
    
        goto :goto_0
    .end method