Skip to content

Instantly share code, notes, and snippets.

View DavidTPate's full-sized avatar

David Pate DavidTPate

  • Denver
View GitHub Profile
private void deinitialize() {
stopPreview();
releaseCamera();
Log.d(TAG, "Camera Initialization has Been Undone");
}
private void initialize() {
if (hasCamera(this) && getCameraInstance() != null) {
startPreview();
Log.d(TAG, "Camera Initialization has Been Completed");
@DavidTPate
DavidTPate / themes.xml
Created April 25, 2013 19:21
Updated themes.xml for AndroidMenuDrawer sample to reduce overdraw and set the window background to null.
<resources>
<style name="SampleBase" parent="@android:style/Theme.Light" />
<style name="SampleTheme" parent="SampleBase">
<item name="android:windowBackground">@null</item>
<item name="menuDrawerStyle">@style/MenuDrawerStyle</item>
</style>
<style name="SampleTheme.RightDrawer" parent="SampleBase">
@DavidTPate
DavidTPate / Car-Telescoping.java
Created February 16, 2014 21:47
An example of the Telescoping Constructor Anti-Pattern
public class Car {
int year;
String make;
String model;
String carType;
public Car(int year) {
this.year = year;
}
@DavidTPate
DavidTPate / Car-Builder.java
Created February 16, 2014 22:24
An example of the Builder Pattern in Java for a simple car class.
public class Car {
int year;
String make;
String model;
String carType;
public static class Builder {
int year;
String make;
String model;
Car carSearchCriteria = new Car(1998, null, "Focus", "Sedan");
// Using the Telescoping Constructor anti-pattern
Car carSearchCriteria = new Car(1998, null, "Focus", "Sedan");
// Using the Builder Pattern
Car carSearchCriteria = new Car.Builder().year(1998)
.model("Focus")
.carType("Sedan")
.build();
public class LazySingleton {
private static LazySingleton instance = null;
private LazySingleton() { }
public static synchronized LazySingleton getInstance() {
if (instance == null) {
instance = new LazySingleton();
}
return instance;
public class EagerSingleton {
private static final EagerSingleton instance = new EagerSingleton();
private EagerSingleton() { }
public static EagerSingleton getInstance() {
return instance;
}
}
public class EagerStaticSingleton {
private static EagerStaticSingleton instance = null;
private EagerStaticSingleton() { }
static {
try {
instance = new EagerStaticSingleton();
} catch (Exception e) {
// Do something
public class OnDemandSingleton {
private OnDemandSingleton() { }
private static class OnDemandSingletonHolder {
public static final OnDemandSingleton instance = new OnDemandSingleton();
}
public static OnDemandSingleton getInstance() {
return OnDemandSingletonHolder.instance;
}