[Eee Pad Transformer Themes and Apps] jschmier:
Creating the Reworked & Resized Weather Widget

The following is an overview of the process I followed in creating the modified & resized weather widget found in the first post. These instructions are intended to serve as a guide to those interested in creating their own modifications.

After going through this process a few times and/or modifying a few different APK files, this whole thing becomes much less intimidating.

Prerequisites

Deodexed Asus Weather APK (attached to post)

android-apktool - tool for reengineering Android apk files (here)

SignApk.jar - (Google search)

zipalign - archive alignment tool (included in Android SDK)

Step 1 - Decoding the APK

Using apktool, decode the APK to retrieve the resources into nearly original form. In this example, the decoded files are placed in a directory called ModWeatherResizedDir.

apktool decode Weather.apk ModWeatherResized

Step 2 - Modifying the package name

The package name is a unique identifier used by Android to manage the installed applications. The easiest package name modification simply involves changing all instances of asus to another unique identifier.

Using your favorite editor (I like gVim), modify all references to the package name (com.asus.weather*) found in the XML resource files (ModWeatherResizedrDir/AndroidManifest.xml and ModWeatherResizedDir/res/xml/*.xml) .

The package name is also embedded in the smali disassembly files (ModWeatherResizedDir/smali/com/asus/weather/*.smali and ModWeatherResizedDir/smali/com/asus/weather/accuWeather/*.smali). My recommendation is to find an editor that makes it easy to perform a global search and replace.

The package name must also match the folder hierarchy under the smali folder (ModWeatherResizedDir/smali/com/asus/weather/ and ModWeatherResizedDir/smali/com/asus/weather/accuWeather/). One simple option is to change the name of the asus folder to match a new unique identifier selected for the application.

Step 3 - Update the application name and any additional text

Using your favorite editor, modify the text (i.e. app_name) found in ModWeatherResizedDir/res/values/strings.xml.

Step 4 - Modify resources

The XML layout resources for the widget are found in ModWeatherResizedDir/res/layout-land/widgetlayout.xml and ModWeatherResizedDir/res/layout-land/widgetlayout.xml. The weather widget uses a relative layout and each text element can be re-sized and/or re-positioned. I followed a trial and error approach to get things where I wanted them. I also modified the thumbnail image in ModWeatherResizedDir/res/drawable-mdpi/.

Step 6 - Modify the smali disassembly

Modifications to the smali disassembly files are required to change the behavior of the widget. This is where I removed the 'last updated' text by setting the update value to "" in WeatherWidgetProvider.smali. I added a line (const-string vXX, "" where XX is the variable number being moved into v2 prior to the call to setTextViewText) following both occurrences of const v4, 0x7f080014, which corresponds to the id for the "widget_lastupdate" value in ModWeatherResizedDir/res/values/public.xml.

I found it useful to pull the classes.dex file from the APK, convert it from .dex to .class format using dex2jar, and then browse the reconstructed source using JD-GUI. It is important to remember that the reconstructed source is not a 100% match to the original source code. However, it is useful for comparing against and understanding the corresponding smali source.

Step 6 - Build the APK

Now that the desired modifications have been made, build the APK using apktool.

apktool build ModWeatherResizedDir ModWeatherResized_unsigned.apk

Step 7 - Sign the APK

The Android system requires that all installed applications be digitally signed with a certificate whose private key is held by the application's developer. I followed the instructions found here or here for generating my keys and using them to sign the APK. It should also be possible to sign the APK using the approach recommended at developer.android.com.

java -jar signapk.jar certificate.pem key.pk8 ModWeatherResized_unsigned.apk ModWeatherResized_signed.apk

Step 8 - Zipalign the APK

Zipalign the APK to optimize the way it is packaged in order to enable the Android operating system to interact with the application more efficiently. The benefit of this step is a reduction in the amount of RAM consumed when running the application.

zipalign -f -v 4ModWeatherResized_signed.apk ModWeatherResized.apk

________________________

I hope some of you find this information useful. If so, be sure to say thanks via the button below.