Skip to content

Instantly share code, notes, and snippets.

View gist:a8245f3336939fb524fa
/**
* Shifts all tiles to the left, merging consecutive tiles as necessary.
*/
public void moveLeft() {
if (mIsGameOver) {
return;
}
final int oldScore = mCurrentScore;
boolean moved = false;
View gist:febcf171605d83e64207
public boolean canMerge(int t1, int t2) {
final int lowFib = Math.min(t1, t2);
final int highFib = Math.max(t1, t2);
int a = 1, b = 1;
while (b < highFib) {
int temp = b;
b = a + b;
a = temp;
}
@alexjlockwood
alexjlockwood / ActivityTransitionCoordinator.java
Last active Aug 29, 2015
ActivityTransitionCoordinator.java
View ActivityTransitionCoordinator.java
package android.app;
import android.content.Context;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.Bundle;
import android.os.Handler;
import android.os.Parcelable;
import android.os.ResultReceiver;
View TextSizeTransition.java
public class TextSizeTransition extends Transition {
private static final String PROPNAME_TEXT_SIZE = "propname_text_size";
private static final String[] TRANSITION_PROPERTIES = { PROPNAME_TEXT_SIZE };
private static final Property<TextView, Float> TEXT_SIZE =
new Property<TextView, Float>(Float.class, "textSize") {
@Override
public Float get(TextView textView) {
return textView.getTextSize();
View TransitionActivity.java
public class TransitionActivity extends Activity implements View.OnClickListener {
private static final Transition TRANSITION = new Fade();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mRootView = findViewById(R.id.root_view);
mRootView.setOnClickListener(this);
}
View activity_main.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
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
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;
@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() { }