Wednesday, August 29, 2012

ActionBarSherlock and ViewPagerIndicator Pattern for Pre-HoneyComb Devices

Download the libraries:

Extract the zip files.  These libraries are packaged with sample codes.  Import these libraries into your Eclipse projects.

Create your new project.  I assume that you are an Eclipse user and not new to android development.  Add these libraries to your project as a library project.  By adding these libraries to your new project, you are telling Android that you are using ActionBarSherlock and ViewPagerIndicator as part of your android project.

To check if libraries are added, go to Project Properties > Android.  It should look like this:

If you encountered an error like this, it's okay don't panic.
This tells that Eclipse detected android-support-v4.jar file in the dependecy list of your project twice but with different SHA-1 hash.  To fix this, just remove the file under <your_projectname>/libs/android-support-v4.jar

Now let's proceed to the fun part... the code.

layout xml.

package com.zipcerio.vpi;

import java.util.ArrayList;
import java.util.List;

import com.actionbarsherlock.view.Menu;
import com.viewpagerindicator.TitlePageIndicator;

import android.os.Bundle;

public class MainActivity extends SherlockFragmentActivity {
 private ViewPager mPager;
 private TitlePageIndicator mIndicator;
 private MainPagerAdapter mAdapter;
 private List mFragments;
 private static final String FRAGMENT1 = Fragment1.class.getName();
 private static final String FRAGMENT2 = Fragment1.class.getName();
 private static final String FRAGMENT3 = Fragment1.class.getName();

 public void onCreate(Bundle savedInstanceState) {
  // add fragments
  mFragments = new ArrayList();
  mFragments.add(Fragment.instantiate(this, FRAGMENT1));
  mFragments.add(Fragment.instantiate(this, FRAGMENT2));
  mFragments.add(Fragment.instantiate(this, FRAGMENT3));
  // adapter
  mAdapter = new MainPagerAdapter(getSupportFragmentManager(), mFragments);
  // pager
  mPager = (ViewPager) findViewById(;
  // indicator
  mIndicator = (TitlePageIndicator) findViewById(;

 public boolean onCreateOptionsMenu(Menu menu) {
  return true;
package com.zipcerio.vpi;

import java.util.List;


public class MainPagerAdapter extends FragmentPagerAdapter {
 private List mFragments;
 private String[] titles = new String[] {"FRAGMENT1", "FRAGMENT2", "FRAGMENT3"};
 private int mCount = titles.length;

 public MainPagerAdapter(FragmentManager fm, List f) {
  mFragments = f;

 public Fragment getItem(int position) {
  return mFragments.get(position);

 public int getCount() {
  return mCount;

 public CharSequence getPageTitle(int position) {
  return titles[position];
package com.zipcerio.vpi;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;


public class Fragment1 extends SherlockFragment {
 private ListView mList;

 public View onCreateView(LayoutInflater inf, ViewGroup grp, Bundle icicle) {
  View v = inf.inflate(R.layout.f_fragment1, grp, false);
  mList = (ListView) v.findViewById(;
  return v;

 public void onActivityCreated(Bundle savedInstanceState) {
  ArrayAdapter adapter = new ArrayAdapter(
    getActivity(), android.R.layout.simple_list_item_1, Cheese.STRINGS);


AndroidManifest file




Finally, this is how it should look like.

See the source code here.

Credit goes to Jake Wharton for these great libraries.

Check CPU Information and Speed

To check CPU information and speed on your Ubuntu or any Linux distro, open the terminal and run this command:

$ cat /proc/cpuinfo

If you have other techniques and ways, please feel free to add it in the comments.

Friday, August 10, 2012

Multiple Workspaces in Eclipse

If you're on the point where all your projects are flooded on your Eclipse package explorer, chances are very difficult to find other library projects when working on a project that references those projects. One way to organize your Eclipse projects is to switch workspaces.  To switch workspaces, go to Eclipse > File > Switch Workspace.

This is a great solution but you will loose all your settings.  Settings like keybindings, code formats, and custom templates are gone.  To set the settings to your new workspace, just copy the folder from your old workspace to your new workspace.

$ cp {old_workspace}/.metadata/.plugins/.org.eclipse.core.runtime/.settings {new_workspace}/

Restart Eclipse.