Android Question TransitionDrawable

Discussion in 'Android Questions' started by udg, Jan 27, 2015.

  1. udg

    udg Expert Licensed 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
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Shouldn't be too difficult. You should use JavaObject instead of Reflector. It is simpler.

    Create a new array of type: android.graphics.drawable.Drawable with JavaObject.InitializeNewArray.
     
  3. udg

    udg Expert Licensed 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
    Code:
    xyz=r.CreateObject2("android.graphics.drawable.TransitionDrawable",Args,Types)
    which generated any kind of error, based on what I set for types().
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Only use JavaObject.
     
  5. udg

    udg Expert Licensed User

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

    Code:
    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?
     
  6. Informatix

    Informatix Expert Licensed User

    Look at the AnimationPlus library. It implements this class.
     
  7. udg

    udg Expert Licensed 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
     
    Informatix likes this.
  8. derez

    derez Expert Licensed User

    with two Imageviews I get the same effect with SetVisibleAnimated:
    Code:
    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
     
  9. udg

    udg Expert Licensed 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: Jan 28, 2015
  10. derez

    derez Expert Licensed User

    Thanks for your effort !
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice