Using Sherlock Actionbar to change tabs with a List Navigation in the Actionbar in Android, or switch between Activities with a List in the Actionbar.

Long title, I know.

So you have a TabHost and a TabWidget. You also are implementing Actionbars to give your app a more mobile-feel and interaction to it, so actual tabs aren’t that neat. However, tabs offer switching between Activities in a easy way, that works for you, or whatever your reasoning is.

So, you have the Actionbar up top, and you want to implement it so that the user doesn’t switch via tabs, but rather via a list. If you’re here, you probably know what I’m talking about. If not, then it’s a dropdown list that on item selected, it displays a new activity in the area below the Actionbar. I think I just repeated the same thing three or four times.

Anywys, I had a TabHost with a TabWidget and what not, all working fine. Looked okay, just it didn’t flow with the gameplay view. So I set out to change this menu to use an Actionbar and list.

Problem being, SherlockActivity extended Activity, and not ActivityGroup, which as some may know, is the known way to have the whole tab shebang working. So the problem arises that, if you change your Menu that did extend ActivityGroup to the SherlockActivity, you have TabHost.setup(LocalActivityManager). This problem is easily solved by a Google that you use:

		th = (TabHost) findViewById(R.id.thMain);
		LocalActivityManager mLocalActivityManager = new LocalActivityManager(
				this, false);
		mLocalActivityManager.dispatchCreate(savedInstanceState);
		th.setup(mLocalActivityManager);

In the onCreate with savedInstanceState being the Bundle that you pass it.

So no big deal so far. This works perfectly fine really. Then you add in the needed List requirements from Sherlock:

		Context context = getSupportActionBar().getThemedContext();
		ArrayAdapter<CharSequence> list = ArrayAdapter.createFromResource(
				context, R.array.mainmenu, R.layout.sherlock_spinner_item);
		list.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);

		getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
		getSupportActionBar().setListNavigationCallbacks(list, this);

R.array.mainmenu is in my XML file in res/values/array.xml. You can Google this as well.

Finally, in the method you implement from the interface: ActionBar.OnNavigationListener, onNavigationItemSelected(int itemPosition, long itemId), you can do a simple:

		if (itemPosition < th.getTabWidget().getTabCount()) {
			th.setCurrentTab(itemPosition);
			return true;
		}
		return false;

So really, pretty easy. Nothing too big, it’s useful as it allows you to switch between Activities with a List, also though, without using Fragments (Which I assume is the “correct” way to do this), or to have custom Views and what not that you change between.

Also, if you want that dirt Tab bar to disappear you want to add to the XML of the TabWidget:

            android:visibility="gone" 

Android: Grabbing pixel xy coordinates when image has been scaled or translated via Matrix.

So you have a view, that has an image.  You move around this image, scaling/translate the matrix to give the effect (I was using a view someone else created: https://github.com/MikeOrtiz/TouchImageView, gives a Map View that you create an image of, in a rough way of explaining it).

His code uses a matrix to alter the image to allow you to move around the screen.  This changes your coordinates, as you probably know because you’re looking at this.

So, the fix is easy, and just takes a bit of thinking, but it was still a pain to figure it out, and I couldn’t find any sources online about it, so I’ll put what I figured out below:

 matrix.getValues(m);
 float transX = m[Matrix.MTRANS_X] * -1;
 float transY = m[Matrix.MTRANS_Y] * -1;
 float scaleX = m[Matrix.MSCALE_X];
 float scaleY = m[Matrix.MSCALE_Y];
 lastTouchX = (int) ((event.getX() + transX) / scaleX);
 lastTouchY = (int) ((event.getY() + transY) / scaleY);
 lastTouchX = Math.abs(lastTouchX);
 lastTouchY = Math.abs(lastTouchY);

So, in general, matrix.getValues(m) stores some values you can access from the matrix you’ve been using. In the View I’m using, it has the matrix as a class variable that can be accessed when needed, along with a float matrix, so it worked fine.

Next four lines are just me grabbing some of the values from the matrix, you can look at the android doc here. They’re the constants up top. I multiplied the transX and transY by -1 as it returned a negative value, which I used a positive coordinate system.

Next, we add the translate to the actual MotionEvent’s x/y value. This gives us our total movement with touch, then divide by scale amount. This moves our position in regards to how much we’ve zoomed in and out.

The abs is just a backup, I don’t believe it’s needed, I was testing other things, but just in case, I’ll keep it there.

Putting Android on HP Touchpad

My brother was lucky and bought one of the HP Touchpads when they went real low in price. Recently though, he couldn’t play movies on it, as the codecs didn’t work correctly or the Touchpad didn’t support it (I didn’t see it, just guessing). He asked me to put on Android for him, so this is basically what I did.
1. Downloading all the stuff
2. Some small commands
3. What happened/Extras!

Downloads

I received a “Unable to find device” on Novacom after putting in the command (Shown in step two), so I had to download this.

I also had the SDK downloaded from HP’s Palm site, so you may want to download this first, then download the previous program to duplicate exactly what I did.  Here is the download.

This is the actual CM9 download.

This is the actual Google Apps.

This is ACME.

This is MOBoot.

This is CWM.

Small Commands

So the “Technical” portion.  Basically, on your machine, go to the furthest Novacom folder, mine was here:

C:\Program Files (x86)\HP webOS\SDK\bin\novacomd\x86>

In this folder, put the download above called ACME.  It won’t be executable by you, but it will know what to do when you enter the command in the cmd (Command prompt, I assume on Linux and Mac you’d use Terminal).  Before this command however, you need to do some work on the Touchpad.  Connect the device as you normally would to the computer.  When connected, on the device, it’ll prompt to enable USB mode.  Say yes.  On the computer, go to the devices folder (Via My Computer) and open up the external device.  Make a directory called “cminstall”.  In here, you want to put the CWM and MOBoot download .zip’s in to this folder.

Now, shut down the device.  But when you go to start it up (Be sure it’s connected to the computer still!), you want to hold the volume up button, (The button closest to the powerbutton).  Once this happens, you want to have your command prompt/terminal still in the previously mentioned path, and input this command:

novacom boot mem:// < ACMEInstaller3

This is the “Magic” portion.  Upon completion, unplug.  If the USB logo stays on, you’ll want to hold all three, the volume up button, the home button (The middle guy below the screen), and then the power button.  Hold until it goes away.  Then go on as normal.

Now, if you start up, you’ll notice that you have WebOS working still.  But you also have a small boot menu.

Now to install the CM9.  You downloaded a .zip file, of which, is named a bit oddly.  Rename the CM9 folder to update-cm.zip.  (I believe it complained about the naming however, so this may change depending on the versions of things, but it tells you on the HP device what to rename it to).  You want to do the same for the Gapps too, rename it to gapps-gb.zip.

Now, run that command above again in the same path, and then it’ll do its thing.  Now you’re done!

Extras

I said their were extras.  I was surprised to see that you can still boot in to WebOS.  So you didn’t lose this functionality, which I think my brother will enjoy.  To do this, you want to hold the power button, click Reboot, then select bootloader, then Ok.  It’ll reboot, and prompt you for selection.  To use this menu, use the volume buttons to scroll, then you use the home button to select an option.

Distributed File System (CEPH), SSHFS, and More

What all has been happening in the past two to three weeks?

1. Change of plan

2. Learning new things

3. Other projects

Plan Changer

So, previously the main goal was to make a service that would track what all happens on your device, data traffic wise. However, a change has been made, temporarily. While this is still the main goal, I’ll be switching gears towards something else (Look at number two). First though, what’s taken me so long. This extends to point three, but also something to address here. Obviously, I’ll be using other machines to work on everything. Because of this, and it being an university ran system, everything isn’t set up how I normally operate, and I’ve been customizing things to fit how I work. So the past week or two has been me getting used to the changes, not only on the system, but also what I’ll be doing in the future. Rather than jump in to the project, I’m trying to plan out how to go about it and have everything worked out before hand, as this (In my opinion), will make the end shorter.

New Things

The new project is distributed file system, which I’m very interested in, and hopefully can sit-in on our distributed system class here at Wright State. The lab I’m working in contains ~30 machines, each machine with 350 gigs of space, not being used, in its own partition. My professor, Dr. Mateti, has requested that I set up these machines to all collaborate together. He’s recommended the program CEPH, which from what I’ve read thus far, seems to be nice, and simple enough to set up. More about that later.

Also, something I found extremely interesting as I’ve wanted to do this, connect a file system to my local machine that handles files on external servers. I knew it was possible, but never looked in to it, nor have I actually done it. Dr. Mateti has this set up from his home and to multiple machines in the building, and we went over SSHFS. Obviously, SSH is secure shell, and FS is file system. This was the most painless configuration I’ve done for a while.

To set up SSHFS, you first want to make a directory on your local system. Then you run a command similiar to such:

sshfs -o idmap=user remoteUserName@remoteIPOrServer:/your/remote/directory $HOME/YourLocalDirectory

You want to change anything bolded. Once done, go in to the directory, type mount, then enter information requested, and you’re set. Honestly, one of the easiest and most useful things I’ve done for a bit of time.

My Projects

I’m currently working on two personal projects. One of which is a simple app that I do in spare time in my room, probably two or three hours a week. Another is working on Fennec, Firefox’s mobile client. I’ll write more about each of these, but a summary for now.

Fennec, I’m doing general bug fixes. This project is very helpful to me for several reasons. First, I’m learning how to effectively use a large code base. While not wasting anyone’s time but my own, I can go through the files, do what I can to make sense of them, and Log.d every couple of lines and see what’s happening. Secondly, I’m seeing how people who program for a living, program. This is surprisingly not common in academics, even though I believe it should be enforced (This, and revision control, whether it be git or Mercurial, etc.). It’s extremely important, in my opinion, to be able to read and understand others code, be able to implement it effectively, and come up with ways to do this. Lastly, I’m working on something that sees the light of day, using technologies that exist and are used everywhere, collaborating (I’m on their IRC 24/7) with others, helping out a public and open-source project, etc. etc. Their really is no “lastly”.

Pic2Griddler is an app that I’m developing. Yet Another Puzzle App, in other words. This is more for my personal use, as I’ve been in to Griddlers for several months now, but I’m not a fan of paying for an app that I’d get a couple weeks out of, then be done. So my solution, make an app that gives me unlimited amount of time to work on. I’ll be posting more in-depth about this later, you can read the README on the GitHub page on the side bar.

Up and Running

Rundown:

1. Easier then I thought.

2. Personal Updates

Easy

As of now, this was not difficult at all.  Booting up and finished boot.  To be honest, this wasn’t difficult. I’m not saying there were not problems, because as always, there were.  But it went smooth.  As in…  I did it in about two hours Monday.

So some tips for future/others.

Most important command:

make mrproper

Now, this lil’ bit of command cleans up your mistakes.  You will make mistakes.  Luckily, this command also takes about 10 seconds to run.  So no big deal.  This saved me countless of times and lots of time.  I am pretty thorough with my work, so I like to make sure everything is at least some-what back to the start/normalized.  I don’t like having a chance that what I did won’t be reproducible because one file was where it wasn’t normally because of a previous mistake.  So I highly recommend and love this snippet of a command.

Beyond that, I found it most difficult of what commands to run.  Going off memory, I believe it was along the lines of:

ARCH=arm SUBARCH=arm CROSS_COMPILE=arm-eabi make goldfish_defconfig

This allows you to set the variables temporarily, makes the config file, then you can run a normal “make”.
That’s really all you need to do after you download the goldfish kernel and you’re golden ;).
Personal Changes

So, my own development machine has changed a lot.  Previously, I had a rule about not working on my own machine, but downloading the Android source takes about 12 hours, building takes more hours, and the kernel takes about as long, so I’d be lucky if someone didn’t turn off the computer in a local lab while this went on.  So that rule, for the time being, is scrapped.  But I’ve also noticed, everyone uses Linux.  I have nothing against Linux, I think it’s great, and to be honest (After using it for a weekend), I’ll be happy about it (Besides the no Spotify support, that irks me, and no, Wine does not count as I get pop up overlays and those are annoying too).  But I don’t mean everyone uses Linux as in, everyone should use it, or that if you don’t use it, it’s bad.  I just mean, every documentation is built off the idea that the end user is using Linux.  Further, if you have a problem?  Guess what, their is a solution.  I remember back in middle school when I first installed Linux, finding solutions was…  awkward.  Every solution wasn’t much of a solution as it was an idea towards a possible solution, which combined with me being about thirteen (Is that middle school?), heck if I could put two and two together in a terminal, I didn’t even know about man pages!

So, no more tangent, I now am running Linux.  Ubuntu 12 (I don’t like it, but again, many projects are geared towards Ubuntu, also lots of support) is now my primary OS, but I still have Windows 7 for now, in case I need to recover something.  I’ll give a list of my favorite command line and other utilities on Ubuntu, but I already have several that keep me sane.

Also, I’m an Emacs user.  I do use Eclipse for personal projects, but for most of my programming, I’ll be trying to use Emacs.  How bad it has gotten?  I’ve done the cut/paste command in a web browser…  Ctrl – W is close tab for most browsers, so that got old fast.  This was a goal of mine sense school started though, and as of now, I love Emacs, and I know I don’t even know half of it.

Back to programming though!  I have built and got Jelly Bean working on this new machine all in one swoop.  No problems.  Same goes with the Goldfish kernel, also, no problem.  Further, I’m trying to pick up Open Source.  I’ll give another update of that when I actually complete something though.

I’ll be meeting with Dr. Mateti to discuss what to do next tomorrow.  Until then… Yeah!

Hold It – Problems

To keep everything short (I had a lot of problems from the build last time, and this is just what I’ve found thus far), to sum.

  1. You need 64 bit version of Linux, and not 32 bit.
  2. Virtual machines require a BIOS setting to run 64 bit (Part of number 1).
  3. On a virtual machine, memory is limited.  Therefore, it won’t build correctly all the time.
  4. Mint vs Ubuntu? Which to use?
  5. What do I do when it’s all downloaded and built?
  6. envsetup.sh, important, but when?
  7. I have it downloaded, I can see the img files, but it still complains when I do this.

64 bit != 32 bit

I received the following error:

/bin/bash: prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.6/bin/arm-linux-androideabi-gcc: cannot execute binary file

So  basically, you need to use 64 bit for Jelly Bean.  And also, from what I’ve read (Not a lot, so not positive on this), also Ice Cream requires 64 bit to build also.

Virtual with 64 bit

My error:

VT-x/AMD-V hardware acceleration has been enabled, but is not operational. Your 64-bit guest will fail to detect a 64-bit CPU and will not be able to boot.

Please ensure that you have enabled VT-x/AMD-V properly in the BIOS of your host computer.

Note, I do use Virtual Box, and this was a simple solution (Even though it requires a computer restart, which those who know me know I hate restarting my computer).  Basically go in to BIOS, go to advanced, and enable the Virtualization.

-j4 Is Okay, Not Too Much

So, I was under the impression that the number you put after the 4 didn’t mean much.  However, I was wrong; wrong wrong wrong.  So basically, when I tried to build/make from source with -j4, it would conflict, or otherwise, not build a system.img (It did do the ramdisk.img and userdata.img).  So, I read a bit online, and it seemed that not many people had this problem.  I did however see someone mention that one of the errors that I came across often (When I built, I would do:

make -j# 2> ERROR_LOG.txt

so I’d get all my errors that occured and I can check on it later on rather than trying to catch glimpses in the hundred thousand lines or so) was caused by not having enough RAM.  More significantly, someone wasn’t able to successfully build Android with -j4 on a machine with two gigs of RAM.  Surprise surprise, I gave my virtual two gigs of RAM.  So I changed this to -j1, and it finished, and from here, I saw that my img files were created.

Mint or Ubuntu

This isn’t about what’s better.  As you might have read previously, I decided to use Mint.  Why? It’s less bloated, it has more dependencies at the start (I understand this is a bit contradictory as bloated == more dependencies, but just ignore this flaw), and in my opinion, works better.  However, after reading a lot of posts, everyone built the source using Ubuntu, so I decided to deal with the Unity bar and everything else that’s not needed, and use it.  The reason I mention this, it could have been a factor in why it wasn’t working.

Now What?

So now the source was good, I have my .img’s, and everything is going all well and dandy.  Hard to actually find much on what to do once you’re done, and a likely reason, if we look at the pages, we see three lines on starting the emulator, of which, only one word in those lines is what you really need, emulator.

I start up my emulator (But I can’t, look at next section for that), and I get an error, surprise.

emulator: ERROR: You did not specify a virtual device name, and the system
directory could not be found.

If you are an Android SDK user, please use '@<name>' or '-avd <name>'
to start a given virtual device (see -help-avd for details).

Otherwise, follow the instructions in -help-disk-images to start the emulator

So, can’t be that easy.  I look around, and see that I need to specify the .img files.  So I try it:

out/host/linux-x86/bin/emulator -sysdir out/target/product/generic/ -system out/target/product/generic/system.img -ramdisk out/target/product/generic/ramdisk.img -data out/target/product/generic/userdata.img -kernel prebuilt/android-arm/kernel/kernel-qemu -sdcard sdcard.img -skindir sdk/emulator/skins -skin WVGA800 -scale 0.7 -memory 512 -partition-size 1024

And my kernel doesn’t work, it’s not there, doesn’t exist.  So I decide to build it separately, but first…

Envsetup

So, I feel this file is a bit misunderstood.  In that, I run it at the begining of the build, then I do the make, and all good.  I then do ./emulator, doesn’t work.  Doesn’t exist.  Then I have to rerun the envsetup line:

source build/envsetup.sh


Now it works, good.  So remember, do this before and after!  Also, a possible problem.  If you have the SDK downloaded and set up, when doing ./emulator, it could be running the SDK, and NOT the built version.  I didn't have this problem, but thought of it while working.

Still Complaining – Kernel Panic

So, finally, the kernel.  It won’t work. I don’t know why.  I just want to do my weekly posts.  Also, I have some ideas:

  1. Build it seprately
  2. Try a pre-made kernel
  3. Build Generic
  4. Build Goldfish
  5. Re-make whole thing from scratch using -j1

And Alas I Am Done

So that’s it for now.  Outside of this project, I’ve gotten some done with my other project.  I’ll hopefully have something to show for it in two weeks.  Going to be a busy weekend, so might not be able to work on my side projects too much.

Downloading and Building Jelly Bean

Obviously the first step to my assignment was to download and build Jelly Bean.

Problems

1.  Permissions on certain machines.

2. Which lead to a problem with Java 1.7 is installed, and you need 1.6 in order to build and run the make.

3.  The time it takes for everything to download is slow.  I mean, it took 10+ hours and multiple repo sync’s.

Permissions on Machines

Obviously the school wouldn’t give me admin rights on the computers, however, I just needed to run (I believe) only one command and I could have finished up the make process on their machines.  The problem is, I couldn’t actually run “sudo update-alternatives –config java” to change from 1.7 to 1.6 (More on that later).  Further, a lot of what I did do up until the actual download (That went surprisingly smoothly on the machine in the lab) seemed a bit backwards because I had to find workarounds between security setings.  By the end after about three hours, I gave up on figuring out the Java problem and decided I’d try it all on a virtual the next day and see if I could get it to work on my own machine.

I ended up using Linux Mint as it’s based on Ubuntu, has more of the programs needed (Except for I found two specifically [bison and flex] and decided to just run their Ubuntu 12.04 lines:

sudo apt-get install git-core gnupg flex bison gperf build-essential \
  zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev \
  libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 \
  libgl1-mesa-dev g++-multilib mingw32 openjdk-6-jdk tofrodos \
  python-markdown libxml2-utils xsltproc zlib1g-dev:i386

This worked perfectly fine on my virtual, even without the following linker line, I assume that the machine already had libgl set up, so no biggy.

Anyways, after this (And as I type this out), the build is running with the make.  This brings a smaller problem, as to what number to put after the j in the “make -j#” command.  I personally used 4 as it’s on a virtual and I didn’t want to really slow down my computer.  But regardless, it’s building right now, so good!

Java 1.7 can not be used for the Jelly Bean build, Java 1.6 is needed

So this was an odd problem to me (Makes sense, with some methods being deprecated and from the warning message it actually used Java 1.5, not 1.6, but 1.6 was backwards compatible enough to work), and it is what ultimately made me use a virtual machine rather than doing it in the lab.  The general solution was to just download the binary file, run, and do the update alternatives snippet (See above).  This worked, however a little tip for future reference, you need to actually put the .bin in the /usr/bin and then chmod and execute it there (This allows it to be in your path).  You can then do an update.  However, I highly recomend following this post here by codingchyne. It’s what I followed, worked perfect. After this, it already set up the Java 1.6, so no need for the update alternatives.

Speed

So, this is where I feel a lot of newbies might be a bit surprised, and Dr. Mateti actually warned me about to begin with.  This process takes… Long.  As in, it took my 8-15 hours to actually update the repository.  This is on about a decent connection.  However, in the labs, I was getting a very fast connection (Friday evening, Saturday afternoon), so it only took about an hour there.

Now the build.  As I said earlier, I already started the build.  It’s been going at it for about an hour now, so obviously this is going to take some time.  I use -j4, which means I’m using 4 threads on my PC to build this.  In the lab, I want to try this again using -j32 and see if it really will finish this up in about two hours.  Lastly, Dr. Mateti brought up that he wants the system to allow distributed computing, and I’d love to see how that works and perhaps push this to -j128 or some other amount that would make it build in only minutes.  Maybe later on I can show a graph of speeds to thread numbers.

So what now?

Obviously, the build has to finish, and hopefully without errors.  If it does, then awesome.  If not, then no big deal, I have to talk to Dr. Mateti and see if I can get the Java versions switched so I can do this on there, and that’s where I’ll be doing most of my work.  After this, I believe that I’ll be working on pruning, or as I’m looking it up, kernel work (Which I’m actually really interested in).  This is probably going to take most of my time, and hopefully I can post updates on what I’m doing to the kernel and why.  We’ll see though, the build might not even work, then we’re back at step one!