Jeremy Morgan

My Blog about Programming, Tech, SEO, Marketing and whatever else I come up with.

Sneak Peek at Android Studio

Today at the Google I/O conference they announced a bunch of new things, but one that caught my eye was Android Studio, a new development tool for Android Devices. I decided I had to download it and check it out.

First Impressions

I’ll start off by saying I’m not really an Android developer. I’ve toyed around with it, and built one app a couple years ago that’s basically a web wrapper. But after looking through this program I’m becoming inspired to pick it up again. Google is clearly trying to pay attention to the developers, who are the lifeblood of the Android platform.

One thing I noticed right away is this is clearly based off Eclipse, as many IDE’s are these days. That’s not really a bad thing, as Eclipse works really well in many ways and there isn’t any reason to reinvent the wheel. But if you don’t like Eclipse, you may not like Android Studio.

Here are some cool options right from the start:

This is the kind of stuff you’d expect for starting a project. There are some options here which version to compile with, and themes available. You also have your basic settings, minimum API, etc. Stuff that helps you so you don’t get in trouble later down the line. Here you have to make your choice whether to support more features, or be compatible with older devices.

Here we have some options, that I don’t really understand, other than it appears you can have a foreground image and adjust your padding. Probably something to play with later.

Here we have a set of templates, which is pretty awesome. Some of the more common ones you might run into are built for you. The options are

Blank Activity - Creates a new blank activity, with an action bar and optional navigational elements such as tabs and vertical swipes.

Fullscreen Activity - Creates a new activity that toggles the visibility of the system UI (status and navigation bars) and action bar upon user interaction

Login Activity - Creates a new login activity, allowing users to enter an email address and password to log in to or register with your application

Master / Detail Flow - Creates a new master/detail flow, allowing users to view a collection of objects as well as details for each object. This flow is presented using two columns on tablet-size screens and one column on handsets and smaller screens. This template creates two activities, a master fragment, and a detail fragment.

Settings Activity - Creates a new application settings activity that presents alternative layouts on handset and tablet-sized screens.

These give you a nice set of options to start. The most intriguing to me is the Master / Detail flow, which I definitely want to learn more about.

Note about Performance

I noticed it’s a little sluggish loading and building, but I did run this on an older Centrino machine with 4 gigs of RAM. Keep in mind this is an early release, and it’s an old machine. When actually coding in the IDE it seems to run really well, and I haven’t had too many quirks.

I can’t say I’m thrilled with that memory usage though.

Inside the IDE

The IDE looks a bit familiar if you’ve ever used Eclipse, but it’s got a lot of nice features, and is clearly tailored for Android development.

It has everything where you’d expect it to be, and the syntax highlighting is pretty nice. Code collapsing and most of the features you’d expect are here.

One thing I noted that’s pretty awesome is the Version Control integration.

There are a lot of awesome tools in this IDE, too many to describe in one article, but the code analysis ones really stand out:

I ran some tests on my basic project and found a lot of things worth looking at:

Lots of refactoring options. This kind of stuff saves you a lot of time and can even help improve your coding.

Overall I think hardcore Android developers are really going to like what’s included here.

A few issues

I mentioned it’s a little sluggish, but that’s to be expected with bleeding edge software on old hardware. It’s only a little slower than Eclipse runs on this machine. But I noticed that I couldn’t get it to find my phone or my Kindle Fire when I tried:

And it wouldn’t let me run anything in the AVD:

Though this could be a configuration error. I couldn’t find where to change it and gave up, but I’ll come back to it soon.

Conclusion

I’m sure in the coming days you’ll hear some complaints and talk of it just being a “reskinned Eclipse” but I think Google is going in the right direction with this. There are tons of features I haven’t even dug into yet, and many I don’t know as I’m not really an Android developer at this time. But I did use the ADT environment for Eclipse and I do see some obvious improvments.

Google is showing that the see the value in their developers and are giving them some pretty awesome tools to succeed. There were also some great gaming APIs released today and what we’re seeing is Google preparing developers to take their popular platform to the next level. It’s an exciting time to be a programmer indeed.

Download it and try it out!

Download Android Studio Here


Do you like articles like this?

I’m constantly hacking on stuff and writing about happenings in the programmer world. You can subscribe to my feed here, or you can get the programmer newsletter spam free!

Intro to ASP.NET MVC 4

The ASP.Net MVC 4 framework was introduced in August of last year and it boasts tons of improvements over MVC 3. If you’re considering building a large application in .Net, you should consider MVC 4 for your project. Today we’re going to take a look at it and build a quick website in MVC 4.

What you’ll need

In order to complete this tutorial you will need Visual Studio. I have decided to use Visual Studio Express 2012 for Web to do this tutorial. I made this choice because it’s a free download and not everyone can afford the professional version of Visual Studio, but if you’re using Visual Studio 2010 or 2012 you can still go along as well.

Software needed:

Microsoft Visual Studio Express 2012 for Web (or a licensed version of Visual Studio 2010/2012)

Microsoft Web Matrix 2 - This is a handy little stack to help organize your server and projects for development

Microsoft ASP.Net MVC 4 - The package you’ll need to install to deploy this on your website.

Keep in mind all of this is free! The MVC package is also Open Source. It’s nice to see Microsoft come around with stuff like this.

Let’s get set up

One of the things every Visual Studio has been raving about lately is the NuGet package manager, for good reason. It makes setting things up super easy. We want to make sure we have it installed for our project.

Go to Tools -> Extensions and Updates

How to Program ASP.Net MVC 4

And make sure the NuGet Package Manager is installed:

How to Program ASP.Net MVC 4

This will enable you to install stuff into your website easily. They have a lot of great plugins and templates available.

Create the Project

Go to the start section and click “New Project” or select it from the File menu. You want make sure to select an ASP.NET MVC 4 Web Application.

How to Program ASP.Net MVC 4

On the next screen, select “Internet Application”. As you can see there are various options here, feel free to play around with them and see what you come up with.

How to Program ASP.Net MVC 4

Now you’ve created your new MVC application. Let’s take a look at it. If you press F5 you’ll see it’s already assembled into a site. But that doesn’t do much yet.

How to Program ASP.Net MVC 4

The parts of your MVC application.

You’ll notice the controller is opened automatically. Let’s take a look at it and see what it does:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";

            return View();
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your app description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }

As you can see this is the “Home” controller that extends the controller class. Since Home is your default route it will control what’s seen on your site root.

1
2
3
4
5
public ActionResult Index()
    {
        ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
        return View();
    }

This is the “Index” method, and it’s not too tough to guess it’s place. This is what shows up when you hit a root directory. Whatever you put in here gets shown on the page. But let’s look a little closer inside the method.

ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";

The ViewBag is a wrapper object used to store dynamic data for the ViewData dictionary object. There are some arguments circulating about which one to use, but since Visual Studio stuffs this in, we’ll use it. Let’s change it to something else:

ViewBag.Message = "This is my first MVC Project!";

Where does this data go? If you open up /Views/Home/Index.cshtml you’ll see where this object is used.

How to Program ASP.Net MVC 4

First, at the top you’ll see where the ViewBag.Title property is assigned a value:

1
2
3
@{
    ViewBag.Title = "Home Page";
}

This is a part of the Razor engine and it’s how you change the title of the page when it loads. You can also change it later. Then further down the page you’ll see:

1
2
<h1>@ViewBag.Title.</h1>
 <h2>@ViewBag.Message</h2>

As you can see, this is where the ViewBag.Message you changed earlier will go.

One advantage of this is you can make the text displayed dynamic, pulled from a database, object or other data source without touching the design. You can also use this for localization if needed. The Razor engine is pretty sweet, this is just scratching the surface of it.

Creating a New Page

By now you’ve probably figured out that the methods in the controller correlate with pages: Index(), About(), and Contact(). So let’s look at creating a new page. We will be creating a page located at “http://(your site url)/Home/Newpage”.

1. Create a new ActionResult Method

Inside your HomeController, create a new method:

1
2
3
4
5
public ActionResult Newpage()
{
  ViewBag.Message = "This is a new page! ";
  return View();
}

The home controller is found in /Controllers/HomeController.cs

What is this? The HomeController is the controller for your home directory and each ActionResult is a function of that controller or page. In our case the url would be

Http://www.yoursite.com/home/newpage

Each action must have a view, which we’ll create next.

2. Create a view page

A view is simply an HTML page that displays data and interacts with the controller. You create views for pages or parts of pages, such as menus.

In the /Views/Home/ folder, create a new view by right-clicking on the /Views/Home folder and selecting “New View”:

How to Program ASP.Net MVC 4

You’ll see a dialog box that looks like this:

How to Program ASP.Net MVC 4

As you can see, this dialog box has a few options. For the view engine, you can choose Razor or ASPX(C#). Choose Razor for this, and leave the rest of the options open. You can create a strongly typed view that’s based of an object, but we’ll leave that for another tutorial. Hit add.

You’ll see the page now in your views folder.

How to Program ASP.Net MVC 4

Open up that page, and you’ll see the following code:

1
2
3
4
5
@{
    ViewBag.Title = "Newpage";
}

<h2>Newpage</h2>

Add some html for fun in there. Also, add the following line:

1
Hi! Today is @DateTime.Now.DayOfWeek

Save the file, and press F5 to run.

Your new MVC Page

To load the page you just created, type in

/home/newpage

after the URL. For instance my local URL is http://localhost:59312/home/newpage but yours may vary. You should see something like this:

How to Program ASP.Net MVC 4

This is your newly created view! Feel free to experiment with the views and the Razor view engine. The best way to learn is to break it!

Summary

In this tutorial we built a very basic MVC 4 page in ASP.Net. I hope it gets you excited enough to start really experimenting. The MVC package really does a lot of the work for you, you can actually create whole websites without a lot of code at all. But I do hope you will dig into the code, and get rid of some that atrocious HTML that’s generated and fiddle around.

In a future tutorial I’ll cover the Entity Framework and show you how easy it is to add data to your MVC Pages. Sign up for my newsletter and you’ll know right when it’s posted!

Where to Find a Cheap Computer in Oregon

This post isn’t going to be much use for the majority of my audience, but I am creating this post because I am often referring people to these places, and wanted to create a nice page to send them to.

This is a small list of computer recyclers in my area that I’ll be updating and spreading around. I’m a huge fan of computer recycling and low cost computing, if you’re curious you should look around in your area for some similar non profit recyclers!

Can I use a recycled computer?

The answer to this isn’t always yes. If you’re looking for the latest and greatest, or you play games (real games not Facebook games) you won’t be able to find what you need here. But mostly what I get asked about is: “I need a computer for school but don’t want to pay a lot” and that’s one area where recycled computers shine. Here’s what you can use recycled computers for:

Schoolwork - High School, college etc. Creating documents and reports, etc. A cheap computer running OpenOffice will work just fine.

Programming - A high end machine is nice for programming but not really necessary. You can do web development on just about anything for instance. I do most of the work for this website on a 2004 Powerbook, because it’s basic text editing. My Windows stuff is done on a 2007 Toshiba Laptop.

Office Management - Again using a cheap older computer with OpenOffice and you can do pretty much anything a high dollar new machine will do, only a bit slower. But if you’re saving $1000 it might be worth the price.

Kid Computers - If you want a computer for your kids to browse the internet and play learning games an old computer works great. If you’re ready for the challenge, you can install Linux on it where most versions have TONS of educational software for free. Take Edubuntu for a spin and check out all the awesome stuff they have.

This list could be a lot longer but it’s not the purpose of the article. Basically if you aren’t playing online games, ripping videos or something of that sort you might notice that a new computer isn’t a whole lot better than an older one.

Cheap Computer Recyclers in Oregon

Here is a list of people I’ve dealt with personally and really like. You can walk in with a couple hundred bucks and come out with a decent desktop or laptop that works great. They test their equipment, set it up and don’t try to upsell your or rip you off.


Computer Drive Connection - Cornelius Oregon

Their Website

Since this one is closest to my hometown I’ve been sending a lot of people here. The guy running it is great, he’s very knowledgeable and honest. Just tell him what you need to use a computer for and he’ll steer you right. Great prices as well.

For instance, I picked up a 20” LCD flatpanel monitor there recently for $100. Worked great, no scratches or dead pixels. It’s the 3rd or 4th monitor I’ve picked up there that works great.

Map to their location

Phone: (503) 992-0180


Eco Binary - Beaverton Oregon

Their Website

I just recently discovered this place, and they treated me really well. I picked up a laptop for $100 (the Core2 Toshiba) and an old G4 machine for a server. The dusty old G4 had been sitting a while but he said “yes, it works if not bring it back”. Great policy, but the machine did work exactly as advertised.

Again it’s a good place with knowledgeable people and no sales pressure. It’s family run and they do a great service for the community and their customers.

Map to their location

Phone: (503) 352-4991


Free Geek

Their Website

For those in the Portland Metro area this is another great service you gotta check out. They are a non profit that offers free computers (if you qualify) and free computer classes as well. But if you don’t qualify for a free one or you feel like supporting them you can visit their thrift store and purchase items at a great price. All purchases support their mission.

Map to their location

Phone: (503) 232-9350


Recycled computers are awesome!

I will be researching more of these types of companies locally and adding to this list. There’s many reasons getting a recycled computer makes sense, you save money and help keep this stuff from hitting landfills. You support families and volunteers rather than giant corporations.

If you’re not from the Northwest Oregon area, search for some recyclers in your area! Even if you already have your dream machine it may be worth getting a machine to tinker with for projects, media servers etc. Enjoy!

What Is MVC?

The MVC or Model View Controller architecture is a software pattern that’s become very popular over the last few years. With this article we’ll take a look at MVC, how it works and how it’s used.

How I Improved the Speed of My Mobile App by Over 1000%

A couple years ago I wrote an app called “FireCom” for the Android phone that’s basically just a listing of active Fire and EMS calls in Washington County, Oregon. I never expected too many people to use it and gave it away so I didn’t put a lot of time into it. As it turned out a lot of people started using it, so lately I decided to put a little more effort into it.

How to Build C# Apps on Your Raspberry Pi

Want to run and build .Net applications on your Raspberry Pi? In this article I’ll show you how. With Mono you can develop and run .Net applications on your Raspberry Pi. I got a few emails about this, so I decided to create a quick tutorial.

The Single Responsibility Principle

There’s a lot of genius in simplicity. This applies to many things in life and definitely in software development. SRP, or Single Responsibility Principle is one of the foundations building better software. It’s a good way to keep code working as expected, and to avoid painting yourself in a corner.

How to Watch Netflix in Ubuntu Linux

One of the biggest hurdles to Linux adoption is getting stuff to work in Linux that works great in Windows. Microsoft has enjoyed a huge market share over the years, and because of that when companies develop commercial software they target Windows first, and maybe OSX. Linux is either an option for companies with a geekier application, or their product is either emulated or ported by dedicated Linux hackers. What this does is ensure you pretty much need a Windows box somewhere for some task. But this changes every day.

How to Set Up the Ultimate PHP Dev Machine in Ubuntu 13.04

Today I’m going to tell you how to build the ultimate PHP development environment in Ubuntu 13.04 (Raring Ringtail). PHP has been getting a lot of flack lately, but there is still a lot of enterprise level professional development going on with this language. And hey, I love .Net programming but you can build solid, quality PHP applications with the right knowledge and the right tools. Today I’ll tell you how set that up.