Xamarin: Rapid Mobile App Prototyping with Xamarin.Forms

Creating mobile app prototypes is an important part of the design process. It’s extremely useful for developers and test users to be able to interact with a prototype in order to experience how the app will behave when it’s complete, but building prototypes can be daunting due to the large amount of time it takes. […]

The post Rapid Mobile App Prototyping with Xamarin.Forms appeared first on Xamarin Blog.

James Montemagno: Xamarin Evolve + Open Source Save The Date App

In just under eight months in Orlando, FL thousands of mobile .NET developers will be heading to the next Xamarin Evolve conference. Xamarin Evolve 2014 was one of the most spectacular conferences that I have ever been part of and have ever attended. The most amazing developers came together for five action packed days of training, sessions, hacking, and collaboration. To keep it short, you do NOT want to miss Xamarin Evolve 2016.

I had the joy last year of crafting multiple mobile applications for Evolve including the main conference application and an interactive scavenger hunt based on iBeacons called Evolve Quest.

With Evolve 2014 coming to a close there isn’t much need for the mobile application to hang around on the app stores, which is why I teamed up with Xamarin’s very own Mike James to craft an updated Save the Date application for Evolve. We decided that we wanted something simple but native. It had to be elegant with the latest iOS and Android designed, but still have deep integration into the platforms. The new Save the Date application for Evolve can be installed from both the Apple App Store or Google Play for Android enabling you easily sign up for updates, add Evolve to your calendar, and of course share Evolve with your friends.

Best yet, is that you can see exactly how Mike and I created the application and create your own Save the Date application for your upcoming event. Simply head over to the github repo to download the entire source code and get started today. 

Greg Shackles: Create Modern Android Apps with the Design Support Library

With the release of Android 5.0, also known as Lollipop, Google introduced its new material design style.

Material Design is a huge step forward for Android apps, bringing with it a total overhaul of theming, as well as a bunch of new UI components you can use in your apps. To make things even better, Google also released the Android Design Support Library, which allows you to take advantage of material design in versions of Android going all the way back to Android 2.1.

In this article I’ll walk-through some of the new components available in this library, and show how easy they are to introduce into an app.


Read the rest of the article over at Visual Studio Magazine.

Xamarin: Test Your Way to Xamarin Evolve Contest Winners!

We’d like to extend a big “Thank you!” to everyone that entered our “Test Your Way to Xamarin Evolve” contest. With app testing at the forefront of every mobile project, Xamarin wanted to relieve some of the stress associated with UI.Testing by introducing Xamarin Test Cloud. Now that all Xamarin Platform subscriptions include 60 Xamarin […]

The post Test Your Way to Xamarin Evolve Contest Winners! appeared first on Xamarin Blog.

Matthew Leibowitz: Genetics for Xamarin.Android

As with all my development, I try to do as little as possible 🙂 The more code you type, the more you have to maintain and bugfix.

Now, being that I enjoy working on libraries/backends rather than on UI/frontends, I like my code to be neat and clean. Sure, the final app must be good, but I read the code.

So, I looked around and found a simple way to reduce the overall boilerplate code, as well as improve the final code. Although good code doesn’t mean a good app, bad code often results in a poor app.

A Practical Example

This library is focused around only one small things, but that one small thing is done over and over again everywhere… boilerplate! This one thing is getting hold of an Android View or Resource based on the ID.

For example, if we have an Activity with X amount of UI widgets that we need to access:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical"
  android:padding="8dp">
  <TextView
    android:id="@+id/myLabel"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:textSize="50sp" />
  <Button
    android:id="@+id/myButton"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp" />
  <ListView
    android:id="@+id/myListView"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:layout_margin="10dp" />
</LinearLayout>

Then, usually we would have X number of FindViewById method calls and X fields:

private TextView myLabel;
private Button myButton;
private ListView myListView;

protected override void OnCreate(Bundle savedInstanceState)
{
  base.OnCreate(savedInstanceState);

  SetContentView(Resource.Layout.MyActivityLayout);

  myLabel = this.FindViewById<TextView>(Resource.Id.myLabel);
  myButton = this.FindViewById<Button>(Resource.Id.myButton);
  myListView = this.FindViewById<ListView>(Resource.Id.myListView);
}

This is not much code as it stands, but it is a bit monotonic if you ask me… especially if you have a good few widgets on the screen.

Now, this is where Genetics comes in. We can replace all those FindViewById methods with a single Splice method call, and annotate the fields, or properties, with the [Splice] attribute:

[Splice(Resource.Id.myLabel)]
private TextView myLabel;
[Splice(Resource.Id.myButton)]
private Button myButton;
[Splice(Resource.Id.myListView)]
private ListView myListView;

protected override void OnCreate(Bundle state)
{
  base.OnCreate(state);

  SetContentView(Resource.Layout.MyActivityLayout);

  Geneticist.Splice(this);
}

And that’s all there is to it!

Resources

Not only can we avoid all the FindViewById method calls, but we can also avoid querying the Resources object for the various values. Given the resource file:

<resources> 
  <string name="titleText">Genetics</string> 
</resources>

We can automatically populate the field or property in the same way as with the views.

[Splice(Resource.String.loginError)]
private string loginErrorMessage;

protected override void OnCreate(Bundle state)
{
  // ...

  Geneticist.Splice(this);
}

Fragments

A special case exists when the target object instance that contains the widgets is not an Activity, Dialog or View. This is most commonly used when inflating views, as when using a Fragment:

public class MyFragment : Fragment
{
  [Splice(Resource.Id.textView)]
  private TextView textView;

  public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle state)
  {
    var view = inflater.Inflate(Resource.Layout.MyFragmentLayout, container, false);

    Geneticist.Splice(this, view);

    return view;
  }
}

List Views

Another popular case is when working with a ListView and the view holder pattern for the list items:

public class SimpleAdapter : BaseAdapter
{ 
    public override View GetView(int position, View convertView, ViewGroup parent)
    {
        ViewHolder holder;
        if (convertView != null)
        {
            holder = (ViewHolder)convertView.Tag;
        }
        else
        {
            convertView = inflater.Inflate(Resource.Layout.SimpleListItem, parent, false);
            holder = new ViewHolder(convertView);
            convertView.Tag = holder;
        }

        holder.word.Text = ...;
        holder.length.Text = ...;
        holder.position.Text = ...;

        return convertView;
    }

    private class ViewHolder : Java.Lang.Object
    {
        [Splice(Resource.Id.word)] 
        public TextView word;
        [Splice(Resource.Id.length)] 
        public TextView length;
        [Splice(Resource.Id.position)] 
        public TextView position;

        public ViewHolder(View view)
        {
            Geneticist.Splice(this, view);
        }
    }
}

Downloading & Using

There is lots more that can be done, or rather, not done, using Genetics. The best way to get hold of this library is either through the Xamarin Components Store or from NuGet.

This library is really tiny, and has no dependencies other than Android…

Lots more information can be found on the Getting Started guide as well as in the source on GitHub.

Adam J Wolf: Weekly Xamarin Newsletter Issue #54

Free Xamarin Subscriptions for Windows Phone Developers Joseph Hill, from Xamarin Inc., made all Windows Phone developers day. Accessing Azure AD information from .Net Azure Mobile Services and the Xamarin Client Kevin Ford digs deep into Azure AD and comes up with a winner. Xamarin Helps Launch AWS APN Mobile Competency Program Lacey Butler, from […]

The post Weekly Xamarin Newsletter Issue #54 appeared first on Syntax is my UI.

Johan Karlsson: Roboto Condensed Bold in Forms (iOS)

The last few days have been spent in pixel perfect land. I’ve done some fine tuning of a clients forms layouts that of course includes a bunch of custom fonts. I’ve started out with making sure that the iOS design is correct and we’ll move on to Android and WP in another post perhaps.

This post is about a specific issue and that issue is how the naming of the font isn’t all that matters.

Short version

Ttf-files only contain one weight. If you bold a regular version of a font it will be calculated bold and not the true bold since that one is contained in another file. To get the real bold, you need to reference the ttf-file containing the bold weight.

Start off here for the longer version

To get a grip of how to use custom fonts, please check out the Xamarin documentation at http://developer.xamarin.com/guides/cross-platform/xamarin-forms/working-with/fonts/ and also a post from Mike James that can be found here: https://blog.xamarin.com/custom-fonts-in-ios/

So what’s the problem?

To summarize the usage of custom fonts loaded from a ttf-file on iOS, all described in the links above.

  • Add the ttf-file to the Resource folder – make it a Bundled Resource and Copy Always
  • Edit the info.plist to include the font
And then to use the font we do something like
<Label FontFamily=Roboto Condensed Text=Very custom />

To find out the FontFamily name to use, you open up the ttf-file in Windows by simply double clicking it and you’ll find it. Since my client is a client, they wanted to use a different typeface for the bold text. No problem, I shouted and downloaded the bolder typeface perfectly named Roboto Condensed Bold.

I then opened the ttf file in windows to check out the name and it was named exactly the same. Wait what? How do I then distinguish between them?

It turns out that the Bold font has the same name and will be used if you set FontAttributes=”Bold”.

<Label FontFamily=Roboto Condensed Text=Very custom FontAttributes=Bold />

And if you use the above without importing the “Roboto Condensed Bold” font it will Bold the regular font.

Still, what’s the problem?

Really, nothing when I come to think of it. TrueType only supports one weight per file from what I understand and that’s what I’ve missed in the past. I just thought that a font is a font and all is included within. 🙂
Also, if you only supply the regular weight and bold it, it would be some kind of calculated boldness instead of the real bold font that is meant to be used.

Summary

Make sure you reference all the weights you want and if they have the same name you only have to change the FontAttributes to select the font you wish for. But be careful and check that you actually get the weight you want since it would still bold a regular font instead of picking the correct one if you miss something along the way.

Resources

TrueType on Wikipedia – https://en.wikipedia.org/wiki/TrueType