Java Question Custom View compiled as Library

LucaMs

Expert
Licensed User
Longtime User
I created a simple custom view (among other things it is not "behaving" as I would like). It is composed of very few lines of code.
It works in the designer (this will be a problem for what follows).

I also tried to compile it into a library.

1) You can not add the view in the code, because ... it is not a view!

2) The methods listed by the IDE include:
Base_Click
Class_Globals
DesignerCreateView
Initialize (target as object, as string EventName)

They are not ideal for a view and should still be hidden (private).

3) In the test project I use the Klaus' module Scale, which requires the JavaObject library. Although I have signed this module with the attribute # ExcludeFromLibrary: True, my library requires JavaObject.

I know, a lot of things that I have written are obvious, but for those who have already created custom views and libraries
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
You can make Base_Click private. You can also make Class_Globals private.
Initialize and DesignerCreateView must be public as they are called from outside.

3) You should remove the reference to JavaObject before you compile.

3) I tried but the result is what I imagined: the compiler reports an error, because the Scale module requires that library.
In my first test, I can remove that module (and I must also edit the Main) but in more complex projects
will not be useful # ExcludeFromLibrary: True.

Also, in my library I use two images. In a test app, I put a reference to my library, I added the view of my library in the designer and I get a java.io.FileNotFoundException: mycheck_102.png (at Runtime only)
 

LucaMs

Expert
Licensed User
Longtime User
I thought I had done something wrong in the construction of my custom view, since GetView generated an error.

Unfortunately, GetView "does not work" even with the AutoTextSizeLabel:
upload_2014-1-23_4-20-4.png


(I mistaken or custom views are all considered BALayout?)

Is there an alternative way?
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
You will need to add any referenced files to each project that uses the library.

The error you are getting is because AutoTextSizeLabel is a class not a view.


If a library uses an image file (internally) need i reference that file in my project? I can not know which files a library needs.
I now that Auto... is a class, but this means that I can never treat custom views as a view !?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
If a library uses an image file (internally) need i reference that file in my project?
Yes.

I now that Auto... is a class, but this means that I can never treat custom views as a view !?
Your class will not be a real View. However you can expose the base view with a sub and work with it.
 

LucaMs

Expert
Licensed User
Longtime User
I would like to use a checkbox without text.

The problem is that the small square is left-aligned instead of centered (images: 480x800 -240 on the left, on the right 800x1280 -243, both after Scale.ScaleAll(panel, True).
upload_2014-1-24_13-12-3.png


The worst thing is that, not only the square is left-aligned, but the proportions between it and the text are not maintained properly (and something has also changed the monetary currency :p. I'm kidding, of course)

I then thought of a simple custom view, but it would be my first, and in fact... I can not do it as I would like:).

I post ONE of the ways I 've tried. The problems are at least 3:

1) allow the use of transparent color;

2) (but this was just an oversight in the "project" designing - momentarily I wanted to simplify) would also have the extra square space, then an additional panel;

3) the best way to simulate the Panel.GetView (since the control will be part of an "item" in a scrollview ("you can expose the base", ok Erel, but the best way to do it? I know that i can add a private Panel var in the Globals, "pointing" to the Base and put in a sub to expose it, but I'm asking for the best way for the "emulation").

Without haste, when the Big (Klaus and Erel are more "specialized", but for the graphic we are fortunate to also have other good programmers, here), I would appreciate suggestions.

Thanks


[EDIT]

I changed the attachment. Now it is slightly better.

I have noticed that the designer turns Transparent in White (or maybe in color that i used for transparency)

(choise! that fool :p)
 

Attachments

  • LMCheckBox.zip
    14.8 KB · Views: 333
Last edited:

LucaMs

Expert
Licensed User
Longtime User
While testing I found a strange behavior:

B4X:
    imvCheckBox.Color = Colors.Transparent
imvCheckBox.Gravity = Gravity.FILL

B4X:
    imvCheckBox.Gravity = Gravity.FILL
imvCheckBox.Color = Colors.Transparent

In the second case the Fill is lost (note: only the Fill, not the picture)
 

LucaMs

Expert
Licensed User
Longtime User
Maybe I'm close to the solution (for the GetView).

I added these routines to the class of the custom view:

B4X:
Public Sub getObject As LMCheckBox
    Return Me
End Sub

Public Sub getBase As Panel
    mBase.Tag = Me
    Return mBase
End Sub

Public Sub GetObjType As String
    Return mType
End Sub

Private Sub SetMyType
    Dim LastDot As Int
    Dim strType As String = GetType(Me)
    LastDot = strType.LastIndexOf(".")
    mType = strType.SubString(LastDot + 1)
End Sub


Helps are still very welcome


P.S. (even though the scale is still a problem ... Klaus, help me :rolleyes:)
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
I have only been able to invent this method:

for each custom view that I add (to an activity or panel) I will be forced to add an invisible label; i'll put my custom view in its tag.

So, I'll get that label with GetView and my custom view from its tag.

Many thanks for your help :mad: :)


P.S. But I will not be able to add my custom view in the designer, to get it with GetView, even using the label
 
Last edited:

stevel05

Expert
Licensed User
Longtime User
Try this one:

I've been using quite a few custom views lately and have developed my own template. This uses that template. It provides all of the standard panel methods that act on the Base panel that is passed from the designer. It also creates it's own panel for the checkbox to sit on if you add it via code and the standard methods will act on that.

To add via code, you need to call the initialize and setup methods.

Please feel free to ask questions if it there is anything you don't understand.
 

Attachments

  • CheckboxCV.zip
    10 KB · Views: 320

LucaMs

Expert
Licensed User
Longtime User
Many thanks, Steve.

I try it immediately !!!!!!


P.S. EHM... Immediately after trying to adapt it to my V.3:00 :)

______________________________________________________
I update the post step by step.

1) Strangely, the Region work without quotation marks, I did not know

2) I tried to use SetCBDrawable, lol ... I imagine that it should be private.

[I'm trying it with interest, but I had resolved (so bad) using imageview.

What would be really useful is a kind of GetView]
 
Last edited:

stevel05

Expert
Licensed User
Longtime User
SetCBDrawable is a utility that you could apply to any checkbox. Although it probably should be private in this Class.

To expose the Base Panel you need a sub like:
B4X:
Sub getBaseView As Panel
    Return mBase
End Sub

And call it as:

B4X:
Dim Pnl As Panel = CheckBox1.BaseView

'Then code your getview

Pnl.getView(0)

Although in this CustomView there is only one View to get - the checkbox.
 

LucaMs

Expert
Licensed User
Longtime User
As I wrote, for the moment I solved in another way.
The aesthetic and functional result is optimal; it is not so from the point of view of the code I used!

By now, I did not write this in reference to my View, but the Custom View in general: it would be VERY useful to find a way to get A Custom View using GetView (I think that only Erel can solve this question, in a new version of B4A: simply adding an attribute #View, is it true Erel? ;)).

You could make two changes:

1) the handle is not in the center
2) I too, at first, I thought the Canvas with DrawText but I could not find the check mark (I even tried to draw it through Path! (is right "through" in this case??? usually, i use "using"... correct my poor english, please :)))


Thank you very much again, Steve.
 

LucaMs

Expert
Licensed User
Longtime User
damn, Steve, learn Italian, please!!! hehehe

I don't need to get a constitutive view of my Custom View;
I need to obtain my Custom View when it is in a panel (where this panel is an "item" in a scrollview).


uhm... you english people read "hehehe" as we "hihihi"... it is not nice!
Read: "haehaehae", maybe :p
 

stevel05

Expert
Licensed User
Longtime User
Ahh OK, If you are using Panel.GetView to test them then the Base panel will be found, you could put the EventName in the tag within the DesignerCreateView Sub and check that.

Example is V3 this time:)
 

Attachments

  • CheckboxCV.zip
    10.3 KB · Views: 318

LucaMs

Expert
Licensed User
Longtime User
Ahh OK, If you are using Panel.GetView to test them then the Base panel will be found, you could put the EventName in the tag within the DesignerCreateView Sub and check that.

Example is V3 this time:)


Thanks (also for the v3 :) ... how did you do? two PC or two instances of B4A?)

but this is what "I" need ("we", i could write):

we will use often, I think, some ScrollView containing panels that serve as items.

Let us assume that each item corresponds to a record in a db.
A checkbox (custom) is bound to a boolean field.

I try to get all the views from that panel, but I'll need to "convert" my custom view.

I could do:
Dim obj as Object = panel.GetView (7)

but the type of Obj will be BALayout and I will not be able to write:

myCustomCheckbox = Obj

and then I will not be able to use myCustomCheckbox with all its properties and its events.

(I write thinking of any kind of our Custom View!)



Thanks again for the time you are devoting to this, Steve.
 

stevel05

Expert
Licensed User
Longtime User
I have two instances of B4a on the same PC.

Try this one, adding 'me' to the Tag allows us to check the panel Tag with Is CheckBoxCV.

You can't then do Log(myCustomCheckBox) as Tag is part of the returned data or Log(myCustomcheckBox.Tag) as there will be a circular reference and it will fail spectacularly.
 

Attachments

  • CheckboxCV.zip
    10.5 KB · Views: 302
Top