am 4f497122: Merge "Add missing already_scanning string" into lmp-mr1-dev

* commit '4f497122c361cb74eca4f44898bc05afeebb554b':
  Add missing already_scanning string
diff --git a/background/JobScheduler/template-params.xml b/background/JobScheduler/template-params.xml
index a9e06de..2a6197b 100644
--- a/background/JobScheduler/template-params.xml
+++ b/background/JobScheduler/template-params.xml
@@ -23,7 +23,7 @@
     <package>com.example.android.jobscheduler</package>
 
     <!-- change minSdk if needed-->
-    <minSdk>18</minSdk>
+    <minSdk>21</minSdk>
     <compileSdkVersion>21</compileSdkVersion>
 
     <strings>
diff --git a/background/alarms/RepeatingAlarm/template-params.xml b/background/alarms/RepeatingAlarm/template-params.xml
index b013a53..f2d68c5 100644
--- a/background/alarms/RepeatingAlarm/template-params.xml
+++ b/background/alarms/RepeatingAlarm/template-params.xml
@@ -21,7 +21,7 @@
 
 
     <!--TODO: change minSdk if needed-->
-    <minSdk>4</minSdk>
+    <minSdk>11</minSdk>
 
     <strings>
         <intro>
diff --git a/build.gradle b/build.gradle
index 5c72a6f..9ced21d 100644
--- a/build.gradle
+++ b/build.gradle
@@ -97,6 +97,9 @@
 "admin/NfcProvisioning",
 "admin/DeviceOwner",
 "wearable/wear/XYZTouristAttractions",
+"connectivity/bluetooth/BluetoothAdvertisements",
+"wearable/wear/AlwaysOn",
+"media/Camera2Raw",
 ]
 
 List<String> taskNames = [
diff --git a/connectivity/bluetooth/BluetoothAdvertisements/Application/src/main/java/com/example/android/bluetoothadvertisements/AdvertiserFragment.java b/connectivity/bluetooth/BluetoothAdvertisements/Application/src/main/java/com/example/android/bluetoothadvertisements/AdvertiserFragment.java
index f8daefb..f3645fc 100644
--- a/connectivity/bluetooth/BluetoothAdvertisements/Application/src/main/java/com/example/android/bluetoothadvertisements/AdvertiserFragment.java
+++ b/connectivity/bluetooth/BluetoothAdvertisements/Application/src/main/java/com/example/android/bluetoothadvertisements/AdvertiserFragment.java
@@ -1,3 +1,19 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package com.example.android.bluetoothadvertisements;
 
 import android.bluetooth.BluetoothAdapter;
diff --git a/connectivity/bluetooth/BluetoothAdvertisements/Application/src/main/java/com/example/android/bluetoothadvertisements/Constants.java b/connectivity/bluetooth/BluetoothAdvertisements/Application/src/main/java/com/example/android/bluetoothadvertisements/Constants.java
index d3941e2..793ac92 100644
--- a/connectivity/bluetooth/BluetoothAdvertisements/Application/src/main/java/com/example/android/bluetoothadvertisements/Constants.java
+++ b/connectivity/bluetooth/BluetoothAdvertisements/Application/src/main/java/com/example/android/bluetoothadvertisements/Constants.java
@@ -1,3 +1,19 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package com.example.android.bluetoothadvertisements;
 
 import android.os.ParcelUuid;
diff --git a/connectivity/bluetooth/BluetoothAdvertisements/Application/src/main/java/com/example/android/bluetoothadvertisements/MainActivity.java b/connectivity/bluetooth/BluetoothAdvertisements/Application/src/main/java/com/example/android/bluetoothadvertisements/MainActivity.java
index f0044a3..871935d 100644
--- a/connectivity/bluetooth/BluetoothAdvertisements/Application/src/main/java/com/example/android/bluetoothadvertisements/MainActivity.java
+++ b/connectivity/bluetooth/BluetoothAdvertisements/Application/src/main/java/com/example/android/bluetoothadvertisements/MainActivity.java
@@ -1,18 +1,18 @@
 /*
-* Copyright 2013 The Android Open Source Project
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*     http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 
 package com.example.android.bluetoothadvertisements;
 
diff --git a/connectivity/bluetooth/BluetoothAdvertisements/Application/src/main/java/com/example/android/bluetoothadvertisements/ScanResultAdapter.java b/connectivity/bluetooth/BluetoothAdvertisements/Application/src/main/java/com/example/android/bluetoothadvertisements/ScanResultAdapter.java
index 0f905ea..f3c141d 100644
--- a/connectivity/bluetooth/BluetoothAdvertisements/Application/src/main/java/com/example/android/bluetoothadvertisements/ScanResultAdapter.java
+++ b/connectivity/bluetooth/BluetoothAdvertisements/Application/src/main/java/com/example/android/bluetoothadvertisements/ScanResultAdapter.java
@@ -1,3 +1,19 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package com.example.android.bluetoothadvertisements;
 
 import android.bluetooth.le.ScanResult;
diff --git a/connectivity/bluetooth/BluetoothAdvertisements/Application/src/main/java/com/example/android/bluetoothadvertisements/ScannerFragment.java b/connectivity/bluetooth/BluetoothAdvertisements/Application/src/main/java/com/example/android/bluetoothadvertisements/ScannerFragment.java
index b9ad4d9..ebb1ad0 100644
--- a/connectivity/bluetooth/BluetoothAdvertisements/Application/src/main/java/com/example/android/bluetoothadvertisements/ScannerFragment.java
+++ b/connectivity/bluetooth/BluetoothAdvertisements/Application/src/main/java/com/example/android/bluetoothadvertisements/ScannerFragment.java
@@ -1,3 +1,19 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package com.example.android.bluetoothadvertisements;
 
 import android.bluetooth.BluetoothAdapter;
diff --git a/media/Camera2Raw/Application/.gitignore b/media/Camera2Raw/Application/.gitignore
new file mode 100644
index 0000000..6eb878d
--- /dev/null
+++ b/media/Camera2Raw/Application/.gitignore
@@ -0,0 +1,16 @@
+# Copyright 2013 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+src/template/
+src/common/
+build.gradle
diff --git a/media/Camera2Raw/Application/src/main/AndroidManifest.xml b/media/Camera2Raw/Application/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..f948c6a
--- /dev/null
+++ b/media/Camera2Raw/Application/src/main/AndroidManifest.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2015 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.example.android.camera2raw"
+    android:versionCode="1"
+    android:versionName="1.0">
+
+    <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle -->
+    <uses-permission android:name="android.permission.CAMERA" />
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
+
+    <!-- A camera with RAW capability is required to use this application -->
+    <uses-feature android:name="android.hardware.camera" />
+    <uses-feature android:name="android.hardware.camera.raw" />
+
+    <application android:allowBackup="true"
+        android:label="@string/app_name"
+        android:icon="@drawable/ic_launcher"
+        android:theme="@style/MaterialTheme">
+
+        <activity android:name="com.example.android.camera2raw.CameraActivity"
+                  android:label="@string/app_name">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+    </application>
+
+</manifest>
diff --git a/media/Camera2Raw/Application/src/main/java/com/example/android/camera2raw/AutoFitTextureView.java b/media/Camera2Raw/Application/src/main/java/com/example/android/camera2raw/AutoFitTextureView.java
new file mode 100644
index 0000000..e02e8b8
--- /dev/null
+++ b/media/Camera2Raw/Application/src/main/java/com/example/android/camera2raw/AutoFitTextureView.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.camera2raw;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.TextureView;
+
+/**
+ * A {@link TextureView} that can be adjusted to a specified aspect ratio.
+ */
+public class AutoFitTextureView extends TextureView {
+
+    private int mRatioWidth = 0;
+    private int mRatioHeight = 0;
+
+    public AutoFitTextureView(Context context) {
+        this(context, null);
+    }
+
+    public AutoFitTextureView(Context context, AttributeSet attrs) {
+        this(context, attrs, 0);
+    }
+
+    public AutoFitTextureView(Context context, AttributeSet attrs, int defStyle) {
+        super(context, attrs, defStyle);
+    }
+
+    /**
+     * Sets the aspect ratio for this view. The size of the view will be measured based on the ratio
+     * calculated from the parameters. Note that the actual sizes of parameters don't matter, that
+     * is, calling setAspectRatio(2, 3) and setAspectRatio(4, 6) make the same result.
+     *
+     * @param width  Relative horizontal size
+     * @param height Relative vertical size
+     */
+    public void setAspectRatio(int width, int height) {
+        if (width < 0 || height < 0) {
+            throw new IllegalArgumentException("Size cannot be negative.");
+        }
+        if (mRatioWidth == width && mRatioHeight == height) {
+            return;
+        }
+        mRatioWidth = width;
+        mRatioHeight = height;
+        requestLayout();
+    }
+
+    @Override
+    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+        int width = MeasureSpec.getSize(widthMeasureSpec);
+        int height = MeasureSpec.getSize(heightMeasureSpec);
+        if (0 == mRatioWidth || 0 == mRatioHeight) {
+            setMeasuredDimension(width, height);
+        } else {
+            if (width < height * mRatioWidth / mRatioHeight) {
+                setMeasuredDimension(width, width * mRatioHeight / mRatioWidth);
+            } else {
+                setMeasuredDimension(height * mRatioWidth / mRatioHeight, height);
+            }
+        }
+    }
+
+}
diff --git a/media/Camera2Raw/Application/src/main/java/com/example/android/camera2raw/Camera2RawFragment.java b/media/Camera2Raw/Application/src/main/java/com/example/android/camera2raw/Camera2RawFragment.java
new file mode 100644
index 0000000..6460bf3
--- /dev/null
+++ b/media/Camera2Raw/Application/src/main/java/com/example/android/camera2raw/Camera2RawFragment.java
@@ -0,0 +1,1674 @@
+/*
+ * Copyright 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.camera2raw;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.app.DialogFragment;
+import android.app.Fragment;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.graphics.ImageFormat;
+import android.graphics.Matrix;
+import android.graphics.RectF;
+import android.graphics.SurfaceTexture;
+import android.hardware.SensorManager;
+import android.hardware.camera2.CameraAccessException;
+import android.hardware.camera2.CameraCaptureSession;
+import android.hardware.camera2.CameraCharacteristics;
+import android.hardware.camera2.CameraDevice;
+import android.hardware.camera2.CameraManager;
+import android.hardware.camera2.CameraMetadata;
+import android.hardware.camera2.CaptureFailure;
+import android.hardware.camera2.CaptureRequest;
+import android.hardware.camera2.CaptureResult;
+import android.hardware.camera2.DngCreator;
+import android.hardware.camera2.TotalCaptureResult;
+import android.hardware.camera2.params.StreamConfigurationMap;
+import android.media.Image;
+import android.media.ImageReader;
+import android.media.MediaScannerConnection;
+import android.net.Uri;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.os.Environment;
+import android.os.Handler;
+import android.os.HandlerThread;
+import android.os.Looper;
+import android.os.Message;
+import android.os.SystemClock;
+import android.util.Log;
+import android.util.Size;
+import android.util.SparseIntArray;
+import android.view.LayoutInflater;
+import android.view.OrientationEventListener;
+import android.view.Surface;
+import android.view.TextureView;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Toast;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * A fragment that demonstrates use of the Camera2 API to capture RAW and JPEG photos.
+ *
+ * In this example, the lifecycle of a single request to take a photo is:
+ * <ul>
+ * <li>
+ * The user presses the "Picture" button, resulting in a call to {@link #takePicture()}.
+ * </li>
+ * <li>
+ * {@link #takePicture()} initiates a pre-capture sequence that triggers the camera's built-in
+ * auto-focus, auto-exposure, and auto-white-balance algorithms (aka. "3A") to run.
+ * </li>
+ * <li>
+ * When the pre-capture sequence has finished, a {@link CaptureRequest} with a monotonically
+ * increasing request ID set by calls to {@link CaptureRequest.Builder#setTag(Object)} is sent to
+ * the camera to begin the JPEG and RAW capture sequence, and an
+ * {@link ImageSaver.ImageSaverBuilder} is stored for this request in the
+ * {@link #mJpegResultQueue} and {@link #mRawResultQueue}.
+ * </li>
+ * <li>
+ * As {@link CaptureResult}s and {@link Image}s become available via callbacks in a background
+ * thread, a {@link ImageSaver.ImageSaverBuilder} is looked up by the request ID in
+ * {@link #mJpegResultQueue} and {@link #mRawResultQueue} and updated.
+ * </li>
+ * <li>
+ * When all of the necessary results to save an image are available, the an {@link ImageSaver} is
+ * constructed by the {@link ImageSaver.ImageSaverBuilder} and passed to a separate background
+ * thread to save to a file.
+ * </li>
+ * </ul>
+ */
+public class Camera2RawFragment extends Fragment implements View.OnClickListener {
+    /**
+     * Conversion from screen rotation to JPEG orientation.
+     */
+    private static final SparseIntArray ORIENTATIONS = new SparseIntArray();
+
+    static {
+        ORIENTATIONS.append(Surface.ROTATION_0, 0);
+        ORIENTATIONS.append(Surface.ROTATION_90, 90);
+        ORIENTATIONS.append(Surface.ROTATION_180, 180);
+        ORIENTATIONS.append(Surface.ROTATION_270, 270);
+    }
+
+    /**
+     * Timeout for the pre-capture sequence.
+     */
+    private static final long PRECAPTURE_TIMEOUT_MS = 1000;
+
+    /**
+     * Tolerance when comparing aspect ratios.
+     */
+    private static final double ASPECT_RATIO_TOLERANCE = 0.005;
+
+    /**
+     * Tag for the {@link Log}.
+     */
+    private static final String TAG = "Camera2RawFragment";
+
+    /**
+     * Camera state: Device is closed.
+     */
+    private static final int STATE_CLOSED = 0;
+
+    /**
+     * Camera state: Device is opened, but is not capturing.
+     */
+    private static final int STATE_OPENED = 1;
+
+    /**
+     * Camera state: Showing camera preview.
+     */
+    private static final int STATE_PREVIEW = 2;
+
+    /**
+     * Camera state: Waiting for 3A convergence before capturing a photo.
+     */
+    private static final int STATE_WAITING_FOR_3A_CONVERGENCE = 3;
+
+    /**
+     * An {@link OrientationEventListener} used to determine when device rotation has occurred.
+     * This is mainly necessary for when the device is rotated by 180 degrees, in which case
+     * onCreate or onConfigurationChanged is not called as the view dimensions remain the same,
+     * but the orientation of the has changed, and thus the preview rotation must be updated.
+     */
+    private OrientationEventListener mOrientationListener;
+
+    /**
+     * {@link TextureView.SurfaceTextureListener} handles several lifecycle events of a
+     * {@link TextureView}.
+     */
+    private final TextureView.SurfaceTextureListener mSurfaceTextureListener
+            = new TextureView.SurfaceTextureListener() {
+
+        @Override
+        public void onSurfaceTextureAvailable(SurfaceTexture texture, int width, int height) {
+            configureTransform(width, height);
+        }
+
+        @Override
+        public void onSurfaceTextureSizeChanged(SurfaceTexture texture, int width, int height) {
+            configureTransform(width, height);
+        }
+
+        @Override
+        public boolean onSurfaceTextureDestroyed(SurfaceTexture texture) {
+            synchronized (mCameraStateLock) {
+                mPreviewSize = null;
+            }
+            return true;
+        }
+
+        @Override
+        public void onSurfaceTextureUpdated(SurfaceTexture texture) {
+        }
+
+    };
+
+    /**
+     * An {@link AutoFitTextureView} for camera preview.
+     */
+    private AutoFitTextureView mTextureView;
+
+    /**
+     * An additional thread for running tasks that shouldn't block the UI.  This is used for all
+     * callbacks from the {@link CameraDevice} and {@link CameraCaptureSession}s.
+     */
+    private HandlerThread mBackgroundThread;
+
+    /**
+     * A counter for tracking corresponding {@link CaptureRequest}s and {@link CaptureResult}s
+     * across the {@link CameraCaptureSession} capture callbacks.
+     */
+    private final AtomicInteger mRequestCounter = new AtomicInteger();
+
+    /**
+     * A {@link Semaphore} to prevent the app from exiting before closing the camera.
+     */
+    private final Semaphore mCameraOpenCloseLock = new Semaphore(1);
+
+    /**
+     * A lock protecting camera state.
+     */
+    private final Object mCameraStateLock = new Object();
+
+    // *********************************************************************************************
+    // State protected by mCameraStateLock.
+    //
+    // The following state is used across both the UI and background threads.  Methods with "Locked"
+    // in the name expect mCameraStateLock to be held while calling.
+
+    /**
+     * ID of the current {@link CameraDevice}.
+     */
+    private String mCameraId;
+
+    /**
+     * A {@link CameraCaptureSession } for camera preview.
+     */
+    private CameraCaptureSession mCaptureSession;
+
+    /**
+     * A reference to the open {@link CameraDevice}.
+     */
+    private CameraDevice mCameraDevice;
+
+    /**
+     * The {@link Size} of camera preview.
+     */
+    private Size mPreviewSize;
+
+    /**
+     * The {@link CameraCharacteristics} for the currently configured camera device.
+     */
+    private CameraCharacteristics mCharacteristics;
+
+    /**
+     * A {@link Handler} for running tasks in the background.
+     */
+    private Handler mBackgroundHandler;
+
+    /**
+     * A reference counted holder wrapping the {@link ImageReader} that handles JPEG image captures.
+     * This is used to allow us to clean up the {@link ImageReader} when all background tasks using
+     * its {@link Image}s have completed.
+     */
+    private RefCountedAutoCloseable<ImageReader> mJpegImageReader;
+
+    /**
+     * A reference counted holder wrapping the {@link ImageReader} that handles RAW image captures.
+     * This is used to allow us to clean up the {@link ImageReader} when all background tasks using
+     * its {@link Image}s have completed.
+     */
+    private RefCountedAutoCloseable<ImageReader> mRawImageReader;
+
+    /**
+     * Whether or not the currently configured camera device is fixed-focus.
+     */
+    private boolean mNoAFRun = false;
+
+    /**
+     * Number of pending user requests to capture a photo.
+     */
+    private int mPendingUserCaptures = 0;
+
+    /**
+     * Request ID to {@link ImageSaver.ImageSaverBuilder} mapping for in-progress JPEG captures.
+     */
+    private final TreeMap<Integer, ImageSaver.ImageSaverBuilder> mJpegResultQueue = new TreeMap<>();
+
+    /**
+     * Request ID to {@link ImageSaver.ImageSaverBuilder} mapping for in-progress RAW captures.
+     */
+    private final TreeMap<Integer, ImageSaver.ImageSaverBuilder> mRawResultQueue = new TreeMap<>();
+
+    /**
+     * {@link CaptureRequest.Builder} for the camera preview
+     */
+    private CaptureRequest.Builder mPreviewRequestBuilder;
+
+    /**
+     * The state of the camera device.
+     *
+     * @see #mPreCaptureCallback
+     */
+    private int mState = STATE_CLOSED;
+
+    /**
+     * Timer to use with pre-capture sequence to ensure a timely capture if 3A convergence is taking
+     * too long.
+     */
+    private long mCaptureTimer;
+
+    //**********************************************************************************************
+
+    /**
+     * {@link CameraDevice.StateCallback} is called when the currently active {@link CameraDevice}
+     * changes its state.
+     */
+    private final CameraDevice.StateCallback mStateCallback = new CameraDevice.StateCallback() {
+
+        @Override
+        public void onOpened(CameraDevice cameraDevice) {
+            // This method is called when the camera is opened.  We start camera preview here if
+            // the TextureView displaying this has been set up.
+            synchronized (mCameraStateLock) {
+                mState = STATE_OPENED;
+                mCameraOpenCloseLock.release();
+                mCameraDevice = cameraDevice;
+
+                // Start the preview session if the TextureView has been set up already.
+                if (mPreviewSize != null && mTextureView.isAvailable()) {
+                    createCameraPreviewSessionLocked();
+                }
+            }
+        }
+
+        @Override
+        public void onDisconnected(CameraDevice cameraDevice) {
+            synchronized (mCameraStateLock) {
+                mState = STATE_CLOSED;
+                mCameraOpenCloseLock.release();
+                cameraDevice.close();
+                mCameraDevice = null;
+            }
+        }
+
+        @Override
+        public void onError(CameraDevice cameraDevice, int error) {
+            Log.e(TAG, "Received camera device error: " + error);
+            synchronized(mCameraStateLock) {
+                mState = STATE_CLOSED;
+                mCameraOpenCloseLock.release();
+                cameraDevice.close();
+                mCameraDevice = null;
+            }
+            Activity activity = getActivity();
+            if (null != activity) {
+                activity.finish();
+            }
+        }
+
+    };
+
+    /**
+     * This a callback object for the {@link ImageReader}. "onImageAvailable" will be called when a
+     * JPEG image is ready to be saved.
+     */
+    private final ImageReader.OnImageAvailableListener mOnJpegImageAvailableListener
+            = new ImageReader.OnImageAvailableListener() {
+
+        @Override
+        public void onImageAvailable(ImageReader reader) {
+            dequeueAndSaveImage(mJpegResultQueue, mJpegImageReader);
+        }
+
+    };
+
+    /**
+     * This a callback object for the {@link ImageReader}. "onImageAvailable" will be called when a
+     * RAW image is ready to be saved.
+     */
+    private final ImageReader.OnImageAvailableListener mOnRawImageAvailableListener
+            = new ImageReader.OnImageAvailableListener() {
+
+        @Override
+        public void onImageAvailable(ImageReader reader) {
+            dequeueAndSaveImage(mRawResultQueue, mRawImageReader);
+        }
+
+    };
+
+    /**
+     * A {@link CameraCaptureSession.CaptureCallback} that handles events for the preview and
+     * pre-capture sequence.
+     */
+    private CameraCaptureSession.CaptureCallback mPreCaptureCallback
+            = new CameraCaptureSession.CaptureCallback() {
+
+        private void process(CaptureResult result) {
+            synchronized(mCameraStateLock) {
+                switch (mState) {
+                    case STATE_PREVIEW: {
+                        // We have nothing to do when the camera preview is running normally.
+                        break;
+                    }
+                    case STATE_WAITING_FOR_3A_CONVERGENCE: {
+                        boolean readyToCapture = true;
+                        if (!mNoAFRun) {
+                            int afState = result.get(CaptureResult.CONTROL_AF_STATE);
+
+                            // If auto-focus has reached locked state, we are ready to capture
+                            readyToCapture =
+                                    (afState == CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED ||
+                                    afState == CaptureResult.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
+                        }
+
+                        // If we are running on an non-legacy device, we should also wait until
+                        // auto-exposure and auto-white-balance have converged as well before
+                        // taking a picture.
+                        if (!isLegacyLocked()) {
+                            int aeState = result.get(CaptureResult.CONTROL_AE_STATE);
+                            int awbState = result.get(CaptureResult.CONTROL_AWB_STATE);
+
+                            readyToCapture = readyToCapture &&
+                                    aeState == CaptureResult.CONTROL_AE_STATE_CONVERGED &&
+                                    awbState == CaptureResult.CONTROL_AWB_STATE_CONVERGED;
+                        }
+
+                        // If we haven't finished the pre-capture sequence but have hit our maximum
+                        // wait timeout, too bad! Begin capture anyway.
+                        if (!readyToCapture && hitTimeoutLocked()) {
+                            Log.w(TAG, "Timed out waiting for pre-capture sequence to complete.");
+                            readyToCapture = true;
+                        }
+
+                        if (readyToCapture && mPendingUserCaptures > 0) {
+                            // Capture once for each user tap of the "Picture" button.
+                            while (mPendingUserCaptures > 0) {
+                                captureStillPictureLocked();
+                                mPendingUserCaptures--;
+                            }
+                            // After this, the camera will go back to the normal state of preview.
+                            mState = STATE_PREVIEW;
+                        }
+                    }
+                }
+            }
+        }
+
+        @Override
+        public void onCaptureProgressed(CameraCaptureSession session, CaptureRequest request,
+                                        CaptureResult partialResult) {
+            process(partialResult);
+        }
+
+        @Override
+        public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request,
+                                       TotalCaptureResult result) {
+            process(result);
+        }
+
+    };
+
+    /**
+     * A {@link CameraCaptureSession.CaptureCallback} that handles the still JPEG and RAW capture
+     * request.
+     */
+    private final CameraCaptureSession.CaptureCallback mCaptureCallback
+            = new CameraCaptureSession.CaptureCallback() {
+        @Override
+        public void onCaptureStarted(CameraCaptureSession session, CaptureRequest request,
+                                     long timestamp, long frameNumber) {
+            String currentDateTime = generateTimestamp();
+            File rawFile = new File(Environment.
+                    getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM),
+                    "RAW_" + currentDateTime + ".dng");
+            File jpegFile = new File(Environment.
+                    getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM),
+                    "JPEG_" + currentDateTime + ".jpg");
+
+            // Look up the ImageSaverBuilder for this request and update it with the file name
+            // based on the capture start time.
+            ImageSaver.ImageSaverBuilder jpegBuilder;
+            ImageSaver.ImageSaverBuilder rawBuilder;
+            int requestId = (int) request.getTag();
+            synchronized (mCameraStateLock) {
+                jpegBuilder = mJpegResultQueue.get(requestId);
+                rawBuilder = mRawResultQueue.get(requestId);
+            }
+
+            if (jpegBuilder != null) jpegBuilder.setFile(jpegFile);
+            if (rawBuilder != null) rawBuilder.setFile(rawFile);
+        }
+
+        @Override
+        public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request,
+                                       TotalCaptureResult result) {
+            int requestId = (int) request.getTag();
+            ImageSaver.ImageSaverBuilder jpegBuilder;
+            ImageSaver.ImageSaverBuilder rawBuilder;
+            StringBuilder sb = new StringBuilder();
+
+            // Look up the ImageSaverBuilder for this request and update it with the CaptureResult
+            synchronized (mCameraStateLock) {
+                jpegBuilder = mJpegResultQueue.get(requestId);
+                rawBuilder = mRawResultQueue.get(requestId);
+
+                // If we have all the results necessary, save the image to a file in the background.
+                handleCompletionLocked(requestId, jpegBuilder, mJpegResultQueue);
+                handleCompletionLocked(requestId, rawBuilder, mRawResultQueue);
+
+                if (jpegBuilder != null) {
+                    jpegBuilder.setResult(result);
+                    sb.append("Saving JPEG as: ");
+                    sb.append(jpegBuilder.getSaveLocation());
+                }
+                if (rawBuilder != null) {
+                    rawBuilder.setResult(result);
+                    if (jpegBuilder != null) sb.append(", ");
+                    sb.append("Saving RAW as: ");
+                    sb.append(rawBuilder.getSaveLocation());
+                }
+                finishedCaptureLocked();
+            }
+
+            showToast(sb.toString());
+        }
+
+        @Override
+        public void onCaptureFailed(CameraCaptureSession session, CaptureRequest request,
+                                    CaptureFailure failure) {
+            int requestId = (int) request.getTag();
+            synchronized (mCameraStateLock) {
+                mJpegResultQueue.remove(requestId);
+                mRawResultQueue.remove(requestId);
+                finishedCaptureLocked();
+            }
+            showToast("Capture failed!");
+        }
+
+    };
+
+    /**
+     * A {@link Handler} for showing {@link Toast}s on the UI thread.
+     */
+    private final Handler mMessageHandler = new Handler(Looper.getMainLooper()) {
+        @Override
+        public void handleMessage(Message msg) {
+            Activity activity = getActivity();
+            if (activity != null) {
+                Toast.makeText(activity, (String) msg.obj, Toast.LENGTH_SHORT).show();
+            }
+        }
+    };
+
+    public static Camera2RawFragment newInstance() {
+        Camera2RawFragment fragment = new Camera2RawFragment();
+        fragment.setRetainInstance(true);
+        return fragment;
+    }
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+                             Bundle savedInstanceState) {
+        return inflater.inflate(R.layout.fragment_camera2_basic, container, false);
+    }
+
+    @Override
+    public void onViewCreated(final View view, Bundle savedInstanceState) {
+        view.findViewById(R.id.picture).setOnClickListener(this);
+        view.findViewById(R.id.info).setOnClickListener(this);
+        mTextureView = (AutoFitTextureView) view.findViewById(R.id.texture);
+
+        // Setup a new OrientationEventListener.  This is used to handle rotation events like a
+        // 180 degree rotation that do not normally trigger a call to onCreate to do view re-layout
+        // or otherwise cause the preview TextureView's size to change.
+        mOrientationListener = new OrientationEventListener(getActivity(),
+                SensorManager.SENSOR_DELAY_NORMAL) {
+            @Override
+            public void onOrientationChanged(int orientation) {
+                if (mTextureView != null && mTextureView.isAvailable()) {
+                    configureTransform(mTextureView.getWidth(), mTextureView.getHeight());
+                }
+            }
+        };
+    }
+
+    @Override
+    public void onResume() {
+        super.onResume();
+        startBackgroundThread();
+        openCamera();
+
+        // When the screen is turned off and turned back on, the SurfaceTexture is already
+        // available, and "onSurfaceTextureAvailable" will not be called. In that case, we should
+        // configure the preview bounds here (otherwise, we wait until the surface is ready in
+        // the SurfaceTextureListener).
+        if (mTextureView.isAvailable()) {
+            configureTransform(mTextureView.getWidth(), mTextureView.getHeight());
+        } else {
+            mTextureView.setSurfaceTextureListener(mSurfaceTextureListener);
+        }
+        if (mOrientationListener != null && mOrientationListener.canDetectOrientation()) {
+            mOrientationListener.enable();
+        }
+    }
+
+    @Override
+    public void onPause() {
+        if (mOrientationListener != null) {
+            mOrientationListener.disable();
+        }
+        closeCamera();
+        stopBackgroundThread();
+        super.onPause();
+    }
+
+    @Override
+    public void onClick(View view) {
+        switch (view.getId()) {
+            case R.id.picture: {
+                takePicture();
+                break;
+            }
+            case R.id.info: {
+                Activity activity = getActivity();
+                if (null != activity) {
+                    new AlertDialog.Builder(activity)
+                            .setMessage(R.string.intro_message)
+                            .setPositiveButton(android.R.string.ok, null)
+                            .show();
+                }
+                break;
+            }
+        }
+    }
+
+    /**
+     * Sets up state related to camera that is needed before opening a {@link CameraDevice}.
+     */
+    private boolean setUpCameraOutputs() {
+        Activity activity = getActivity();
+        CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
+        if (manager == null) {
+            ErrorDialog.buildErrorDialog("This device doesn't support Camera2 API.").
+                    show(getFragmentManager(), "dialog");
+            return false;
+        }
+        try {
+            // Find a CameraDevice that supports RAW captures, and configure state.
+            for (String cameraId : manager.getCameraIdList()) {
+                CameraCharacteristics characteristics
+                        = manager.getCameraCharacteristics(cameraId);
+
+                // We only use a camera that supports RAW in this sample.
+                if (!contains(characteristics.get(
+                        CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES),
+                        CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_RAW)) {
+                    continue;
+                }
+
+                StreamConfigurationMap map = characteristics.get(
+                        CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
+
+                // For still image captures, we use the largest available size.
+                Size largestJpeg = Collections.max(
+                        Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)),
+                        new CompareSizesByArea());
+
+                Size largestRaw = Collections.max(
+                        Arrays.asList(map.getOutputSizes(ImageFormat.RAW_SENSOR)),
+                        new CompareSizesByArea());
+
+                synchronized(mCameraStateLock) {
+                    // Set up ImageReaders for JPEG and RAW outputs.  Place these in a reference
+                    // counted wrapper to ensure they are only closed when all background tasks
+                    // using them are finished.
+                    if (mJpegImageReader == null || mJpegImageReader.getAndRetain() == null) {
+                        mJpegImageReader = new RefCountedAutoCloseable<>(
+                                ImageReader.newInstance(largestJpeg.getWidth(),
+                                largestJpeg.getHeight(), ImageFormat.JPEG, /*maxImages*/5));
+                    }
+                    mJpegImageReader.get().setOnImageAvailableListener(
+                            mOnJpegImageAvailableListener, mBackgroundHandler);
+
+                    if (mRawImageReader == null || mRawImageReader.getAndRetain() == null) {
+                        mRawImageReader = new RefCountedAutoCloseable<>(
+                                ImageReader.newInstance(largestRaw.getWidth(),
+                                largestRaw.getHeight(), ImageFormat.RAW_SENSOR, /*maxImages*/ 5));
+                    }
+                    mRawImageReader.get().setOnImageAvailableListener(
+                            mOnRawImageAvailableListener, mBackgroundHandler);
+
+                    mCharacteristics = characteristics;
+                    mCameraId = cameraId;
+                }
+                return true;
+            }
+        } catch (CameraAccessException e) {
+            e.printStackTrace();
+        }
+
+        // If we found no suitable cameras for capturing RAW, warn the user.
+        ErrorDialog.buildErrorDialog("This device doesn't support capturing RAW photos").
+                show(getFragmentManager(), "dialog");
+        return false;
+    }
+
+    /**
+     * Opens the camera specified by {@link #mCameraId}.
+     */
+    private void openCamera() {
+        if (!setUpCameraOutputs()) {
+            return;
+        }
+
+        Activity activity = getActivity();
+        CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
+        try {
+            // Wait for any previously running session to finish.
+            if (!mCameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) {
+                throw new RuntimeException("Time out waiting to lock camera opening.");
+            }
+
+            String cameraId;
+            Handler backgroundHandler;
+            synchronized (mCameraStateLock) {
+                cameraId = mCameraId;
+                backgroundHandler = mBackgroundHandler;
+            }
+
+            // Attempt to open the camera. mStateCallback will be called on the background handler's
+            // thread when this succeeds or fails.
+            manager.openCamera(cameraId, mStateCallback, backgroundHandler);
+        } catch (CameraAccessException e) {
+            e.printStackTrace();
+        } catch (InterruptedException e) {
+            throw new RuntimeException("Interrupted while trying to lock camera opening.", e);
+        }
+    }
+
+    /**
+     * Closes the current {@link CameraDevice}.
+     */
+    private void closeCamera() {
+        try {
+            mCameraOpenCloseLock.acquire();
+            synchronized(mCameraStateLock) {
+
+                // Reset state and clean up resources used by the camera.
+                // Note: After calling this, the ImageReaders will be closed after any background
+                // tasks saving Images from these readers have been completed.
+                mPendingUserCaptures = 0;
+                mState = STATE_CLOSED;
+                if (null != mCaptureSession) {
+                    mCaptureSession.close();
+                    mCaptureSession = null;
+                }
+                if (null != mCameraDevice) {
+                    mCameraDevice.close();
+                    mCameraDevice = null;
+                }
+                if (null != mJpegImageReader) {
+                    mJpegImageReader.close();
+                    mJpegImageReader = null;
+                }
+                if (null != mRawImageReader) {
+                    mRawImageReader.close();
+                    mRawImageReader = null;
+                }
+            }
+        } catch (InterruptedException e) {
+            throw new RuntimeException("Interrupted while trying to lock camera closing.", e);
+        } finally {
+            mCameraOpenCloseLock.release();
+        }
+    }
+
+    /**
+     * Starts a background thread and its {@link Handler}.
+     */
+    private void startBackgroundThread() {
+        mBackgroundThread = new HandlerThread("CameraBackground");
+        mBackgroundThread.start();
+        synchronized(mCameraStateLock) {
+            mBackgroundHandler = new Handler(mBackgroundThread.getLooper());
+        }
+    }
+
+    /**
+     * Stops the background thread and its {@link Handler}.
+     */
+    private void stopBackgroundThread() {
+        mBackgroundThread.quitSafely();
+        try {
+            mBackgroundThread.join();
+            mBackgroundThread = null;
+            synchronized (mCameraStateLock) {
+                mBackgroundHandler = null;
+            }
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * Creates a new {@link CameraCaptureSession} for camera preview.
+     *
+     * Call this only with {@link #mCameraStateLock} held.
+     */
+    private void createCameraPreviewSessionLocked() {
+        try {
+            SurfaceTexture texture = mTextureView.getSurfaceTexture();
+            // We configure the size of default buffer to be the size of camera preview we want.
+            texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());
+
+            // This is the output Surface we need to start preview.
+            Surface surface = new Surface(texture);
+
+            // We set up a CaptureRequest.Builder with the output Surface.
+            mPreviewRequestBuilder
+                    = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
+            mPreviewRequestBuilder.addTarget(surface);
+
+            // Here, we create a CameraCaptureSession for camera preview.
+            mCameraDevice.createCaptureSession(Arrays.asList(surface,
+                    mJpegImageReader.get().getSurface(),
+                    mRawImageReader.get().getSurface()), new CameraCaptureSession.StateCallback() {
+                        @Override
+                        public void onConfigured(CameraCaptureSession cameraCaptureSession) {
+                            synchronized (mCameraStateLock) {
+                                // The camera is already closed
+                                if (null == mCameraDevice) {
+                                    return;
+                                }
+
+                                try {
+                                    setup3AControlsLocked(mPreviewRequestBuilder);
+                                    // Finally, we start displaying the camera preview.
+                                    cameraCaptureSession.setRepeatingRequest(
+                                            mPreviewRequestBuilder.build(),
+                                            mPreCaptureCallback, mBackgroundHandler);
+                                    mState = STATE_PREVIEW;
+                                } catch (CameraAccessException|IllegalStateException e) {
+                                    e.printStackTrace();
+                                    return;
+                                }
+                                // When the session is ready, we start displaying the preview.
+                                mCaptureSession = cameraCaptureSession;
+                            }
+                        }
+
+                        @Override
+                        public void onConfigureFailed(CameraCaptureSession cameraCaptureSession) {
+                            showToast("Failed to configure camera.");
+                        }
+                    }, mBackgroundHandler
+            );
+        } catch (CameraAccessException e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * Configure the given {@link CaptureRequest.Builder} to use auto-focus, auto-exposure, and
+     * auto-white-balance controls if available.
+     *
+     * Call this only with {@link #mCameraStateLock} held.
+     *
+     * @param builder the builder to configure.
+     */
+    private void setup3AControlsLocked(CaptureRequest.Builder builder) {
+        // Enable auto-magical 3A run by camera device
+        builder.set(CaptureRequest.CONTROL_MODE,
+                CaptureRequest.CONTROL_MODE_AUTO);
+
+        Float minFocusDist =
+                mCharacteristics.get(CameraCharacteristics.LENS_INFO_MINIMUM_FOCUS_DISTANCE);
+
+        // If MINIMUM_FOCUS_DISTANCE is 0, lens is fixed-focus and we need to skip the AF run.
+        mNoAFRun = (minFocusDist == null || minFocusDist == 0);
+
+        if (!mNoAFRun) {
+            // If there is a "continuous picture" mode available, use it, otherwise default to AUTO.
+            if (contains(mCharacteristics.get(
+                            CameraCharacteristics.CONTROL_AF_AVAILABLE_MODES),
+                    CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE)) {
+                builder.set(CaptureRequest.CONTROL_AF_MODE,
+                        CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
+            } else {
+                builder.set(CaptureRequest.CONTROL_AF_MODE,
+                        CaptureRequest.CONTROL_AF_MODE_AUTO);
+            }
+        }
+
+        // If there is an auto-magical flash control mode available, use it, otherwise default to
+        // the "on" mode, which is guaranteed to always be available.
+        if (contains(mCharacteristics.get(
+                        CameraCharacteristics.CONTROL_AE_AVAILABLE_MODES),
+                CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH)) {
+            builder.set(CaptureRequest.CONTROL_AE_MODE,
+                    CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
+        } else {
+            builder.set(CaptureRequest.CONTROL_AE_MODE,
+                    CaptureRequest.CONTROL_AE_MODE_ON);
+        }
+
+        // If there is an auto-magical white balance control mode available, use it.
+        if (contains(mCharacteristics.get(
+                        CameraCharacteristics.CONTROL_AWB_AVAILABLE_MODES),
+                CaptureRequest.CONTROL_AWB_MODE_AUTO)) {
+            // Allow AWB to run auto-magically if this device supports this
+            builder.set(CaptureRequest.CONTROL_AWB_MODE,
+                    CaptureRequest.CONTROL_AWB_MODE_AUTO);
+        }
+    }
+
+    /**
+     * Configure the necessary {@link android.graphics.Matrix} transformation to `mTextureView`,
+     * and start/restart the preview capture session if necessary.
+     *
+     * This method should be called after the camera state has been initialized in
+     * setUpCameraOutputs.
+     *
+     * @param viewWidth  The width of `mTextureView`
+     * @param viewHeight The height of `mTextureView`
+     */
+    private void configureTransform(int viewWidth, int viewHeight) {
+        Activity activity = getActivity();
+        synchronized(mCameraStateLock) {
+            if (null == mTextureView || null == activity) {
+                return;
+            }
+
+            StreamConfigurationMap map = mCharacteristics.get(
+                    CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
+
+            // For still image captures, we always use the largest available size.
+            Size largestJpeg = Collections.max(Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)),
+                    new CompareSizesByArea());
+
+            // Find the rotation of the device relative to the native device orientation.
+            int deviceRotation = activity.getWindowManager().getDefaultDisplay().getRotation();
+
+            // Find the rotation of the device relative to the camera sensor's orientation.
+            int totalRotation = sensorToDeviceRotation(mCharacteristics, deviceRotation);
+
+            // Swap the view dimensions for calculation as needed if they are rotated relative to
+            // the sensor.
+            boolean swappedDimensions = totalRotation == 90 || totalRotation == 270;
+            int rotatedViewWidth = viewWidth;
+            int rotatedViewHeight = viewHeight;
+            if (swappedDimensions) {
+                rotatedViewWidth = viewHeight;
+                rotatedViewHeight = viewWidth;
+            }
+
+            // Find the best preview size for these view dimensions and configured JPEG size.
+            Size previewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class),
+                    rotatedViewWidth, rotatedViewHeight, largestJpeg);
+
+            if (swappedDimensions) {
+                mTextureView.setAspectRatio(
+                        previewSize.getHeight(), previewSize.getWidth());
+            } else {
+                mTextureView.setAspectRatio(
+                        previewSize.getWidth(), previewSize.getHeight());
+            }
+
+            // Find rotation of device in degrees (reverse device orientation for front-facing
+            // cameras).
+            int rotation = (mCharacteristics.get(CameraCharacteristics.LENS_FACING) ==
+                    CameraCharacteristics.LENS_FACING_FRONT) ?
+                    (360 + ORIENTATIONS.get(deviceRotation)) % 360 :
+                    (360 - ORIENTATIONS.get(deviceRotation)) % 360;
+
+            Matrix matrix = new Matrix();
+            RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
+            RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth());
+            float centerX = viewRect.centerX();
+            float centerY = viewRect.centerY();
+
+            // Initially, output stream images from the Camera2 API will be rotated to the native
+            // device orientation from the sensor's orientation, and the TextureView will default to
+            // scaling these buffers to fill it's view bounds.  If the aspect ratios and relative
+            // orientations are correct, this is fine.
+            //
+            // However, if the device orientation has been rotated relative to its native
+            // orientation so that the TextureView's dimensions are swapped relative to the
+            // native device orientation, we must do the following to ensure the output stream
+            // images are not incorrectly scaled by the TextureView:
+            //   - Undo the scale-to-fill from the output buffer's dimensions (i.e. its dimensions
+            //     in the native device orientation) to the TextureView's dimension.
+            //   - Apply a scale-to-fill from the output buffer's rotated dimensions
+            //     (i.e. its dimensions in the current device orientation) to the TextureView's
+            //     dimensions.
+            //   - Apply the rotation from the native device orientation to the current device
+            //     rotation.
+            if (Surface.ROTATION_90 == deviceRotation || Surface.ROTATION_270 == deviceRotation) {
+                bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
+                matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
+                float scale = Math.max(
+                        (float) viewHeight / previewSize.getHeight(),
+                        (float) viewWidth / previewSize.getWidth());
+                matrix.postScale(scale, scale, centerX, centerY);
+
+            }
+            matrix.postRotate(rotation, centerX, centerY);
+
+            mTextureView.setTransform(matrix);
+
+            // Start or restart the active capture session if the preview was initialized or
+            // if its aspect ratio changed significantly.
+            if (mPreviewSize == null || !checkAspectsEqual(previewSize, mPreviewSize)) {
+                mPreviewSize = previewSize;
+                if (mState != STATE_CLOSED) {
+                    createCameraPreviewSessionLocked();
+                }
+            }
+        }
+    }
+
+    /**
+     * Initiate a still image capture.
+     *
+     * This function sends a capture request that initiates a pre-capture sequence in our state
+     * machine that waits for auto-focus to finish, ending in a "locked" state where the lens is no
+     * longer moving, waits for auto-exposure to choose a good exposure value, and waits for
+     * auto-white-balance to converge.
+     */
+    private void takePicture() {
+        synchronized(mCameraStateLock) {
+            mPendingUserCaptures++;
+
+            // If we already triggered a pre-capture sequence, or are in a state where we cannot
+            // do this, return immediately.
+            if (mState != STATE_PREVIEW) {
+                return;
+            }
+
+            try {
+                // Trigger an auto-focus run if camera is capable. If the camera is already focused,
+                // this should do nothing.
+                if (!mNoAFRun) {
+                    mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
+                            CameraMetadata.CONTROL_AF_TRIGGER_START);
+                }
+
+                // If this is not a legacy device, we can also trigger an auto-exposure metering
+                // run.
+                if (!isLegacyLocked()) {
+                    // Tell the camera to lock focus.
+                    mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER,
+                            CameraMetadata.CONTROL_AE_PRECAPTURE_TRIGGER_START);
+                }
+
+                // Update state machine to wait for auto-focus, auto-exposure, and
+                // auto-white-balance (aka. "3A") to converge.
+                mState = STATE_WAITING_FOR_3A_CONVERGENCE;
+
+                // Start a timer for the pre-capture sequence.
+                startTimerLocked();
+
+                // Replace the existing repeating request with one with updated 3A triggers.
+                mCaptureSession.capture(mPreviewRequestBuilder.build(), mPreCaptureCallback,
+                        mBackgroundHandler);
+            } catch (CameraAccessException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+    /**
+     * Send a capture request to the camera device that initiates a capture targeting the JPEG and
+     * RAW outputs.
+     *
+     * Call this only with {@link #mCameraStateLock} held.
+     */
+    private void captureStillPictureLocked() {
+        try {
+            final Activity activity = getActivity();
+            if (null == activity || null == mCameraDevice) {
+                return;
+            }
+            // This is the CaptureRequest.Builder that we use to take a picture.
+            final CaptureRequest.Builder captureBuilder =
+                    mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
+
+            captureBuilder.addTarget(mJpegImageReader.get().getSurface());
+            captureBuilder.addTarget(mRawImageReader.get().getSurface());
+
+            // Use the same AE and AF modes as the preview.
+            setup3AControlsLocked(captureBuilder);
+
+            // Set orientation.
+            int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
+            captureBuilder.set(CaptureRequest.JPEG_ORIENTATION,
+                    sensorToDeviceRotation(mCharacteristics, rotation));
+
+            // Set request tag to easily track results in callbacks.
+            captureBuilder.setTag(mRequestCounter.getAndIncrement());
+
+            CaptureRequest request = captureBuilder.build();
+
+            // Create an ImageSaverBuilder in which to collect results, and add it to the queue
+            // of active requests.
+            ImageSaver.ImageSaverBuilder jpegBuilder = new ImageSaver.ImageSaverBuilder(activity)
+                    .setCharacteristics(mCharacteristics);
+            ImageSaver.ImageSaverBuilder rawBuilder = new ImageSaver.ImageSaverBuilder(activity)
+                    .setCharacteristics(mCharacteristics);
+
+            mJpegResultQueue.put((int) request.getTag(), jpegBuilder);
+            mRawResultQueue.put((int) request.getTag(), rawBuilder);
+
+            mCaptureSession.capture(request, mCaptureCallback, mBackgroundHandler);
+
+        } catch (CameraAccessException e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * Called after a RAW/JPEG capture has completed; resets the AF trigger state for the
+     * pre-capture sequence.
+     *
+     * Call this only with {@link #mCameraStateLock} held.
+     */
+    private void finishedCaptureLocked() {
+        try {
+            // Reset the auto-focus trigger in case AF didn't run quickly enough.
+            if (!mNoAFRun) {
+                mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
+                        CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
+
+                mCaptureSession.capture(mPreviewRequestBuilder.build(), mPreCaptureCallback,
+                        mBackgroundHandler);
+
+                mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
+                        CameraMetadata.CONTROL_AF_TRIGGER_IDLE);
+            }
+        } catch (CameraAccessException e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * Retrieve the next {@link Image} from a reference counted {@link ImageReader}, retaining
+     * that {@link ImageReader} until that {@link Image} is no longer in use, and set this
+     * {@link Image} as the result for the next request in the queue of pending requests.  If
+     * all necessary information is available, begin saving the image to a file in a background
+     * thread.
+     *
+     * @param pendingQueue the currently active requests.
+     * @param reader a reference counted wrapper containing an {@link ImageReader} from which to
+     *               acquire an image.
+     */
+    private void dequeueAndSaveImage(TreeMap<Integer, ImageSaver.ImageSaverBuilder> pendingQueue,
+                                     RefCountedAutoCloseable<ImageReader> reader) {
+        synchronized (mCameraStateLock) {
+            Map.Entry<Integer, ImageSaver.ImageSaverBuilder> entry =
+                    pendingQueue.firstEntry();
+            ImageSaver.ImageSaverBuilder builder = entry.getValue();
+
+            // Increment reference count to prevent ImageReader from being closed while we
+            // are saving its Images in a background thread (otherwise their resources may
+            // be freed while we are writing to a file).
+            if (reader == null || reader.getAndRetain() == null) {
+                Log.e(TAG, "Paused the activity before we could save the image," +
+                        " ImageReader already closed.");
+                pendingQueue.remove(entry.getKey());
+                return;
+            }
+
+            Image image;
+            try {
+                image = reader.get().acquireNextImage();
+            } catch (IllegalStateException e) {
+                Log.e(TAG, "Too many images queued for saving, dropping image for request: " +
+                        entry.getKey());
+                pendingQueue.remove(entry.getKey());
+                return;
+            }
+
+            builder.setRefCountedReader(reader).setImage(image);
+
+            handleCompletionLocked(entry.getKey(), builder, pendingQueue);
+        }
+    }
+
+    /**
+     * Runnable that saves an {@link Image} into the specified {@link File}, and updates
+     * {@link android.provider.MediaStore} to include the resulting file.
+     *
+     * This can be constructed through an {@link ImageSaverBuilder} as the necessary image and
+     * result information becomes available.
+     */
+    private static class ImageSaver implements Runnable {
+
+        /**
+         * The image to save.
+         */
+        private final Image mImage;
+        /**
+         * The file we save the image into.
+         */
+        private final File mFile;
+
+        /**
+         * The CaptureResult for this image capture.
+         */
+        private final CaptureResult mCaptureResult;
+
+        /**
+         * The CameraCharacteristics for this camera device.
+         */
+        private final CameraCharacteristics mCharacteristics;
+
+        /**
+         * The Context to use when updating MediaStore with the saved images.
+         */
+        private final Context mContext;
+
+        /**
+         * A reference counted wrapper for the ImageReader that owns the given image.
+         */
+        private final RefCountedAutoCloseable<ImageReader> mReader;
+
+        private ImageSaver(Image image, File file, CaptureResult result,
+                CameraCharacteristics characteristics, Context context,
+                RefCountedAutoCloseable<ImageReader> reader) {
+            mImage = image;
+            mFile = file;
+            mCaptureResult = result;
+            mCharacteristics = characteristics;
+            mContext = context;
+            mReader = reader;
+        }
+
+        @Override
+        public void run() {
+            boolean success = false;
+            int format = mImage.getFormat();
+            switch(format) {
+                case ImageFormat.JPEG: {
+                    ByteBuffer buffer = mImage.getPlanes()[0].getBuffer();
+                    byte[] bytes = new byte[buffer.remaining()];
+                    buffer.get(bytes);
+                    FileOutputStream output = null;
+                    try {
+                        output = new FileOutputStream(mFile);
+                        output.write(bytes);
+                        success = true;
+                    } catch (IOException e) {
+                        e.printStackTrace();
+                    } finally {
+                        mImage.close();
+                        closeOutput(output);
+                    }
+                    break;
+                }
+                case ImageFormat.RAW_SENSOR: {
+                    DngCreator dngCreator = new DngCreator(mCharacteristics, mCaptureResult);
+                    FileOutputStream output = null;
+                    try {
+                        output = new FileOutputStream(mFile);
+                        dngCreator.writeImage(output, mImage);
+                        success = true;
+                    } catch (IOException e) {
+                        e.printStackTrace();
+                    } finally {
+                        mImage.close();
+                        closeOutput(output);
+                    }
+                    break;
+                }
+                default: {
+                    Log.e(TAG, "Cannot save image, unexpected image format:" + format);
+                    break;
+                }
+            }
+
+            // Decrement reference count to allow ImageReader to be closed to free up resources.
+            mReader.close();
+
+            // If saving the file succeeded, update MediaStore.
+            if (success) {
+                MediaScannerConnection.scanFile(mContext, new String[] { mFile.getPath()},
+                /*mimeTypes*/null, new MediaScannerConnection.MediaScannerConnectionClient() {
+                    @Override
+                    public void onMediaScannerConnected() {
+                        // Do nothing
+                    }
+
+                    @Override
+                    public void onScanCompleted(String path, Uri uri) {
+                        Log.i(TAG, "Scanned " + path + ":");
+                        Log.i(TAG, "-> uri=" + uri);
+                    }
+                });
+            }
+        }
+
+        /**
+         * Builder class for constructing {@link ImageSaver}s.
+         *
+         * This class is thread safe.
+         */
+        public static class ImageSaverBuilder {
+            private Image mImage;
+            private File mFile;
+            private CaptureResult mCaptureResult;
+            private CameraCharacteristics mCharacteristics;
+            private Context mContext;
+            private RefCountedAutoCloseable<ImageReader> mReader;
+
+            /**
+             * Construct a new ImageSaverBuilder using the given {@link Context}.
+             * @param context a {@link Context} to for accessing the
+             *                  {@link android.provider.MediaStore}.
+             */
+            public ImageSaverBuilder(final Context context) {
+                mContext = context;
+            }
+
+            public synchronized ImageSaverBuilder setRefCountedReader(
+                    RefCountedAutoCloseable<ImageReader> reader) {
+                if (reader == null ) throw new NullPointerException();
+
+                mReader = reader;
+                return this;
+            }
+
+            public synchronized ImageSaverBuilder setImage(final Image image) {
+                if (image == null) throw new NullPointerException();
+                mImage = image;
+                return this;
+            }
+
+            public synchronized ImageSaverBuilder setFile(final File file) {
+                if (file == null) throw new NullPointerException();
+                mFile = file;
+                return this;
+            }
+
+            public synchronized ImageSaverBuilder setResult(final CaptureResult result) {
+                if (result == null) throw new NullPointerException();
+                mCaptureResult = result;
+                return this;
+            }
+
+            public synchronized ImageSaverBuilder setCharacteristics(
+                    final CameraCharacteristics characteristics) {
+                if (characteristics == null) throw new NullPointerException();
+                mCharacteristics = characteristics;
+                return this;
+            }
+
+            public synchronized ImageSaver buildIfComplete() {
+                if (!isComplete()) {
+                    return null;
+                }
+                return new ImageSaver(mImage, mFile, mCaptureResult, mCharacteristics, mContext,
+                        mReader);
+            }
+
+            public synchronized String getSaveLocation() {
+                return (mFile == null) ? "Unknown" : mFile.toString();
+            }
+
+            private boolean isComplete() {
+                return mImage != null && mFile != null && mCaptureResult != null
+                        && mCharacteristics != null;
+            }
+        }
+    }
+
+    // Utility classes and methods:
+    // *********************************************************************************************
+
+    /**
+     * Comparator based on area of the given {@link Size} objects.
+     */
+    static class CompareSizesByArea implements Comparator<Size> {
+
+        @Override
+        public int compare(Size lhs, Size rhs) {
+            // We cast here to ensure the multiplications won't overflow
+            return Long.signum((long) lhs.getWidth() * lhs.getHeight() -
+                    (long) rhs.getWidth() * rhs.getHeight());
+        }
+
+    }
+
+    /**
+     * A dialog fragment for displaying non-recoverable errors; this {@ling Activity} will be
+     * finished once the dialog has been acknowledged by the user.
+     */
+    public static class ErrorDialog extends DialogFragment {
+
+        private String mErrorMessage;
+
+        public ErrorDialog() {
+            mErrorMessage = "Unknown error occurred!";
+        }
+
+        // Build a dialog with a custom message (Fragments require default constructor).
+        public static ErrorDialog buildErrorDialog(String errorMessage) {
+            ErrorDialog dialog = new ErrorDialog();
+            dialog.mErrorMessage = errorMessage;
+            return dialog;
+        }
+
+        @Override
+        public Dialog onCreateDialog(Bundle savedInstanceState) {
+            final Activity activity = getActivity();
+            return new AlertDialog.Builder(activity)
+                    .setMessage(mErrorMessage)
+                    .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
+                        @Override
+                        public void onClick(DialogInterface dialogInterface, int i) {
+                            activity.finish();
+                        }
+                    })
+                    .create();
+        }
+    }
+
+    /**
+     * A wrapper for an {@link AutoCloseable} object that implements reference counting to allow
+     * for resource management.
+     */
+    public static class RefCountedAutoCloseable<T extends AutoCloseable> implements AutoCloseable {
+        private T mObject;
+        private long mRefCount = 0;
+
+        /**
+         * Wrap the given object.
+         * @param object an object to wrap.
+         */
+        public RefCountedAutoCloseable(T object) {
+            if (object == null) throw new NullPointerException();
+            mObject = object;
+        }
+
+        /**
+         * Increment the reference count and return the wrapped object.
+         *
+         * @return the wrapped object, or null if the object has been released.
+         */
+        public synchronized T getAndRetain() {
+            if (mRefCount < 0) {
+                return null;
+            }
+            mRefCount++;
+            return mObject;
+        }
+
+        /**
+         * Return the wrapped object.
+         *
+         * @return the wrapped object, or null if the object has been released.
+         */
+        public synchronized T get() {
+            return mObject;
+        }
+
+        /**
+         * Decrement the reference count and release the wrapped object if there are no other
+         * users retaining this object.
+         */
+        @Override
+        public synchronized void close() {
+            if (mRefCount >= 0) {
+                mRefCount--;
+                if (mRefCount < 0) {
+                    try {
+                        mObject.close();
+                    } catch (Exception e) {
+                        throw new RuntimeException(e);
+                    } finally {
+                        mObject = null;
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * Given {@code choices} of {@code Size}s supported by a camera, chooses the smallest one whose
+     * width and height are at least as large as the respective requested values, and whose aspect
+     * ratio matches with the specified value.
+     *
+     * @param choices     The list of sizes that the camera supports for the intended output class
+     * @param width       The minimum desired width
+     * @param height      The minimum desired height
+     * @param aspectRatio The aspect ratio
+     * @return The optimal {@code Size}, or an arbitrary one if none were big enough
+     */
+    private static Size chooseOptimalSize(Size[] choices, int width, int height, Size aspectRatio) {
+        // Collect the supported resolutions that are at least as big as the preview Surface
+        List<Size> bigEnough = new ArrayList<>();
+        int w = aspectRatio.getWidth();
+        int h = aspectRatio.getHeight();
+        for (Size option : choices) {
+            if (option.getHeight() == option.getWidth() * h / w &&
+                    option.getWidth() >= width && option.getHeight() >= height) {
+                bigEnough.add(option);
+            }
+        }
+
+        // Pick the smallest of those, assuming we found any
+        if (bigEnough.size() > 0) {
+            return Collections.min(bigEnough, new CompareSizesByArea());
+        } else {
+            Log.e(TAG, "Couldn't find any suitable preview size");
+            return choices[0];
+        }
+    }
+
+    /**
+     * Generate a string containing a formatted timestamp with the current date and time.
+     *
+     * @return a {@link String} representing a time.
+     */
+    private static String generateTimestamp() {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss_SSS", Locale.US);
+        return sdf.format(new Date());
+    }
+
+    /**
+     * Cleanup the given {@link OutputStream}.
+     *
+     * @param outputStream the stream to close.
+     */
+    private static void closeOutput(OutputStream outputStream) {
+        if (null != outputStream) {
+            try {
+                outputStream.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+    /**
+     * Return true if the given array contains the given integer.
+     *
+     * @param modes array to check.
+     * @param mode integer to get for.
+     * @return true if the array contains the given integer, otherwise false.
+     */
+    private static boolean contains(int[] modes, int mode) {
+        if (modes == null) {
+            return false;
+        }
+        for (int i : modes) {
+            if (i == mode) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Return true if the two given {@link Size}s have the same aspect ratio.
+     *
+     * @param a first {@link Size} to compare.
+     * @param b second {@link Size} to compare.
+     * @return true if the sizes have the same aspect ratio, otherwise false.
+     */
+    private static boolean checkAspectsEqual(Size a, Size b) {
+        double aAspect = a.getWidth() / (double) a.getHeight();
+        double bAspect = b.getWidth() / (double) b.getHeight();
+        return Math.abs(aAspect - bAspect) <= ASPECT_RATIO_TOLERANCE;
+    }
+
+    /**
+     * Rotation need to transform from the camera sensor orientation to the device's current
+     * orientation.
+     * @param c the {@link CameraCharacteristics} to query for the camera sensor orientation.
+     * @param deviceOrientation the current device orientation relative to the native device
+     *                          orientation.
+     * @return the total rotation from the sensor orientation to the current device orientation.
+     */
+    private static int sensorToDeviceRotation(CameraCharacteristics c, int deviceOrientation) {
+        int sensorOrientation = c.get(CameraCharacteristics.SENSOR_ORIENTATION);
+
+        // Get device orientation in degrees
+        deviceOrientation = ORIENTATIONS.get(deviceOrientation);
+
+        // Reverse device orientation for front-facing cameras
+        if (c.get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_FRONT) {
+            deviceOrientation = -deviceOrientation;
+        }
+
+        // Calculate desired JPEG orientation relative to camera orientation to make
+        // the image upright relative to the device orientation
+        return (sensorOrientation + deviceOrientation + 360) % 360;
+    }
+
+    /**
+     * Shows a {@link Toast} on the UI thread.
+     *
+     * @param text The message to show.
+     */
+    private void showToast(String text) {
+        // We show a Toast by sending request message to mMessageHandler. This makes sure that the
+        // Toast is shown on the UI thread.
+        Message message = Message.obtain();
+        message.obj = text;
+        mMessageHandler.sendMessage(message);
+    }
+
+    /**
+     * If the given request has been completed, remove it from the queue of active requests and
+     * send an {@link ImageSaver} with the results from this request to a background thread to
+     * save a file.
+     *
+     * Call this only with {@link #mCameraStateLock} held.
+     *
+     * @param requestId the ID of the {@link CaptureRequest} to handle.
+     * @param builder the {@link ImageSaver.ImageSaverBuilder} for this request.
+     * @param queue the queue to remove this request from, if completed.
+     */
+    private void handleCompletionLocked(int requestId, ImageSaver.ImageSaverBuilder builder,
+                                        TreeMap<Integer, ImageSaver.ImageSaverBuilder> queue) {
+        if (builder == null) return;
+        ImageSaver saver = builder.buildIfComplete();
+        if (saver != null) {
+            queue.remove(requestId);
+            AsyncTask.THREAD_POOL_EXECUTOR.execute(saver);
+        }
+    }
+
+    /**
+     * Check if we are using a device that only supports the LEGACY hardware level.
+     *
+     * Call this only with {@link #mCameraStateLock} held.
+     *
+     * @return true if this is a legacy device.
+     */
+    private boolean isLegacyLocked() {
+        return mCharacteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL) ==
+                CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY;
+    }
+
+    /**
+     * Start the timer for the pre-capture sequence.
+     *
+     * Call this only with {@link #mCameraStateLock} held.
+     */
+    private void startTimerLocked() {
+        mCaptureTimer = SystemClock.elapsedRealtime();
+    }
+
+    /**
+     * Check if the timer for the pre-capture sequence has been hit.
+     *
+     * Call this only with {@link #mCameraStateLock} held.
+     *
+     * @return true if the timeout occurred.
+     */
+    private boolean hitTimeoutLocked() {
+        return (SystemClock.elapsedRealtime() - mCaptureTimer) > PRECAPTURE_TIMEOUT_MS;
+    }
+
+    // *********************************************************************************************
+
+}
diff --git a/media/Camera2Raw/Application/src/main/java/com/example/android/camera2raw/CameraActivity.java b/media/Camera2Raw/Application/src/main/java/com/example/android/camera2raw/CameraActivity.java
new file mode 100644
index 0000000..e56efab
--- /dev/null
+++ b/media/Camera2Raw/Application/src/main/java/com/example/android/camera2raw/CameraActivity.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.camera2raw;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+/**
+ * Activity displaying a fragment that implements RAW photo captures.
+ */
+public class CameraActivity extends Activity {
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_camera);
+        if (null == savedInstanceState) {
+            getFragmentManager().beginTransaction()
+                    .replace(R.id.container, Camera2RawFragment.newInstance())
+                    .commit();
+        }
+    }
+
+}
diff --git a/media/Camera2Raw/Application/src/main/res/drawable-hdpi/ic_action_info.png b/media/Camera2Raw/Application/src/main/res/drawable-hdpi/ic_action_info.png
new file mode 100644
index 0000000..32bd1aa
--- /dev/null
+++ b/media/Camera2Raw/Application/src/main/res/drawable-hdpi/ic_action_info.png
Binary files differ
diff --git a/media/Camera2Raw/Application/src/main/res/drawable-hdpi/ic_launcher.png b/media/Camera2Raw/Application/src/main/res/drawable-hdpi/ic_launcher.png
new file mode 100644
index 0000000..bba1165
--- /dev/null
+++ b/media/Camera2Raw/Application/src/main/res/drawable-hdpi/ic_launcher.png
Binary files differ
diff --git a/media/Camera2Raw/Application/src/main/res/drawable-mdpi/ic_action_info.png b/media/Camera2Raw/Application/src/main/res/drawable-mdpi/ic_action_info.png
new file mode 100644
index 0000000..8efbbf8
--- /dev/null
+++ b/media/Camera2Raw/Application/src/main/res/drawable-mdpi/ic_action_info.png
Binary files differ
diff --git a/media/Camera2Raw/Application/src/main/res/drawable-mdpi/ic_launcher.png b/media/Camera2Raw/Application/src/main/res/drawable-mdpi/ic_launcher.png
new file mode 100644
index 0000000..4304591
--- /dev/null
+++ b/media/Camera2Raw/Application/src/main/res/drawable-mdpi/ic_launcher.png
Binary files differ
diff --git a/media/Camera2Raw/Application/src/main/res/drawable-xhdpi/ic_action_info.png b/media/Camera2Raw/Application/src/main/res/drawable-xhdpi/ic_action_info.png
new file mode 100644
index 0000000..ba143ea
--- /dev/null
+++ b/media/Camera2Raw/Application/src/main/res/drawable-xhdpi/ic_action_info.png
Binary files differ
diff --git a/media/Camera2Raw/Application/src/main/res/drawable-xhdpi/ic_launcher.png b/media/Camera2Raw/Application/src/main/res/drawable-xhdpi/ic_launcher.png
new file mode 100644
index 0000000..80c5eba
--- /dev/null
+++ b/media/Camera2Raw/Application/src/main/res/drawable-xhdpi/ic_launcher.png
Binary files differ
diff --git a/media/Camera2Raw/Application/src/main/res/drawable-xxhdpi/ic_action_info.png b/media/Camera2Raw/Application/src/main/res/drawable-xxhdpi/ic_action_info.png
new file mode 100644
index 0000000..394eb7e
--- /dev/null
+++ b/media/Camera2Raw/Application/src/main/res/drawable-xxhdpi/ic_action_info.png
Binary files differ
diff --git a/media/Camera2Raw/Application/src/main/res/drawable-xxhdpi/ic_launcher.png b/media/Camera2Raw/Application/src/main/res/drawable-xxhdpi/ic_launcher.png
new file mode 100644
index 0000000..9baac9b
--- /dev/null
+++ b/media/Camera2Raw/Application/src/main/res/drawable-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/media/Camera2Raw/Application/src/main/res/layout-land/fragment_camera2_basic.xml b/media/Camera2Raw/Application/src/main/res/layout-land/fragment_camera2_basic.xml
new file mode 100644
index 0000000..3eb68db
--- /dev/null
+++ b/media/Camera2Raw/Application/src/main/res/layout-land/fragment_camera2_basic.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+ Copyright 2015 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent">
+
+    <com.example.android.camera2raw.AutoFitTextureView
+        android:id="@+id/texture"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentBottom="true"
+        android:layout_alignParentStart="true"
+        android:layout_alignParentTop="true" />
+
+    <FrameLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_alignParentBottom="true"
+        android:layout_alignParentEnd="true"
+        android:layout_alignParentTop="true"
+        android:layout_below="@id/texture"
+        android:layout_toRightOf="@id/texture"
+        android:background="#4285f4"
+        android:orientation="horizontal">
+
+        <Button
+            android:id="@+id/picture"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center"
+            android:text="@string/picture" />
+
+        <ImageButton
+            android:id="@+id/info"
+            style="@android:style/Widget.Material.Light.Button.Borderless"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center_horizontal|bottom"
+            android:contentDescription="@string/description_info"
+            android:padding="20dp"
+            android:src="@drawable/ic_action_info" />
+
+
+    </FrameLayout>
+
+</RelativeLayout>
diff --git a/media/Camera2Raw/Application/src/main/res/layout/activity_camera.xml b/media/Camera2Raw/Application/src/main/res/layout/activity_camera.xml
new file mode 100644
index 0000000..b6db9a1
--- /dev/null
+++ b/media/Camera2Raw/Application/src/main/res/layout/activity_camera.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+ Copyright 2015 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:id="@+id/container"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:background="#000"
+    tools:context="com.example.android.camera2raw.CameraActivity" />
diff --git a/media/Camera2Raw/Application/src/main/res/layout/fragment_camera2_basic.xml b/media/Camera2Raw/Application/src/main/res/layout/fragment_camera2_basic.xml
new file mode 100644
index 0000000..e8ed001
--- /dev/null
+++ b/media/Camera2Raw/Application/src/main/res/layout/fragment_camera2_basic.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+ Copyright 2015 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent">
+
+    <com.example.android.camera2raw.AutoFitTextureView
+        android:id="@+id/texture"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentStart="true"
+        android:layout_alignParentTop="true" />
+
+    <FrameLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_alignParentBottom="true"
+        android:layout_alignParentStart="true"
+        android:layout_below="@id/texture"
+        android:background="#4285f4">
+
+        <Button
+            android:id="@+id/picture"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center"
+            android:text="@string/picture" />
+
+        <ImageButton
+            android:id="@+id/info"
+            android:contentDescription="@string/description_info"
+            style="@android:style/Widget.Material.Light.Button.Borderless"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center_vertical|right"
+            android:padding="20dp"
+            android:src="@drawable/ic_action_info" />
+
+    </FrameLayout>
+
+</RelativeLayout>
diff --git a/media/Camera2Raw/Application/src/main/res/values/strings.xml b/media/Camera2Raw/Application/src/main/res/values/strings.xml
new file mode 100644
index 0000000..0f56ce9
--- /dev/null
+++ b/media/Camera2Raw/Application/src/main/res/values/strings.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+ Copyright 2015 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<resources>
+    <string name="picture">Picture</string>
+    <string name="description_info">Info</string>
+</resources>
diff --git a/media/Camera2Raw/Application/src/main/res/values/styles.xml b/media/Camera2Raw/Application/src/main/res/values/styles.xml
new file mode 100644
index 0000000..34d16bd
--- /dev/null
+++ b/media/Camera2Raw/Application/src/main/res/values/styles.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+ Copyright 2015 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<resources>
+    <style name="MaterialTheme" parent="android:Theme.Material.Light.NoActionBar.Fullscreen" />
+</resources>
diff --git a/media/Camera2Raw/Application/tests/AndroidManifest.xml b/media/Camera2Raw/Application/tests/AndroidManifest.xml
new file mode 100644
index 0000000..4954d03
--- /dev/null
+++ b/media/Camera2Raw/Application/tests/AndroidManifest.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  Copyright (C) 2013 The Android Open Source Project
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+  -->
+<!-- package name must be unique so suffix with "tests" so package loader doesn't ignore us -->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+          package="com.example.android.camera2raw.tests"
+          android:versionCode="1"
+          android:versionName="1.0">
+
+    <!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle -->
+
+    <!-- We add an application tag here just so that we can indicate that
+         this package needs to link against the android.test library,
+         which is needed when building test cases. -->
+    <application>
+        <uses-library android:name="android.test.runner" />
+    </application>
+
+    <!--
+    Specifies the instrumentation test runner used to run the tests.
+    -->
+    <instrumentation
+            android:name="android.test.InstrumentationTestRunner"
+            android:targetPackage="com.example.android.camera2raw"
+            android:label="Tests for com.example.android.camera2raw" />
+
+</manifest>
diff --git a/media/Camera2Raw/Application/tests/src/com/example/android/camera2raw/tests/SampleTests.java b/media/Camera2Raw/Application/tests/src/com/example/android/camera2raw/tests/SampleTests.java
new file mode 100644
index 0000000..d4bdb63
--- /dev/null
+++ b/media/Camera2Raw/Application/tests/src/com/example/android/camera2raw/tests/SampleTests.java
@@ -0,0 +1,57 @@
+/*
+* Copyright (C) 2015 The Android Open Source Project
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package com.example.android.camera2raw.tests;
+
+import com.example.android.camera2raw.*;
+
+import android.test.ActivityInstrumentationTestCase2;
+
+/**
+* Tests for Camera2Raw sample.
+*/
+public class SampleTests extends ActivityInstrumentationTestCase2<CameraActivity> {
+
+    private CameraActivity mTestActivity;
+
+    public SampleTests() {
+        super(CameraActivity.class);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        // Starts the activity under test using the default Intent with:
+        // action = {@link Intent#ACTION_MAIN}
+        // flags = {@link Intent#FLAG_ACTIVITY_NEW_TASK}
+        // All other fields are null or empty.
+        mTestActivity = getActivity();
+    }
+
+    /**
+    * Test if the test fixture has been set up correctly.
+    */
+    public void testPreconditions() {
+        //Try to add a message to add context to your assertions. These messages will be shown if
+        //a tests fails and make it easy to understand why a test failed
+        assertNotNull("mTestActivity is null", mTestActivity);
+    }
+
+    /**
+    * Add more tests below.
+    */
+
+}
diff --git a/media/Camera2Raw/CONTRIB.md b/media/Camera2Raw/CONTRIB.md
new file mode 100644
index 0000000..14a4fcf
--- /dev/null
+++ b/media/Camera2Raw/CONTRIB.md
@@ -0,0 +1,35 @@
+# How to become a contributor and submit your own code
+
+## Contributor License Agreements
+
+We'd love to accept your sample apps and patches! Before we can take them, we
+have to jump a couple of legal hurdles.
+
+Please fill out either the individual or corporate Contributor License Agreement (CLA).
+
+  * If you are an individual writing original source code and you're sure you
+    own the intellectual property, then you'll need to sign an [individual CLA]
+    (https://developers.google.com/open-source/cla/individual).
+  * If you work for a company that wants to allow you to contribute your work,
+    then you'll need to sign a [corporate CLA]
+    (https://developers.google.com/open-source/cla/corporate).
+
+Follow either of the two links above to access the appropriate CLA and
+instructions for how to sign and return it. Once we receive it, we'll be able to
+accept your pull requests.
+
+## Contributing A Patch
+
+1. Submit an issue describing your proposed change to the repo in question.
+1. The repo owner will respond to your issue promptly.
+1. If your proposed change is accepted, and you haven't already done so, sign a
+   Contributor License Agreement (see details above).
+1. Fork the desired repo, develop and test your code changes.
+1. Ensure that your code adheres to the existing style in the sample to which
+   you are contributing. Refer to the
+   [Android Code Style Guide]
+   (https://source.android.com/source/code-style.html) for the
+   recommended coding standards for this organization.
+1. Ensure that your code has an appropriate set of unit tests which all pass.
+1. Submit a pull request.
+
diff --git a/media/Camera2Raw/build.gradle b/media/Camera2Raw/build.gradle
new file mode 100644
index 0000000..c7a137e
--- /dev/null
+++ b/media/Camera2Raw/build.gradle
@@ -0,0 +1,10 @@
+// BEGIN_EXCLUDE
+import com.example.android.samples.build.SampleGenPlugin
+apply plugin: SampleGenPlugin
+
+samplegen {
+  pathToBuild "../../../../build"
+  pathToSamplesCommon "../../common"
+}
+apply from: "../../../../build/build.gradle"
+// END_EXCLUDE
diff --git a/media/Camera2Raw/buildSrc/build.gradle b/media/Camera2Raw/buildSrc/build.gradle
new file mode 100644
index 0000000..29282af
--- /dev/null
+++ b/media/Camera2Raw/buildSrc/build.gradle
@@ -0,0 +1,18 @@
+
+
+
+repositories {
+    mavenCentral()
+}
+dependencies {
+    compile 'org.freemarker:freemarker:2.3.20'
+}
+
+sourceSets {
+    main {
+        groovy {
+            srcDir new File(rootDir, "../../../../../build/buildSrc/src/main/groovy")
+        }
+    }
+}
+
diff --git a/media/Camera2Raw/gradle/wrapper/gradle-wrapper.jar b/media/Camera2Raw/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000..8c0fb64
--- /dev/null
+++ b/media/Camera2Raw/gradle/wrapper/gradle-wrapper.jar
Binary files differ
diff --git a/media/Camera2Raw/gradle/wrapper/gradle-wrapper.properties b/media/Camera2Raw/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..0c71e76
--- /dev/null
+++ b/media/Camera2Raw/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Wed Apr 10 15:27:10 PDT 2013
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
diff --git a/media/Camera2Raw/gradlew b/media/Camera2Raw/gradlew
new file mode 100755
index 0000000..91a7e26
--- /dev/null
+++ b/media/Camera2Raw/gradlew
@@ -0,0 +1,164 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+##  Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+    echo "$*"
+}
+
+die ( ) {
+    echo
+    echo "$*"
+    echo
+    exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+  CYGWIN* )
+    cygwin=true
+    ;;
+  Darwin* )
+    darwin=true
+    ;;
+  MINGW* )
+    msys=true
+    ;;
+esac
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched.
+if $cygwin ; then
+    [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+    ls=`ls -ld "$PRG"`
+    link=`expr "$ls" : '.*-> \(.*\)$'`
+    if expr "$link" : '/.*' > /dev/null; then
+        PRG="$link"
+    else
+        PRG=`dirname "$PRG"`"/$link"
+    fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >&-
+APP_HOME="`pwd -P`"
+cd "$SAVED" >&-
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+        # IBM's JDK on AIX uses strange locations for the executables
+        JAVACMD="$JAVA_HOME/jre/sh/java"
+    else
+        JAVACMD="$JAVA_HOME/bin/java"
+    fi
+    if [ ! -x "$JAVACMD" ] ; then
+        die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+    fi
+else
+    JAVACMD="java"
+    which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+    MAX_FD_LIMIT=`ulimit -H -n`
+    if [ $? -eq 0 ] ; then
+        if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+            MAX_FD="$MAX_FD_LIMIT"
+        fi
+        ulimit -n $MAX_FD
+        if [ $? -ne 0 ] ; then
+            warn "Could not set maximum file descriptor limit: $MAX_FD"
+        fi
+    else
+        warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+    fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+    GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+    APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+    CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
+    # We build the pattern for arguments to be converted via cygpath
+    ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+    SEP=""
+    for dir in $ROOTDIRSRAW ; do
+        ROOTDIRS="$ROOTDIRS$SEP$dir"
+        SEP="|"
+    done
+    OURCYGPATTERN="(^($ROOTDIRS))"
+    # Add a user-defined pattern to the cygpath arguments
+    if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+        OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+    fi
+    # Now convert the arguments - kludge to limit ourselves to /bin/sh
+    i=0
+    for arg in "$@" ; do
+        CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+        CHECK2=`echo "$arg"|egrep -c "^-"`                                 ### Determine if an option
+
+        if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then                    ### Added a condition
+            eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+        else
+            eval `echo args$i`="\"$arg\""
+        fi
+        i=$((i+1))
+    done
+    case $i in
+        (0) set -- ;;
+        (1) set -- "$args0" ;;
+        (2) set -- "$args0" "$args1" ;;
+        (3) set -- "$args0" "$args1" "$args2" ;;
+        (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+        (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+        (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+        (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+        (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+        (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+    esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+    JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/media/Camera2Raw/gradlew.bat b/media/Camera2Raw/gradlew.bat
new file mode 100644
index 0000000..aec9973
--- /dev/null
+++ b/media/Camera2Raw/gradlew.bat
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off

+@rem ##########################################################################

+@rem

+@rem  Gradle startup script for Windows

+@rem

+@rem ##########################################################################

+

+@rem Set local scope for the variables with windows NT shell

+if "%OS%"=="Windows_NT" setlocal

+

+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.

+set DEFAULT_JVM_OPTS=

+

+set DIRNAME=%~dp0

+if "%DIRNAME%" == "" set DIRNAME=.

+set APP_BASE_NAME=%~n0

+set APP_HOME=%DIRNAME%

+

+@rem Find java.exe

+if defined JAVA_HOME goto findJavaFromJavaHome

+

+set JAVA_EXE=java.exe

+%JAVA_EXE% -version >NUL 2>&1

+if "%ERRORLEVEL%" == "0" goto init

+

+echo.

+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

+echo.

+echo Please set the JAVA_HOME variable in your environment to match the

+echo location of your Java installation.

+

+goto fail

+

+:findJavaFromJavaHome

+set JAVA_HOME=%JAVA_HOME:"=%

+set JAVA_EXE=%JAVA_HOME%/bin/java.exe

+

+if exist "%JAVA_EXE%" goto init

+

+echo.

+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%

+echo.

+echo Please set the JAVA_HOME variable in your environment to match the

+echo location of your Java installation.

+

+goto fail

+

+:init

+@rem Get command-line arguments, handling Windowz variants

+

+if not "%OS%" == "Windows_NT" goto win9xME_args

+if "%@eval[2+2]" == "4" goto 4NT_args

+

+:win9xME_args

+@rem Slurp the command line arguments.

+set CMD_LINE_ARGS=

+set _SKIP=2

+

+:win9xME_args_slurp

+if "x%~1" == "x" goto execute

+

+set CMD_LINE_ARGS=%*

+goto execute

+

+:4NT_args

+@rem Get arguments from the 4NT Shell from JP Software

+set CMD_LINE_ARGS=%$

+

+:execute

+@rem Setup the command line

+

+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

+

+@rem Execute Gradle

+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%

+

+:end

+@rem End local scope for the variables with windows NT shell

+if "%ERRORLEVEL%"=="0" goto mainEnd

+

+:fail

+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of

+rem the _cmd.exe /c_ return code!

+if  not "" == "%GRADLE_EXIT_CONSOLE%" exit 1

+exit /b 1

+

+:mainEnd

+if "%OS%"=="Windows_NT" endlocal

+

+:omega

diff --git a/media/Camera2Raw/packaging.yaml b/media/Camera2Raw/packaging.yaml
new file mode 100644
index 0000000..042cd50
--- /dev/null
+++ b/media/Camera2Raw/packaging.yaml
@@ -0,0 +1,15 @@
+# GOOGLE SAMPLE PACKAGING DATA
+#
+# This file is used by Google as part of our samples packaging process.
+# End users may safely ignore this file. It has no relevance to other systems.
+---
+
+status:       PUBLISHED
+technologies: [Android]
+categories:   [Media]
+languages:    [Java]
+solutions:    [Mobile]
+github:       googlesamples/android-Camera2Raw
+level:        BEGINNER
+icon:         Camera2RawSample/src/main/res/drawable-xxhdpi/ic_launcher.png
+license:      apache2
diff --git a/media/Camera2Raw/screenshots/icon-web.png b/media/Camera2Raw/screenshots/icon-web.png
new file mode 100644
index 0000000..d9bd4c4
--- /dev/null
+++ b/media/Camera2Raw/screenshots/icon-web.png
Binary files differ
diff --git a/media/Camera2Raw/screenshots/main.png b/media/Camera2Raw/screenshots/main.png
new file mode 100644
index 0000000..47419eb
--- /dev/null
+++ b/media/Camera2Raw/screenshots/main.png
Binary files differ
diff --git a/media/Camera2Raw/settings.gradle b/media/Camera2Raw/settings.gradle
new file mode 100644
index 0000000..9464a35
--- /dev/null
+++ b/media/Camera2Raw/settings.gradle
@@ -0,0 +1 @@
+include 'Application'
diff --git a/media/Camera2Raw/template-params.xml b/media/Camera2Raw/template-params.xml
new file mode 100644
index 0000000..3d735e8
--- /dev/null
+++ b/media/Camera2Raw/template-params.xml
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2015 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<sample>
+    <name>Camera2Raw</name>
+    <group>Media</group>
+    <package>com.example.android.camera2raw</package>
+    <minSdk>21</minSdk>
+    <compileSdkVersion>21</compileSdkVersion>
+    <strings>
+        <intro>
+            <![CDATA[
+            This sample demonstrates how to use the Camera2 API to capture RAW
+            camera buffers and save them as DNG files.
+            ]]>
+        </intro>
+    </strings>
+
+    <template src="base"/>
+
+        <metadata>
+        <status>PUBLISHED</status>
+        <categories>Media, Camera, Camera2</categories>
+        <technologies>Android</technologies>
+        <languages>Java</languages>
+        <solutions>Mobile</solutions>
+        <level>INTERMEDIATE</level>
+        <icon>screenshots/icon-web.png</icon>
+        <screenshots>
+            <img>screenshots/main.png</img>
+        </screenshots>
+        <api_refs>
+            <android>android.hardware.camera2.DngCreator</android>
+        </api_refs>
+
+        <description>
+<![CDATA[
+This sample demonstrates using the Camera2 API to capture a JPEG and RAW sensor frame.
+Check the source code to see a typical example of how to display the camera preview;
+run auto-focus, auto-exposure metering, and auto-white-balance; capture a JPEG and
+RAW image for the same sensor frame; and save these into MediaStore for use in other
+applications.
+]]>
+        </description>
+
+        <intro>
+<![CDATA[
+The [Camera2 API][1] allows users to capture RAW images, i.e. unprocessed pixel data
+directly from the camera sensor that has not yet been converted into a format and
+colorspace typically used for displaying and storing images viewed by humans.  The
+[DngCreator][2] class is provided as part of the Camera2 API as a utility for saving
+RAW images as DNG files.
+
+This sample displays a live camera preview in a TextureView, and saves JPEG and DNG
+file for each image captured.
+
+[1]: https://developer.android.com/reference/android/hardware/camera2/package-summary.html
+[2]: https://developer.android.com/reference/android/hardware/camera2/DngCreator.html
+]]>
+        </intro>
+    </metadata>
+
+</sample>
diff --git a/media/MediaRecorder/template-params.xml b/media/MediaRecorder/template-params.xml
index fa4a165..a057637 100644
--- a/media/MediaRecorder/template-params.xml
+++ b/media/MediaRecorder/template-params.xml
@@ -18,7 +18,7 @@
     <name>MediaRecorder</name>
     <group>Media</group>
     <package>com.example.android.mediarecorder</package>
-    <minSdk>14</minSdk>
+    <minSdk>16</minSdk>
     <strings>
         <intro>
 <![CDATA[
diff --git a/renderScript/BasicRenderScript/template-params.xml b/renderScript/BasicRenderScript/template-params.xml
index d0d3be2..9f0c558 100644
--- a/renderScript/BasicRenderScript/template-params.xml
+++ b/renderScript/BasicRenderScript/template-params.xml
@@ -23,7 +23,7 @@
     <package>com.example.android.basicrenderscript</package>
 
     <!-- change minSdk if needed-->
-    <minSdk>8</minSdk>
+    <minSdk>16</minSdk>
 
     <dependency_external>'renderscript-v8.jar'</dependency_external>
 
diff --git a/renderScript/RenderScriptIntrinsic/template-params.xml b/renderScript/RenderScriptIntrinsic/template-params.xml
index 8b80bb2..a2a9370 100644
--- a/renderScript/RenderScriptIntrinsic/template-params.xml
+++ b/renderScript/RenderScriptIntrinsic/template-params.xml
@@ -21,7 +21,7 @@
     <package>com.example.android.renderscriptintrinsic</package>
 
     <!-- change minSdk if needed-->
-    <minSdk>8</minSdk>
+    <minSdk>13</minSdk>
 
     <dependency_external>'renderscript-v8.jar'</dependency_external>
 
diff --git a/ui/actionbarcompat/ActionBarCompat-ListViewModalSelect/template-params.xml b/ui/actionbarcompat/ActionBarCompat-ListViewModalSelect/template-params.xml
index 03f6877..3c7e83a 100644
--- a/ui/actionbarcompat/ActionBarCompat-ListViewModalSelect/template-params.xml
+++ b/ui/actionbarcompat/ActionBarCompat-ListViewModalSelect/template-params.xml
@@ -25,7 +25,7 @@
     <dependency>com.android.support:appcompat-v7:21.0.2</dependency>
 
     <!-- change minSdk if needed-->
-    <minSdk>7</minSdk>
+    <minSdk>8</minSdk>
 
     <strings>
         <intro>
diff --git a/ui/views/NavigationDrawer/template-params.xml b/ui/views/NavigationDrawer/template-params.xml
index af92a68..559f32e 100644
--- a/ui/views/NavigationDrawer/template-params.xml
+++ b/ui/views/NavigationDrawer/template-params.xml
@@ -25,7 +25,7 @@
     <auto_add_support_lib>false</auto_add_support_lib>
 
     <!-- change minSdk if needed-->
-    <minSdk>14</minSdk>
+    <minSdk>21</minSdk>
     <compileSdkVersion>21</compileSdkVersion>
 
 
diff --git a/ui/views/SlidingTabs/SlidingTabsBasic/template-params.xml b/ui/views/SlidingTabs/SlidingTabsBasic/template-params.xml
index 7d6c97f..fe39dab 100644
--- a/ui/views/SlidingTabs/SlidingTabsBasic/template-params.xml
+++ b/ui/views/SlidingTabs/SlidingTabsBasic/template-params.xml
@@ -23,7 +23,7 @@
     <package>com.example.android.slidingtabsbasic</package>
 
     <!-- change minSdk if needed-->
-    <minSdk>4</minSdk>
+    <minSdk>14</minSdk>
 
 
     <strings>
diff --git a/ui/views/SlidingTabs/SlidingTabsColors/template-params.xml b/ui/views/SlidingTabs/SlidingTabsColors/template-params.xml
index ecdad8c..752927b 100644
--- a/ui/views/SlidingTabs/SlidingTabsColors/template-params.xml
+++ b/ui/views/SlidingTabs/SlidingTabsColors/template-params.xml
@@ -24,7 +24,7 @@
 
 
     <!-- change minSdk if needed-->
-    <minSdk>4</minSdk>
+    <minSdk>14</minSdk>
 
 
     <strings>
diff --git a/ui/views/SwipeRefreshLayout/SwipeRefreshLayoutBasic/template-params.xml b/ui/views/SwipeRefreshLayout/SwipeRefreshLayoutBasic/template-params.xml
index 0b99bcc..ddce9d1 100644
--- a/ui/views/SwipeRefreshLayout/SwipeRefreshLayoutBasic/template-params.xml
+++ b/ui/views/SwipeRefreshLayout/SwipeRefreshLayoutBasic/template-params.xml
@@ -23,7 +23,7 @@
     <package>com.example.android.swiperefreshlayoutbasic</package>
 
     <!-- change minSdk if needed-->
-    <minSdk>10</minSdk>
+    <minSdk>14</minSdk>
 
     <strings>
         <intro>
diff --git a/ui/views/SwipeRefreshLayout/SwipeRefreshListFragment/template-params.xml b/ui/views/SwipeRefreshLayout/SwipeRefreshListFragment/template-params.xml
index 4210182..13230a5 100644
--- a/ui/views/SwipeRefreshLayout/SwipeRefreshListFragment/template-params.xml
+++ b/ui/views/SwipeRefreshLayout/SwipeRefreshListFragment/template-params.xml
@@ -21,7 +21,7 @@
     <name>SwipeRefreshListFragment</name>
     <group>UI</group>
     <package>com.example.android.swiperefreshlistfragment</package>
-    <minSdk>10</minSdk>
+    <minSdk>14</minSdk>
     <strings>
         <intro>
             <![CDATA[
diff --git a/ui/views/SwipeRefreshLayout/SwipeRefreshMultipleViews/template-params.xml b/ui/views/SwipeRefreshLayout/SwipeRefreshMultipleViews/template-params.xml
index bb0054b..ad1ad5e 100644
--- a/ui/views/SwipeRefreshLayout/SwipeRefreshMultipleViews/template-params.xml
+++ b/ui/views/SwipeRefreshLayout/SwipeRefreshMultipleViews/template-params.xml
@@ -23,7 +23,7 @@
     <package>com.example.android.swiperefreshmultipleviews</package>
 
     <!-- change minSdk if needed-->
-    <minSdk>10</minSdk>
+    <minSdk>14</minSdk>
     <strings>
         <intro>
             <![CDATA[
diff --git a/ui/window/ImmersiveMode/template-params.xml b/ui/window/ImmersiveMode/template-params.xml
index 8959099..da1e511 100644
--- a/ui/window/ImmersiveMode/template-params.xml
+++ b/ui/window/ImmersiveMode/template-params.xml
@@ -20,7 +20,7 @@
     <package>com.example.android.immersivemode</package>
     
     <!--TODO: change minSdk if needed-->
-    <minSdk>4</minSdk>
+    <minSdk>11</minSdk>
 
 
     <strings>
diff --git a/wearable/wear/AgendaData/Application/src/main/java/com/example/android/wearable/agendadata/MainActivity.java b/wearable/wear/AgendaData/Application/src/main/java/com/example/android/wearable/agendadata/MainActivity.java
index 8e4063d..62dc349 100644
--- a/wearable/wear/AgendaData/Application/src/main/java/com/example/android/wearable/agendadata/MainActivity.java
+++ b/wearable/wear/AgendaData/Application/src/main/java/com/example/android/wearable/agendadata/MainActivity.java
@@ -96,28 +96,33 @@
                     .setResultCallback(new ResultCallback<DataItemBuffer>() {
                         @Override
                         public void onResult(DataItemBuffer result) {
-                            if (result.getStatus().isSuccess()) {
-                                deleteDataItems(result);
-                            } else {
-                                if (Log.isLoggable(TAG, Log.DEBUG)) {
-                                    Log.d(TAG, "onDeleteEventsClicked(): failed to get Data Items");
+                            try {
+                                if (result.getStatus().isSuccess()) {
+                                    // Store the DataItem URIs in a List and release the buffer.
+                                    // Then use these URIs to delete the DataItems.
+                                    List<DataItem> dataItemList = FreezableUtils
+                                            .freezeIterable(result);
+                                    deleteDataItems(dataItemList);
+                                } else {
+                                    if (Log.isLoggable(TAG, Log.DEBUG)) {
+                                        Log.d(TAG,"onDeleteEventsClicked(): failed to get Data "
+                                                + "Items");
+
+                                    }
                                 }
+                            } finally {
+                                result.release();
                             }
-                            result.close();
                         }
                     });
         } else {
             Log.e(TAG, "Failed to delete data items"
-                     + " - Client disconnected from Google Play Services");
+                    + " - Client disconnected from Google Play Services");
         }
     }
 
-    private void deleteDataItems(DataItemBuffer dataItems) {
+    private void deleteDataItems(final List<DataItem> dataItemList) {
         if (mGoogleApiClient.isConnected()) {
-            // Store the DataItem URIs in a List and close the buffer. Then use these URIs
-            // to delete the DataItems.
-            final List<DataItem> dataItemList = FreezableUtils.freezeIterable(dataItems);
-            dataItems.close();
             for (final DataItem dataItem : dataItemList) {
                 final Uri dataItemUri = dataItem.getUri();
                 // In a real calendar application, this might delete the corresponding calendar
diff --git a/wearable/wear/AlwaysOn/Wearable/src/main/AndroidManifest.xml b/wearable/wear/AlwaysOn/Wearable/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..12c4b03
--- /dev/null
+++ b/wearable/wear/AlwaysOn/Wearable/src/main/AndroidManifest.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+          package="com.example.android.wearable.wear.alwayson">
+
+    <uses-sdk android:minSdkVersion="20" android:targetSdkVersion="22" />
+
+    <uses-permission android:name="android.permission.WAKE_LOCK" />
+    <uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
+
+    <uses-feature android:name="android.hardware.type.watch" />
+
+    <application
+        android:allowBackup="false"
+        android:label="@string/app_name">
+
+        <!--If you want your app to run on pre-22, then set required to false -->
+        <uses-library android:name="com.google.android.wearable" android:required="false" />
+
+        <!--
+            To update the screen more than once per minute in ambient mode, developers should set
+            the launch mode for the activity to single instance. Otherwise, the AlarmManager launch
+            intent will open a new activity every time the Alarm is triggered rather than reusing
+            the same (already active) Activity.
+        -->
+        <activity android:name="com.example.android.wearable.wear.alwayson.MainActivity"
+            android:label="@string/app_name"
+            android:launchMode="singleInstance"
+            android:configChanges="orientation|keyboardHidden"
+            android:exported="true">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+
+    </application>
+</manifest>
diff --git a/wearable/wear/AlwaysOn/Wearable/src/main/java/com/example/android/wearable/wear/alwayson/MainActivity.java b/wearable/wear/AlwaysOn/Wearable/src/main/java/com/example/android/wearable/wear/alwayson/MainActivity.java
new file mode 100644
index 0000000..3673545
--- /dev/null
+++ b/wearable/wear/AlwaysOn/Wearable/src/main/java/com/example/android/wearable/wear/alwayson/MainActivity.java
@@ -0,0 +1,336 @@
+/*
+ * Copyright (C) 2015 Google Inc. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.example.android.wearable.wear.alwayson;
+
+import android.app.AlarmManager;
+import android.app.PendingIntent;
+import android.content.Context;
+import android.content.Intent;
+import android.graphics.Color;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.support.wearable.activity.WearableActivity;
+import android.support.wearable.view.WatchViewStub;
+import android.util.Log;
+import android.widget.TextView;
+
+import java.lang.ref.WeakReference;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Demonstrates support for Ambient screens by extending WearableActivity and overriding
+ * onEnterAmbient, onUpdateAmbient, and onExitAmbient.
+ *
+ * There are two modes (Active and Ambient). To trigger future updates (data/screen), we use a
+ * custom Handler for the "Active" mode and an Alarm for the "Ambient" mode.
+ *
+ * Why don't we use just one? Handlers are generally less battery intensive and can be triggered
+ * every second. However, they can not wake up the processor (common in Ambient mode).
+ *
+ * Alarms can wake up the processor (what we need for Ambient), but they struggle with quick updates
+ * (less than one second) and are much less efficient compared to Handlers.
+ *
+ * Therefore, we use Handlers for "Active" mode (can trigger every second and are better on the
+ * battery), and we use Alarms for "Ambient" mode (only need to update once every 20 seconds and
+ * they can wake up a sleeping processor).
+ *
+ * Again, the Activity waits 20 seconds between doing any processing (getting data, updating screen
+ * etc.) while in ambient mode to conserving battery life (processor allowed to sleep). If you can
+ * hold off on updates for a full minute, you can throw away all the Alarm code and just use
+ * onUpdateAmbient() to save even more battery life.
+ *
+ * As always, you will still want to apply the performance guidelines outlined in the Watch Faces
+ * documention to your app.
+ *
+ * Finally, in ambient mode, this Activity follows the same best practices outlined in the
+ * Watch Faces API documentation, e.g., keep most pixels black, avoid large blocks of white pixels,
+ * use only black and white, and disable anti-aliasing.
+ *
+ */
+public class MainActivity extends WearableActivity {
+
+    private static final String TAG = "MainActivity";
+
+    /** Custom 'what' for Message sent to Handler. */
+    private static final int MSG_UPDATE_SCREEN = 0;
+
+    /** Milliseconds between updates based on state. */
+    private static final long ACTIVE_INTERVAL_MS = TimeUnit.SECONDS.toMillis(1);
+    private static final long AMBIENT_INTERVAL_MS = TimeUnit.SECONDS.toMillis(20);
+
+    /** Tracks latest ambient details, such as burnin offsets, etc. */
+    private Bundle mAmbientDetails;
+
+    private TextView mTimeTextView;
+    private TextView mTimeStampTextView;
+    private TextView mStateTextView;
+    private TextView mUpdateRateTextView;
+    private TextView mDrawCountTextView;
+
+    private final SimpleDateFormat sDateFormat =
+            new SimpleDateFormat("HH:mm:ss", Locale.US);
+
+    private volatile int mDrawCount = 0;
+
+
+    /**
+     * Since the handler (used in active mode) can't wake up the processor when the device is in
+     * ambient mode and undocked, we use an Alarm to cover ambient mode updates when we need them
+     * more frequently than every minute. Remember, if getting updates once a minute in ambient
+     * mode is enough, you can do away with the Alarm code and just rely on the onUpdateAmbient()
+     * callback.
+     */
+    private AlarmManager mAmbientStateAlarmManager;
+    private PendingIntent mAmbientStatePendingIntent;
+
+    /**
+     * This custom handler is used for updates in "Active" mode. We use a separate static class to
+     * help us avoid memory leaks.
+     */
+    private final Handler mActiveModeUpdateHandler = new UpdateHandler(this);
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        Log.d(TAG, "onCreate()");
+        super.onCreate(savedInstanceState);
+
+        setContentView(R.layout.activity_main);
+
+        setAmbientEnabled();
+
+        mAmbientStateAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
+        Intent ambientStateIntent = new Intent(getApplicationContext(), MainActivity.class);
+
+        mAmbientStatePendingIntent = PendingIntent.getActivity(
+                getApplicationContext(),
+                0 /* requestCode */,
+                ambientStateIntent,
+                PendingIntent.FLAG_UPDATE_CURRENT);
+
+
+        /** Determines whether watch is round or square and applies proper view. **/
+        final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
+        stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
+            @Override
+            public void onLayoutInflated(WatchViewStub stub) {
+
+                mTimeTextView = (TextView) stub.findViewById(R.id.time);
+                mTimeStampTextView = (TextView) stub.findViewById(R.id.time_stamp);
+                mStateTextView = (TextView) stub.findViewById(R.id.state);
+                mUpdateRateTextView = (TextView) stub.findViewById(R.id.update_rate);
+                mDrawCountTextView = (TextView) stub.findViewById(R.id.draw_count);
+
+                refreshDisplayAndSetNextUpdate();
+            }
+        });
+    }
+
+    /**
+     * This is mostly triggered by the Alarms we set in Ambient mode and informs us we need to
+     * update the screen (and process any data).
+     */
+    @Override
+    public void onNewIntent(Intent intent) {
+        Log.d(TAG, "onNewIntent(): " + intent);
+        super.onNewIntent(intent);
+
+        setIntent(intent);
+
+        refreshDisplayAndSetNextUpdate();
+    }
+
+    @Override
+    public void onDestroy() {
+        Log.d(TAG, "onDestroy()");
+
+        mActiveModeUpdateHandler.removeMessages(MSG_UPDATE_SCREEN);
+        mAmbientStateAlarmManager.cancel(mAmbientStatePendingIntent);
+
+        super.onDestroy();
+    }
+
+    /**
+     * Prepares UI for Ambient view.
+     */
+    @Override
+    public void onEnterAmbient(Bundle ambientDetails) {
+        Log.d(TAG, "onEnterAmbient()");
+        super.onEnterAmbient(ambientDetails);
+
+        /**
+         * In this sample, we aren't using the ambient details bundle (EXTRA_BURN_IN_PROTECTION or
+         * EXTRA_LOWBIT_AMBIENT), but if you need them, you can pull them from the local variable
+         * set here.
+         */
+        mAmbientDetails = ambientDetails;
+
+        /** Clears Handler queue (only needed for updates in active mode). */
+        mActiveModeUpdateHandler.removeMessages(MSG_UPDATE_SCREEN);
+
+        /**
+         * Following best practices outlined in WatchFaces API (keeping most pixels black,
+         * avoiding large blocks of white pixels, using only black and white,
+         * and disabling anti-aliasing anti-aliasing, etc.)
+         */
+        mStateTextView.setTextColor(Color.WHITE);
+        mUpdateRateTextView.setTextColor(Color.WHITE);
+        mDrawCountTextView.setTextColor(Color.WHITE);
+
+        mTimeTextView.getPaint().setAntiAlias(false);
+        mTimeStampTextView.getPaint().setAntiAlias(false);
+        mStateTextView.getPaint().setAntiAlias(false);
+        mUpdateRateTextView.getPaint().setAntiAlias(false);
+        mDrawCountTextView.getPaint().setAntiAlias(false);
+
+        refreshDisplayAndSetNextUpdate();
+    }
+
+    /**
+     * Updates UI in Ambient view (once a minute). Because we need to update UI sooner than that
+     * (every ~20 seconds), we also use an Alarm. However, since the processor is awake for this
+     * callback, we might as well call refreshDisplayAndSetNextUpdate() to update screen and reset
+     * the Alarm.
+     *
+     * If you are happy with just updating the screen once a minute in Ambient Mode (which will be
+     * the case a majority of the time), then you can just use this method and remove all
+     * references/code regarding Alarms.
+     */
+    @Override
+    public void onUpdateAmbient() {
+        Log.d(TAG, "onUpdateAmbient()");
+        super.onUpdateAmbient();
+
+        refreshDisplayAndSetNextUpdate();
+    }
+
+    /**
+     * Prepares UI for Active view (non-Ambient).
+     */
+    @Override
+    public void onExitAmbient() {
+        Log.d(TAG, "onExitAmbient()");
+        super.onExitAmbient();
+
+        /** Clears out Alarms since they are only used in ambient mode. */
+        mAmbientStateAlarmManager.cancel(mAmbientStatePendingIntent);
+
+        mStateTextView.setTextColor(Color.GREEN);
+        mUpdateRateTextView.setTextColor(Color.GREEN);
+        mDrawCountTextView.setTextColor(Color.GREEN);
+
+        mTimeTextView.getPaint().setAntiAlias(true);
+        mTimeStampTextView.getPaint().setAntiAlias(true);
+        mStateTextView.getPaint().setAntiAlias(true);
+        mUpdateRateTextView.getPaint().setAntiAlias(true);
+        mDrawCountTextView.getPaint().setAntiAlias(true);
+
+        refreshDisplayAndSetNextUpdate();
+    }
+
+    /**
+     * Loads data/updates screen (via method), but most importantly, sets up the next refresh
+     * (active mode = Handler and ambient mode = Alarm).
+     */
+    private void refreshDisplayAndSetNextUpdate() {
+
+        loadDataAndUpdateScreen();
+
+        long timeMs = System.currentTimeMillis();
+
+        if (isAmbient()) {
+            /** Calculate next trigger time (based on state). */
+            long delayMs = AMBIENT_INTERVAL_MS - (timeMs % AMBIENT_INTERVAL_MS);
+            long triggerTimeMs = timeMs + delayMs;
+
+            /**
+             * Note: Make sure you have set activity launchMode to singleInstance in the manifest.
+             * Otherwise, it is easy for the AlarmManager launch intent to open a new activity
+             * every time the Alarm is triggered rather than reusing this Activity.
+             */
+            mAmbientStateAlarmManager.setExact(
+                    AlarmManager.RTC_WAKEUP,
+                    triggerTimeMs,
+                    mAmbientStatePendingIntent);
+
+        } else {
+            /** Calculate next trigger time (based on state). */
+            long delayMs = ACTIVE_INTERVAL_MS - (timeMs % ACTIVE_INTERVAL_MS);
+
+            mActiveModeUpdateHandler.removeMessages(MSG_UPDATE_SCREEN);
+            mActiveModeUpdateHandler.sendEmptyMessageDelayed(MSG_UPDATE_SCREEN, delayMs);
+        }
+    }
+
+    /**
+     * Updates display based on Ambient state. If you need to pull data, you should do it here.
+     */
+    private void loadDataAndUpdateScreen() {
+
+        mDrawCount += 1;
+        long currentTimeMs = System.currentTimeMillis();
+        Log.d(TAG, "loadDataAndUpdateScreen(): " + currentTimeMs + "(" + isAmbient() + ")");
+
+        if (isAmbient()) {
+
+            mTimeTextView.setText(sDateFormat.format(new Date()));
+            mTimeStampTextView.setText(getString(R.string.timestamp_label, currentTimeMs));
+
+            mStateTextView.setText(getString(R.string.mode_ambient_label));
+            mUpdateRateTextView.setText(
+                    getString(R.string.update_rate_label, (AMBIENT_INTERVAL_MS / 1000)));
+
+            mDrawCountTextView.setText(getString(R.string.draw_count_label, mDrawCount));
+
+        } else {
+            mTimeTextView.setText(sDateFormat.format(new Date()));
+            mTimeStampTextView.setText(getString(R.string.timestamp_label, currentTimeMs));
+
+            mStateTextView.setText(getString(R.string.mode_active_label));
+            mUpdateRateTextView.setText(
+                    getString(R.string.update_rate_label, (ACTIVE_INTERVAL_MS / 1000)));
+
+            mDrawCountTextView.setText(getString(R.string.draw_count_label, mDrawCount));
+        }
+    }
+
+    /**
+     * Handler separated into static class to avoid memory leaks.
+     */
+    private static class UpdateHandler extends Handler {
+        private final WeakReference<MainActivity> mMainActivityWeakReference;
+
+        public UpdateHandler(MainActivity reference) {
+            mMainActivityWeakReference = new WeakReference<MainActivity>(reference);
+        }
+
+        @Override
+        public void handleMessage(Message message) {
+            MainActivity mainActivity = mMainActivityWeakReference.get();
+
+            if (mainActivity != null) {
+                switch (message.what) {
+                    case MSG_UPDATE_SCREEN:
+                        mainActivity.refreshDisplayAndSetNextUpdate();
+                        break;
+                }
+            }
+        }
+    }
+}
\ No newline at end of file
diff --git a/wearable/wear/AlwaysOn/Wearable/src/main/res/layout/activity_main.xml b/wearable/wear/AlwaysOn/Wearable/src/main/res/layout/activity_main.xml
new file mode 100644
index 0000000..d808e6b
--- /dev/null
+++ b/wearable/wear/AlwaysOn/Wearable/src/main/res/layout/activity_main.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!-- Copyright (C) 2015 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<android.support.wearable.view.WatchViewStub
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:id="@+id/watch_view_stub"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    app:rectLayout="@layout/rect_activity_main"
+    app:roundLayout="@layout/round_activity_main"
+    tools:context=".MainActivity"
+    tools:deviceIds="wear">
+</android.support.wearable.view.WatchViewStub>
diff --git a/wearable/wear/AlwaysOn/Wearable/src/main/res/layout/rect_activity_main.xml b/wearable/wear/AlwaysOn/Wearable/src/main/res/layout/rect_activity_main.xml
new file mode 100644
index 0000000..bfb8147
--- /dev/null
+++ b/wearable/wear/AlwaysOn/Wearable/src/main/res/layout/rect_activity_main.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:paddingTop="@dimen/square_top_margin"
+    android:paddingLeft="@dimen/square_left_margin"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical"
+    tools:context=".MainActivity"
+    tools:deviceIds="wear_square">
+
+    <TextView
+        android:id="@+id/time"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:textSize="24sp"
+        android:text="Hello, time!"/>
+
+    <TextView
+        android:id="@+id/time_stamp"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:text="Hello, timestamp!"/>
+
+    <TextView
+        android:id="@+id/state"
+        android:textColor="@color/green"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:text="Hello, state!"/>
+
+    <TextView
+        android:id="@+id/update_rate"
+        android:textColor="@color/green"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:text="Hello, update rate!"/>
+
+    <TextView
+        android:id="@+id/draw_count"
+        android:textColor="@color/green"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:text="Hello, draw count!"/>
+</LinearLayout>
diff --git a/wearable/wear/AlwaysOn/Wearable/src/main/res/layout/round_activity_main.xml b/wearable/wear/AlwaysOn/Wearable/src/main/res/layout/round_activity_main.xml
new file mode 100644
index 0000000..8fa7a2d
--- /dev/null
+++ b/wearable/wear/AlwaysOn/Wearable/src/main/res/layout/round_activity_main.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:paddingTop="@dimen/round_top_margin"
+    android:paddingLeft="@dimen/round_left_margin"
+    android:layout_width="match_parent"
+    android:orientation="vertical"
+    android:layout_height="match_parent"
+    tools:context=".MainActivity"
+    tools:deviceIds="wear_round">
+
+    <TextView
+        android:id="@+id/time"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:textSize="24sp"
+        android:text="Hello, time!"/>
+
+    <TextView
+        android:id="@+id/time_stamp"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:text="Hello, timestamp!"/>
+
+    <TextView
+        android:id="@+id/state"
+        android:textColor="@color/green"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:text="Hello, state!"/>
+
+    <TextView
+        android:id="@+id/update_rate"
+        android:textColor="@color/green"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:text="Hello, update rate!"/>
+
+    <TextView
+        android:id="@+id/draw_count"
+        android:textColor="@color/green"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:text="Hello, draw count!"/>
+</LinearLayout>
diff --git a/wearable/wear/AlwaysOn/Wearable/src/main/res/values/dimens.xml b/wearable/wear/AlwaysOn/Wearable/src/main/res/values/dimens.xml
new file mode 100644
index 0000000..d44096a
--- /dev/null
+++ b/wearable/wear/AlwaysOn/Wearable/src/main/res/values/dimens.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<resources>
+    <!-- Default screen margins, per the Android Design guidelines. -->
+    <dimen name="square_top_margin">24dp</dimen>
+    <dimen name="square_left_margin">16dp</dimen>
+
+    <dimen name="round_top_margin">34dp</dimen>
+    <dimen name="round_left_margin">34dp</dimen>
+</resources>
diff --git a/wearable/wear/AlwaysOn/Wearable/src/main/res/values/strings.xml b/wearable/wear/AlwaysOn/Wearable/src/main/res/values/strings.xml
new file mode 100644
index 0000000..7d4c2f6
--- /dev/null
+++ b/wearable/wear/AlwaysOn/Wearable/src/main/res/values/strings.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+    <string name="app_name">Always On Example</string>
+    <string name="timestamp_label">Timestamp: %1$d</string>
+    <string name="mode_active_label">Active Mode (Handler)</string>
+    <string name="mode_ambient_label">Ambient Mode (Alarm)</string>
+    <string name="update_rate_label">Update rate: %1$d sec</string>
+    <string name="draw_count_label">Draw count: %1$d</string>
+</resources>
diff --git a/wearable/wear/AlwaysOn/build.gradle b/wearable/wear/AlwaysOn/build.gradle
new file mode 100644
index 0000000..18f393f
--- /dev/null
+++ b/wearable/wear/AlwaysOn/build.gradle
@@ -0,0 +1,11 @@
+
+// BEGIN_EXCLUDE
+import com.example.android.samples.build.SampleGenPlugin
+apply plugin: SampleGenPlugin
+
+samplegen {
+  pathToBuild "../../../../../build"
+  pathToSamplesCommon "../../../common"
+}
+apply from: "../../../../../build/build.gradle"
+// END_EXCLUDE
diff --git a/wearable/wear/AlwaysOn/buildSrc/build.gradle b/wearable/wear/AlwaysOn/buildSrc/build.gradle
new file mode 100644
index 0000000..7cebf71
--- /dev/null
+++ b/wearable/wear/AlwaysOn/buildSrc/build.gradle
@@ -0,0 +1,15 @@
+repositories {
+    mavenCentral()
+}
+dependencies {
+    compile 'org.freemarker:freemarker:2.3.20'
+}
+
+sourceSets {
+    main {
+        groovy {
+            srcDir new File(rootDir, "../../../../../../build/buildSrc/src/main/groovy")
+        }
+    }
+}
+
diff --git a/wearable/wear/AlwaysOn/gradle/wrapper/gradle-wrapper.jar b/wearable/wear/AlwaysOn/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000..8c0fb64
--- /dev/null
+++ b/wearable/wear/AlwaysOn/gradle/wrapper/gradle-wrapper.jar
Binary files differ
diff --git a/wearable/wear/AlwaysOn/gradle/wrapper/gradle-wrapper.properties b/wearable/wear/AlwaysOn/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..7d3b483
--- /dev/null
+++ b/wearable/wear/AlwaysOn/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Mon Dec 22 11:24:44 EST 2014
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
diff --git a/wearable/wear/AlwaysOn/gradlew b/wearable/wear/AlwaysOn/gradlew
new file mode 100755
index 0000000..91a7e26
--- /dev/null
+++ b/wearable/wear/AlwaysOn/gradlew
@@ -0,0 +1,164 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+##  Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+    echo "$*"
+}
+
+die ( ) {
+    echo
+    echo "$*"
+    echo
+    exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+  CYGWIN* )
+    cygwin=true
+    ;;
+  Darwin* )
+    darwin=true
+    ;;
+  MINGW* )
+    msys=true
+    ;;
+esac
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched.
+if $cygwin ; then
+    [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+    ls=`ls -ld "$PRG"`
+    link=`expr "$ls" : '.*-> \(.*\)$'`
+    if expr "$link" : '/.*' > /dev/null; then
+        PRG="$link"
+    else
+        PRG=`dirname "$PRG"`"/$link"
+    fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >&-
+APP_HOME="`pwd -P`"
+cd "$SAVED" >&-
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+        # IBM's JDK on AIX uses strange locations for the executables
+        JAVACMD="$JAVA_HOME/jre/sh/java"
+    else
+        JAVACMD="$JAVA_HOME/bin/java"
+    fi
+    if [ ! -x "$JAVACMD" ] ; then
+        die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+    fi
+else
+    JAVACMD="java"
+    which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+    MAX_FD_LIMIT=`ulimit -H -n`
+    if [ $? -eq 0 ] ; then
+        if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+            MAX_FD="$MAX_FD_LIMIT"
+        fi
+        ulimit -n $MAX_FD
+        if [ $? -ne 0 ] ; then
+            warn "Could not set maximum file descriptor limit: $MAX_FD"
+        fi
+    else
+        warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+    fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+    GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+    APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+    CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
+    # We build the pattern for arguments to be converted via cygpath
+    ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+    SEP=""
+    for dir in $ROOTDIRSRAW ; do
+        ROOTDIRS="$ROOTDIRS$SEP$dir"
+        SEP="|"
+    done
+    OURCYGPATTERN="(^($ROOTDIRS))"
+    # Add a user-defined pattern to the cygpath arguments
+    if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+        OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+    fi
+    # Now convert the arguments - kludge to limit ourselves to /bin/sh
+    i=0
+    for arg in "$@" ; do
+        CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+        CHECK2=`echo "$arg"|egrep -c "^-"`                                 ### Determine if an option
+
+        if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then                    ### Added a condition
+            eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+        else
+            eval `echo args$i`="\"$arg\""
+        fi
+        i=$((i+1))
+    done
+    case $i in
+        (0) set -- ;;
+        (1) set -- "$args0" ;;
+        (2) set -- "$args0" "$args1" ;;
+        (3) set -- "$args0" "$args1" "$args2" ;;
+        (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+        (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+        (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+        (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+        (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+        (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+    esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+    JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/wearable/wear/AlwaysOn/gradlew.bat b/wearable/wear/AlwaysOn/gradlew.bat
new file mode 100644
index 0000000..aec9973
--- /dev/null
+++ b/wearable/wear/AlwaysOn/gradlew.bat
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off

+@rem ##########################################################################

+@rem

+@rem  Gradle startup script for Windows

+@rem

+@rem ##########################################################################

+

+@rem Set local scope for the variables with windows NT shell

+if "%OS%"=="Windows_NT" setlocal

+

+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.

+set DEFAULT_JVM_OPTS=

+

+set DIRNAME=%~dp0

+if "%DIRNAME%" == "" set DIRNAME=.

+set APP_BASE_NAME=%~n0

+set APP_HOME=%DIRNAME%

+

+@rem Find java.exe

+if defined JAVA_HOME goto findJavaFromJavaHome

+

+set JAVA_EXE=java.exe

+%JAVA_EXE% -version >NUL 2>&1

+if "%ERRORLEVEL%" == "0" goto init

+

+echo.

+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

+echo.

+echo Please set the JAVA_HOME variable in your environment to match the

+echo location of your Java installation.

+

+goto fail

+

+:findJavaFromJavaHome

+set JAVA_HOME=%JAVA_HOME:"=%

+set JAVA_EXE=%JAVA_HOME%/bin/java.exe

+

+if exist "%JAVA_EXE%" goto init

+

+echo.

+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%

+echo.

+echo Please set the JAVA_HOME variable in your environment to match the

+echo location of your Java installation.

+

+goto fail

+

+:init

+@rem Get command-line arguments, handling Windowz variants

+

+if not "%OS%" == "Windows_NT" goto win9xME_args

+if "%@eval[2+2]" == "4" goto 4NT_args

+

+:win9xME_args

+@rem Slurp the command line arguments.

+set CMD_LINE_ARGS=

+set _SKIP=2

+

+:win9xME_args_slurp

+if "x%~1" == "x" goto execute

+

+set CMD_LINE_ARGS=%*

+goto execute

+

+:4NT_args

+@rem Get arguments from the 4NT Shell from JP Software

+set CMD_LINE_ARGS=%$

+

+:execute

+@rem Setup the command line

+

+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

+

+@rem Execute Gradle

+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%

+

+:end

+@rem End local scope for the variables with windows NT shell

+if "%ERRORLEVEL%"=="0" goto mainEnd

+

+:fail

+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of

+rem the _cmd.exe /c_ return code!

+if  not "" == "%GRADLE_EXIT_CONSOLE%" exit 1

+exit /b 1

+

+:mainEnd

+if "%OS%"=="Windows_NT" endlocal

+

+:omega

diff --git a/wearable/wear/AlwaysOn/screenshots/1-main-active.png b/wearable/wear/AlwaysOn/screenshots/1-main-active.png
new file mode 100644
index 0000000..cf5db84
--- /dev/null
+++ b/wearable/wear/AlwaysOn/screenshots/1-main-active.png
Binary files differ
diff --git a/wearable/wear/AlwaysOn/screenshots/2-main-ambient.png b/wearable/wear/AlwaysOn/screenshots/2-main-ambient.png
new file mode 100644
index 0000000..b871fce
--- /dev/null
+++ b/wearable/wear/AlwaysOn/screenshots/2-main-ambient.png
Binary files differ
diff --git a/wearable/wear/AlwaysOn/screenshots/3-main-active-round.png b/wearable/wear/AlwaysOn/screenshots/3-main-active-round.png
new file mode 100644
index 0000000..6acb920
--- /dev/null
+++ b/wearable/wear/AlwaysOn/screenshots/3-main-active-round.png
Binary files differ
diff --git a/wearable/wear/AlwaysOn/screenshots/4-main-ambient-round.png b/wearable/wear/AlwaysOn/screenshots/4-main-ambient-round.png
new file mode 100644
index 0000000..2a56f89
--- /dev/null
+++ b/wearable/wear/AlwaysOn/screenshots/4-main-ambient-round.png
Binary files differ
diff --git a/wearable/wear/AlwaysOn/template-params.xml b/wearable/wear/AlwaysOn/template-params.xml
new file mode 100644
index 0000000..e5794ee
--- /dev/null
+++ b/wearable/wear/AlwaysOn/template-params.xml
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<sample>
+    <name>AlwaysOn</name>
+    <group>Wearable</group>
+    <package>com.example.android.wearable.wear.alwayson</package>
+
+    <dependency_wearable>com.google.android.support:wearable:1.2.0</dependency_wearable>
+    <provided_dependency_wearable>com.google.android.wearable:wearable:1.0.0</provided_dependency_wearable>
+
+    <minSdk>20</minSdk>
+    <targetSdkVersion>22</targetSdkVersion>
+
+    <strings>
+        <intro>
+            <![CDATA[
+            Demonstrates a native Android Wear app using ambient screen support.
+            ]]>>
+        </intro>
+    </strings>
+
+    <template src="base-build" />
+    <template src="Wear" />
+
+    <!-- Include common code modules by uncommenting them below. -->
+    <!-- common src="logger"/ -->
+
+    <metadata>
+        <status>PUBLISHED</status>
+        <categories>Wearable</categories>
+        <technologies>Android</technologies>
+        <languages>Java</languages>
+        <solutions>Mobile</solutions>
+        <level>INTERMEDIATE</level>
+        <screenshots>
+            <img>screenshots/1-main-active.png</img>
+            <img>screenshots/2-main-ambient.png</img>
+            <img>screenshots/3-main-active-round.png</img>
+            <img>screenshots/4-main-ambient-round.png</img>
+        </screenshots>
+        <api_refs>
+            <android>android.support.wearable.activity.WearableActivity</android>
+        </api_refs>
+        <description>
+            <![CDATA[
+A basic sample showing how to support ambient mode for native Android Wear apps.
+]]>
+        </description>
+
+        <intro>
+            <![CDATA[
+[WearableActivity][1] offers methods for supporting your native app staying on the screen when the Wear device enters ambient mode.
+
+This example extends [WearableActivity][1] and overrides onEnterAmbient, onUpdateAmbient, and onExitAmbient to allow the simple native Wear app to support ambient mode.
+
+In ambient mode, this app follows best practices by keeping most pixels black, avoiding large blocks of white pixels, using only black and white, and disabling anti-aliasing (following the [design guidelines for Watch Faces][2]).
+
+In addition and most importantly, the app sleeps while in ambient mode for 20 seconds between any updates to conserving battery life (processor allowed to sleep). If you can hold off on updates for a full minute, you can throw away the Handler and just use onUpdateAmbient to save even more battery life.
+
+As always, you will still want to apply the [performance guidelines][3] outlined in the Watch Faces documention to your app.
+
+[1]: http://developer.android.com/reference/android/support/wearable/activity/WearableActivity.html
+[2]: https://developer.android.com/training/wearables/watch-faces/designing.html#DesignGuidelines
+[3]: https://developer.android.com/training/wearables/watch-faces/performance.html
+]]>
+        </intro>
+    </metadata>
+</sample>
\ No newline at end of file
diff --git a/wearable/wear/ElizaChat/Application/src/main/java/com/example/android/wearable/elizachat/MainActivity.java b/wearable/wear/ElizaChat/Application/src/main/java/com/example/android/wearable/elizachat/MainActivity.java
index 982e3de..2e132a8 100644
--- a/wearable/wear/ElizaChat/Application/src/main/java/com/example/android/wearable/elizachat/MainActivity.java
+++ b/wearable/wear/ElizaChat/Application/src/main/java/com/example/android/wearable/elizachat/MainActivity.java
@@ -55,11 +55,12 @@
             }
         };
         mHistoryView = (TextView) findViewById(R.id.history);
-        startResponderService();
+        startResponderService(ResponderService.ACTION_INCOMING);
     }
 
-    private void startResponderService() {
-        Intent serviceIntent = new Intent(ResponderService.ACTION_INCOMING);
+    private void startResponderService(String action) {
+        Intent serviceIntent = new Intent(this, ResponderService.class);
+        serviceIntent.setAction(action);
         startService(serviceIntent);
     }
 
@@ -69,9 +70,7 @@
         LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver,
                 new IntentFilter(ACTION_NOTIFY));
         mHistoryView.setText("");
-        Intent serviceIntent = new Intent(ACTION_GET_CONVERSATION);
-        startService(serviceIntent);
-
+        startResponderService(ACTION_GET_CONVERSATION);
     }
 
     @Override
diff --git a/wearable/wear/FindMyPhone/Wearable/src/main/java/com/example/android/wearable/findphone/FindPhoneService.java b/wearable/wear/FindMyPhone/Wearable/src/main/java/com/example/android/wearable/findphone/FindPhoneService.java
index 97204b4..c6c6d67 100644
--- a/wearable/wear/FindMyPhone/Wearable/src/main/java/com/example/android/wearable/findphone/FindPhoneService.java
+++ b/wearable/wear/FindMyPhone/Wearable/src/main/java/com/example/android/wearable/findphone/FindPhoneService.java
@@ -73,19 +73,22 @@
             if (intent.getAction().equals(ACTION_TOGGLE_ALARM)) {
                 // Get current state of the alarm.
                 DataItemBuffer result = Wearable.DataApi.getDataItems(mGoogleApiClient).await();
-                if (result.getStatus().isSuccess()) {
-                    if (result.getCount() == 1) {
-                        alarmOn = DataMap.fromByteArray(result.get(0).getData())
-                                .getBoolean(FIELD_ALARM_ON, false);
-                    } else {
-                        Log.e(TAG, "Unexpected number of DataItems found.\n"
-                                + "\tExpected: 1\n"
-                                + "\tActual: " + result.getCount());
+                try {
+                    if (result.getStatus().isSuccess()) {
+                        if (result.getCount() == 1) {
+                            alarmOn = DataMap.fromByteArray(result.get(0).getData())
+                                    .getBoolean(FIELD_ALARM_ON, false);
+                        } else {
+                            Log.e(TAG, "Unexpected number of DataItems found.\n"
+                                    + "\tExpected: 1\n"
+                                    + "\tActual: " + result.getCount());
+                        }
+                    } else if (Log.isLoggable(TAG, Log.DEBUG)) {
+                        Log.d(TAG, "onHandleIntent: failed to get current alarm state");
                     }
-                } else if (Log.isLoggable(TAG, Log.DEBUG)) {
-                    Log.d(TAG, "onHandleIntent: failed to get current alarm state");
+                } finally {
+                    result.release();
                 }
-                result.close();
                 // Toggle alarm.
                 alarmOn = !alarmOn;
                 // Change notification text based on new value of alarmOn.
diff --git a/wearable/wear/Quiz/Application/src/main/java/com/example/android/wearable/quiz/MainActivity.java b/wearable/wear/Quiz/Application/src/main/java/com/example/android/wearable/quiz/MainActivity.java
index 1e58935..855fcd6 100644
--- a/wearable/wear/Quiz/Application/src/main/java/com/example/android/wearable/quiz/MainActivity.java
+++ b/wearable/wear/Quiz/Application/src/main/java/com/example/android/wearable/quiz/MainActivity.java
@@ -445,16 +445,19 @@
                     .setResultCallback(new ResultCallback<DataItemBuffer>() {
                         @Override
                         public void onResult(DataItemBuffer result) {
-                            if (result.getStatus().isSuccess()) {
-                                List<DataItem> dataItemList = FreezableUtils.freezeIterable(result);
-                                result.close();
-                                resetDataItems(dataItemList);
-                            } else {
-                                if (Log.isLoggable(TAG, Log.DEBUG)) {
-                                    Log.d(TAG, "Reset quiz: failed to get Data Items to reset");
+                            try {
+                                if (result.getStatus().isSuccess()) {
+                                    List<DataItem> dataItemList = FreezableUtils
+                                            .freezeIterable(result);
+                                    resetDataItems(dataItemList);
+                                } else {
+                                    if (Log.isLoggable(TAG, Log.DEBUG)) {
+                                        Log.d(TAG, "Reset quiz: failed to get Data Items to reset");
+                                    }
                                 }
+                            } finally {
+                                result.release();
                             }
-                            result.close();
                         }
                     });
         } else {
@@ -521,19 +524,23 @@
                     .setResultCallback(new ResultCallback<DataItemBuffer>() {
                         @Override
                         public void onResult(DataItemBuffer result) {
-                            if (result.getStatus().isSuccess()) {
-                                List<Uri> dataItemUriList = new ArrayList<Uri>();
-                                for (final DataItem dataItem : result) {
-                                    dataItemUriList.add(dataItem.getUri());
+                            try {
+                                if (result.getStatus().isSuccess()) {
+                                    List<Uri> dataItemUriList = new ArrayList<Uri>();
+                                    for (final DataItem dataItem : result) {
+                                        dataItemUriList.add(dataItem.getUri());
+                                    }
+                                    deleteDataItems(dataItemUriList);
+                                } else {
+                                    if (Log.isLoggable(TAG, Log.DEBUG)) {
+                                        Log.d(TAG, "Clear quiz: failed to get Data Items for "
+                                                + "deletion");
+
+                                    }
                                 }
-                                result.close();
-                                deleteDataItems(dataItemUriList);
-                            } else {
-                                if (Log.isLoggable(TAG, Log.DEBUG)) {
-                                    Log.d(TAG, "Clear quiz: failed to get Data Items for deletion");
-                                }
+                            } finally {
+                                result.release();
                             }
-                            result.close();
                         }
                     });
         } else {
diff --git a/wearable/wear/SpeedTracker/template-params.xml b/wearable/wear/SpeedTracker/template-params.xml
index 6287a2a..71c5ac2 100644
--- a/wearable/wear/SpeedTracker/template-params.xml
+++ b/wearable/wear/SpeedTracker/template-params.xml
@@ -28,8 +28,8 @@
         <has_handheld_app>true</has_handheld_app>
     </wearable>
 
-    <dependency>com.google.android.gms:play-services-location:6.5.+</dependency>
-    <dependency_wearable>com.google.android.gms:play-services-location:6.5.+</dependency_wearable>
+    <dependency>com.google.android.gms:play-services-location:7.3.0</dependency>
+    <dependency_wearable>com.google.android.gms:play-services-location:7.3.0</dependency_wearable>
 
 
     <strings>
diff --git a/wearable/wear/WatchFace/Wearable/src/main/java/com/example/android/wearable/watchface/AnalogWatchFaceService.java b/wearable/wear/WatchFace/Wearable/src/main/java/com/example/android/wearable/watchface/AnalogWatchFaceService.java
index f0fb4f5..15c550f 100644
--- a/wearable/wear/WatchFace/Wearable/src/main/java/com/example/android/wearable/watchface/AnalogWatchFaceService.java
+++ b/wearable/wear/WatchFace/Wearable/src/main/java/com/example/android/wearable/watchface/AnalogWatchFaceService.java
@@ -33,10 +33,10 @@
 import android.support.wearable.watchface.CanvasWatchFaceService;
 import android.support.wearable.watchface.WatchFaceService;
 import android.support.wearable.watchface.WatchFaceStyle;
-import android.text.format.Time;
 import android.util.Log;
 import android.view.SurfaceHolder;
 
+import java.util.Calendar;
 import java.util.TimeZone;
 import java.util.concurrent.TimeUnit;
 
@@ -64,12 +64,14 @@
     private class Engine extends CanvasWatchFaceService.Engine {
         static final int MSG_UPDATE_TIME = 0;
 
+        static final float TWO_PI = (float) Math.PI * 2f;
+
         Paint mHourPaint;
         Paint mMinutePaint;
         Paint mSecondPaint;
         Paint mTickPaint;
         boolean mMute;
-        Time mTime;
+        Calendar mCalendar;
 
         /** Handler to update the time once a second in interactive mode. */
         final Handler mUpdateTimeHandler = new Handler() {
@@ -95,8 +97,8 @@
         final BroadcastReceiver mTimeZoneReceiver = new BroadcastReceiver() {
             @Override
             public void onReceive(Context context, Intent intent) {
-                mTime.clear(intent.getStringExtra("time-zone"));
-                mTime.setToNow();
+                mCalendar.setTimeZone(TimeZone.getDefault());
+                invalidate();
             }
         };
         boolean mRegisteredTimeZoneReceiver = false;
@@ -124,7 +126,7 @@
                     .build());
 
             Resources resources = AnalogWatchFaceService.this.getResources();
-            Drawable backgroundDrawable = resources.getDrawable(R.drawable.bg);
+            Drawable backgroundDrawable = resources.getDrawable(R.drawable.bg, null /* theme */);
             mBackgroundBitmap = ((BitmapDrawable) backgroundDrawable).getBitmap();
 
             mHourPaint = new Paint();
@@ -150,7 +152,7 @@
             mTickPaint.setStrokeWidth(2.f);
             mTickPaint.setAntiAlias(true);
 
-            mTime = new Time();
+            mCalendar = Calendar.getInstance();
         }
 
         @Override
@@ -212,7 +214,7 @@
 
         @Override
         public void onDraw(Canvas canvas, Rect bounds) {
-            mTime.setToNow();
+            mCalendar.setTimeInMillis(System.currentTimeMillis());
 
             int width = bounds.width();
             int height = bounds.height();
@@ -236,7 +238,7 @@
             float innerTickRadius = centerX - 10;
             float outerTickRadius = centerX;
             for (int tickIndex = 0; tickIndex < 12; tickIndex++) {
-                float tickRot = (float) (tickIndex * Math.PI * 2 / 12);
+                float tickRot = tickIndex * TWO_PI / 12;
                 float innerX = (float) Math.sin(tickRot) * innerTickRadius;
                 float innerY = (float) -Math.cos(tickRot) * innerTickRadius;
                 float outerX = (float) Math.sin(tickRot) * outerTickRadius;
@@ -245,10 +247,13 @@
                         centerX + outerX, centerY + outerY, mTickPaint);
             }
 
-            float secRot = mTime.second / 30f * (float) Math.PI;
-            int minutes = mTime.minute;
-            float minRot = minutes / 30f * (float) Math.PI;
-            float hrRot = ((mTime.hour + (minutes / 60f)) / 6f ) * (float) Math.PI;
+            float seconds =
+                    mCalendar.get(Calendar.SECOND) + mCalendar.get(Calendar.MILLISECOND) / 1000f;
+            float secRot = seconds / 60f * TWO_PI;
+            float minutes = mCalendar.get(Calendar.MINUTE) + seconds / 60f;
+            float minRot = minutes / 60f * TWO_PI;
+            float hours = mCalendar.get(Calendar.HOUR) + minutes / 60f;
+            float hrRot = hours / 12f * TWO_PI;
 
             float secLength = centerX - 20;
             float minLength = centerX - 40;
@@ -280,8 +285,7 @@
                 registerReceiver();
 
                 // Update time zone in case it changed while we weren't visible.
-                mTime.clear(TimeZone.getDefault().getID());
-                mTime.setToNow();
+                mCalendar.setTimeZone(TimeZone.getDefault());
             } else {
                 unregisterReceiver();
             }
diff --git a/wearable/wear/WatchFace/Wearable/src/main/java/com/example/android/wearable/watchface/DigitalWatchFaceService.java b/wearable/wear/WatchFace/Wearable/src/main/java/com/example/android/wearable/watchface/DigitalWatchFaceService.java
index b8b1314..0bc420d 100644
--- a/wearable/wear/WatchFace/Wearable/src/main/java/com/example/android/wearable/watchface/DigitalWatchFaceService.java
+++ b/wearable/wear/WatchFace/Wearable/src/main/java/com/example/android/wearable/watchface/DigitalWatchFaceService.java
@@ -31,7 +31,7 @@
 import android.support.wearable.watchface.CanvasWatchFaceService;
 import android.support.wearable.watchface.WatchFaceService;
 import android.support.wearable.watchface.WatchFaceStyle;
-import android.text.format.Time;
+import android.text.format.DateFormat;
 import android.util.Log;
 import android.view.SurfaceHolder;
 import android.view.WindowInsets;
@@ -46,6 +46,7 @@
 import com.google.android.gms.wearable.DataMapItem;
 import com.google.android.gms.wearable.Wearable;
 
+import java.util.Calendar;
 import java.util.TimeZone;
 import java.util.concurrent.TimeUnit;
 
@@ -125,8 +126,8 @@
         final BroadcastReceiver mTimeZoneReceiver = new BroadcastReceiver() {
             @Override
             public void onReceive(Context context, Intent intent) {
-                mTime.clear(intent.getStringExtra("time-zone"));
-                mTime.setToNow();
+                mCalendar.setTimeZone(TimeZone.getDefault());
+                invalidate();
             }
         };
         boolean mRegisteredTimeZoneReceiver = false;
@@ -139,7 +140,7 @@
         Paint mColonPaint;
         float mColonWidth;
         boolean mMute;
-        Time mTime;
+        Calendar mCalendar;
         boolean mShouldDrawColons;
         float mXOffset;
         float mYOffset;
@@ -185,7 +186,7 @@
             mAmPmPaint = createTextPaint(resources.getColor(R.color.digital_am_pm));
             mColonPaint = createTextPaint(resources.getColor(R.color.digital_colons));
 
-            mTime = new Time();
+            mCalendar = Calendar.getInstance();
         }
 
         @Override
@@ -219,8 +220,7 @@
                 registerReceiver();
 
                 // Update time zone in case it changed while we weren't visible.
-                mTime.clear(TimeZone.getDefault().getID());
-                mTime.setToNow();
+                mCalendar.setTimeZone(TimeZone.getDefault());
             } else {
                 unregisterReceiver();
 
@@ -403,18 +403,14 @@
             return String.format("%02d", hour);
         }
 
-        private int convertTo12Hour(int hour) {
-            int result = hour % 12;
-            return (result == 0) ? 12 : result;
-        }
-
-        private String getAmPmString(int hour) {
-            return (hour < 12) ? mAmString : mPmString;
+        private String getAmPmString(int amPm) {
+            return amPm == Calendar.AM ? mAmString : mPmString;
         }
 
         @Override
         public void onDraw(Canvas canvas, Rect bounds) {
-            mTime.setToNow();
+            mCalendar.setTimeInMillis(System.currentTimeMillis());
+            boolean is24Hour = DateFormat.is24HourFormat(DigitalWatchFaceService.this);
 
             // Show colons for the first half of each second so the colons blink on when the time
             // updates.
@@ -425,7 +421,19 @@
 
             // Draw the hours.
             float x = mXOffset;
-            String hourString = String.valueOf(convertTo12Hour(mTime.hour));
+            String hourString;
+            if (is24Hour) {
+                hourString = formatTwoDigitNumber(mCalendar.get(Calendar.HOUR_OF_DAY));
+            } else {
+                int hour = mCalendar.get(Calendar.HOUR);
+                if (hour == 0) {
+                    hour = 12;
+                }
+                hourString = String.valueOf(hour);
+                if (hour < 10) {
+                    x += mHourPaint.measureText("0");
+                }
+            }
             canvas.drawText(hourString, x, mYOffset, mHourPaint);
             x += mHourPaint.measureText(hourString);
 
@@ -437,22 +445,23 @@
             x += mColonWidth;
 
             // Draw the minutes.
-            String minuteString = formatTwoDigitNumber(mTime.minute);
+            String minuteString = formatTwoDigitNumber(mCalendar.get(Calendar.MINUTE));
             canvas.drawText(minuteString, x, mYOffset, mMinutePaint);
             x += mMinutePaint.measureText(minuteString);
 
-            // In ambient and mute modes, draw AM/PM. Otherwise, draw a second blinking
-            // colon followed by the seconds.
-            if (isInAmbientMode() || mMute) {
-                x += mColonWidth;
-                canvas.drawText(getAmPmString(mTime.hour), x, mYOffset, mAmPmPaint);
-            } else {
+            // In unmuted interactive mode, draw a second blinking colon followed by the seconds.
+            // Otherwise, if we're in 12-hour mode, draw AM/PM
+            if (!isInAmbientMode() && !mMute) {
                 if (mShouldDrawColons) {
                     canvas.drawText(COLON_STRING, x, mYOffset, mColonPaint);
                 }
                 x += mColonWidth;
-                canvas.drawText(formatTwoDigitNumber(mTime.second), x, mYOffset,
-                        mSecondPaint);
+                canvas.drawText(formatTwoDigitNumber(
+                        mCalendar.get(Calendar.SECOND)), x, mYOffset, mSecondPaint);
+            } else if (!is24Hour) {
+                x += mColonWidth;
+                canvas.drawText(getAmPmString(
+                        mCalendar.get(Calendar.AM_PM)), x, mYOffset, mAmPmPaint);
             }
         }
 
diff --git a/wearable/wear/WatchFace/Wearable/src/main/java/com/example/android/wearable/watchface/SweepWatchFaceService.java b/wearable/wear/WatchFace/Wearable/src/main/java/com/example/android/wearable/watchface/SweepWatchFaceService.java
index 44e9569..193f29a 100644
--- a/wearable/wear/WatchFace/Wearable/src/main/java/com/example/android/wearable/watchface/SweepWatchFaceService.java
+++ b/wearable/wear/WatchFace/Wearable/src/main/java/com/example/android/wearable/watchface/SweepWatchFaceService.java
@@ -31,10 +31,10 @@
 import android.support.wearable.watchface.CanvasWatchFaceService;
 import android.support.wearable.watchface.WatchFaceService;
 import android.support.wearable.watchface.WatchFaceStyle;
-import android.text.format.Time;
 import android.util.Log;
 import android.view.SurfaceHolder;
 
+import java.util.Calendar;
 import java.util.TimeZone;
 
 /**
@@ -53,18 +53,20 @@
     }
 
     private class Engine extends CanvasWatchFaceService.Engine {
+        static final float TWO_PI = (float) Math.PI * 2f;
+
         Paint mHourPaint;
         Paint mMinutePaint;
         Paint mSecondPaint;
         Paint mTickPaint;
         boolean mMute;
-        Time mTime;
+        Calendar mCalendar;
 
         final BroadcastReceiver mTimeZoneReceiver = new BroadcastReceiver() {
             @Override
             public void onReceive(Context context, Intent intent) {
-                mTime.clear(intent.getStringExtra("time-zone"));
-                mTime.setToNow();
+                mCalendar.setTimeZone(TimeZone.getDefault());
+                invalidate();
             }
         };
         boolean mRegisteredTimeZoneReceiver = false;
@@ -92,7 +94,7 @@
                     .build());
 
             Resources resources = SweepWatchFaceService.this.getResources();
-            Drawable backgroundDrawable = resources.getDrawable(R.drawable.bg);
+            Drawable backgroundDrawable = resources.getDrawable(R.drawable.bg, null /* theme */);
             mBackgroundBitmap = ((BitmapDrawable) backgroundDrawable).getBitmap();
 
             mHourPaint = new Paint();
@@ -118,7 +120,7 @@
             mTickPaint.setStrokeWidth(2.f);
             mTickPaint.setAntiAlias(true);
 
-            mTime = new Time();
+            mCalendar = Calendar.getInstance();
         }
 
         @Override
@@ -174,8 +176,7 @@
                 Log.v(TAG, "onDraw");
             }
             long now = System.currentTimeMillis();
-            mTime.set(now);
-            int milliseconds = (int) (now % 1000);
+            mCalendar.setTimeInMillis(now);
 
             int width = bounds.width();
             int height = bounds.height();
@@ -208,11 +209,13 @@
                         centerX + outerX, centerY + outerY, mTickPaint);
             }
 
-            float seconds = mTime.second + milliseconds / 1000f;
-            float secRot = seconds / 30f * (float) Math.PI;
-            int minutes = mTime.minute;
-            float minRot = minutes / 30f * (float) Math.PI;
-            float hrRot = ((mTime.hour + (minutes / 60f)) / 6f ) * (float) Math.PI;
+            float seconds =
+                    mCalendar.get(Calendar.SECOND) + mCalendar.get(Calendar.MILLISECOND) / 1000f;
+            float secRot = seconds / 60f * TWO_PI;
+            float minutes = mCalendar.get(Calendar.MINUTE) + seconds / 60f;
+            float minRot = minutes / 60f * TWO_PI;
+            float hours = mCalendar.get(Calendar.HOUR) + minutes / 60f;
+            float hrRot = hours / 12f * TWO_PI;
 
             float secLength = centerX - 20;
             float minLength = centerX - 40;
@@ -246,8 +249,7 @@
                 registerReceiver();
 
                 // Update time zone in case it changed while we weren't visible.
-                mTime.clear(TimeZone.getDefault().getID());
-                mTime.setToNow();
+                mCalendar.setTimeZone(TimeZone.getDefault());
 
                 invalidate();
             } else {
diff --git a/wearable/wear/WatchFace/Wearable/src/main/java/com/example/android/wearable/watchface/TiltWatchFaceService.java b/wearable/wear/WatchFace/Wearable/src/main/java/com/example/android/wearable/watchface/TiltWatchFaceService.java
index 6dd01b0..ffb0b6c 100644
--- a/wearable/wear/WatchFace/Wearable/src/main/java/com/example/android/wearable/watchface/TiltWatchFaceService.java
+++ b/wearable/wear/WatchFace/Wearable/src/main/java/com/example/android/wearable/watchface/TiltWatchFaceService.java
@@ -24,11 +24,11 @@
 import android.opengl.Matrix;
 import android.support.wearable.watchface.Gles2WatchFaceService;
 import android.support.wearable.watchface.WatchFaceStyle;
-import android.text.format.Time;
 import android.util.Log;
 import android.view.Gravity;
 import android.view.SurfaceHolder;
 
+import java.util.Calendar;
 import java.util.TimeZone;
 import java.util.concurrent.TimeUnit;
 
@@ -44,6 +44,9 @@
     /** Expected frame rate in interactive mode. */
     private static final long FPS = 60;
 
+    /** Z distance from the camera to the watchface. */
+    private static final float EYE_Z = 2.3f;
+
     /** How long each frame is displayed at expected frame rate. */
     private static final long FRAME_PERIOD_MS = TimeUnit.SECONDS.toMillis(1) / FPS;
 
@@ -107,7 +110,7 @@
         /** Triangle for the hour hand. */
         private Gles2ColoredTriangleList mHourHandTriangle;
 
-        private Time mTime = new Time();
+        private Calendar mCalendar = Calendar.getInstance();
 
         /** Whether we've registered {@link #mTimeZoneReceiver}. */
         private boolean mRegisteredTimeZoneReceiver;
@@ -115,8 +118,8 @@
         private final BroadcastReceiver mTimeZoneReceiver = new BroadcastReceiver() {
             @Override
             public void onReceive(Context context, Intent intent) {
-                mTime.clear(intent.getStringExtra("time-zone"));
-                mTime.setToNow();
+                mCalendar.setTimeZone(TimeZone.getDefault());
+                invalidate();
             }
         };
 
@@ -170,7 +173,7 @@
             mMinuteHandTriangle = createHand(
                     triangleProgram,
                     0.06f /* width */,
-                    0.8f /* height */,
+                    1f /* height */,
                     new float[]{
                             0.7f /* red */,
                             0.7f /* green */,
@@ -181,7 +184,7 @@
             mHourHandTriangle = createHand(
                     triangleProgram,
                     0.1f /* width */,
-                    0.5f /* height */,
+                    0.6f /* height */,
                     new float[]{
                             0.9f /* red */,
                             0.9f /* green */,
@@ -204,14 +207,14 @@
                 final float eyeY = (float) Math.sin(cameraAngle);
                 Matrix.setLookAtM(mViewMatrices[i],
                         0, // dest index
-                        eyeX, eyeY, -3, // eye
+                        eyeX, eyeY, EYE_Z, // eye
                         0, 0, 0, // center
                         0, 1, 0); // up vector
             }
 
             Matrix.setLookAtM(mAmbientViewMatrix,
                     0, // dest index
-                    0, 0, -3, // eye
+                    0, 0, EYE_Z, // eye
                     0, 0, 0, // center
                     0, 1, 0); // up vector
         }
@@ -378,8 +381,7 @@
                 registerReceiver();
 
                 // Update time zone in case it changed while we were detached.
-                mTime.clear(TimeZone.getDefault().getID());
-                mTime.setToNow();
+                mCalendar.setTimeZone(TimeZone.getDefault());
 
                 invalidate();
             } else {
@@ -436,26 +438,28 @@
             GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
 
             // Compute angle indices for the three hands.
-            mTime.setToNow();
-            final int secIndex = mTime.second * 360 / 60;
-            final int minIndex = mTime.minute * 360 / 60;
-            final int hoursIndex = (mTime.hour % 12) * 360 / 12 + mTime.minute * 360 / 60 / 12;
+            mCalendar.setTimeInMillis(System.currentTimeMillis());
+            float seconds =
+                    mCalendar.get(Calendar.SECOND) + mCalendar.get(Calendar.MILLISECOND) / 1000f;
+            float minutes = mCalendar.get(Calendar.MINUTE) + seconds / 60f;
+            float hours = mCalendar.get(Calendar.HOUR) + minutes / 60f;
+            final int secIndex = (int) (seconds / 60f * 360f);
+            final int minIndex = (int) (minutes / 60f * 360f);
+            final int hoursIndex = (int) (hours / 12f * 360f);
 
             // Draw triangles from back to front. Don't draw the second hand in ambient mode.
-            {
-                // Combine the model matrix with the projection and camera view.
-                Matrix.multiplyMM(mMvpMatrix, 0, vpMatrix, 0, mModelMatrices[hoursIndex], 0);
 
-                // Draw the triangle.
-                mHourHandTriangle.draw(mMvpMatrix);
-            }
-            {
-                // Combine the model matrix with the projection and camera view.
-                Matrix.multiplyMM(mMvpMatrix, 0, vpMatrix, 0, mModelMatrices[minIndex], 0);
+            // Combine the model matrix with the projection and camera view.
+            Matrix.multiplyMM(mMvpMatrix, 0, vpMatrix, 0, mModelMatrices[hoursIndex], 0);
 
-                // Draw the triangle.
-                mMinuteHandTriangle.draw(mMvpMatrix);
-            }
+            // Draw the triangle.
+            mHourHandTriangle.draw(mMvpMatrix);
+
+            // Combine the model matrix with the projection and camera view.
+            Matrix.multiplyMM(mMvpMatrix, 0, vpMatrix, 0, mModelMatrices[minIndex], 0);
+
+            // Draw the triangle.
+            mMinuteHandTriangle.draw(mMvpMatrix);
             if (!isInAmbientMode()) {
                 // Combine the model matrix with the projection and camera view.
                 Matrix.multiplyMM(mMvpMatrix, 0, vpMatrix, 0, mModelMatrices[secIndex], 0);
@@ -463,11 +467,10 @@
                 // Draw the triangle.
                 mSecondHandTriangle.draw(mMvpMatrix);
             }
-            {
-                // Draw the major and minor ticks.
-                mMajorTickTriangles.draw(vpMatrix);
-                mMinorTickTriangles.draw(vpMatrix);
-            }
+
+            // Draw the major and minor ticks.
+            mMajorTickTriangles.draw(vpMatrix);
+            mMinorTickTriangles.draw(vpMatrix);
 
             // Draw every frame as long as we're visible and in interactive mode.
             if (isVisible() && !isInAmbientMode()) {
diff --git a/wearable/wear/XYZTouristAttractions/Application/src/main/AndroidManifest.xml b/wearable/wear/XYZTouristAttractions/Application/src/main/AndroidManifest.xml
index 5f330d5..76f0198 100644
--- a/wearable/wear/XYZTouristAttractions/Application/src/main/AndroidManifest.xml
+++ b/wearable/wear/XYZTouristAttractions/Application/src/main/AndroidManifest.xml
@@ -58,6 +58,10 @@
         <meta-data android:name="com.google.android.gms.version"
             android:value="@integer/google_play_services_version" />
 
+        <meta-data
+            android:name="com.example.android.xyztouristattractions.config.GlideConfiguration"
+            android:value="GlideModule"/>
+
     </application>
 
 </manifest>
diff --git a/wearable/wear/XYZTouristAttractions/Application/src/main/java/com/example/android/xyztouristattractions/config/GlideConfiguration.java b/wearable/wear/XYZTouristAttractions/Application/src/main/java/com/example/android/xyztouristattractions/config/GlideConfiguration.java
new file mode 100644
index 0000000..77d6fc8
--- /dev/null
+++ b/wearable/wear/XYZTouristAttractions/Application/src/main/java/com/example/android/xyztouristattractions/config/GlideConfiguration.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2015 Google Inc. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.xyztouristattractions.config;
+
+import android.content.Context;
+
+import com.bumptech.glide.Glide;
+import com.bumptech.glide.GlideBuilder;
+import com.bumptech.glide.load.DecodeFormat;
+import com.bumptech.glide.module.GlideModule;
+
+/**
+ * This allows global overriding of some default Glide configuration values.
+ * For additional information see the Glide docs:
+ * https://github.com/bumptech/glide/wiki/Configuration
+ */
+public class GlideConfiguration implements GlideModule {
+    @Override
+    public void applyOptions(Context context, GlideBuilder builder) {
+        // Set Glide decode format to the higher quality ARGB_8888 format
+        builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
+    }
+
+    @Override
+    public void registerComponents(Context context, Glide glide) {
+
+    }
+}
diff --git a/wearable/wear/XYZTouristAttractions/Application/src/main/java/com/example/android/xyztouristattractions/ui/AttractionListActivity.java b/wearable/wear/XYZTouristAttractions/Application/src/main/java/com/example/android/xyztouristattractions/ui/AttractionListActivity.java
index 8d43112..8d2908c 100644
--- a/wearable/wear/XYZTouristAttractions/Application/src/main/java/com/example/android/xyztouristattractions/ui/AttractionListActivity.java
+++ b/wearable/wear/XYZTouristAttractions/Application/src/main/java/com/example/android/xyztouristattractions/ui/AttractionListActivity.java
@@ -16,9 +16,9 @@
 
 package com.example.android.xyztouristattractions.ui;
 
-import android.app.AlertDialog;
 import android.os.Bundle;
-import android.support.v7.app.ActionBarActivity;
+import android.support.v7.app.AlertDialog;
+import android.support.v7.app.AppCompatActivity;
 import android.view.Menu;
 import android.view.MenuItem;
 import android.widget.Toast;
@@ -31,7 +31,7 @@
  * The main tourist attraction activity screen which contains a list of
  * attractions sorted by distance.
  */
-public class AttractionListActivity extends ActionBarActivity {
+public class AttractionListActivity extends AppCompatActivity {
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
diff --git a/wearable/wear/XYZTouristAttractions/Application/src/main/java/com/example/android/xyztouristattractions/ui/DetailActivity.java b/wearable/wear/XYZTouristAttractions/Application/src/main/java/com/example/android/xyztouristattractions/ui/DetailActivity.java
index a83f480..3950785 100644
--- a/wearable/wear/XYZTouristAttractions/Application/src/main/java/com/example/android/xyztouristattractions/ui/DetailActivity.java
+++ b/wearable/wear/XYZTouristAttractions/Application/src/main/java/com/example/android/xyztouristattractions/ui/DetailActivity.java
@@ -24,7 +24,7 @@
 import android.os.Bundle;
 import android.support.v4.app.ActivityCompat;
 import android.support.v4.app.ActivityOptionsCompat;
-import android.support.v7.app.ActionBarActivity;
+import android.support.v7.app.AppCompatActivity;
 import android.view.View;
 
 import com.example.android.xyztouristattractions.R;
@@ -33,7 +33,7 @@
  * The tourist attraction detail activity screen which contains the details of
  * a single attraction.
  */
-public class DetailActivity extends ActionBarActivity {
+public class DetailActivity extends AppCompatActivity {
 
     private static final String EXTRA_ATTRACTION = "attraction";
 
diff --git a/wearable/wear/XYZTouristAttractions/Application/src/main/res/values/colors.xml b/wearable/wear/XYZTouristAttractions/Application/src/main/res/values/colors.xml
index 142f548..2c16a5d 100644
--- a/wearable/wear/XYZTouristAttractions/Application/src/main/res/values/colors.xml
+++ b/wearable/wear/XYZTouristAttractions/Application/src/main/res/values/colors.xml
@@ -17,10 +17,6 @@
 
 <resources>
 
-    <color name="colorPrimary">#4e6cef</color>
-    <color name="colorPrimaryDark">#2a36b1</color>
-    <color name="colorAccent">#ff7043</color>
-
     <color name="text_background">#90000000</color>
     <color name="transparent_actionbar_background">#22000000</color>
     <color name="lighter_gray">#ddd</color>
diff --git a/wearable/wear/XYZTouristAttractions/Wearable/src/main/res/color/action_color.xml b/wearable/wear/XYZTouristAttractions/Shared/src/main/res/values/colors.xml
similarity index 73%
rename from wearable/wear/XYZTouristAttractions/Wearable/src/main/res/color/action_color.xml
rename to wearable/wear/XYZTouristAttractions/Shared/src/main/res/values/colors.xml
index 634d806..73c2b6c 100644
--- a/wearable/wear/XYZTouristAttractions/Wearable/src/main/res/color/action_color.xml
+++ b/wearable/wear/XYZTouristAttractions/Shared/src/main/res/values/colors.xml
@@ -15,11 +15,10 @@
   limitations under the License.
   -->
 
-<selector xmlns:android="http://schemas.android.com/apk/res/android">
+<resources>
 
-    <item android:state_pressed="true"
-        android:color="#ee3c4b90" /> <!-- pressed -->
+    <color name="colorPrimary">#4e6cef</color>
+    <color name="colorPrimaryDark">#2a36b1</color>
+    <color name="colorAccent">#ff7043</color>
 
-    <item android:color="#ee5c6bc0" /> <!-- default -->
-
-</selector>
\ No newline at end of file
+</resources>
\ No newline at end of file
diff --git a/wearable/wear/XYZTouristAttractions/Wearable/src/main/java/com/example/android/xyztouristattractions/ui/AttractionsActivity.java b/wearable/wear/XYZTouristAttractions/Wearable/src/main/java/com/example/android/xyztouristattractions/ui/AttractionsActivity.java
index 464eb8a..64d28bc 100644
--- a/wearable/wear/XYZTouristAttractions/Wearable/src/main/java/com/example/android/xyztouristattractions/ui/AttractionsActivity.java
+++ b/wearable/wear/XYZTouristAttractions/Wearable/src/main/java/com/example/android/xyztouristattractions/ui/AttractionsActivity.java
@@ -84,6 +84,8 @@
         mAdapter = new AttractionsGridPagerAdapter(this, mAttractions);
         mAdapter.setOnChromeFadeListener(this);
         mGridViewPager.setAdapter(mAdapter);
+        mDotsPageIndicator.setPager(mGridViewPager);
+        mDotsPageIndicator.setOnPageChangeListener(mAdapter);
 
         topFrameLayout.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
             @Override
@@ -243,8 +245,6 @@
                 // Update UI based on the result of the background processing
                 mAdapter.setData(result);
                 mAdapter.notifyDataSetChanged();
-                mDotsPageIndicator.setPager(mGridViewPager);
-                mDotsPageIndicator.setOnPageChangeListener(mAdapter);
                 mProgressBar.setVisibility(View.GONE);
                 mDotsPageIndicator.setVisibility(View.VISIBLE);
                 mGridViewPager.setVisibility(View.VISIBLE);
diff --git a/wearable/wear/XYZTouristAttractions/Wearable/src/main/java/com/example/android/xyztouristattractions/ui/AttractionsGridPagerAdapter.java b/wearable/wear/XYZTouristAttractions/Wearable/src/main/java/com/example/android/xyztouristattractions/ui/AttractionsGridPagerAdapter.java
index 99737f4..97accde 100644
--- a/wearable/wear/XYZTouristAttractions/Wearable/src/main/java/com/example/android/xyztouristattractions/ui/AttractionsGridPagerAdapter.java
+++ b/wearable/wear/XYZTouristAttractions/Wearable/src/main/java/com/example/android/xyztouristattractions/ui/AttractionsGridPagerAdapter.java
@@ -25,11 +25,11 @@
 import android.graphics.drawable.Drawable;
 import android.os.Handler;
 import android.support.wearable.activity.ConfirmationActivity;
+import android.support.wearable.view.ActionPage;
 import android.support.wearable.view.CardFrame;
 import android.support.wearable.view.CardScrollView;
 import android.support.wearable.view.GridPagerAdapter;
 import android.support.wearable.view.GridViewPager;
-import android.support.wearable.view.WatchViewStub;
 import android.text.TextUtils;
 import android.view.Gravity;
 import android.view.LayoutInflater;
@@ -97,7 +97,7 @@
     }
 
     @Override
-    protected Object instantiateItem(ViewGroup container, int row, final int column) {
+    public Object instantiateItem(ViewGroup container, int row, final int column) {
         if (mAttractions != null && mAttractions.size() > 0) {
             final Attraction attraction = mAttractions.get(row);
             switch (column) {
@@ -150,48 +150,30 @@
                     return cardScrollView;
                 case PAGER_NAVIGATE_ACTION_COLUMN:
                     // The navigate action
-                    final WatchViewStub navStub = (WatchViewStub) mLayoutInflater.inflate(
+                    final ActionPage navActionPage = (ActionPage) mLayoutInflater.inflate(
                             R.layout.gridpager_action, container, false);
 
-                    navStub.setOnClickListener(getStartActionClickListener(
+                    navActionPage.setOnClickListener(getStartActionClickListener(
                             attraction, Constants.START_NAVIGATION_PATH,
                             ConfirmationActivity.SUCCESS_ANIMATION));
+                    navActionPage.setImageResource(R.drawable.ic_full_directions_walking);
+                    navActionPage.setText(mContext.getString(R.string.action_navigate));
 
-                    navStub.setOnLayoutInflatedListener(
-                            new WatchViewStub.OnLayoutInflatedListener() {
-                        @Override
-                        public void onLayoutInflated(WatchViewStub watchViewStub) {
-                            ImageView imageView = (ImageView) navStub.findViewById(R.id.imageView);
-                            imageView.setImageResource(R.drawable.ic_full_directions_walking);
-                            TextView textView = (TextView) navStub.findViewById(R.id.textView);
-                            textView.setText(R.string.action_navigate);
-                        }
-                    });
-
-                    container.addView(navStub);
-                    return navStub;
+                    container.addView(navActionPage);
+                    return navActionPage;
                 case PAGER_OPEN_ACTION_COLUMN:
                     // The "open on device" action
-                    final WatchViewStub openStub = (WatchViewStub) mLayoutInflater.inflate(
+                    final ActionPage openActionPage = (ActionPage) mLayoutInflater.inflate(
                             R.layout.gridpager_action, container, false);
 
-                    openStub.setOnClickListener(getStartActionClickListener(
+                    openActionPage.setOnClickListener(getStartActionClickListener(
                             attraction, Constants.START_ATTRACTION_PATH,
                             ConfirmationActivity.OPEN_ON_PHONE_ANIMATION));
+                    openActionPage.setImageResource(R.drawable.ic_full_openonphone);
+                    openActionPage.setText(mContext.getString(R.string.action_open));
 
-                    openStub.setOnLayoutInflatedListener(
-                            new WatchViewStub.OnLayoutInflatedListener() {
-                        @Override
-                        public void onLayoutInflated(WatchViewStub watchViewStub) {
-                            ImageView imageView = (ImageView) openStub.findViewById(R.id.imageView);
-                            imageView.setImageResource(R.drawable.ic_full_open_on_device);
-                            TextView textView = (TextView) openStub.findViewById(R.id.textView);
-                            textView.setText(R.string.action_open);
-                        }
-                    });
-
-                    container.addView(openStub);
-                    return openStub;
+                    container.addView(openActionPage);
+                    return openActionPage;
             }
         }
         return new View(mContext);
@@ -209,7 +191,7 @@
     }
 
     @Override
-    protected void destroyItem(ViewGroup viewGroup, int row, int column, Object object) {
+    public void destroyItem(ViewGroup viewGroup, int row, int column, Object object) {
         mDelayedHide.remove((View) object);
         viewGroup.removeView((View)object);
     }
@@ -242,6 +224,7 @@
     private void startAction(Attraction attraction, String pathName, int confirmAnimationType) {
         Intent intent = new Intent(mContext, ConfirmationActivity.class);
         intent.putExtra(ConfirmationActivity.EXTRA_ANIMATION_TYPE, confirmAnimationType);
+        intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
         mContext.startActivity(intent);
 
         UtilityService.clearNotification(mContext);
@@ -270,8 +253,8 @@
     }
 
     public interface OnChromeFadeListener {
-        abstract void onChromeFadeIn();
-        abstract void onChromeFadeOut();
+        void onChromeFadeIn();
+        void onChromeFadeOut();
     }
 
     /**
diff --git a/wearable/wear/XYZTouristAttractions/Wearable/src/main/res/drawable-hdpi/ic_full_open_on_device.png b/wearable/wear/XYZTouristAttractions/Wearable/src/main/res/drawable-hdpi/ic_full_open_on_device.png
deleted file mode 100644
index 4e11601..0000000
--- a/wearable/wear/XYZTouristAttractions/Wearable/src/main/res/drawable-hdpi/ic_full_open_on_device.png
+++ /dev/null
Binary files differ
diff --git a/wearable/wear/XYZTouristAttractions/Wearable/src/main/res/drawable-hdpi/ic_full_openonphone.png b/wearable/wear/XYZTouristAttractions/Wearable/src/main/res/drawable-hdpi/ic_full_openonphone.png
new file mode 100644
index 0000000..8952486
--- /dev/null
+++ b/wearable/wear/XYZTouristAttractions/Wearable/src/main/res/drawable-hdpi/ic_full_openonphone.png
Binary files differ
diff --git a/wearable/wear/XYZTouristAttractions/Wearable/src/main/res/drawable-xhdpi/ic_full_open_on_device.png b/wearable/wear/XYZTouristAttractions/Wearable/src/main/res/drawable-xhdpi/ic_full_open_on_device.png
deleted file mode 100644
index 2f6f056..0000000
--- a/wearable/wear/XYZTouristAttractions/Wearable/src/main/res/drawable-xhdpi/ic_full_open_on_device.png
+++ /dev/null
Binary files differ
diff --git a/wearable/wear/XYZTouristAttractions/Wearable/src/main/res/drawable-xhdpi/ic_full_openonphone.png b/wearable/wear/XYZTouristAttractions/Wearable/src/main/res/drawable-xhdpi/ic_full_openonphone.png
new file mode 100644
index 0000000..d10a19c
--- /dev/null
+++ b/wearable/wear/XYZTouristAttractions/Wearable/src/main/res/drawable-xhdpi/ic_full_openonphone.png
Binary files differ
diff --git a/wearable/wear/XYZTouristAttractions/Wearable/src/main/res/layout/activity_main.xml b/wearable/wear/XYZTouristAttractions/Wearable/src/main/res/layout/activity_main.xml
index a4ef94b..27fce1f 100644
--- a/wearable/wear/XYZTouristAttractions/Wearable/src/main/res/layout/activity_main.xml
+++ b/wearable/wear/XYZTouristAttractions/Wearable/src/main/res/layout/activity_main.xml
@@ -41,9 +41,6 @@
         android:layout_height="wrap_content"
         android:layout_width="wrap_content"
         app:dotFadeWhenIdle="false"
-        app:dotFadeInDuration="0"
-        app:dotFadeOutDuration="0"
-        app:dotFadeOutDelay="0"
         android:visibility="gone" />
 
     <android.support.wearable.view.DismissOverlayView
diff --git a/wearable/wear/XYZTouristAttractions/Wearable/src/main/res/layout/gridpager_action.xml b/wearable/wear/XYZTouristAttractions/Wearable/src/main/res/layout/gridpager_action.xml
index 4b3bbaf..ac01509 100644
--- a/wearable/wear/XYZTouristAttractions/Wearable/src/main/res/layout/gridpager_action.xml
+++ b/wearable/wear/XYZTouristAttractions/Wearable/src/main/res/layout/gridpager_action.xml
@@ -16,11 +16,14 @@
   limitations under the License.
   -->
 
-<android.support.wearable.view.WatchViewStub
+<android.support.wearable.view.ActionPage
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:id="@+id/actionpage"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    app:rectLayout="@layout/gridpager_action_square"
-    app:roundLayout="@layout/gridpager_action_round"
-    android:clickable="true" />
+    android:src="@drawable/ic_full_openonphone"
+    android:text="@string/action_open"
+    android:maxLines="1"
+    android:color="@color/colorPrimary"
+    app:rippleColor="@color/colorAccent" />
diff --git a/wearable/wear/XYZTouristAttractions/Wearable/src/main/res/layout/gridpager_action_round.xml b/wearable/wear/XYZTouristAttractions/Wearable/src/main/res/layout/gridpager_action_round.xml
deleted file mode 100644
index 70cec1a..0000000
--- a/wearable/wear/XYZTouristAttractions/Wearable/src/main/res/layout/gridpager_action_round.xml
+++ /dev/null
@@ -1,59 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-
-<!--
-  Copyright 2015 Google Inc. All rights reserved.
-
-  Licensed under the Apache License, Version 2.0 (the "License");
-  you may not use this file except in compliance with the License.
-  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
-  -->
-
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:app="http://schemas.android.com/apk/res-auto"
-    xmlns:tools="http://schemas.android.com/tools"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent">
-
-    <View
-        android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        android:background="#7F000000"/>
-
-    <android.support.wearable.view.CircledImageView
-        android:id="@+id/circleImageView"
-        android:layout_width="112dp"
-        android:layout_height="112dp"
-        android:layout_centerInParent="true"
-        app:circle_radius="52dp"
-        app:circle_radius_pressed="56dp"
-        app:circle_color="@color/action_color">
-
-        <ImageView
-            android:id="@+id/imageView"
-            android:layout_width="64dp"
-            android:layout_height="64dp"
-            android:layout_gravity="center"
-            android:src="@drawable/ic_full_open_on_device"
-            android:scaleType="centerCrop" />
-
-    </android.support.wearable.view.CircledImageView>
-
-    <TextView
-        android:id="@+id/textView"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        style="@style/ActionTextStyleRound"
-        android:layout_below="@id/circleImageView"
-        android:layout_centerHorizontal="true"
-        android:gravity="center"
-        tools:text="Navigate" />
-
-</RelativeLayout>
\ No newline at end of file
diff --git a/wearable/wear/XYZTouristAttractions/Wearable/src/main/res/layout/gridpager_action_square.xml b/wearable/wear/XYZTouristAttractions/Wearable/src/main/res/layout/gridpager_action_square.xml
deleted file mode 100644
index 362671b..0000000
--- a/wearable/wear/XYZTouristAttractions/Wearable/src/main/res/layout/gridpager_action_square.xml
+++ /dev/null
@@ -1,63 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-
-<!--
-  Copyright 2015 Google Inc. All rights reserved.
-
-  Licensed under the Apache License, Version 2.0 (the "License");
-  you may not use this file except in compliance with the License.
-  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
-  -->
-
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:app="http://schemas.android.com/apk/res-auto"
-    xmlns:tools="http://schemas.android.com/tools"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent">
-
-    <View
-        android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        android:background="#7F000000"/>
-
-    <android.support.wearable.view.CircledImageView
-        android:id="@+id/circleImageView"
-        android:layout_width="112dp"
-        android:layout_height="112dp"
-        android:layout_alignParentTop="true"
-        android:layout_centerHorizontal="true"
-        android:layout_marginTop="24dp"
-        app:circle_radius="52dp"
-        app:circle_radius_pressed="56dp"
-        app:circle_color="@color/action_color">
-
-        <ImageView
-            android:id="@+id/imageView"
-            android:layout_width="64dp"
-            android:layout_height="64dp"
-            android:layout_gravity="center"
-            android:src="@drawable/ic_full_open_on_device"
-            android:scaleType="centerCrop" />
-
-    </android.support.wearable.view.CircledImageView>
-
-    <TextView
-        android:id="@+id/textView"
-        android:layout_width="wrap_content"
-        android:layout_height="match_parent"
-        style="@style/ActionTextStyle"
-        android:layout_below="@id/circleImageView"
-        android:layout_marginBottom="12dp"
-        android:layout_centerHorizontal="true"
-        android:maxLines="2"
-        android:gravity="center"
-        tools:text="Navigate" />
-
-</RelativeLayout>
\ No newline at end of file
diff --git a/wearable/wear/XYZTouristAttractions/Wearable/src/main/res/values/styles.xml b/wearable/wear/XYZTouristAttractions/Wearable/src/main/res/values/styles.xml
index cebe1c7..11b2d3d 100644
--- a/wearable/wear/XYZTouristAttractions/Wearable/src/main/res/values/styles.xml
+++ b/wearable/wear/XYZTouristAttractions/Wearable/src/main/res/values/styles.xml
@@ -31,18 +31,4 @@
         <item name="android:ellipsize">end</item>
     </style>
 
-    <style name="ActionTextStyle" parent="@android:style/TextAppearance.Large">
-        <item name="android:fontFamily">sans-serif-condensed-light</item>
-        <item name="android:textStyle">normal</item>
-        <item name="android:textSize">18sp</item>
-        <item name="android:maxLines">2</item>
-        <item name="android:ellipsize">end</item>
-        <item name="android:textColor">#FFFFFF</item>
-    </style>
-
-    <style name="ActionTextStyleRound" parent="ActionTextStyle">
-        <item name="android:textSize">14sp</item>
-        <item name="android:maxLines">1</item>
-    </style>
-
 </resources>
\ No newline at end of file
diff --git a/wearable/wear/XYZTouristAttractions/template-params.xml b/wearable/wear/XYZTouristAttractions/template-params.xml
index 0b64557..51882ac 100644
--- a/wearable/wear/XYZTouristAttractions/template-params.xml
+++ b/wearable/wear/XYZTouristAttractions/template-params.xml
@@ -24,11 +24,11 @@
         <has_handheld_app>true</has_handheld_app>
     </wearable>
 
-    <dependency>com.android.support:appcompat-v7:21.0.3</dependency>
+    <dependency>com.android.support:appcompat-v7:22.1.1</dependency>
     <dependency>com.google.android.gms:play-services-location:7.3.0</dependency>
     <dependency>com.google.maps.android:android-maps-utils:0.3.2</dependency>
     <dependency>com.github.bumptech.glide:glide:3.5.2</dependency>
-    <dependency>com.android.support:recyclerview-v7:21.0.0</dependency>
+    <dependency>com.android.support:recyclerview-v7:22.1.1</dependency>
     <dependency_wearable>com.google.android.gms:play-services-location:7.3.0</dependency_wearable>
     <dependency_shared>com.google.android.gms:play-services-wearable:7.3.0</dependency_shared>
     <dependency_shared>com.google.android.gms:play-services-location:7.3.0</dependency_shared>
@@ -96,6 +96,7 @@
             <android>android.support.wearable.view.CardScrollView</android>
             <android>android.support.wearable.view.GridPagerAdapter</android>
             <android>android.support.wearable.view.WatchViewStub</android>
+            <android>android.support.wearable.view.ActionPage</android>
         </api_refs>
 
         <!-- 1-3 line description of the sample here.