B4A Library Reflection library

There will be lots to come in future versions of Basic4Android as Erel adds more of Androids capabilities. In the mean time there will be things that would be nice to have but are not actually implemented. This library will help to solve at least some of those requirements.

This is the Android equivalent of the Basic4ppc Door library that turned out to be so useful. There is a demo for the library that adds onFocus and onTouch events to views that don't implement them, accesses objects fields and runs methods.

A separate demo shows how to "Linkify" text so that URLs in the text become active hyperlinks.

EDIT:- Version 1.1 posted. See post #17 for details.

EDIT:- Version 1.2 posted. Bug fix. See post#19 for details.

EDIT:- Version 1.3 posted. See post#20 for details.

EDIT:- Version 1.4 posted. See post#21 for details.

EDIT:- Version 1.5 posted. See post #25 for details.

EDIT:- Version 1.6 posted. See post #31 for details.

EDIT:- Version 1.7 posted. See post #32 for details.

EDIT:- Version 1.8 posted. See post #33 for details.

EDIT:- Version 1.9 posted. See post #48 for details.

EDIT:- Version 2.0 posted. See post #51 for details.

EDIT:- Version 2.1 posted. See post #53 for details.

EDIT:- Version 2.2 posted for Basic4android 2.0 or later. Version 2.1 remains for earlier versions. See post #57 for details.

EDIT:- Informatix has produced Version 2.3 in post #317

EDIT:- Version 2.4 posted. See post #91 for details.
 

Attachments

  • Reflection2.1.zip
    33.2 KB · Views: 1,892
  • Reflection2.4.zip
    33 KB · Views: 4,136
Last edited:

campy74

New Member
Licensed User
Longtime User
I don't download this library

:sign0085:

Hi, I've purchase basic4android product yesterday but I don't have permission for download it... can you help me?

Thanks in advance



There will be lots to come in future versions of Basic4Android as Erel adds more of Androids capabilities. In the mean time there will be things that would be nice to have but are not actually implemented. This library will help to solve at least some of those requirements.

This is the Android equivalent of the Basic4ppc Door library that turned out to be so useful. There is a demo for the library that adds onFocus and onTouch events to views that don't implement them, accesses objects fields and runs methods.

A separate demo shows how to "Linkify" text so that URLs in the text become active hyperlinks.

EDIT:- Version 1.1 posted. See post #17 for details.

EDIT:- Version 1.2 posted. Bug fix. See post#19 for details.

EDIT:- Version 1.3 posted. See post#20 for details.

EDIT:- Version 1.4 posted. See post#21 for details.

EDIT:- Version 1.5 posted. See post #25 for details.

EDIT:- Version 1.6 posted. See post #31 for details.

EDIT:- Version 1.7 posted. See post #32 for details.

EDIT:- Version 1.8 posted. See post #33 for details.

EDIT:- Version 1.9 posted. See post #48 for details.

EDIT:- Version 2.0 posted. See post #51 for details.

EDIT:- Version 2.1 posted. See post #53 for details.

EDIT:- Version 2.2 posted for Basic4android 2.0 or later. Version 2.1 remains for earlier versions. See post #57 for details.
 

corwin42

Expert
Licensed User
Longtime User
Added RunPublicMethod.
This is a slightly more efficient i.e. slightly faster executing version of RunMethod4 but can only be used on Public methods.

Are you sure that this is implemented correct? It shows a signature of
RunPublicMethod(Method as String, Args() as Object, Types() as Class) as Object

If I try to pass the types as Stringarray I get a B4A compile error. If I try to pass the types as objectarray I get a ClassCastException at runtime.
 

agraham

Expert
Licensed User
Longtime User
The signature is correct for that method but it's not easily callable from Basic4android. :( I think it arose because I did a cut and paste of the internal private method that all the RunMethods end up calling and overlooked changing the "types" parameter type.
 

qsrtech

Active Member
Licensed User
Longtime User
Reflection use help, set class property value dynamically

Hi, I'm trying to use this library to set my custom classes properties dynamically. I grab the classes property names and values from a remote server. I currently use RTTI in Delphi to do this.


I could use a Select Case for every property but this becomes difficult to maintain everytime a new property is added to the class. I want something clean and simple like this:

'this is just concept code, not actual
Dim MyItem as MyClass
myItem.initialize()

Dim r as reflection
r.target=myitem

'loop through retrieved values
for a=1 to recordcount
sql=record(a-1)
aproperty=sql.field(0)
avalue=sql.field(1)
r.SetPublicField2(AProperty,AValue) 'doesn't seem to work
'vs
Select aproperty
Case "prop1"
myitem.prop1=avalue
Case "prop2"
myitem.prop2=avalue
Case "propx"
myitem.propx=avalue
End Select
next

I reviewed several examples but can't seem to figure out how to accomplish my goal. Can someone please kindly help me out?

Thanks!

John
 

Dominex

Active Member
Licensed User
Longtime User
Hi agraham,

I need to intercept within a class, pressing the menu, I tried the code below, but it does not work. Is there a way to do that?
B4X:
'Class module
Sub Class_Globals
   Private vActivity As Activity
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize (Target As Activity)
   vActivity = Target
   Dim r As Reflector
   r.Target = vActivity
   r.SetOnKeyListener("Activity_KeyPress")
End Sub

Private Sub Activity_KeyPress (ViewTag As Object, KeyCode As Int,KeyEvent As Object) As Boolean
   If KeyCode = KeyCodes.KEYCODE_MENU Then
      ToastMessageShow("OK",False)
      Return True
   End If
End Sub
 

agraham

Expert
Licensed User
Longtime User
Look in the logs. I guess you may have an "activity_keypress raiseEvent returned null" message. Erel will have to answer this as I am not familiar with how (or if) Basic4android Class methods are entered into the lookup table used to identify methods called as events.
 

dclarkchem

Member
Licensed User
Longtime User
Can't seem to get the library registered

Sorry, didn't see your response, but thanks for taking the time.

You can see from the first gif, that I have the Reflection.jar and the Reflection.xml in the additional subdirectory of B4A:

http://decsoftware.com/reflect.gif

but within B4A, I can't use the Reflection library. You can see that despite 'refreshing', restarting B4A and even restarting the computer, I can't use the library:

http://decsoftware.com/reflect2.gif

OK, I put them in a file folder called additional, and I get the same results.


I'm probably missing something simple.


Thanks!
 
Last edited:

dclarkchem

Member
Licensed User
Longtime User
THANK YOU! I never saw that before (and I had successfully installed the ByteConverter several weeks ago in another subdirectory).
 

burutxaga

New Member
Licensed User
Longtime User
Error when compiling with the Reflection library

Hello,
I've just installed the Reflection Library and loaded the ReflectionDemo program in the IDE.
When I try to compile I get this error:

Compiling code. 0.04
Compiling layouts code. 0.01
Generating R file. 1.01
Compiling generated Java code. 1.36
Convert byte code - optimized dex. Error
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.NullPointerException
at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:179)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:123)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
at com.android.dx.command.dexer.Main.processOne(Main.java:418)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:329)
at com.android.dx.command.dexer.Main.run(Main.java:206)
at com.android.dx.command.dexer.Main.main(Main.java:174)
at com.android.dx.command.Main.main(Main.java:95)
1 error; aborting
Standard dexer.

Can anyone help me? :BangHead:
 

burutxaga

New Member
Licensed User
Longtime User
Error

Hello, and thanks for your anwswer.

I have the project at the same directory where I have ther other projects (at c:\users\Txus\Android\b4a programas\), with no problem at all with the other projects.

Anywhere, I copied the proyect to C:\reflection, loaded it and compiled it again, and the result was the same.

Thanks
 
Top