Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

[Q] Access variables in an outer class

OP perseus0807

25th June 2014, 03:11 PM   |  #1  
OP Senior Member
Flag Pune
Thanks Meter: 55
 
129 posts
Join Date:Joined: Mar 2011
Donate to Me
More
Hullo, you lot. I was working on my own xposed module - and I had a bit of a question. Assuming I'm hooking into a function that's a member of a nested class, how do I refer to objects in the outer class? Here's what I'm trying to hook into - initContentView is a member function of the class ActionPopupWindow, which is inside the outer class Editor. I'm trying to access mTextView - a TextView defined within Editor, not ActionPopupWindow.

Any suggestions? Cheers
25th June 2014, 08:11 PM   |  #2  
Tungstwenty's Avatar
Recognized Contributor
Thanks Meter: 4,407
 
1,824 posts
Join Date:Joined: Nov 2011
Donate to Me
More
Quote:
Originally Posted by perseus0807

Hullo, you lot. I was working on my own xposed module - and I had a bit of a question. Assuming I'm hooking into a function that's a member of a nested class, how do I refer to objects in the outer class? Here's what I'm trying to hook into - initContentView is a member function of the class ActionPopupWindow, which is inside the outer class Editor. I'm trying to access mTextView - a TextView defined within Editor, not ActionPopupWindow.

Any suggestions? Cheers

Use XposedHelpers.getSurroundingThis(...), something like:
Code:
Object outerObject = XposedHelpers.getSurroundingThis(param.thisObject);
Object fieldValue = XposedHelpers.getObjectField(outerObject, "mTextView");
...
However, for the specific case you mention I don't think this is what you need. mTextView isn't defined on the Editor class but rather on PinnedPopupWindow, which is also an inner class and a superclass of ActionPopupWindow.
getObjectField() is aware of fields on superclasses and will fetch it for you just by using:
Code:
XposedHelpers.getObjectField(param.thisObject, "mTextView");
The Following User Says Thank You to Tungstwenty For This Useful Post: [ View ]
25th June 2014, 10:14 PM   |  #3  
OP Senior Member
Flag Pune
Thanks Meter: 55
 
129 posts
Join Date:Joined: Mar 2011
Donate to Me
More
This is exactly what I was looking for, thank you! Although you were wrong about the inherited part; mTextView is a member of Editor.

I'm curious - where did you read all this? There doesn't seem to be very cohesive documentation on the wiki :/

Thanks again!
26th June 2014, 01:01 AM   |  #4  
GermainZ's Avatar
Forum Moderator / Recognized Developer / XDA Portal Team
Thanks Meter: 7,330
 
5,909 posts
Join Date:Joined: Aug 2012
Donate to Me
More
Quote:
Originally Posted by perseus0807

This is exactly what I was looking for, thank you! Although you were wrong about the inherited part; mTextView is a member of Editor.

I'm curious - where did you read all this? There doesn't seem to be very cohesive documentation on the wiki :/

Thanks again!

You can check the helper classes (e.g. XposedHelpers) and read the Java docs.
26th June 2014, 01:29 AM   |  #5  
Tungstwenty's Avatar
Recognized Contributor
Thanks Meter: 4,407
 
1,824 posts
Join Date:Joined: Nov 2011
Donate to Me
More
Quote:
Originally Posted by perseus0807

This is exactly what I was looking for, thank you! Although you were wrong about the inherited part; mTextView is a member of Editor.

I'm curious - where did you read all this? There doesn't seem to be very cohesive documentation on the wiki :/

Thanks again!

There is a wiki page about the helpers, but it doesn't cover them all. The best thing is to check the existing methods and read the javadocs, as mentioned by GermainZ.
Post Reply Subscribe to Thread

Tags
android, nested, xposed
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes