Greg [entries|archive|friends|userinfo]
Greg

[ website | gregstoll.com ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

Links
[Links:| * Homepage * Mobile apps (Windows Phone, Win8, Android, webOS) * Pictures * LJBackup * Same-sex marriage map * iTunesAnalysis * Where's lunch? ]

Windows Phone: properly managing BackStack entries with the NavigationHelper [May. 19th, 2015|09:11 pm]
Greg
[Tags|, ]
[Current Mood |okayokay]

TL;DR - if you're manually manipulating the BackStack and using NavigationHelper, see the bottom of this post to avoid a bug. Also, download FlySmarter!

I fixed an interesting bug in FlySmarter after a user complained that the first-run tutorial kept showing up after it had been run once. Here's some background:

On Windows Phone, the Frame class has a BackStack property, which is the history of the Frame. If the user presses the hardware Back button (or you call Frame.GoBack()), the Frame looks at the last entry in the BackStack to figure out what page to go to, and what arguments to pass it.

95% of the time, this what you want. However, sometimes you want to change what happens when the user presses Back. One example in FlySmarter is when you start at the main page (the FlightsList), then you tap to add a flight (AddFlight page), then you enter data and hit OK and the app finds the flight and goes to the flight information page for that flight. (FlightInfo page) Here, when the user presses Back I wanted to go back to the FlightsList page because the user is already done adding the flight. Of course, this is up to you as the developer to figure out what makes sense for your app.

Actually, to implement that I just call Frame.GoBack() to pop the stack after adding a flight to get back to FlightsList, then call Frame.Navigate() to go directly to the FlightsList page. Another, weirder, case, is with the first-run tutorial (see my universal app template for an example of a first-run tutorial). Here I want to start at the FlightsList page, then show some popups on the FlightInfo page, then show some more popups on the FlightsList page. There are several ways you could implement this - my way was to do something like this when we navigate to the FlightsList page:

    // if we've navigated to this page with a first-run tutorial ID
    if (Frame.CanGoBack &&
        Frame.BackStack[Frame.BackStackDepth - 1].SourcePageType
          == typeof(FlightInfo))
    {
        Frame.BackStack.RemoveAt(Frame.BackStackDepth - 1);
    }

--

So, what's the problem? When I started debugging through FlySmarter to try to find out why the first-run tutorial kept popping up, I noticed that when it happened, the PageState that was being passed to the FlightsList page was not what it should have been! After some debugging, I found the culprit in the NavigationHelper class. Here's a snippet of code from the class:

    public void OnNavigatedTo(NavigationEventArgs e)
    {
         var frameState = SuspensionManager.SessionStateForFrame(this.Frame);
         this._pageKey = "Page-" + this.Frame.BackStackDepth;
         // code omitted for brevity
         this.LoadState(this, new LoadStateEventArgs(e.Parameter,
           (Dictionary<String, Object>)frameState[this._pageKey]));
    }

This code is using the current BackStackDepth as part of the key for storing this page's data, which is a problem if we're manually manipulating the BackStack and changing its depth!

So, to fix it, I added the following method to the NavigationHelper class:

    /// <summary>
    /// Clients must call this to remove something from the BackStack, since
    /// this uses the BackStackDepth to generate page keys
    /// </summary>
    public void RemoveBackStackEntry(int indexToRemove)
    {
        var frameState = SuspensionManager.SessionStateForFrame(this.Frame);
        bool entryPresent = true;
        int index = indexToRemove + 1;
        while (entryPresent)
        {
            entryPresent = frameState.ContainsKey("Page-" + index);
            if (entryPresent)
            {
                frameState["Page-" + (index - 1)] = frameState["Page-" + index];
                frameState.Remove("Page-" + index);
            }
            index++;
        }
        Frame.BackStack.RemoveAt(indexToRemove);
        this._pageKey = this._pageKey = "Page-" + this.Frame.BackStackDepth;
    }

and then I call this method instead of BackStack.RemoveAt(). Problem solved!

--

See all my Windows Phone development posts. I also send out a monthly-or-so email with news for developers - check out the latest email and sign up here!

I'm planning on writing more posts about Windows Phone development - what would you like to hear about? Reply here, on twitter at @gregstoll, or by email at greg@gregstoll.com.
LinkLeave a comment

link saturday: excessive medical care, smart social programs, 2 minute walks [May. 16th, 2015|09:37 pm]
Greg
[Tags|]
[Current Mood |cheerfulcheerful]

- Atul Gawande has a great article about excessive medical care and what some places are doing to fight it. It's a long read, but worth it!

- So Seymour Hersh wrote a long article claiming the government lied about a lot of things regarding Osama bin Laden's death, including the fact that Pakistan gave him up to the US. There are a bunch of articles that point out a lot of flaws with the article, but the Columbia Journalism Review says we should take it more seriously. So...?

- Smart Social Programs - social programs do help improve social mobility. Let's have more of them!

- A 2-Minute Walk May Counter the Harms of Sitting - encouraging, I guess!

- The mathematically proven winning strategy for 14 of the most popular games (thanks Jessica!)

- ABC is making a new Muppet show - the trailer looks OK, but man the voices are wrong!

- The fact that people make wrong predictions (about Obamacare being a disaster, etc.) and then don't take responsibility for them makes me sad.

- Playing With My Son: An experiment in forced nostalgia and questionable parenting - pretty awesome!

- SpaceX made some awesome travel posters for Mars - I love art deco! (this is "art deco", right? Whatever this is, that's what I like)

- @_FloridaMan Beguiles With the Hapless and Harebrained - here's @_FloridaMan on Twitter, and here are the best @_FloridaMan tweets. There are some gems in there!

- Joining The Avengers Is As Deadly As Jumping Off A Four-Story Building
LinkLeave a comment

FlySmarter now available for Windows Phone! [May. 13th, 2015|05:13 pm]
Greg
[Tags|, , ]
[Current Mood |proud]

I'm happy to announce that FlySmarter is now available for Windows Phone! FlySmarter lets you
- easily add flights to Cortana
- stay up to date with live tiles and push notifications about your flight's status
- navigate through airports with offline terminal maps for more than 70 airports

Download it for Windows Phone now!

I've been working on FlySmarter for a while and thought it would be fun to pull some statistics from my Subversion repository:
- 154 commits, first one was June 8, 2014, last one was May 10, 2015. I committed code on 106 unique days, which means on average I committed code every 3.17 days in that span.
- The largest gap between commits was 49 days, which was July 16 to September 3
- lines of code:
- Shared project and PCL library: 497 lines of XAML, 12820 lines of C#
- Windows Phone project: 2067 lines of XAML, 4533 lines of C#
- Azure mobile services project: 1822 lines of C#

Which makes a total of 2564 lines of XAML and 19175 lines of C#. Which is a lot! And makes me wish I had written 725 more C# lines :-)
LinkLeave a comment

Windows Phone: //build/ conference for Windows/Windows Phone developers [May. 10th, 2015|11:59 am]
Greg
[Tags|]
[Current Mood |calmcalm]

I attended Microsoft's //build/ conference a few weeks ago, and there was a lot of interesting news for Windows/Windows Phone developers. Here's what you need to know!

Useful links:
- Microsoft's landing page for developing for Windows 10
- How to move a Universal 8.1 app to Windows 10
- Windows 10 app samples
- What's New in Windows 10
- Join the Windows Insider program to download a preview of Windows 10
- See video/slides for all the //build/ sessions

If you've developed for Windows/Windows Phone 8.1, you're familiar with the idea of Universal apps, where most of the code can be shared between the two platforms. Microsoft has doubled down on this idea, and in Windows 10 you'll be able to share basically all your code between these platforms and more (including XBox, Surface Hub, the Internet of Things, and HoloLens). Microsoft is calling this the Universal Windows Platform (UWP) or the Universal App Platform (UAP), but it's just an extension of the WinRT that we all know and love.

So how does this work? Well, one big difference between platforms is screen size - what makes sense on a phone doesn't make sense on a laptop or XBox. To handle this, there are new capabilities in UWP to allow you to layout your page views different depending on the size of the screen your app is running on - see Responsive design 101 for UWP apps. Actually, most of these capabilities were in Windows 8.1 apps (using VisualState's and the like) but Microsoft has cleaned them up and made them easier to use.

Another big difference between platforms is, well, platform-specific APIs. Most APIs are available on all platforms, Your laptop probably doesn't have a hardware camera button, for example. You can use the new ApiInformation class to query for the presence of particular types and such.

Microsoft seems really serious about this - they showed how apps running on the desktop look like phone apps if you resize their windows to be narrow enough, and using Continuum you can plug your phone into a monitor and resize the phone apps to look like desktop apps.

If you have existing apps on Android or iOS you'd like to port to Windows, Microsoft announced some new bridges to UWP - see Project Astoria for Android and Project Islandwood for iOS.

I also got to demo a HoloLens - see my thoughts afterwards.

--

Below are my raw notes from the sessions I went to.
raw notesCollapse )

--

See all my Windows Phone development posts. I also send out a monthly-or-so email with news for developers - check out the latest email and sign up here!

I'm planning on writing more posts about Windows Phone development - what would you like to hear about? Reply here, on twitter at @gregstoll, or by email at greg@gregstoll.com.
LinkLeave a comment

My experience with Microsoft HoloLens [May. 1st, 2015|12:20 am]
Greg
[Tags|, ]
[Current Mood |tiredtired]

I got to try a HoloLens today!

After the keynote yesterday at //build, I signed up online to try to get to demo it, and a few hours later I got an email saying I was on a waitlist. I sighed and couldn't conceive of a way that I would get off of that list (they didn't require you to confirm in advance or anything, so even if people didn't show up it would probably be too late to invite someone else), so I sighed and went on with my life.

Then I heard that there was a strict NDA around the whole thing and it was a short demo, so this morning I was consoling myself that it wouldn't be that great anyway. Literally minutes later I got an email saying I was in for a 12:30 slot! (what's the opposite of "sour grapes"?)

So I showed up early to a nearby hotel and we waited in line for a while. We were batched in groups of 8 and taken up to the 27th floor. I've never been to an event where a company rented out a whole floor of a hotel. (and probably more than one, now that I think about it) It was neat!

As the email said, we were lead into a locker room and told to put away any device that could record anything. (no NDA, though, which is why you're hearing about it!) Then we went next door where we got a quick intro to the device from some of the people who have been working on it. The main ways to interact with HoloLens are GGV - gaze means where your head is facing is where the "mouse" is, gestures is a simple move of your index finger up and down (like clicking a mouse) to select something, and voice to give other commands. We then were measured for our interpupillary distance (mine is 64!) with a fancy device (which we were assured would not be packaged with every HoloLens; they're working on fixing this in software), then lead down the hall. Each hotel room had one demo station; mine had two Microsoft employees, which I assume was typical.

So! I got some duplicate explanation and then I got to put the device on. I was able to get a comfortable fit with my glasses, although it took a bit of tweaking. The HoloLens itself was totally wireless, although it clearly communicated with a laptop later on in the demo. It didn't feel particularly heavy, either.

The first scenario was hanging a sign on a wall. There was a sign on the floor, but it didn't look right - when I moved closer to it it got further away, etc. I said this and they seemed to know what the problem was; after recalibrating it (or whatever) I put it back on and it worked. The motion and head tracking worked very well - the holograms really looked like they were in a physical spot in the room! They weren't quite as bright as I would have liked, but they were fairly clear. I was able to walk around the sign and see the back as well.

One big downside is that the field of view is a lot smaller than I had thought/hoped. It's wide enough that you can use it, but it's definitely not immersive like the Oculus Rift. I feel like it was maybe the center third of my vision both horizontally and vertically, althouhg I could be way off.

Anyway, I was able to interact with the sign by looking at it and "clicking" to pick it up, then it followed my gaze. To put it on the wall I had to say something like "scan wall" (probably not the actual words) and then the depth finding went to work and in a few seconds was showing me a cool mesh over the detected surface. It worked surprisingly well and looked very cool. I realize that this is really not that different from what Kinect does, but seeing it in front of your eyes makes it seem way more space-age-y :-)

So I put the sign on the wall and that was that.

The next demo was a 3D model of an underwater scene. After just walking around it and looking a bit, I got to use spray paint to change the color of things. At the start of the demo the toolbox was over in a corner of the room, so I kept looking over there and clicking to select a color. Changing tools was done via speech, like "spray paint", "move", "copy" and the like. The voice recognition was almost flawless, and the more I "clicked" the more impressed I was, because it never missed a click even though I didn't raise my hand up in front of my face or anything and I was purposefully a bit lazy about the motion. Kudos!

The final demo was taking a 3D model of what was (for legal reasons) definitely not an X-wing, changing some colors on that, and exporting the new model to a website, which all just worked. Then the short demo was over, modulo the T-shirt and poster I got.

So...what do I think?
- The actual functionality worked pretty darn well, better than I expected given how paranoid they were about recording devices and the like.
- The headset was comfortable enough, although I only had it on for like 10 minutes.
- The field of view keeps it from being too immersive.
- I'm not sure what the future is for HoloLens. For some niche markets, like 3D modeling or diagnosing mechanical problems remotely or whatnot it seems like a really good idea. The demo they had at the keynote about Joe Consumer pinning apps to walls...I'm not convinced that's going to be a thing that people will do.
- It was a pretty cool experience and I was a little giddy coming out of it :-)
LinkLeave a comment

link friday: solving chronic homelessness, lucky duckies, a wrinkle in time [Apr. 24th, 2015|03:19 pm]
Greg
[Tags|]
[Current Mood |happyhappy]

- The surprisingly simple way Utah solved chronic homelessness and saved millions - by giving homes to homeless people. It's actually more cost effective than what the state was doing already (between jail, hospital visits, and shelters), and it's awfully decent thing to do. There are some moral hazard concerns, I guess, but I would love to see this happen to at least the chronically homeless.

- The double-standard of making the poor prove they’re worthy of government benefits - some people are really worried about people getting government money who don't deserve it. (see also lucky duckies, sigh) (thanks Jessica!)

- When ‘Moneyball’ Meets Medicine - seems like a good idea!

- Uninsured Rate Falls Again for Random Reason Totally Unrelated to Obamacare - who woulda thunk it?

- Gay Marriage State by State: A Trickle Became a Torrent - although I like my map better, the time-lapse pictograph view is pretty nice!

- Madeleine L'Engle's granddaughter found a few pages from "A Wrinkle In Time" that were cut from the book before publication - neat!

- Natural Selection May Help Account for Dutch Height Advantage - weird! Also, I had no idea the average height of the Dutch is over six feet!

- The universe has produced another Nine Inch Nails and Carly Rae Jepsen mashup - pretty good, if you like this sort of thing.

- A Math Problem From Singapore Goes Viral: When Is Cheryl’s Birthday? - fun little problem, took me a little while but I got it. Also: if you saw this somewhere else, this is not a problem given to Singapore fourth and fifth graders, it's from a high school math olympiad...

- Forgotten Wonders of the Digital World: World of Warcraft - ah, I know these places! Un'Goro Crater was always a cool zone, even if some of the quests were rather annoying. (colored crystal collecting, anyone?)
LinkLeave a comment

pictures from the US v Mexico soccer game! [Apr. 21st, 2015|09:56 pm]
Greg
[Tags|, ]

<- click for the full album! (it's small, I promise)

Last Wednesday David and I drove down to San Antonio after work to watch the US Men's National Team play Mexico! The trip started inauspiciously as traffic through downtown was terrible - it took 2:45 to get to San Antonio when it usually takes 1:30. The parking lot around the Alamodome was full so we were directed to the AT&T center and took the Park and Ride there, which actually ran very smoothly. There were a lot of people in both US and Mexico uniforms/outfits. I think the Mexico fans probably outnumbered US ones, but not by as much as I had expected.

<- the players walking out on the field

<- After the US National Anthem played, the American Outlaws brought out the giant flag.

<- Me in the stands! There were a lot of Mexico fans near us.

The game was pretty good, although the pitch looked a bit sloppy. (the Alamodome is not really a soccer stadium...) There was some good-natured ribbing between the US and Mexico fans, especially after the US went up 1-0 near the start of the second half. After the US scored again, a Mexico fan sitting a few rows in front of us threw his beer in the air out of frustration, which prompted a bunch of others around us to do the same. Luckily it passed quickly, and we didn't get tooo wet.

Anyway, the US won by the now familiar Dos a Cero score and all was right with the world. USA! USA!
LinkLeave a comment

India trip: recap, all the posts/pictures [Apr. 5th, 2015|04:32 pm]
Greg
[Tags|]
[Current Mood |pensivepensive]

Here they are!

India, week 1
India, week 2: wanderings, temples, and waterfalls
India, week 3: Delhi, a wedding, home

So, what went well and what didn't go well, so I can remind myself next time I go?

- Meals went well, partially because the hotel restaurants were better than last time, and partially because I got out and walked to dinner places more in the evenings. I also had Indian food most days for lunch instead of pizza, which I think is a net positive because the pizza tastes different than American pizza, and it weirded my stomach out.

- Getting out of the hotel more was good, but I didn't do great here. It's tough since I often got back to the hotel late and I would be tired and not want to go out. What I should have done is walked in the mornings more (since there's a beautiful park two minutes away), or gone to the gym in the evenings, or...something!

- I was lazy about setting up weekend plans with people, which almost totally backfired on me. I need to learn to be comfortable being more aggressive about such things.

- Instead of getting international service through AT&T, I need to just get a local SIM card, which is much cheaper and means I can leave my phone on so people can call me. Again, this came down to laziness. Bad!
LinkLeave a comment

India, week 3: Delhi, a wedding, home [Apr. 5th, 2015|04:19 pm]
Greg
[Tags|, ]
[Current Mood |tiredtired]

<- click for full album
Note that you can "View Slideshow" to get a Facebook-like browsing experience!

Week 3Collapse )
LinkLeave a comment

pre-Austin links: unregulated aggression, metro areas with gay populations, andre the giant [Apr. 2nd, 2015|03:49 pm]
Greg
[Tags|]
[Current Mood |contentcontent]

I'm leaving for Austin tomorrow! Here are some links!

- How Arizona State Reinvented Free-Throw Distraction - The Curtain of Distraction sounds pretty awesome! (and it works!)

- Argument Cultures and Unregulated Aggression - I catch myself doing this occasionally...something to work on. (thanks Adam!)

- Zombie Operating Systems and ASP.NET MVC - backwards compatibility is a harsh master! And 36 years is a long time...

- How to Stop the Stadium Wars - I have no problem with cities helping to build stadiums, but yeah, sports franchises don't need another way to avoid taxes. (remember, the NFL is a nonprofit organization!)

- The Metro Areas With the Largest, and Smallest, Gay Populations - honestly I'm a little surprised that Austin is so high on the list. But, yay Austin!

- Being Andre the Giant - sounds like he was a legitimately nice guy.

- Democrats Had A Sweet Response For Republicans Who Celebrated Texas' Gay Marriage Ban
LinkLeave a comment

navigation
[ viewing | most recent entries ]
[ go | earlier ]