Skip to content

Instantly share code, notes, and snippets.

Alex Lockwood alexjlockwood

Block or report user

Report or block alexjlockwood

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View SingletonDatabase.java
/**
* 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;
View SingletonDatabase.java
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
newInstance() fragment instantiation #2
View MyFragment.java
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
newInstance fragment instantiation #1
View Singleton.java
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() { }
View SampleActivity.java
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";
View CompatabilityManager.java
public class CompatibilityUtil {
/**
* Get the current Android API level.
*/
public static int getSdkVersion() {
return Build.VERSION.SDK_INT;
}
/**
View AbstractStorageDirFactory.java
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
View BaseAlbumDirFactory.java
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
View FroyoAlbumDirFactory.java
public class FroyoAlbumDirFactory extends AlbumStorageDirFactory {
@Override
public File getAlbumStorageDir(String albumName) {
return new File(
Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES
),
albumName
);
View SampleActivity.java
public class SampleActivity extends Activity {
private AlbumStorageDirFactory mAlbumFactory;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/* Implementation not shown */
You can’t perform that action at this time.