Android Question How can I create VIEW based CostumView/Lib

Tayfur

Well-Known Member
Licensed User
Longtime User


I was try it. Now again try it.

But; Same problem.

B4X:
Compiling generated Java code.    Error
B4A line: 125
If CustomView1 Is View Then
javac 1.8.0_25
src\b4a\Animation\Multiple\main.java:588: error: incompatible types: dddd cannot be converted to View
if (mostCurrent._customview1 instanceof android.view.View) {
               ^

B4X:
Sub CustomView1_DoubleClick
    Log("double")
 
    If CustomView1 Is View Then
        Log("view len")
    End If
End Sub


Now you can say to me
use it:
B4X:
Public sub AsView as View
   Retrun  Mainx
end sub


it is works basicly.
But I cant detecet set/get values

for example
animation lib ....

animation.intalizetranslate(CustomView1.asView,10,10,500,500)

On the process running..
animation lib change View.left Right, Top, Width... etc

My custumview has own set/Get LEFT /TOP etc. and they cant run.

animation lib change directly Mainx (Panel) change LEFT TOP....
How can I enter together.

I want to be....
CustomView1 Is View >>> Result = TRUE

--------------------------------------

Lib code
B4X:
'Events declaration
#Event: DoubleClick
#Event: SingleClick
'Class module
Sub Class_Globals
   Private mTarget As Object
   Private mEventName As String
   Private btn As Button
   Private topPanel As Panel
   Private downTime As Long
   Private timer1 As Timer
Private Mainx As Panel
End Sub

Public Sub Initialize (TargetModule As Object, EventName As String)
   mTarget = TargetModule
   mEventName = EventName
   timer1.Initialize("timer1", 300)
End Sub


Public Sub DesignerCreateView(Base As Panel, Lbl As Label, Props As Map)
   btn.Initialize("")
   'create a button and add it to the Base panel.
   Base.AddView(btn, 0, 0, Base.Width, Base.Height)
   btn.TextSize = Lbl.TextSize
   btn.TextColor = Lbl.TextColor
   btn.Gravity = Lbl.Gravity
   btn.Text = Lbl.Text
   btn.Typeface = Lbl.Typeface
   topPanel.Initialize("topPanel")
   'Add a transparent panel over the button.
   'the panel will handle the touch event.
   Base.AddView(topPanel, 0, 0, Base.Width, Base.Height)
Mainx=Base
End Sub

Private Sub topPanel_Touch (Action As Int, X As Float, Y As Float)
   If Action = topPanel.ACTION_DOWN Then
      If downTime + timer1.Interval > DateTime.Now Then
         timer1.Enabled = False
         'raise the DoubleClick event
         CallSub(mTarget, mEventName & "_" & "DoubleClick")
      Else
         downTime = DateTime.Now
         timer1.Enabled = True
      End If
   End If
End Sub

Private Sub Timer1_Tick
   timer1.Enabled = False
   'raise the event
   CallSub(mTarget, mEventName & "_" & "SingleClick")
End Sub
 
Upvote 0

Tayfur

Well-Known Member
Licensed User
Longtime User
Your class will never be a subclass of View. This is why you need to expose the AsView property.

My librarries can not run directly other libs (for ex animation lib.it need to view). My own SetLeft or getLeft cant run with animation lib.

I cheked other external libs @Erel
Sample

@warwound 's lib is view based. How do it?

B4X:
Sub CustomMenu_MenuClick
    Msgbox("Menu oldu","")
    If touchimageview1 Is View Then << Return is TRUE
        LogColor(touchimageview1,Colors.Red) '<<< @warwound  lib. 
        Log(CustomHelper) '<<<< my lib
        '>>>  wavwound lib source  >>> https://www.b4x.com/android/forum/threads/touchimageview.15616/
    End If

if CustomHelper is view then  '<<< return is FALSE
   log("this is View based")
end if

Log Result...
B4X:
(TouchImageView): Left=50, Top=50, Width=336, Height=5334

[ana_panel=(BALayout): Visible=false, Left=0, Top=0, Width=75, Height=75, callback=class b4a.example.main, text=(TextView): Left=0, Top=0, Width=75, Height=75, Text=49%, image_top=(BALayout): Left=0, Top=-762, Width=75, Height=762, image_name_corner_p=55.png, image_name_corner_n=55.png, image_left=(BALayout): Left=-1920, Top=0, Width=480, Height=75, eventname=CustomHelper, image_corner_p=(Bitmap): 48 x 48, image_corner_n=(Bitmap): 48 x 48, image=(ImageView): Left=0, Top=0, Width=75, Height=75, cx=0, first_touch=0.0, cy=0, horizontal_anchor=true

You say to me...
Your class will never be a subclass of View. This is why you need to expose the AsView property.

So Now i saw it is possible. @warwound 's lid do it.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

Tayfur

Well-Known Member
Licensed User
Longtime User
You need to know Java in order to write a library in Java. See the tutorials here: https://www.b4x.com/android/forum/forums/libraries-developers-questions.32/
You can post a feature request in the wishlist forum. Make sure to explain why do you need this feature (it is not clear from this thread).

Thank you for links, it is like a mine :) I will search it
My thread is not clear... :( sorry my bad english.

I explain it step by step with example.

B4X:
dim stdpanel is panel '<<< standart view
dim custompanel is mylib  '<< my lib
'.....
'..... intalize etc codes

B4X:
animation.translete(stdpanel,0,0,100,100)
animation.start
This codes (I think it) change stp panel coordinates
Yoour lib/animations works like :
1.step >>stdpanel.left=0
2.step >>stdpanel.left=10
3.step >>stdpanel.left=20
'- many time in cycle
10.step >> stdpanel.left=100

Codes work very welll
*******************************************************
Now We looks for mylib

cccc.png

B4X:
animation.translete(custompanel.asView,0,0,100,100)
animation.start
This codes (I think it) change only and directly MAIN_PANEL coordinates
Your lib/animations works like :
1.step >>MAIN_PANEL.left=0
2.step >>MAIN_PANEL.left=10
3.step >>MAIN_PANEL.left=20
'- many time in cycle
10.step >> MAIN_PANEL.left=100

But; Animations dont work my own "LEFT" method.
And Resluts are cant change Label1.Left dont change.
Iwant to work own method

***************************************

I wish
Your lib/animations works like :
B4X:
animation.translete(custompanel,0,0,100,100)
animation.start
1.step >>CustomPanel.left=0 (then mylib work auto change Label1.left and MAIN PANEL.Left)
2.step >>CustomPanel.left=10(then mylib work auto change Label1.left and MAIN PANEL.Left)
3.step >>CustomPanel.left=20(then mylib work auto change Label1.left and MAIN PANEL.Left)
'- many time in cycle
10.step >> CustomPanel.left=100(then mylib work auto change Label1.left and MAIN PANEL.Left)
 
Last edited:
Upvote 0

Tayfur

Well-Known Member
Licensed User
Longtime User
It should work. If you want then set top, left, width... of your custom view, you can use MyCustomView.AsView.Top = ...

or, if your "view" has Top property:
B4X:
Public sub setTop(Top As Int)
    Mainx.Top = Top
End sub

Thanky you feedback @LucaMs
Your way is nomaly run.

But, My problem is different.

I explane it #12
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
My thread is not clear... :( sorry my bad english.

... and my bad English does not allow me to understand the problem :D

I'm attaching a project, based on the code you posted; please, write what does not work as you expect.
(In your code there are a panel and a button as big as your custom view; I suppose you do not want this).
 

Attachments

  • CustomViewAnim.zip
    13.3 KB · Views: 142
Upvote 0

Tayfur

Well-Known Member
Licensed User
Longtime User
thank you Luca. I cant more spent your free time.


Shortly.
I want to control directly all customview objects.
Other codes/libs or methods cant change directly my object.
I want to full control.

Normalyy I control own object.
Like left pictures.

But other lib/methıods etc . directliy control own ojects in Customview
like right pictures

I can not interfere between my customview and other lib/method.
222.png


@warwound 's lib is view based. How do it?
B4X:
If touchimageview1 IsViewThen << ReturnisTRUE
LogColor(touchimageview1,Colors.Red) '<<< @warwound lib. Log(CustomHelper) '<<<< my lib
'>>> wavwound lib source >>> https://www.b4x.com/android/forum/threads/touchimageview.15616/EndIf
 
Upvote 0
Top