Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,786,281 Members 50,230 Now Online
XDA Developers Android and Mobile Development Forum

[Q] Access variables in an outer class

Tip us?
 
perseus0807
Old
#1  
Senior Member - OP
Thanks Meter 52
Posts: 127
Join Date: Mar 2011
Location: Pune

 
DONATE TO ME
Question [Q] Access variables in an outer class

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
 
Tungstwenty
Old
#2  
Tungstwenty's Avatar
Recognized Contributor
Thanks Meter 4,374
Posts: 1,808
Join Date: Nov 2011

 
DONATE TO ME
Quote:
Originally Posted by perseus0807 View Post
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");

Device: Xperia Z (C6603)
ROM: Stock 4.4.2 10.5.A.0.230
Locked bootloader, rooted, XZDualRecovery
Retired device: Samsung Galaxy S2 (GT-I9100)

My threads that you might find useful:

SUPERCOMPUTER: what it sounded like before you bought it
The Following User Says Thank You to Tungstwenty For This Useful Post: [ Click to Expand ]
 
perseus0807
Old
#3  
Senior Member - OP
Thanks Meter 52
Posts: 127
Join Date: Mar 2011
Location: Pune

 
DONATE TO ME
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!
 
GermainZ
Old
#4  
GermainZ's Avatar
Forum Moderator / Recognized Developer
Thanks Meter 6,218
Posts: 5,365
Join Date: Aug 2012
Quote:
Originally Posted by perseus0807 View Post
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.
 
Tungstwenty
Old
#5  
Tungstwenty's Avatar
Recognized Contributor
Thanks Meter 4,374
Posts: 1,808
Join Date: Nov 2011

 
DONATE TO ME
Quote:
Originally Posted by perseus0807 View Post
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.

Device: Xperia Z (C6603)
ROM: Stock 4.4.2 10.5.A.0.230
Locked bootloader, rooted, XZDualRecovery
Retired device: Samsung Galaxy S2 (GT-I9100)

My threads that you might find useful:

SUPERCOMPUTER: what it sounded like before you bought it
Tags
android, nested, xposed
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes