Home Blog Page 1782

Humanitarian Toolbox to Deliver Open Software for Good Causes

Here at OStatic, we’ve covered open source software aimed at humanitarian causes before, including tools from called InSTEDD (Innovative Support to Emergencies, Diseases and Disasters). Now, a very interesting new startup called Humanitarian Toolbox has appeared, and is focused on open source tools for humanitarian causes. Team mebers from NetHope, CrisisCommons and GeeksWithoutBounds have announced, in partnership with Microsoft and DotNetRocks the launch of the new company.

The Humanitarian Toolbox is characterized as an initiative to “help bring the expertise and good will of the software development community to the humanitarian world.” According to the announcement:

 

Read more at Ostatic

Development Release: Fedora 20 Alpha

Kevin Fenzi has announced that the delayed alpha release of Fedora 20 is now ready for testing – complete with Linux kernel 3.11, GNOME 3.10, KDE 4.11, ARM as a primary architecture, NetworkManager improvements and many other goodies: “The Fedora 20 “Heisenbug” alpha release has arrived with a….

Read more at DistroWatch

Android App Development for Beginners: Layout and UI Options, Part Two

Following on from last month’s tutorial on the basics of layout, and in particular LinearLayout, in this tutorial we’ll look at RelativeLayout, and at how you can reuse layouts easily with theinclude directive. Getting a firm grip on how Android layout works is a big help towards making your beginner app into something that looks good and has great UI. Check out last month’s tutorial for the basics of XML and resource management if there’s anything here you don’t recognize. We’ll reuse the basic code structure from that tutorial. (See Android App Development for Beginners: Layout and UI Options, Part One.)

RelativeLayout

With LinearLayout, you can only display your various elements stacked next to each other or one above the other (although you can nest LinearLayouts to do both of these in the same layout). RelativeLayout is much more flexible, allowing you to specify the position of each child element relative to its parent or to another named element. One of the big advantages to using RelativeLayout over nested LinearLayouts is that nested view groups have a performance impact. If you can translate your nested LinearLayout into a single RelativeLayout, it’s almost always a good idea to do so.

First up, let’s replace our nested LinearLayout from the last tutorial with a single RelativeLayout. What we want is a TextView, an EditText below it, and two buttons below that. Using the same Activity as for the last tutorial, create a file activity_relativelayout.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    
    <TextView
        android:id="@+id/helloTextView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:text="@string/hello" />
    
    <EditText
       android:id="@+id/nameEditText"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/helloTextView"
        android:hint="@string/name" />
    
    <Button
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:layout_below="@id/nameEditText"
        android:layout_alignParentLeft="true"
        android:text="@string/setName" />
    <Button
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:layout_below="@id/nameEditText"
        android:layout_alignParentRight="true"
        android:text="@string/clearName" />
</RelativeLayout>

You’ll also need to change the layout reference in LayoutTestActivity to our new layout file:

public class LayoutTestActivity extends Activity {
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_relativelayout);
  }
}

Run this, and you should see a layout like the image below.

android relativelayout 1

All the elements have height “wrap content”, so they’re just as tall as their content. The buttons have a specific width (which you can play around with it to find out what looks good).

The important new layout attributes are layout_alignParentToplayout_alignParentRightlayout_alignParentLeft, and layout_below. The names make it fairly clear what they do: these are the layout attributes that allow you to describe the alignment of elements relative to other elements. The ‘parent’ element here is the RelativeLayout itself; all other elements in this layout are its children. The layout_below (or layout_above, etc) attribute allows you to specify a layout relative to another named child element. There are a stack of more options available, too — check out the the RelativeLayout.LayoutParams API to see them all.

Centring and distributing elements

You’ll notice that the TextView above isn’t centered. To center it, you have two options. The first is to make the element fill the parent, then center the text within the element:

<TextView
        android:layout_width="fill_parent"
        android:gravity="center" />

The second is to make the element a specific size (here, wrapping its content), then center the whole element within its parent:

<TextView
        android:layout_width="wrap_content"
        android:layout_centerHorizontal="true" />

You may need to combine these if you want an element to have a specific width that is wider than its content, but also want to center the element within its parent.

android relativelayout

You can’t use the weight property (which we used in the last tutorial) in a RelativeLayout. This means that you can’t spread your elements across the whole parent container by allocating them a weight. Instead, if you want to spread your elements out, you’ll need to specify a width/height in dp. If using weight is important for your layout, you’ll need to use a LinearLayout.

Aligning edges

Here’s another way of laying out the elements to produce the same effect:

<TextView
  android:id="@+id/helloTextView"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_centerHorizontal="true"
  android:layout_alignParentStart="true"
  android:text="@string/hello" />
    
<EditText
  android:id="@+id/nameEditText"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:layout_below="@id/helloTextView"
  android:hint="@string/name" />
    
<Button
  android:id="@+id/setNameButton"
  android:layout_width="150dp"
  android:layout_height="wrap_content"
  android:layout_below="@id/nameEditText"
  android:layout_toEndOf="@id/nameEditText"
  android:text="@string/setName" />
<Button
  android:layout_width="150dp"
  android:layout_height="wrap_content"
  android:layout_below="@id/nameEditText"
  android:layout_toRightOf="@id/setNameButton"
  android:text="@string/clearName" />

Attributes that look like layout_toEndOf align the start edge of that element to the end edge of the referenced element. (layout_toStartOf aligns the element’s end edge to the start edge of the referenced element). Check the API docs for specific details of which edge aligns to which. This layout will look much like the previous layout, but the buttons are slightly to the left of center. This is because the second button is arranged to the right of the first button, rather than aligned with the parent’s right edge as it was before. You can play around with adding padding or a margin to see how that affects the position, too.

android relativelayout

If you remove the layout_below line from the two buttons, you’ll get them overlaid on the previous element. This is because the edges will be aligned, but without moving them down underneath the reference element. 

android relativelayout 4

Try out the various layout options to get a feel for how they work with one another. The full list of parameters is available at the RelativeLayout.LayoutParams API reference page.

Reusing layouts

Finally, a quick note that you can reuse layouts by using the include tag. Let’s say we want to reuse the RelativeLayout above. It must look exactly as you want to use it wherever you’re about to include it. Now let’s set up a LinearLayout (include_layout_test.xml) to drop it into:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    
    <TextView
        android:id="@+id/helloTextView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:layout_alignParentStart="true"
        android:text="@string/includetest" />
    
    <include layout="@layout/activity_relativelayout" />
</LinearLayout>

As you can see in the screenshot, this does exactly what you want it to, including the RelativeLayout underneath the TextView.

android relativelayout 5

Being able to reuse XML layouts like this has obvious advantages in terms of making a consistent (and maintainably consistent) look and feel across your app. Set up your repeatedly used text bar or button group in its own XML file, and include it wherever you want it to appear.

For more Android app development tutorials in this series see:

Android App Development for Beginners: Layout and UI Options, Part One

Android App Development: Handling Extra Camera Capabilities

Android App Development: How to Capture Video

Announcing Apache CloudStack CloudMonkey 5.0.0!

The Apache CloudStack project is pleased to announce the immediate availability of the Apache CloudStack CloudMonkey 5.0.0 release.

Apache CloudStack’s CloudMonkey is a Python-based command line utility for interacting with Apache CloudStack IaaS clouds. The software provides an interactive shell environment that includes command discovery, auto-completion and multiple output formats. CloudMonkey can also be used as a simple command line utility, which can be easily integrated into larger shell scripts.

 

Advancements Continue Around Wayland, GNOME

Red Hat’s Christian Schaller has shared some more information about improvements happening in the GNOME/Fedora Wayland world…

Read more at Phoronix

ZTE to Bring Second Wave of Firefox OS Phones to U.S.

ZTE plans on launching another phone running Mozilla’s Firefox OS, this time with a dual-core processor, a bigger screen, and a revamped user experience, a company executive said on Tuesday.

Read more at ComputerWorld

Google’s Native Client Dilemma: A Fast but Fragmented Web?

The powerful new Google+ photos app embodies a sticky situation facing Web developers: Embracing Google’s NaCl tech for high-performance Web apps risks sites that only work for Chrome users. [Read more]

Read more at CNET News

Distribution Release: GParted Live 0.16.2-1b

Curtis Gedak has announced the availability of a new stable version of GParted Live, a Debian-based live CD with specialist tools designed for disk management and data rescue tasks: “The GParted team is proud to announce a new stable release of GParted Live. This release includes a number….

Read more at DistroWatch

NVIDIA to Provide Documentation for Nouveau

Nouveau is the reverse-engineered driver for NVIDIA GPUs; it has been developed for a number of years with no assistance from NVIDIA. Now, though, an NVIDIA developer has surfaced on the Nouveau list with an offer to help: “NVIDIA is releasing public documentation on certain aspects of our GPUs, with the intent to address areas that impact the out-of-the-box usability of NVIDIA GPUs with Nouveau. We intend to provide more documentation over time, and guidance in additional areas as we are able.” This would appear to be a big step in the right direction.

Read more at LWN

Kernel Prepatch 3.12-rc2

The second 3.12 kernel prepatch is out. Linus said: “Things have been fairly quiet, probably because lots of people were traveling for LinuxCon and Linux Plumbers conference last week. So nothing very exciting stands out. It’s mainly driver updates/fixes (gpu drivers stand out, but there’s networking too, and smaller stuff all over). Apart from drivers there’s arch updates (tile/arm/mips) and some filesystem noise (mainly btrfs).

Read more at LWN