Is there a way to stop Glass from taking picture while listening to wink command?
Whenever I detect Wink from my code, it automatically takes a picture which I don't want.
Edit:
The library is a stub. Whenever the onDetected function is called, I get a log message then Glass takes picture. Is there a way to stop the Internal glass function from running? I tried adding return at the end of onDetected but that didn't work.... Maybe a function to abort to exit the function?
The code is below.
#Override
public void onDetected(final EyeGesture eyeGesture) {
runOnUiThread(new Runnable() {
#Override
public void run() {
mAudioManager.playSoundEffect(Sounds.SUCCESS);
Log.e(TAG, eyeGesture + " is detected");
if(eyeGesture==target1.WINK){
mTextView.setText("Detected " + eyeGesture + "!");
}
}
});
}
In the old days (XE16 and before), winks sent out a broadcast. If you simply created a high priority broadcast receiver, you could abort the broadcast (and the wink-picture-receiver would never see the broadcast).
I put togethher some old code to demonstrate this here: https://gist.github.com/victorkp/0f98cd5c096de53f4518
Try this code:
https://github.com/prt2121/EyeGestureLib
Revision for XE19.
Related
I will try to be brief.
For a school project I need a UI with a command prompt (textbox) and a log window (richtextbox).
When we type a command,System::Void MyForm::cmd_textBox_KeyDown(System::Object^ sender, KeyEventArgs^ e) called another function (in another .cpp) to process it and the function is displayed in my richtextbox.
Some functions send usb frames and receive responses via the interrupt function :
System::Void MyForm::serialPort1_DataReceived(System::Object^ sender, System::IO::Ports::SerialDataReceivedEventArgs^ e)
My concern is the following:
should my command be launched in another thread than the one managed by the UI?
when we receive a USB frame and I want to do an AppendText in my richtextbox, the Appentext is sometimes done with a lot of delays (sometimes after other commands).
Currently I update my log via this function, but it still has a delay.
If I replace BeginInvoke with Invoke the UI freezes.
void MyForm::Update_log_TextBox(String^ text, Color text_color)
{
Update_log_TextBox_Delegate^ action = gcnew Update_log_TextBox_Delegate(this, &MyForm::Worker);
this->BeginInvoke(action, text, text_color);
}
void MyForm::Worker(String^ text, Color text_color)
{
MyForm::log_TextBox->SelectionColor = text_color;
MyForm::log_TextBox->AppendText(text);
}
Do you have any solutions for me please?
Sorry for my broken English it is not my native language
Application::DoEvents();
solve my problem.
Force the UI to applicate change.
In my application (Vaadin.8.6.3, Tomcat 9 and Maven 3) I need to set cookies which works well unless I use #Push. I need #Push only for one progress window implemented as described here.
I read that it is possible to turn #Push on and off using e.g.
getUI().getPushConfiguration().setPushMode(PushMode.AUTOMATIC);
I tried several ways and places in the code to turn #Push on and off, but nothing worked.
One example:
#Push(PushMode.DISABLED)
public class MyUI extends UI {
Since I have more than one place in the code where I do cookies handling, I thought the best is to disable #Push in the UI class and turn it on when I run the background thread.
With a button click I start the runnable and in the runnable I turn on the #Push mode:
class Loader implements Runnable {
#Override
public void run() {
try {
getUI().access(() -> {
getUI().getPushConfiguration().setPushMode(PushMode.AUTOMATIC);
getUI().getNavigator().navigateTo("scandataview/" + name);
});
} catch (Exception e) {
e.printStackTrace();
}
}
}
I have no error but nothing happens, i.e. the data I want to load are never loaded and the progress window stays forever.
My questions:
Is it possible to just turn on #Push to show the progress window while loading long data and turn it off after loading?
If yes, where in the code should I turn on/off the #Push?
If you need more information please let me know. I would be very glad for your help. Thank you!
If you need Push only in one place and for some reason have described complications I recommend the following.
Set the push mode to manual i.e. #Push(PushMode.MANUAL)
And then modify the code as follows, i.e. perform manual push instead of relying automatic.
class Loader implements Runnable {
#Override
public void run() {
try {
getUI().access(() -> {
getUI().getNavigator().navigateTo("scandataview/" + name);
getUI().push();
});
} catch (Exception e) {
e.printStackTrace();
}
}
}
The above use of access() can be further improved according information provided in this question: Access method from current UI in Vaadin
For testing software with Google Espresso test-framework I have following issue:
At start of the program, a splash screen starts and initialises the entire application. After this, I start an Activity which asks for input.
In Espresso, the application starts and the test starts with following code:
onView(withId(R.id.chooseBookTitle)).perform(click());
This crashes, because the display still shows the splash screen and the chooseBookTitle is only visible afterwards. How to prevent that Google-Espresso will click the key before it is there?
(I don't want to insert wait loops, but keep it event driven. In worse case, I go back to Robotium)
Please check the IdlingResource interface:
As mentioned by Stefano Dacchille (see sample below) you must create an idling ressource implementation that waits to become idle:
public class WaitForSomethingResource implements IdlingResource {
ResourceCallback mResourceCallback;
private boolean isIdle;
#Override
public String getName() {
return WaitForSomethingResource.class.getName();
}
#Override
public void registerIdleTransitionCallback(
ResourceCallback resourceCallback) {
mResourceCallback = resourceCallback;
}
#Override
public boolean isIdleNow() {
return isIdle;
}
/**
* Register an listener, use an event bus or something
* else to get notified about any change you want to track.
*/
public void onProgressChanged() {
isIdle = true;
if (isIdle && mResourceCallback != null) {
mResourceCallback.onTransitionToIdle();
}
}
}
After that, you have to register the IdlingResource implementation within the tests setUp() or #before method by writing:
Espresso.registerIdlingResource(waitForSomethingResource)
Sample:
http://dev.jimdo.com/2014/05/09/wait-for-it-a-deep-dive-into-espresso-s-idling-resources/
API Doc:
http://developer.android.com/reference/android/support/test/espresso/IdlingResource.html#isIdleNow()
From what I see, you should open directly the activity that contains R.id.chooseBookTitle, otherwise your view will never be on the screen so your test will always fail because Espresso can't find the specified view.
Otherwise, I use Thread.sleep(...) before I do some tests to make the tests wait. Try it before calling onView(withId(R.id.chooseBookTitle)).perform(click()); and see if it's working.
Good luck!
I have run into an interesting problem with WT, I have solved it, but I do not understand WHY my solution solved the problem. I've dug through WT documentation for the widgets and have come up empty handed so far, so maybe someone who knows more about WT can help me out here.
Anyway, the problem is with a WComboBox widget in a boost thread not updating it's data when clicked on and having it's selection changed.
I created a boost thread in a class
class MyConsole: public WApplication
{
private:
boost::shared_ptr<boost::thread> _thread;
WComboBox* _combo_box;
bool running;
//Thread function
void my_thread(Wt::WApplication *app);
}
Then I fill the combo box with data, lets use "foo" and "goya" as the 2 entries. I made a function for the thread, and put a loop into it.
void MyConsole::my_thread(Wt::WApplication *app)
{
while(running)
{
std::string test;
Wt::WApplication::UpdateLock lock(app);
if(lock)
{
test = _combo_box->valueText().narrow();
}
if (strcmp("foo", test.c_str()) == 0)
{
cout << "we got foo" << endl;
}
else if (strcmp("goya", test.c_str()) == 0)
{
cout << "we got goya" << endl;
}
}
}
Without changing the initial selection of the combo box, the above code always enters the foo if statement, which is expected. However, when I change the selection of the _combo_box to "goya" the above code still enters the "foo" if statement, which is very unexpected. Investigating the matter further such as printing out the current index of the combo box before the if statement showed me that it is always 0 and never gets incremented when the selection changes.
The way I fixed it was by connecting the combo box changed() signal to a do nothing function that I added to the class.
class MyConsole: public WApplication
{
private:
...
void WWidgetForceUpdate(void)
{
}
...
}
...
_combo_box->changed().connect(this, &MyConsole::WWidgetForceUpdate);
With the addition of that function call when the selection changes, the "foo" and "goya" if statements worked properly, and printing out the current index of the combo box before the if statement confirmed that the index was now changing.
Why did connecting the changed() signal to a do nothing function remedy the situation? I am sure there is a bigger problem that I am not seeing here :(
Any help would be much appreciated.
Wt sends changes from the browser to the server when events happen. If your program is not interested in an event, this synchronisation will not take place (otherwise synchronisation would take place on every character of text you enter in an input box, on every mose movement, .... even if your application is not doing anything with it). Nothing connected to changed() means that nothing is interested in that specific event, and the browser will not notify the server when it happens.
Any event that is being listened upon will send all changes of all widgets to the server, so that the full widget tree is synchronised. So if you have a button with clicked() listener, and a combobox without a changed() listener, the state of the combobox will still be updated in the widget tree when you click the button.
There is however a bug in your code: you cannot just access the widget tree from a random thread without grabbing the update lock (WApplication::UpdateLock).
I have a version hit check right after my application gets start.
But when simulator is loading its sending the request and all that stuff. After my application starts it give version hit value NULL but after I close the application and open it again it gives the correct value.
1) My Question is that Why is this behavior occurring and what should I do that app starts and version check gives correct value at first attempt!
2) And the app is even not executed by user why its line of codes are executed?????
public MyScreen() {
Bitmap bitmap = Bitmap.getBitmapResource("background.png");
this.getMainManager().setBackground(
BackgroundFactory.createBitmapBackground(bitmap));
synchronized (Application.getEventLock())
{
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
Status.show("Please Wait...", Bitmap.getPredefinedBitmap(Bitmap.INFORMATION), 1000);
LoginScreen();
}
});
}
Now what does it do is that it shows only the background screen and nothing happens no service but when I start it again it works. Whats the problem? Thanks
If your MyScreen class is actually a kind of Screen (through inheritance), then there's no need for you to synchronize on the event lock in this case. The constructor for a Screen will already be called on the UI thread, so, just simplify your code to:
public MyScreen() {
Bitmap bitmap = Bitmap.getBitmapResource("background.png");
this.getMainManager().setBackground(
BackgroundFactory.createBitmapBackground(bitmap));
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
Status.show("Please Wait...", Bitmap.getPredefinedBitmap(Bitmap.INFORMATION), 1000);
LoginScreen();
}
});
Also, you might be able to get rid of the invokeLater() call, too, leaving you with this:
public MyScreen() {
Bitmap bitmap = Bitmap.getBitmapResource("background.png");
this.getMainManager().setBackground(
BackgroundFactory.createBitmapBackground(bitmap));
Status.show("Please Wait...", Bitmap.getPredefinedBitmap(Bitmap.INFORMATION), 1000);
LoginScreen();
You would normally use invokeLater() if you just wanted to safely initiate the code inside its run() method from a background thread, or if you wanted to queue it to be run after the constructor finishes.
But, if you're ready for it to happen right away, and you were just using that call to ensure that
Status.show("Please Wait...", Bitmap.getPredefinedBitmap(Bitmap.INFORMATION), 1000);
LoginScreen();
was run on the UI thread, then there's no need for that, because as I said, you're already on the UI thread in the MyScreen constructor.
But, I also can't see what you do at the end of your MyScreen constructor, so it's possible that using invokeLater() is appropriate.
Post some more information in response to my comment above, and I'll try to help with more.