12 Jun

Changing Keyboard Layouts

In my last post I set a goal to switch to the Dvorak layout over the next few months and I’m looking to double my typing speed.  To do that, I am practicing typing on the Dvorak layout for a 10-15 minutes a day for a while and as my speed improves I’ll add time.  I’ve found that switching layouts is startlingly easy, so I thought I’d share how to do it (instructions are for Windows 7 and may vary for other versions).

Click Start and type “intl.cpl” into the search box.  This will bring up the Region and Language control panel.  Click on the Keyboards and Languages tab.

Capture1

Click Change Keyboards

Capture2

Click Add and select the keyboards you want to add.  I just added United States-Dvorak.

Go to the Advanced Key Settings

Capture3

From here you can assign Hot Keys to switch between layouts.  If you highlight the “Between input languages” and click the Change Key Sequence, you alter what key combinations cycle between languages and keyboard layouts.  I removed the cycle between languages because I only use US-English, and I assigned the Left Alt-Shift to cycle between keyboard layouts.

Capture4

The last thing I did is back on the General tab, I went to the properties of the Dvorak keyboard and I changed the icon to a keyboard with a red border so that when my keyboard is in Dvorak mode the little Language Bar icon on the right side of the task bar is a read keyboard instead of the standard one.

QWERTY

image

Dvorak

image

No for the best part, or worst part, I’m not entirely sure yet.  When you switch layouts, the switch only affects the app you were in when you switched layouts.  So, I can keep my browser in Dvorak for typing practice, but Outlook and Visual Studio stay in QWERTY.  I think this will come in handy in the long run as I can keep a say Outlook in Dvorak, and Visual Studio in QWERTY or vice versa depending on productivity.  Eventually I’ll switch the default…

07 Jun

Typing Speed

So, I read one blog by Steve Yegge linked from CodePoject about typing speed (which is a great read if you have the time).  Then Steve Smith tweeted his blog post on the same subject, which was in response to Jeff Atwood’s post.  Apparently all 3 articles are from 2008, but I read them like they were news today.

Was that enough name dropping?

I read those 3 articles, and all 3 have the same premise.  You should be a fast efficient typist if you write code for a living.  They go almost as far as saying it’s the most important skill.  I don’t think that’s true, but being a better typist will most likely make you a better programmer.  If I code type as fast as I thought, I could either put out a bunch more code per day, or I could put out the same amount of code, just better thought out.  Or some combination in the middle – a little more slightly better thought out code.

They also linked to this typing speed test.  Steve Smith and Jeff Atwood were both in the mid 80′s and Steve Yegge claims 120 WPM.  I have no reason to doubt Mr. Yegge, but his measurement may be from typing his own thoughts whereas the rest of us used the typing speed test where you are copying text and I think there’s quite a difference.  I suspect Steve Smith and Jeff Atwood would easily put out 100+ WPM of their own thoughts.

Of course I tested myself and came up ~55 WPM.  I did the test 3 times at 54, 56 and 54 WPM.  Each test had between 1 and 3 errors.  I was not impressed with my performance (partly why I took the test 3 times), so I’ve set a goal to double my speed on that test.

My plan is this:  I’m going to switch to Dvorak layout for ~10-15 minutes a day and practice with some sort of online typing tutor.  Once I have the keyboard memorized and I’m typing >30 WPM, I’m going to add a few hours a day in Dvorak, the rest in Qwerty.  Once I hit >50 WPM, I’ll switch to full-time Dvorak, and continue with the typing tutors for the 10-15 minutes per day until I reach 110 WPM.

Through this I’m going to try to update here every week or two to report progress.

05 Jun

Using a different DataTemplate when a WPF ComboBox is expanded

A quick post showing how to create a combo box that shows a single line, shows multiple lines when expanded. Obviously you can extend this to show any two datatemplates for collapsed and expanded.

ComboBoxExample

The first thing I did was create the data templates that control how the address is going be displayed. When it’s collapsed, I just wanted to show the AddressName and AddressType on one line:

<DataTemplate x:Key="AddressComboCollapsed" >
    <StackPanel Width="150" HorizontalAlignment="Stretch" >
        <DockPanel HorizontalAlignment="Stretch">
            <TextBlock Text="{Binding Path=AddressName}" 
                       DockPanel.Dock="Left" 
            />
            <TextBlock Text="{Binding Path=AddressType}" 
                       DockPanel.Dock="Right"
                       HorizontalAlignment="Right"
            />
        </DockPanel>
    </StackPanel>
</DataTemplate>

When it’s expanded, I want to show the whole address and suppress AddressLine2 if it’s blank:

<DataTemplate x:Key="AddressComboExpanded" >
    <GroupBox BorderThickness = "1"
              Margin = "0,0,0,3"
              Width = "Auto "
              HorizontalAlignment = "Stretch"
              Header = "{Binding Path=AddressType}">
        <StackPanel Margin="3" 
                    HorizontalAlignment="Stretch"
                    MinWidth="250">
                <TextBlock Text = "{Binding Path=AddressName}"/>

            <TextBlock Text = "{Binding Path=AddressLine1}"
                       Name = "tbAddr1"
            />
            <TextBlock Text = "{Binding Path=AddressLine2}"
                       Name = "tbAddr2"
            />

            <!-- City, State, and ZIP display -->
            <StackPanel Orientation = "Horizontal">
                <TextBlock Text = "{Binding Path=City}" />
                <TextBlock Text="," Padding="0,0,5,0"/>
                <!-- Put a comma between city and state -->

                <TextBlock Text = "{Binding Path=State}" Padding="0,0,5,0" />
                <TextBlock Text = "{Binding Path=PostalCode}" />
            </StackPanel>
        </StackPanel>
    </GroupBox>

    <DataTemplate.Triggers>
        <!--If the "AddressLine2" portion of the address is blank, then
            HIDE it (no need to display an extra blank line)
            
            This only works is AddressLine2 = "", not if it's null
        -->
        <DataTrigger Binding = "{Binding Path=AddressLine2}" Value = "">
            <Setter TargetName = "tbAddr2" 
                    Property = "Visibility" 
                    Value = "Collapsed"
            />
        </DataTrigger>
    </DataTemplate.Triggers>
</DataTemplate>

The next step was to create a AddressTemplateSelector class that inherits from System.Windows.Controls.DataTemplateSelector.DataTemplateSelector, and override the SelectTemplate method.

public class AddressTemplateSelector : System.Windows.Controls.DataTemplateSelector
{
    public override DataTemplate SelectTemplate(object item, DependencyObject container)
    {
        ContentPresenter presenter = (ContentPresenter)container;

        if (presenter.TemplatedParent is ComboBox)
        {
            return (DataTemplate)presenter.FindResource("AddressComboCollapsed");
        }
        else // Templated parent is ComboBoxItem
        {
            return (DataTemplate)presenter.FindResource("AddressComboExpanded");
        }
    }
}

After that, it’s just a matter of importing the namespace of the DataTemplateSelector into the Window, merging the Resource Dictionary that contains the DataTemplates, and setting the ItemTemplateSelector of the ComboBox.

<ComboBox Height="30" Width="200"
            ItemsSource="{Binding Path=Addresses}">
    <ComboBox.ItemTemplateSelector>
        <dt:AddressTemplateSelector/>
    </ComboBox.ItemTemplateSelector>
</ComboBox>

Point of Interest

If you look closely at the templates, you’ll notice that the expanded template is wider than both the combobox and the collapsed template. This allows you to have the list be wider than the original combobox. That’ll be a nice feature when I move on to the state selection combo (display only StateCode, but show StateCode + StateName when expanded).

04 Jun

WP7 Application Capabilities

WMPoserUser posted some interesting stats on what capabilities applications are requesting.  Interesting stuff, but they clearly haven’t published an app, or at least not an ad supported app.

First let me say that I have only published a single app so far, so I’m not some amazing expert.  My app, Chess Tactics, doesn’t actually need any capabilities by itself.  That being said I have quite a few capabilities listed.  Most of these capabilities are required by Microsoft’s ad control, with one additional capability required by MTIKS (a utility I’m using usage and error detail).

Here’s my capabilities list and why I include it and why I think it’s required:

  • Phone Dialer
    • MS Ad Control – so you can dial a phone number direct from an advertisement
  • Networking
    • MS Ad Control – to download ads for display and report any clicks
    • MTIKS – Send data back for reporting
  • Web Browser
    • MS Ad Control – to display the ads
  • User Identity
    • MS Ad Control – to track what the users interests are across apps
    • MTIKS – Track user loyalty across app versions and user device upgrades
  • Media Library
    • MS Ad Control – No idea at all
  • Device Identity
    • MTIKS – To track what devices are using my app in case a particular one become problematic

None of these capabilities indicate an app is trying to do anything nefarious.  I would expect pretty much every app to need these capabilities.  Now if an app wants access to my microphone, it better have a damned good reason.

Between collecting stats, serving ads, and apps that use network service to provide value, I think it’s out of line to say that 95% requesting network services is “larger than necessary”.  In fact, it makes me wonder what the 5% of apps that don’t require network access are.

If you know why the MS ad control needs access to the Media Library please let me know in the comments.