CGRectIntersectsRect for cocos2d Android - java

I'm currently trying to test for collisions between two CGRects. Usually in Objective C I'd use the CGRectIntersectsRect method, but in Coso2d Android the only method available seems to be CGRect.containsRect which doesn't work as desired. Is there another way this must be done for Android?

I found intersects method in CGRect at github repo use that function to check intersect of two rect.
I also found one issue logged with the same and there is also a solution mention.

Downloaded an updated version of the .jar file which contains a CGRect.intersects method

Related

How to find where a LiveData is observed

I am studying a project with LiveDatas on Android Studio (Java). I would like to know if it exists an Android Studio option to see where a particular LiveData is observed in the project, to see all the objects that are been notified and in which method.
you can access by typing .observe into Find in Path(cmd + shift + f in Mac):
sample live data observing:
viewModel.liveData.observe(this, Observer {})
You can't do that. Android studio can't give you such "runtime" information. The best you can do, is to call LiveData's hasActiveObservers() returns true if there are active observers, or hasObservers() returns true if there are any observer.
It seems that the best solution, to me, is to find usages of the particular
LiveData's getter method of viewModel, then see when the LiveData is observed after get.

How to get method name in Android?

I've been using this instruction to get the name of a method which is currently being used.
currentThread().getStackTrace()[1].getMethodName()
It works fine when I developed Spring Framework or other simple programmings.
However, It seems it works differently in Android Studio. I get time instead of the name of a method.
The reason why I try to use this instruction is for debugging. I used to use
Log.d(TAG, "Method()");
However, The problem when I use this... I should type its method name each. So, To implement this instruction in all the different methods with the same instruction. I found out using currentTrace(). But when I use this on Android Studio. I just get 'geStackTrace' instead of the current method name.
Is there any way to implement it correctly or better way for debugging?
Try this
StackTraceElement[] stacktraceObj = Thread.currentThread().getStackTrace();
stacktraceObj[1].getMethodName();
For further reference, checkout the links
https://www.badprog.com/android-api-getting-the-current-method-name-with-stacktraceelement
https://developer.android.com/reference/java/lang/Throwable.html#getStackTrace()
If typing it out every-time is the issue use the default live templates for log statements.
Use cmd+j(ctrl + j in windows) and look for logd, logi, logw or loge.
By default it prints the method and a colon. You can customize it in preferences.
There's logt for creating a TAG too.

Is there a way to get the IJavaElementDelta object from IResourceDelta?

I'm working on an Eclipse plugin that enables traceability. I am implementing a notification system that tells the user whenever a traced item changes (is removed, renamed or edited) and for that purpose I implemented an IResourceChangeListener, but that doesn't give me all the support that I want for Java elements.
For example, when I rename a Java method inside a .java file, it only tells me which file has been edited, but I would like to have the info about the method as well. I know that this can be achieved with implementing the IElementChangedListener, but is there any way around it? Do I really have to implement two listeners (ResourceListener for other files and ElementChangedListener just for java elements) or can I somehow get the IJavaElementDelta (normally obtained from the ElementChangedListener) from the IResourceDelta? Thanks!
These two deltas are completely unrelated. You need to use both listeners.
Try to check this link example 5. There is some method with this description:
Converts an IResourceDelta and its children into
the corresponding IJavaElementDeltas.
Return whether the delta corresponds to a resource on the classpath.
If it is not a resource on the classpath, it will be added as a non-java
resource by the sender of this method.
So I suppose it could be possible.
The links leads here which should you check ass well. Method public void processJavaDelta(IJavaElementDelta delta)

GraphViz - org.graphstream.graph.IdAlreadyInUseException

I use GraphViz to draw oriented graph - I read file with graph data according to http://graphstream-project.org/doc/Tutorials/Reading-files-using-FileSource/ tutorial.
Everything works fine when there is not two or more edges between two nodes. If so, the org.graphstream.graph.IdAlreadyInUseException: singleton exception: id "(48;63)" already in use. Cannot create an edge. is thrown.
I understand the exeption quite well. The problem is that I don't know how to get rid of it (and I don't want to write my own data parser).
Does anyone know how to solve this?
I don't know about graphviz, but the error you get and the tutorial you refer to are GraphStream related.
In GraphStream, you need to use the MultiGraph class in place of the DefaultGraph one.

How to compare two identical methods in eclipse?

I'm doing android app from a book, for some reason the exact method source code I wrote myself does not work as expected and I am trying to debug it.
I have two exact chunks of code, my method and the sample method.
How to compare them in eclipse?
Select both files by clicking the first, then while holding CTRL click on the second.
Now both of them got selected.
Now click one of them (doesn't matter which one) with the right mouse button.
From the appearing context menu choose:
Compare
Each other
Now you can do a text compare.
Did I get right that neither of the sample method nor your method do what they should?
Then there are two possibilities why the code won't do what it should:
The book is obsolet
You made something wrong
either way, google for your specific problem, maybe someone else has encountered it as well and already solved it.
for your Question: already answered in another comment
use beyond compare, it's a great tool for comparing classes, and methods! download beyond compare

Categories