Home Blog Page 2069

Consort Desktop: A New Fork Of GNOME Classic

The Debian-powered SolusOS Linux distribution has forked GNOME Classic into the Consort Desktop Environment.

While there’s already the MATE Desktop fork of GNOME 2.x plus Cinnamon and other open-source initiatives for those not liking the current taste of upstream GNOME 3.x with its Shell, SolusOS felt the need to bring another alternative…Read more at Phoronix

The openSUSE 12.3 Beta is Out! Time for Pizza…

Beta_pizza_party_istanbul posterAccording to plan, today openSUSE 12.3 Beta sees the light. The beta comes with mostly smallish changes as we’re in serious testing waters now – we hope you’re out there to help us clear the way to the final release! The first RC is already coming on February 7 so this Beta needs a good workout. As is tradition in openSUSE, the Beta will be celebrated with a BetaPizzaParty at the Nuremberg headquarters on Wed 30th of Jan starting 16:00 CET! Read on to find out a bit more about the Parties and Pizzas and what’s new and about the awesome 12.3 Polish Hackaton which is being organized this weekend at the SUSE headquarters!

Hackaton

Coolest things first: to make the release even better, we’ve organized a hackaton in Nuremberg!…Read more at openSUSE News

Android Programming for Beginners: User Menus

In our previous Android coding tutorials (part 1, part 2), you set up your dev environment, built a basic app, and then improved it by adding a menu and a second Activity. In this tutorial we’re going to look at a very handy part of the Android API: ListView, ListActivity, and the associated methods which give you an easy way to show the user a list and then act when they click a list item.

Creating a ListView

A very common pattern in an Android activity is showing a list of items for the user to select from. The Android API provides the ListView and ListActivity classes to help out with this. Carrying on with the Countdown app from previous tutorials, we’ll list a few sample countdown times for the user to select from to set the timer.

If all you want is a List, ListActivity will set your View up for you automatically; no need to write any XML at all. So onCreate()can be very simple:

public class CountdownActivity extends ListActivity {
  public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	
    Integer[] values = new Integer[] { 5, 10, 15, 20, 25, 30, 45, 60 }; 
    ArrayAdapter adapter = 
        new ArrayAdapter(this, android.R.layout.simple_list_item_1, 
                                  values);
    setListAdapter(adapter);
  }
}

CountdownActivity now extends ListActivity. ListActivity does a lot of the preparation work for you, so to show a list, you just need to create an array of values to show, hook it up to an ArrayAdapter, and set the ArrayAdapter as the ListActivity’s ListAdapter. The ArrayAdapter has three parameters:

  1. The current context (this);
  2. The layout resource defining how each array element should be displayed;
  3. The array itself (values).

For the layout resource, we’re use a standard Android resource, android.R.layout.simple_list_item_1. But you could create your own, or use another of the standard layout items (of which more later). You can also take a look at the XML of the standard resources.

The problem with this layout is that it only shows a list. We want to be able to see the countdown and the start button as well. This means setting up our own XML layout, rather than relying on ListActivity to generate its own layout. Add this to your XML, below the TextView and the Button:

<ListView
          android:id="@android:id/list"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" 
          android:layout_below="@+id/startbutton" />

It’s important that the ListView should have the ID @android:id/list. This is what enables the ListActivity to do its magic without you explicitly setting up the List.

android 3 listchoice

Now go back to CountdownActivity.onCreate(), and put your previous display and button setup code back in, after the ListView setup:

public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
		
  Integer[] values .... etc ...
  [ ... ]
  setListAdapter(adapter);
  setContentView(R.layout.activity_main);
  countdownDisplay = (TextView) findViewById(R.id.time_display_box);
  Button startButton = (Button) findViewById(R.id.startbutton);
  [ .... etc .... ]
}

Again, it’s important that you set up the ListView first, before setContentView(), or it won’t work properly. Recompile and run, and you’ll see the list appear below the text and button. What you won’t see, though, is anything happening when you click the list elements. The next section will tackle that problem.

One final note: you can also set up an empty element in the layout, which will display if and only if the ListView is empty. Add this to your XML:

<TextView 
       android:id="@android:id/empty" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerHorizontal="true" 
       android:layout_below="@+id/startbutton" 
       android:text="@string/empty_list" /> 

(You’ll need to set up the string value in res/values/strings.xml, too). Now replace the array declaration line in CountdownActivity.onCreate()with this one:

Integer[] values = new Integer[] { };

Compile and run, and you’ll see the empty text displayed, and no list. Put the array declaration back how it was, compile and run again, and the list shows, but no text. In our app this isn’t particularly useful, but if you were populating the array from elsewhere in your code, it’s a neat trick to have available.

Clicking on List elements

Now we have the List set up, we need to make it do something when you click on a list element. Specifically, it should set the countdown seconds to the new value, and change the display. Happily, Android has a straightforward API for this, too:

ListView list = getListView();
list.setOnItemClickListener(new OnItemClickListener() {
  public void onItemClick(AdapterView<?> parent, View view, int position, 
                          long id ) {
    countdownSeconds = (Integer) getListAdapter().getItem(position);
   	countdownDisplay.setText(Long.toString(countdownSeconds));
  }
});

This is all pretty self-explanatory! We grab the ListView, set its OnItemClickListener, and create an onItemClick() method for the Listener. As you can see here, onItemClick()has access to the position in the List of the item you clicked on. So we can grab the ListAdapter, get the item from that position, and then cast the value to an Integer. Save and run, and you have a list of values to set your timer.

Changing the List’s appearance

Earlier, we mentioned the other standard layouts available. If you switch simple_list_item_1 to simple_list_item_single_choice, and rerun your code, you’ll see that you get a selection indicator next to your list items. However, when you click it, the countdown value changes, but the selection indicator doesn’t do anything. To make this work, you need to change your ListView, too. Add this attribute in your XML:

<ListView .... 
          android:choiceMode="singleChoice" 
... >

Run it again, and the selection indicator does its job. If you were using a ListActivity without an XML file, you could do this with a line of code in your app:

getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE); 

Conclusion

There are lots of situations in apps where you might want to show the user a list. ListView and ListActivity make that very easy, and as shown just above, there are plenty of ways to improve the UI experience. You could also look at providing a context menu (in these tutorials we’ve only used the options menu so far) when the user long-clicks on a list item. Or you could look at some form of back-end data storage, and allow the user to add and edit their own list items, so they have a list of countdown times that they regularly use. As ever, keep playing with the code and see where it takes you!

For more Android programming training resources, please visit the Linux training website.

Samba conference will celebrate the release of Samba 4

SambaXP logoThe twelfth annual SambaXP conference is taking place in Göttingen, Germany from 14 to 17 May. The Call for Papers for the conference, which is mainly focused on topics relating to Samba 4, is now open…Read more at The H

NVIDIA Still Working On PRIME/DMA-BUF Contribution

Aaron Plattner at NVIDIA is still working on the open-source “PRIME Helpers” patches for the Linux kernel. This is work towards ultimately better handling PRIME/DMA-BUF for NVIDIA Optimus Technology on Linux…

Read more at Phoronix

How to install the MATE and Cinnamon desktops on Fedora 18

Fedora 18 was released today, and among the promised new features are alternatives to the GNOME desktop in the form of MATE and Cinnamon. Fedora users who dislike the latest versions of GNOME may be disappointed to learn that it’s still the only desktop environment that is installed by default—MATE and Cinnamon have to be installed separately.

These alternative desktop environments could already be installed through the command line on Fedora 17. Promising support for both MATE and Cinnamon in official release notes and press announcements might have led some to hope that the interfaces would be included right up front. But with the full install DVDs going up to 4.4GB and MATE alone adding another 104MB, Fedora maintainers decided not to bulk up that download any further.

Thus, you still have to do some extra work to get an alternative to GNOME. Here’s how to do it…Read more at Ars Technica

Long-delayed Fedora Linux 18 arrives at last

‘Spherical Cow’ brings updates for desktop, cloud, and more

The latest version of the popular Fedora Linux distribution has finally been released, just one week later than the already-delayed ship date that was announced in November.…

Read more at The Register

New ‘Aaron’s Law’ aims to alter controversial computer fraud law

Silicon Valley congresswoman wants to change a 1984 law that was used to prosecute Internet activist Aaron Swartz, who committed suicide last week…Read more at CNET News

Recent Linux Happenings: Elive, Fedora 18, Slax

I’ve been out of commission for a few days and there have been several exciting Linux happenilinuxng in that time. Elive is discovered to be still alive, and I’m not the only one who thinks it is looking great. Fedora 18 is actually released and Slax got a couple more updates.

Elive 2.1.23 (Unstable)

It was quite exciting news to discover that Elive was still in development. Although no disbanding news had leaked out of the project, it’d been a while since the last release. This lead some to wonder if they’d ever release again. Well, wonder no more. Elive is alive and with the focus on E17, it’s looking better than ever. I took Elive 2.1.23 for a little spin yesterday and it is impressively fast and responsive. And with the new E17, it is looking…Read more at Ostatic

Skytap unveils templates that simplify adoption of Hadoop

HadoopTo simplify the roll-out of clusters for big data applications, Skytap is now offering pre-configured Cloudera Hadoop templates that can run in the company’s public cloud. There is a growing interest in big data using Hadoop, but to even start learning, experimenting and developing proof-of-concepts requires a lot of up-front investment in hardware, and it is also fairly complicated to download and configure, according to Brett Goodwin, vice president of marketing and business development. Skytap wants to address that with the introduction of its pre-configured templates, and allow enterprises…Read more at ComputerWorld