Android Question TransitionDrawable

udg

Expert
Licensed User
Longtime User
Hi all,

It seems I can't figure out how to properly set types for the object in the title.
Its definition is available on this Android Developer page.
I am using the Reflection library. My goal is to set two BitmapDrawable objects and have the "startTransition" function working on those in order to fade out the first one while fading in the second one.

After a lot of try-and-error I feel it's time to call the community to rescue :)

udg
 

udg

Expert
Licensed User
Longtime User
Hi Erel.
Never tried JO before. Maybe it's time to learn something new...;)
Anyway, are you suggesting to use JO for the array and then Reflection to init the TransitionDrawable with that or instead doing everything by JO?
My attempts were based on code like the following
B4X:
xyz=r.CreateObject2("android.graphics.drawable.TransitionDrawable",Args,Types)
which generated any kind of error, based on what I set for types().
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Lacking any java knowledge made things a bit difficult..anyway here's what I came up with so far. It works!!

B4X:
Sub Globals
   Private ImgV3 As ImageView
   Dim a,b As BitmapDrawable
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("lytMain")
   a.Initialize(LoadBitmapSample(File.DirAssets,"image1.png",130dip,130dip))
   b.Initialize(LoadBitmapSample(File.DirAssets,"image2.png",130dip,130dip))
   test0(ImgV3,a,b)
End Sub

Sub test0(ivTran As ImageView, FirstImg As BitmapDrawable, SecondImg As BitmapDrawable)
   Dim jo As JavaObject
   Dim jBD As JavaObject
   jBD=jo.InitializeArray("android.graphics.drawable.Drawable", Array As Object(FirstImg,SecondImg))
   Dim jo2 As JavaObject
   jo2=jo.InitializeNewInstance("android.graphics.drawable.TransitionDrawable",Array As Object(jBD))
   ivTran.Background = jo2
   jo2.RunMethod("resetTransition",Null)
   jo2.RunMethod("startTransition",Array As Object(4000))
End Sub

Out of curiosity, what should have I done to code it with the Reflection lib?
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
Hi all,

It seems I can't figure out how to properly set types for the object in the title.
Its definition is available on this Android Developer page.
I am using the Reflection library. My goal is to set two BitmapDrawable objects and have the "startTransition" function working on those in order to fade out the first one while fading in the second one.

After a lot of try-and-error I feel it's time to call the community to rescue :)

udg
Look at the AnimationPlus library. It implements this class.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Hi Informatix,

I know and appreciate your lib AnimationPlus, but today my intention was to learn something new. Since I never used the JavaObject lib before, my first attempts were done with the Reflection lib, which every once in a while I use with some success.
So, it seems now I have got a new tool in my toolbox (although I've still a lot to learn before I can use it safely..eheh).

udg
 
Upvote 0

derez

Expert
Licensed User
Longtime User
with two Imageviews I get the same effect with SetVisibleAnimated:
B4X:
Sub Globals
Dim iv1,iv2 As ImageView
Dim b1,b2 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
b1.Initialize("b1")
Activity.AddView(b1,20%x,50%y,15%x,15%x)
b1.Text = 1
b2.Initialize("b2")
Activity.AddView(b2,65%x,50%y,15%x,15%x)
b2.Text = 2

iv1.initialize("")
iv2.Initialize("")
Activity.AddView(iv1, 25%x,5%y,50%x,35%x)
Activity.AddView(iv2, 25%x,5%y,50%x,35%x)
iv1.SetBackgroundImage(LoadBitmap(File.DirAssets,"28.jpg"))
iv2.SetBackgroundImage(LoadBitmap(File.DirAssets,"29.jpg"))
iv1.Gravity = Gravity.FILL
iv2.Gravity = Gravity.FILL
End Sub

Sub b1_click
    iv1.SetVisibleAnimated(4000,True)
    iv2.SetVisibleAnimated(4000,False)
End Sub

Sub b2_click
    iv1.SetVisibleAnimated(4000,False)
    iv2.SetVisibleAnimated(4000,True)
End Sub
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Hi derez,

I see there are so many ways to deploy that same effect as you, Informatix and NJDude (in another thread) suggested.
As stated above my goal was mainly to experiment with something new rather than achieve a specific visual effect.

Anyway, the TransitionDrawable object solution should be available to any Android and B4A release versions which is not necessarily true for the alternatives.

udg
 
Last edited:
Upvote 0
Top