Showing posts with label mobile. Show all posts
Showing posts with label mobile. Show all posts

Tuesday, February 25, 2014

Android: "No Resource Found" & nextFocusDown

I received a mysterious Android XML error earlier today:

error: Error: No resource found that matches the given name (at 'nextFocusDown' with value '@id/current_calculation_display').

This requires a bit of background.

My application has three layout files:
  1. activity_calculator_horizontal.xml
  2. activity_calculator_small_vertical.xml
  3. activity_calculator_vertical.xml
All three files have a parent node: LinearLayout or ScrollView depending on layout. Each contains a TextView with attribute android:id="@+id/current_calculation_display".

This error occured when setting the android:nextFocusDown attribute in the 'horizontal' activity's parent node to "@id/current_calculation_display". I did this with the 'vertical' and 'small_vertical' layouts without issue.

The problem is that, in the 'horizontal' activity, the 'current_calculation_display' ID doesn't exist yet! This isn't a problem for the other two files because the ID gets created in the 'horizontal' activity. I tested this behavior by adding a (mostly blank) activity with the current_calculation_display TextView.

Using android:nextFocusDown="@+id/current_calculation_display" fixes the problem.

Friday, November 8, 2013

Getting Started With Bourbon Neat (without Rails)

What is Bourbon Neat?

Bourbon Neat is a Sass (CSS extension language) framework that provides mixins used to make responsive grid layouts for sites. It's built on-top of Bourbon, a helper mixin library also for Sass.

Bootstrap and similar front-end frameworks are great, but sometimes, you want something that's lighter weight. It's very difficult to use Bootstrap with an existing site while keeping the original look of the site, and besides, all I need is a responsive grid. That's where Bourbon Neat comes in.

This post will show you the basics: it covers setup and basic use of Neat in a non-Rails Ruby project.

Initial Setup for Bourbon Neat

I will go ahead and assume that you:
  • Have at least one existing sass/scss file, preferably in its own directory
  • Are using Bundler for your project
Step 1: Add gem "neat" to your Gemfile
Step 2: Run bundle install
Step 3: Go to your Sass directory and run bundle exec bourbon install && bundle exec neat install

This will add files for Bourbon and Neat to your Sass folder. Should you add these files to version control? I'm not sure what the best practice is, but I went ahead and added them to version control on my project.

Using Bourbon Neat in Your Sass File

Drop the following two lines at the top of each main Sass/SCSS file:


@import "bourbon/bourbon";
@import "neat/neat";
 
By themselves, these two lines don't change output CSS much. Including Neat adds some CSS that sets box-sizing for all elements to 'border-box.'

The official Bourbon Neat site has a sample that shows you how to build a semantic grid. The basic principle is that you need something that includes the 'outer-container' mixin and at least one element nested within it that includes the 'span-columns' mixin.

Using Bourbon Neat for Responsive Styles

One of the many nice things about Bootstrap, Foundation, and other heavyweight style frameworks is that their grid systems are very responsive to changes in browser/device width. They'll do things like change a row with two 6-column divs to look like two rows of full-width divs. Bourbon Neat allows you to do this too, but you manually have to specify settings like width breakpoints and what columns do at those breakpoints.

Here's an example SCSS file using Bourbon Neat:

@import "bourbon/bourbon";
@import "neat/neat";
$desktop: new-breakpoint(min-width 768px 12);
$tablet: new-breakpoint(max-width 768px 1);

.header {
  @include media($desktop) {
    @include outer-container;
  }

  .page-title {
    @include media($desktop) {
      @include span-columns(7);
    }

    @include media($tablet) {
      display: block;
    }
  }

  .site-nav {
    @include media($desktop) {
      @include span-columns(7);
    }
    @include media($tablet) {
      display: block;
    }
  }
}


Neat includes a 'media' mixin that allows you to specify styling for a specific breakpoint. As far as I know, Neat has no built-in breakpoints, so you must use the 'new-breakpoint' function to make them.

February 17, 2014 Update: Simplified example file and removed incorrect information about an error that can occur within new-breakpoint.

Saturday, September 22, 2012

Quick Guide to Adding a Mobile Stylesheet to Your Site

Do you want your site to look alright on a mobile device? Do you want to avoid using Foundation, Twitter Bootstrap, or any other front-end web framework? Here’s a four-line guide to having a separate stylesheet for iPod Touch/iPhone 4 (and maybe some other devices).

Put this in your web page’s header:


<link href="/css/main.css" rel="stylesheet" media="screen and (min-device-width: 768px)">
<link href="/css/mobile.css" rel="stylesheet" media="screen and (max-device-width: 767px)">


Where “/css/main.css” and “/css/mobile.css” are your desktop and mobile style files.

What with the 768?

It’s the width in the screen resolution of 1024x768. That’s the resolution of the iPad 2, so users on the iPad 2 will use the desktop stylesheet.

What with the 767?


It’s a quick-and-dirty fix so that devices like the iPad don’t try to load both styles at the same time. Foundation’s CSS file constantly references this number with regard to mobile devices, so I might be onto something.

Will This Work With Retina Displays or Tablets?

You need to tweak the numbers a little for tablets. I don’t have access to a device with a Retina display.

Can This Break My Existing Desktop Layout?

Visitors stuck with a display resolution of 800x600 will be forced into viewing the mobile layout. Twitter Bootstrap (at the time of this writing) does the exact same thing. Foundation only does this for visitors at 640x480! Then again, you’ll have to make significant changes to your site’s markup (and existing styles) to use Bootstrap or Foundation.

Can Resizing the Window Force My Page to Use the Mobile Style?

Nope. The media attributes list ‘min-device-width’ and ‘max-device-width’ instead of ‘min-width’ and ‘max-width,’ so resizing the browser window will not change the style. If you want this behavior, use ‘min-width’ instead of ‘min-device-width’ and ‘max-width’ instead of ‘max-device-width’.

Is This Four-Line Guide Perfect?

I’m not an expert in designing interfaces for mobile devices, so no. Use those four lines of information at your own risk!