DelayedConfirmationView doesn`t while changing layouts - wear-os

I am pretty new to programming and trying to build my first own app for my Android Wear.
Basically I want to see a new layout when pressing one of two buttons. On the new layout should be a DelayedConfirmationView with the possibility to cancel and to go back to the previous layout (kind of using "ok google" "Set timer to 5 seconds")
For this I created two layouts and coded in the manifest:
public void onClickcallSpringer(View view) {
setContentView(R.layout.callspringer);
DelayedConfirmationView DelayConfirmationView = (DelayedConfirmationView) findViewById(R.id.delayed_confirmation);
DelayConfirmationView.setTotalTimeMs(2000);
DelayConfirmationView.setListener((DelayedConfirmationView.DelayedConfirmationListener) this);
DelayConfirmationView.start();
}
This leads to an crash, when pressing the button in my app.
I tried to understand the function DelayedConfirmationView from another App, but there it also leads to a crash (https://github.com/livefront/android-wear-demo).
I hope somebody can help me with this (and maybe explain to me how to solve this with a new activity as well).

Found my mistake: I had to make a new activity.
I am using now a .setOnClickListener to start a new Activity
button_callspringer.setOnClickListener((v) -> {
startActivity(new Intent(MainActivity.this, callspringer.class));})
and in the new class I coded on the onCreate-Methode:
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.callspringer);
DelayedConfirmationView delayedconfirmationview_experte = (DelayedConfirmationView) findViewById(R.id.delayed_confirmation_springer_view);
delayedconfirmationview_experte.setTotalTimeMs(5000);
delayedconfirmationview_experte.setListener(this);
delayedconfirmationview_experte.start();}
This leads to the wished result. Maybe this will help someone one day too.

Related

Wearable DataAPI syncing issue with multiple watches (Looping)

I have a watchface with a companion app for phone. It uses Wearable.DataApi to sync changes between the phone and watch. I have a DataApi.DataListener setup and sync changes made on the watch or phone side. I have no issue with a phone and ONE watch communicating.
The issue is when i have multiple watches using the same watch face if changes on watch or phone side are made quickly it seems to go into a loop and start flashing the changes on all devices. So if im changing the color by tapping watch if I press a few times quickly to do that all devices start cycling through all colors and takes some time before it catches up and stops.
If I change options slowly there is no problem. I put a log in the DataApi listener and I see both uri's making the change but just seems to loop for some reason when changed quickly. Is there anyway to prevent this?
I know this might not seem like a big issue but if a user has 2 watches and accidently changes an option or options quickly it will start with the options and or colors changing. I want to prevent that from happening.
This is how im adding my listener in the onConnected method
Wearable.DataApi.addListener(mGoogleApiClient, dataListener);
And this is my listener method
DataApi.DataListener dataListener = new DataApi.DataListener() {
#Override
public void onDataChanged(DataEventBuffer dataEvents) {
Log.d(TAG, "onDataChanged");
for (DataEvent event : dataEvents) {
Log.d(TAG, "dataEvent.uri: " + event.getDataItem().getUri().toString());
DataMap item = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
/////other code to set data/////
}
updateCanvas();
}
};
You should be able to avoid this by filtering out dataEvents that originated from the local node (i.e., the device that the code is running on).
Get the local node ID with code like this:
NodeApi.GetLocalNodeResult nodeResult = Wearable.NodeApi.getLocalNode(googleApiClient).await();
String localNodeID = getLocalNodeResult.getNode().getId();
Then, put code like this inside your for loop to do the filtering:
Uri uri = item.getUri();
String nodeID = uri.getHost();
if (nodeID.equals(localNodeID)) {
// Skip changes originating on this device
continue;
}

deal with Unity 5 UI in augmented reality app

I'm trying to make an augmented reality application with vuforia and unity.
whenever it recognize the image target, it must tell a story by showing text , and it should enable the user to press next and back to go on reading the different parts of this story, I'm totally new to unity and don't know how to handle with UI throughout scripting, I need some help on how to accomplish the part of "going forward and backward on showing the story by hitting Next and Back buttons", and all these parts of story should be related to the same image target in the same scene.
I appreciate it if you help me with an example code.
You should create some script that attach on trackable object, maybe something like this.
public class DataBook {
string[] dataBook;
string idText;
bool isActive;
}
Then you must create another script to set that trackable object is active or not, this link can help you to get that.
https://developer.vuforia.com/forum/faq/unity-how-do-i-get-list-active-trackables
Then after you get the active trackable object, you can set the dialog from the book by create another controller script for button, example
public void Next() {
DataBook[] books = FindObjectsOfType<DataBook>(); // if the object more than one, it will be more easy if it only the one
foreach (var book in books)
{
if (book.isActive) {
book.idText += 1;
textUI.text = book.dataBook[idText]; //textUI assign to object text on canvas
}
}
}
you can learn about unity UI Button on this :
https://unity3d.com/learn/tutorials/modules/beginner/ui/ui-button
Good luck

Cocoa context menu causing crash when timer on main thread

I am working in mono on OSX10.6 - but this question is for Cocoa experts also please.
I have a context menu which I attach to an NSTableView. When I select the context menu the handler (which is empty for test) is called ok but then the application crashes.
This is the code I have in the window controller:
...
myNSTableView.Menu = new NSMenu();
NSMenuItem mi = new NSMenuItem("menu item 1", myHandler);
myNSTableView.Menu.AddItem(mi);
...
public void myHandler(object Sender, EventArgs e)
{
}
I also have an NSTimer setup to repeat every 200ms
myNSTimer = NSTimer.CreateRepeatingScheduledTimer(new TimeSpan(2000000),delegate {
move an NSSlider
});
NSRunLoop.Main.AddTimer(myNSTimer, NSRunLoopMode.Common);
NSRunLoop.Main.AddTimer(myNSTimer, NSRunLoopMode.EventTracking);
As soon as I try to access the context menu, the application crashes - every time.
If I dont start the timer, the context menu is fine.
I have tried literally everything to get this to work and have run out of ideas, so I really need someones help please, even just a pointer to where the problem might be. Forgetting about the fact that its mono just now, can anyone see from a cocoa point of view a problem?
It turned out that the problem was exacerbated by the timer, but the cause was actually that I wasn't declaring instance variables for the NSMenuItems, so they were getting garbage collected and causing crash at objc level.

Mono navigation

I just started out with mono and I've already gotten problems. I'm used to play with c# code and was told that mono would be easy for me, but no no. I simply want to start a new activity and close the one i just were using. I checked out some mono API examples, but they are simply too complicated for this task. It has to be some easier way of doing it. This is my first activity class:
[Activity(Label = "CryptotoDroid", MainLauncher = true, Icon = "#drawable/icon")]
public class Activity1 : Activity
{
EditText inputpassword;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
Button button = FindViewById<Button>(Resource.Id.MyButton);
inputpassword = FindViewById<EditText>(Resource.Id.beforetext);
button.Click += delegate
{
if (inputpassword.Text == "Moo")
{
StartActivity(typeof(ActivityContacts));
}
};
}
}
This is what i tried, but the program crashes. I Simply want to make the program to start a new activity when the password is "moo".
The activity I want to start is:
[Activity(Label = "My Activity")]
public class ActivityContacts : Activity
{
protected override void OnCreate(Bundle bundle)
{
SetContentView(Resource.Layout.Main);
var contactgrid = FindViewById<GridView>(Resource.Id.gridview);
}
}
Later on, i would also like to fill out my gridview with all contacts in the phone, but that belongs to another topic.
Did you mean to set both activities' content views to the Main layout?
SetContentView(Resource.Layout.Main);
public void setContentView (View view)
Set the activity content to an explicit view. This view is placed directly into the activity's view hierarchy. It can itself be a complex view hierarchy. When calling this method, the layout parameters of the specified view are ignored. Both the width and the height of the view are set by default to MATCH_PARENT. To use your own layout parameters, invoke setContentView(android.view.View, android.view.ViewGroup.LayoutParams) instead.
For starting with MonoDroid, I recommend:
getting hold of one of the excellent books out there (Wally, Greg, Chris or others will be along with suggestions - I've personally yet to see a bad one so won't give a recommendation!)
try watching a couple of the Xaminar's on youTube -http://www.yourepeat.com/g/Xaminar
try building the Xamarin sample programs and then try adapting them - it's sometimes easier to adjust working programs than it is to start new ones (sometimes!)
try building new things just as you have above.
When you hit problems - as we all do - then please do ask questions here or on the Xamarin forums - people will help.
However, when you hit a crash or exception, please try:
Give us as much info as you can about the crash/exception - including there are some ways to get extra debug logs off of a phone or emulator - http://docs.xamarin.com/Android/Guides/Deployment,_Testing,_and_Metrics/Android_Debug_Log - these logs often contain important text which will help us help you diagnose the crash
If you are running under the VS2010, VS2012 or MonoDevelop debugging tools, try adding extra Console.WriteLine statements and/or use breakpoints - this can help you and us work out which line is causing the crash - or if the crash is occurring somewhere in setup before the code even runs.
Speaking personally, I believe Mono for Android does help experience C# devs exploit their skills on Android - but there's still new things to learn, and there are still embedded development frustrations to tackle and overcome (like these sort of crashes)

Converting from 3.1 to 4.0... gamestates

I'm restarting development of a game I was working on, and have successfully converted it over to XNA 4.0 using the cheat sheet. Most of it works, some of it doesn't, and I'm in the process of fixing what doesn't work.
One thing that I had was a state system that was heavily based on the state system used as an example of XNA Unleashed, the ebook. I didn't have much in it.... basically just the ability to pause the game.
When I paused the game, the action of the game would stop, and the word "PAUSED" would appear in block letters across the screen, and you'd see the paused action. However, now it seems that the sprite batch automatically clears out everything between frames, so when I pause the game now, the screen clears, leaving PAUSED over a purple background. Back then, I believe that adding "SaveStateMode.SaveState" would prevent that from happening, but that functionality was removed. When I did some research, I found out that it was removed because it was essentially useless, that's all handled in the game state manager.
However, I can't find any documentation on this. Where should I start? Right now, my code looks like this:
In the Playing Game State update method:
if (input.WasPressed(0, Buttons.Start, Keys.Enter))
{
GameManager.PushState((GameState)ThisGame.PausedGameState.Value);
}
public void PushState(GameState newState)
{
AddState(newState);
//Let everyone know we just changed states
if (OnStateChange != null)
{
OnStateChange(this, null);
}
}
private void AddState(GameState state)
{
states.Push(state);
Game.Components.Add(state);
//Register the event for this state
OnStateChange += state.StateChanged;
}
//PausedGameState Draw method:
public override void Draw(GameTime gameTime)
{
ThisGame.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, null, null, null);
DrawPaused(); //draws the Paused Text
ThisGame.SpriteBatch.End();
}
The goal is to make "PAUSED" appear over the screen, with a snapshot of where the gameplay left off... and not "PAUSED" over a cleared purple screen.
Do you suppose that GraphicsDevice.Clear() somehow got called after the state changed to paused? What does the DrawPaused() method do in your code?

Resources