Android Question Error AnimatedCounter only with Xiaomi MI 9

Watchkido1

Active Member
Licensed User
Longtime User
Solved!


Hello everybody

This error occurs only on Xiaomi MI 9 (MIUI Global 10.2.28; Android 9)
Everything is fine with Ulefone Power 5 (Android: 8.1.0) and Nexus 5 ( Android 6.0.1).
What am I doing wrong?

Thank you

B4X:
Logger verbunden mit:  Xiaomi MI 9
....
** Activity (counter) Create, isFirst = true **
animatedcounter_setvalue (java line: 312)
java.lang.IllegalArgumentException: Cannot set 'scaleX' to Float.NaN
    at android.view.View.sanitizeFloatPropertyValue(View.java:15446)
    at android.view.View.sanitizeFloatPropertyValue(View.java:15420)
    at android.view.View.setScaleX(View.java:14809)
    at android.animation.PropertyValuesHolder.nCallFloatMethod(Native Method)
    at android.animation.PropertyValuesHolder.access$400(PropertyValuesHolder.java:38)
    at android.animation.PropertyValuesHolder$FloatPropertyValuesHolder.setAnimatedValue(PropertyValuesHolder.java:1387)
    at android.animation.ObjectAnimator.animateValue(ObjectAnimator.java:990)
    at android.animation.ValueAnimator.setCurrentFraction(ValueAnimator.java:674)
    at android.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:637)
    at android.animation.ValueAnimator.start(ValueAnimator.java:1069)
    at android.animation.ValueAnimator.start(ValueAnimator.java:1088)
    at android.animation.ObjectAnimator.start(ObjectAnimator.java:852)
    at android.animation.ValueAnimator.startWithoutPulsing(ValueAnimator.java:1081)
    at android.animation.AnimatorSet.handleAnimationEvents(AnimatorSet.java:1142)
    at android.animation.AnimatorSet.startAnimation(AnimatorSet.java:1227)
    at android.animation.AnimatorSet.start(AnimatorSet.java:729)
    at android.animation.AnimatorSet.start(AnimatorSet.java:684)
    at anywheresoftware.b4a.objects.B4XViewWrapper.SetLayoutAnimated(B4XViewWrapper.java:158)
    at de.watchkido.redemeister.animatedcounter._setvalue(animatedcounter.java:312)
    at de.watchkido.redemeister.animatedcounter._designercreateview(animatedcounter.java:246)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
    at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:67)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:162)
    at anywheresoftware.b4a.objects.ActivityWrapper.LoadLayout(ActivityWrapper.java:209)
    at de.watchkido.redemeister.counter._activity_create(counter.java:375)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
    at de.watchkido.redemeister.counter.afterFirstLayout(counter.java:104)
    at de.watchkido.redemeister.counter.access$000(counter.java:17)
    at de.watchkido.redemeister.counter$WaitForLayout.run(counter.java:82)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:201)
    at android.app.ActivityThread.main(ActivityThread.java:6815)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
Application_Error
(IllegalArgumentException) java.lang.IllegalArgumentException: Cannot set 'scaleX' to Float.NaN
java.lang.IllegalArgumentException: Cannot set 'scaleX' to Float.NaN
    at android.view.View.sanitizeFloatPropertyValue(View.java:15446)
    at android.view.View.sanitizeFloatPropertyValue(View.java:15420)
    at android.view.View.setScaleX(View.java:14809)
    at android.animation.PropertyValuesHolder.nCallFloatMethod(Native Method)
    at android.animation.PropertyValuesHolder.access$400(PropertyValuesHolder.java:38)
    at android.animation.PropertyValuesHolder$FloatPropertyValuesHolder.setAnimatedValue(PropertyValuesHolder.java:1387)
    at android.animation.ObjectAnimator.animateValue(ObjectAnimator.java:990)
    at android.animation.ValueAnimator.setCurrentFraction(ValueAnimator.java:674)
    at android.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:637)
    at android.animation.ValueAnimator.start(ValueAnimator.java:1069)
    at android.animation.ValueAnimator.start(ValueAnimator.java:1088)
    at android.animation.ObjectAnimator.start(ObjectAnimator.java:852)
    at android.animation.ValueAnimator.startWithoutPulsing(ValueAnimator.java:1081)
    at android.animation.AnimatorSet.handleAnimationEvents(AnimatorSet.java:1142)
    at android.animation.AnimatorSet.startAnimation(AnimatorSet.java:1227)
    at android.animation.AnimatorSet.start(AnimatorSet.java:729)
    at android.animation.AnimatorSet.start(AnimatorSet.java:684)
    at anywheresoftware.b4a.objects.B4XViewWrapper.SetLayoutAnimated(B4XViewWrapper.java:158)
    at de.watchkido.redemeister.animatedcounter._setvalue(animatedcounter.java:312)
    at de.watchkido.redemeister.animatedcounter._designercreateview(animatedcounter.java:246)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
    at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:67)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:162)
    at anywheresoftware.b4a.objects.ActivityWrapper.LoadLayout(ActivityWrapper.java:209)
    at de.watchkido.redemeister.counter._activity_create(counter.java:375)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
    at de.watchkido.redemeister.counter.afterFirstLayout(counter.java:104)
    at de.watchkido.redemeister.counter.access$000(counter.java:17)
    at de.watchkido.redemeister.counter$WaitForLayout.run(counter.java:82)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:201)
    at android.app.ActivityThread.main(ActivityThread.java:6815)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
Copying updated assets files (145)
*** Service (starter) Create ***
Using FileProvider? true
/storage/emulated/0/1-Redemeister/Video/
defileprovider
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Firsttime:++++++++++++++++++++++++true
Firsttime1:++++++++++++++++++++++++False
Firsttime1:++++++++++++++++++++++++False
false
true
true
true
** Activity (main) Pause, UserClosed = false **
** Activity (counter) Create, isFirst = true **
0
0
0
Error occurred on line: 89 (AnimatedCounter)
java.lang.IllegalArgumentException: Cannot set 'scaleX' to Float.NaN
    at android.view.View.sanitizeFloatPropertyValue(View.java:15446)
    at android.view.View.sanitizeFloatPropertyValue(View.java:15420)
    at android.view.View.setScaleX(View.java:14809)
    at android.animation.PropertyValuesHolder.nCallFloatMethod(Native Method)
    at android.animation.PropertyValuesHolder.access$400(PropertyValuesHolder.java:38)
    at android.animation.PropertyValuesHolder$FloatPropertyValuesHolder.setAnimatedValue(PropertyValuesHolder.java:1387)
    at android.animation.ObjectAnimator.animateValue(ObjectAnimator.java:990)
    at android.animation.ValueAnimator.setCurrentFraction(ValueAnimator.java:674)
    at android.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:637)
    at android.animation.ValueAnimator.start(ValueAnimator.java:1069)
    at android.animation.ValueAnimator.start(ValueAnimator.java:1088)
    at android.animation.ObjectAnimator.start(ObjectAnimator.java:852)
    at android.animation.ValueAnimator.startWithoutPulsing(ValueAnimator.java:1081)
    at android.animation.AnimatorSet.handleAnimationEvents(AnimatorSet.java:1142)
    at android.animation.AnimatorSet.startAnimation(AnimatorSet.java:1227)
    at android.animation.AnimatorSet.start(AnimatorSet.java:729)
    at android.animation.AnimatorSet.start(AnimatorSet.java:684)
    at anywheresoftware.b4a.objects.B4XViewWrapper.SetLayoutAnimated(B4XViewWrapper.java:158)
    at de.watchkido.redemeister.animatedcounter._setvalue(animatedcounter.java:99)
    at de.watchkido.redemeister.animatedcounter._designercreateview(animatedcounter.java:407)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)
    at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:61)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:162)
    at anywheresoftware.b4a.objects.ActivityWrapper.LoadLayout(ActivityWrapper.java:209)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at de.watchkido.redemeister.counter.afterFirstLayout(counter.java:104)
    at de.watchkido.redemeister.counter.access$000(counter.java:17)
    at de.watchkido.redemeister.counter$WaitForLayout.run(counter.java:82)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:201)
    at android.app.ActivityThread.main(ActivityThread.java:6815)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)


Code Modul AnimatedCounter error at Private Sub TopFromValue (Digit As Int) As Int

B4X:
'version 1.10
#DesignerProperty: Key: Digits, DisplayName: Number Of Digits, FieldType: Int, DefaultValue: 4, Description: Number of digits
#DesignerProperty: Key: Duration, DisplayName: Animation Duration, FieldType: Int, DefaultValue: 1000, Description:

Sub Class_Globals
    Private mEventName As String 'ignore
    Private mCallBack As Object 'ignore
    Private mBase As B4XView 'ignore
    Private xui As XUI 'ignore
    Private ImageViews As List
    Private mdigits As Int
    Private lblTemplate As B4XView
    Private mValue As List
    Private DigitHeight, DigitWidth As Int
    Private mDuration As Int
    Private fade As B4XBitmap
    Private xfadeIv As B4XView
End Sub

Public Sub Initialize (Callback As Object, EventName As String)
    mEventName = EventName
    mCallBack = Callback
    ImageViews.Initialize
    mValue.Initialize
End Sub

'Base type must be Object
Public Sub DesignerCreateView (Base As Object, lbl As Label, Props As Map)
    mBase = Base
    Dim pnl As B4XView = xui.CreatePanel("") 'needed as the passed pane in B4J doesn't crop the child views
    mBase.AddView(pnl, 0, 0, 0, 0)
    mdigits = Props.Get("Digits")
    mDuration = Props.Get("Duration")
    lblTemplate = lbl
    fade = CreateFadeBitmap
    For i = 0 To mdigits - 1
        Dim iv As ImageView
        iv.Initialize("")
        ImageViews.Add(iv)
        mBase.GetView(0).AddView(iv, 0, 0, 0, 0)
    Next
    Dim fadeIv As ImageView
    fadeIv.Initialize("")
    xfadeIv = fadeIv
    mBase.GetView(0).AddView(fadeIv, 0, 0, 0, 0)
    setValue(0)
    If xui.IsB4A Then
        Base_Resize(mBase.Width, mBase.Height)
        setValue(getValue)
    End If
End Sub

Private Sub CreateFadeBitmap As B4XBitmap
    Dim bc As BitmapCreator
    bc.Initialize(200, 50)
    Dim r As B4XRect
    r.Initialize(0, 0, bc.mWidth, bc.mHeight / 3)
    bc.FillGradient(Array As Int(xui.Color_White, 0x00ffffff), r, "TOP_BOTTOM")
    r.Top = bc.mHeight * 2 / 3
    r.Bottom = bc.mHeight
    bc.FillGradient(Array As Int(xui.Color_White, 0x00ffffff), r, "BOTTOM_TOP")
    Return bc.Bitmap
End Sub


Private Sub Base_Resize (Width As Double, Height As Double)
    mBase.GetView(0).SetLayoutAnimated(0, 0, 0, Width, Height)
    xfadeIv.SetLayoutAnimated(0, 0, 0, Width, Height)
    xfadeIv.SetBitmap(fade.Resize(Width, Height, False))
    DigitHeight = Height
    Dim Columns As Int = mdigits
    DigitWidth = Width / Columns
    Dim bmp As B4XBitmap = CreateBitmap(lblTemplate)
    Dim left As Int = Width
    For i = 0 To ImageViews.Size - 1
        Dim iv As B4XView = ImageViews.Get(i)
        'from right to left
        left = left - DigitWidth
        iv.SetLayoutAnimated(0, left, TopFromValue(i), DigitWidth, DigitHeight * 10)
        iv.SetBitmap(bmp)
    Next
End Sub

Private Sub TopFromValue (Digit As Int) As Int
    Log(Digit) 'all 3 smartphones log "0" here
    Log(DigitHeight) 'all 3 smartphones log "0" here
    Dim d As Int = mValue.Get(Digit)
    Log(mValue.Get(Digit)) 'all 3 smartphones log "0" here
    Return -d * DigitHeight 'Only the Xiaomi MI9 crashes here
End Sub

Private Sub CreateBitmap (lbl As B4XView) As B4XBitmap
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, DigitWidth, DigitHeight * 10)
    Dim cvs As B4XCanvas
    cvs.Initialize(p)
    Dim voffset As Float = 0.7
    For i = 0 To 9
        cvs.DrawText(i, DigitWidth / 2, (i + voffset) * DigitHeight, lbl.Font, lbl.TextColor, "CENTER")
    Next
    cvs.Invalidate
    Dim res As B4XBitmap = cvs.CreateBitmap
    cvs.Release
    Return res
End Sub

Public Sub setValue(v As Int)
    mValue.Clear
    For i = 0 To mdigits - 1
        mValue.Add(v Mod 10)
        v = v / 10
        Dim iv As B4XView = ImageViews.Get(i)
        iv.SetLayoutAnimated(mDuration, iv.Left, TopFromValue(i), iv.Width, iv.Height)
    Next
  
End Sub

Public Sub getValue As Int
    Dim res As Int
    For i = 0 To mValue.Size - 1
        res = res + mValue.Get(i) * Power(10, i)
    Next
    Return res
End Sub

my Code

B4X:
#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim AnimatedCounter1 As AnimatedCounter
    Private Button1 As Button
    Dim v As Int = 0
    Private Button2 As Button
    Private Button3 As Button
    Dim Beeper1 As Beeper
    Private ToggleButton1 As ToggleButton
    Private ton As Boolean = False
    Private EditText1 As EditText
    Public p As Phone
    Dim Clrs(2) As Int
    Dim Gradient1 As GradientDrawable

End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Count")
    Activity.Title = "Füllwortzähler"

    EditText1.Text = File.ReadString(Main.PadDir, "1counter.txt")
    EditText1.TextSize = 20
    Button1.Text = "Zählen"
    Button2.Text = "Zurück"
    Button3.Text = "Reset"
    Beeper1.Initialize(100, 800)
    Activity.Title = Main.AppName
  
    Activity.AddMenuItem("Einstellungen","Hilfe")
    Activity.AddMenuItem("Hilfe","Hilfe")
    Activity.AddMenuItem("Feedback an Entwickler senden","Hilfe")
    
    Clrs(0) = Main.Farbe1
    Clrs(1) = Main.Farbe2
    Gradient1.Initialize("TOP_BOTTOM", Clrs)
    Activity.Background = Gradient1
  
End Sub




Sub Activity_Resume
    Main.Phone1.KeepAlive(True)
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    Main.Phone1.ReleaseKeepAlive
End Sub

Sub Button1_Click
    'Log(AnimatedCounter1.Value)
    v = v+1
    AnimatedCounter1.Value = v
  
    File.WriteString(Main.paddir,"1counter.txt",EditText1.Text)
    If ton Then Beeper1.Beep
End Sub

Sub Button2_Click
    'Log(AnimatedCounter1.Value)
    If v>0 Then
        v = v-1
    Else
        v = 0
    End If 
    AnimatedCounter1.Value = v
    File.WriteString(Main.paddir,"1counter.txt",EditText1.Text)
End Sub

Sub ToggleButton1_CheckedChange(Checked As Boolean)
    ton = Checked
    File.WriteString(Main.paddir,"1counter.txt",EditText1.Text)
End Sub

Sub Label1_Click
    File.WriteString(Main.paddir,"1counter.txt",EditText1.Text)
End Sub

Sub Button3_Click
    'Log(AnimatedCounter1.Value)
    v = 0
    AnimatedCounter1.Value = v
    File.WriteString(Main.paddir,"1counter.txt",EditText1.Text)
End Sub



Sub Activity_KeyPress (KeyCode As Int) 'return true if you want to consume the event
    If KeyCode = KeyCodes.KEYCODE_BACK Then
        File.WriteString(Main.paddir,"1counter.txt",EditText1.Text)
        Sleep(100)
        Activity.Finish
    Else
        File.WriteString(Main.paddir,"1counter.txt",EditText1.Text)
        Sleep(100)
    End If
End Sub
Sub Button4_Click
    File.WriteString(Main.paddir,"1counter.txt",EditText1.Text)
End Sub

Sub EditText1_EnterPressed
  
    p.HideKeyboard(Activity)
    File.WriteString(Main.paddir,"1counter.txt",EditText1.Text)
    Sleep(100)
End Sub

Sub Hilfe_click
    Dim N As String = Sender
    Frank.Hilfe(N)
End Sub
 
Last edited:

Watchkido1

Active Member
Licensed User
Longtime User
Solved!

I used "28" because the "Google Play" requested it

Not correct:<uses-sdk android:minSdkVersion="18" android:targetSdkVersion="28"/>

Right:
B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="18" android:targetSdkVersion="26"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)

EDIT:
Unfortunately, the Google Play Console requires "android: targetSdkVersion =" 28 "
This is not a problem with Ulefone Power 5 and Nexus 5, but Xiaomi MI 9 does not do that.
So I delete the counter out of the app.
 
Last edited:
Upvote 0
Top