ARToolKit marker detect java Method - java

I am using ARToolKit nftSimple example and trying to java method when marker is detected but code is not working.

You could do it in a much easier way without touching the NDK.
The ARToolkit class has methods for querying the visibility of the markers, they are usually invoked on the Renderer, but you could as well create a thread that keeps checking them.
This is the code you need to check for marker visibility in Java:
boolean markerVisible = ARToolKit.getInstance().queryMarkerVisible(mMarkerId);

I just extended the sample arSimpleProj (the Android Studio project).
In the class org.artoolkit.ar.samples.ARSimple.SimpleRenderer
after line 104 add the following:
Intent newActivity = new Intent(activity,PlainActivity.class);
activity.startActivity(newActivity);
You need to have a Activity named PlainActivity with a corresponding layout.

Related

How would I load a new page in JavaFX WebView by an event from another method?

Basically, I am trying to call the equivalent of the line:
myWebView.getEngine().load("http://google.com");
I want to call this line by an interaction from a listener that is networked to touch controls on my phone. My listener can call methods easily. My only problem is that modifying the WebView at all from other methods is proving difficult. The WebView can't be modified from any other method but the one it was instantiated in, it also doesn't work to make it a public WebView. I'm getting errors with every workaround I've tried, including a PageHandler class. All I want to do is call that line of code whenever my listener (in another method) is called.
I'm sure there is a very simple solution to this that I'm missing, and I welcome you guys's help.
Thanks ahead of time!

Execute method using onclick or ID?

Keeping things short and simple, which is better for managing android click events when working with buttons?
Assigning it to an ID in the XML Construct lines?
android:id="#+id/ButtonEventName"
and working with it by detecting press event via Java?
Taken from the login activity template based in android studio:
Button mEmailSignInButton = (Button) findViewById(R.id.email_sign_in_button);
mEmailSignInButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
attemptLogin();
}
});
or assigning the button to an onclick method:
android:onClick="EventName"
the integrate Java side:
public void EventName(){}
Which is more effective and reliable and recommended when working with button events?
Both methods have their good and bad sides. I don't know which one is more effective though.
Using id + onClickListener is more complex code, but it gives you opportunity to do run-time check for errors. In your example that would mean additional null check.
Second approach is much simpler to read, but if you don't have EventName method app will crash
I prefer second one because it is simpler, and it is always easier to follow logic and find errors in less code.
I also have to add that while first solution does provide means of avoiding app crash, at the end that does not matter too much because if findViewById returns null you basically have same buggy, code that is in mismatch with layout xml and adding null check (that should be superfluous in final working app) just additionally pollutes the code.
Point 1 -
Creating it in code allow you to shield method access by making the method private, whereas doing it the xml way leads to exposure of the method.
Point 2 - android:onClick is for API level 4 onwards, so if you're targeting < 1.6, then you can't use it.
Otherwise as per my understanding, these 2 are similar.
It is really up to you, but keep in mind that android:onClick="EventName" will not work if you define it in an xml that will be inflated as part of a Fragment and you try to receive the button press on the Fragment itself. The onClick property only searches Activities for the method name you specified.
I would recommend you look into ButterKnife

When is Activity.onBackPressed called in Android? (in relation to other callback functions)

When is Activity.onBackPressed called in my Android application? I'm not looking for the obvious answer of when the user presses the back button. I wan't the answer in relation to other "callback" functions.
Is is possible to be called during the execution of another function within the Activity class?
What is the case if I have my Activity class implement some typical interfaces used for your typical game? For example GLSurfaceView.Rendered? I'm having the feeling onBackPressed is called during GlSurfaceView.Renderer.onDrawFrame but I'm not 100 % sure yet. Even if this isn't the case, I want to know how it works. (It seems difficult to find this kind of simple information anywhere.)
Finally, below is a code example for the layout of my Activity class. The question is, however, not limited to this particular setup.
class MainActivity extends Activity implements Renderer {
onCreate(...) {
layout = new FrameLayout(this);
GLSurfaceHolder glsurface = new GLSurfaceHolder(this, this);
glsurface.setRenderer(this);
layout.addView(glsurface);
setContentView(layout);
GLSurfaceHolder is just a simple dummy class that extends GLSurfaceView. It has the onTouchEvent overloaded and simple passes the data over to the MainActivity class. (The design philosophy in this very, very simple app is just to focus all the sensory and other data to one place and then "make things happen"..)
onbackpressed will be called when you pressed back button. Default behaviour will be destroying the activity. To avoid override the onbackkeypressed or onkeypressed.

How to change app theme from ordinary "Blank Activity" to "Master/Detail Flow"

I have an application that works on the basic theme "Blank Activity" and what i would like to do is to change it to a "Master/Detail Flow" theme. I do know that this will make my application work on android SDK 11 + (android 3.0 Honeycomb +), that is OK with me. The issue is i don't know where to start from, what are the basic steps to make this BIG conversion? I couldn't find any example to help me out with this issue. What should i be looking for. i am sure this has been done, can you at least please give me some pointer on how to do this?
my Application is not that complicated it uses activities, async tasks, DB, custom lists,... it is very basic. I use the custom list to display data and when i click on it it displays much more details, so I thought what better way to do this in a more professorial matter than the "Master/Detail Flow". If you have any tutorial regarding the "Master/Detail Flow" that you can hook me up with that might help.
I have an application that works on the basic theme "Blank Activity"
and what i would like to do is to change it to a Master/Detail Flow"
theme.
I think a change of the application flow would be more appropriate then a change of theme. Two obvious questions that would appear are why do you suddenly want to make this change and are sure your app makes sense in a master/detail flow? The answer would most likely be positive but you should answer them nonetheless.
I do know that this will make my application work on android SDK 11 +
(android 3.0 Honeycomb +), that is OK with me
I don't see why you're app couldn't run on versions below with the new master/detail stuff.
The issue is i don't know where to start from, what are the basic
steps to make this BIG conversion? I couldn't find any example to help
me out with this issue. What should i be looking for. i am sure this
has been done, can you at least please give me some pointer on how to
do this?
You haven't provided details about how is your app implemented. The change would revolve around fragments so a BIG question would be if the current single pane version is built using the fragments framework.
If your app is built using fragments then making the change shouldn't be too hard. You'd need to:
establish which parts(fragments) should be combined in an activity(from your old ones) to make the master/detail(when the space would allow it)
change the multi pane activity to accommodate the new fragment(s). This should be easy to do but it would depend on the size of the features exposed by each of those fragments.
modify the rest of the activities(for when the app will not run in the multi pane mode), this would be small changes as the activities would mainly remain as the current version
If your app isn't built using fragments, then what I said above still applies but you'd need to also actually make the required fragments wrapping whatever functionality your app has. This would most likely result in a big code refactoring.
Here is a tutorial about the Master/Detail template in Android - An Android Master/Detail Flow Tutorial.
As far as I understand your application is up and running - so I'm not sure whether it is worth it to try rewriting it, unless you are experiencing some problems of course. :)
In general the master/details flow requires the following steps:
Implement a ListFragment showing basic information of your items
Implement a Fragment showing detailed information about a particular item
Make an xml layout file for large devices (located in layout-sw600dp folder for example). In this layout you have to put both your fragments.
Write a general version of this layout file (i.e. file with the same name but located in the layout folder), which contains only the ListFragment.
Let your activity handle onItemClick event from the ListFragment. Each time an item is clicked, you have to check if the activity is showing both fragments or only the ListFragment. If both are visible, you have to notify the details fragment that new item is selected so it can show its data. Otherwise you have to create new details fragment (you reuse it of course), pass it some information about the selected item (so it can show the item's data) and replace the ListFragment with the new one.
That a basic overview, but it should be enough to give you some idea about this flow. If you need any more details - just let me know. :)
Master/detail flow and blank activity is not same as you want to change by only changing app theme or app base theme. It will be better, if you first design master/detail flow template using UI fragments, then according integrate you blank activity with the master template making necessary changes. And for master/detail flow tutorial just google it, you will find lots of example there.
Here are some links from developer.android.com fragment-ui and adaptui
These are some guidelines about fragments but they are told using a master/Detail app.
Also dont forget to checkout the news reader app provided as sample in the second link.
If you have a recent version of the Android SDK, you should be able to create a new Android application and during that process you can elect to have the wizard create a Master/Detail Flow app for you. It will create a basic working app so that you can look through the code and understand the necessary parts.
Then, depending on how simple your app is, you may want to move all your present code to the new application or vise versa.
Macro changes that will happen:
Change all your current Activities to extend Fragment instead.
You will have to create a FragmentActivity to call your Fragments. This will basically be the boilerplate code, with just the names of your Fragments added to it.
Don't forget to double check your Manifest!
In your converted Fragments that previously extended Activity:
Everywhere you needed a Context, switch that with getActivty() (or create a global variable so that it is only called once)
Change onCreate() to
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mView = inflater.inflate(R.layout.fragment_signals, container, false);
setHasOptionsMenu(true); // Add if you want to display a Menu
// Your initiation code here
return mView;
}
If you have a menu, change it to
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.activity_main, menu);
super.onCreateOptionsMenu(menu, inflater);
}
And that's it for basic applications. When you first change Activities to Fragments, there will be many errors. But, they are all easy to fix.

android default xml layout not loading

I'm trying to make a ListActivity with check boxes using one of the built in android layouts, android.R.layout.simple_list_item_multiple_choice. For background, I'm fetching the list in a private AsyncTask, then calling the adapter like this:
listActivity.setListAdapter(new ArrayAdapter<String>(listActivity,
android.R.layout.simple_list_item_multiple_choice, mDisplayList));
However when I run my code, the ListView is displayed with list_item.xml, which I'm using for all the other ListViews in my project. Any idea why this is happening?
The reason the right xml layout wasn't being used was because my AsyncTask was extending my (other) custom AsyncTask that used another xml layout and I left in this line.
super.onPostExecute();
which was at the end of the method so the inherited layout trumped the one I wanted.
When you use the android R in this way: android.R.layout... than you already have the package android before the class name R.
If you explicitly provide a class name with a complete package name, you don't need to import it, too.
That's for the case that you have the same class name from different packages which happens often when you use the android.R and your generated R class.
You don't need to import android.R.layout since you invoke it explicitely using android.R.layout.simple_list_item_multiple_choice.
That post may be of use.
Update from comment
It's hard to figure out what's the problem. Did you try to clean your project and rebuild? Sometime android int id's just do strange things if you don't clean the project and regenerate the gen files. But messing android internal references is highly unlikely… If it doesn't work, you may have another polluting setListAdapter somewhere else but it's hard to say without your full project.

Categories