This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Car carSearchCriteria = new Car(1998, null, "Focus", "Sedan"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Car { | |
| int year; | |
| String make; | |
| String model; | |
| String carType; | |
| public static class Builder { | |
| int year; | |
| String make; | |
| String model; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Car { | |
| int year; | |
| String make; | |
| String model; | |
| String carType; | |
| public Car(int year) { | |
| this.year = year; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <resources> | |
| <style name="SampleBase" parent="@android:style/Theme.Light" /> | |
| <style name="SampleTheme" parent="SampleBase"> | |
| <item name="android:windowBackground">@null</item> | |
| <item name="menuDrawerStyle">@style/MenuDrawerStyle</item> | |
| </style> | |
| <style name="SampleTheme.RightDrawer" parent="SampleBase"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void deinitialize() { | |
| stopPreview(); | |
| releaseCamera(); | |
| Log.d(TAG, "Camera Initialization has Been Undone"); | |
| } | |
| private void initialize() { | |
| if (hasCamera(this) && getCameraInstance() != null) { | |
| startPreview(); | |
| Log.d(TAG, "Camera Initialization has Been Completed"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private Camera.ErrorCallback getErrorCallback() { | |
| if (mErrorCallback == null) { | |
| mErrorCallback = new Camera.ErrorCallback() { | |
| @Override | |
| public void onError(int error, Camera camera) { | |
| if (error == Camera.CAMERA_ERROR_SERVER_DIED) { | |
| deinitialize(); | |
| initialize(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private Camera getCameraInstance() { | |
| try { | |
| // attempt to get a Camera instance | |
| // this will open the default camera, which is the back-facing camera (if it exists) | |
| mCamera = Camera.open(); | |
| // need to handle the Media Server Dying | |
| mCamera.setErrorCallback(getErrorCallback()); | |
| Log.d(TAG, "Camera Opened Successfully"); | |
| } catch (RuntimeException e) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private boolean hasCamera(Context context) { | |
| if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) { | |
| // this device has a camera | |
| Log.d(TAG, "At Least one Camera Detected!"); | |
| return true; | |
| } else { | |
| // no camera on this device | |
| Log.d(TAG, "No Cameras detected."); | |
| return false; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.simple_camera_activity); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Override | |
| protected void onPause() { | |
| super.onPause(); | |
| deinitialize(); | |
| } |