How to write variable of activity that contains fragment class from inside current Fragment? - android-activity

I have an activity with indefinite number of fragments. Inside fragments there is a variable that need to access in the activity to call an intend from activity bar correctly.
But only the variable of the current fragment is on screen.
This is because the call depends of the fragment you are.
Due to fragment manager creates three fragment at a time can't write a variable calling from inside fragment because i don't know who is the last that writes variable.
Need to identify the fragment is displayed.
I tried from inside to control visibility overriding setUserVisibleHint(boolean b) and write variable when true but same happends. not guaranteed that the current fragment is the last writting.
I also tried getting the current fragment from activity to call fragment method and get this variable. But is difficult to identify current fragment. I tried this:
getsupportFragmentManager()
.findFragmentByTag("android:switcher:"+R.id.myViewPager+":"+myViewPager.getCurrentItem()).getVariable();
But have null Pointer Exception.

Related

MRTK Add ManipulationHandler in C#

I'm attempting to dynamically add Manipulation Events to a ManipulationHandler that is being added to child objects of a parent. The parent object will be what the user is inspecting, but the user will be able to grab parts off of the parent and inspect them more closely. (i.e. you can look at an engine (parent object), but if you want to inspect the pistons (child objects) you can grab them and look at them)
Instead of having to go into every child object and manually add it in Unity I'd like to be able to add the parent object and just procedurally add the ManipulationHandler and ManipulationEvents on start or awake.
So far I have the following code for adding the ManipulationHandler script, but to add the ManipulationEvent I'm not sure how to set up the pointers so I can use the script and function I want from the source:
gameObject.AddComponent<ManipulationHandler>();
ManipulationHandler handler = gameObject.GetComponent<ManipulationHandler>();
ManipulationEvent newevent = new ManipulationEvent();
ManipulationEventData eventdata = new ManipulationEventData();
eventdata.ManipulationSource = gameObject;
The program works when I grab the objects, but I'd like to add manipulation events when I grab them so I can display additional data.
I see there's a getter and setter for Pointer in ManipulationEventData, but I'm not sure how to instantiate IMixedRealityPointer and how to get it to work. I'm also not sure if that's the object I actually need to accomplish what I'd like to accomplish.
I apologize in advance if I've missed something obvious. I'm new to MRTK.
Thanks!
The ManipulationHandler has four callback events among them OnManipulationStarted and OnManipulationEnded you can simply add listeners to. (see UnityEvent.AddListener)
Unless I understood your question wrong you don't have to instantiate any IMixedRealityPointer. You don't create the event data yourself but rather the ManipulationHandler feeds these events with the current event data including the interacting pointer information. The ManipulationHandler uses OnPointerDown and OnPointerDragged and OnPointerUp via the IMixedRealityPointerHandler interface in order to manage the interacting pointers and invokes the according events where needed.
Instead of using AddComponent followed by GetComponent directly store and use the return value of AddComponent which will be the reference of the newly added Component. MRTK also has an extension method
T EnsureComponent<T>(this Component component) where T : Component
so that you can simply use e.g.
var handler = this.EnsureComponent<ManipulationHandler>();
which internally first checks whether the component already exists, and if not it adds it.
Note that in order to enable near interactions you will also need a NearInteractionGrabbable so you should add this one too.
You also will have to make sure that your objects have some sort of Collider attached to the same GameObject as the NearInteractionGrabbable.
...
gameObject.transform.EnsureComponnet<NearInteractionGrabbable>();
var handler = gameObject.transform.EnsureComponnet<ManipulationHandler>();
handler.OnManipulationStarted.AddListener(HandleOnManipulationStarted);
handler.OnManipulationEnded.AddListener(HandleOnManipulationEnded);
...
/// <summary>
/// If you need it later you need to store the pointer since unfortunately in
/// OnManipulationEnded the <see cref="ManipulationEventData.Pointer"/> is null
/// (no idea why they do it this way :D )
/// </summary>
private IMixedRealityPointer _pointer;
private void HandleOnManipulationStarted(ManipulationEventData eventData)
{
_pointer = eventData.Pointer;
// whatever shall happen when manipulation started
}
private void HandleOnManipulationEnded(ManipulationEventData eventData)
{
// whatever shall happen when manipulation ended
}
Note: I am not sure if this thing you are trying to achieve is possible with this architecture ... it is very possible that nesting various ManipulationHanlder leads to strange behavior here and there. Especially very small parts will be almost impossible to grab ...

How to make eclipse cdt UI Blocking code run in background and show the result in an editor after finishing the run?

In Eclipse CDT at DefaultBinaryFileEditor class, in the method getStorage there is a comment that tells the line objdump.getOutput(limitBytes) is a UI blocking call...
How can I make it run in background without UI Blocking to process longer files than it is stated with parameter int limitBytes = 6*1024*1024;
I can access org.eclipse.cdt.utils.Objdump class' getOutput method via plugin.xml extension point "org.eclipse.cdt.core.BinaryParser"...
I tried to replace the class that is used in extension point "org.eclipse.ui.editors" in editor tag with id "org.eclipse.cdt.ui.binaryEditor" via my plugin.xml, but this did not worked.
I put a boolean flag to outer class and in inner class BinaryFileEditorInput in method getStorage I put a Job and before this job works I created an empty fStorage = new FileStorage. I return this empty fstorage. So first the editor gets blank. Then when the objdump.getOutput(limitBytes) method returns in job, I set the fStorage to the returned output. I simply call the outer class'es refresh method. I put a reference of created outer class to inner static class in outerclasses constructor. This way I can access the refresh method. Also I moved fStorage varible to outerclass because refresh method triggers creating a new inner class so it overrides the valuable fStorage variable.
Finally If you want to update the opened elf file editor when you build the project again, assign the boolean variable and fStorage to first values in method resourceChanged before calling refresh method.

access a variable from level blueprint in unreal engine 4

I Have a variable that updates every time i move my cube in the level blueprint , now i want to access this variable from multiple class blueprints , what do I do , I tried casting to gamestate but didn't succeed , I am really new to ue4 if you could explain in details please
edit: sorry for not adding details ,
The var I want to access is an integer named cube_side that tells me what side the cube is on every time I move , all of this happens in the level bp , I want to access this variable to see what side the cube is on from other class blueprints ->
here are some details in a picture
I know it's not good to code everything in the level blueprint , but it's too late now , I only need to transfer the var cube_side to other class blueprints so the other object can change depending what side the cube is on.
Create an Actor Class for your logic/functionality. Then use Get all actors of class (choose your class) -> Get a copy -> get variable
Communication with the level blueprint is rather tricky in UE4, since they are not as persistent as e.g. the GameMode, and therefore shouldn't be accessed directly (Imagine older games like Final Fantasy where a new level was loaded every time you stepped outside a boundary, so relying on it could potentially break your actors or crash the game due to nullptrs).
It's a little hacky, but works:
Move the variable inside the cube-blueprint. Add an event dispatcher to the cube, if it is moved, call it and pass the variable in.
Select the cube in the editor, open the level blueprint, right-click, "add reference to selected actor" (the cube must be part of a blueprintclass, not only a static mesh dragged in, though), and bind the event dispatcher inside the Level BP.
Create a function inside every blueprint that needs access to the variable, which does whatever it should do, depending on the variable.
The custom event of the Level Bp (that was bound to the Event Dispatcher of the cube), needs references to all actors that have to work, when the variable changes and call each Actors function (you can get the references like you got the one from the cube)
Then, every time the variable changes, the Level BP is notified, the custom Event is executed and this custom event calls all the actor's functions.
Event Dispatchers explained
This is a huge wastage of functions/code, since you only need it for this one level and may never use it again. Avoid this in the future, by not relying on the level BP so much.
You can use GameStateBP to create and store all variables that you need in game, in GameModeBP create functions to get and set this variables via Get Game State function and then function Cast To GameState and then logic. After that from any blueprint access it using Get Game Mode -> Cast to you GameMode -> use your function to set or get data from GameState.

AnyLogic - create objects dynamically on simulation time

Is it possible to dynamically create objects or modify them on run-time ?for example,on button click,another button created or change number of lines of a road?
When I write this code for a button Action,in run-time
road123.setBackwardLanesCount(3);
I get error below:
root:
road123: Markup element is already initiated and cannot be modified.Please use constructor without arguments,perform setup and finally call initialize() .function
You'll get that error with any object you attempt to create at runtime using a parameterized constructor. If you create the object with a simple constructor (just "()") and then set all of the parameters individually, you won't run into that issue. Check the Anylogic API for specific information about the object you are using, because some require you to call .initiliaze() on that object after setting all of it's parameters if you created it using a simple constructor. Furthermore, if you want to add the object to the screen at runtime you'll need to add this code to the function that creates it:
#Override
public void onDraw( Panel panel, Graphics2D graphics) {
obj.drawModel(panel, graphics, true);
}
where obj is replaced with the name of the object you created dynamically.

Passing parameters in mvp pattern

This might be a general mvp places and activities question, but the show case I'm trying to understand here is this gwtphonegap-showcase-gwt example.
How do I pass a parameter to a view from another one?
For example, let's say I want that when a user clicks on any cell on the OverviewActivity, it will take them to the same place everytime (AboutPlace), but the text should be different (let's say it contains the cell number).
I added a setText(String text) to the AboutDisplay interface with the corresponding label and setText() in the AboutDisplayGwtImpl, but I have no idea where to call it. I tried calling it in AboutActivity start() method and ClientFactoryGwtImpl getAboutDisplay() method, but they seem to be called only once when the app first loads, so I end up with the same text each time.
you should not use a view directly for that.
You can add a field on a place and set your value there and access the same value in the next activity.