Categories
爪机爪机

[MOD][HOW-TO] 在快捷按钮中增加“手电筒” [4.3]

英文原文来自:http://forum.xda-developers.com/showthread.php?t=2617552
本人对翻译成果保留版权。
翻译待办
=====================================================
需要的东西:

  1. SystemUI.apk
  2. SecSettings.apk
  3. Notepad++ 或其他文本编辑器 (请勿使用系统自带的“记事本”软件)
  4. apktool 或 baksmali+smali 或 VTS等等能够反编译的工具

———————————————————–
第1步: 修改 SystemUI.apk

  1. Decompile SystemUI.apk and navigate to com/android/systemui/statusbar/policy/quicksetting in your file browser
  2. Copy and paste FlashlightQuickSettingButton.smali (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 (before the of course)
    <string name="quickpanel_flashlight_text">Flashlight</string>

     

  7. Now we need to generate public.xml values for the files you added so compile the SystemUI.apk at this point and then decompile it again
  8. Navigate to SystemUI/res/values and open the public.xml with your text editor
  9. Now find the lines for the three resources you added (search in the file) and write down the ids for each. The ids will be in the form 0x12345678
    Look for these names and write down the ids for each (make sure you write down the name WITH the id)
    tw_quick_panel_icon_flashlight_off
    tw_quick_panel_icon_flashlight_on
    quickpanel_flashlight_text

     

  10. Now navigate to com/android/systemui/statusbar/policy/quicksetting and open FlashlightQuickSettingButton.smali with your text editor
  11. Now go to to the constructor (search for .method public constructor ) and you will see the following three lines of code
    # text id
    const v3, 0x0
    # on image id
    const v4, 0x0
    # off off id
    const v5, 0x0

    These lines reference the resource ids for the flashlight toggle text, on image, and off image respectively. Use the comments indicating which is which and replace the ids that are currently there with the ids that you wrote down above.

  12. 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

附件1:flashlight_files

——————————————————————-
Step 2: 修改 SecSettings.apk

  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.
    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;
    AND
    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

    makeConvertPanelName

    method, then add them to the end of the method before the

    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)
    <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

下面是最后一步,将修改好的 SecSettings.apk, SystemUI.apk 和 来自附件中的Torch.apk 一并加入 /system/app 文件夹下!
恭喜大功告成 

感谢:
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!!