One off the striking things about WP7 is how it tries to force developers to style apps. I don’t see this as a bad thing, and the ApplicationBar is one of the ways it does this. If your application uses a Pivot control, you may want to show a different menu depending on which PivotItem is selected. Unfortunately, the outermost control’s Applicati0onBar is the one which is shown. A relatively easy way to get around this is to define multiple ApplicationBars in the PhoneApplicationPage’s resources, then switch based on the selected index…
Read more »
After being thoroughly let down by the Entity Framework in .NET 3.5, I’ve recently started using it again under .NET 4. So far it seems a lot of the bugs and niggles have been worked out. There are a few things I’ve picked up so far.
Read more »
There are several datagrids available for WPF, but in my experience the best free one is the one included in .NET 4 (formerly the WPF toolkit). A fairly common task which I use in dialogs is using a checkbox to allow selection of items. This isn’t as trivial as it appears with the WPF datagrid, but it is possible.
The first thing you need is an extended DataGrid control which includes a handler for the OnPreviewMouseLeftButtonDown event which listens for mouse clicks, then if the clicked cell contains a checkbox, places the cell in edit mode and toggles the checkbox.
Read more »
There are many times in ChickenPing Android, where I’ve needed to load data from a database to show in an Activity. It’s a fairly common task, but keeping the UI responsive was surprisingly difficult to accomplish.
I tried several methods, including using a runnable to load the data, but they all failed to show a loading dialog soon enough.
The easy way of doing this is with ASyncTask. When the activity is created,after loading the saved state and calling super.onCreate (required to prevent an exception), a custom ASyncTask is executed.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// show the dialog to indicate loading
dialog = ProgressDialog.show(this, getString(R.string.loading), getString(R.string.loading_please_wait), true);
// initialize database
mDatabaseAdapter = new ChickenPingDatabase(ShowRecipe.this);
mRecipeId = (savedInstanceState == null)? null : (Long)savedInstanceState.getSerializable(Recipes.ID);
// load and populate data on separate thread
new loadRecipesTask().execute();
}
There’s a slight delay before the loading dialog is shown, but it’s much smaller than when loading the data in the UI thread. Fire we need to define a few class variables to store references to the UI controls and also to hold the data loaded on a separate thread. A nice way of doing this in for another platform would be to create a DTO to hold the data needed, then return it via the DTO from onPostExecute. The Android best practices, however, state that unless absolutely necessary you should avoid creating objects and DTOs. Instead, I used class variables, which although messier, have the same effect.
Read more »
One of many dinky but interesting methods I'm implementing in ChickenPing Android is this one to format a number of seconds as a human readable string. This uses a context for localization, but it could easily be converted and the localized portions hard-coded.
public static String prettyDateTime(Context ctx, int seconds) {
String timeFormat = ctx.getString(R.string.timeFormat),
longTimeFormat = ctx.getString(R.string.longTimeFormat);
int totalHours;
int totalMinutes;
if (seconds < 60) {
return ctx.getString(R.string.instant);// no time at all!
} else if (seconds < 3600) {
totalMinutes = seconds/60;
return timeFormat.replace("HOURS", "00")
.replace("MINUTES", Integer.toString(totalMinutes));
} else if (seconds < 86400) {
totalHours = (int) Math.floor(seconds/3600);
totalMinutes = (seconds-(totalHours*3600))/60;
return timeFormat.replace("HOURS", Integer.toString(totalHours))
.replace("MINUTES", Integer.toString(totalMinutes));
} else {/*if (seconds < 2592000) {//1 month
double totalDays = Math.Floor(time.TotalDays);
return string.Format("{0} day{1}, {2} hours",totalDays,totalDays==1?string.Empty:"s" , time.Hours);
} else {*/
int totalDays = (int)Math.floor(seconds/86400);
int wholeDaySeconds = (int) Math.floor(seconds-(totalDays*86400));// whole days as seconds
totalHours = (int) Math.floor((seconds-wholeDaySeconds)/3600);
int wholeHoursSeconds = (int) Math.floor(seconds-wholeDaySeconds-(totalHours*3600));// whole days as seconds
totalMinutes = (seconds-wholeDaySeconds-wholeHoursSeconds)/60;
return longTimeFormat.replace("DAYS", Integer.toString(totalDays))
.replace("HOURS", Integer.toString(totalHours))
.replace("MINUTES", Integer.toString(totalMinutes));
}
}
I’m a big fan of jQuery, but so far I’ve only used it for effects. I recently did a draggable, resizable football shirt customization widget for an ASP.NET site and ran into some problems on the way. It’s not quite as simple as just calling $(‘#ele’).draggable().resizable(); due to a jQuery bug, so a bit of hackery is needed.
First, the controls to display the image which the user uploads.
Read more »
I’ve been working with Kentico recently and I needed a section of text on the MasterPage ediatble by the admin, of which there was only one instance. The problem is, if you use a <cms:CMSEditableRegion>, you end up with one instance on every page as the property is stored on the page. In Umbraco you’d probably use a either page in the CMS specifically to hold the text or a new property on the root node.
Read more »
The .NET documentation seems fairly sparese with examples for working PayPal API calls, so here’s my contribution. The CancelSubscription method may not be 100% working, but I believe the problem is with my Paypal account. You also need paypal_base.dll from the SDK. The methods are:
- SetExpressCheckout – Sets the token and returns a URL to which to redirect the user.
- GetExpressCheckoutDetails – Checks whether a token is valid on returning from PayPal
- DoExpressCheckout – Initiates a payment
- CreateRecurringPaymentsProfileCode – Creates a subscription with an optional initial amount
- CancelSubscription – Cancels a subscription
Read more »
Blog4Umbraco is probably one of the only ways to get a decent blog for Umbraco. I had a site which used some other JavaScript and lots of jQuery UI which I neeed to integrate, but as soon as I applied my MasterPage, the AJAX comment form broke. A quick search shows a few people have had this problem, so I want to post my fix. It’s almost embarrassingly simple
Read more »
I’ve been using Umbraco recently, and always find it hard to find XSL templates or spend hours tweaking one when countless other people must have done the same thing, but not published the finished stylesheet.
Below is a navigation breadcrumb template which prints a trail to the current page, starting with level 1.
Read more »