[Android General] Grouxho:
Guide - A bit different way for Toast Animations

This is the same mod than the one [MENTION=5405448]thereassaad[/MENTION] shared, but i think in this way we save time in implementing the mod and also some cpu cycles on every toast. At least is what this small modification of the mod pretends..

1- Read and Download [MENTION=5405448]thereassaad[/MENTION] guide from here

https://xdaforums.com/showpost.php?p=76950488&postcount=294

2.- Add the animations to framework-res , compile, etc

3.- Decompile services.jar and

- Edit Lcom/android/server/policy/PhoneWindowManager$SettingsObserver.smali

add this block of code

.method observe()V
.locals 4

const/4 v3, 0x0

const/4 v2, -0x1

iget-object v1, p0, Lcom/android/server/policy/PhoneWindowManager$SettingsObserver;->this$0:Lcom/android/server/policy/PhoneWindowManager;

iget-object v1, v1, Lcom/android/server/policy/PhoneWindowManager;->mContext:Landroid/content/Context;

invoke-virtual {v1}, Landroid/content/Context;->getContentResolver()Landroid/content/ContentResolver;

move-result-object v0

[COLOR="RoyalBlue"]	#### add this block of code

const-string/jumbo v1, "g_toast_animation" ## change the preference key to your convenience

invoke-static {v1}, Landroid/provider/Settings$System;->getUriFor(Ljava/lang/String;)Landroid/net/Uri;

move-result-object v1

invoke-virtual {v0, v1, v3, p0, v2}, Landroid/content/ContentResolver;->registerContentObserver(Landroid/net/Uri;ZLandroid/database/ContentObserver;I)V

#########[/COLOR]

- Now edit Lcom/android/server/policy/PhoneWindowManager.smali

Add this var

# instance fields

[COLOR="royalblue"].field public mGrxToastAnimation:I ### add this field[/COLOR]

Now locate updateSettings()V method and add the following line

.method public updateSettings()V
.locals 14

const/4 v8, 0x2

const/4 v9, 0x1

iget-object v10, p0, Lcom/android/server/policy/PhoneWindowManager;->mContext:Landroid/content/Context;

invoke-virtual {v10}, Landroid/content/Context;->getContentResolver()Landroid/content/ContentResolver;

move-result-object v3

[COLOR="royalblue"]	## add next line
invoke-virtual {p0, v3}, Lcom/android/server/policy/PhoneWindowManager;->grxSetToastAnimation(Landroid/content/ContentResolver;)V ### add this line[/COLOR]

Now add the following method to the end

.method public grxSetToastAnimation(Landroid/content/ContentResolver;)V ######### add this method at the end
.locals 4

const-string v0, "g_toast_animation"

invoke-static {p1, v0}, Landroid/provider/Settings$System;->getString(Landroid/content/ContentResolver;Ljava/lang/String;)Ljava/lang/String;

move-result-object v0

if-eqz v0, :cond_def

invoke-static {v0}, Landroid/text/TextUtils;->isEmpty(Ljava/lang/CharSequence;)Z

move-result v1

if-nez v1, :cond_def

:goto_goon

iget-object v1, p0, Lcom/android/server/policy/PhoneWindowManager;->mContext:Landroid/content/Context;

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

move-result-object v1

const-string v2, "style"

const-string v3, "android"

invoke-virtual {v1, v0, v2, v3}, Landroid/content/res/Resources;->getIdentifier(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I

move-result v0

iput v0, p0, Lcom/android/server/policy/PhoneWindowManager;->mGrxToastAnimation:I

return-void

:cond_def

const-string v0, "Animation.Toast"

goto: goto_goon

.end method

And finally we see why i made these small changes

Go to

.method public adjustWindowParamsLw(Landroid/view/WindowManager$LayoutParams;)V

and add the indicated modifications

.method public adjustWindowParamsLw(Landroid/view/WindowManager$LayoutParams;)V
.locals 12

const-wide/16 v10, 0xdac

...

[COLOR="seagreen"]:sswitch_83 ### sswitch for windown type 0x7d5[/COLOR]

iget-wide v2, p1, Landroid/view/WindowManager$LayoutParams;->hideTimeoutMilliseconds:J

const-wide/16 v4, 0x0

cmp-long v1, v2, v4

if-ltz v1, :cond_91

iget-wide v2, p1, Landroid/view/WindowManager$LayoutParams;->hideTimeoutMilliseconds:J

cmp-long v1, v2, v10

if-lez v1, :cond_93

:cond_91
iput-wide v10, p1, Landroid/view/WindowManager$LayoutParams;->hideTimeoutMilliseconds:J

:cond_93

[COLOR="royalblue"]	const v2, 0x0 #### add this line

iget v1, p0, Lcom/android/server/policy/PhoneWindowManager;->mGrxToastAnimation:I #### add this line

if-ne v1, v2, :cond_abab #### add this line[/COLOR]

const v1, 0x1030004

[COLOR="RoyalBlue"]:cond_abab #### add this line[/COLOR]

iput v1, p1, Landroid/view/WindowManager$LayoutParams;->windowAnimations:I

goto/16 :goto_d

...
..

.sparse-switch
0x7d0 -> :sswitch_5c
[COLOR="SeaGreen"]0x7d5 -> :sswitch_83 ### Look for the corresponding sswitch tag for 0x7d5 (toast type)[/COLOR]
0x7d6 -> :sswitch_4d
0x7df -> :sswitch_4d
0x7f4 -> :sswitch_7c
.end sparse-switch
.end method

The logic is simple, if mGrxToastAnimation:I is 0x0 (animation not found or not valid) we use stock animation. We make the most of the existing observer to observe our rom control preference. When it changes we calculate the animation id (mGrxToastAnimation:I ) . When a toast appear we use this id, instead of a pswitch, so less processing.

Finally in your Rom Control app (myListPreference in 6th or GrxSingleSelection in GrxSettings) your values array for the preference should be the animation style names instead of a number.

We avoid the match of ids in the mod now. If we add a new animation we only have to add it to our rc app, nothing else.

<string-array name="toast_animation_values">
<item>Animation.Toast</item>
<item>Animation.Toast.Fade</item>
<item>Animation.Toast.SlideRight</item>
<item>Animation.Toast.SlideLeft</item>
<item>Animation.Toast.Xylon</item>
<item>Animation.Toast.Toko</item>
<item>Animation.Toast.Tn</item>
<item>Animation.Toast.Honami</item>
<item>Animation.Toast.FastFade</item>
<item>Animation.Toast.GrowFade</item>
<item>Animation.Toast.GrowFadeCenter</item>
<item>Animation.Toast.GrowFadeBottom</item>
<item>Animation.Toast.Translucent</item>
<item>Animation.Toast.SlideLeftRight</item>
<item>Animation.Toast.SlideRightLeft</item>
</string-array>