[Android General] AbrahamGC:
FontUtils (Custom fonts for all TextViews with RC)

Last day [MENTION=5829833]a.raul[/MENTION] and me was thinking about change all text fonts. On our mods we always had the same 4 fonts... default, bold, italic and italic bold... So we made a class that can be invoked anywhere passing an integer from 0(default) to 51, then the class returns the TypeFace correct.

For the example I will show how to implement it on datausage on quickpanel, cuz we have the source method and can be teached clearly. (thx wuby986 & daxgirl.)

First of all merge attached SystemUI.zip on your decompiled SystemUI.

On the method onWindowFocusChanged(Z)V, at the moment we have this :

int typeFace = Settings.System.getInt(contentResolver, "data_usage_view_text_style", 0);
switch (typeFace) {
case 1:
setTypeface(null, Typeface.BOLD);
break;
case 2:
setTypeface(null, Typeface.ITALIC);
break;
case 3:
setTypeface(null, Typeface.BOLD_ITALIC);
break;
default:
setTypeface(null, Typeface.NORMAL);
}

For use our class, we just will remove all previous code and add this :

setTypeface(FontUtils.getCustomFont(GearUtils.getDbIntForKey("data_usage_view_text_style", 0)));

Easy, no?

On smali, get the font and apply on current TextView, will look like this:

const-string v1, "data_usage_view_text_style"

const/4 v2, 0x0

invoke-static {v1, v2}, Lcom/android/wubydax/GearUtils;->getDbIntForKey(Ljava/lang/String;I)I

move-result v1

invoke-static {v1}, Lcom/android/deluxerom/FontUtils;->getCustomFont(I)Landroid/graphics/Typeface;

move-result-object v1

invoke-virtual {p0, v1}, Lcom/android/systemui/qs/DataUsageView;->setTypeface(Landroid/graphics/Typeface;)V

So, for use it on DataUsageView, just replace whole onWindowFocusChanged(Z)V method with this :

.method public onWindowFocusChanged(Z)V
.registers 5
.param p1, "hasWindowFocus" # Z

.prologue
.line 19
invoke-super {p0, p1}, Landroid/widget/TextView;->onWindowFocusChanged(Z)V

.line 20
if-eqz p1, :cond_2f

.line 21
const-string v1, "data_usage_text_gravity"

const/4 v2, 0x2

invoke-static {v1, v2}, Lcom/android/wubydax/GearUtils;->getDbIntForKey(Ljava/lang/String;I)I

move-result v0

.line 22
.local v0, "p":I
packed-switch v0, :pswitch_data_3c

.line 30
const v1, 0x800003

invoke-virtual {p0, v1}, Lcom/android/systemui/qs/DataUsageView;->setGravity(I)V

.line 33
:goto_15
const-string v1, "data_usage_view_text_style"

const/4 v2, 0x0

invoke-static {v1, v2}, Lcom/android/wubydax/GearUtils;->getDbIntForKey(Ljava/lang/String;I)I

move-result v1

invoke-static {v1}, Lcom/android/deluxerom/FontUtils;->getCustomFont(I)Landroid/graphics/Typeface;

move-result-object v1

invoke-virtual {p0, v1}, Lcom/android/systemui/qs/DataUsageView;->setTypeface(Landroid/graphics/Typeface;)V

.line 34
const-string v1, "data_usage_text_color"

const v2, -0xff0001

invoke-static {v1, v2}, Lcom/android/wubydax/GearUtils;->getDbIntForKey(Ljava/lang/String;I)I

move-result v1

invoke-virtual {p0, v1}, Lcom/android/systemui/qs/DataUsageView;->setTextColor(I)V

.line 36
.end local v0 # "p":I
:cond_2f
return-void

.line 24
.restart local v0 # "p":I
:pswitch_30
const v1, 0x800005

invoke-virtual {p0, v1}, Lcom/android/systemui/qs/DataUsageView;->setGravity(I)V

goto :goto_15

.line 27
:pswitch_37
const/4 v1, 0x1

invoke-virtual {p0, v1}, Lcom/android/systemui/qs/DataUsageView;->setGravity(I)V

goto :goto_15

.line 22
:pswitch_data_3c
.packed-switch 0x1
:pswitch_37
:pswitch_30
.end packed-switch
.end method

Here some screenshots :

For RomControl just change your DataUsage preferences with these :

Copy this on any xml :

<PreferenceCategory
android:title="Data Usage view preferences">
<com.wubydax.romcontrol.v2.prefs.MySwitchPreference
android:title="Data usage view visibility"
android:summaryOff="Hidden"
android:summaryOn="Shown"
android:key="data_usage_visibility"
android:defaultValue="true"/>
<com.wubydax.romcontrol.v2.prefs.ColorPickerPreference
android:title="Data usage text color"
android:key="data_usage_text_color"
android:dependency="data_usage_visibility"
android:defaultValue="#e61e4e78"/>
<com.wubydax.romcontrol.v2.prefs.MyListPreference
android:title="Data usage text gravity"
android:key="data_usage_text_gravity"
android:dependency="data_usage_visibility"
android:entries="@array/data_usage_gravity_entries"
android:entryValues="@array/data_usage_gravity_values"
android:defaultValue="0"/>
<com.wubydax.romcontrol.v2.prefs.ThumbnailListPreference
android:title="@string/font"
android:key="data_usage_view_text_style"
android:defaultValue="0"
app:drawableArray="@array/common_font_drawables"
app:entryList="@array/common_font_entries"
app:entryValuesList="@array/common_font_values" />
</PreferenceCategory>

NOTE : Arrays will be the same anywhere u apply the mod, don't copy it 1000 times...

<string-array name="data_usage_gravity_entries">
<item>To end</item>
<item>Center horizontal</item>
<item>To start</item>
</string-array>
<string-array name="data_usage_gravity_values" translatable="false">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>
<array name="common_font_drawables">
<item>@drawable/defaultt</item>
<item>@drawable/abductionsmall</item>
<item>@drawable/aabeakrg</item>
<item>@drawable/addisababa</item>
<item>@drawable/agentletouch</item>
<item>@drawable/airmolestripe</item>
<item>@drawable/aller</item>
<item>@drawable/androidclock</item>
<item>@drawable/arial</item>
<item>@drawable/arial_rb</item>
<item>@drawable/arraybold</item>
<item>@drawable/astandardbold</item>
<item>@drawable/attic</item>
<item>@drawable/barmeno105</item>
<item>@drawable/bauhaus</item>
<item>@drawable/beau_sans_pro_book</item>
<item>@drawable/beautifuleverytime</item>
<item>@drawable/belligerentbold</item>
<item>@drawable/blackchancery</item>
<item>@drawable/bluehigh</item>
<item>@drawable/bluehighbold</item>
<item>@drawable/bubbleletters</item>
<item>@drawable/cantaneobold</item>
<item>@drawable/caprica</item>
<item>@drawable/cartoon</item>
<item>@drawable/caviardreams_bold</item>
<item>@drawable/celtic</item>
<item>@drawable/comicsansms</item>
<item>@drawable/cooljazz</item>
<item>@drawable/darkromanticism</item>
<item>@drawable/dustismobold</item>
<item>@drawable/feastofflesh</item>
<item>@drawable/felipe</item>
<item>@drawable/galantnormal</item>
<item>@drawable/gezoe</item>
<item>@drawable/gillsansmtitalic</item>
<item>@drawable/helveticaneueece5roman</item>
<item>@drawable/jaramondbold</item>
<item>@drawable/laneposhbold</item>
<item>@drawable/lauren</item>
<item>@drawable/melonio</item>
<item>@drawable/metal</item>
<item>@drawable/motleycrue</item>
<item>@drawable/nokiapure</item>
<item>@drawable/petermorgan</item>
<item>@drawable/piratebold</item>
<item>@drawable/questbold</item>
<item>@drawable/roboto</item>
<item>@drawable/robotobold</item>
<item>@drawable/rosemary</item>
<item>@drawable/sansationbold</item>
<item>@drawable/segoe</item>
</array>
<string-array name="common_font_entries">
<item>Default</item>
<item>Abductionsmall</item>
<item>ABEAKRG</item>
<item>AddisAbaba</item>
<item>AGentleTouch</item>
<item>AirmoleStripe</item>
<item>Aller</item>
<item>AndroidClock</item>
<item>Arial</item>
<item>Arial_RB</item>
<item>ArrayBold</item>
<item>Astandardbold</item>
<item>Attic</item>
<item>Barmeno105</item>
<item>Bauhaus</item>
<item>Beau_Sans_Pro_Book</item>
<item>beautifuleverytime</item>
<item>Belligerentbold</item>
<item>BlackChancery</item>
<item>Bluehigh</item>
<item>Bluehighbold</item>
<item>BubbleLetters</item>
<item>Cantaneobold</item>
<item>Caprica</item>
<item>Cartoon</item>
<item>caviardreams_bold</item>
<item>Celtic</item>
<item>comicsansms</item>
<item>Cooljazz</item>
<item>Darkromanticism</item>
<item>Dustismobold</item>
<item>FeastOfFlesh</item>
<item>Felipe</item>
<item>GalantNormal</item>
<item>Gezoe</item>
<item>GillSansMTItalic</item>
<item>HelveticaNeueCE55Roman</item>
<item>Jaramondbold</item>
<item>Laneposhbold</item>
<item>Lauren</item>
<item>Melonio</item>
<item>Metal</item>
<item>MotleyCrue</item>
<item>NokiaPure</item>
<item>Petermorgan</item>
<item>Piratebold</item>
<item>Questbold</item>
<item>Roboto</item>
<item>Roboto-Bold</item>
<item>Rosemary</item>
<item>Sansationbold</item>
<item>Segoe</item>
</string-array>
<string-array name="common_font_values">
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
<item>5</item>
<item>6</item>
<item>7</item>
<item>8</item>
<item>9</item>
<item>10</item>
<item>11</item>
<item>12</item>
<item>13</item>
<item>14</item>
<item>15</item>
<item>16</item>
<item>17</item>
<item>18</item>
<item>19</item>
<item>20</item>
<item>21</item>
<item>22</item>
<item>23</item>
<item>24</item>
<item>25</item>
<item>26</item>
<item>27</item>
<item>28</item>
<item>29</item>
<item>30</item>
<item>31</item>
<item>32</item>
<item>33</item>
<item>34</item>
<item>35</item>
<item>36</item>
<item>37</item>
<item>38</item>
<item>39</item>
<item>40</item>
<item>41</item>
<item>42</item>
<item>43</item>
<item>44</item>
<item>45</item>
<item>46</item>
<item>47</item>
<item>48</item>
<item>49</item>
<item>50</item>
<item>51</item>
</string-array>

Now extract attached drawable.zip on RomControl drawable folder.

When you recompile the SystemUI, merge fonts zip on your assets folder (On recompiled apk)

We hope it will be useful :D
​