Home Blog Page 1692

Haswell Mini-ITX Boards Get Expansive

Commell unveiled a Linux-friendly Mini-ITX board equipped with 4th Gen Intel Core (Haswell) CPUs, PCIe and SIM slots, and a generous supply of coastline I/O ports. According to Commell, also known as Taiwan Commate Computer Inc., the LV-67M mini-ITX SBC is best suited for gaming, surveillance, medical, defense, transportation, and industrial automation applications. The Mini-ITX […]

Read more at LinuxGizmos

Linux-Based TOR Device Protects IP Identity

Pogoplug announced a $49, Linux-based security device called the Safeplug that taps into the Tor network to hide your IP information when using the web. The Safeplug is a router security peripheral that addresses growing fears about cyber-snooping by anonymizing your web browsing sessions and hiding your identity and physical location. The device protects against […]

Read more at LinuxGizmos

CyanogenMod Rolls Out Encrypted Text Messaging by Default

As we continue to read new revelations about the extent of the government’s spying on citizens, more people are looking into ways to protect their privacy in emails, texts, and phone calls. You could write all your messages with lemon juice on parchment, but given the realities of the modern world, cryptographic encryption provides the best balance between security and convenience.

Unfortunately, encrypting your messages is still really inconvenient. Users who want to protect their privacy must typically go through a lengthy installation process that is probably explained in technical jargon, and then only send messages to people who are using the same protocol.

But what if secure messaging were built into your phone’s underlying…

Continue reading…

Read more at The Verge

SolydXK Hands On: Two Good Linux Distributions with a Solid Base

Two Linux distributions (Xfce and KDE), based on Debian Testing, with LMDE extras.

Behind Samsung’s Push to Rule the World

Details matter. A lot. As Sujin Park, a senior member of Samsung’s design strategy team, put it to me, “Localizing is our strategy.”

It’s a strategy that, over the past few years, has helped Samsung soar to the top of the smartphone world. Unlike its fierce Cupertino, Calif., rival, Samsung wants to be everything for everyone. A bigger screen? You can get it from Samsung. A stylus? Sure. Want a flip phone? No problem.

This is the Samsung Way: Do it all, and do it fast. Really fast, even if you’re following the market Apple created and sometimes, as a jury determined, stealing its ideas. In the year it takes Apple to release a new iPhone, Samsung typically unveils three or four “flagship” products, adding up to several dozens in all. That speed, coupled with its fierce commitment to quality and marketing heft, has lifted this sprawling South Korean empire from niche player status in just half a decade.

Read more at CNET.

Android App Development: How to Create an Options Menu

So far in our Android UI building blocks tutorials we haven’t really looked at menus, but of course they’re an essential part of the user experience of our application. Read on to get started with the first type of Android menu, the options menu.

The Android UI provides three basic menu types:

  1. The options menu is the one that appears when you click the menu button on older Android devices, or via the action bar at the top of the screen in newer ones (post 3.0). The options menu should handle global application actions that make sense for the whole app.
  2. Contextual menus appear when you long-click on an element. Contextual menus should handle element-specific actions. They’re particularly useful in GridView or ListView layouts, where you are showing the user a list of elements.
  3. Pop-up menus display a vertical list of items. These are good for providing options for a second part of a menu command, rather than as a stand-alone menu.

In this tutorial, we’ll look at creating an options menu via XML, and at adding a menu item programmatically. Next month we’ll look at contextual menus for individual items and for batches of items. We’ll use the code from the previous tutorial, on GridView, and add a menu to that.

Options Menu

It’s best practice to define a menu and its items as an XML menu resource, then inflate it in your code. This makes it easier to see the menu structure, it means you can readily create different versions of the menu for different hardware, and it separates visual and behavioural code.

The important parts of the menu XML (for both options and contextual menus) are:

  • <menu> -- a container for menu items (<item> and <group> elements), which must be the root node of the menu XML file.
  • <item> -- a menu item (MenuItem once inflated in the code).
  • <group> -- allows you to categorise <item>s into groups, but isn't itself visible.

Here’s a sample options menu to save under res/menu/main_menu.xml:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:id="@+id/background"
        android:title="@string/background_title"/>
        android:showAsAction="never"
    <item
        android:id="@+id/toast"
        android:title="@string/toast_title"/>
        android:showAsAction="ifRoom"
</menu>

The id attribute will let us refer to this menu item in the code later; and the title attribute is the item’s text title, which will be shown if there is no icon. showAsAction specifies whether the action will be shown by itself in the action bar, or just in the ‘more actions’ menu on the right-hand side of the bar. Here, one action will be shown if there is room, and the other will never be shown. See the docs for more attributes you can set for a menu item.

You’ll also need to add strings to res/values/strings.xml:

<string name="background_title">Change background colour</string>
<string name="toast_title">Show toast message</string>

Once you’ve created the menu, you need to inflate it in the code for it to be shown at runtime. Add this to GridViewTestActivity:

public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main_menu, menu);
    return true;
}

Compile and run, and check out your options menu. This is Android 4.3 so it shows the action bar; in Android 2.3 or lower you would hit the menu button to pull up the options menu, and it would appear at the bottom of the screen.

android menu option

The text used on the action bar isn’t ideal; you’d be better off creating and saving an icon in res/drawable and then adding this attribute to the menu item:

android:icon="@drawable/toast_icon.png"

Handling menu clicks

Currently, nothing happens when the user clicks the menu items. We need to write a method to handle clicks:

public boolean onOptionsItemSelected(MenuItem item) {
  switch (item.getItemId()) {
    case R.id.background:
      changeBackground();
      return true;
    case R.id.toast:
      Toast.makeText(getBaseContext(), R.string.toast_message, 
                     Toast.LENGTH_LONG).show();
      return true;
    default:
      return super.onOptionsItemSelected(item);
  }
}
    
private void changeBackground() {
  gridview.setBackgroundColor(Color.CYAN);
}

All we need is a switch statement, which looks at the item ID to decide what action to do. Note that the default is to pass up to the superclass. This is particularly useful if you want to have some menu items in multiple Activities in a single app. You can write a superclass which just creates a basic menu, and then inherit from that superclass to get those same methods in all your Activities.

Compile and run this, and you’ll be able to see a message or change the background colour. A nice improvement would be to give the user a choice of different background colours.

android menu actions

Adding a menu item in code

Although most of the time it’s best to write your menu items in XML, sometimes you need to be able to add a menu item programmatically — for example, a menu item that shows up only in certain circumstances, or which changes. First, let’s look at changing a menu item based on the day of the week:

public class GridViewTestActivity extends Activity {
  private Menu menu;
  int backgroundColour;
  public boolean onCreateOptionsMenu(Menu menu) {
   	this.menu = menu;
    getMenuInflater().inflate(R.menu.main_menu, menu);
    setBackgroundItem();
    return true;
  }
    
  public boolean onOptionsItemSelected(MenuItem item) {
    // as before
    case R.id.background:
   	  changeBackground(backgroundColour);
      return true;
    // rest as before
  }
    
  private void setBackgroundItem() {
    Calendar cal = Calendar.getInstance();
    int day = cal.get(Calendar.DAY_OF_WEEK);
    if (day == Calendar.SUNDAY) {
      backgroundColour = Color.MAGENTA;
      MenuItem item = menu.findItem(R.id.background);
      item.setTitle("Change background colour to magenta");
    } else {
      backgroundColour = Color.CYAN;
    }
  }
    
  private void changeBackground(int color) {
    gridview.setBackgroundColor(color);
  }
}

Much of this is the same code as before, just refactored a little (we need the menu and the background color as class variables). The main change is insetBackgroundItem(), which checks the day of the week, and if it’s a Sunday, grabs the background color menu item using its ID, and changes the title withitem.setTitle().

android menu dynamic

Adding a whole menu item is also fairly straightforward.

public class GridViewTestActivity extends Activity {
  private static final int NEW_MESSAGE = 0;
  public boolean onCreateOptionsMenu(Menu menu) {
    // add this line:
    addNewItem();
  }
  public boolean onOptionsItemSelected(MenuItem item) {
    	switch (item.getItemId()) {
    // rest of switch statement as before
   	case NEW_MESSAGE:
      Toast.makeText(getBaseContext(), R.string.new_message, 
                     Toast.LENGTH_LONG).show();
    // rest as before
  }
  private void addNewItem() {
    menu.add(0, NEW_MESSAGE,0, R.string.new_message_title);
  }
}   

The first argument to menu.add() is the group ID; we have no groups on this menu so this is zero. The second is the item ID, defined at the top of the class. The third is the order, we use 0 as we don’t care about the order. Finally, we give the title. And that’s our new menu item created. Remember to add a case to onOptionsItemSelected() so that your new menu item is correctly handled.

Compile and run, and you’ll see your new message appear. Note however that although a dynamically added menu item is sometimes correct, you might be better off creating the menu item in XML as with the others, and then using this line:

item.setVisible(false);

to set its visibility based on code conditions, just as we changed the title of the background color menu item in the code.

We’ve covered the basics of options menus; check out next month’s tutorial for more on contextual menus and batch processing of items in a list.

 

LLVM Clang OpenMP 4 Support Nears Reality

It’s taken far longer than most anyone would have estimated, but it looks like things may finally be getting close for the mainlining of OpenMP within the LLVM Clang compiler. The good news is that Intel developers have already been working on OpenMP 4.0 support for Clang…

Read more at Phoronix

Fedora 20 Delayed for Another Week Due to Anaconda

The next release of Fedora, HeisenBug, has been delayed due to a number of showstopper bugs in the installer.

Enlightenment’s Terminal Gets New Features

Terminology, the terminal emulator for the Enlightenment desktop built atop their EFL libraries, is up to version 0.4 and it’s landed heavy with new features…

Read more at Phoronix

GCC Support Arrives For The ARM Cortex-A12

ARM Holdings has published GCC compiler support today for the Cortex-A12 processor…

Read more at Phoronix