ShareThis

Showing posts with label Android. Show all posts
Showing posts with label Android. Show all posts

Tuesday, April 3, 2012

new racquetball app coming from evonsdesigns




Monday, April 2, 2012

Android: How to Retrieve Shared Preferences Values

To a beginner this may be daunting. But it is a really easy solution!

Example preference activity:

public class FooActivity extends PreferenceActivity {

 @Override
 public void onCreate(Bundle icicle) {
  super.onCreate(icicle);
  addPreferencesFromResource(R.xml.preference);
 }
}

Preference xml file:


Method to access those items: (use in any class necessary)


import android.preference.PreferenceManager;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
// then you use
prefs.getBoolean("keystring", true);

Set your android:key= "" to the key value you want to access later on. That simple! No need for ids on checkbox preferences either (unless you're doing dynamic changes to the settings and need to)


Sunday, April 1, 2012

How to use Dropbox to sync Android Projects


Hello avid android programmers. If you're like me, you have at least two stations that you program on. A laptop and a desktop pc. In the past you've had some trouble getting android applications to sync between your computers and the workspace on dropbox.

Here is the problem: Workspaces are unique to the computer they are on and the location they are at. So having the same workspace usable from TWO pcs causes them to clash (and subsequently breaks your android builds).

The fix: It is actually really simple. All you need to do is retain the original workspaces on each PC. You dont want to sync the workspace on dropbox (unless only one PC uses it.)

From the secondary pc, or both if you prefer, import the project folder into your eclipse workspace. Do not copy the files into your workspace ( we need them to reference the synced files! ).

You should now be able to run the android emulator and app fine without any startup errors on your secondary device!

Cheers,
Joe


Monday, February 6, 2012

DroidSmart Pre-Alpha screenshots

I need a place to store these...They are rough design pics for an app im working on. DroidSmart













Friday, January 13, 2012

Android Expandable lists Java

Multilevel, expandable lists are useful user interface elements and Android does support two-level expandable lists. This fact would not be worth a blog entry if there were no traps using the widget.

Click here to download the example program.

The example program implements a simple, two-level expandable list to display color shade information.



The first thing to note is that our Activity extends android.app.ExpandableListActivity. Otherwise setting up the list is pretty similar to ordinary ListActivity classes. The tricky part is the android.widget.SimpleExpandableListAdapter.

SimpleExpandableListAdapter expListAdapter = 
new SimpleExpandableListAdapter(
 
this,
 
createGroupList(), // groupData describes the first-level entries
 
R.layout.child_row, // Layout for the first-level entries
 new
String[] { "colorName" }, // Key in the groupData maps to display
 
new int[] { R.id.childname }, // Data under "colorName" key goes into this TextView
 createChildList(), // childData describes second-level entries 
R.layout.child_row, // Layout for second-level entries
 
new String[] { "shadeName", "rgb" }, // Keys in childData maps to display
 
new int[] { R.id.childname, R.id.rgb } // Data under the keys above go into these TextViews
 
);


First of all, this adapter requires somewhat complicated (although pretty well-documented) data structures. There are two of them, one describing the first-level group elements, the other describing the second-level string elements.

Here is the first one:
List->Map
Every map describes one first-level group element. The keys in the Map are arbitrary but are specified for SimpleExpandableListAdapter so that it can map the keys in the Map to widget IDs. In our case, the data under key name "colourName" will be set as the value of the TextView with "childname" ID.

The second one is a bit more complicated.
List->List->Map
Every entry in the first List represents a group. Entries in the second List represent entries of the group and each such entry is a Map that describes one child, similarly to the description of groups. In our case, the child Map contains two entries (keys "shadeName" and "rgb") that go to TextViews ("childname" and "rgb").

So far so good. Unfortunately, SimpleExpandableListAdapter has its tricks. First of all, the adapter takes the description of one row from a layout (child_row in our case, located under res/layout/child_row.xml). When the adapter draws the expand button onto the row, it does not consider the content of the row, it simply draws the button over the row. That's the reason child_row.xml defines generous left padding for the first TextView. While this behaviour can be considered just an oddity, the fact that SimpleExpandableListAdapter must be created with identical views for first- and second-level lines is a plain bug that existed at least since m3-rc37a. Having group- and child rows with different styles is a cool and useful feature that is supported by SimpleExpandableListAdapter but does not work.

Replace this fragment:

R.layout.child_row, // Layout for the first-level entries 
new String[] { "colorName" }, // Key in the groupData maps to display
 
new int[] { R.id.childname }, // Data under "colorName" key goes into this TextView
 


with this one:

R.layout.group_row, // Layout for the first-level entries 
new String[] { "colorName" }, // Key in the groupData maps to display
 
new int[] { R.id.groupname }, // Data under "colorName" key goes into this TextView
 


and you will see, how the expandable list gets confused.

Saturday, December 24, 2011

How to find a stolen/lost Android Phone

Check out the android application Plan B.

For download *AFTER* your device has been lost or stolen. You authorize it to download and install to your phone (better hope the battery isn't dead) and it emails its location to your Gmail account.

With over +260,000 downloads, 4.5 star rating from +1000 ratings, this application is the one to go to when you've lost your phone!

Monday, November 21, 2011

[ANDROID] How to tile a background image in Android



For one of the apps I'm working on I wanted to have a nice pixel pattern tiled behind my widgets.
After a little bit of hunting around I found this tutorial, and I thought I'd clean up the lessons within and show you how.

Here's the contents of my main.xml layout file,
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/backrepeat" android:gravity="center_horizontal" ><TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />  </LinearLayout>



which is referenced in code in the standard way like this:

@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);...// (rest of onCreate method continues here..)

Now note this line:
android:background="@drawable/backrepeat"


What's going on there?
.. Glad you asked!

Here's a quick screenshot of the contents of one of my drawable folders in my project:

What is this 
backrepeat.xml?

Well, here's the contents of that file here:
<bitmapxmlns:android="http://schemas.android.com/apk/res/android"android:src="@drawable/scale1"android:tileMode="repeat"android:dither="true" />


Can you see what's going on?
Backrepeat.xml defines an instance of the BitmapDrawable class, and that class references our simple scale1.jpg, located in the drawable-hdpi folder.

Simply by adding the:
<bitmap xmlns:android="http://schemas.android.com/apk/res/android" android:src="@drawable/scale1" android:tileMode="repeat" android:dither="true" />

line in bold, we are able to achieve results such as this:


Easy isn't it?

One thing to keep in mind is that you should have folders drawable-hdpi, drawable-mdpi & drawable-ldpi, you'll need to add this backrepeat.xml file and the relevant images to each of these to allow this functionality in high, medium and low dpi (dots per inch) screen sizes.

Enjoy.