Skip to content

Instantly share code, notes, and snippets.

@alexjlockwood
alexjlockwood / SingletonDatabase.java
Created May 23, 2012 01:07
Singleton Database #2
/**
* create custom DatabaseHelper class that extends SQLiteOpenHelper
*/
public class DatabaseHelper extends SQLiteOpenHelper {
private static DatabaseHelper mInstance = null;
private static final String DATABASE_NAME = "databaseName";
private static final String DATABASE_TABLE = "tableName";
private static final int DATABASE_VERSION = 1;
@alexjlockwood
alexjlockwood / SingletonDatabase.java
Created May 23, 2012 01:18
Singleton Database #1
public class MainApplication extends Application {
/**
* see NotePad tutorial for an example implementation of DataDbAdapter
*/
private static DataDbAdapter mDbHelper;
/**
* Called when the application is starting, before any other
* application objects have been created. Implementations
@alexjlockwood
alexjlockwood / MyFragment.java
Created May 24, 2012 19:20
newInstance() fragment instantiation #2
public class MyFragment {
/**
* Make the default constructor private to prevent direct
* instantiation. Now all instances of this class must be
* instantiated with a call to newInstance().
*/
private MyFragment() { }
/**
@alexjlockwood
alexjlockwood / Singleton.java
Created May 24, 2012 19:26
newInstance fragment instantiation #1
public static class Singleton {
private static final Singleton instance = null;
/**
* Make the class private to prevent direct instantiation.
* this forces clients to call newInstance(), which will
* ensure the class' Singleton property.
*/
private Singleton() { }
@alexjlockwood
alexjlockwood / SampleActivity.java
Created May 31, 2012 00:00
Simple Debugging #1
public class SampleActivity extends Activity {
/**
* A string constant to use in calls to the "log" methods. Its
* value is often given by the name of the class, as this will
* allow you to easily determine where log methods are coming
* from when you analyze your logcat output.
*/
private static final String TAG = "SampleActivity";
@alexjlockwood
alexjlockwood / CompatabilityManager.java
Created June 1, 2012 23:08
Compatability Manager
public class CompatibilityUtil {
/**
* Get the current Android API level.
*/
public static int getSdkVersion() {
return Build.VERSION.SDK_INT;
}
/**
public abstract class AlbumStorageDirFactory {
/**
* Returns a File object that points to the folder that will store
* the album's pictures.
*/
public abstract File getAlbumStorageDir(String albumName);
/**
* A static factory method that returns a new AlbumStorageDirFactory
public class BaseAlbumDirFactory extends AlbumStorageDirFactory {
/**
* For pre-Froyo devices, we must provide the name of the photo directory
* ourselves. We choose "/dcim/" as it is the widely considered to be the
* standard storage location for digital camera files.
*/
private static final String CAMERA_DIR = "/dcim/";
@Override
public class FroyoAlbumDirFactory extends AlbumStorageDirFactory {
@Override
public File getAlbumStorageDir(String albumName) {
return new File(
Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES
),
albumName
);
public class SampleActivity extends Activity {
private AlbumStorageDirFactory mAlbumFactory;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/* Implementation not shown */