B4A Library Allow end users to change (and save) layout's views positions while running live the apk

Discussion in 'Additional libraries, classes and official updates' started by Yayou49, Sep 9, 2018.

  1. Yayou49

    Yayou49 Active Member Licensed User

    Hi,

    This new library is based on my experience of end users requirements for Windows app or even Android app about UI modifications.
    Even if your UI is quite beautifull, there is always one (or more) end user asking to change the shape of your layout

    This new library allow end users to change by themselves the position of each view in your layout while running live the apk.

    Enclosed, you will find the .jar and .xml to put into your additional library folder, and also a test project.

    Just bellow, a video to show how it works (read the video until the end) followed by requirements to use the library.

    In this test, to enter in modification mode, I've set the event on Activity_LongClick.
    To save modifications, it's also on Activity_LongClick.
    Of course, you can handle fonctionnalities with all others events you want.

    NB: this library has no pretension and works with very simple layout only.




    EDIT#1:
    Library has been updated to V1.01 in first post:
    - Avoid crash on recursive Views (debug mode will generate huge log of error but no impact on apk. I'm trying to solve it ASAP)
    - populate different colors in modification mode according to views types

    EDIT#2:
    Library has been updated to V1.02 in first post:
    - Huge log of error solved.

    Requirements:
    (Based on one Activity module you want to populate)

    - in your Starter class, add a reference to RuntimePermissions (as shown in test file)

    - Add the library "CustomLayout" into your project

    - Add in your Sub Global:
    Code:
    Sub Globals
     
       
    Dim Cust As CustomLayout
       
    Dim mbase As Panel
       
    Dim Flag As Boolean
       
    Dim LayoutName As String
       
    Dim ActivityName As String
       
    Dim FileDir As String
     
    End Sub
    - Add In your Sub Activity_Create:

    Code:
    Sub Activity_Create(FirstTime As Boolean)
     
       LayoutName = 
    "...your layout name..."  'LayoutName will be used in some others places
     
       
    Activity.LoadLayout(LayoutName)
     
       Init
     
    End Sub
    - Add the following sub into your activity code:

    Code:
    Sub Init
     
       FileDir = Starter.SharedFolder
     
       
    'Initialize views
       'set the tag for all views
       'if you already set a tag for a view, you will find it under map.get("Owner") in your view tag
       ActivityName = Me
       Cust.Initialize(Me,
    "Custo")
       Cust.Name(ActivityName,LayoutName,FileDir)
       mbase.Initialize(
    "mbase")
       Flag = 
    False
     
       
    'set all existing views
       For Each V As View In Activity.GetAllViewsRecursive
           Cust.InitLst(v)
       
    Next
     
       LayoutRedraw
    End Sub



    Private Sub activity_LongClick
     
       
    If Flag = True Then
     
           mbaseLongClick
     
       
    Else
           
    Dim Choice As Int = Msgbox2("What would you like to do ?","Settings","Set default values","Quit","Change layout",Null)

           
    Select Case Choice
     
               
    Case -1  'set default
     
                   Cust.RAZ
                   
    Activity.RemoveAllViews
                   
    Activity.LoadLayout(LayoutName)
                   Init
                   Flag = 
    False
     
               
    Case -2 'change layout
       
                   
    Activity.RemoveAllViews
                   mbase = Cust.Init(
    100%x,100%y)
                   
    Activity.AddView(mbase,0,0,mbase.Width,mbase.Height)
                   Flag = 
    True
     
               
    Case Else
                   Flag = 
    False
           
    End Select
       
    End If
     

    End Sub

    Private Sub LayoutRedraw
     
     
       
    If File.Exists(FileDir, ActivityName & "_" & LayoutName & "_Custo" & ".map") = True Then
     
           Cust.Name(ActivityName,LayoutName,FileDir)
       
           
    'Apply new settings
           For Each V As View In Activity.GetAllViewsRecursive
               v = Cust.Draw(v)
           
    Next
       
    End If
     
       Flag = 
    False
     
    End Sub


    Sub mbaseLongClick
     
       Cust.Save
       
    For Each v As View In Activity.GetAllViewsRecursive
           v.RemoveView
       
    Next
       
    Activity.LoadLayout(LayoutName)
     
       LayoutRedraw
     
       Flag = 
    False
     
    End Sub
     

    Attached Files:

    Last edited: Sep 11, 2018
  2. peacemaker

    peacemaker Well-Known Member Licensed User

    Is there any internal lock flag ? To fix the layout immediately.
     
  3. Yayou49

    Yayou49 Active Member Licensed User

    What do you mean with "fix the layout immediately" ?
     
  4. peacemaker

    peacemaker Well-Known Member Licensed User

    Stop editing and disallow change.
     
  5. Yayou49

    Yayou49 Active Member Licensed User

    No, there is no such flag.
    I think If you want to handle this kind of feature, you have to manage it in your project to allow or not the call to sub "init" in ActivityCreate.

    You can also add a flag in Activity_LongClick to allow or not, but it will be manage by your project and not by the Library.

    Hope it fits your goal o_O
     
    Last edited: Sep 11, 2018
    peacemaker likes this.
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