ActiveAndroid – Dummys Guide to creating a jar


1. You MUST have installed:

2. Go to https://github.com/pardom/ActiveAndroid, and copy https://github.com/pardom/ActiveAndroid.git

Screenshot-pardom-ActiveAndroid · GitHub - Google Chrome

3. Clone to ActiveAndroid git repository:
git-clone-active-android

 

 

4, Change directory to ActiveAndroid and execute ant command (Ant takes in build.xml)

> ant

ant

 

5.  Change directory to dist/ where ActiveAndroid.jar is created!

active-record-dist

 

7. Thats it! ..Now you can import the ActiveAndroid.jar library to use with your Android Project!

 

Advanced Android UI – WheelPicker


Ever wanted Sleek-n-Sexy UI components like Apple’s iPhone/iPad?

Now you can with Android-Wheel – the sexy WheelPicker for Android:
Android-Wheel: http://code.google.com/p/android-wheel/
It comes with a handy ScrollListener for listen to touch events on the wheel component. Yah …..C-A-S-I-N-O!

Download: TestWheel.zip

Some Notes:

  • Sometimes you need to adjust the wheel width..I know I had to do this to prevent text from overflowing ..and the wheels rolling off…I think WheelView.java is where it at!
  • res/drawables – contains the styles/gradients etc.

The Application:

The Code:

import kankan.wheel.widget.ArrayWheelAdapter;
import kankan.wheel.widget.OnWheelChangedListener;
import kankan.wheel.widget.OnWheelScrollListener;
import kankan.wheel.widget.WheelView;
import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;

public class Main extends Activity
	{
		// TODO: Externalize string-array
		String wheelMenu1[] = new String[]{"Right Arm", "Left Arm", "R-Abdomen", "L-Abdomen", "Right Thigh", "Left Thigh"};
		String wheelMenu2[] = new String[]{"Upper", "Middle", "Lower"};
		String wheelMenu3[] = new String[]{"R", "L"};

		// Wheel scrolled flag
		private boolean wheelScrolled = false;

		private TextView text;
		private EditText text1;
		private EditText text2;
		private EditText text3;

		@Override
		public void onCreate(Bundle savedInstanceState)
			{
				super.onCreate(savedInstanceState);
				setContentView(R.layout.empty_layout);

				initWheel1(R.id.p1);
				initWheel2(R.id.p2);
				initWheel3(R.id.p3);

				text1 = (EditText) this.findViewById(R.id.r1);
				text2 = (EditText) this.findViewById(R.id.r2);
				text3 = (EditText) this.findViewById(R.id.r3);
				text = (TextView) this.findViewById(R.id.result);
			}

		// Wheel scrolled listener
		OnWheelScrollListener scrolledListener = new OnWheelScrollListener()
			{
				public void onScrollStarts(WheelView wheel)
					{
						wheelScrolled = true;
					}

				public void onScrollEnds(WheelView wheel)
					{
						wheelScrolled = false;
						updateStatus();
					}
			};

		// Wheel changed listener
		private final OnWheelChangedListener changedListener = new OnWheelChangedListener()
			{
				public void onChanged(WheelView wheel, int oldValue, int newValue)
					{
						if (!wheelScrolled)
							{
								updateStatus();
							}
					}
			};

		/**
		 * Updates entered PIN status
		 */
		private void updateStatus()
			{
				text1.setText(wheelMenu1[getWheel(R.id.p1).getCurrentItem()]);
				text2.setText(wheelMenu2[getWheel(R.id.p2).getCurrentItem()]);
				text3.setText(wheelMenu3[getWheel(R.id.p3).getCurrentItem()]);

				text.setText(wheelMenu1[getWheel(R.id.p1).getCurrentItem()] + " - " + wheelMenu2[getWheel(R.id.p2).getCurrentItem()] + " - " + wheelMenu3[getWheel(R.id.p3).getCurrentItem()]);
			}

		/**
		 * Initializes wheel
		 *
		 * @param id
		 *          the wheel widget Id
		 */

		private void initWheel1(int id)
			{
				WheelView wheel = (WheelView) findViewById(id);
				wheel.setAdapter(new ArrayWheelAdapter(wheelMenu1));
				wheel.setVisibleItems(2);
				wheel.setCurrentItem(0);
				wheel.addChangingListener(changedListener);
				wheel.addScrollingListener(scrolledListener);
			}

		private void initWheel2(int id)
			{
				WheelView wheel = (WheelView) findViewById(id);
				wheel.setAdapter(new ArrayWheelAdapter(wheelMenu2));
				wheel.setVisibleItems(2);
				wheel.setCurrentItem(0);
				wheel.addChangingListener(changedListener);
				wheel.addScrollingListener(scrolledListener);
			}

		private void initWheel3(int id)
			{
				WheelView wheel = (WheelView) findViewById(id);

				wheel.setAdapter(new ArrayWheelAdapter(wheelMenu3));
				wheel.setVisibleItems(2);
				wheel.setCurrentItem(0);
				wheel.addChangingListener(changedListener);
				wheel.addScrollingListener(scrolledListener);
			}

		/**
		 * Returns wheel by Id
		 *
		 * @param id
		 *          the wheel Id
		 * @return the wheel with passed Id
		 */
		private WheelView getWheel(int id)
			{
				return (WheelView) findViewById(id);
			}

		/**
		 * Tests wheel value
		 *
		 * @param id
		 *          the wheel Id
		 * @param value
		 *          the value to test
		 * @return true if wheel value is equal to passed value
		 */
		private int getWheelValue(int id)
			{
				return getWheel(id).getCurrentItem();
			}
	}

Anatomy of an Android Project


Software projects ……mmmh ..have anatomy…yahhhh …sexy!

  • Logical structure imposed due to the organization of code into packages.
  • Structural organization of software code generally is a good practice makes things easier to find, but also maintainable over the long run as the project grows.
  • Most importantly, knowing the project structure helps you track down program errors easilly!

Let’ take a look at the Project Structure generated by Eclipse ADT plug-in from our previous post:

Folder generated:

src/ –  Source folder contains all your Java source code

gen/ – Generated folder contains source code generated by Android/Eclipse.

  • Well it only contains R.java – one of Android’s most important file to perform name lookup/resolution and referencing.
  • R.java is automatically generated by the build system and references your resources.

assets/ – Assets folder contains static files such as html which can be included in your program.

res/ – Resource folder contains your program resource files.

res/drawables/ – Contains image files eg. PNG, JPG etc but also drawables which are specified in XML format

res/layouts/ – Contains XML files to specify your application View layouts

res/values/ – Contains XML files where you can specify static string,text, numeric and other constant values.

Referenced Libraries/ – A folder containing third-party/downloaded JAR libraries which can be used in your Android App.

AndroidManifest.xml – A manifest file where you can specify all you Activities, Permissions, and other configurations.